I have a function that creates a geometry primitive from a geometry instance. I works great when creating new geometry.
Now I need to remove some of the primitives so that I can re-create them in a different location.
I’m not storing the original geometry primitive data anywhere but I do have the parameters that were input into the function used to create it. My logic was that if I could recreate the exact same parameters within a primitive, then I could just use that to remove the pre-existing primitive.
The problem is that when I try to re-create the primitive object it refuses to accept the instance.
Here is an example of what I’m trying to do that can be copied to the sandbox:
var viewer = new Cesium.Viewer(‘cesiumContainer’);
var scene = viewer.scene;
var ellipsoid = scene.globe.ellipsoid;
var input = {
id: ‘ID1’,
length: 500000,
topRadius: 300000,
bottomRadius: 1000
};
function arCylinder(ar, input){
var instance = new Cesium.GeometryInstance({
geometry: new Cesium.CylinderOutlineGeometry({
length: input.length,
topRadius: input.topRadius,
bottomRadius: input.bottomRadius,
slices: 10
}),
modelMatrix: Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)), new Cesium.Cartesian3(0.0, 0.0, 1000000.0), new Cesium.Matrix4()),
id: input.id,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.YELLOW)
}
});
var newPrimitive = new Cesium.Primitive({
geometryInstances: instance,
appearance: new Cesium.PerInstanceColorAppearance({
flat: true
})
});
if (ar === ‘a’) {
scene.primitives.add(newPrimitive);
}else if(ar === ‘r’){
scene.primitives.remove(newPrimitive);
}
}
Sandcastle.addToolbarButton(‘Add’, function() {
arCylinder(‘a’, input);
});
Sandcastle.addToolbarButton(‘Remove’, function() {
arCylinder(‘r’, input);
});
``
Both times the function is run it should create the exact same ‘newPrimitive’, but if you debug newPrimitive, ‘newPrimitive.numberOfInstances’ is 0 on the remove pass.
Why isn’t it adding the instance to the primitive when I am trying to recreate the original geometry variable to remove it?