how to update polygon material in 1.17?

In 1.16, we would update a polygon’s material just by changing the material and calling configurePolygonHierarchy:

polygon.material = Cesium.Material.fromType(‘Color’);

polygon.material.uniforms.color = {

red: rgb[0],

green: rgb[1],

blue: rgb[2],

alpha: alphaValue

};

var hierarchy = {

positions : positions,

holes : [{ positions : seaLevelInnerRingPositions }]

};

        polygon.configureFromPolygonHierarchy(hierarchy);

``

With the removal of Polygon, how do we do this in 1.17? I tried the code below but I can’t get the polygon material to update (to the default red color). Is this the right idea?

//polygon is the original polygon we're trying to modify

        var instance = new Cesium.GeometryInstance({

geometry : new Cesium.PolygonGeometry({

polygonHierarchy : hierarchy,

height : polygon.height,

vertexFormat : Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,

stRotation : polygon.textureRotationAngle,

ellipsoid : polygon.ellipsoid,

granularity : polygon.granularity,

extrudedHeight : polygon.extrudedHeight

}),

id : polygon.id,

pickPrimitive : polygon

});

polygon._primitive.destroy();

polygon._primitive = new Cesium.Primitive({

geometryInstances : instance,

appearance : new Cesium.EllipsoidSurfaceAppearance({

aboveGround : (polygon.height > 0.0),

material : Cesium.Material.fromType(‘Color’)

}),

asynchronous : polygon.asynchronous

});

``

Hello,

Yes, you will need to remove and re-add the primitive in order to change the material.

Alternatively, you could try using the Entity API instead, which will update the material automatically the same way the Polygon used to.

Here is an example of creating Polygons with the Entity API: http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Polygon.html&label=Geometries

Best,

Hannah

Blast from the past here: Is this still the case? In order to update a primitive, should we remove and re-create the primitive?

It depends what you are trying to update. You can change the color of a Primitive using a PerInstanceColorAppearance without having to recreate it, but for most other properties you need to create a new one with something like this:

if (defined(this._primitive)) {

var color = this._primitive.getGeometryInstanceAttributes(this._id).color;

color[0] = value.red * 255;

color[1] = value.green * 255;

color[2] = value.blue * 255;

color[3] = value.alpha * 255;

this._primitive.getGeometryInstanceAttributes(this._id).color = color;

}

``

However this method won’t work for GroundPrimitives.
I would recommend using the Entity API. The Entity API uses Primitives under the hood and handles all of the updating and recreating in an optimal way. It also means you don’t have to worry about what can and cannot be changed in your own code.

-Hannah

Hi,

I have a similar issue. I have an array of GeometryInstance (geometry, color, …) that makes a tile. I wanna change the alpha of each instance (that can different colors) in the tile. You said with the help of

PerInstanceColorAppearance

the alpha can be changed. But as you can see in the below link

(https://cesiumjs.org/Cesium/Build/Documentation/PerInstanceColorAppearance.html?classFilter=PerInstanceColorAppearance)

there is no field that I can change the color.

Another solution that I tried to address the issue is that: I assigned an id to each GeometryInstance. Then tries to change the color

var color = that.primitive.getGeometryInstanceAttributes(‘cube’ + cube_id).color

the cesium gives me the error that the that.primitive.getGeometryInstanceAttributes is not a function.

I would appreciate if you can help me to address this issue.

Maryam

See this thread for the solution to this question: https://groups.google.com/forum/#!msg/cesium-dev/93GZVBcmlsk/-o9Tj1zZCgAJ