trianglesOf static method
The triangles of data in engine axes (+Y down), placed by its nodes
in its rest pose: of mesh mesh alone, or of every mesh when null.
Null when there are none.
Implementation
static ModelGeometry? trianglesOf(ModelData data, {int? mesh}) {
final positions = <double>[];
final indices = <int>[];
final point = Vector3.zero();
data.forEachNode((node, modelFromNode) {
final index = data.nodes[node].mesh;
if (index == null || index >= data.meshes.length) return;
if (mesh != null && index != mesh) return;
final m = gltfToEngine.multiplied(modelFromNode);
for (final p in data.meshes[index].primitives) {
final base = positions.length ~/ 3;
for (var v = 0; v < p.vertexCount; v++) {
final o = v * kVertexFloats;
point.setValues(p.vertices[o], p.vertices[o + 1], p.vertices[o + 2]);
m.transformPointInto(point, point);
positions.addAll([point.x, point.y, point.z]);
}
indices.addAll(p.indices.map((i) => i + base));
}
});
if (indices.isEmpty) return null;
return ModelGeometry(
Float32List.fromList(positions),
Uint32List.fromList(indices),
);
}