MeshGeometry.resetAttribs constructor

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

Implementation

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

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

      final VectorList<Vector> inputView =
          inputAttrib.getView(inputMesh.buffer);

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

  return mesh;
}