The materialindex for every face of a model exported from Blender using the GLTF exporter is returning 0 for me. Is that correct? The model is using 6 different materials.
Asked
Active
Viewed 134 times
0
-
Your model probably has six meshes with different materials for each now. I would not expect specific materials on specific faces — as Blender stores them — to remain represented that way in realtime engines. – Don McCurdy Jan 28 '19 at 06:27
-
I added a pic to the post to show exactly how the model is structured. – M1ke Jan 28 '19 at 17:56
-
1Ok yeah, I expect that will become 6 meshes (one for each material) in three.js. – Don McCurdy Jan 28 '19 at 21:01
-
Interesting, thanks! Is there a way to not have it as 6 different materials but only one mesh in ThreeJS using the GLTF exporter? – M1ke Jan 28 '19 at 21:09
-
You could merge them after export using [`BufferGeometryUtils.mergeBufferGeometries()`](https://threejs.org/docs/#examples/utils/BufferGeometryUtils.mergeBufferGeometries) and the "useGroups" option. But note that with six materials, there's no performance benefit to merging them – it's six draw calls either way. Best to use vertex colors and a single material if you want a single mesh exported. – Don McCurdy Jan 28 '19 at 21:24
-
The reason I'd like to access the materialindex is for when a raycaster ray hits a face, it'd be more efficient for me to know the material of that face. – M1ke Jan 28 '19 at 23:36
-
1You'll know this way because it will return a different mesh, with a different material. ;) But regardless, Blender's representation does not export through to three.js. – Don McCurdy Jan 29 '19 at 05:36