MeshData class Geometry
An isolate-transferable snapshot of a mesh's vertex and index data.
MeshData separates the CPU work of building a mesh (assembling vertex
arrays and generating normals) from the GPU upload. Its construction is
pure and touches no GPU resources, so it can run on a background
isolate; the result is sent back and turned into a live mesh on the
render isolate. This keeps heavy meshing, such as remeshing a voxel
chunk, off the render isolate.
It is also the interchange type for reading geometry back and deriving
new geometry from it: Geometry.extractMeshData produces one from a
loaded mesh, and the pure derivation methods (unweld, extractEdges,
merge) consume and produce them, so a whole derivation chain can run
off the render isolate.
Recipe (using compute from package:flutter/foundation.dart):
// Top-level or static, runs on the background isolate.
MeshData buildChunk(ChunkInput input) {
final positions = ...; // your generator
final indices = ...;
return MeshData.build(positions: positions, indices: indices);
}
// On the render isolate:
final data = await compute(buildChunk, input);
final geometry = MeshGeometry.fromMeshData(data);
// or, to update an existing updatable mesh in place:
existing.applyMeshData(data);
Constructors
-
MeshData({required Float32List positions, required int vertexCount, Float32List? normals, Float32List? texCoords, Float32List? colors, List<
int> ? indices, PrimitiveType primitiveType = gpu.PrimitiveType.triangle, Map<String, MeshAttributeData> customAttributes = const {}}) - Wraps already-prepared vertex arrays without generating anything.
-
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
normalsis absent andprimitiveTypeis a triangle list. The normal generation is the work worth doing off the render isolate. The attribute-array contract matches MeshGeometry.fromArrays.factory
Properties
- colors → Float32List?
-
Vertex colors (four floats each), or null to default to opaque white.
final
-
customAttributes
→ Map<
String, MeshAttributeData> -
Named custom per-vertex attribute streams, forwarded to
Geometry.setCustomAttributeon upload.final - hashCode → int
-
The hash code for this object.
no setterinherited
-
indices
→ List<
int> ? -
Triangle (or line/point) indices, or null for a non-indexed mesh.
final
- normals → Float32List?
-
Vertex normals (three floats each), or null to let the upload
generate or default them.
final
- positions → Float32List
-
Vertex positions, three floats each.
final
- primitiveType → PrimitiveType
-
How the vertices assemble into primitives when drawn.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- texCoords → Float32List?
-
Texture coordinates (two floats each), or null to default to
(0, 0).final - triangleCount → int
-
The number of triangles (indexed or not). Zero for non-triangle
primitive types.
no setter
-
triangles
→ Iterable<
MeshTriangle> -
Iterates the mesh's triangles with their corner indices and positions.
no setter
- vertexCount → int
-
The number of vertices, equal to
positions.length ~/ 3.final
Methods
-
extractEdges(
{double? creaseAngleDegrees}) → LineSegmentData - The mesh's unique undirected edges as disconnected line segments.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
unweld(
{Set< UnweldAttribute> attributes = const {}}) → MeshData - A flat-shaded triangle soup derived from this mesh.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited