@cesium/engine 0.1.0 → 1.1.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 (217) hide show
  1. package/Build/Workers/{AttributeCompression-4589338a.js → AttributeCompression-b646d393.js} +1 -1
  2. package/Build/Workers/{AxisAlignedBoundingBox-bfb1234f.js → AxisAlignedBoundingBox-a4321399.js} +1 -1
  3. package/Build/Workers/{BoundingRectangle-7ffc2153.js → BoundingRectangle-80d8801f.js} +1 -1
  4. package/Build/Workers/{BoxGeometry-93f344a3.js → BoxGeometry-33c10a4f.js} +1 -1
  5. package/Build/Workers/{Color-0c5aaf47.js → Color-1bf9a6e0.js} +1 -1
  6. package/Build/Workers/{CoplanarPolygonGeometryLibrary-6597982a.js → CoplanarPolygonGeometryLibrary-5c5b981b.js} +1 -1
  7. package/Build/Workers/{CorridorGeometryLibrary-2119580e.js → CorridorGeometryLibrary-7cbae7a0.js} +1 -1
  8. package/Build/Workers/{CylinderGeometry-f9503c6d.js → CylinderGeometry-42740df0.js} +1 -1
  9. package/Build/Workers/{EllipseGeometry-fedf72d5.js → EllipseGeometry-49a3ac21.js} +1 -1
  10. package/Build/Workers/{EllipseGeometryLibrary-4ea68687.js → EllipseGeometryLibrary-b891b2f8.js} +1 -1
  11. package/Build/Workers/{EllipseOutlineGeometry-e2ae6a35.js → EllipseOutlineGeometry-fbd72e07.js} +1 -1
  12. package/Build/Workers/{EllipsoidGeodesic-16de63ea.js → EllipsoidGeodesic-98c62a56.js} +1 -1
  13. package/Build/Workers/{EllipsoidGeometry-95c0330e.js → EllipsoidGeometry-a351dba8.js} +1 -1
  14. package/Build/Workers/{EllipsoidOutlineGeometry-d6d2ceec.js → EllipsoidOutlineGeometry-3e8779bf.js} +1 -1
  15. package/Build/Workers/{EllipsoidRhumbLine-ae5e65e0.js → EllipsoidRhumbLine-19756602.js} +1 -1
  16. package/Build/Workers/{EllipsoidTangentPlane-bfc674bf.js → EllipsoidTangentPlane-cfb50678.js} +1 -1
  17. package/Build/Workers/{EncodedCartesian3-f473ea18.js → EncodedCartesian3-81f70735.js} +1 -1
  18. package/Build/Workers/{FrustumGeometry-3bf2e4eb.js → FrustumGeometry-c5754412.js} +1 -1
  19. package/Build/Workers/{GeometryAttribute-df5f473e.js → GeometryAttribute-0bfd05e8.js} +1 -1
  20. package/Build/Workers/{GeometryInstance-aa75b4cf.js → GeometryInstance-451dc1cd.js} +1 -1
  21. package/Build/Workers/{GeometryPipeline-f0e46c42.js → GeometryPipeline-0166905d.js} +1 -1
  22. package/Build/Workers/{IntersectionTests-9de29d51.js → IntersectionTests-a93d3de9.js} +1 -1
  23. package/Build/Workers/{Matrix2-ce637455.js → Matrix2-13178034.js} +4 -2
  24. package/Build/Workers/{Matrix3-4f4df527.js → Matrix3-315394f6.js} +2 -1
  25. package/Build/Workers/{OrientedBoundingBox-d3ff3d4d.js → OrientedBoundingBox-b450cb61.js} +5 -5
  26. package/Build/Workers/{Plane-b81241c2.js → Plane-900aa728.js} +1 -1
  27. package/Build/Workers/{PolygonGeometryLibrary-6f4937bb.js → PolygonGeometryLibrary-f918ac26.js} +1 -1
  28. package/Build/Workers/PolygonPipeline-f59a8f0a.js +1345 -0
  29. package/Build/Workers/{PolylinePipeline-2e2b015c.js → PolylinePipeline-d8e6bd9b.js} +1 -1
  30. package/Build/Workers/{PolylineVolumeGeometryLibrary-7ee1d449.js → PolylineVolumeGeometryLibrary-125d2edf.js} +1 -1
  31. package/Build/Workers/{PrimitivePipeline-a9b7aae0.js → PrimitivePipeline-0d7b5ed4.js} +1 -1
  32. package/Build/Workers/{RectangleGeometryLibrary-9aa6c8f6.js → RectangleGeometryLibrary-0768db63.js} +1 -1
  33. package/Build/Workers/{TerrainEncoding-b52dcfc5.js → TerrainEncoding-06470d7f.js} +1 -1
  34. package/Build/Workers/{Transforms-2f755df8.js → Transforms-26539bce.js} +97 -83
  35. package/Build/Workers/{WallGeometryLibrary-ab19a93d.js → WallGeometryLibrary-6167b0fc.js} +1 -1
  36. package/Build/Workers/{WebMercatorProjection-9f25de49.js → WebMercatorProjection-13a90d41.js} +1 -1
  37. package/Build/Workers/cesiumWorkerBootstrapper.js +25 -1
  38. package/Build/Workers/combineGeometry.js +1 -1
  39. package/Build/Workers/createBoxGeometry.js +1 -1
  40. package/Build/Workers/createBoxOutlineGeometry.js +1 -1
  41. package/Build/Workers/createCircleGeometry.js +1 -1
  42. package/Build/Workers/createCircleOutlineGeometry.js +1 -1
  43. package/Build/Workers/createCoplanarPolygonGeometry.js +1 -1
  44. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +1 -1
  45. package/Build/Workers/createCorridorGeometry.js +1 -1
  46. package/Build/Workers/createCorridorOutlineGeometry.js +1 -1
  47. package/Build/Workers/createCylinderGeometry.js +1 -1
  48. package/Build/Workers/createCylinderOutlineGeometry.js +1 -1
  49. package/Build/Workers/createEllipseGeometry.js +1 -1
  50. package/Build/Workers/createEllipseOutlineGeometry.js +1 -1
  51. package/Build/Workers/createEllipsoidGeometry.js +1 -1
  52. package/Build/Workers/createEllipsoidOutlineGeometry.js +1 -1
  53. package/Build/Workers/createFrustumGeometry.js +1 -1
  54. package/Build/Workers/createFrustumOutlineGeometry.js +1 -1
  55. package/Build/Workers/createGeometry.js +1 -1
  56. package/Build/Workers/createGroundPolylineGeometry.js +1 -1
  57. package/Build/Workers/createPlaneGeometry.js +1 -1
  58. package/Build/Workers/createPlaneOutlineGeometry.js +1 -1
  59. package/Build/Workers/createPolygonGeometry.js +1 -1
  60. package/Build/Workers/createPolygonOutlineGeometry.js +1 -1
  61. package/Build/Workers/createPolylineGeometry.js +1 -1
  62. package/Build/Workers/createPolylineVolumeGeometry.js +1 -1
  63. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +1 -1
  64. package/Build/Workers/createRectangleGeometry.js +1 -1
  65. package/Build/Workers/createRectangleOutlineGeometry.js +1 -1
  66. package/Build/Workers/createSimplePolylineGeometry.js +1 -1
  67. package/Build/Workers/createSphereGeometry.js +1 -1
  68. package/Build/Workers/createSphereOutlineGeometry.js +1 -1
  69. package/Build/Workers/createVectorTileClampedPolylines.js +1 -1
  70. package/Build/Workers/createVectorTileGeometries.js +1 -1
  71. package/Build/Workers/createVectorTilePoints.js +1 -1
  72. package/Build/Workers/createVectorTilePolygons.js +1 -1
  73. package/Build/Workers/createVectorTilePolylines.js +1 -1
  74. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +1 -1
  75. package/Build/Workers/createVerticesFromHeightmap.js +7 -3
  76. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +1 -1
  77. package/Build/Workers/createWallGeometry.js +1 -1
  78. package/Build/Workers/createWallOutlineGeometry.js +1 -1
  79. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +95 -76
  80. package/Build/Workers/decodeI3S.js +1 -1
  81. package/Build/Workers/package.js +25 -1
  82. package/Build/Workers/transferTypedArrayTest.js +25 -1
  83. package/Build/Workers/upsampleQuantizedTerrainMesh.js +1 -1
  84. package/README.md +9 -9
  85. package/Source/Core/EarthOrientationParameters.js +67 -63
  86. package/Source/Core/Ion.js +1 -1
  87. package/Source/Core/Matrix2.js +2 -1
  88. package/Source/Core/Matrix3.js +2 -1
  89. package/Source/Core/Matrix4.js +1 -0
  90. package/Source/Core/OrientedBoundingBox.js +4 -4
  91. package/Source/Core/S2Cell.js +3 -3
  92. package/Source/Core/Transforms.js +3 -7
  93. package/Source/DataSources/GpxDataSource.js +4 -6
  94. package/Source/DataSources/KmlDataSource.js +3 -5
  95. package/Source/Renderer/Context.js +230 -177
  96. package/Source/Renderer/Pass.js +3 -2
  97. package/Source/Scene/Cesium3DTileContentType.js +19 -0
  98. package/Source/Scene/Cesium3DTilesVoxelProvider.js +482 -0
  99. package/Source/Scene/Cesium3DTilesetMetadata.js +2 -2
  100. package/Source/Scene/ContentMetadata.js +2 -2
  101. package/Source/Scene/DerivedCommand.js +7 -0
  102. package/Source/Scene/Expression.js +1 -1
  103. package/Source/Scene/Globe.js +10 -0
  104. package/Source/Scene/GlobeSurfaceTileProvider.js +7 -0
  105. package/Source/Scene/GltfImageLoader.js +1 -1
  106. package/Source/Scene/GltfVertexBufferLoader.js +10 -2
  107. package/Source/Scene/GroupMetadata.js +2 -2
  108. package/Source/Scene/I3SDataProvider.js +2 -1
  109. package/Source/Scene/I3SFeature.js +1 -1
  110. package/Source/Scene/I3SLayer.js +64 -2
  111. package/Source/Scene/I3SNode.js +50 -6
  112. package/Source/Scene/ImplicitMetadataView.js +2 -2
  113. package/Source/Scene/ImplicitSubtreeCache.js +127 -0
  114. package/Source/Scene/ImplicitSubtreeMetadata.js +2 -2
  115. package/Source/Scene/ImplicitTileset.js +3 -2
  116. package/Source/Scene/KeyframeNode.js +47 -0
  117. package/Source/Scene/Megatexture.js +490 -0
  118. package/Source/Scene/MetadataClass.js +60 -25
  119. package/Source/Scene/MetadataClassProperty.js +132 -68
  120. package/Source/Scene/MetadataComponentType.js +78 -57
  121. package/Source/Scene/MetadataEnum.js +59 -23
  122. package/Source/Scene/MetadataEnumValue.js +49 -15
  123. package/Source/Scene/MetadataSchema.js +53 -24
  124. package/Source/Scene/MetadataSchemaLoader.js +2 -2
  125. package/Source/Scene/MetadataTableProperty.js +2 -2
  126. package/Source/Scene/MetadataType.js +6 -14
  127. package/Source/Scene/Model/GeoJsonLoader.js +1 -1
  128. package/Source/Scene/Model/Model.js +38 -6
  129. package/Source/Scene/Model/buildDrawCommand.js +19 -11
  130. package/Source/Scene/PointCloud.js +1 -1
  131. package/Source/Scene/PropertyAttribute.js +2 -2
  132. package/Source/Scene/PropertyAttributeProperty.js +2 -2
  133. package/Source/Scene/PropertyTable.js +2 -2
  134. package/Source/Scene/PropertyTexture.js +2 -2
  135. package/Source/Scene/PropertyTextureProperty.js +2 -2
  136. package/Source/Scene/ResourceCache.js +9 -1
  137. package/Source/Scene/ResourceCacheKey.js +9 -1
  138. package/Source/Scene/Scene.js +20 -50
  139. package/Source/Scene/SpatialNode.js +375 -0
  140. package/Source/Scene/StructuralMetadata.js +2 -2
  141. package/Source/Scene/TileMetadata.js +2 -2
  142. package/Source/Scene/TilesetMetadata.js +2 -2
  143. package/Source/Scene/VoxelBoxShape.js +527 -0
  144. package/Source/Scene/VoxelContent.js +169 -0
  145. package/Source/Scene/VoxelCylinderShape.js +937 -0
  146. package/Source/Scene/VoxelEllipsoidShape.js +937 -0
  147. package/Source/Scene/VoxelPrimitive.js +1919 -0
  148. package/Source/Scene/VoxelProvider.js +255 -0
  149. package/Source/Scene/VoxelRenderResources.js +224 -0
  150. package/Source/Scene/VoxelShape.js +152 -0
  151. package/Source/Scene/VoxelShapeType.js +105 -0
  152. package/Source/Scene/VoxelTraversal.js +1144 -0
  153. package/Source/Scene/buildVoxelDrawCommands.js +116 -0
  154. package/Source/Scene/parseBatchTable.js +18 -2
  155. package/Source/Scene/preprocess3DTileContent.js +8 -0
  156. package/Source/Scene/processVoxelProperties.js +455 -0
  157. package/Source/Shaders/BillboardCollectionVS.glsl +1 -1
  158. package/Source/Shaders/BillboardCollectionVS.js +1 -1
  159. package/Source/Shaders/Builtin/Constants/passOverlay.glsl +1 -1
  160. package/Source/Shaders/Builtin/Constants/passOverlay.js +1 -1
  161. package/Source/Shaders/Builtin/Constants/passVoxels.glsl +9 -0
  162. package/Source/Shaders/Builtin/Constants/passVoxels.js +11 -0
  163. package/Source/Shaders/Builtin/CzmBuiltins.js +2 -0
  164. package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.glsl +55 -43
  165. package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.js +55 -43
  166. package/Source/Shaders/GlobeFS.glsl +2 -1
  167. package/Source/Shaders/GlobeFS.js +2 -1
  168. package/Source/Shaders/PointPrimitiveCollectionVS.glsl +5 -2
  169. package/Source/Shaders/PointPrimitiveCollectionVS.js +5 -2
  170. package/Source/Shaders/Voxels/IntersectBox.glsl +79 -0
  171. package/Source/Shaders/Voxels/IntersectBox.js +81 -0
  172. package/Source/Shaders/Voxels/IntersectClippingPlanes.glsl +70 -0
  173. package/Source/Shaders/Voxels/IntersectClippingPlanes.js +72 -0
  174. package/Source/Shaders/Voxels/IntersectCylinder.glsl +273 -0
  175. package/Source/Shaders/Voxels/IntersectCylinder.js +275 -0
  176. package/Source/Shaders/Voxels/IntersectDepth.glsl +23 -0
  177. package/Source/Shaders/Voxels/IntersectDepth.js +25 -0
  178. package/Source/Shaders/Voxels/IntersectEllipsoid.glsl +337 -0
  179. package/Source/Shaders/Voxels/IntersectEllipsoid.js +339 -0
  180. package/Source/Shaders/Voxels/Intersection.glsl +54 -0
  181. package/Source/Shaders/Voxels/Intersection.js +56 -0
  182. package/Source/Shaders/Voxels/IntersectionUtils.glsl +151 -0
  183. package/Source/Shaders/Voxels/IntersectionUtils.js +153 -0
  184. package/Source/Shaders/Voxels/Megatexture.glsl +136 -0
  185. package/Source/Shaders/Voxels/Megatexture.js +138 -0
  186. package/Source/Shaders/Voxels/Octree.glsl +221 -0
  187. package/Source/Shaders/Voxels/Octree.js +223 -0
  188. package/Source/Shaders/Voxels/VoxelFS.glsl +150 -0
  189. package/Source/Shaders/Voxels/VoxelFS.js +152 -0
  190. package/Source/Shaders/Voxels/VoxelVS.glsl +11 -0
  191. package/Source/Shaders/Voxels/VoxelVS.js +13 -0
  192. package/Source/Shaders/Voxels/convertUvToBox.glsl +16 -0
  193. package/Source/Shaders/Voxels/convertUvToBox.js +18 -0
  194. package/Source/Shaders/Voxels/convertUvToCylinder.glsl +79 -0
  195. package/Source/Shaders/Voxels/convertUvToCylinder.js +81 -0
  196. package/Source/Shaders/Voxels/convertUvToEllipsoid.glsl +133 -0
  197. package/Source/Shaders/Voxels/convertUvToEllipsoid.js +135 -0
  198. package/Source/ThirdParty/Workers/draco_decoder_nodejs.js +100 -101
  199. package/Source/ThirdParty/Workers/pako_deflate.min.js +2 -2
  200. package/Source/ThirdParty/Workers/pako_inflate.min.js +2 -2
  201. package/Source/ThirdParty/draco_decoder.wasm +0 -0
  202. package/Source/Widget/CesiumWidget.js +1 -1
  203. package/index.d.ts +961 -56
  204. package/index.js +92 -60
  205. package/package.json +6 -4
  206. package/Build/ThirdParty/Workers/basis_transcoder.js +0 -2233
  207. package/Build/ThirdParty/Workers/draco_decoder_nodejs.js +0 -1872
  208. package/Build/ThirdParty/Workers/package.json +0 -1
  209. package/Build/ThirdParty/Workers/pako_deflate.min.js +0 -589
  210. package/Build/ThirdParty/Workers/pako_inflate.min.js +0 -798
  211. package/Build/ThirdParty/Workers/z-worker-pako.js +0 -503
  212. package/Build/ThirdParty/basis_transcoder.wasm +0 -0
  213. package/Build/ThirdParty/draco_decoder.wasm +0 -0
  214. package/Build/ThirdParty/google-earth-dbroot-parser.js +0 -8019
  215. package/Build/Widget/CesiumWidget.css +0 -120
  216. package/Build/Widget/lighter.css +0 -13
  217. package/Build/Workers/PolygonPipeline-774a8aaf.js +0 -1341
