Struct Mesh
- Namespace
- BepuPhysics.Collidables
- Assembly
- BepuPhysics.dll
Shape designed to contain a whole bunch of triangles. Triangle collisions and ray tests are one-sided; only tests which see the triangle as wound clockwise in right handed coordinates or counterclockwise in left handed coordinates will generate contacts.
public struct Mesh : IHomogeneousCompoundShape<Triangle, TriangleWide>, IDisposableShape, IShape, IBoundsQueryableCompound
- Implements
- Inherited Members
Constructors
Mesh(Buffer<Triangle>, Vector3, BufferPool, IThreadDispatcher)
Creates a mesh shape.
public Mesh(Buffer<Triangle> triangles, Vector3 scale, BufferPool pool, IThreadDispatcher dispatcher = null)
Parameters
triangles
Buffer<Triangle>Triangles to use in the mesh.
scale
Vector3Scale to apply to all vertices at runtime. Note that the scale is not baked into the triangles or acceleration structure; the same set of triangles and acceleration structure can be used across multiple Mesh instances with different scales.
pool
BufferPoolPool used to allocate acceleration structures.
dispatcher
IThreadDispatcherDispatcher to use to multithread the execution of the mesh build process. If null, the build will be single threaded.
Mesh(Span<byte>, BufferPool)
Loads a mesh from data stored in a byte buffer previously stored by the Serialize function.
public Mesh(Span<byte> data, BufferPool pool)
Parameters
Fields
Id
Type id of mesh shapes.
public const int Id = 8
Field Value
Tree
Acceleration structure of the mesh.
public Tree Tree
Field Value
Triangles
Buffer of triangles composing the mesh. Triangles will only collide with tests which see the triangle as wound clockwise in right handed coordinates or counterclockwise in left handed coordinates.
public Buffer<Triangle> Triangles
Field Value
- Buffer<Triangle>
Properties
ChildCount
Gets the number of children in the compound shape.
public readonly int ChildCount { get; }
Property Value
Scale
Gets or sets the scale of the mesh.
public Vector3 Scale { get; set; }
Property Value
TypeId
Unique type id for this shape type.
public static int TypeId { get; }
Property Value
Methods
ComputeBounds(Quaternion, out Vector3, out Vector3)
Computes the bounding box of a compound shape.
public readonly void ComputeBounds(Quaternion orientation, out Vector3 min, out Vector3 max)
Parameters
orientation
QuaternionOrientation of the compound.
min
Vector3Minimum of the compound's bounding box.
max
Vector3Maximum of the compound's bounding box.
ComputeClosedCenterOfMass()
Computes the center of mass of the mesh. Assumes the mesh is closed and should be treated as solid.
public readonly Vector3 ComputeClosedCenterOfMass()
Returns
- Vector3
Center of mass of the closed mesh.
ComputeClosedCenterOfMass(out float, out Vector3)
Computes the volume and center of mass of the mesh. Assumes the mesh is closed and should be treated as solid.
public readonly void ComputeClosedCenterOfMass(out float volume, out Vector3 center)
Parameters
ComputeClosedInertia(float)
Computes the inertia of the mesh. Assumes the mesh is closed and should be treated as solid.
public readonly BodyInertia ComputeClosedInertia(float mass)
Parameters
mass
floatMass to scale the inertia tensor with.
Returns
- BodyInertia
Inertia tensor of the closed mesh.
ComputeClosedInertia(float, out Vector3)
Computes the inertia of the mesh around its volumetric center and recenters the points of the mesh around it. Assumes the mesh is closed and should be treated as solid.
public BodyInertia ComputeClosedInertia(float mass, out Vector3 center)
Parameters
Returns
- BodyInertia
Inertia tensor of the closed mesh.
ComputeOpenCenterOfMass()
Computes the center of mass of the mesh. Assumes the mesh is open and should be treated as a triangle soup.
public readonly Vector3 ComputeOpenCenterOfMass()
Returns
- Vector3
Center of mass of the open mesh.
ComputeOpenInertia(float)
Computes the inertia of the mesh. Assumes the mesh is open and should be treated as a triangle soup.
public readonly BodyInertia ComputeOpenInertia(float mass)
Parameters
mass
floatMass to scale the inertia tensor with.
Returns
- BodyInertia
Inertia of the open mesh.
ComputeOpenInertia(float, out Vector3)
Computes the inertia of the mesh around its volumetric center and recenters the points of the mesh around it. Assumes the mesh is open and should be treated as a triangle soup.
public BodyInertia ComputeOpenInertia(float mass, out Vector3 center)
Parameters
Returns
- BodyInertia
Inertia tensor of the closed mesh.
CreateShapeBatch(BufferPool, int, Shapes)
Creates a shape batch for this type of shape.
public static ShapeBatch CreateShapeBatch(BufferPool pool, int initialCapacity, Shapes shapeBatches)
Parameters
pool
BufferPoolBuffer pool used to create the batch.
initialCapacity
intInitial capacity to allocate within the batch.
shapeBatches
ShapesThe set of shapes to contain this batch.
Returns
- ShapeBatch
Shape batch for the shape type.
Remarks
This is typically used internally to initialize new shape collections in response to shapes being added. It is not likely to be useful outside of the engine.
CreateWithSweepBuild(Buffer<Triangle>, Vector3, BufferPool)
Creates a mesh shape instance and builds an acceleration structure using a sweep builder.
public static Mesh CreateWithSweepBuild(Buffer<Triangle> triangles, Vector3 scale, BufferPool pool)
Parameters
triangles
Buffer<Triangle>Triangles to use in the mesh.
scale
Vector3Scale to apply to all vertices at runtime. Note that the scale is not baked into the triangles or acceleration structure; the same set of triangles and acceleration structure can be used across multiple Mesh instances with different scales.
pool
BufferPoolPool used to allocate acceleration structures.
Returns
- Mesh
Created mesh shape.
Remarks
The sweep builder is significantly slower than the binned builder, but can sometimes create higher quality trees.
Note that the binned builder can be tuned to create higher quality trees. That is usually a better choice than trying to use the sweep builder; this is here primarily for legacy reasons.
CreateWithoutTreeBuild(Buffer<Triangle>, Vector3, BufferPool)
Creates a mesh shape instance, but leaves the Tree in an unbuilt state. The tree must be built before the mesh can be used.
public static Mesh CreateWithoutTreeBuild(Buffer<Triangle> triangles, Vector3 scale, BufferPool pool)
Parameters
triangles
Buffer<Triangle>Triangles to use in the mesh.
scale
Vector3Scale to apply to all vertices at runtime. Note that the scale is not baked into the triangles or acceleration structure; the same set of triangles and acceleration structure can be used across multiple Mesh instances with different scales.
pool
BufferPoolPool used to allocate acceleration structures.
Returns
- Mesh
Created mesh shape.
Remarks
In some cases, the default binned build may not be the ideal builder. This function does everything needed to set up a tree without the expense of figuring out the details of the acceleration structure. The user can then run whatever build/refinement process is appropriate.
Dispose(BufferPool)
Returns the mesh's resources to a buffer pool.
public void Dispose(BufferPool bufferPool)
Parameters
bufferPool
BufferPoolPool to return the mesh's resources to.
FillSubtreesForTriangles(Span<Triangle>, Span<NodeChild>)
Fills a buffer of subtrees according to a buffer of triangles.
public static void FillSubtreesForTriangles(Span<Triangle> triangles, Span<NodeChild> subtrees)
Parameters
triangles
Span<Triangle>Triangles to build subtrees from.
subtrees
Span<NodeChild>Subtrees created for the triangles.
Remarks
The term "subtree" is used because the binned builder does not care whether the input came from leaf nodes or a refinement process's internal nodes.
FindLocalOverlaps<TOverlaps>(Vector3, Vector3, Vector3, float, BufferPool, Shapes, void*)
public readonly void FindLocalOverlaps<TOverlaps>(Vector3 min, Vector3 max, Vector3 sweep, float maximumT, BufferPool pool, Shapes shapes, void* overlaps) where TOverlaps : ICollisionTaskSubpairOverlaps
Parameters
Type Parameters
TOverlaps
FindLocalOverlaps<TOverlaps, TSubpairOverlaps>(ref Buffer<OverlapQueryForPair>, BufferPool, Shapes, ref TOverlaps)
public readonly void FindLocalOverlaps<TOverlaps, TSubpairOverlaps>(ref Buffer<OverlapQueryForPair> pairs, BufferPool pool, Shapes shapes, ref TOverlaps overlaps) where TOverlaps : struct, ICollisionTaskOverlaps<TSubpairOverlaps> where TSubpairOverlaps : struct, ICollisionTaskSubpairOverlaps
Parameters
pairs
Buffer<OverlapQueryForPair>pool
BufferPoolshapes
Shapesoverlaps
TOverlaps
Type Parameters
TOverlaps
TSubpairOverlaps
GetLocalChild(int, out Triangle)
Gets a child shape as it appears in the compound's local space.
public readonly void GetLocalChild(int triangleIndex, out Triangle target)
Parameters
GetLocalChild(int, ref TriangleWide)
Gets a child shape as it appears in the compound's local space.
public readonly void GetLocalChild(int triangleIndex, ref TriangleWide target)
Parameters
triangleIndex
inttarget
TriangleWide
GetPosedLocalChild(int, out Triangle, out RigidPose)
Gets a child shape from the compound and compounds a pose for it in the local space of the compound parent. Useful for processes which require a child shape (like a triangle in a mesh) to have their center of mass at zero in the child's own local space.
public readonly void GetPosedLocalChild(int triangleIndex, out Triangle target, out RigidPose childPose)
Parameters
triangleIndex
inttarget
TrianglechildPose
RigidPosePose in the compound's local space that brings the child shape as described to the proper location in the parent compound's local space.
GetSerializedByteCount()
Gets the number of bytes it would take to store the given mesh in a byte buffer.
public readonly int GetSerializedByteCount()
Returns
- int
Number of bytes it would take to store the mesh.
RayTest<TRayHitHandler>(in RigidPose, in RayData, ref float, ref TRayHitHandler)
Casts a ray against the mesh. Executes a callback for every test candidate and every hit.
public readonly void RayTest<TRayHitHandler>(in RigidPose pose, in RayData ray, ref float maximumT, ref TRayHitHandler hitHandler) where TRayHitHandler : struct, IShapeRayHitHandler
Parameters
pose
RigidPosePose of the mesh during the ray test.
ray
RayDataRay to test against the mesh.
maximumT
floatMaximum length of the ray in units of the ray direction length.
hitHandler
TRayHitHandlerCallback to execute for every hit.
Type Parameters
TRayHitHandler
Type of the callback to execute for every test candidate and hit.
RayTest<TRayHitHandler>(in RigidPose, ref RaySource, ref TRayHitHandler)
Casts a bunch of rays against the mesh at the same time, executing a callback for every test candidate and every hit.
public readonly void RayTest<TRayHitHandler>(in RigidPose pose, ref RaySource rays, ref TRayHitHandler hitHandler) where TRayHitHandler : struct, IShapeRayHitHandler
Parameters
pose
RigidPosePose of the mesh during the ray test.
rays
RaySourceSet of rays to cast against the mesh.
hitHandler
TRayHitHandlerCallbacks to execute.
Type Parameters
TRayHitHandler
Type of the callback to execute for every ray test candidate and every hit.
Recenter(Vector3)
Subtracts the newCenter from all points in the mesh hull.
public void Recenter(Vector3 newCenter)
Parameters
newCenter
Vector3New center that all points will be made relative to.
Serialize(Span<byte>)
Writes a mesh's data to a byte buffer.
public readonly void Serialize(Span<byte> data)