Blender exporter: select order of mesh export

I’ve been looking at the documentation on the exporter to Blender (the images appear to be behind the current release so maybe the documentation is a bit behind also), and I cannot discern how (or even if) it is possible to select the order that the meshes are exported in.

Currently I have a blender file with 6 mesh objects, one of which is the parent to the other five. Based on the hierarchy, I would have thought that the order of export would be the parent first (so when I do LoadAssetContainerAsync the resulting meshes property has the parent at index 0). But that is not the case.

So is there a way to reorder how the meshes export from the collection in Blender so that on load they are in a specific order?

Pinging @JCPalmer who wrote the exporter.

However, I would be surprised if the order could be set at export time as it should not matter what is the order of your meshes in the file: why would you need a specific order? Also, even if an order could be defined, the loader does not ensure that the order of the meshes in the returned mesh array will be the same than in the file. It’s currently the case but a future implementation could do things differently (granted, chances are low that this will change, but we still don’t guarantee that the order of meshes is preserved at loading time).

They are in whatever order Blender gives them. I think that is determined by the order they were created. Just use either scene.getMeshById or scene.getMeshByName. This means you will have to know something about what is being loaded.

I will not be adding any depth first or breadth first sorting of meshes to the exporter.

Is the parent rleation broke when loading is done?

@Vinc3r No, the parent relation stays in place (which is what I want).

@JCPalmer and @Evgeni_Popov, thanks for the feedback. As to “why” I wanted to do this, my asset container holds the 6 objects in it, through which I want to loop through each mesh and set some initialization to them (textures, state property, etc.). The parent element of the group needs some slightly different settings, so my plan was to have the parent be index 0 and apply its settings, then loop through the rest.

Admittedly, I’m new to learning Babylonjs (and fairly new to JavaScript, though feel like I have a reasonable grasp of it). But I’ve been finding myself a little “lost” in trying to figure out the node relationships/structures of what I have to locate the meshes properly. I bring in my asset container and then instantiate them similar to PirateJC’s hex tiling demonstration here, so I am making multiple instances of the asset, only in my version, the group brought in are actually differing objects that need to be related in a parent/child relation (I believe in his, the various meshes are all part of one “hex” object, so to speak). Even what would seem to be a simple getMeshById or Name becomes complicated in that through the instantiating, a number of Clone of... names and id’s get set, so it is challenging to locate by that.

It appears my asset container that is loaded has a “meshes” property that directly accesses the meshes, but when I set the “state” property on those, the settings did not persist in a way that was locatable by pickResult.pickedMesh.state on a pointerDown event. In looking at a console.log of my mesh, the “state” property I ended up setting doing it that way is buried deeper in submeshes it seems with the instantiation. So instead of accessing the “meshes” property of the asset, it seemed I might have success getting the “state” set where I wanted it on each object by going through the rootNodes[0] of my loaded asset (which I thought and/or wanted to be the parent) and then also looping through children.

Any further advice on understanding the structure of what I’m receiving in the asset load, and how to best access the meshes on instantiation to set properties, would be appreciated. In the demo for the createHexGrid and onPointerDown function, he uses various .parent, .getDescendants(), .rootNodes[0], .getChildMeshes(), so I’m trying to get a handle on my own stuff to figure out (or set) my structure so I know where to set/get the information I need.

I think it could help if you can reproduce this in a playground :slight_smile:

The best thing to do here is to look what’s going on thanks to the inspector I think.

1 Like

I had mentioned I was new to Babylonjs, right? Duh! I didn’t even know about the possibility of a local inspector (I knew the playground had it)! Just got it up and running, and way better than trying to track things down in a console.log. Thanks for that small bit of “further advice”; that should help tremendously!