@@ -0,0 +1,527 @@
1
+ import BoundingSphere from "../Core/BoundingSphere.js";
2
+ import Cartesian3 from "../Core/Cartesian3.js";
3
+ import CesiumMath from "../Core/Math.js";
4
+ import Check from "../Core/Check.js";
5
+ import Matrix3 from "../Core/Matrix3.js";
6
+ import Matrix4 from "../Core/Matrix4.js";
7
+ import OrientedBoundingBox from "../Core/OrientedBoundingBox.js";
8
+ import defaultValue from "../Core/defaultValue.js";
9
+
10
+ /**
11
+ * A box {@link VoxelShape}.
12
+ *
13
+ * @alias VoxelBoxShape
14
+ * @constructor
15
+ *
16
+ * @see VoxelShape
17
+ * @see VoxelEllipsoidShape
18
+ * @see VoxelCylinderShape
19
+ * @see VoxelShapeType
20
+ *
21
+ * @private
22
+ */
23
+ function VoxelBoxShape() {
24
+ /**
25
+ * An oriented bounding box containing the bounded shape.
26
+ * The update function must be called before accessing this value.
27
+ * @type {OrientedBoundingBox}
28
+ * @readonly
29
+ */
30
+ this.orientedBoundingBox = new OrientedBoundingBox();
31
+
32
+ /**
33
+ * A bounding sphere containing the bounded shape.
34
+ * The update function must be called before accessing this value.
35
+ * @type {BoundingSphere}
36
+ * @readonly
37
+ */
38
+ this.boundingSphere = new BoundingSphere();
39
+
40
+ /**
41
+ * A transformation matrix containing the bounded shape.
42
+ * The update function must be called before accessing this value.
43
+ * @type {Matrix4}
44
+ * @readonly
45
+ */
46
+ this.boundTransform = new Matrix4();
47
+
48
+ /**
49
+ * A transformation matrix containing the shape, ignoring the bounds.
50
+ * The update function must be called before accessing this value.
51
+ * @type {Matrix4}
52
+ * @readonly
53
+ */
54
+ this.shapeTransform = new Matrix4();
55
+
56
+ /**
57
+ * @type {Cartesian3}
58
+ * @private
59
+ */
60
+ this._minBounds = Cartesian3.clone(
61
+ VoxelBoxShape.DefaultMinBounds,
62
+ new Cartesian3()
63
+ );
64
+
65
+ /**
66
+ * @type {Cartesian3}
67
+ * @private
68
+ */
69
+ this._maxBounds = Cartesian3.clone(
70
+ VoxelBoxShape.DefaultMaxBounds,
71
+ new Cartesian3()
72
+ );
73
+
74
+ /**
75
+ * @type {Object.<string, any>}
76
+ * @readonly
77
+ */
78
+ this.shaderUniforms = {
79
+ boxUvToRenderBoundsTransform: new Matrix4(),
80
+ boxUvToRenderBoundsScale: new Cartesian3(),
81
+ boxUvToRenderBoundsTranslate: new Cartesian3(),
82
+ boxUvToShapeUvScale: new Cartesian3(),
83
+ boxUvToShapeUvTranslate: new Cartesian3(),
84
+ };
85
+
86
+ /**
87
+ * @type {Object.<string, any>}
88
+ * @readonly
89
+ */
90
+ this.shaderDefines = {
91
+ BOX_INTERSECTION_INDEX: undefined,
92
+ BOX_HAS_RENDER_BOUNDS: undefined,
93
+ BOX_HAS_SHAPE_BOUNDS: undefined,
94
+ BOX_IS_2D: undefined,
95
+ };
96
+
97
+ /**
98
+ * The maximum number of intersections against the shape for any ray direction.
99
+ * @type {Number}
100
+ * @readonly
101
+ */
102
+ this.shaderMaximumIntersectionsLength = 0; // not known until update
103
+ }
104
+
105
+ const scratchCenter = new Cartesian3();
106
+ const scratchScale = new Cartesian3();
107
+ const scratchRotation = new Matrix3();
108
+ const scratchTransformLocalToBounds = new Matrix4();
109
+ const scratchBoundsTranslation = new Cartesian3();
110
+ const scratchBoundsScale = new Cartesian3();
111
+ const scratchBoundsScaleMatrix = new Matrix3();
112
+ const scratchClipMinBounds = new Cartesian3();
113
+ const scratchClipMaxBounds = new Cartesian3();
114
+ const scratchRenderMinBounds = new Cartesian3();
115
+ const scratchRenderMaxBounds = new Cartesian3();
116
+
117
+ const transformUvToLocal = Matrix4.fromRotationTranslation(
118
+ Matrix3.fromUniformScale(2.0, new Matrix3()),
119
+ new Cartesian3(-1.0, -1.0, -1.0),
120
+ new Matrix4()
121
+ );
122
+
123
+ const transformXYZToZYX = Matrix4.fromRotation(
124
+ Matrix3.fromColumnMajorArray(
125
+ [0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0],
126
+ new Matrix3()
127
+ ),
128
+ new Matrix4()
129
+ );
130
+
131
+ const transformXYZToXZY = Matrix4.fromRotation(
132
+ Matrix3.fromColumnMajorArray(
133
+ [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0],
134
+ new Matrix3()
135
+ ),
136
+ new Matrix4()
137
+ );
138
+
139
+ /**
140
+ * Update the shape's state.
141
+ *
142
+ * @param {Matrix4} modelMatrix The model matrix.
143
+ * @param {Cartesian3} minBounds The minimum bounds.
144
+ * @param {Cartesian3} maxBounds The maximum bounds.
145
+ * @param {Cartesian3} [clipMinBounds=VoxelBoxShape.DefaultMinBounds] The minimum clip bounds.
146
+ * @param {Cartesian3} [clipMaxBounds=VoxelBoxShape.DefaultMaxBounds] The maximum clip bounds.
147
+ * @returns {Boolean} Whether the shape is visible.
148
+ */
149
+ VoxelBoxShape.prototype.update = function (
150
+ modelMatrix,
151
+ minBounds,
152
+ maxBounds,
153
+ clipMinBounds,
154
+ clipMaxBounds
155
+ ) {
156
+ clipMinBounds = defaultValue(clipMinBounds, VoxelBoxShape.DefaultMinBounds);
157
+ clipMaxBounds = defaultValue(clipMaxBounds, VoxelBoxShape.DefaultMaxBounds);
158
+ //>>includeStart('debug', pragmas.debug);
159
+ Check.typeOf.object("modelMatrix", modelMatrix);
160
+ Check.typeOf.object("minBounds", minBounds);
161
+ Check.typeOf.object("maxBounds", maxBounds);
162
+ //>>includeEnd('debug');
163
+
164
+ const defaultMinBounds = VoxelBoxShape.DefaultMinBounds;
165
+ const defaultMaxBounds = VoxelBoxShape.DefaultMaxBounds;
166
+
167
+ minBounds = this._minBounds = Cartesian3.clamp(
168
+ minBounds,
169
+ defaultMinBounds,
170
+ defaultMaxBounds,
171
+ this._minBounds
172
+ );
173
+
174
+ maxBounds = this._maxBounds = Cartesian3.clamp(
175
+ maxBounds,
176
+ defaultMinBounds,
177
+ defaultMaxBounds,
178
+ this._maxBounds
179
+ );
180
+
181
+ clipMinBounds = Cartesian3.clamp(
182
+ clipMinBounds,
183
+ defaultMinBounds,
184
+ defaultMaxBounds,
185
+ scratchClipMinBounds
186
+ );
187
+
188
+ clipMaxBounds = Cartesian3.clamp(
189
+ clipMaxBounds,
190
+ defaultMinBounds,
191
+ defaultMaxBounds,
192
+ scratchClipMaxBounds
193
+ );
194
+
195
+ const renderMinBounds = Cartesian3.clamp(
196
+ minBounds,
197
+ clipMinBounds,
198
+ clipMaxBounds,
199
+ scratchRenderMinBounds
200
+ );
201
+
202
+ const renderMaxBounds = Cartesian3.clamp(
203
+ maxBounds,
204
+ clipMinBounds,
205
+ clipMaxBounds,
206
+ scratchRenderMaxBounds
207
+ );
208
+
209
+ const scale = Matrix4.getScale(modelMatrix, scratchScale);
210
+
211
+ // Box is not visible if:
212
+ // - any of the min render bounds exceed the max render bounds
213
+ // - two or more of the min bounds equal the max bounds (line / point)
214
+ // - any of the min clip bounds exceed the max clip bounds
215
+ // - scale is 0 for any component (too annoying to reconstruct rotation matrix)
216
+ if (
217
+ renderMinBounds.x > renderMaxBounds.x ||
218
+ renderMinBounds.y > renderMaxBounds.y ||
219
+ renderMinBounds.z > renderMaxBounds.z ||
220
+ (renderMinBounds.x === renderMaxBounds.x) +
221
+ (renderMinBounds.y === renderMaxBounds.y) +
222
+ (renderMinBounds.z === renderMaxBounds.z) >=
223
+ 2 ||
224
+ clipMinBounds.x > clipMaxBounds.x ||
225
+ clipMinBounds.y > clipMaxBounds.y ||
226
+ clipMinBounds.z > clipMaxBounds.z ||
227
+ scale.x === 0.0 ||
228
+ scale.y === 0.0 ||
229
+ scale.z === 0.0
230
+ ) {
231
+ return false;
232
+ }
233
+
234
+ this.shapeTransform = Matrix4.clone(modelMatrix, this.shapeTransform);
235
+
236
+ this.orientedBoundingBox = getBoxChunkObb(
237
+ renderMinBounds,
238
+ renderMaxBounds,
239
+ this.shapeTransform,
240
+ this.orientedBoundingBox
241
+ );
242
+
243
+ // All of the box bounds go from -1 to +1, so the model matrix scale can be
244
+ // used as the oriented bounding box half axes.
245
+ this.boundTransform = Matrix4.fromRotationTranslation(
246
+ this.orientedBoundingBox.halfAxes,
247
+ this.orientedBoundingBox.center,
248
+ this.boundTransform
249
+ );
250
+
251
+ this.boundingSphere = BoundingSphere.fromOrientedBoundingBox(
252
+ this.orientedBoundingBox,
253
+ this.boundingSphere
254
+ );
255
+
256
+ const shaderUniforms = this.shaderUniforms;
257
+ const shaderDefines = this.shaderDefines;
258
+
259
+ // To keep things simple, clear the defines every time
260
+ for (const key in shaderDefines) {
261
+ if (shaderDefines.hasOwnProperty(key)) {
262
+ shaderDefines[key] = undefined;
263
+ }
264
+ }
265
+
266
+ const hasRenderBounds =
267
+ renderMinBounds.x !== defaultMinBounds.x ||
268
+ renderMaxBounds.x !== defaultMaxBounds.x ||
269
+ renderMinBounds.y !== defaultMinBounds.y ||
270
+ renderMaxBounds.y !== defaultMaxBounds.y ||
271
+ renderMinBounds.z !== defaultMinBounds.z ||
272
+ renderMaxBounds.z !== defaultMaxBounds.z;
273
+
274
+ const hasShapeBounds =
275
+ minBounds.x !== defaultMinBounds.x ||
276
+ maxBounds.x !== defaultMaxBounds.x ||
277
+ minBounds.y !== defaultMinBounds.y ||
278
+ maxBounds.y !== defaultMaxBounds.y ||
279
+ minBounds.z !== defaultMinBounds.z ||
280
+ maxBounds.z !== defaultMaxBounds.z;
281
+
282
+ // Keep track of how many intersections there are going to be.
283
+ let intersectionCount = 0;
284
+
285
+ shaderDefines["BOX_INTERSECTION_INDEX"] = intersectionCount;
286
+ intersectionCount += 1;
287
+
288
+ if (hasRenderBounds) {
289
+ shaderDefines["BOX_HAS_RENDER_BOUNDS"] = true;
290
+
291
+ const min = renderMinBounds;
292
+ const max = renderMaxBounds;
293
+
294
+ // inverse(scale)
295
+ // inverse(maxBoundsUv - minBoundsUv)
296
+ // inverse((maxBounds * 0.5 + 0.5) - (minBounds * 0.5 + 0.5))
297
+ // inverse(0.5 * (maxBounds - minBounds))
298
+ // 2.0 / (maxBounds - minBounds) // with divide by zero protection
299
+ const scaleLocalToBounds = Cartesian3.fromElements(
300
+ 2.0 / (min.x === max.x ? 1.0 : max.x - min.x),
301
+ 2.0 / (min.y === max.y ? 1.0 : max.y - min.y),
302
+ 2.0 / (min.z === max.z ? 1.0 : max.z - min.z),
303
+ scratchBoundsScale
304
+ );
305
+
306
+ // -inverse(scale) * translation // affine inverse
307
+ // -inverse(scale) * 0.5 * (minBounds + maxBounds)
308
+ const translateLocalToBounds = Cartesian3.fromElements(
309
+ -scaleLocalToBounds.x * 0.5 * (min.x + max.x),
310
+ -scaleLocalToBounds.y * 0.5 * (min.y + max.y),
311
+ -scaleLocalToBounds.z * 0.5 * (min.z + max.z),
312
+ scratchBoundsTranslation
313
+ );
314
+
315
+ let transformLocalToBounds = Matrix4.fromRotationTranslation(
316
+ Matrix3.fromScale(scaleLocalToBounds, scratchBoundsScaleMatrix),
317
+ translateLocalToBounds,
318
+ scratchTransformLocalToBounds
319
+ );
320
+
321
+ if (min.x === max.x || min.y === max.y || min.z === max.z) {
322
+ shaderDefines["BOX_IS_2D"] = true;
323
+
324
+ let transformAxisConversion;
325
+ if (min.x === max.x) {
326
+ transformAxisConversion = transformXYZToZYX;
327
+ } else if (min.y === max.y) {
328
+ transformAxisConversion = transformXYZToXZY;
329
+ } else if (min.z === max.z) {
330
+ transformAxisConversion = Matrix4.IDENTITY;
331
+ }
332
+ transformLocalToBounds = Matrix4.multiplyTransformation(
333
+ transformAxisConversion,
334
+ transformLocalToBounds,
335
+ transformLocalToBounds
336
+ );
337
+ }
338
+
339
+ shaderUniforms.boxUvToRenderBoundsTransform = Matrix4.multiplyTransformation(
340
+ transformLocalToBounds,
341
+ transformUvToLocal,
342
+ shaderUniforms.boxUvToRenderBoundsTransform
343
+ );
344
+ shaderUniforms.boxUvToRenderBoundsScale = Matrix4.getScale(
345
+ shaderUniforms.boxUvToRenderBoundsTransform,
346
+ shaderUniforms.boxUvToRenderBoundsScale
347
+ );
348
+ shaderUniforms.boxUvToRenderBoundsTranslate = Matrix4.getTranslation(
349
+ shaderUniforms.boxUvToRenderBoundsTransform,
350
+ shaderUniforms.boxUvToRenderBoundsTranslate
351
+ );
352
+ }
353
+
354
+ if (hasShapeBounds) {
355
+ shaderDefines["BOX_HAS_SHAPE_BOUNDS"] = true;
356
+
357
+ const min = minBounds;
358
+ const max = maxBounds;
359
+
360
+ // Go from UV space to bounded UV space:
361
+ // delerp(posUv, minBoundsUv, maxBoundsUv)
362
+ // (posUv - minBoundsUv) / (maxBoundsUv - minBoundsUv)
363
+ // posUv / (maxBoundsUv - minBoundsUv) - minBoundsUv / (maxBoundsUv - minBoundsUv)
364
+ // scale = 1.0 / (maxBoundsUv - minBoundsUv)
365
+ // scale = 1.0 / ((maxBounds * 0.5 + 0.5) - (minBounds * 0.5 + 0.5))
366
+ // scale = 2.0 / (maxBounds - minBounds)
367
+ // offset = -minBoundsUv / ((maxBounds * 0.5 + 0.5) - (minBounds * 0.5 + 0.5))
368
+ // offset = -2.0 * (minBounds * 0.5 + 0.5) / (maxBounds - minBounds)
369
+ // offset = -scale * (minBounds * 0.5 + 0.5)
370
+ shaderUniforms.boxUvToShapeUvScale = Cartesian3.fromElements(
371
+ 2.0 / (min.x === max.x ? 1.0 : max.x - min.x),
372
+ 2.0 / (min.y === max.y ? 1.0 : max.y - min.y),
373
+ 2.0 / (min.z === max.z ? 1.0 : max.z - min.z),
374
+ shaderUniforms.boxUvToShapeUvScale
375
+ );
376
+
377
+ shaderUniforms.boxUvToShapeUvTranslate = Cartesian3.fromElements(
378
+ -shaderUniforms.boxUvToShapeUvScale.x * (min.x * 0.5 + 0.5),
379
+ -shaderUniforms.boxUvToShapeUvScale.y * (min.y * 0.5 + 0.5),
380
+ -shaderUniforms.boxUvToShapeUvScale.z * (min.z * 0.5 + 0.5),
381
+ shaderUniforms.boxUvToShapeUvTranslate
382
+ );
383
+ }
384
+
385
+ this.shaderMaximumIntersectionsLength = intersectionCount;
386
+
387
+ return true;
388
+ };
389
+
390
+ const scratchTileMinBounds = new Cartesian3();
391
+ const scratchTileMaxBounds = new Cartesian3();
392
+
393
+ /**
394
+ * Computes an oriented bounding box for a specified tile.
395
+ * The update function must be called before calling this function.
396
+ *
397
+ * @param {Number} tileLevel The tile's level.
398
+ * @param {Number} tileX The tile's x coordinate.
399
+ * @param {Number} tileY The tile's y coordinate.
400
+ * @param {Number} tileZ The tile's z coordinate.
401
+ * @param {OrientedBoundingBox} result The oriented bounding box that will be set to enclose the specified tile
402
+ * @returns {OrientedBoundingBox} The oriented bounding box.
403
+ */
404
+ VoxelBoxShape.prototype.computeOrientedBoundingBoxForTile = function (
405
+ tileLevel,
406
+ tileX,
407
+ tileY,
408
+ tileZ,
409
+ result
410
+ ) {
411
+ //>>includeStart('debug', pragmas.debug);
412
+ Check.typeOf.number("tileLevel", tileLevel);
413
+ Check.typeOf.number("tileX", tileX);
414
+ Check.typeOf.number("tileY", tileY);
415
+ Check.typeOf.number("tileZ", tileZ);
416
+ Check.typeOf.object("result", result);
417
+ //>>includeEnd('debug');
418
+
419
+ const minBounds = this._minBounds;
420
+ const maxBounds = this._maxBounds;
421
+ const sizeAtLevel = 1.0 / Math.pow(2, tileLevel);
422
+
423
+ const tileMinBounds = Cartesian3.fromElements(
424
+ CesiumMath.lerp(minBounds.x, maxBounds.x, sizeAtLevel * tileX),
425
+ CesiumMath.lerp(minBounds.y, maxBounds.y, sizeAtLevel * tileY),
426
+ CesiumMath.lerp(minBounds.z, maxBounds.z, sizeAtLevel * tileZ),
427
+ scratchTileMinBounds
428
+ );
429
+
430
+ const tileMaxBounds = Cartesian3.fromElements(
431
+ CesiumMath.lerp(minBounds.x, maxBounds.x, sizeAtLevel * (tileX + 1)),
432
+ CesiumMath.lerp(minBounds.y, maxBounds.y, sizeAtLevel * (tileY + 1)),
433
+ CesiumMath.lerp(minBounds.z, maxBounds.z, sizeAtLevel * (tileZ + 1)),
434
+ scratchTileMaxBounds
435
+ );
436
+
437
+ return getBoxChunkObb(
438
+ tileMinBounds,
439
+ tileMaxBounds,
440
+ this.shapeTransform,
441
+ result
442
+ );
443
+ };
444
+
445
+ /**
446
+ * Computes an approximate step size for raymarching the root tile of a voxel grid.
447
+ * The update function must be called before calling this function.
448
+ *
449
+ * @param {Cartesian3} dimensions The voxel grid dimensions for a tile.
450
+ * @returns {Number} The step size.
451
+ */
452
+ VoxelBoxShape.prototype.computeApproximateStepSize = function (dimensions) {
453
+ //>>includeStart('debug', pragmas.debug);
454
+ Check.typeOf.object("dimensions", dimensions);
455
+ //>>includeEnd('debug');
456
+
457
+ return 1.0 / Cartesian3.maximumComponent(dimensions);
458
+ };
459
+
460
+ /**
461
+ * Defines the minimum bounds of the shape. Corresponds to minimum X, Y, Z.
462
+ *
463
+ * @type {Cartesian3}
464
+ * @constant
465
+ * @readonly
466
+ */
467
+ VoxelBoxShape.DefaultMinBounds = Object.freeze(
468
+ new Cartesian3(-1.0, -1.0, -1.0)
469
+ );
470
+
471
+ /**
472
+ * Defines the maximum bounds of the shape. Corresponds to maximum X, Y, Z.
473
+ *
474
+ * @type {Cartesian3}
475
+ * @constant
476
+ * @readonly
477
+ */
478
+ VoxelBoxShape.DefaultMaxBounds = Object.freeze(
479
+ new Cartesian3(+1.0, +1.0, +1.0)
480
+ );
481
+
482
+ /**
483
+ * Computes an {@link OrientedBoundingBox} for a subregion of the shape.
484
+ *
485
+ * @function
486
+ *
487
+ * @param {Cartesian3} minimumBounds The minimum bounds, in the local coordinates of the shape.
488
+ * @param {Cartesian3} maximumBounds The maximum bounds, in the local coordinates of the shape.
489
+ * @param {Matrix4} matrix The matrix to transform the points.
490
+ * @param {OrientedBoundingBox} result The object onto which to store the result.
491
+ * @returns {OrientedBoundingBox} The oriented bounding box that contains this subregion.
492
+ *
493
+ * @private
494
+ */
495
+ function getBoxChunkObb(minimumBounds, maximumBounds, matrix, result) {
496
+ const defaultMinBounds = VoxelBoxShape.DefaultMinBounds;
497
+ const defaultMaxBounds = VoxelBoxShape.DefaultMaxBounds;
498
+
499
+ const isDefaultBounds =
500
+ Cartesian3.equals(minimumBounds, defaultMinBounds) &&
501
+ Cartesian3.equals(maximumBounds, defaultMaxBounds);
502
+
503
+ if (isDefaultBounds) {
504
+ result.center = Matrix4.getTranslation(matrix, result.center);
505
+ result.halfAxes = Matrix4.getMatrix3(matrix, result.halfAxes);
506
+ } else {
507
+ let scale = Matrix4.getScale(matrix, scratchScale);
508
+ const localCenter = Cartesian3.midpoint(
509
+ minimumBounds,
510
+ maximumBounds,
511
+ scratchCenter
512
+ );
513
+ result.center = Matrix4.multiplyByPoint(matrix, localCenter, result.center);
514
+ scale = Cartesian3.fromElements(
515
+ scale.x * 0.5 * (maximumBounds.x - minimumBounds.x),
516
+ scale.y * 0.5 * (maximumBounds.y - minimumBounds.y),
517
+ scale.z * 0.5 * (maximumBounds.z - minimumBounds.z),
518
+ scratchScale
519
+ );
520
+ const rotation = Matrix4.getRotation(matrix, scratchRotation);
521
+ result.halfAxes = Matrix3.setScale(rotation, scale, result.halfAxes);
522
+ }
523
+
524
+ return result;
525
+ }
526
+
527
+ export default VoxelBoxShape;
@@ -0,0 +1,169 @@
1
+ import Check from "../Core/Check.js";
2
+ import DeveloperError from "../Core/DeveloperError.js";
3
+ import defined from "../Core/defined.js";
4
+ import getJsonFromTypedArray from "../Core/getJsonFromTypedArray.js";
5
+ import MetadataTable from "./MetadataTable.js";
6
+
7
+ /**
8
+ * An object representing voxel content for a {@link Cesium3DTilesVoxelProvider}.
9
+ *
10
+ * @alias VoxelContent
11
+ * @constructor
12
+ *
13
+ * @param {Resource} resource The resource for this voxel content. This is used for fetching external buffers as needed.
14
+ * @param {Object} [json] Voxel JSON contents. Mutually exclusive with binary.
15
+ * @param {Uint8Array} [binary] Voxel binary contents. Mutually exclusive with json.
16
+ * @param {MetadataSchema} metadataSchema The metadata schema used by property tables in the voxel content
17
+ *
18
+ * @exception {DeveloperError} One of json and binary must be defined.
19
+ *
20
+ * @private
21
+ * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy.
22
+ */
23
+ function VoxelContent(resource, json, binary, metadataSchema) {
24
+ //>>includeStart('debug', pragmas.debug);
25
+ Check.typeOf.object("resource", resource);
26
+ if (defined(json) === defined(binary)) {
27
+ throw new DeveloperError("One of json and binary must be defined.");
28
+ }
29
+ //>>includeEnd('debug');
30
+
31
+ this._resource = resource;
32
+ this._metadataTable = undefined;
33
+
34
+ let chunks;
35
+ if (defined(json)) {
36
+ chunks = {
37
+ json: json,
38
+ binary: undefined,
39
+ };
40
+ } else {
41
+ chunks = parseVoxelChunks(binary);
42
+ }
43
+
44
+ this._readyPromise = initialize(
45
+ this,
46
+ chunks.json,
47
+ chunks.binary,
48
+ metadataSchema
49
+ );
50
+ }
51
+
52
+ Object.defineProperties(VoxelContent.prototype, {
53
+ /**
54
+ * A promise that resolves once all buffers are loaded.
55
+ *
56
+ * @type {Promise}
57
+ * @readonly
58
+ * @private
59
+ */
60
+ readyPromise: {
61
+ get: function () {
62
+ return this._readyPromise;
63
+ },
64
+ },
65
+
66
+ /**
67
+ * The {@link MetadataTable} storing voxel property values.
68
+ *
69
+ * @type {MetadataTable}
70
+ * @readonly
71
+ * @private
72
+ */
73
+ metadataTable: {
74
+ get: function () {
75
+ return this._metadataTable;
76
+ },
77
+ },
78
+ });
79
+
80
+ function initialize(content, json, binary, metadataSchema) {
81
+ return requestBuffers(content, json, binary).then(function (buffersU8) {
82
+ const bufferViewsU8 = {};
83
+ const bufferViewsLength = json.bufferViews.length;
84
+ for (let i = 0; i < bufferViewsLength; ++i) {
85
+ const bufferViewJson = json.bufferViews[i];
86
+ const start = bufferViewJson.byteOffset;
87
+ const end = start + bufferViewJson.byteLength;
88
+ const buffer = buffersU8[bufferViewJson.buffer];
89
+ const bufferView = buffer.subarray(start, end);
90
+ bufferViewsU8[i] = bufferView;
91
+ }
92
+
93
+ const propertyTableIndex = json.voxelTable;
94
+ const propertyTableJson = json.propertyTables[propertyTableIndex];
95
+ content._metadataTable = new MetadataTable({
96
+ count: propertyTableJson.count,
97
+ properties: propertyTableJson.properties,
98
+ class: metadataSchema.classes[propertyTableJson.class],
99
+ bufferViews: bufferViewsU8,
100
+ });
101
+ return content;
102
+ });
103
+ }
104
+
105
+ function requestBuffers(content, json, binary) {
106
+ const buffersLength = json.buffers.length;
107
+ const bufferPromises = new Array(buffersLength);
108
+ for (let i = 0; i < buffersLength; i++) {
109
+ const buffer = json.buffers[i];
110
+ if (defined(buffer.uri)) {
111
+ const baseResource = content._resource;
112
+ const bufferResource = baseResource.getDerivedResource({
113
+ url: buffer.uri,
114
+ });
115
+ bufferPromises[i] = bufferResource
116
+ .fetchArrayBuffer()
117
+ .then(function (arrayBuffer) {
118
+ return new Uint8Array(arrayBuffer);
119
+ });
120
+ } else {
121
+ bufferPromises[i] = Promise.resolve(binary);
122
+ }
123
+ }
124
+
125
+ return Promise.all(bufferPromises);
126
+ }
127
+
128
+ /**
129
+ * A helper object for storing the two parts of the binary voxel content
130
+ *
131
+ * @typedef {Object} VoxelChunks
132
+ * @property {Object} json The json chunk of the binary voxel content
133
+ * @property {Uint8Array} binary The binary chunk of the binary voxel content. This represents the internal buffer.
134
+ * @private
135
+ */
136
+
137
+ /**
138
+ * Given binary voxel content, split into JSON and binary chunks
139
+ *
140
+ * @param {Uint8Array} binaryView The binary voxel content
141
+ * @returns {VoxelChunks} An object containing the JSON and binary chunks
142
+ * @private
143
+ */
144
+ function parseVoxelChunks(binaryView) {
145
+ // Parse the header
146
+ const littleEndian = true;
147
+ const reader = new DataView(binaryView.buffer, binaryView.byteOffset);
148
+ // Skip to the chunk lengths
149
+ let byteOffset = 8;
150
+
151
+ // Read the bottom 32 bits of the 64-bit byte length. This is ok for now because:
152
+ // 1) not all browsers have native 64-bit operations
153
+ // 2) the data is well under 4GB
154
+ const jsonByteLength = reader.getUint32(byteOffset, littleEndian);
155
+ byteOffset += 8;
156
+ const binaryByteLength = reader.getUint32(byteOffset, littleEndian);
157
+ byteOffset += 8;
158
+
159
+ const json = getJsonFromTypedArray(binaryView, byteOffset, jsonByteLength);
160
+ byteOffset += jsonByteLength;
161
+ const binary = binaryView.subarray(byteOffset, byteOffset + binaryByteLength);
162
+
163
+ return {
164
+ json: json,
165
+ binary: binary,
166
+ };
167
+ }
168
+
169
+ export default VoxelContent;