|
| 1 | +// @ts-check |
| 2 | + |
| 3 | +import BufferPrimitiveCollection from "./BufferPrimitiveCollection.js"; |
| 4 | +import BufferPoint from "./BufferPoint.js"; |
| 5 | +import Cartesian3 from "../Core/Cartesian3.js"; |
| 6 | +import Frozen from "../Core/Frozen.js"; |
| 7 | + |
| 8 | +/** @import Color from "../Core/Color.js"; */ |
| 9 | +/** @import FrameState from "./FrameState.js" */ |
| 10 | + |
| 11 | +/** |
| 12 | + * @typedef {object} BufferPointOptions |
| 13 | + * @property {boolean} [show=true] |
| 14 | + * @property {Color} [color=Color.WHITE] |
| 15 | + * @property {Cartesian3} [position=Cartesian3.ZERO] |
| 16 | + * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy. |
| 17 | + */ |
| 18 | + |
| 19 | +/** |
| 20 | + * Collection of points held in ArrayBuffer storage for performance and memory optimization. |
| 21 | + * |
| 22 | + * <p>Default buffer memory allocation is arbitrary, and collections cannot be resized, |
| 23 | + * so specific per-buffer capacities should be provided in the collection |
| 24 | + * constructor when available.</p> |
| 25 | + * |
| 26 | + * @example |
| 27 | + * const collection = new BufferPointCollection({primitiveCountMax: 1024}); |
| 28 | + * |
| 29 | + * const point = new BufferPoint(); |
| 30 | + * |
| 31 | + * // Create a new point, temporarily bound to 'point' local variable. |
| 32 | + * collection.add({ |
| 33 | + * position: new Cartesian3(0.0, 0.0, 0.0), |
| 34 | + * color: Color.WHITE, |
| 35 | + * }, point); |
| 36 | + * |
| 37 | + * // Iterate over all points in collection, temporarily binding 'point' |
| 38 | + * // local variable to each, and updating point color. |
| 39 | + * for (let i = 0; i < collection.primitiveCount; i++) { |
| 40 | + * collection.get(i, point); |
| 41 | + * point.setColor(Color.RED); |
| 42 | + * } |
| 43 | + * |
| 44 | + * @see BufferPoint |
| 45 | + * @see BufferPrimitiveCollection |
| 46 | + * @extends BufferPrimitiveCollection<BufferPoint> |
| 47 | + * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy. |
| 48 | + */ |
| 49 | +class BufferPointCollection extends BufferPrimitiveCollection { |
| 50 | + /** |
| 51 | + * @param {object} options |
| 52 | + * @param {number} [options.primitiveCountMax=BufferPrimitiveCollection.DEFAULT_CAPACITY] |
| 53 | + * @param {boolean} [options.show=true] |
| 54 | + * @param {boolean} [options.debugShowBoundingVolume=false] |
| 55 | + */ |
| 56 | + constructor(options = Frozen.EMPTY_OBJECT) { |
| 57 | + super({ ...options, vertexCountMax: options.primitiveCountMax }); |
| 58 | + } |
| 59 | + |
| 60 | + _getCollectionClass() { |
| 61 | + return BufferPointCollection; |
| 62 | + } |
| 63 | + |
| 64 | + _getPrimitiveClass() { |
| 65 | + return BufferPoint; |
| 66 | + } |
| 67 | + |
| 68 | + ///////////////////////////////////////////////////////////////////////////// |
| 69 | + // COLLECTION LIFECYCLE |
| 70 | + |
| 71 | + /** |
| 72 | + * @param {BufferPointCollection} collection |
| 73 | + * @returns {BufferPointCollection} |
| 74 | + * @override |
| 75 | + * @ignore |
| 76 | + */ |
| 77 | + static _cloneEmpty(collection) { |
| 78 | + return new BufferPointCollection({ |
| 79 | + primitiveCountMax: collection.primitiveCountMax, |
| 80 | + }); |
| 81 | + } |
| 82 | + |
| 83 | + ///////////////////////////////////////////////////////////////////////////// |
| 84 | + // PRIMITIVE LIFECYCLE |
| 85 | + |
| 86 | + /** |
| 87 | + * Adds a new point to the collection, with the specified options. A |
| 88 | + * {@link BufferPoint} instance is linked to the new point, using |
| 89 | + * the 'result' argument if given, or a new instance if not. For repeated |
| 90 | + * calls, prefer to reuse a single BufferPoint instance rather than |
| 91 | + * allocating a new instance on each call. |
| 92 | + * |
| 93 | + * @param {BufferPointOptions} options |
| 94 | + * @param {BufferPoint} result |
| 95 | + * @returns {BufferPoint} |
| 96 | + * @override |
| 97 | + */ |
| 98 | + add(options, result = new BufferPoint()) { |
| 99 | + super.add(options, result); |
| 100 | + |
| 101 | + result._setUint32( |
| 102 | + BufferPoint.Layout.POSITION_OFFSET_U32, |
| 103 | + this._positionCount++, |
| 104 | + ); |
| 105 | + result.setPosition(options.position ?? Cartesian3.ZERO); |
| 106 | + |
| 107 | + return result; |
| 108 | + } |
| 109 | + |
| 110 | + ///////////////////////////////////////////////////////////////////////////// |
| 111 | + // RENDER |
| 112 | + |
| 113 | + /** |
| 114 | + * @param {FrameState} frameState |
| 115 | + * @ignore |
| 116 | + */ |
| 117 | + update(frameState) { |
| 118 | + super.update(frameState); |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | +export default BufferPointCollection; |
0 commit comments