Hi,
I am new to CesiumJS and looked at some code example in the Sandcastle. Currently I try to extend the example of a polyline that can be drawn on a map and is clamped to the terrain. Now I would like to add a 3D model that moves along this polyline back and forth but stays at this polyline that is clamped to the terrain so that the 3D model moves along this line and doesn’t collide with the terrain. I managed to add a 3D model at the beginning at the first point at the polyline, but the model collides now with the terrain. Can you please give me an example on how to do this? The polyline only has e.g. 3 points but the line is clamped and drawn correctly.
Thank you in advance!
Hi @Lisi ,
Thanks for your post and welcome to the Cesium community.
You should be able to get this working with current API with some variation depending on the details of your approach. Here is an example in our sandcastle tool using the entity API.
A few things to note:
-
Use the timeline controls at the bottom of the Cesium Sandcastle viewer to advance the scene time, and you will see the model move along the specified path.
-
The scene uses CesiumWorldTerrain so the height reference of the model is set to CLAMP_TO_TERRAIN as follows
heightReference: Cesium.HeightReference.CLAMP_TO_TERRAIN
. This positions the model relative to the terrain at each timestep. You can see other options such as positioning relative to 3DTiles in this sandcastle example Cesium Sandcastle -
The path the model travels is set with SampledPositionProperty, to which we supply the start and end positions as follows
const positionProperty = new Cesium.SampledPositionProperty();
positionProperty.addSample(startTime, start);
positionProperty.addSample(stopTime, end);
- Showing the polyline is optional and redundent, the path for the model to follow is specified in the PositionProperty field, but the polyline also sets
clampToGround: true
.
Hope that helps and please let us know if you have further questions.
Thanks,
Luke
Thank you!
Does this mean I always have to use the animation? In the end the object should move back and forth in an endless loop.
BR, Elisabeth