Efficient Primitives

Hello all,

On my globe I am, on load, drawing about 5 primitives (billboard, labels etc).

Then, on a set interval, I use the position of a satellite, say, and calculate the footprint as a polyline (as I can’t seem to figure out how to draw a polygon with no fill but just an outline). This polyline I add with primitives.add(footprint).

The problem with this is that after a while I have hundreds of _primitives loaded, and it slows the viewer down massively.

What is the best way to update the polyline collection / primitives?

Pseudo code:

var primitives = scene.getPrimitives();

var footprintLines = new Cesium.PolylineCollection();

function tick(xyz){

var satelliteLocation = xyz;

frame = calculatedfromxyz;

var footprint = footprintLines.add();

footprint.setPositions(frame);

primitives.add(footprintLines);

}

I can see that there is an ‘update’ function on the primitives but unsure how to use it.

Thanks for any help.

Toby

Hi Toby,

If tick is called n times, then footprintLines will be updated n times for each frame. You only need to add the primitive once. Try:

var primitives = scene.getPrimitives();

var footprintLines = new Cesium.PolylineCollection();

var footprint = footprintLines.add();

primitives.add(footprintLines);

function tick(xyz){

var satelliteLocation = xyz;

frame = calculatedfromxyz;

footprint.setPositions(frame);

}

Dan

Perfect. Exactly what I was after. Thanks Dan.