physics meshes not working accurately!?

Hello,

I am using Cesium for Unity to reconstruct 3D buildings and then shoot some rays from the camera to check which buildings are visible from that location and which are occluded.
I am benefitting from Physics Meshes of the Cesium OSM Buildings to detect ray hits with the mesh and thus mark that building as visible.

However, I have found out that despite having occluding buildings, some rays are passing through the buildings and continue to hit some other buildings at very far, while they are completely occluded by other buildings. In other words, the meshes seem not to work acccurately in cases.

In the image below, you can see the view of the Dynamic Camera which show a few visible buildings in the user sight. But considering the Debug Scene Camera, you can see that some rays are wrongly passing through and hit some buildings at the very far (marked with red points).

Also, on the map below, I have circled around the occluded buildings that no ray should hit them in theory! (camera is the green triangle)

Is there any fix for this issue that rays are wrongly pass through buildings?
I really need to detect the hits of rays with accurate meshes (or bbox) of the buildings.
Please Let me know if there is any way I can improve it.
Thank you.

Hi @alireza.MBTM, welcome to the community!

I don’t know what would cause that. Am I understanding correctly that for certain buildings, rays sometimes (but not always) hit them?

One tricky thing about Cesium OSM Buildings is that it uses something called “additive refinement”. In practice, that means, that large buildings tend to be part of tiles that cover a large spatial area, and thus have large coordinate values. It’s possible that we’re hitting a limitation in Unity’s physics engine, which isn’t usually asked to deal with planet-size coordinates.

That’s just a guess, though. Can you provide a scene file that allows us to easily reproduce the problem you’re seeing? If so, we can debug.

Hi @Kevin_Ring

Thank you for your message and your information.

Actually, I found out that it happens for various buildings at some points of their mesh. It seemed to me that they are usually better at the center of their walls, but it became worse as we move to the edges and the rays pass through!

I am unfortunately unable to share the scene with the scripts, but I have found out about Maxium Screen Space Error under the Level of Detail in the Cesium OSM Buidling gameobject. It seems that the meshes are loaded more accurately if we decrease this value to 1. Does that match with technical implementation and is it what you may expect too?
With setting this parameter to 1, I have saw a good improvement and instead of 10 out of 49 rays, I have now 1 or 2 rays that are incorrectly passing through the buildings.

Also, reducing the Culled Screen Space Error and checking Generate Smooth Normals seems to help with negligible effect.

I wonder if you can think of any more improvement that may help accurate matching of meshes with their corresponding building geometry, or if there are always some errors in the mesh creating accuracy?

Thank you so much.

I don’t know, it’s not clear to me why reducing Maximum Screen Space Error, or any of those other properties, would help at all. Assuming, of course, that the tiles you’re trying to collide with are actually being loaded. Keep in mind that smaller buildings won’t load unless your Camera.Main is observing them from a close enough distance and with a high enough resolution viewport that the screen-space error calculation deems it necessary to load them. If reducing the Max SSE helps, it could indicate something is going wrong there.

Without a way to reproduce this, though, all I can do is guess. I understand you can’t share your scene or scripts, but perhaps you can create a scene with Cesium OSM Buildings and a simpler script that casts a bunch of rays? Just the exercise of trying to create a minimal reproduction case like that might very well reveal what’s going wrong.