MeshGeometry.resetAttribs constructor Null safety

MeshGeometry.resetAttribs(
  1. MeshGeometry inputMesh,
  2. List<VertexAttrib> attributes
)

Implementation

factory MeshGeometry.resetAttribs(
    MeshGeometry inputMesh, List<VertexAttrib> attributes) {
  final mesh = MeshGeometry(inputMesh.length, attributes)
    ..indices = inputMesh.indices;

  // Copy over the attributes that were specified
  for (var attrib in mesh.attribs) {
    final inputAttrib = inputMesh.getAttrib(attrib.name);
    if (inputAttrib != null) {
      if (inputAttrib.size != attrib.size ||
          inputAttrib.type != attrib.type) {
        throw Exception(
            'Attributes size or type is mismatched: ${attrib.name}');
      }

      final inputView = inputAttrib.getView(inputMesh.buffer);

      // Copy [inputView] to a view from attrib
      attrib.getView(mesh.buffer).copy(inputView);
    }
  }

  return mesh;
}