Is there a way to force redering of terrain and OSM buildings along a path

Hi!

So I’m currently trying to find a way to get a polyline clamped to the ground throughout a path.

I’m currently doing it using this snippet of code:

    var samples = 200;
    var cartesians = [];
    
    for (var i = 0; i < samples; ++i) {
        var offset = i / (samples - 1);
        cartesians[i] = Cesium.Cartesian3.lerp(origin , target , offset , new Cesium.Cartesian3());
    }

    viewer.scene
    .clampToHeightMostDetailed(cartesians)
    .then(function (clampedCartesians) {
        clampedPath = viewer.entities.add({
            polyline: {
                positions: clampedCartesians,
                width: 2,
                material: Cesium.Color.CYAN
            },
        });
    });

Where origin is the Cartesian3 point to start the polyline and target is the Cartesian3 point to end the polyline

But, in some larger paths, since not all the terrain and buildings are rendered yet, I get some results like the one on this image

So my question is if there’s a way to force the render along the defined path so that I can get an accurate result?

@eduardo_ferreira

Welcome to the community! :confetti_ball: :grinning:

Thank you for sharing some information about your project. What data are you rendering along the path outlined in blue? In general, our API does not provide a simple way to render data that is in close proximity to a polyline. However, I am guessing that after a few seconds, the data loads in and you are getting the desired results. If you are would like to learn more about how to control how 3D Tiles are loaded into your viewer, I suggest checking out the following demo.

This demo showcases how the level of detail can be optimized at runtime. See the “optimizations” tab. Let me know if you have any other questions or concerns.

-Sam

1 Like

Hey @sam.rothstein !

Thank you for the response and the warm welcome!

To give you some broader scope on why I’m doing this, I’m trying to find a way to get all the points of intersection between a ray/polyline (basically2 points) and buildings/terrain.

This is what I’ve tried so far

  • IntersectionTests doesn’t have a way (that I know of) to get intersections either with the terrain (using viewer.scene.globe.ellipsoid doesn’t work for Cesium.IntersectionTests.rayEllipsoid) or buildings;

  • Using viewer.scene.globe.pick only gives me the last intersection and only works for terrain, so that doesn’t work either

So finally what I’m trying to do is create a polyline, then clamp it to the ground (since viewer.scene.clampToHeightMostDetailed works for both terrain and buildings) and compare the angles created by the polyline clamped to the ground and the vector connecting the origin and target points. So if the sum of angles is above 0 there’s and intersection and when the sum is 0 or less the intersection has ended

Here’s an image of what that would look like so that it’s easier to understand (at least I hope so :sweat_smile:)

And here is where I have the problem I began exposing, the clampToHeightMostDetailed only gives me the points for the best render that it has at that time, so when the camera is really far away from the point being clamped I get results like shown before.

If there’s a easier way to do this or a method already implemented please tell me :smiley:

Kind regards,

Eduardo

@eduardo_ferreira

Thank you for providing some more details on the issue that you have encountered. The image that you added really helps me understand your problem. From my research, I think you are going about tackling this issue correctly. However, it is always useful to bounce ideas off of other developers. I wonder if any other community members have any suggestions or thoughts.

-Sam