CesiumGS / cesium

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

GroundPrimitive Render Error #11291

Open BloodlustLR opened 1 year ago

BloodlustLR commented 1 year ago

I want to use PolygonGeometry and groundPrimitive to draw Hexagonal Grids on Terrain, but there is a problem with the color rendering of the hexagonal grid, which goes out of the edge grid.And I check the edge points to ensure points are correct. `hexagonInstances.push(new Cesium.GeometryInstance({ geometry: new Cesium.PolygonGeometry({ polygonHierarchy: new Cesium.PolygonHierarchy(geoInfo.cartesian3Data as Cesium.Cartesian3[]), vertexFormat: Cesium.PerInstanceColorAppearance.VERTEXFORMAT }), id: "Hexagon-" + geoInfo.indexX + "" + geoInfo.indexY, attributes: { color: Cesium.ColorGeometryInstanceAttribute.fromColor(this.config.showSatelliteImage?color.withAlpha(0.2):color.withAlpha(0.8)) } }))

this.viewer.scene.primitives.add( new Cesium.Primitive({ geometryInstances: hexagonInstances, interleave: true, vertexCacheOptimize: true, allowPicking: false, asynchronous: false, appearance: new Cesium.PerInstanceColorAppearance({ flat: true }) }), 0) `

L3_W3O2O $UWJZDTOF MB

ggetz commented 1 year ago

Hi @BloodlustLR,

Where is the hexagon grid outline coming from? Can you provide a Sandcastle code example that replicates the issue? That would help us give us more context to determine the issue.

Thanks!

BloodlustLR commented 1 year ago

Hi @BloodlustLR,

Where is the hexagon grid outline coming from? Can you provide a Sandcastle code example that replicates the issue? That would help us give us more context to determine the issue.

Thanks!

the hexagon grid outline is drawed by myself with GroundPolylinePrimitive.The code above is my Sandcastle code example, which color render incorrectly.Thanks!@ggetz

