Class CollisionMesh
- Namespace
- Box3D
- Assembly
- Box3D.NET.dll
A triangle mesh, used for static level geometry.
public sealed class CollisionMesh : IDisposableInheritance
Implements
Inherited Members
Examples
// Build once, from your level data.
using var terrain = CollisionMesh.FromTriangles(vertices, indices);
using (var world = new PhysicsWorld())
{
Body level = world.CreateStaticBody();
level.AddMesh(terrain);
// The same mesh again, at half scale, somewhere else.
Body scaled = world.CreateStaticBody(new Vector3(100.0f, 0.0f, 0.0f));
scaled.AddMesh(terrain, scale: new Vector3(0.5f));
Simulate(world);
}
// World first, mesh second.
Remarks
A mesh is built once and shared by as many shapes as needed, at different scales if you like. Building one is expensive; attaching it is not.
Lifetime. Unlike every other shape, attaching a mesh does not copy it. The shape points at this object's memory, so it must outlive every shape built from it. Disposing it while a shape still refers to it will crash inside the solver rather than raise an exception. The safe order is: dispose the world, then dispose the meshes.
Static bodies only. Box3D generates mesh contacts against static bodies. Attaching one to a dynamic or kinematic body is rejected.
Properties
- Bounds
-
Gets the local-space bounding box.
- ByteCount
-
Gets the memory the mesh occupies, in bytes.
- DegenerateTriangleCount
-
Gets the number of degenerate triangles found while building, which were discarded.
- IsDisposed
-
Gets a value indicating whether this mesh has been disposed.
- TriangleCount
-
Gets the number of triangles.
- VertexCount
-
Gets the number of vertices.
Methods
- BoxMesh(Vector3, Vector3, bool)
-
Builds a closed box as a triangle mesh.
- Dispose()
-
Releases the mesh.
- FromTriangles(ReadOnlySpan<Vector3>, ReadOnlySpan<int>, MeshOptions?, ReadOnlySpan<byte>)
-
Builds a mesh from vertices and triangle indices.
- Grid(int, int, float, int, bool)
-
Builds a flat grid in the xz plane, useful as a test floor.
- HollowBox(Vector3, Vector3)
-
Builds a hollow box, useful as a container that things fall into.
- Wave(int, int, float, float, float, float)
-
Builds a rolling wave surface, useful for testing uneven ground.