toPrimitive method

PrimitiveData toPrimitive({
  1. int? material = 0,
})

As the renderer takes it: interleaved vertices (kVertexFloats each: no tangents — the shader derives them — and white vertex colour).

Implementation

PrimitiveData toPrimitive({int? material = 0}) {
  final count = vertexCount;
  final v = Float32List(count * kVertexFloats);
  for (var i = 0; i < count; i++) {
    final o = i * kVertexFloats;
    v[o] = positions[i * 3];
    v[o + 1] = positions[i * 3 + 1];
    v[o + 2] = positions[i * 3 + 2];
    v[o + 3] = normals[i * 3];
    v[o + 4] = normals[i * 3 + 1];
    v[o + 5] = normals[i * 3 + 2];
    v[o + 10] = uvs[i * 2];
    v[o + 11] = uvs[i * 2 + 1];
    v[o + 12] = 1;
    v[o + 13] = 1;
    v[o + 14] = 1;
    v[o + 15] = 1;
  }
  return PrimitiveData(
    vertices: v,
    indices: indices,
    material: material,
    bounds: bounds,
    hasTangents: false,
  );
}