toTriMeshShape method

TriMeshShape toTriMeshShape()

A collision triangle mesh over this mesh's triangles.

The shape holds its own copy of the positions and indices, so the snapshot can be discarded afterwards. Triangle meshes are hollow and carry no volume, so they collide as static environment geometry; use toConvexHullShape for a dynamic body.

Throws a StateError when this snapshot is not a triangle list or has no triangles.

Implementation

TriMeshShape toTriMeshShape() {
  _requireTriangles('toTriMeshShape');
  final count = triangleCount;
  if (count == 0) {
    throw StateError('toTriMeshShape requires at least one triangle');
  }
  final outIndices = Uint32List(count * 3);
  for (var corner = 0; corner < outIndices.length; corner++) {
    outIndices[corner] = _cornerIndex(corner);
  }
  return TriMeshShape(
    vertices: Float32List.fromList(positions),
    indices: outIndices,
  );
}