Appearance for RectangleOutlineGeometry?

I’m guessing I’m missing something simple here. I’m trying to add a RectangleOutlineGeometry as a primitive and hitting a strange issue.

First, here’s the code I’m using, copied directly from here:

const rectangleInstance = new Cesium.GeometryInstance({
  geometry : new Cesium.RectangleGeometry({
    rectangle : Cesium.Rectangle.fromDegrees(-140.0, 30.0, -100.0, 40.0),
    vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT
  }),
  id : 'rectangle',
  attributes : {
    color : new Cesium.ColorGeometryInstanceAttribute(0.0, 1.0, 1.0, 0.5)
  }
});
scene.primitives.add(new Cesium.Primitive({
  geometryInstances : rectangleInstance,
  appearance : new Cesium.PerInstanceColorAppearance()
}));

All I’m doing is changing RectangleGeometry to RectangleOutlineGeometry, which results in this error:

DeveloperError: Appearance/Geometry mismatch. The appearance requires vertex shader attribute input 'compressedAttributes', which was not computed as part of the Geometry. Use the appearance's vertexFormat property when constructing the geometry.

Taking a look at this page, it looks like vertexFormat isn’t part of the options for that class.

What am I missing?

Thanks!

Hi @BoatyTob, welcome to the community!

I can get this to work by supplying the flat option to PerInstanceColorAppearance:

scene.primitives.add(new Cesium.Primitive({
  geometryInstances : [rectangleInstance1, rectangleInstance2],
  appearance : new Cesium.PerInstanceColorAppearance({ flat: true }),
}));

See this Sandcastle example.

You are correct that vertexFormat is irrelevant for RectangleOutlineGeometry, so the error message is not helpful. I opened Irrelevant error message from `PerInstanceColorAppearance` · Issue #12107 · CesiumGS/cesium · GitHub to improve the message.

Have you considered using entities rather than primitives? Entities may provide easier control of the styling. See the Custom Geometry and Appearances tutorial for some examples.

1 Like

Thank you! This is exactly what I was looking for. Given the number of items we’re dealing with I try to look for primitives-based solutions wherever possible, but in this case I ended up using a normal Entity as you suggested.

1 Like