Why doesn't GLTFExporter support ShaderMaterials?

Hello everyone,

I’m trying to export GLTF files in three.js, but all my meshes are using ShaderMateraials and GLTFExporter doesn’t support them.

I would like to know the reasons why this specific material is not supported in order to find an alternative to my problem.

If I can’t fix it via WebGL (Three.js) I was wondering if I could do the exportation using OpenGL, does that make sense? Do you think It may be possible?

Thanks!
J.

glTF has a material specification whereas ShaderMaterials represent custom and thus arbitrary shader code. This code can’t be just exported to glTF and no other 3D standard.

No. three.js is a WebGL engine. OpenGL is totally unrelated.

Hi Mugen, thanks for your answer!

So, what alternative do you recommend to export a scene with ShaderMaterials in gltf file? Or can not be done in any way?

The only way to retain shader materials is the usage of the three.js JSON format. You can produce this format by using calling scene.toJSON();. The resulting JSON can be loaded via ObjectLoader.

Hi,

Thanks! Seems that the JSON file is exporting well, but when I try to load the resulting JSON, I have the following error:

THREE.ObjectLoader: You have to import LegacyJSONLoader in order load geometry data of type “Geometry”.

I saw that LegacyJSONLoader is now removed, what can I do?

The idea is to use BufferGeometry.

Hi Mugen,
The exportation with JSON seems to work fine for me, but it is huge in size in my model. There’s a way to export the ShaderMaterial (vertex+fragment) and the OBJ Model and then load this data?

Thank you!