@cesium/engine 23.0.1 → 24.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/Build/Workers/{chunk-G6MJ3ZW3.js → chunk-2N4KDHS3.js} +10 -10
  2. package/Build/Workers/{chunk-C6HHBKT5.js → chunk-44EMEGKW.js} +5 -5
  3. package/Build/Workers/{chunk-TNXOPEIG.js → chunk-4TIG36AW.js} +12 -12
  4. package/Build/Workers/{chunk-PQTSXJBJ.js → chunk-5A2SW66E.js} +16 -16
  5. package/Build/Workers/{chunk-TXYQNXNW.js → chunk-5GXYJQ2K.js} +3 -3
  6. package/Build/Workers/{chunk-O67UP5YO.js → chunk-63SIWPLS.js} +13 -13
  7. package/Build/Workers/{chunk-CVAAIRNP.js → chunk-6MPGQEHA.js} +2 -2
  8. package/Build/Workers/{chunk-LHFC4R7Z.js → chunk-6RMS4S72.js} +6 -6
  9. package/Build/Workers/{chunk-77DJBHMI.js → chunk-6WLHJFD3.js} +7 -7
  10. package/Build/Workers/{chunk-HXEPZWJN.js → chunk-72VYSVEW.js} +9 -9
  11. package/Build/Workers/{chunk-VPWYHFQA.js → chunk-7MDYBRYJ.js} +4 -4
  12. package/Build/Workers/{chunk-XPMXRJDD.js → chunk-7O5XJTVE.js} +5 -5
  13. package/Build/Workers/{chunk-UEWYSOFD.js → chunk-7QRFIKWQ.js} +2 -2
  14. package/Build/Workers/{chunk-3UQ2YMPP.js → chunk-7TYLCBGK.js} +8 -8
  15. package/Build/Workers/{chunk-GLCPE2BJ.js → chunk-7X322WP2.js} +13 -13
  16. package/Build/Workers/{chunk-2OBWHTIC.js → chunk-A47HVBC5.js} +7 -7
  17. package/Build/Workers/{chunk-CID5SY7L.js → chunk-AF3MU2RL.js} +5 -5
  18. package/Build/Workers/{chunk-BTP3634E.js → chunk-AJLTU6PF.js} +1 -1
  19. package/Build/Workers/{chunk-YSJRB2UZ.js → chunk-AMIHNSST.js} +2 -2
  20. package/Build/Workers/{chunk-QPXGGVHC.js → chunk-B6SCUUFP.js} +10 -10
  21. package/Build/Workers/{chunk-QNABVTTP.js → chunk-BJD6QGXZ.js} +12 -12
  22. package/Build/Workers/{chunk-RZX6LOG6.js → chunk-C6P4IG5P.js} +6 -6
  23. package/Build/Workers/{chunk-4JJQRZYL.js → chunk-D4EJ2NXG.js} +17 -17
  24. package/Build/Workers/{chunk-K7UTK4OM.js → chunk-DHKPFLSJ.js} +1 -1
  25. package/Build/Workers/{chunk-S53HSRT6.js → chunk-DVB56LG7.js} +6 -6
  26. package/Build/Workers/{chunk-PBECJOWF.js → chunk-EDXL4W76.js} +2 -2
  27. package/Build/Workers/{chunk-ALTCIHRH.js → chunk-EV3VGO6Y.js} +17 -17
  28. package/Build/Workers/{chunk-UOQB7XQI.js → chunk-GOQBUCXH.js} +10 -10
  29. package/Build/Workers/{chunk-TMCTZ5E3.js → chunk-GQUNK2XC.js} +14 -14
  30. package/Build/Workers/{chunk-PAFMAR7A.js → chunk-HKUES6UG.js} +12 -12
  31. package/Build/Workers/{chunk-6U5QMZU3.js → chunk-HRHRYFHS.js} +9 -9
  32. package/Build/Workers/{chunk-PUO7BYDY.js → chunk-HXJMS2ZI.js} +1 -1
  33. package/Build/Workers/{chunk-FXSRA5UG.js → chunk-ILMFADZA.js} +4 -4
  34. package/Build/Workers/{chunk-U4SWB6TI.js → chunk-ISY4EZCA.js} +4 -4
  35. package/Build/Workers/{chunk-PGZ3B6CB.js → chunk-J6AW5YHS.js} +14 -14
  36. package/Build/Workers/{chunk-VX774SWE.js → chunk-JCI63T3K.js} +6 -6
  37. package/Build/Workers/{chunk-54O3AGOA.js → chunk-KLPGTXS3.js} +6 -6
  38. package/Build/Workers/{chunk-CNLXMOPM.js → chunk-LIB2H534.js} +10 -10
  39. package/Build/Workers/{chunk-H3TVRJLY.js → chunk-LXMCPFFS.js} +4 -4
  40. package/Build/Workers/{chunk-DNMASBMH.js → chunk-MKM27KGV.js} +2 -2
  41. package/Build/Workers/{chunk-66OWUDO7.js → chunk-N65BAKSH.js} +8 -8
  42. package/Build/Workers/{chunk-ZEMJQKHD.js → chunk-NKT5K3K3.js} +11 -11
  43. package/Build/Workers/{chunk-EIC3VAOZ.js → chunk-NPF7SSHZ.js} +7 -7
  44. package/Build/Workers/{chunk-YDR5LX5Z.js → chunk-PVV64VFW.js} +1 -1
  45. package/Build/Workers/{chunk-FKU77FNM.js → chunk-Q3C6VQH6.js} +4 -4
  46. package/Build/Workers/{chunk-CYOPNGPX.js → chunk-RQNJD3O4.js} +12 -12
  47. package/Build/Workers/{chunk-IJ3SUMK3.js → chunk-UIGVOKKI.js} +1 -1
  48. package/Build/Workers/{chunk-TFPG3ZKW.js → chunk-UQU4RXLT.js} +27 -19
  49. package/Build/Workers/{chunk-N6HRZLS6.js → chunk-VLDEUTOP.js} +2 -2
  50. package/Build/Workers/{chunk-MNSNOONX.js → chunk-VMVOUQ5J.js} +7 -7
  51. package/Build/Workers/{chunk-OZYB3AOR.js → chunk-XJRBB253.js} +11 -11
  52. package/Build/Workers/{chunk-B2VA6IEL.js → chunk-XY6HMDGI.js} +5 -5
  53. package/Build/Workers/{chunk-2M7DKGLW.js → chunk-Y7HNNPNK.js} +10 -10
  54. package/Build/Workers/{chunk-CJ7ZDY77.js → chunk-YAOZMOFL.js} +5 -5
  55. package/Build/Workers/{chunk-FCJQO4NC.js → chunk-YJZGW74L.js} +8 -8
  56. package/Build/Workers/{chunk-JUKGMJX7.js → chunk-YQFTYQMZ.js} +1 -1
  57. package/Build/Workers/{chunk-HNDE73JK.js → chunk-ZBZRTRJB.js} +10 -10
  58. package/Build/Workers/combineGeometry.js +24 -24
  59. package/Build/Workers/createBoxGeometry.js +18 -18
  60. package/Build/Workers/createBoxOutlineGeometry.js +16 -16
  61. package/Build/Workers/createCircleGeometry.js +26 -26
  62. package/Build/Workers/createCircleOutlineGeometry.js +19 -19
  63. package/Build/Workers/createCoplanarPolygonGeometry.js +33 -33
  64. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +31 -31
  65. package/Build/Workers/createCorridorGeometry.js +29 -29
  66. package/Build/Workers/createCorridorOutlineGeometry.js +28 -28
  67. package/Build/Workers/createCylinderGeometry.js +20 -20
  68. package/Build/Workers/createCylinderOutlineGeometry.js +18 -18
  69. package/Build/Workers/createEllipseGeometry.js +26 -26
  70. package/Build/Workers/createEllipseOutlineGeometry.js +19 -19
  71. package/Build/Workers/createEllipsoidGeometry.js +19 -19
  72. package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -18
  73. package/Build/Workers/createFrustumGeometry.js +18 -18
  74. package/Build/Workers/createFrustumOutlineGeometry.js +18 -18
  75. package/Build/Workers/createGeometry.js +24 -24
  76. package/Build/Workers/createGroundPolylineGeometry.js +22 -22
  77. package/Build/Workers/createPlaneGeometry.js +16 -16
  78. package/Build/Workers/createPlaneOutlineGeometry.js +15 -15
  79. package/Build/Workers/createPolygonGeometry.js +32 -32
  80. package/Build/Workers/createPolygonOutlineGeometry.js +30 -30
  81. package/Build/Workers/createPolylineGeometry.js +25 -25
  82. package/Build/Workers/createPolylineVolumeGeometry.js +31 -31
  83. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +27 -27
  84. package/Build/Workers/createRectangleGeometry.js +27 -27
  85. package/Build/Workers/createRectangleOutlineGeometry.js +20 -20
  86. package/Build/Workers/createSimplePolylineGeometry.js +23 -23
  87. package/Build/Workers/createSphereGeometry.js +19 -19
  88. package/Build/Workers/createSphereOutlineGeometry.js +18 -18
  89. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  90. package/Build/Workers/createVectorTileClampedPolylines.js +14 -14
  91. package/Build/Workers/createVectorTileGeometries.js +24 -24
  92. package/Build/Workers/createVectorTilePoints.js +13 -13
  93. package/Build/Workers/createVectorTilePolygons.js +22 -22
  94. package/Build/Workers/createVectorTilePolylines.js +14 -14
  95. package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +25 -25
  96. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +22 -22
  97. package/Build/Workers/createVerticesFromHeightmap.js +22 -22
  98. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +20 -20
  99. package/Build/Workers/createWallGeometry.js +25 -25
  100. package/Build/Workers/createWallOutlineGeometry.js +24 -24
  101. package/Build/Workers/decodeDraco.js +10 -10
  102. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  103. package/Build/Workers/decodeI3S.js +12 -12
  104. package/Build/Workers/gaussianSplatSorter.js +4 -4
  105. package/Build/Workers/gaussianSplatTextureGenerator.js +4 -4
  106. package/Build/Workers/incrementallyBuildTerrainPicker.js +10 -10
  107. package/Build/Workers/transcodeKTX2.js +6 -6
  108. package/Build/Workers/transferTypedArrayTest.js +1 -1
  109. package/Build/Workers/upsampleQuantizedTerrainMesh.js +22 -22
  110. package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +25 -25
  111. package/Source/Core/BoundingSphere.js +1 -1
  112. package/Source/Core/Cartesian2.js +7 -5
  113. package/Source/Core/Cartesian3.js +8 -6
  114. package/Source/Core/Cartesian4.js +8 -6
  115. package/Source/Core/Color.js +5 -3
  116. package/Source/Core/DeveloperError.js +2 -1
  117. package/Source/Core/ITwinPlatform.js +1 -0
  118. package/Source/Core/Ion.js +1 -1
  119. package/Source/Core/S2Cell.js +2 -2
  120. package/Source/Core/TerrainMesh.js +10 -1
  121. package/Source/Core/TerrainPicker.js +1 -0
  122. package/Source/Core/WallGeometry.js +1 -1
  123. package/Source/Core/WallOutlineGeometry.js +1 -1
  124. package/Source/Core/assert.js +27 -0
  125. package/Source/Core/globalTypes.js +4 -0
  126. package/Source/DataSources/CzmlDataSource.js +9 -0
  127. package/Source/DataSources/PathGraphics.js +13 -0
  128. package/Source/DataSources/PathVisualizer.js +330 -18
  129. package/Source/DataSources/StaticGeometryColorBatch.js +7 -2
  130. package/Source/DataSources/StaticGeometryPerMaterialBatch.js +7 -2
  131. package/Source/DataSources/StaticGroundGeometryPerMaterialBatch.js +3 -1
  132. package/Source/DataSources/StaticGroundPolylinePerMaterialBatch.js +3 -1
  133. package/Source/Renderer/Context.js +1 -1
  134. package/Source/Renderer/RenderState.js +2 -2
  135. package/Source/Renderer/VertexArray.js +80 -0
  136. package/Source/Scene/ArcGisMapService.js +1 -1
  137. package/Source/Scene/BillboardCollection.js +65 -364
  138. package/Source/Scene/BufferPoint.js +148 -0
  139. package/Source/Scene/BufferPointCollection.js +135 -0
  140. package/Source/Scene/BufferPointMaterial.js +95 -0
  141. package/Source/Scene/BufferPolygon.js +516 -0
  142. package/Source/Scene/BufferPolygonCollection.js +368 -0
  143. package/Source/Scene/BufferPolygonMaterial.js +41 -0
  144. package/Source/Scene/BufferPolyline.js +185 -0
  145. package/Source/Scene/BufferPolylineCollection.js +136 -0
  146. package/Source/Scene/BufferPolylineMaterial.js +93 -0
  147. package/Source/Scene/BufferPrimitive.js +347 -0
  148. package/Source/Scene/BufferPrimitiveCollection.js +702 -0
  149. package/Source/Scene/BufferPrimitiveMaterial.js +140 -0
  150. package/Source/Scene/Cesium3DTileContent.js +5 -1
  151. package/Source/Scene/Cesium3DTileContentFactory.js +9 -0
  152. package/Source/Scene/Cesium3DTileStyle.js +22 -0
  153. package/Source/Scene/Cesium3DTileset.js +1 -0
  154. package/Source/Scene/ClippingPolygonCollection.js +270 -101
  155. package/Source/Scene/CubeMapPanorama.js +4 -4
  156. package/Source/Scene/GaussianSplat3DTileContent.js +40 -46
  157. package/Source/Scene/GaussianSplatPrimitive.js +413 -70
  158. package/Source/Scene/GetFeatureInfoFormat.js +3 -3
  159. package/Source/Scene/GltfLoader.js +215 -34
  160. package/Source/Scene/GltfSpzLoader.js +109 -0
  161. package/Source/Scene/ITwinData.js +1 -0
  162. package/Source/Scene/Label.js +32 -0
  163. package/Source/Scene/LabelCollection.js +14 -13
  164. package/Source/Scene/Material.js +2 -0
  165. package/Source/Scene/Megatexture.js +1 -0
  166. package/Source/Scene/MetadataClassProperty.js +24 -10
  167. package/Source/Scene/MetadataComponentType.js +115 -23
  168. package/Source/Scene/Model/CustomShaderPipelineStage.js +3 -1
  169. package/Source/Scene/Model/EdgeVisibilityPipelineStage.js +761 -263
  170. package/Source/Scene/Model/MaterialPipelineStage.js +147 -0
  171. package/Source/Scene/Model/MetadataPipelineStage.js +3 -3
  172. package/Source/Scene/Model/ModelDrawCommand.js +6 -0
  173. package/Source/Scene/Model/ModelReader.js +1 -1
  174. package/Source/Scene/Model/ModelUtility.js +3 -1
  175. package/Source/Scene/Model/createVectorTileBuffersFromModelComponents.js +330 -0
  176. package/Source/Scene/ModelComponents.js +1632 -1542
  177. package/Source/Scene/PickedMetadataInfo.js +1 -0
  178. package/Source/Scene/ScreenSpaceCameraController.js +13 -0
  179. package/Source/Scene/SkyBox.js +17 -8
  180. package/Source/Scene/TileBoundingRegion.js +1 -1
  181. package/Source/Scene/TileBoundingS2Cell.js +1 -1
  182. package/Source/Scene/TileBoundingSphere.js +1 -1
  183. package/Source/Scene/TweenCollection.js +7 -0
  184. package/Source/Scene/VectorGltf3DTileContent.js +382 -0
  185. package/Source/Scene/VertexAttributeSemantic.js +14 -0
  186. package/Source/Scene/WebMapServiceImageryProvider.js +2 -2
  187. package/Source/Scene/WebMapTileServiceImageryProvider.js +366 -131
  188. package/Source/Scene/parseStructuralMetadata.js +97 -37
  189. package/Source/Scene/renderBufferPointCollection.js +334 -0
  190. package/Source/Scene/renderBufferPolygonCollection.js +386 -0
  191. package/Source/Scene/renderBufferPolylineCollection.js +529 -0
  192. package/Source/Shaders/BillboardCollectionFS.glsl +2 -77
  193. package/Source/Shaders/BillboardCollectionFS.js +2 -77
  194. package/Source/Shaders/BillboardCollectionVS.glsl +2 -60
  195. package/Source/Shaders/BillboardCollectionVS.js +2 -60
  196. package/Source/Shaders/BufferPointMaterialFS.glsl +27 -0
  197. package/Source/Shaders/BufferPointMaterialFS.js +29 -0
  198. package/Source/Shaders/BufferPointMaterialVS.glsl +48 -0
  199. package/Source/Shaders/BufferPointMaterialVS.js +50 -0
  200. package/Source/Shaders/BufferPolygonMaterialFS.glsl +13 -0
  201. package/Source/Shaders/BufferPolygonMaterialFS.js +15 -0
  202. package/Source/Shaders/BufferPolygonMaterialVS.glsl +30 -0
  203. package/Source/Shaders/BufferPolygonMaterialVS.js +32 -0
  204. package/Source/Shaders/BufferPolylineMaterialFS.glsl +13 -0
  205. package/Source/Shaders/BufferPolylineMaterialFS.js +15 -0
  206. package/Source/Shaders/BufferPolylineMaterialVS.glsl +49 -0
  207. package/Source/Shaders/BufferPolylineMaterialVS.js +51 -0
  208. package/Source/Shaders/Model/EdgeVisibilityStageFS.glsl +34 -48
  209. package/Source/Shaders/Model/EdgeVisibilityStageFS.js +34 -49
  210. package/Source/Shaders/Model/EdgeVisibilityStageVS.glsl +98 -0
  211. package/Source/Shaders/Model/EdgeVisibilityStageVS.js +100 -0
  212. package/Source/Shaders/Model/ModelFS.glsl +15 -0
  213. package/Source/Shaders/Model/ModelFS.js +15 -0
  214. package/Source/Shaders/Model/ModelVS.glsl +8 -0
  215. package/Source/Shaders/Model/ModelVS.js +8 -0
  216. package/Source/Shaders/PolygonSignedDistanceFS.glsl +64 -33
  217. package/Source/Shaders/PolygonSignedDistanceFS.js +64 -33
  218. package/Source/Shaders/PrimitiveGaussianSplatVS.glsl +9 -2
  219. package/Source/Shaders/PrimitiveGaussianSplatVS.js +9 -2
  220. package/Source/Shaders/Voxels/VoxelFS.glsl +1 -1
  221. package/Source/Shaders/Voxels/VoxelFS.js +1 -1
  222. package/Source/Workers/decodeDraco.js +3 -0
  223. package/Source/Workers/decodeI3S.js +5 -2
  224. package/index.d.ts +1007 -111
  225. package/index.js +394 -369
  226. package/package.json +2 -2