G}_ZWR67Z6YF7$TNR}IYM(1

Sandcastle Example URL: https://sandcastle.cesium.com/#c=pVZrb+I6EP0rEV82SCjk/aAPXdR225W2txW3d3elpqrcYIi1wUaOU5Zd9b/fsfMooSkFXQQCe86Mz5yZCU4YzYX2xPgUc+1E+xPTuLfCuYh7I82yLcO3Ixu+HS+yLDsaSHPOCpFKu+0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NzIIsK0QiUWsrSoAY1ZoJnmGOlTsX9qr1vnH0dX98+3t08Xk5u/v37/LWmFZNSDr0k2DdEiqmu97WTU0lkmy3HCwZFq8BHKlJv0DvOxTrDpzHV1OsvslhC8lrBM90whgIvlplMYPhUJD+xMJI8l74SejzcdD2ekmeNTE86/hy1JEN5DpZZkWX/kN847p0eDwH/xjVjCASb38CUZmgtYal1+rXcNAzjeAjLbk/BWPaE+Fbk/wA

Sandcastle Example Code: `const border = { "west": 121.62921213591129, "south": 24.81999135320948, "north": 24.865129705580536, "east": 121.67205922150731 };

const data = [ [ [ 121.63778155330164, 24.865129705580532 ], [ 121.6463509706242, 24.860615882618365 ], [ 121.6463509706242, 24.851588228512096 ], [ 121.63778155330164, 24.84707439736872 ], [ 121.62921213591129, 24.851588228512096 ], [ 121.62921213591129, 24.860615882618365 ], [ 121.63778155330164, 24.865129705580532 ] ], [ [ 121.65492038781119, 24.865129705580532 ], [ 121.66348980479482, 24.860615882618365 ], [ 121.66348980479482, 24.851588228512096 ], [ 121.65492038781119, 24.84707439736872 ], [ 121.6463509706242, 24.851588228512096 ], [ 121.6463509706242, 24.860615882618365 ], [ 121.65492038781119, 24.865129705580532 ] ], [ [ 121.62921213591129, 24.851588228512096 ], [ 121.63778155330164, 24.84707439736872 ], [ 121.63778155330164, 24.838046726903297 ], [ 121.62921213591129, 24.833532887581978 ], [ 121.62064271852094, 24.838046726903297 ], [ 121.62064271852094, 24.84707439736872 ], [ 121.62921213591129, 24.851588228512096 ] ], [ [ 121.6463509706242, 24.851588228512096 ], [ 121.65492038781119, 24.84707439736872 ], [ 121.65492038781119, 24.838046726903297 ], [ 121.6463509706242, 24.833532887581978 ], [ 121.63778155330164, 24.838046726903297 ], [ 121.63778155330164, 24.84707439736872 ], [ 121.6463509706242, 24.851588228512096 ] ] ];

const viewer = new Cesium.Viewer("cesiumContainer");

let cartesian3Data = []; for(let hex of data){ let hexData = []; for(let position of hex){ hexData.push(Cesium.Cartesian3.fromDegrees(position[0], position[1])); } cartesian3Data.push(hexData); }

//drawOutline let hexagonOutline = []; for(let hex of cartesian3Data){ hexagonOutline.push(new Cesium.GeometryInstance({ geometry: new Cesium.GroundPolylineGeometry({ positions: hex, width: 2 }) })); }

viewer.scene.groundPrimitives.add(new Cesium.GroundPolylinePrimitive({ geometryInstances: hexagonOutline, interleave: true, allowPicking: false, appearance: new Cesium.PolylineMaterialAppearance({ material: new Cesium.Material({ fabric : { type : 'Color', uniforms : { color : Cesium.Color.WHITE.withAlpha(0.5) } } }) }) }), 0);

//drawHexagon let hexagon = []; for(let hex of cartesian3Data){ let geometry = new Cesium.PolygonGeometry({ polygonHierarchy: new Cesium.PolygonHierarchy(hex), vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT }); let instance = new Cesium.GeometryInstance({ geometry: geometry, attributes: { color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromRandom()) } }); hexagon.push(instance); } viewer.scene.groundPrimitives.add( new Cesium.GroundPrimitive({ geometryInstances: hexagon, appearance: new Cesium.PerInstanceColorAppearance({ flat: true }) }), 0);

//zoomToArea let rectangle = Cesium.Rectangle.fromDegrees(border.west, border.south, border.east, border.north); let entity = viewer.entities.add({ rectangle: { height:0, coordinates: rectangle, heightReference: Cesium.HeightReference.CLAMP_TO_GROUND } }); viewer.zoomTo(entity).then(() => { viewer.entities.remove(entity); }); `

ggetz commented 1 year ago

Thanks @BloodlustLR!

I can confirm there seems to be artifacts based on the camera angle:

https://github.com/CesiumGS/cesium/assets/4439461/58cd7afb-ebcb-46ee-8a55-fd26f53df400

BloodlustLR commented 1 year ago

Thanks @BloodlustLR!

I can confirm there seems to be artifacts based on the camera angle:

2023-05-18.09-25-16.mp4

Yes,That's the problem.It seems a bug of GroundPrimitive.

ggetz commented 1 year ago

Also reported in https://github.com/CesiumGS/cesium/issues/11292.

LTJhon commented 1 year ago

I also encountered this problem. However, during my testing, I found that this does not seem to happen when the area of each instance is small

jjspace commented 11 months ago

Also reported on the forum here

wenzhihao123 commented 11 months ago

@BloodlustLR @ggetz I also encountered this problem。 I find if you set :viewer.scene.globe.depthTestAgainstTerrain = false,and use Primitive instead of GroundPrimitive,it worked perfect ! But i want to set depthTestAgainstTerrain = true in my whole project!What should i do ? Please give me some advices,Thanks a lot !

BloodlustLR commented 11 months ago

@BloodlustLR @ggetz I also encountered this problem。 I find if you set :viewer.scene.globe.depthTestAgainstTerrain = false,and use Primitive instead of GroundPrimitive,it worked perfect ! But i want to set depthTestAgainstTerrain = true in my whole project!What should i do ? Please give me some advices,Thanks a lot !

The reason for this error is that the intersections of the rendered polygons of the same level overlap, so in my project, the solution I am taking to temporarily avoid this problem is to divide them into odd and even rows and render them separately. The effect is very good. You can Take a similar approach. But I don’t think this is the best way, because dividing one rendering into two times will still increase the performance burden. I still hope that the official can help solve this BUG.

wenzhihao123 commented 11 months ago

@BloodlustLR @ggetz I also encountered this problem。 I find if you set :viewer.scene.globe.depthTestAgainstTerrain = false,and use Primitive instead of GroundPrimitive,it worked perfect ! But i want to set depthTestAgainstTerrain = true in my whole project!What should i do ? Please give me some advices,Thanks a lot !

Thanks for your solution ~ I also agree that the official can help solve this problem.

jjspace commented 4 months ago

Reported on the forum again with an example showing a number of polygons in close proximity and being unable to select the specific one under the cursor due to the shadow volumes. sandcastle