CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
12.82k stars 3.46k forks source link

Corridor renders from Primitive API but not Entity API #4829

Open hpinkos opened 7 years ago

hpinkos commented 7 years ago

From #4326

This corridor renders:

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

var redCorridorInstance = new Cesium.GeometryInstance({
    geometry: new Cesium.CorridorGeometry({
        positions : Cesium.Cartesian3.fromDegreesArray([
            -16.41549000000001,28.44423000000001,
            -16.41549000000001,28.44423000000001,
            -16.41505000000001,28.44430000000001,
            -16.41507000000001,28.44430000000001,
            -16.41473000000001,28.44460000000001,
            -16.41429000000001,28.44452000000001,
            -16.41430000000001,28.44453000000001,
            -16.41428000000001,28.44452000000001,
            -16.41416000000001,28.44434000000001,
            -16.41415000000001,28.44434000000001,
            -16.41397000000001,28.44408000000001
        ]),
        width : 1,
        vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
    }),
    attributes : {
        color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 0.0, 0.0, 0.5))
    }
});

var primitive = scene.groundPrimitives.add(new Cesium.GroundPrimitive({
    geometryInstances: [redCorridorInstance],
    appearance: new Cesium.PerInstanceColorAppearance({
        closed: true
    })
}));

scene.camera.setView({
    destination: Cesium.Cartesian3.fromDegrees(-16.41549000000001, 28.44423000000001, 100)
});

But this one doesn't

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

var redCorridor = viewer.entities.add({
    name : 'Red corridor on surface with rounded corners and outline',
    corridor : {
        positions : Cesium.Cartesian3.fromDegreesArray([
            -16.41549000000001,28.44423000000001,
            -16.41549000000001,28.44423000000001,
            -16.41505000000001,28.44430000000001,
            -16.41507000000001,28.44430000000001,
            -16.41473000000001,28.44460000000001,
            -16.41429000000001,28.44452000000001,
            -16.41430000000001,28.44453000000001,
            -16.41428000000001,28.44452000000001,
            -16.41416000000001,28.44434000000001,
            -16.41415000000001,28.44434000000001,
            -16.41397000000001,28.44408000000001
        ]),
        width : 1,
        material : Cesium.Color.RED.withAlpha(0.5),
        outline : true,
        outlineColor : Cesium.Color.RED
    }
});

viewer.zoomTo(viewer.entities);
hpinkos commented 7 years ago

Related forum posts: https://groups.google.com/forum/?hl=en#!topic/cesium-dev/9wvnNNQcLTA https://groups.google.com/forum/?hl=en#!topic/cesium-dev/7h3W_ICb4wM

Another example:

positions : Cesium.Cartesian3.fromDegreesArray([
    43.0298791905732,30.3249511347621,
    43.0535143723772,30.3254863499896,
    43.0531351413855,30.217161279318,
    43.0300902644761,30.2171721034287,
    43.0298791905732,30.3249511347621
]),
hpinkos commented 7 years ago

From @mramato

If someone wants to look at this, the geometry for the Corridor is created in CorridorGeometryUpdater.createFillGeometryInstance and then it's used in StaticGroundGeometryColorBrach in the createPrimitive block around line 86. There's probably an unrelated bug specific to CorridorGeometry in the Entity API.

CHBaker commented 6 years ago

I think I am having the same issue, but with polylines. I get the z-fighting you referenced in the related issue. Is there a fix for this yet?

I have an example on the sandcastle running this code:

var viewer = new Cesium.Viewer('cesiumContainer', { infoBox : false });
var entities = viewer.entities;

entities.add({
     polyline : {
        positions : Cesium.Cartesian3.fromDegreesArray([-111.0, 40.0,
                                                        -95.0, 40.0]),
        width : 3,
        material : Cesium.Color.RED,
        heightReference : Cesium.HeightReference.CLAMP_TO_GROUND
    }
    });
viewer.zoomTo(viewer.entities);
hpinkos commented 6 years ago

Hi @CHBaker. Polylines don't have a heightReference property and do not support being clamped to terrain. They will curve to fit the ellipsoid automatically though.

CHBaker commented 6 years ago

@hpinkos hmmm. I saw some posts about adding this feature in 2015, guess it never got added. The problem I have is two polylines crossing at a perfetc '+' sign, but when you zoom in one is floating above the other, so when you ctrl + click to move perspective the lines move a lot and do not lay directly on top of each other.

This only occurs once you zoom in very close, they lay directly on top of each other, but once cesium renders as close as you can get, they don't appear on top of each other

hpinkos commented 6 years ago

@CHBaker try changing the value of the granularity attribute. This is a value in radians that specifies the distance at which the line should be subdivided and pushed to the ellipsoid surface. Here's an illustration to show what I'm talking about: image

For a really large number, the line will just cut through the ellipsoid. A smaller value will break the line up to better fit the curvature.

By default, it subdivides the line each degree (Math.PI/180 radians). A smaller value might work better for your case.

CHBaker commented 6 years ago

Alright, I think that did it, thanks!