Hi Patrick,
I'm also trying to extrude a polygon, in this case a circle, and to do that I started with CylinderGeometry.
My goal is to draw a cylinder with dynamic height through the on mouse movement.
I was able to achieve this but have two problems:
- I need to create GeometryInstance and CylinderGeometry on every frame because I could not set the geometry attributes on the fly. I believe that this causes the draw of the cylinder to be very slow;
- The cylinder grows for both sides instead of just towards the sky.
This is my code on my onMouseMove handler:
if (me.currentState === me.States.Extrude) {
console.log('extrude');
// distance: the mouse distance from the on click position
var length = distance;
var topRadius = me.radius;
var bottomRadius = me.radius;
var modelMatrix = Cesium.Matrix4.multiplyByTranslation(Cesium.Transforms.eastNorthUpToFixedFrame(
//startPointCarte: the on click position
startPointCarte),
new Cesium.Cartesian3(0.0, 0.0, 1.0));
var cylinderInstance = new Cesium.GeometryInstance({
geometry: new Cesium.CylinderGeometry({
length: length,
topRadius: topRadius,
bottomRadius: bottomRadius,
vertexFormat: Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
}),
modelMatrix: modelMatrix,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(me.color)
}
});
var xcylinder = new Cesium.Primitive({
geometryInstances: [cylinderInstance],
appearance: new Cesium.PerInstanceColorAppearance({
translucent: false,
closed: true
})
});
var oldpoly = me.cylinderPrimitive;
xprimitives.add(xcylinder);
me.cylinderPrimitive = xcylinder;
xprimitives.remove(oldpoly);
}
Is there a better way to achieve this? Or something that I'm missing in order to get the results?
Any help would be much appreciated,
Thank you,