Raycasting before calling updateWorldMatrix

Hi,
I have the following issue:
A group positioned at some place (not 0,0,0), with a single child sphere mesh
A render loop running throttled to some pace
An event listener on mouse move which calculates intersection with the group (unthrottled)

At some point I swap the sphere mesh with a cube mesh (unrelated to user behavior)
If this happened while the cursor was on top of the sphere (and on top of the cube when it will be swapped) the raycasting will sometimes get 0 intersections.

i.e.
Sphere is added to the group
Cursor on top of sphere
Intersection found
Cursor moving - intersection still found
Swap cube
Few empty intersections
Back to getting intersections

After some debugging I found the the only thing that helps is either making sure I call render() before the raycasting happens or calling manually updateWorldMatrix.
So it seems like rendering calls updateWorldMatrix for me, and raycasting doesn’t.
I looked at the code (mine’s and three.js’) and I wasn’t able to find where updateWorldMatrix is being called in the renderer, but I found where updateMatrixWorld is being called:

Not sure this is related though

I’m not sure this is issue worthy as it’s quite a rare case, and also I’m not sure there’s an easy solution that would prevent called updateWorldMatrix multiple times per frame.

So my questions are:

  1. What’s the relationship between updateWorldMatrix and updateMatrixWorld?
  2. Is what I’m describing sound like a real issue or something that should be solved on the application level?

Thanks

It was the idea to replace updateMatrixWorld() with updateWorldMatrix() at some point. The problem is that the world matrix update design has some flaws but there is no consensus so far in how the system should be improved. I suggest you search at GitHub for related issues and PRs to understand the entire (long) history.

The issue needs to be handled on application level right now. So if you perform raycasting or any sort of collision detection test, you have to ensure that world matrices are up-to-date. Even if that means that certain matrices will be computed more than once per frame.

1 Like

I was only searching for updateWorldMatrix in the context of raycasting because it seems like there is a LOT of discussions on these functions (and unfortunately only during the writing of this question I realized there’s much more complexity around these)
So seems like this is not an issue worthy question…
Thanks!