Class CollisionData
Represents a physics mesh that can be used with a MeshCollider. Physics mesh can be a generic triangle mesh or a convex mesh.
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Physics/CollisionData.h
Syntax
public class CollisionData : public BinaryAsset
Methods
CookCollision(CollisionDataType type, const Span<Float3>& vertices, const Span<int32>& triangles, ConvexMeshGenerationFlags convexFlags=ConvexMeshGenerationFlags::None, int32 convexVertexLimit=255)
Cooks the mesh collision data and updates the virtual asset. action cannot be performed on a main thread.
Can be used only for virtual assets (see IsVirtual() and CreateVirtualAsset()).
Declaration
public bool CookCollision(CollisionDataType type, const Span<Float3>& vertices, const Span<int32>& triangles, ConvexMeshGenerationFlags convexFlags=ConvexMeshGenerationFlags::None, int32 convexVertexLimit=255)
Parameters
CollisionDataType
type
The collision data type. |
Span<Float3>
vertices
The source geometry vertex buffer with vertices positions. Cannot be empty. |
Span<int32>
triangles
The source data index buffer (triangles list). Uses 32-bit stride buffer. Cannot be empty. Length must be multiple of 3 (as 3 vertices build a triangle). |
ConvexMeshGenerationFlags
convexFlags
The convex mesh generation flags. |
int32
convexVertexLimit
The convex mesh vertex limit. Use values in range [8;255] |
Returns
bool
True if failed, otherwise false. |
CookCollision(CollisionDataType type, const Span<Float3>& vertices, const Span<uint32>& triangles, ConvexMeshGenerationFlags convexFlags=ConvexMeshGenerationFlags::None, int32 convexVertexLimit=255)
Cooks the mesh collision data and updates the virtual asset. action cannot be performed on a main thread.
Can be used only for virtual assets (see IsVirtual() and CreateVirtualAsset()).
Declaration
public bool CookCollision(CollisionDataType type, const Span<Float3>& vertices, const Span<uint32>& triangles, ConvexMeshGenerationFlags convexFlags=ConvexMeshGenerationFlags::None, int32 convexVertexLimit=255)
Parameters
CollisionDataType
type
The collision data type. |
Span<Float3>
vertices
The source geometry vertex buffer with vertices positions. Cannot be empty. |
Span<uint32>
triangles
The source data index buffer (triangles list). Uses 32-bit stride buffer. Cannot be empty. Length must be multiple of 3 (as 3 vertices build a triangle). |
ConvexMeshGenerationFlags
convexFlags
The convex mesh generation flags. |
int32
convexVertexLimit
The convex mesh vertex limit. Use values in range [8;255] |
Returns
bool
True if failed, otherwise false. |
CookCollision(CollisionDataType type, ModelBase* model, int32 modelLodIndex = 0, uint32 materialSlotsMask=MAX_uint32, ConvexMeshGenerationFlags convexFlags=ConvexMeshGenerationFlags::None, int32 convexVertexLimit=255)
Cooks the mesh collision data and updates the virtual asset.
Can be used only for virtual assets (see IsVirtual() and CreateVirtualAsset()).
Declaration
public bool CookCollision(CollisionDataType type, ModelBase* model, int32 modelLodIndex = 0, uint32 materialSlotsMask=MAX_uint32, ConvexMeshGenerationFlags convexFlags=ConvexMeshGenerationFlags::None, int32 convexVertexLimit=255)
Parameters
CollisionDataType
type
The collision data type. |
ModelBase
model
The source model. If model is virtual then this method cannot be called from the main thread. |
int32
modelLodIndex
The source model LOD index. |
uint32
materialSlotsMask
The source model material slots mask. One bit per-slot. Can be used to exclude particular material slots from collision cooking. |
ConvexMeshGenerationFlags
convexFlags
The convex mesh generation flags. |
int32
convexVertexLimit
The convex mesh vertex limit. Use values in range [8;255] |
Returns
bool
True if failed, otherwise false. |
CookCollision(CollisionDataType type, ModelData* modelData, ConvexMeshGenerationFlags convexFlags, int32 convexVertexLimit)
Cooks the mesh collision data and updates the virtual asset. action cannot be performed on a main thread.
Can be used only for virtual assets (see IsVirtual() and CreateVirtualAsset()).
Declaration
public bool CookCollision(CollisionDataType type, ModelData* modelData, ConvexMeshGenerationFlags convexFlags, int32 convexVertexLimit)
Parameters
CollisionDataType
type
The collision data type. |
ModelData
modelData
The custom geometry. |
ConvexMeshGenerationFlags
convexFlags
The convex mesh generation flags. |
int32
convexVertexLimit
The convex mesh vertex limit. Use values in range [8;255] |
Returns
bool
True if failed, otherwise false. |
ExtractGeometry(Array<Float3>& vertexBuffer, Array<int32>& indexBuffer)
Extracts the collision data geometry into list of triangles.
Declaration
public void ExtractGeometry(Array<Float3>& vertexBuffer, Array<int32>& indexBuffer) const
Parameters
Array<Float3>
vertexBuffer
The output vertex buffer. |
Array<int32>
indexBuffer
The output index buffer. |
getChunksToPreload()
Gets packed chunks indices to preload before asset loading action
Declaration
protected virtual AssetChunksFlag getChunksToPreload() const override
Returns
AssetChunksFlag
Chunks to load flags |
Overrides
GetConvex()
Gets the convex mesh object (valid only if asset is loaded and has cooked convex data).
Declaration
public void* GetConvex() const
Returns
void
|
GetDebugLines()
Declaration
public Array<Float3> GetDebugLines()
Returns
Array<Float3>
|
GetDebugTriangles(Array<Float3>*& vertexBuffer, Array<int32>*& indexBuffer)
Declaration
public void GetDebugTriangles(Array<Float3>*& vertexBuffer, Array<int32>*& indexBuffer)
Parameters
Array<Float3>
vertexBuffer
|
Array<int32>
indexBuffer
|
GetModelTriangle(uint32 faceIndex, MeshBase*& mesh, uint32& meshTriangleIndex)
Extracts the triangle index of the original mesh data used for cooking this collision data. Can be used to get vertex attributes of the triangle mesh hit by the raycast.
Supported only for collision data built as triangle mesh and without ConvexMeshGenerationFlags.SuppressFaceRemapTable flag set.
Declaration
public bool GetModelTriangle(uint32 faceIndex, MeshBase*& mesh, uint32& meshTriangleIndex) const
Parameters
uint32
faceIndex
The face index of the collision mesh. |
MeshBase
mesh
The result source mesh used to build this collision data (can be null if collision data was cooked using custom geometry without source Model set). |
uint32
meshTriangleIndex
The result triangle index of the source geometry used to build this collision data. |
Returns
bool
True if got a valid triangle index, otherwise false. |
GetOptions()
Gets the options.
Declaration
public CollisionDataOptions GetOptions() const
Returns
CollisionDataOptions
|
GetTriangle()
Gets the triangle mesh object (valid only if asset is loaded and has cooked triangle data).
Declaration
public void* GetTriangle() const
Returns
void
|
load()
Load data from the chunks
Declaration
protected virtual LoadResult load() override
Returns
LoadResult
Loading result |
Overrides
unload(bool isReloading)
Unloads asset data
Declaration
protected virtual void unload(bool isReloading) override
Parameters
bool
isReloading
True if asset is reloading data, otherwise false. |