# Merging BufferGeometry Objects

**URL:** <https://discourse.threejs.org/t/merging-buffergeometry-objects/16272>\
**Category:** Questions\
**Tags:** geometry\
**Created:** [June 16, 2020, 11:09am UTC](https://discourse.threejs.org/t/merging-buffergeometry-objects/16272 "2020-06-16T11:09:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mirko.simanic](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@mirko.simanic](https://discourse.threejs.org/u/mirko.simanic)\
**Post date:** [June 16, 2020, 11:09am UTC](https://discourse.threejs.org/t/merging-buffergeometry-objects/16272/1 "2020-06-16T11:09:06Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [June 16, 2020, 12:59pm UTC](https://discourse.threejs.org/t/merging-buffergeometry-objects/16272/2 "2020-06-16T12:59:19Z")

</div>

It seems you want to use multiple materials with your merged geometry. In this case you have to set the second parameter of [BufferGeometryUtils.mergeBufferGeometries()](https://threejs.org/docs/index.html#examples/en/utils/BufferGeometryUtils.mergeBufferGeometries) to `true` otherwise group data are not added.

Besides, `MeshFaceMaterial` is deprecated. It’s sufficient to just assign the array of materials to the mesh. Moreover, when working with `BufferGeometry` calling `computeFaceNormals()` has no effect (since `BufferGeometry` only works with vertex data).

---

<div class="post-metadata">

**Author:** ![mirko.simanic](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@mirko.simanic](https://discourse.threejs.org/u/mirko.simanic)\
**Post date:** [June 16, 2020, 1:37pm UTC](https://discourse.threejs.org/t/merging-buffergeometry-objects/16272/3 "2020-06-16T13:37:31Z")

</div>

Thank you!!  
With this change, I was able to insert GLB file without problems.

Mirko
