I have couple of meshes inside one array object.
What I am trying to do it to merge all of them to one merge with the following code:
(all mesh objects are in ‘insertedMeshes’ array)
var materials = [],
geometries = [],
mergedGeometry = new THREE.BufferGeometry(),
meshMaterial,
mergedMesh;
insertedMeshes.forEach(function(mesh, index) {
mesh.updateMatrix();
geometries.push(mesh.geometry);
meshMaterial = new THREE.MeshStandardMaterial(mesh.material);
materials.push(meshMaterial);
});
mergedGeometry = THREE.BufferGeometryUtils.mergeBufferGeometries(geometries, false);
mergedGeometry.groupsNeedUpdate = true;
mergeMaterial = new THREE.MeshFaceMaterial(materials);
mergedMesh = new THREE.Mesh(mergedGeometry, materials);
mergedMesh.geometry.computeFaceNormals();
mergedMesh.geometry.computeVertexNormals();
mergedMesh.updateMatrixWorld();
console.log(mergedMesh);
scene.add(mergedMesh);
render();
When I try to add any of the objects from insertedMeshes array to the scene it works
but mergedMesh is never added to the scene (although I see mesh in console.log).
Many thanks for your help!