function meshFromShapeModel( model ) {
const geometries = {};
model.shapes.forEach( (shape) => {
const geometry = new THREE.Geometry();
geometry.vertices = shape.vertices.map(
({x, y, z}) => new THREE.Vector3(x, y, z));
geometry.faces = shape.faces.map(
({vertices: [a, b, c]}) => new THREE.Face3(a, b, c));
geometry.computeFaceNormals();
geometries[ shape.id ] = geometry;
} );
const group = new THREE.Object3D()
model.instances.forEach( (instance) => {
const material = new THREE.MeshLambertMaterial({ color: instance.color });
const geometry = geometries[ instance.shape ];
if ( geometry ) {
const mesh = new THREE.Mesh( geometry, material );
mesh.position .set( ...Object.values( instance.position ) )
if ( instance.rotation )
mesh.quaternion .set( ...Object.values( instance.rotation ) )
group.add( mesh );
}
});
return group
}