Re-using data from a sampledPositionProperty for Walls.

I’ve been going round and round in circles with this…

In simple terms, how do I draw a wall under the path of a moving entity? The code below shows how the entity is defined.

var entity = viewer.entities.add(

{

//Set the entity availability to the same interval as the simulation time.

availability : new Cesium.TimeIntervalCollection([new Cesium.TimeInterval(

  {

start : start, stop : stop

  }

)

]),

	//Use our computed positions - a sampledPositionProperty

position : position,

                            // viewer.trackedEntity = entity,

//compute orientation - a sampledProperty

orientation : heading,

HeightReference : Cesium.HeightReference.NONE,

//Load the Cesium plane model to represent the entity

model : {

uri : ‘…/…/SampleData/models/CesiumAir/Cesium_Air.gltf’,

minimumPixelSize : 64

},

//Show the path as a pink line sampled in 1 second increments.

path : {

resolution : 1,

material : new Cesium.PolylineGlowMaterialProperty(

{

glowPower : 0.1, color : Cesium.Color.RED

}

),

width : 3,

leadTime :0

},

wall: {

show : true

material : Cesium.Color.BLUE.withAlpha(0.5),
outline : true,
outlineColor : Cesium.Color.BLACK

  }

}

);

The ‘wall’ property added (in blue) must be missing something as nothing is shown. I have taken that from the details of WallGraphics in the API documentation.

Any suggestions as to how this could be achieved would be gratefully received.

Thanks,

Hugh

Hi Hugh,

For reference, here’s the wall sandcastle example. I would add the wall as it’s own separate entity, like so:

viewer.entities.add({

wall : {

    positions: // list of wall positions

material : Cesium.Color.BLUE.withAlpha(0. 5),
outline : true,
outlineColor : Cesium.Color.BLACK

}

});

Secondly, do you want the wall to be static? If so, you should just be able to set the positions property to the list of the computed positions. Otherwise, I’m not sure exactly what behavior you want. Could you provide an example?

Thanks,

Gabby

Hi Gabby,

I want the wall to appear underneath a moving entity, but only trailing it.

Thanks,

Hugh

Ok, I see. I think your best bet would be to keep a list of the wall positions, and update it in a callbackProperty with the current position of the moving entity. Something like this:

var wallPositions = ;

function updateWallPositions(time) {

var position = entity.position.getValue(time);

wallPositions.push(position);

return wallPositions;

}

viewer.entities.add({

wall : {

    positions: new Cesium.CallbackProperty(updateWallPositions, false),

material : Cesium.Color.BLUE.withAlpha(0. 5),
outline : true,
outlineColor : Cesium.Color.BLACK

}

});

Aha! Genius!

Thank you.

Hi, Grabby

the wall follows the plane trace with your example, but an error occurred in the end. by the way, the plane trace data comes from czml path example of Sandcastle. how can I avoid or hide this error? thanks.

Thanks

Jorbin

Cannot read property ‘x’ of undefined,maybe it occurs on computePositions()

Hi Jorbin,

I have a working Sandcastle example with loading CZML here. If you are having more problems, please provide a code example so we can figure out the issue.

Thanks!

Gabby

I also used this approach, but with an impact on performance.

When and how often is the CallBack invoked?

I decided to create a timer (that fires once a second) outside the Cesium rendering loop to add a position to the wall for each entity in the viewer. Better performance.

Can I use SampledPositionProperty for the wall positions?
Do I need to set the entity availability property for this?
The SampledPositionProperty did not seem to work - even with availability set. Only re-assigning the complete array of positions works (which I think yields in a performance overhead).

Any suggestions on best approach?

I.e. re-assgining complete position array?
Use SampledPositionProperty? (and how)

Remember that Cesium’s time dynamic properties are time-based, not tick-based. So there is no frame rate for how often a CallbackProperty is invoked. It depends entirely on how often this property is getting evaluated (it could be anywhere from 0 times per frame to multiple times per frame). Our discussion in this thread has more explanation:

https://groups.google.com/d/msg/cesium-dev/CmaPzdlQdfQ/1FuC1zyPFQAJ

Feel free to start a new thread with a Sandcastle of your working solution that re-assigns the complete array of positions, and I’d be happy to take a look and see if there’s a way to speed that up.

Hi Gabby,

I ran the working Sandcastle example but the animation crashed at the end of the position. I looked at the error log but had no clue as to why it ran smoothly until the end of the track. Could you take look?

Thanks.