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, which gets and sets 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 positions passed to Set. The code below shows how to update a polyline with surface points using Set. Perhaps the polyline represents a range ring around an object. When the object moves, the range ring needs to also move, so all of its positions are updated.
[C#] | Copy Code |
---|---|
If you plan on calling a Set method frequently, initialize the primitive with SetHint.Frequent as described in the Set Hint Performance Overview.
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. To call SetPartial, the primitive must be initialized with SetHint.Partial. See the Set Hint Performance Overview.
SetPartial takes a collection of positions. In addition, SetPartial also takes a collection of indices that maps the corresponding position from the position's collection to a position already in the primitive. The following example creates a point batch with 10 positions then updates 4 of the positions with SetPartial.
[C#] | Copy Code | |
---|---|---|
|
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, although if you can easily provide positions sorted in ascending order, pass IndicesOrderHint.SortedAscending for best performance.