Class TriangleShape
Represents a triangle shape defined by a reference to a TriangleMesh and an index.
public class TriangleShape : RigidBodyShape, IDynamicTreeProxy, IPartitionedSetIndex, IUpdatableBoundingBox, ISupportFeature, ISupportMappable, IRayCastable, IAngularSweepTestable, ISweepTestable, IDistanceTestable, IDebugDrawable
- Inheritance
-
TriangleShape
- Implements
- Inherited Members
Constructors
TriangleShape(TriangleMesh, int)
Initializes a new instance of the TriangleShape class.
public TriangleShape(TriangleMesh mesh, int index)
Parameters
meshTriangleMeshThe triangle mesh to which this triangle belongs.
indexintThe index representing the position of the triangle within the mesh.
Exceptions
- ArgumentNullException
Thrown when
meshisnull.- ArgumentOutOfRangeException
Thrown when
indexis negative or greater than or equal to the number of triangles in the mesh.
Fields
Index
The index representing the position of the triangle within the mesh.
public readonly int Index
Field Value
Mesh
The triangle mesh to which this triangle belongs.
public readonly TriangleMesh Mesh
Field Value
Methods
CalculateBoundingBox(in JQuaternion, in JVector, out JBoundingBox)
public override void CalculateBoundingBox(in JQuaternion orientation, in JVector position, out JBoundingBox box)
Parameters
orientationJQuaternionpositionJVectorboxJBoundingBox
CalculateMassInertia(out JSymmetricMatrix, out JVector, out float)
public override void CalculateMassInertia(out JSymmetricMatrix inertia, out JVector com, out float mass)
Parameters
inertiaJSymmetricMatrixcomJVectormassfloat
Exceptions
- NotSupportedException
Always thrown because a triangle has no volume and therefore no mass properties.
CreateAllShapes(TriangleMesh)
Creates one shape for each triangle in the mesh.
public static IEnumerable<TriangleShape> CreateAllShapes(TriangleMesh mesh)
Parameters
meshTriangleMesh
Returns
DebugDrawLocal<TSink>(ref TSink, in DebugDrawSettings)
Draws the shape's surface as triangles in local coordinates.
protected override void DebugDrawLocal<TSink>(ref TSink triangleSink, in DebugDrawSettings settings) where TSink : ISink<JTriangle>
Parameters
triangleSinkTSinkThe destination for generated triangles.
settingsDebugDrawSettingsThe visualization settings.
Type Parameters
TSink
Remarks
Override to provide custom debug geometry; otherwise, the surface is approximated. Use outward-facing triangles for closed surfaces. Body and shape transforms are applied automatically.
GetCenter(out JVector)
Returns a point inside the shape. It does not need to be the center of mass.
public override void GetCenter(out JVector point)
Parameters
pointJVectorAn interior point in local space.
GetWorldVertices(out JVector, out JVector, out JVector)
Gets the vertices transformed by the attached rigid body. If the shape is unattached, returns the mesh vertices without a world transform.
public void GetWorldVertices(out JVector a, out JVector b, out JVector c)
Parameters
aJVectorThe transformed coordinate of the first vertex.
bJVectorThe transformed coordinate of the second vertex.
cJVectorThe transformed coordinate of the third vertex.
LocalRayCast(in JVector, in JVector, out JVector, out float)
Casts a ray against the shape in local coordinates, without applying the body's transform.
public override bool LocalRayCast(in JVector origin, in JVector direction, out JVector normal, out float lambda)
Parameters
originJVectorThe starting point of the ray.
directionJVectorThe direction of the ray. This vector does not need to be normalized.
normalJVectorThe surface normal at the point of intersection, if an intersection occurs.
lambdafloatThe ray parameter from the
originto the intersection point. Becausedirectionneed not be normalized, this is not necessarily a distance. The hit point is:origin + lambda * direction.
Returns
- bool
trueif the ray intersects with the object; otherwise,false.
Remarks
Back-facing triangles are culled.
SupportFeature(in JVector, float, Span<JVector>)
Writes the outermost feature of the shape in the given direction.
public override int SupportFeature(in JVector direction, float tolerance, Span<JVector> vertices)
Parameters
directionJVectorThe direction in local space. Does not need to be normalized.
tolerancefloatThe sine of the angle within which directions share the feature.
verticesSpan<JVector>Receives the vertices in local space: one for a point, two for a segment, three or more for a convex polygon in winding order. At least MaxVertices entries long.
Returns
- int
The number of vertices written, at least one.
Remarks
The default samples the support mapping with SupportFeatureSampler. Shapes that know their features analytically should override it.
SupportMap(in JVector, out JVector)
Computes the point on the shape that is furthest in the specified direction.
public override void SupportMap(in JVector direction, out JVector result)