Mesh colliders in code

After perfecting (I thought) my script that decomposes an imported model into it’s meshInstances and creates new entities with those meshes – I have imported a model and tried the code on it. Really everything works as expected, except the mesh colliders. I’m almost sure it has something to do with scale. Run the project, open the console and click on different countries. The raycast routines runs on each click, but never returns a result.

In the code, I set the model’s scale to [ 0.01, 0.01, 0.01, ]. Otherwise the model is unnecessarily huge. Interestingly, if you don’t do this, the model does not assemble itself correctly, not at all. Try commenting that line out. To make the model work at that scale, multiply the position vector by 100 a few lines down from there. You will be inside the globe when it finishes loading and initializing. But the meshes still don’t respond to raycasting.

The model is a globe with individual meshes for each country. Each country has two meshes, a country shape and then a beveled cap. You will see that I’m using a collisionMode variable to control which meshes get the colliders (only the cap or only the shape or both). No configuration that I’ve tried has worked.

https://playcanvas.com/editor/project/771851

This is coming out next week hopefully

When you use instantiateRenderComponent function on loaded glb container, it would return you an entity hierarchy with meshes attached to entities … something similar to what you’ve just finished it seems.

But colliders are still on the list to do for this … so that won’t help you.

1 Like

Glad to know that it’s in the works! I think it could be something in that .FBX to .glb conversion.

1 Like

There you go: https://playcanvas.com/project/771884/overview/testcolliders
I had to use a private API. Main changes:

1 Like

That’s it! It works perfectly now. But, a private API? I can’t see where you linked any additional code in to your project. Or you mean, an undocumented function in the code?

Yes, correct. I mean the .recreatePhysicalShapes() method, which is not public. Using private API is discouraged, as it may change any time without notice. But it is ok, if you know what you are doing :wink: