First off, congrats on 4.1! super exciting news and I’m looking forward to leveraging some of the new features in our large CAM application.
I’m working on a personal project and all was going well until I tried to cast some rays. I’m having a hard time working out what the right combination of positions etc I need to construct the ray properly.
Basically what I’m trying to achieve is as follows:
Given a Vector3 in world space, decide whether or not it is occluded by a known mesh.
I’m going to be using this logic in my project to manually cull the segments of a wireframe that should not be visible (the project takes a wireframe and the mesh for that wireframe, and computes the set of line segments to generate an svg for).
I’ve created a playground with a minimal demo where I
- construct a box
- put a target sphere on that box
- construct a ray from the camera to the target (this is where I think I’ve gone wrong)
- test if the ray intersects the box
- change the target colour based on the test.
https://www.babylonjs-playground.com/#669TCN#3
If you try the demo out, I would expect when the camera rotates around the box, when the target goes to the backside, it should become red. This is partially working, but it takes far more rotation than expected to make the transition happen.
I suspect the issue is that my from argument of the ray is the camera centre, but really I want the intersection of the camera plane and the screen space coordinate of the target?
I should add, I actually want this to work with an orthographic camera, so I’ve included the code for that in the demo. If you do turn off the orthographic camera it does appear to work, so maybe the issue is there?
any pointers greatly appreciated!
(edit, posted wrong link, oops)