Jump to content

Determine when 3D point is out of view


Flomotion
 Share

Recommended Posts

Hi all,

I'd like to know if anyone knows how to determine if a 3D point is out of range from the camera view.

I'm making 2D labels on top of a 3D model. And it all works nice but when camera is 180 to the object, the 2D labels appear back on the canvas.

I based what I'm doing on this example by Wingnut.

http://playground.babylonjs.com/#1HLSBC%234

You'll see the menu's floating by if you zoom a bit closer to the red sphere and make a box float behind you. So to prevent that from happening.. my question again:

I'd like to know if anyone knows how to determine if a 3D point is out of range from the camera view?

:-)

Floris

Link to comment
Share on other sites

Hi Floris,

 

I believe Frustum  inspection can help in your case. It will inspect if an object is in the camera's view.

The only catch is - it will return true also when an object is hidden behind another object. 

To use it, get the frustum planes of your camera:

var frustumPlanes = BABYLON.Frustum.GetPlanes(scene.getTransformMatrix());

and then use it to determine if part of the object is in the camera's view:

if(!mesh.isInFrustum(frustumPlanes)) {   doSomethingWithTheMesh(mesh);} 

You could also get the array of active meshes from the scene and use it - Simply put, active meshes can be seen as meshes in the camera's view. To Get it:

var smartActiveMeshesArray = scene.getActiveMeshes(); 

Or check if a mesh is active:

var active = scene.isActiveMesh(mesh); 

I hope it helps!

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...