Importing GLB file - every material is single mesh

Hello,

I am trying to import GLB file into a scene (using THREE.GLTFLoader) and the issue I am facing with is the following:
The GLB file itself has a object with 4 different materials, and during the export I am getting 4 different meshes out of it. This makes things difficult because I want to have everything as a single mesh.

on the picture you may see the structure of GLB file in Blender.

GLTFLoader does not create multi-material meshes. In the screenshot above it will create four meshes as children of a single parent Group. You’ll need to either work with that Group instead, or merge them after loading using BufferGeometryUtils.

2 Likes

Thanks for your answer. I was able to merge all those different meshes into one with the following function:

function createMesh(insertedMeshes) {

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, true);
mergedGeometry.groupsNeedUpdate = true;

mergedMesh = new THREE.Mesh(mergedGeometry, materials);

return mergedMesh;

}

I hope it will help somebody.

Mirko

3 Likes

Hi @donmccurdy … Is it ok group multiple meshes to a group to reduce the draw calls?

If you mean putting multiple THREE.Mesh instances as children of a shared THREE.Group, then there’s nothing wrong with that but it will not reduce draw calls. One Mesh/Material pair is one draw call. InstancedMesh will help if you’re drawing many of the same Mesh/Material pair.

1 Like