newbie question: How to set the orientation for an entity?

Finally getting to work with Cesium and having some basic trouble -- I want to make a generic polygon that I reposition via a matrix (on an ongoing basis). Really, it's a data source but it's listening to live data coming in over SSE, so I don't have it set up as a data source right now.

So first, I've ended up defining some czml for the data, an exciting arrow shape:

const czml = [{
    "id" : "document",
    "name" : "CZML Geometries: Polygon",
    "version" : "1.0"
}, {
    "id" : "arrow",
    "name" : "the arrow",
    "polygon" : {
        "positions" : {
            "cartesian" : [0, 0, 100000,
                                     -10, -3, 100000,
                                     0, 10, 100000,
                                     10, -3, 100000,
                                     0, 0, 100000
            ]
        },
        "material" : {
            "solidColor" : {
                "color" : {
                    "rgba" : [255, 100, 0, 128]
                }
            }
        },
        "extrudedHeight" : 50
    }
}];

I can then load that, but when I set the orientation nothing seems to happen. The entity is always drawn near the north pole.

let dataSourcePromise = CzmlDataSource.load(czml).then(function(loadedData){
      
      let entity = loadedData.entities.values[0];
      
      const hpr = new HeadingPitchRoll(heading, 0.0, 0.0);
      const transform = Transforms.headingPitchRollToFixedFrame(raisedPoint[0], hpr);
      entity.orientation = transform; // this doesn't work, nor does using position.

      viewerWrapper.viewer.entities.add(entity);

Is there a better/correct way to do this? What tutorial should I be looking at? I've tried everything I can think of.

Thanks much
Tamar

As you can see from the original CZML, polygons do not have “position” or “orientation”. Polygons are defined only by the “positions” property (note the plural). To change the polygon, you need to calculate a new array of positions.

Thanks Scott.

Certainly I see that in the CZML format, polygons don’t have position or orientation. What I am trying to do is build a polygonal extruded geometry that I can position and orient later. My understanding is that under the hood, entities are building primitives which do have a matrix that can be set and reapplied, and in fact when you set the position (or orientation) of an entity that will update the primitive via the model matrix.

I have gotten this to work easily with a cylinder entity, but seem unable to do the same with a polygon. I am certainly not tied to the CZML, it was just the latest of my many many efforts.

Thanks for all input.

Tamar

I am still stuck on the same issue -- really what I'm trying to do is show an arrowhead to track gps position and compass heading. Someone must have done this before? Thanks for any assistance.

Hi Tamar,

Your use use case, I would suggest creating a 3D model and applying to rotation to that. This will be much easier than recomputing the vertex positions every time you need to rotate.

You can create model in the obj or collada format and convert it to glTF using our online tool: https://cesiumjs.org/convertmodel.html

If all you need is a 3D arrow, you can probably find a model online somewhere under creative commons.

Then you can import it as shown here: http://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=3D%20Models.html&label=Showcases

Hope that helps,

  • Rachel