Changing the extrusion of polygon primitives

Hello Cesium gang,

I’ve got a bunch of polygons in cartographic coordinates, all on the ellipsoid. I create primitives from PolygonGeometry for these.

Here’s an example of the code that makes the primitive. This works fine.

var longLats = [ … ];

var cartesian3Points = new Cesium.Cartesian3.fromDegreesArray(longLats);

var polyGeometry, polyInstance, primitive;

polyGeometry = new Cesium.PolygonGeometry.fromPositions({

height: 1.0,

width: 5.0,

extrudedHeight: 50000,

positions: cartesian3Points

});

polyInstance = new Cesium.GeometryInstance({

geometry: polyGeometry,

id: “Test LGA2 poly”

});

primitive = new Cesium.Primitive({

geometryInstances: polyInstance,

releaseGeometryInstances: true,

show: true,

appearance: new Cesium.MaterialAppearance({

material: Cesium.Material.fromType(

“Color”,

{color: Cesium.Color.RED})

}),

});

scene.primitives.add(primitive);

I want to dynamically adjust the extrusion of these primitives periodically. Is there a way to do that?

(I am using primitives because in my experience using entities was too slow. I’m using 1.58.1 on Windows in Chrome 76.)

Thanks,

Bryan

Hey Bryan!

I think the easiest way would be to recreate the geometry. This is what dynamic entities do, and they handle copying over the previous state. For example, if you run this Sandcastle which has a rectangle with a dynamic extrusion, and print out a message in the RectangleGeometryUpdater:

You’ll see it continually recreating the geometry.

This is great stuff Omar thank you.

If you run this sandcastle you can see me recreating the primitive (manually) every 40ms and that seems to work fine, even with a 759-point polygon.

Please glance at the code at the end of that sandcastle. Is there any worthwhile optimization I can do, like avoiding re-creating all three objects inside makePolyPrimitive() each time?

Thanks,

Bryan

From a first glance, it looks like one thing you could easily cache is the material, where you create it once and just pass it to the new primitive you create.

I’d need to dig a bit more here to recommend any more optimization. For example, it might be worth investigating how much work happens when you construct a geometry instance, if it’s worth trying to keep that alive and only replacing its geometry property, or if it’s more of just a simple interface.