Gltf loader - export blender scene

Hi everyone,

Is there a work around/script to import gltf file into the threeJS scene showing not just a flat list of meshes but preserving the blender scene hierarchy with all the collections etc.

I looked around and couldn’t find any easy way.

I’m using the default Glb/gltf exporter in blender

Thank you

Blender does export to glTF including the scene hierarchy. I’m not sure what it does with collections — that concept does not exist outside of Blender. Perhaps it creates additional scenes, or additional groups within a scene, for each collection?

When loading the glTF file with GLTFLoader, you’ll get that same scene, or list of scenes if there’s more than one… so the hierarchy is kept, possibly with some additional parent objects for orientation etc. If this isn’t working as you expect, it may help to share a .blend. If you open the JS console on https://gltf-viewer.donmccurdy.com/ you can see the printed scene graph created from the glTF file:

Thanks for your reply,

So I uploaded the glb file into your gltf Viewer and I don’t get the scene hierarchy as in Blender (refer to the picture below in Blender).

I would expect to have blender collections as “groups” as parent of any children “meshes” and “groups”

Any work around that ? Am I doing anything wrong ?

“Collections” are a Blender-specific concept, not the same as objects in the scene graph. I don’t know what Blender’s exporters do with them, but apparently they aren’t converted to nodes based on your results. I think if you replace them with Empties they’ll come through in the scene hierarchy.

Empty (3d objects) in blender would do the trick

Thank you!

i just wanted to chime in to confirm that blender will not export collections. blender also (sometimes?) does not export empties that do not have children.

building the scene with empties as parents indeed is the correct solution.