Can GLTF export a specific mesh from scene?

Hi all
Currently we use the command
BABYLON.GLTF2Export.GLTFAsync(scene, “marbleTower”).then((gltf) => { gltf.downloadFiles();
to export a mesh assuming that it is the only mesh in the scene.

If I have many meshes in my scene, can I filter/choose which mesh to export?

Thanks

Yes

https://doc.babylonjs.com/extensions/gltfexporter#excluding-geometry

2 Likes

Thanks Delkatosh
In the PG referred, I added 2 gltf files.

https://www.babylonjs-playground.com/#YBEKDT#1

When exporting it also includes textures from the excluded mesh. Isn’t this unnecessary?

Also, in the options can I specify an array of meshes?
Finally, it seems OPTIONS is an exclusion, not an inclusion, ie: if I want to specify the gltf mesh to be exported doesn’t seem to work
let options = {
shouldExportNode: function(node) {
return node == fan;
}

Pinging @Drigax

Hey, just stumbled upon this asking the same question. My go to solution is to just parent everything you don’t want to a Node (mine is just called ‘exclude’), then just have return node !== exclude;

Hey @3D_Wave_Design, @Jacob

Yes, the IExportOptions | Babylon.js Documentation callback function should work for specifying which nodes in scene you want to export.

Regarding exporting materials not used by the exported objects, The playground you posted doesn’t appear to include those materials or their textures, either. Looking at the code it doesn’t seem apparent how this bug could happen, It definitely could have been fixed sometime along the way, however.

Feel free to update with a playground that does reproduce this, and I can take a closer look :slight_smile:.

Thanks!

Hey @Drigax, this is something i’ve seen too.
unused materials/textures are exported, but not loaded.

Pre-export scene contains
mesh - plane
mesh - sphere
mat - grass material
mat - sphere material
tex - grass.png

plane.material = null;

exported only plane to gltf, using exluded geometry option
scene.gltf contains info about both materials and the texture, also downloads the grass.png file together with the gltf & bin files.
scene.zip (736.8 KB)

Thanks for the info, I did manage to get a repro even when using a more strict export node predicate:

https://www.babylonjs-playground.com/#YBEKDT#4

Definitely looks like we’re still exporting the materials somehow. I’ll take a closer look.

glTF2Exporter includes materials used by excluded meshes. · Issue #10009 · BabylonJS/Babylon.js · GitHub (wow! 10k!)

1 Like

I’m curious to see what the issue is. If I export a glb following the documentation I have the same material issues, whereas exporting from the Sandbox doesn’t seem to do that. Thanks for tackling this @Drigax

I would like to dig into this issue a bit and see if I can contribute. This would be my first issue and welcome any suggestions :slight_smile:

1 Like

That would be awesome !!!

1 Like