@@ -0,0 +1,516 @@
1
+ // @ts-check
2
+
3
+ import assert from "../Core/assert.js";
4
+ import Check from "../Core/Check.js";
5
+ import defined from "../Core/defined.js";
6
+ import BufferPrimitive from "./BufferPrimitive.js";
7
+ import BufferPrimitiveCollection from "./BufferPrimitiveCollection.js";
8
+
9
+ /** @import { TypedArray, TypedArrayConstructor } from "../Core/globalTypes.js"; */
10
+ /** @import BufferPolygonCollection from "./BufferPolygonCollection.js"; */
11
+
12
+ const { ERR_CAPACITY, ERR_RESIZE, ERR_OUT_OF_RANGE } =
13
+ BufferPrimitiveCollection.Error;
14
+
15
+ /**
16
+ * View bound to the underlying buffer data of a {@link BufferPolygonCollection}.
17
+ *
18
+ * <p>BufferPolygon instances are {@link https://en.wikipedia.org/wiki/Flyweight_pattern|flyweights}:
19
+ * a single BufferPolygon instance can be temporarily bound to any conceptual
20
+ * "polygon" in a BufferPolygonCollection, allowing very large collections to be
21
+ * iterated and updated with a minimal memory footprint.</p>
22
+ *
23
+ * <p>Represented as one (1) external linear ring of three (3) or more positions.
24
+ * May optionally define one or more internal linear rings ("holes") within the
25
+ * polygon. Each hole is represented as a single index into the positions array,
26
+ * where the vertex at that index is the start of an internal linear ring that
27
+ * continues along the following vertices until reaching either the vertex
28
+ * index of the next hole, or the end of the vertex list. Stores a precomputed
29
+ * triangulation, represented as three vertex indices per triangle.</p>
30
+ *
31
+ * @see BufferPolygonCollection
32
+ * @see BufferPolygonMaterial
33
+ * @see BufferPrimitive
34
+ * @extends BufferPrimitive
35
+ * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
36
+ */
37
+ class BufferPolygon extends BufferPrimitive {
38
+ /**
39
+ * @type {BufferPolygonCollection}
40
+ * @ignore
41
+ */
42
+ _collection = null;
43
+
44
+ /** @ignore */
45
+ static Layout = {
46
+ ...BufferPrimitive.Layout,
47
+
48
+ /**
49
+ * Offset in collection position array to first vertex in polygon, number
50
+ * of VEC3 elements.
51
+ * @type {number}
52
+ * @ignore
53
+ */
54
+ POSITION_OFFSET_U32: BufferPrimitive.Layout.__BYTE_LENGTH,
55
+
56
+ /**
57
+ * Count of positions (vertices) in this polygon, number of VEC3 elements.
58
+ * @type {number}
59
+ * @ignore
60
+ */
61
+ POSITION_COUNT_U32: BufferPrimitive.Layout.__BYTE_LENGTH + 4,
62
+
63
+ /**
64
+ * Offset in collection holes array to first hole in polygon, number of
65
+ * integer elements.
66
+ * @type {number}
67
+ * @ignore
68
+ */
69
+ HOLE_OFFSET_U32: BufferPrimitive.Layout.__BYTE_LENGTH + 8,
70
+
71
+ /**
72
+ * Count of holes (indices) in this polygon.
73
+ * @type {number}
74
+ * @ignore
75
+ */
76
+ HOLE_COUNT_U32: BufferPrimitive.Layout.__BYTE_LENGTH + 12,
77
+
78
+ /**
79
+ * Offset in collection triangles array to first triangle in polygon,
80
+ * number of VEC3 elements.
81
+ * @type {number}
82
+ * @ignore
83
+ */
84
+ TRIANGLE_OFFSET_U32: BufferPrimitive.Layout.__BYTE_LENGTH + 16,
85
+
86
+ /**
87
+ * Count of triangles in this polygon, number of VEC3 elements.
88
+ * @type {number}
89
+ * @ignore
90
+ */
91
+ TRIANGLE_COUNT_U32: BufferPrimitive.Layout.__BYTE_LENGTH + 20,
92
+
93
+ /**
94
+ * @type {number}
95
+ * @ignore
96
+ */
97
+ __BYTE_LENGTH: BufferPrimitive.Layout.__BYTE_LENGTH + 24,
98
+ };
99
+
100
+ /////////////////////////////////////////////////////////////////////////////
101
+ // LIFECYCLE
102
+
103
+ /**
104
+ * Copies data from source polygon to result. If the result polygon is not
105
+ * new (the last polygon in the collection) then source and result polygons
106
+ * must have the same vertex counts, hole counts, and triangle counts.
107
+ *
108
+ * @param {BufferPolygon} polygon
109
+ * @param {BufferPolygon} result
110
+ * @return {BufferPolygon}
111
+ * @override
112
+ */
113
+ static clone(polygon, result) {
114
+ super.clone(polygon, result);
115
+ result.setPositions(polygon.getPositions());
116
+ result.setHoles(polygon.getHoles());
117
+ result.setTriangles(polygon.getTriangles());
118
+ return result;
119
+ }
120
+
121
+ /////////////////////////////////////////////////////////////////////////////
122
+ // GEOMETRY
123
+
124
+ /**
125
+ * Offset in collection position array to first vertex in polygon, number
126
+ * of VEC3 elements.
127
+ *
128
+ * @type {number}
129
+ * @readonly
130
+ * @ignore
131
+ */
132
+ get vertexOffset() {
133
+ return this._getUint32(BufferPolygon.Layout.POSITION_OFFSET_U32);
134
+ }
135
+
136
+ /**
137
+ * Count of positions (vertices) in this polygon, including both outer ring and
138
+ * internal rings (holes), number of VEC3 elements.
139
+ *
140
+ * @type {number}
141
+ * @readonly
142
+ */
143
+ get vertexCount() {
144
+ return this._getUint32(BufferPolygon.Layout.POSITION_COUNT_U32);
145
+ }
146
+
147
+ /**
148
+ * Returns an array view of this polygon's vertex positions. If 'result'
149
+ * argument is given, vertex positions are written to that array and returned.
150
+ * Otherwise, returns an ArrayView on collection memory — changes to this array
151
+ * will not trigger render updates, which requires `.setPositions()`.
152
+ *
153
+ * @param {TypedArray} [result]
154
+ * return {TypedArray}
155
+ */
156
+ getPositions(result) {
157
+ return this._getPositionsRange(0, this.vertexCount, result);
158
+ }
159
+
160
+ /** @param {TypedArray} positions */
161
+ setPositions(positions) {
162
+ const collection = this._collection;
163
+ const vertexOffset = this.vertexOffset;
164
+ const srcCount = this.vertexCount;
165
+ const dstCount = positions.length / 3;
166
+ const collectionCount = collection.vertexCount + dstCount - srcCount;
167
+
168
+ //>>includeStart('debug', pragmas.debug);
169
+ assert(srcCount === dstCount || this._isResizable(), ERR_RESIZE);
170
+ assert(collectionCount <= collection.vertexCountMax, ERR_CAPACITY);
171
+ //>>includeEnd('debug');
172
+
173
+ collection._positionCount = collectionCount;
174
+ this._setUint32(BufferPolygon.Layout.POSITION_COUNT_U32, dstCount);
175
+
176
+ const positionView = collection._positionView;
177
+ for (let i = 0; i < dstCount; i++) {
178
+ positionView[(vertexOffset + i) * 3] = positions[i * 3];
179
+ positionView[(vertexOffset + i) * 3 + 1] = positions[i * 3 + 1];
180
+ positionView[(vertexOffset + i) * 3 + 2] = positions[i * 3 + 2];
181
+ }
182
+
183
+ collection._makeDirtyBoundingVolume();
184
+ }
185
+
186
+ /**
187
+ * Offset in collection position array to first vertex in polygon's outer
188
+ * linear ring, number of VEC3 elements.
189
+ *
190
+ * @type {number}
191
+ * @readonly
192
+ */
193
+ get outerVertexOffset() {
194
+ return this.vertexOffset;
195
+ }
196
+
197
+ /**
198
+ * Count of positions (vertices) in this polygon's outer linear ring, number
199
+ * of VEC3 elements.
200
+ *
201
+ * @type {number}
202
+ * @readonly
203
+ */
204
+ get outerVertexCount() {
205
+ if (this.holeCount > 0) {
206
+ return this.getHoles()[0];
207
+ }
208
+ return this.vertexCount;
209
+ }
210
+
211
+ /**
212
+ * Returns an array view of this polygon's outer linear ring vertex positions.
213
+ * If 'result' argument is given, vertex positions are written to that array
214
+ * and returned. Otherwise, returns an ArrayView on collection memory —
215
+ * changes to this array will not trigger render updates, which requires
216
+ * `.setPositions()`.
217
+ *
218
+ * @param {TypedArray} [result]
219
+ * @returns {TypedArray}
220
+ */
221
+ getOuterPositions(result) {
222
+ return this._getPositionsRange(0, this.outerVertexCount, result);
223
+ }
224
+
225
+ /**
226
+ * Offset in collection holes array to first hole in polygon, number of
227
+ * integer elements.
228
+ *
229
+ * @type {number}
230
+ * @readonly
231
+ * @ignore
232
+ */
233
+ get holeOffset() {
234
+ return this._getUint32(BufferPolygon.Layout.HOLE_OFFSET_U32);
235
+ }
236
+
237
+ /**
238
+ * Count of holes (indices) in this polygon.
239
+ *
240
+ * @type {number}
241
+ * @readonly
242
+ */
243
+ get holeCount() {
244
+ return this._getUint32(BufferPolygon.Layout.HOLE_COUNT_U32);
245
+ }
246
+
247
+ /**
248
+ * Gets this polygon's hole indices, with each hole represented as a single
249
+ * offset into this polygon's positions array. Each hole implicitly
250
+ * continues along an internal linear ring from that vertex offset until
251
+ * reaching either the end of the positions array, or the next hole offset.
252
+ *
253
+ * If 'result' argument is given, hole indices are written to that array and
254
+ * returned. Otherwise, returns an ArrayView on collection memory — changes
255
+ * to this array will not trigger render updates, which requires `.setHoles()`.
256
+ *
257
+ * @param {TypedArray} [result]
258
+ * @returns {TypedArray}
259
+ */
260
+ getHoles(result) {
261
+ const { holeOffset, holeCount } = this;
262
+ const holeIndexView = this._collection._holeIndexView;
263
+
264
+ if (!defined(result)) {
265
+ const byteOffset =
266
+ holeIndexView.byteOffset + holeOffset * holeIndexView.BYTES_PER_ELEMENT;
267
+ const TypedArray = /** @type {TypedArrayConstructor} */ (
268
+ holeIndexView.constructor
269
+ );
270
+ return new TypedArray(
271
+ /** @type {ArrayBuffer} */ (holeIndexView.buffer),
272
+ byteOffset,
273
+ holeCount,
274
+ );
275
+ }
276
+
277
+ for (let i = 0; i < holeCount; i++) {
278
+ result[i] = holeIndexView[holeOffset + i];
279
+ }
280
+ return result;
281
+ }
282
+
283
+ /**
284
+ * Sets this polygon's hole indices, with holes represented as a single
285
+ * offset into this polygon's positions array. Each hole implicitly
286
+ * continues along an internal linear ring from that vertex offset until
287
+ * reaching either the end of the positions array, or the next hole offset.
288
+ *
289
+ * @param {TypedArray} holes
290
+ */
291
+ setHoles(holes) {
292
+ const collection = this._collection;
293
+ const holeOffset = this.holeOffset;
294
+ const srcCount = this.holeCount;
295
+ const dstCount = holes.length;
296
+ const collectionCount = collection.holeCount + dstCount - srcCount;
297
+
298
+ //>>includeStart('debug', pragmas.debug);
299
+ assert(srcCount === dstCount || this._isResizable(), ERR_RESIZE);
300
+ assert(collectionCount <= collection.holeCountMax, ERR_CAPACITY);
301
+ //>>includeEnd('debug');
302
+
303
+ collection._holeCount = collectionCount;
304
+ this._setUint32(BufferPolygon.Layout.HOLE_COUNT_U32, dstCount);
305
+
306
+ const holeIndexView = collection._holeIndexView;
307
+ for (let i = 0; i < dstCount; i++) {
308
+ holeIndexView[holeOffset + i] = holes[i];
309
+ }
310
+
311
+ collection._makeDirtyBoundingVolume();
312
+ }
313
+
314
+ /**
315
+ * Returns the number of (VEC3) vertices in the specified hole.
316
+ *
317
+ * @param {number} holeIndex
318
+ * @returns {number}
319
+ */
320
+ getHoleVertexCount(holeIndex) {
321
+ const holes = this.getHoles();
322
+
323
+ //>>includeStart('debug', pragmas.debug);
324
+ Check.typeOf.number.greaterThanOrEquals("holeIndex", holeIndex, 0);
325
+ Check.typeOf.number.lessThan("holeIndex", holeIndex, holes.length);
326
+ //>>includeEnd('debug');
327
+
328
+ const holeVertexOffset = holes[holeIndex];
329
+ return holeIndex === holes.length - 1
330
+ ? this.vertexCount - holeVertexOffset
331
+ : holes[holeIndex + 1] - holeVertexOffset;
332
+ }
333
+
334
+ /**
335
+ * Returns an array view of the inner linear ring vertex positions for the
336
+ * specified hole. If 'result' argument is given, vertex positions are written
337
+ * to that array and returned. Otherwise, returns an ArrayView on collection
338
+ * memory — changes to this array will not trigger render updates, which
339
+ * requires `.setPositions()`.
340
+ *
341
+ * @param {number} holeIndex
342
+ * @param {TypedArray} [result]
343
+ * return {TypedArray}
344
+ */
345
+ getHolePositions(holeIndex, result) {
346
+ const holes = this.getHoles();
347
+
348
+ //>>includeStart('debug', pragmas.debug);
349
+ Check.typeOf.number.greaterThanOrEquals("holeIndex", holeIndex, 0);
350
+ Check.typeOf.number.lessThan("holeIndex", holeIndex, holes.length);
351
+ //>>includeEnd('debug');
352
+
353
+ const holeVertexOffset = holes[holeIndex];
354
+ const holeVertexCount = this.getHoleVertexCount(holeIndex);
355
+ return this._getPositionsRange(holeVertexOffset, holeVertexCount, result);
356
+ }
357
+
358
+ /**
359
+ * Internal helper for accessing vertex positions. 'vertexOffset' argument
360
+ * is relative to the start of the polygon's vertex block, with 0 being
361
+ * the first vertex in the polygon. If 'result' argument is given, the
362
+ * requested range of vertices are written to the result array and returned.
363
+ * Otherwise, returns an ArrayView on collection memory.
364
+ *
365
+ * @param {number} vertexOffset
366
+ * @param {number} vertexCount
367
+ * @param {TypedArray} [result]
368
+ * @returns {TypedArray}
369
+ * @private
370
+ */
371
+ _getPositionsRange(vertexOffset, vertexCount, result) {
372
+ const collection = this._collection;
373
+ const positionView = this._collection._positionView;
374
+
375
+ const collectionVertexOffset = this.vertexOffset + vertexOffset;
376
+
377
+ //>>includeStart('debug', pragmas.debug);
378
+ assert(collectionVertexOffset >= 0, ERR_OUT_OF_RANGE);
379
+ assert(collectionVertexOffset < collection.vertexCount, ERR_OUT_OF_RANGE);
380
+ assert(vertexCount > 0, ERR_OUT_OF_RANGE);
381
+ assert(vertexCount <= this.vertexCount, ERR_OUT_OF_RANGE);
382
+ //>>includeEnd('debug');
383
+
384
+ if (!defined(result)) {
385
+ const byteOffset =
386
+ positionView.byteOffset +
387
+ collectionVertexOffset * 3 * positionView.BYTES_PER_ELEMENT;
388
+ const TypedArray = /** @type {TypedArrayConstructor} */ (
389
+ positionView.constructor
390
+ );
391
+ return new TypedArray(
392
+ /** @type {ArrayBuffer} */ (positionView.buffer),
393
+ byteOffset,
394
+ vertexCount * 3,
395
+ );
396
+ }
397
+
398
+ for (let i = 0; i < vertexCount; i++) {
399
+ result[i * 3] = positionView[(collectionVertexOffset + i) * 3];
400
+ result[i * 3 + 1] = positionView[(collectionVertexOffset + i) * 3 + 1];
401
+ result[i * 3 + 2] = positionView[(collectionVertexOffset + i) * 3 + 2];
402
+ }
403
+ return result;
404
+ }
405
+
406
+ /**
407
+ * Offset in collection triangles array to first triangle in polygon,
408
+ * number of VEC3 elements.
409
+ * @type {number}
410
+ * @readonly
411
+ * @ignore
412
+ */
413
+ get triangleOffset() {
414
+ return this._getUint32(BufferPolygon.Layout.TRIANGLE_OFFSET_U32);
415
+ }
416
+
417
+ /**
418
+ * Count of triangles in this polygon, number of VEC3 elements.
419
+ *
420
+ * @type {number}
421
+ * @readonly
422
+ */
423
+ get triangleCount() {
424
+ return this._getUint32(BufferPolygon.Layout.TRIANGLE_COUNT_U32);
425
+ }
426
+
427
+ /**
428
+ * Returns an array view of this polygon's triangle indices, represented as
429
+ * three vertex indices per triangle.
430
+ *
431
+ * If 'result' argument is given, triangle indices are written to that array
432
+ * and returned. Otherwise, returns an ArrayView on collection memory —
433
+ * changes to this array will not trigger render updates, which requires
434
+ * `.setTriangles()`.
435
+ *
436
+ * @param {TypedArray} [result]
437
+ * @returns {TypedArray}
438
+ */
439
+ getTriangles(result) {
440
+ const { triangleOffset, triangleCount } = this;
441
+ const indices = this._collection._triangleIndexView;
442
+
443
+ if (!defined(result)) {
444
+ const byteOffset =
445
+ indices.byteOffset + triangleOffset * 3 * indices.BYTES_PER_ELEMENT;
446
+ const TypedArray = /** @type {TypedArrayConstructor} */ (
447
+ indices.constructor
448
+ );
449
+ return new TypedArray(
450
+ /** @type {ArrayBuffer} */ (indices.buffer),
451
+ byteOffset,
452
+ triangleCount * 3,
453
+ );
454
+ }
455
+
456
+ for (let i = 0; i < triangleCount; i++) {
457
+ result[i * 3] = indices[(triangleOffset + i) * 3];
458
+ result[i * 3 + 1] = indices[(triangleOffset + i) * 3 + 1];
459
+ result[i * 3 + 2] = indices[(triangleOffset + i) * 3 + 2];
460
+ }
461
+ return result;
462
+ }
463
+
464
+ /**
465
+ * Sets this polygon's triangle indices, represented as three vertex indices
466
+ * per triangle.
467
+ *
468
+ * @param {TypedArray} indices
469
+ */
470
+ setTriangles(indices) {
471
+ const collection = this._collection;
472
+ const triangleOffset = this.triangleOffset;
473
+ const srcCount = this.triangleCount;
474
+ const dstCount = indices.length / 3;
475
+ const collectionCount = collection.triangleCount + dstCount - srcCount;
476
+
477
+ //>>includeStart('debug', pragmas.debug);
478
+ assert(srcCount === dstCount || this._isResizable(), ERR_RESIZE);
479
+ assert(collectionCount <= collection.triangleCountMax, ERR_CAPACITY);
480
+ //>>includeEnd('debug');
481
+
482
+ collection._triangleCount += dstCount - srcCount;
483
+ this._setUint32(BufferPolygon.Layout.TRIANGLE_COUNT_U32, dstCount);
484
+
485
+ const dstIndices = collection._triangleIndexView;
486
+ for (let i = 0; i < dstCount; i++) {
487
+ dstIndices[(triangleOffset + i) * 3] = indices[i * 3];
488
+ dstIndices[(triangleOffset + i) * 3 + 1] = indices[i * 3 + 1];
489
+ dstIndices[(triangleOffset + i) * 3 + 2] = indices[i * 3 + 2];
490
+ }
491
+
492
+ collection._makeDirtyBoundingVolume();
493
+ }
494
+
495
+ /////////////////////////////////////////////////////////////////////////////
496
+ // DEBUG
497
+
498
+ /**
499
+ * Returns a JSON-serializable object representing the polygon. This encoding
500
+ * is not memory-efficient, and should generally be used for debugging and
501
+ * testing.
502
+ *
503
+ * @returns {Object} JSON-serializable object.
504
+ * @override
505
+ */
506
+ toJSON() {
507
+ return {
508
+ ...super.toJSON(),
509
+ positions: Array.from(this.getPositions()),
510
+ holes: Array.from(this.getHoles()),
511
+ triangles: Array.from(this.getTriangles()),
512
+ };
513
+ }
514
+ }
515
+
516
+ export default BufferPolygon;