API reference

DestructibleMeshComponent Class

Extends MonoBehaviour
The DestructibleMeshComponent handles the segmentation and manipulation of a mesh to create a segmented version of the original.
Used mainly to build destructible environments in conjunction with a global mesh. For mor details on its usage see DestructibleGlobalMeshSpawner It uses asynchronous tasks to perform the computations for mesh segmentation based on specified parameters and reserved areas.

Fields

OnDestructibleMeshCreated : UnityEvent< DestructibleMeshComponent >
Event triggered when a destructible mesh is successfully created.
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

Properties

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

Methods

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

Inner Structs

MeshSegment Struct

Represents a single mesh segment with position data, indices for mesh topology, UVs for texturing, and tangents for normal mapping.

Fields

indices : int[]
Signature
int [] indices
positions : Vector3[]
Signature
Vector3 [] positions
tangents : Vector4[]
Signature
Vector4 [] tangents
uv : Vector2[]
Signature
Vector2 [] uv

MeshSegmentationResult Struct

Contains the results of a mesh segmentation operation, including a list of mesh segments and a specially reserved segment.

Fields

reservedSegment : MeshSegment
Signature
MeshSegment reservedSegment
segments : List< MeshSegment >
Signature
List<MeshSegment> segments