Gil Posted April 17, 2017 Share Posted April 17, 2017 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 ? Quote Link to comment Share on other sites More sharing options...
brianzinn Posted April 17, 2017 Share Posted April 17, 2017 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: Quote Link to comment Share on other sites More sharing options...
Gil Posted April 18, 2017 Author Share Posted April 18, 2017 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. Quote Link to comment Share on other sites More sharing options...
Gil Posted April 22, 2017 Author Share Posted April 22, 2017 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 ? Quote Link to comment Share on other sites More sharing options...
Gil Posted April 25, 2017 Author Share Posted April 25, 2017 Little bump hoping that someone can give it some time Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted April 25, 2017 Share Posted April 25, 2017 I suggest using dot product: http://www.babylonjs-playground.com/#QNJ03P#5 when dot(a, b ) > 0.95 then you are front facing Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Gil Posted April 26, 2017 Author Share Posted April 26, 2017 @Deltakosh Wow ! That's perfect ! Thank you ! I saw a post where you talked about that but I wasn't able to connect the dots :p. Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Gil Posted April 26, 2017 Author Share Posted April 26, 2017 @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 Quote Link to comment Share on other sites More sharing options...
adam Posted April 27, 2017 Share Posted April 27, 2017 Use mesh.getDirection(localDirection) to get the world direction of whichever axis or direction you want. Gil 1 Quote Link to comment Share on other sites More sharing options...
Gil Posted April 27, 2017 Author Share Posted April 27, 2017 Yep that was it :). Thank you ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.