UniversalCamera move with collisions drops frame rate from 120 to 30


sorry for a rather vague question and no PG to demonstrate but I am more looking for pointers in understanding what might be causing my problem.

I have a model of a room made in Blender and imported to BJS (via GLB and Draco compression). The room has a table in the middle and a few other bits with a combined stats of: 49,660 verts, 66,180 faces and 15 materials (hence submeshes). When I import the room I set checkCollisions=true (via newMeshes.forEach) and I have gravity enabled on the camera. Everything works fine but when I am moving with arrow keys the frame rate drops dramatically and climbs again to 120 after I stop moving.

So the question is should I be expecting this fps drop with this size model as the collision detection is colliding with verts (from what I understand). Or is there some setting I can adjust to maintain FPS.
Do I need to try ad structure it that I can isolate the floor, walls, doors and table and only collide with them (the model is not setup like this at present).

Other potentially relevant factors may be that I have 8 lights in the scene so have boosted max lights on materials. I have also tried with optimizer and freezing mesh transforms but have that all off at present as it was interfering with other things.

Hi Mark, the larger the object is, the more calculations will be required to check collisions against it.

If you separate the collided area (i assume a floor?) to a few meshes that intersect correctly (so it is invisible to the user), you won’t have such a performance hit. The collision system can’t pick the right position in the vertex data when it is checking for collision. If it finds that you are in the “area” (bounding box) of a specific mesh, it will check against its entire structure to see whether or not you are colliding against it. The less indices, the better :slight_smile:

Thanks for the reply. I thought it might be something like that. I am not sure I will be able to seprate the mesh out and create multiple intersecting meshes for floor and wall as you suggest. When I export from Blender (via GLB) meshes are created based on the material, ie one mesh for each material. So this would require multiple materials.

Based on your suggestion, I thought maybe if I have an invisible low poly mesh (with minimal verts) that I collide with rather than the actiual mesh (kind of like a physics impostor) then this might work. I have tried to setup a PG with this but haven’t got it working yet so this brings up another question.
My room is a circular room so I created a cyclinder with flipped normals but the collisions dont seem to work. If you are inside a mesh with inward facing normals are you able to collide with the mesh? It doesn’t lolok like it does. In the PG the camera starts in the cylinder and you can move until you are outside it but then cannot move back inside it. I thought collisions used normals but doesn’t seem to. (Or perhaps I need to create a model with flipped normals in Blender rather than doing it with a BJS primitive)
PG: Babylon.js Playground

OK, to answer my own question, yes, if you are inside a geometry with the normals flipped then the collisions work as expected and you are confined to the mesh.
In the PG I linked I was flipping the Vertex normals (thinking that that would flow through to the facet normals but it does not). I started looking at doing the same for the facet data but couldn’t see how to do the final update. Anyway, I went into my Blender model and created a cylinder with flipped normals (with the cylinder just inside the room walls and floor) and gave it a special material then exported it (via GLB+draco) and imported it to BJS, setting only meshes bound to that material as enable collisions. Result is that it works and the framerate stays close to 120. So all good :slight_smile:
All I have to do now is add some geometry to the cylinder collider to handle the table bbut that is simple.


Amazing solution! And sorry for a late reply, we were all very busy with the release.

I’m glad it works! And i can’t wait to see what you are building :slight_smile:

No problem, I thought you would all be busy with the release.

What I am building is for a company and so I can’t release it publicly yet but I would be happy to give you a link to a password protected test site if you were interested. The basic functionality is done I am now just fine tuning textures and visuals, fine tuning UI/UX, performance on different devices etc. This has been my first time using BJS so it has been a steep leaning curve but I am very pleased with BJS.

1 Like