Detect if Entities are in view

212 views
Skip to first unread message

Nathan

unread,
Apr 1, 2020, 4:36:37 AM4/1/20
to cesium-dev
1. A concise explanation of the problem you're experiencing.

Unable to detect if a bounding box is occluded by the earth. I've tried creating an occluder using the bounding sphere from the earth & one from the frustum but both methods do not seem to be working!

The occluder always returns "NONE" and the fustrum always returns "FULL"


2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.

My current thinking (working on the sandbox)


var viewer = new Cesium.Viewer('cesiumContainer');


// To geographically place an HTML element on top of the Cesium canvas, we use
// scene.cartesianToCanvasCoordinates to map a world position to canvas x and y values.
// This example places and img element, but any element will work.

// Scractch memory allocation, happens only once.
var scratchRectangle = new Cesium.Rectangle();
var worldSphere;
worldSphere = Cesium.BoundingSphere.fromEllipsoid(Cesium.Ellipsoid.WGS84);

var htmlOverlay = document.getElementById('htmlOverlay');
var scratch = new Cesium.Cartesian2();
viewer.scene.preRender.addEventListener(function() {
    
    var position = Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883);
    
     var viewRect =
         viewer.camera.computeViewRectangle(viewer.scene.globe.ellipsoid,
        scratchRectangle);

    var east = Cesium.Math.toDegrees(viewRect.east);
    var west = Cesium.Math.toDegrees(viewRect.west);
    // This does not work when zoomed out - reaches +-180 degrees.
    //console.log("east: " + east + ", west: " + west);
    
    var sphere2 = new Cesium.BoundingSphere(position, 0.5);    
    
    console.log("Earth Position: " + worldSphere.center);    
    console.log("Earth Radius: " + worldSphere.radius);
    console.log("Position Center: " + sphere2.center);
    console.log("Position Radius: " + sphere2.radius);    
    console.log("Camera  : " + viewer.camera.direction);
    var occluder = new Cesium.Occluder(worldSphere, viewer.camera.direction);
    var visible = occluder.computeVisibility(sphere2);
        
    // var cullingVolume = viewer.camera.frustum.computeCullingVolume(viewer.camera.position, viewer.camera.direction, viewer.camera.up);
    // var intersect = cullingVolume.computeVisibility(sphere2);
    
    
    if(visible != Cesium.Visibility.NONE) {
        console.log(visible); //returns Visibility.NONE
    }
    
    
    var canvasPosition = viewer.scene.cartesianToCanvasCoordinates(position, scratch);
    if (Cesium.defined(canvasPosition)) {
        htmlOverlay.style.top = canvasPosition.y + 'px';
        htmlOverlay.style.left = canvasPosition.x + 'px';
    }
});


3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

I would like to render dynamic content (canvas elements) on top of the Cesium viewer. Billboards and BillboardGroups run out of graphics eventually (I believe this is due to Atlas not freeing up texture space for removed billboards) so I'd like to do this if possible via the cartesianToCanvasCoordinates method.


4. The Cesium version you're using, your operating system and browser.
1.67 Chrome 80



Message has been deleted
Message has been deleted
Message has been deleted

Nathan

unread,
Apr 2, 2020, 2:12:38 AM4/2/20
to cesium-dev
Apologies for the deletions - accidently forgot to remove my email address from publicly displaying.

    var cameraPosition = viewer.camera.position;
     var occluderEllipsoid = Cesium.Ellipsoid.WGS84;
     var occluder2 = new Cesium.EllipsoidalOccluder(occluderEllipsoid, cameraPosition);
     var isPointVisible = occluder2.isPointVisible(position);
     console.log(isPointVisible);

This seems to work - however the method seems undocumented and deprecated in an older release log. Does this functionality exist anywhere else?
Reply all
Reply to author
Forward
0 new messages