question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose objects' frustum culled state

See original GitHub issue
Description of the problem

The WebGLRenderer already calculates whether an object is frustum culled, using an internal Frustum.

It’d be nice if this information was exposed so that we don’t have to duplicate the Scene traversal and calculations with our own Frustum outside of the renderer.

A couple ideas:

  • Maybe Mesh objects can have an onFrustumCullChange property that is undefined or null by default. If it is set to a function, then when the frustum culling for the object changes the function can be called with true or false.
  • Another idea would be to just set a boolean flag on the Mesh objects, but this would make logic relying on it be one frame behind. In most cases it wouldn’t be a problem. The user could make the property into a getter/setter to achieve the same feature as the onFrustumCullChange idea.

Any other ways to do it without requiring a second traversal and calculations?

Three.js version
  • Dev
Browser
  • All of them
OS
  • All of them

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

14reactions
mrdoobcommented, Dec 18, 2018

I guess you can currently do this hack:

object1.onBeforeRender = function () { this.userData.inView = true } );

// render loop
scene.traverse( function ( child ) { child.userData.inView = false } );
renderer.render( scene, camera );

But I agree with @Usnul. I would use cannon.js or something.

2reactions
trusktrcommented, Dec 10, 2018

In my current case I’m doing the in-view detection only once when the user stops dragging an object, and not every frame, so performance is not as important in my current case, but I could see this being important if the detection needs to happen every frame, especially if there’s many objects in the scene.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Frustum Culling | Bruno Opsenica's Blog
Frustum culling is a solution to this problem wherein we identify which primitives are actually relevant to the current view by performing ...
Read more >
Visibility and Occlusion Culling
View Frustum culling uses the visible screen area of the camera's field of view (FOV) to cull objects not within this space. The...
Read more >
Occlusion Culling - Unity Manual
Occlusion Culling is a feature that disables rendering of objects when they are not currently seen by the camera because they are obscured...
Read more >
Is there an Object3D poperty to check if it's within camera ...
One reason for this is that exposing the object's frustum culling state can be perceived from certain users as buggy.
Read more >
Frustum Culling
Frustum culling can be useful to avoid computation of things that are not visible. You can use it to not compute the animation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found