MeshData.build constructor
MeshData.build({
- required Float32List positions,
- Float32List? normals,
- Float32List? texCoords,
- Float32List? colors,
- List<
int> ? indices, - PrimitiveType primitiveType = gpu.PrimitiveType.triangle,
- Map<
String, MeshAttributeData> customAttributes = const {},
Builds a snapshot from vertex attribute arrays, generating
area-weighted normals from the faces when normals is absent and
primitiveType is a triangle list. The normal generation is the work
worth doing off the render isolate. The attribute-array contract
matches MeshGeometry.fromArrays.
Implementation
factory MeshData.build({
required Float32List positions,
Float32List? normals,
Float32List? texCoords,
Float32List? colors,
List<int>? indices,
gpu.PrimitiveType primitiveType = gpu.PrimitiveType.triangle,
Map<String, MeshAttributeData> customAttributes = const {},
}) {
if (positions.length % 3 != 0) {
throw ArgumentError(
'positions has ${positions.length} floats; expected a multiple of '
'three (one vec3 per vertex)',
);
}
final vertexCount = positions.length ~/ 3;
final resolvedNormals =
normals ??
(vertexCount > 0 && primitiveType == gpu.PrimitiveType.triangle
? InterleavedLayoutAdapter.generateNormals(
positions: positions,
vertexCount: vertexCount,
indices: indices,
)
: null);
return MeshData(
positions: positions,
vertexCount: vertexCount,
normals: resolvedNormals,
texCoords: texCoords,
colors: colors,
indices: indices,
primitiveType: primitiveType,
customAttributes: customAttributes,
);
}