Jump to content

Test if camera is facing mesh


Gil
 Share

Recommended Posts

I'm doing a label system, you can see the original post here. I don't think it's relevant but you get the background.


To make it work, I created various faces on a mesh. Each faces generate a label.

To know which one has to be displayed, I would like to compare their angle to the camera to know if it's facing the camera enough to be visible.

After some research I came with this :

http://www.babylonjs-playground.com/#QNJ03P#1


I'm pretty bad in 3D math but I already found some usefull posts and PG on the forums and the doc.


- I think I'm pretty close but I don't know why my camera Quaternion doesn't seems to be refreshed when I rotate the camera (except for the Y axis which switch btw 0 and -0).

- Also I'm not sure how to compare both quat so that I can say if the difference is less than 40° I can display it

- And finally when I apply the function toQuaternion() on the ground it rotates it. I have the same issues with my faces and I don't know if it will changes something or not.

 

Could someone give some insight to finish this ?

 

Link to comment
Share on other sites

Also, when I'm using a RotateArcCamera, I'm using the alpha property to do calculations on placing Meshes, so I would guess that may work well with what you are doing.  So, I'm not using the camera Quaternion:

var observer = scene.onAfterCameraRenderObservable.add(() => {
    this.meshToCounterRotate.rotation.y = -camera.alpha
}

Check out the alpha/beta here:

http://babylonjsguide.github.io/basics/Cameras

Looks like you want to make sure the plane itself is visible enough by the angle, but If you just need to see if it's within the camera field of view as "visible" check out mesh.isInFrustrum on this post:

Link to comment
Share on other sites

Hello Brianzinn,

I will give a shot to compare alpha and beta from the camera to the mesh to see if I can figure it out.
Thanks.

I was going for quaternion because I read somewhere that it was the best way to compare orientation. Maybe your solution is simpler.

 

I already saw the frustum option but since I have many planes to get informations from any angle I think it's easier to test by angle to not have the same information displayed twice.

Link to comment
Share on other sites

Hello,

I think I made some progress but went in another direction.

The logic I wanted is to get the camera direction, then get the plane direction.
Get the angle with both direction.
Then check if they have the opposite direction with negate.
And finally get the difference between both.

If the difference is small the camera and the plane should be looking together.

 

I updated the PG : http://www.babylonjs-playground.com/#QNJ03P#4

 

Could somebody tell me if I'm in the right direction and what I'm missing ?

Link to comment
Share on other sites

@Deltakosh sorry to bother you again with this but when I use the rotation of planes I export of 3ds Max I can't get it work.
The Z axis is the front axis of my planes.

The only thing I updated in the code is "planeDir". I tested with both normalized and not normalized value but it doesn't work (it should be normalized I think).

var planeDir = this.rotation.clone().normalize();

If I don't clone the rotation, doing the operation turn the planes (which I suppose is normal ?).

 

It's like the only option would be to create all planes in the engine directly.

Am I doing something wrong ?

Labels.babylon

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...