智慧水务管理系统 - 精河县供水工程综合管理平台

BufferPointCollection.js 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // @ts-check
  2. import BufferPrimitiveCollection from "./BufferPrimitiveCollection.js";
  3. import BufferPoint from "./BufferPoint.js";
  4. import Cartesian3 from "../Core/Cartesian3.js";
  5. import Frozen from "../Core/Frozen.js";
  6. import renderPoints from "./renderBufferPointCollection.js";
  7. import BufferPointMaterial from "./BufferPointMaterial.js";
  8. /** @import BlendOption from "./BlendOption.js"; */
  9. /** @import BoundingSphere from "../Core/BoundingSphere.js"; */
  10. /** @import ComponentDatatype from "../Core/ComponentDatatype.js"; */
  11. /** @import Matrix4 from "../Core/Matrix4.js"; */
  12. /** @import FrameState from "./FrameState.js"; */
  13. /**
  14. * @typedef {object} BufferPointOptions
  15. * @property {Matrix4} [modelMatrix=Matrix4.IDENTITY] Transforms geometry from model to world coordinates.
  16. * @property {boolean} [show=true]
  17. * @property {BufferPointMaterial} [material=BufferPointMaterial.DEFAULT_MATERIAL]
  18. * @property {number} [featureId]
  19. * @property {object} [pickObject]
  20. * @property {Cartesian3} [position=Cartesian3.ZERO]
  21. * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
  22. */
  23. /**
  24. * Collection of points held in ArrayBuffer storage for performance and memory optimization.
  25. *
  26. * <p>Default buffer memory allocation is arbitrary, and collections cannot be resized,
  27. * so specific per-buffer capacities should be provided in the collection
  28. * constructor when available.</p>
  29. *
  30. * @example
  31. * const collection = new BufferPointCollection({primitiveCountMax: 1024});
  32. *
  33. * const point = new BufferPoint();
  34. * const material = new BufferPointMaterial({color: Color.WHITE});
  35. *
  36. * // Create a new point, temporarily bound to 'point' local variable.
  37. * collection.add({
  38. * position: new Cartesian3(0.0, 0.0, 0.0),
  39. * material
  40. * }, point);
  41. *
  42. * // Iterate over all points in collection, temporarily binding 'point'
  43. * // local variable to each, and updating point material.
  44. * for (let i = 0; i < collection.primitiveCount; i++) {
  45. * collection.get(i, point);
  46. * point.setMaterial(material);
  47. * }
  48. *
  49. * @see BufferPoint
  50. * @see BufferPrimitiveCollection
  51. * @extends BufferPrimitiveCollection<BufferPoint>
  52. * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
  53. */
  54. class BufferPointCollection extends BufferPrimitiveCollection {
  55. /**
  56. * @param {object} options
  57. * @param {Matrix4} [options.modelMatrix=Matrix4.IDENTITY] Transforms geometry from model to world coordinates.
  58. * @param {number} [options.primitiveCountMax=BufferPrimitiveCollection.DEFAULT_CAPACITY]
  59. * @param {ComponentDatatype} [options.positionDatatype=ComponentDatatype.DOUBLE]
  60. * @param {boolean} [options.positionNormalized=false]
  61. * @param {boolean} [options.show=true]
  62. * @param {boolean} [options.allowPicking=false] When <code>true</code>, primitives are pickable with {@link Scene#pick}. When <code>false</code>, memory and initialization cost are lower.
  63. * @param {BoundingSphere} [options.boundingVolume] Bounding volume, in world space, for the collection. When
  64. * unspecified, a bounding volume is computed automatically and updated when primitive positions change. When
  65. * specified, users are responsible for updating bounding volume as needed. Pre-computing the bounding volume
  66. * manually, and updating it only as needed, will improve performance for larger dynamic collections.
  67. * @param {boolean} [options.debugShowBoundingVolume=false]
  68. * @param {BlendOption} [options.blendOption=BlendOption.TRANSLUCENT]
  69. */
  70. constructor(options = Frozen.EMPTY_OBJECT) {
  71. super({ ...options, vertexCountMax: options.primitiveCountMax });
  72. }
  73. _getCollectionClass() {
  74. return BufferPointCollection;
  75. }
  76. _getPrimitiveClass() {
  77. return BufferPoint;
  78. }
  79. _getMaterialClass() {
  80. return BufferPointMaterial;
  81. }
  82. /////////////////////////////////////////////////////////////////////////////
  83. // COLLECTION LIFECYCLE
  84. /**
  85. * @param {BufferPointCollection} collection
  86. * @returns {BufferPointCollection}
  87. * @override
  88. * @ignore
  89. */
  90. static _cloneEmpty(collection) {
  91. return new BufferPointCollection({
  92. primitiveCountMax: collection.primitiveCountMax,
  93. positionDatatype: collection.positionDatatype,
  94. positionNormalized: collection.positionNormalized,
  95. });
  96. }
  97. /////////////////////////////////////////////////////////////////////////////
  98. // PRIMITIVE LIFECYCLE
  99. /**
  100. * Adds a new point to the collection, with the specified options. A
  101. * {@link BufferPoint} instance is linked to the new point, using
  102. * the 'result' argument if given, or a new instance if not. For repeated
  103. * calls, prefer to reuse a single BufferPoint instance rather than
  104. * allocating a new instance on each call.
  105. *
  106. * @param {BufferPointOptions} options
  107. * @param {BufferPoint} result
  108. * @returns {BufferPoint}
  109. * @override
  110. */
  111. add(options, result = new BufferPoint()) {
  112. super.add(options, result);
  113. result._setUint32(
  114. BufferPoint.Layout.POSITION_OFFSET_U32,
  115. this._positionCount++,
  116. );
  117. result.setPosition(options.position ?? Cartesian3.ZERO);
  118. return result;
  119. }
  120. /////////////////////////////////////////////////////////////////////////////
  121. // RENDER
  122. /**
  123. * @param {FrameState} frameState
  124. * @ignore
  125. */
  126. update(frameState) {
  127. super.update(frameState);
  128. const passes = frameState.passes;
  129. if (this.show && (passes.render || passes.pick)) {
  130. this._renderContext = renderPoints(this, frameState, this._renderContext);
  131. }
  132. }
  133. }
  134. export default BufferPointCollection;