CesiumGS / cesium-ion-rest-api-examples

Code examples for using the Cesium ion REST API :earth_americas:
https://cesium.com/
35 stars 16 forks source link

Polygon Geometry Render Error #309

Closed Aviian314 closed 4 years ago

Aviian314 commented 4 years ago

I've found an oddly specific rendering issue when learning how to use geometries. I was attempting to create a sort of warped box. The first 5 sides came up and looked great, but the last side would only render a triangle and not a quadrilateral. If you manipulate any decimal value of pt6 it will render properly.

Here's the code:

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

let pt1 = [-108.0, 25.0, 100000];
let pt2 = [-100.0, 25.0, 200000];
let pt3 = [-100.0, 30.0, 300000];
let pt4 = [-108.0, 30.0, 400000];
let pt5 = [-108.0, 25.0, 600000];
let pt6 = [-100.0, 25.0, 700000];
let pt7 = [-100.0, 30.0, 800000];
let pt8 = [-108.0, 30.0, 900000];
let side_positions = [
    //[...pt1, ...pt2, ...pt3, ...pt4], //bot
    //[...pt5, ...pt6, ...pt7, ...pt8], //top
    //[...pt1, ...pt2, ...pt6, ...pt5], //south
    //[...pt3, ...pt4, ...pt8, ...pt7], //north
    //[...pt1, ...pt5, ...pt8, ...pt4], //west
    [...pt2, ...pt3, ...pt7, ...pt6], //east
];

let instances = [];
for (let sidepos of side_positions){

    let side = new Cesium.PolygonGeometry({
        polygonHierarchy : {
            positions: Cesium.Cartesian3.fromDegreesArrayHeights(sidepos),
        },
        perPositionHeight : true,
    });

    let sideInstance = new Cesium.GeometryInstance({
      geometry : side,
      attributes : {
        color : new Cesium.ColorGeometryInstanceAttribute(1.0, 0, 0, 0.5)
      }
    });

    instances.push(sideInstance);
}

viewer.scene.primitives.add(
    new Cesium.Primitive({
      geometryInstances : instances,
      appearance : new Cesium.PerInstanceColorAppearance(),
    })
);

image

OmarShehata commented 4 years ago

I'm not sure why this is happening - my best guess is there may be an edge case in PolygonGeometry.createGeometry if a polygon is exactly aligned with the surface normal at a given position like that. I'd be curious if you see the same issue using Coplanar polygons.

The Cesium community forum (https://community.cesium.com/) is a better place to ask this question since this repository is for Cesium ion related issues. I'd post your findings there if you make any more progress here!