Some issues when export a single MESH with multiple materials using gltf-exporter

When import a glb model which is single Mesh with multiple materials. And I export this Mesh using gltf-exporter.Then I find the gltf-exporter replaced multiple materials(material array) with single material. There is same problem when I process in THREE.EDITOR.How can I fix it.

GLTFLoader does not produce 3D objects with multi-materials so I wonder how you setup the initial mesh in the editor. Do you mind sharing the glb that you import in the editor.

Sorry I made a mistake , the initial mesh is obj instead of glb, so it shows multi-materials. This means that if I wonder import 3D objects with multi-materials, it’s best not to import glb or gltf because GLTFLoader does not produce 3D objects with multi-materials.And I found ‘OBJLoader’ is support multi-materials.What I want to ask is that the official will support GLTFLoader to import 3D objects with multi-materials in the future?

1 Like

Exporting a multi-material mesh with GLTFExporter and then importing it with GLTFLoader should produce a scene with the same appearance, but — as you mention – the multi-material mesh will be split into one part per material.

We have no plans to change that behavior, sorry. It was supported at one point in the past, but was overly complex to maintain and had to be removed.

Okay, thank you very much for your reply

Hi @donmccurdy
As you said the multi-material was supported as one point.
Can you tell me the Three.js version where it was supported or provide that GLTFExporter file?

There is no exact concept of “multi-material meshes” in glTF, but GLTFExporter writes three.js multi-material meshes as a glTF mesh containing multiple primitives, and still does this in the latest release.

In the past GLTFLoader had the ability to do the inverse — loading a glTF mesh containing multiple primitives into a multi-material mesh in three.js. That behavior was removed in r103:

Assuming that we exported the gltf file with the multi-material support.
Do we need to make changes in the GLTFLoader too?

GLTFLoader will never create a “multi-material mesh” in current three.js versions (after r103+). It will load the model fine, but each material vertex group will be assigned to a different mesh. If you need the loader to create a multi-material mesh, then you would need to use the older copy of GLTFLoader — and update it as needed for newer three.js versions. That’s an advanced topic.

Personally, I do not recommend using multi-material meshes in three.js at all, use separate meshes instead.

Can you tell me how to break a single mesh into the multiple meshes depending upon the Groups property of a Geometry which is part of the mesh?

Each “group” represents a range in the geometry.attributes (or geometry.index if present) to be drawn. You’d need to slice out that range into a separate geometry. I don’t know of any example code showing how to do this, at the moment.

Has someone implemented an exporter that exports meshes split by their different materials? I’m currently trying to edit the GLTFExporter but i’m a bit stuck in doing so. Any hints are greatly appreciated:)