DestructibleMeshComponent handles the segmentation and manipulation of a mesh to create a segmented version of the original.
private void OnDestructibleMeshCreated(DestructibleMeshComponent destructibleMeshComponent)
{
_destructibleMeshComponent = destructibleMeshComponent;
destructibleMeshComponent.GetDestructibleMeshSegments(_globalMeshSegments);
foreach (var globalMeshSegment in _globalMeshSegments)
{
globalMeshSegment.AddComponent<MeshCollider>();
}
}OnDestructibleMeshCreated
: UnityEvent< DestructibleMeshComponent > |
Event triggered when a destructible mesh is successfully created.
Is automatically set to the DestructibleGlobalMeshSpawner.OnDestructibleMeshCreated event
Signature
UnityEvent<DestructibleMeshComponent> OnDestructibleMeshCreated |
OnSegmentationCompleted
: Func< MeshSegmentationResult, MeshSegmentationResult > |
Function delegate that processes the segmentation result.
It can be used to modify the segmentation results before they are instantiated.
Signature
Func<MeshSegmentationResult, MeshSegmentationResult> OnSegmentationCompleted |
GlobalMeshMaterial
: Material
[Get][Set] |
Gets or sets the material used for the mesh.
This material is applied to the mesh segments that are created during the segmentation process.
Signature
Material GlobalMeshMaterial |
ReservedBottom
: float
[Get][Set] |
Gets or sets the reserved space at the bottom of the mesh.
TThis space is not included in the destructible area, allowing for controlled segmentation.
Signature
float ReservedBottom |
ReservedSegment
: GameObject
[Get] |
Gets the game object associated to the reserved segment defined as the portion of the mesh that should be indestructible.
Can be null if no segment has been reserved.
Signature
GameObject ReservedSegment |
ReservedTop
: float
[Get][Set] |
Gets or sets the reserved space at the top of the mesh.
This space is not included in the destructible area, allowing for controlled segmentation.
Signature
float ReservedTop |
DebugDestructibleMeshComponent
()
|
Debugging method to color each segment with a unique color.
Signature
void DebugDestructibleMeshComponent() Returns void |
DestroySegment
(
segment
)
|
Cleans up created mesh segments when the component is destroyed or reset.
Signature
void DestroySegment(GameObject segment) Parameters segment: GameObjectÂ
The game object associated to the segment to be destroyed.
Returns void |
GetDestructibleMeshSegments
(
segments
)
|
Populates an array with GameObjects representing the destructible mesh segments.
The array should be provided with enough space to hold all segments. see GetDestructibleMeshSegmentsCount.
Signature
void GetDestructibleMeshSegments(GameObject[] segments) Parameters segments: GameObject[]Â
The array to populate with mesh segment GameObjects.
Returns void |
GetDestructibleMeshSegments< T >
(
segments
)
|
Populates a provided container with GameObjects representing the destructible mesh segments.
The container will be cleared before being populated.
Signature
void GetDestructibleMeshSegments< T >(T segments) Parameters segments: TÂ
The list to populate with mesh segment GameObjects.
Returns void |
GetDestructibleMeshSegmentsCount
()
|
Returns the count of destructible mesh segments currently managed by this component.
Signature
int GetDestructibleMeshSegmentsCount() Returns intÂ
The number of child GameObjects representing mesh segments.
|
SegmentMesh
(
meshPositions
, meshIndices
, segmentationPoints
)
|
Initiates the mesh segmentation process asynchronously based on the provided mesh positions, indices, and segmentation points.
It uses native functions to perform the segmentation and updates the mesh accordingly.
Signature
unsafe void SegmentMesh(Vector3[] meshPositions, uint[] meshIndices, Vector3[] segmentationPoints) Parameters meshPositions: Vector3[]Â
Array of mesh vertex positions.
meshIndices: uint[]Â
Array of mesh indices.
segmentationPoints: Vector3[]Â
Array of points used for segmenting the mesh.
Returns unsafe void |
colors
: Color[] |
The colors applied to each vertex of the mesh segment.
Vertex colors can be used for a variety of effects, including vertex-based shading and color blending.
Signature
Color [] colors |
indices
: int[] |
The indices that define the mesh topology.
\ Use the MeshSegmentationResult struct to create and manage mesh segments.
Signature
int [] indices |
positions
: Vector3[] |
The vertex positions of the mesh segment.
Use the MeshSegmentationResult struct to create and manage mesh segments.
Signature
Vector3 [] positions |
tangents
: Vector4[] |
The tangents used for normal mapping.
Tangents are necessary for advanced lighting effects, such as bump mapping.
Signature
Vector4 [] tangents |
uv
: Vector2[] |
The UV coordinates for texturing the mesh segment.
UVs map the 2D texture to the 3D surface of the mesh.
Signature
Vector2 [] uv |
private static DestructibleMeshComponent.MeshSegmentationResult ModifySegmentationResult(
DestructibleMeshComponent.MeshSegmentationResult meshSegmentationResult)
{
var newSegments = new List<DestructibleMeshComponent.MeshSegment>();
foreach (var segment in meshSegmentationResult.segments)
{
var newSegment = ModifyMeshSegment(segment);
newSegments.Add(newSegment);
}
var newReservedSegment = ModifyMeshSegment(meshSegmentationResult.reservedSegment);
return new DestructibleMeshComponent.MeshSegmentationResult()
{
segments = newSegments,
reservedSegment = newReservedSegment
};
}reservedSegment
: MeshSegment |
A specially reserved segment that remains indestructible.
This segment is kept intact and is not subject to the usual segmentation process.
Signature
MeshSegment reservedSegment |
segments
: List< MeshSegment > |
A list of resulting from the segmentation operation.
Each MeshSegment represents a distinct part of the original mesh.
Signature
List<MeshSegment> segments |