TriangleMesh
CPU triangle BVH for local ray/segment queries.
TriangleMesh is an owned RefCounted intersection structure rather than a drawable ArrayMesh or physics body. CreateFromFaces takes a flat Vector3 array in triples rather than an index buffer. It builds a BVH snapshot: editing the source mesh/array does not update it automatically. Dispose an owned instance after use.
Build positions are snapped with snappedf(0.0001) and welded by snapped coordinates. GetFaces need not preserve input floats bit-for-bit. Account for units/scale: this is not exact arbitrary-scale microgeometry intersection.
IntersectRay takes origin plus a nonzero direction; IntersectSegment takes origin plus endpoint. Use BVH coordinates for all inputs: MeshInstance3D transforms are not applied automatically. Both return an owned Dictionary. Empty means miss or an unbuilt BVH. Hits contain position (Vector3), normal (Vector3), and face_index (int). The normal is oriented against the query rather than necessarily matching source winding. Read keys after checking Count and dispose the dictionary.
Returns the nearest accepted intersection rather than every hit, collider, UV or scene-surface list. face_index identifies a triple in the current faces input rather than an Entity/material ID. Equal-distance ties, degenerate triangles and extreme-scale accuracy were not accepted by this review.
The combined 34 headless checks covered a new empty object, building, nearest ray/segment hits, opposed normals, GetFaces copies, span rebuild and snapping. This is CPU evidence; graphics and physics-world execution were not tested.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
TriangleMeshConstructor
public TriangleMesh();Creates an owned RefCounted without a valid BVH. GetFaces/queries return empty before building.
Methods5
CreateFromFaces2 overloads
public bool CreateFromFaces(Vector3[] faces);Replaces BVH from nonempty flat Vector3 triples. Positions snap to a 0.0001 grid and equal snapped coordinates are welded. Invalid lengths are diagnosed after valid is reset; do not assume the old valid BVH survives. Array/span overloads share semantics.
| Name | Type | Default |
|---|---|---|
faces | Vector3[] | — |
facesNonempty finite Vector3 array with length divisible by 3; every triple is a triangle, not an index list.
booltrue for a valid built BVH; false does not guarantee preservation of the previous structure.
public bool CreateFromFaces(ReadOnlySpan<Vector3> faces);Replaces BVH from nonempty flat Vector3 triples. Positions snap to a 0.0001 grid and equal snapped coordinates are welded. Invalid lengths are diagnosed after valid is reset; do not assume the old valid BVH survives. Array/span overloads share semantics.
| Name | Type | Default |
|---|---|---|
faces | ReadOnlySpan<Vector3> | — |
facesNonempty finite Vector3 array with length divisible by 3; every triple is a triangle, not an index list.
booltrue for a valid built BVH; false does not guarantee preservation of the previous structure.
GetFacesVector3[]
public Vector3[] GetFaces();Returns a managed copy of current BVH triangle corners in triples. Coordinates are already snapped; editing the result does not mutate BVH. Empty without a valid structure.
Vector3[]New Vector3[] of corner triples, or empty.
IntersectRayReckfell.Collections.Dictionary
public Reckfell.Collections.Dictionary IntersectRay(Vector3 begin, Vector3 dir);Finds the nearest accepted forward hit from begin along nonzero dir. An infinite ray rather than segment begin→dir. Hit normal opposes the query. Uses local snapshot coordinates without physics layers or automatic Transform3D.
| Name | Type | Default |
|---|---|---|
begin | Vector3 | — |
dir | Vector3 | — |
beginQuery origin in BVH coordinates.
dirNonzero ray direction, normally normalized, rather than an endpoint.
Reckfell.Collections.DictionaryOwned Dictionary: position, normal, face_index on hit, otherwise empty. Dispose after use.
IntersectSegmentReckfell.Collections.Dictionary
public Reckfell.Collections.Dictionary IntersectSegment(Vector3 begin, Vector3 end);Finds the nearest accepted hit on finite begin→end. Returns one hit with its normal facing against travel. Not a full-body containment/overlap query.
| Name | Type | Default |
|---|---|---|
begin | Vector3 | — |
end | Vector3 | — |
beginQuery origin in BVH coordinates.
endSegment endpoint in BVH coordinates rather than a direction.
Reckfell.Collections.DictionaryOwned Dictionary: position, normal, face_index on hit, otherwise empty. Dispose after use.