I’m trying to render a PolygonGeometry in a Primitive by using coordinates taken from clicked events and projected using a model matrix.
The click handler:
handler.setInputAction(function (click) {
var pickedObject = viewer.scene.pick(click.position);
if (defined(pickedObject) ) {
var pickedPosition = viewer.scene.pickPosition(click.position);
if (defined(pickedPosition)) {
points.push(Matrix4.multiplyByPoint(Matrix4.inverse(model.modelMatrix, new Matrix4()), pickedPosition, new Cartesian3()));
}
}
}, ScreenSpaceEventType.LEFT_CLICK);
and the primitive created from a set of points:
const p = new Primitive({
debugShowBoundingVolume: true,
asynchronous: false,
geometryInstances: [
new GeometryInstance({
geometry: new PolygonGeometry({
polygonHierarchy: new PolygonHierarchy(points, []),
perPositionHeight: true,
}),
attributes: {
color: ColorGeometryInstanceAttribute.Color.RED
}
})
],
appearance: new PerInstanceColorAppearance(),
modelMatrix: model.modelMatrix,
releaseGeometryInstances: false
});
viewer.scene.primitives.add(p);
This works for some polygons but for most it fails due to “normalized result is not a number” with stack:
app-index.js:35 An error occurred while rendering. Rendering has stopped.
DeveloperError: normalized result is not a number
Error
at new DeveloperError (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Core/DeveloperError.js:41:11)
at Cartesian3.normalize (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Core/Cartesian3.js:456:11)
at Stereographic.fromCartesian (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Core/Stereographic.js:166:58)
at eval (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Core/PolygonGeometry.js:1248:73)
at computeAttributes (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Core/PolygonGeometry.js:203:22)
at PolygonGeometry.createGeometry (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Core/PolygonGeometry.js:1483:35)
at loadSynchronous (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Scene/Primitive.js:1380:46)
at Primitive.update (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Scene/Primitive.js:2180:7)
at PrimitiveCollection.update (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Scene/PrimitiveCollection.js:423:19)
at updateAndRenderPrimitives (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Scene/Scene.js:3473:21)
at executeCommandsInViewport (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Scene/Scene.js:3240:3)
at Scene.updateAndExecuteCommands (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Scene/Scene.js:2985:5)
at render (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Scene/Scene.js:4060:9)
at tryAndCatchError (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Scene/Scene.js:4079:5)
at Scene.render (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Scene/Scene.js:4173:5)
at CesiumWidget.render (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Widget/CesiumWidget.js:848:17)
at render (webpack-internal:///(app-pages-browser)/./node_modules/@cesium/engine/Source/Widget/CesiumWidget.js:63:18)
window.console.error @ app-index.js:35
console.error @ hydration-error-info.js:41
CesiumWidget.showErrorPanel @ CesiumWidget.js:749
CesiumWidget._onRenderError @ CesiumWidget.js:420
Event.raiseEvent @ Event.js:142
tryAndCatchError @ Scene.js:4081
Scene.render @ Scene.js:4173
CesiumWidget.render @ CesiumWidget.js:848
render @ CesiumWidget.js:63
Show less
Would really appreciate someone enlightening me as to what is going on here. Thanks