Dynamic Updates |
Primitives support dynamic updates to their position and other per-position data via Set and SetPartial methods.
Primitives that are defined by a single position, such as ModelPrimitive, provide a Position property, to get and set the primitive's position. Primitives that are defined by a list of positions, such as PolylinePrimitive and PointBatchPrimitive, provide both Set and SetPartial methods to update either all of their positions or a subset of them.
Use a Set method to update all of the positions in a primitive. The primitive's old positions will be replaced with the given positions. The code below shows how to update a polyline with surface points using Set. Suppose the polyline represents a range ring around an object. When the object moves, the range ring must also move, so we must update all of its positions.
CentralBody earth = CentralBodiesFacet.GetFromContext().Earth;
SurfaceShapesResult shape = SurfaceShapes.ComputeCircleCartographic(earth, center, 20000.0);
line.Set(shape.Positions);
Tip |
---|
If you plan on calling a Set method frequently, initialize the primitive with SetHint.Frequent, as described in the Set Hint topic. |
Use a SetPartial method to update a subset of positions in a primitive. For example, if one point batch primitive represents thousands of objects and only a few dozen move at a time, use SetPartial to update just those positions, instead of calling Set to update all of the positions. In order to call SetPartial methods, the primitive must be initialized with SetHint.Partial. See the Set Hint topic for more information.
SetPartial methods take a collection of positions, plus a collection of indices that maps the corresponding position to a position already in the primitive. The following example creates a point batch with 10 positions then updates 4 of the positions:
List<Cartesian> originalPositions = new List<Cartesian> { new Cartesian(6500000.0, 0.0, 0.0), new Cartesian(6600000.0, 0.0, 0.0), new Cartesian(6700000.0, 0.0, 0.0), new Cartesian(6800000.0, 0.0, 0.0), new Cartesian(6900000.0, 0.0, 0.0), new Cartesian(7000000.0, 0.0, 0.0), new Cartesian(7100000.0, 0.0, 0.0), new Cartesian(7200000.0, 0.0, 0.0), new Cartesian(7300000.0, 0.0, 0.0), new Cartesian(7400000.0, 0.0, 0.0) }; PointBatchPrimitive batch = new PointBatchPrimitive(SetHint.Partial); batch.Set(originalPositions); batch.PixelSize = 5.0f; SceneManager.Primitives.Add(batch); // Modify 4 positions with SetPartial List<Cartesian> newPositions = new List<Cartesian> { new Cartesian(8000000.0, 0.0, 0.0), new Cartesian(8100000.0, 0.0, 0.0), new Cartesian(8200000.0, 0.0, 0.0), new Cartesian(8300000.0, 0.0, 0.0) }; List<int> indices = new List<int> { 3, 6, 8, 9 }; batch.SetPartial(newPositions, indices, IndicesOrderHint.SortedAscending);
The indices allow random access updates to positions in the primitives. The indices do not need to be consecutive, nor do they need to be sorted. However, if you can easily provide positions sorted in ascending order, pass IndicesOrderHint.SortedAscending for best performance.