Using Complex Models

Good afternoon. Help me please. Previously, I used simple models, but now it became necessary to switch to complex ones and several problems immediately appeared.
I am attaching a link to the playground, I specially added a loader from my project (that is, how I worked with simple models) for clarity. Lines 86-124. I didn’t adjust it for the playground - it’s just to understand what the problem is.
Now about problems. Previously, after loading the model, I hid it and created instances from it, which I then put into the corresponding “Instances” object, and then I could already refer to any instance by unid or name, depending on the situation.
That is, instance[unid].dispose()
navigation - this.agents.push({ idx: agentIndex, trf: transform, mesh: instance[unid], target: target }) gave me the same instance that matched some instanse[unid].name
This all worked conveniently for me, but now I tried to adjust the complex loading through the container for the same needs, and I sketched it on the playground, and I want to ask your opinion, am I doing it right?
Also, how can we now use event.pickInfo.pickedMesh to get the corresponding instanse[unid]? I found only the ability to add parent.parent … parent, but if there is a model with less nesting, it will have to be bypassed through conditions - this is very inconvenient, maybe there is something better?

Sorry, but it’s hard to understand exactly what you need from your explanation. It feels like you’re asking a few different things here about model loading and about instances. About model loading, there really isn’t one single “correct” way of doing things. It all depends on your application.

About picking with instances, if you’re using regular Instances (not ThinInstances), pickedMesh will be the corresponding instanced mesh, not the “base mesh”: Pick instances | Babylon.js Playground (

@Lazarus_Rainhard , complementing what @carolhmj said, if your problem is that you don’t want to have to search all the way up in the hierarchy when handling the event from pickedMesh (since you don’t want to make your code dependent on the hierarchy depth). One thing you can try is to add an invisible box at the top level of your object hierarchy that surrounds all child meshes, this way the picked event will bring that box as the pickInfo.pickedMesh and you will be able to control where in the hierarchy that is relative to the nodes you care about.

The thing is, I’m already working with simple models and instances, and I just need to replace simple models with complex ones, and here comes the snag. I can’t use createInstance, and as a result, since I’m working with instances, I have to rebuild the code :slight_smile:
I’m generally interested in whether I’m following the path correctly, so I attached part of the old code and an example of using the same needs with a complex model. But I would like advice if I’m doing something wrong from what I attached on the site :slight_smile:
In particular, I managed to overcome almost everything from my list (but I’m not sure that I found all the pitfalls).
The obvious problem I’m having right now is that my models are facing backwards and lookAt turns them back to the target and navigationMesh moves them backwards.
At the same time, there is no such problem on the playground, I don’t understand why.
There is also a problem with HighlightLayer - I didn’t understand how to make it work, although everything worked on the instance, but I will deal with it later, so I have not attached the code yet.
You may have to abandon complex models, and apply textures as a whole, and then attach animations separately to instances, although I haven’t thought about how yet :frowning:

Thank you, I already looked at the option with a cycle, I don’t know why I didn’t think of it right away :slight_smile:
var mesh
if (pickResult.hit) {
mesh = pickResult.pickedMesh;
while (mesh.parent !== null) {
mesh = mesh.parent;
But the box is still interesting to me, can you tell me how?

It’s very funny, but I realized that my complex models are turned back, unlike simple models, that’s why they move back and forth in my project :))) But then I don’t understand why they are displayed correctly on the playground (automatically unfolding on 180 degrees)… but in my project they don’t unfold in the same way

I want to share that I found a solution to the backlight problem. The forum previously answered how to deal with a complex model, but the topic is incorrectly named, so it’s hard to find: Hightlayer issues

It would be nice if someone adds examples to the documentation (here Highlighting Meshes | Babylon.js Documentation ) on how to deal with highlighting in complex models (and instances at the same time):
Complex model: Babylon.js Playground (from this thread: Hightlayer issues)
Instaces: (from this thread: Why can't I add an InstancedMesh to HighlightLayer - #7 by kekeqy)

1 Like

Our documentation is open source, so that someone can be you! :smiley:

1 Like