Dynamic update primitive?

I create polylineGeometry object,I want dynamic update polylineGeometry width property。

Hi @zyy1987,

Can you please share a code sample to show how you create the polylineGeometry ? I don’t think you can update its width dynamically if you are re using the primitives API

const polyline = new Cesim.PolylineGeometry({
positions: coordinates,
width: polylineWidth,
});
const geometry = new Cesim.GeometryInstance({
id: ++objId,
geometry: polyline,
attributes: {
show: new Cesim.ShowGeometryInstanceAttribute(true),
color: currentColor,
},
});
const primitive = scene.primitives.add(
new Cesim.Primitive({
geometryInstances: geometry,
appearance: new Cesim.PolylineColorAppearance({
flat: true,
renderState: {
depthTest: { enabled: false },
},
}),
})
);

i want in some scenarios, update the width.

Ok, I don’t think you can only update the width. So what you could do is either remove the instance and create a new one, or you can create several instances with different widths and hide / show the ones with the appropriate width using the getGeometryAttributes method.

let attributes = primitive.getGeometryInstanceAttributes(objId)
if (attributes) {
    attributes.show =
    Cesium.ShowGeometryInstanceAttribute.toValue(false)
 }

this will hide one instance

Thanks for reply!

1 Like