Is there a way to know which objects are seeing by the camera?

I want to display some actions in certain objects but those actions will be enable only if the camera is seeing/rendering that object. I don’t know if someone made already an example of this. I’ll searching and trying it anyway.

Hi @Axel_Saucedo,

Not directly, but if you have frustum culling enabled in your active camera, you can find which mesh instances are visible.

Check this forum post for sample code on how to approach this:

1 Like

I tried this example but at the moment I’ve more instances of an object, It only affects the last instances instead of each of them.

https://playcanvas.com/editor/scene/976175

For example: Now I’ve 3 “tv” instances and only “Model 50” (3rd instance) detects when is rendered by the camera or not and the other ones are not working, I don’t know if I’ve to create a new object instead of instancing the object box for the tvs.

Yes because you are using that code in four different script instances. You can override the world layer onPostCull method only once per frame.

You need to create a centralized manager that loops through all entities, checks their model visibility state and acts accordingly on each script instance.

Here is some code that will loop through all World mesh instances and find its parent entity if it’s visible or not per frame:

    this.app.scene.layers.getLayerByName("World").onPostCull = (cameraIndex) => {
        
        var opaqueMeshInstances = this.app.scene.layers.getLayerByName("World").opaqueMeshInstances;
        
        opaqueMeshInstances.forEach( (meshInstance) => {
            
            var entity = meshInstance.node.parent;
            
            console.log(entity.name, ' entity is visible: ', meshInstance.visibleThisFrame);
        });
    };
1 Like