@cesium/engine 1.0.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 (196) 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/decodeI3S.js +1 -1
  80. package/Build/Workers/package.js +25 -1
  81. package/Build/Workers/transferTypedArrayTest.js +25 -1
  82. package/Build/Workers/upsampleQuantizedTerrainMesh.js +1 -1
  83. package/Source/Core/EarthOrientationParameters.js +67 -63
  84. package/Source/Core/Ion.js +1 -1
  85. package/Source/Core/Matrix2.js +2 -1
  86. package/Source/Core/Matrix3.js +2 -1
  87. package/Source/Core/Matrix4.js +1 -0
  88. package/Source/Core/OrientedBoundingBox.js +4 -4
  89. package/Source/Core/S2Cell.js +3 -3
  90. package/Source/Core/Transforms.js +3 -7
  91. package/Source/DataSources/GpxDataSource.js +4 -6
  92. package/Source/DataSources/KmlDataSource.js +3 -5
  93. package/Source/Renderer/Context.js +27 -9
  94. package/Source/Renderer/Pass.js +3 -2
  95. package/Source/Scene/Cesium3DTileContentType.js +19 -0
  96. package/Source/Scene/Cesium3DTilesVoxelProvider.js +482 -0
  97. package/Source/Scene/Cesium3DTilesetMetadata.js +2 -2
  98. package/Source/Scene/ContentMetadata.js +2 -2
  99. package/Source/Scene/DerivedCommand.js +7 -0
  100. package/Source/Scene/Expression.js +1 -1
  101. package/Source/Scene/Globe.js +10 -0
  102. package/Source/Scene/GlobeSurfaceTileProvider.js +7 -0
  103. package/Source/Scene/GltfImageLoader.js +1 -1
  104. package/Source/Scene/GltfVertexBufferLoader.js +10 -2
  105. package/Source/Scene/GroupMetadata.js +2 -2
  106. package/Source/Scene/ImplicitMetadataView.js +2 -2
  107. package/Source/Scene/ImplicitSubtreeCache.js +127 -0
  108. package/Source/Scene/ImplicitSubtreeMetadata.js +2 -2
  109. package/Source/Scene/ImplicitTileset.js +3 -2
  110. package/Source/Scene/KeyframeNode.js +47 -0
  111. package/Source/Scene/Megatexture.js +490 -0
  112. package/Source/Scene/MetadataClass.js +60 -25
  113. package/Source/Scene/MetadataClassProperty.js +132 -68
  114. package/Source/Scene/MetadataComponentType.js +78 -57
  115. package/Source/Scene/MetadataEnum.js +59 -23
  116. package/Source/Scene/MetadataEnumValue.js +49 -15
  117. package/Source/Scene/MetadataSchema.js +53 -24
  118. package/Source/Scene/MetadataSchemaLoader.js +2 -2
  119. package/Source/Scene/MetadataTableProperty.js +2 -2
  120. package/Source/Scene/MetadataType.js +6 -14
  121. package/Source/Scene/Model/GeoJsonLoader.js +1 -1
  122. package/Source/Scene/Model/Model.js +2 -3
  123. package/Source/Scene/Model/buildDrawCommand.js +19 -11
  124. package/Source/Scene/PointCloud.js +1 -1
  125. package/Source/Scene/PropertyAttribute.js +2 -2
  126. package/Source/Scene/PropertyAttributeProperty.js +2 -2
  127. package/Source/Scene/PropertyTable.js +2 -2
  128. package/Source/Scene/PropertyTexture.js +2 -2
  129. package/Source/Scene/PropertyTextureProperty.js +2 -2
  130. package/Source/Scene/ResourceCache.js +9 -1
  131. package/Source/Scene/ResourceCacheKey.js +9 -1
  132. package/Source/Scene/Scene.js +17 -0
  133. package/Source/Scene/SpatialNode.js +375 -0
  134. package/Source/Scene/StructuralMetadata.js +2 -2
  135. package/Source/Scene/TileMetadata.js +2 -2
  136. package/Source/Scene/TilesetMetadata.js +2 -2
  137. package/Source/Scene/VoxelBoxShape.js +527 -0
  138. package/Source/Scene/VoxelContent.js +169 -0
  139. package/Source/Scene/VoxelCylinderShape.js +937 -0
  140. package/Source/Scene/VoxelEllipsoidShape.js +937 -0
  141. package/Source/Scene/VoxelPrimitive.js +1919 -0
  142. package/Source/Scene/VoxelProvider.js +255 -0
  143. package/Source/Scene/VoxelRenderResources.js +224 -0
  144. package/Source/Scene/VoxelShape.js +152 -0
  145. package/Source/Scene/VoxelShapeType.js +105 -0
  146. package/Source/Scene/VoxelTraversal.js +1144 -0
  147. package/Source/Scene/buildVoxelDrawCommands.js +116 -0
  148. package/Source/Scene/parseBatchTable.js +18 -2
  149. package/Source/Scene/preprocess3DTileContent.js +8 -0
  150. package/Source/Scene/processVoxelProperties.js +455 -0
  151. package/Source/Shaders/BillboardCollectionVS.glsl +1 -1
  152. package/Source/Shaders/BillboardCollectionVS.js +1 -1
  153. package/Source/Shaders/Builtin/Constants/passOverlay.glsl +1 -1
  154. package/Source/Shaders/Builtin/Constants/passOverlay.js +1 -1
  155. package/Source/Shaders/Builtin/Constants/passVoxels.glsl +9 -0
  156. package/Source/Shaders/Builtin/Constants/passVoxels.js +11 -0
  157. package/Source/Shaders/Builtin/CzmBuiltins.js +17 -15
  158. package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.glsl +55 -43
  159. package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.js +55 -43
  160. package/Source/Shaders/GlobeFS.glsl +2 -1
  161. package/Source/Shaders/GlobeFS.js +2 -1
  162. package/Source/Shaders/PointPrimitiveCollectionVS.glsl +5 -2
  163. package/Source/Shaders/PointPrimitiveCollectionVS.js +5 -2
  164. package/Source/Shaders/Voxels/IntersectBox.glsl +79 -0
  165. package/Source/Shaders/Voxels/IntersectBox.js +81 -0
  166. package/Source/Shaders/Voxels/IntersectClippingPlanes.glsl +70 -0
  167. package/Source/Shaders/Voxels/IntersectClippingPlanes.js +72 -0
  168. package/Source/Shaders/Voxels/IntersectCylinder.glsl +273 -0
  169. package/Source/Shaders/Voxels/IntersectCylinder.js +275 -0
  170. package/Source/Shaders/Voxels/IntersectDepth.glsl +23 -0
  171. package/Source/Shaders/Voxels/IntersectDepth.js +25 -0
  172. package/Source/Shaders/Voxels/IntersectEllipsoid.glsl +337 -0
  173. package/Source/Shaders/Voxels/IntersectEllipsoid.js +339 -0
  174. package/Source/Shaders/Voxels/Intersection.glsl +54 -0
  175. package/Source/Shaders/Voxels/Intersection.js +56 -0
  176. package/Source/Shaders/Voxels/IntersectionUtils.glsl +151 -0
  177. package/Source/Shaders/Voxels/IntersectionUtils.js +153 -0
  178. package/Source/Shaders/Voxels/Megatexture.glsl +136 -0
  179. package/Source/Shaders/Voxels/Megatexture.js +138 -0
  180. package/Source/Shaders/Voxels/Octree.glsl +221 -0
  181. package/Source/Shaders/Voxels/Octree.js +223 -0
  182. package/Source/Shaders/Voxels/VoxelFS.glsl +150 -0
  183. package/Source/Shaders/Voxels/VoxelFS.js +152 -0
  184. package/Source/Shaders/Voxels/VoxelVS.glsl +11 -0
  185. package/Source/Shaders/Voxels/VoxelVS.js +13 -0
  186. package/Source/Shaders/Voxels/convertUvToBox.glsl +16 -0
  187. package/Source/Shaders/Voxels/convertUvToBox.js +18 -0
  188. package/Source/Shaders/Voxels/convertUvToCylinder.glsl +79 -0
  189. package/Source/Shaders/Voxels/convertUvToCylinder.js +81 -0
  190. package/Source/Shaders/Voxels/convertUvToEllipsoid.glsl +133 -0
  191. package/Source/Shaders/Voxels/convertUvToEllipsoid.js +135 -0
  192. package/Source/ThirdParty/Workers/z-worker-pako.js +0 -0
  193. package/index.d.ts +3124 -2287
  194. package/index.js +1117 -1085
  195. package/package.json +3 -4
  196. package/Build/Workers/PolygonPipeline-774a8aaf.js +0 -1341
@@ -0,0 +1,937 @@
1
+ import BoundingSphere from "../Core/BoundingSphere.js";
2
+ import Cartesian2 from "../Core/Cartesian2.js";
3
+ import Cartesian3 from "../Core/Cartesian3.js";
4
+ import Check from "../Core/Check.js";
5
+ import Ellipsoid from "../Core/Ellipsoid.js";
6
+ import CesiumMath from "../Core/Math.js";
7
+ import Matrix3 from "../Core/Matrix3.js";
8
+ import Matrix4 from "../Core/Matrix4.js";
9
+ import OrientedBoundingBox from "../Core/OrientedBoundingBox.js";
10
+ import Rectangle from "../Core/Rectangle.js";
11
+ import defaultValue from "../Core/defaultValue.js";
12
+
13
+ /**
14
+ * An ellipsoid {@link VoxelShape}.
15
+ *
16
+ * @alias VoxelEllipsoidShape
17
+ * @constructor
18
+ *
19
+ * @see VoxelShape
20
+ * @see VoxelBoxShape
21
+ * @see VoxelCylinderShape
22
+ * @see VoxelShapeType
23
+ *
24
+ * @private
25
+ */
26
+ function VoxelEllipsoidShape() {
27
+ /**
28
+ * An oriented bounding box containing the bounded shape.
29
+ * The update function must be called before accessing this value.
30
+ * @type {OrientedBoundingBox}
31
+ * @readonly
32
+ */
33
+ this.orientedBoundingBox = new OrientedBoundingBox();
34
+
35
+ /**
36
+ * A bounding sphere containing the bounded shape.
37
+ * The update function must be called before accessing this value.
38
+ * @type {BoundingSphere}
39
+ * @readonly
40
+ */
41
+ this.boundingSphere = new BoundingSphere();
42
+
43
+ /**
44
+ * A transformation matrix containing the bounded shape.
45
+ * The update function must be called before accessing this value.
46
+ * @type {Matrix4}
47
+ * @readonly
48
+ */
49
+ this.boundTransform = new Matrix4();
50
+
51
+ /**
52
+ * A transformation matrix containing the shape, ignoring the bounds.
53
+ * The update function must be called before accessing this value.
54
+ * @type {Matrix4}
55
+ * @readonly
56
+ */
57
+ this.shapeTransform = new Matrix4();
58
+
59
+ /**
60
+ * @type {Rectangle}
61
+ */
62
+ this._rectangle = new Rectangle();
63
+
64
+ /**
65
+ * @type {Number}
66
+ * @private
67
+ */
68
+ this._minimumHeight = VoxelEllipsoidShape.DefaultMinBounds.z;
69
+
70
+ /**
71
+ * @type {Number}
72
+ * @private
73
+ */
74
+ this._maximumHeight = VoxelEllipsoidShape.DefaultMaxBounds.z;
75
+
76
+ /**
77
+ * @type {Ellipsoid}
78
+ * @private
79
+ */
80
+ this._ellipsoid = new Ellipsoid();
81
+
82
+ /**
83
+ * @type {Cartesian3}
84
+ */
85
+ this._translation = new Cartesian3();
86
+
87
+ /**
88
+ * @type {Matrix3}
89
+ */
90
+ this._rotation = new Matrix3();
91
+
92
+ /**
93
+ * @type {Object.<string, any>}
94
+ * @readonly
95
+ */
96
+ this.shaderUniforms = {
97
+ ellipsoidRadiiUv: new Cartesian3(),
98
+ ellipsoidInverseRadiiSquaredUv: new Cartesian3(),
99
+ ellipsoidRenderLongitudeMinMax: new Cartesian2(),
100
+ ellipsoidShapeUvLongitudeMinMaxMid: new Cartesian3(),
101
+ ellipsoidUvToShapeUvLongitude: new Cartesian2(),
102
+ ellipsoidUvToShapeUvLatitude: new Cartesian2(),
103
+ ellipsoidRenderLatitudeCosSqrHalfMinMax: new Cartesian2(),
104
+ ellipsoidInverseHeightDifferenceUv: 0.0,
105
+ ellipseInnerRadiiUv: new Cartesian2(),
106
+ ellipsoidInverseInnerScaleUv: 0.0,
107
+ };
108
+
109
+ /**
110
+ * @type {Object.<string, any>}
111
+ * @readonly
112
+ */
113
+ this.shaderDefines = {
114
+ ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE: undefined,
115
+ ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_EQUAL_ZERO: undefined,
116
+ ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_UNDER_HALF: undefined,
117
+ ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_EQUAL_HALF: undefined,
118
+ ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_OVER_HALF: undefined,
119
+ ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_MIN_DISCONTINUITY: undefined,
120
+ ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_MAX_DISCONTINUITY: undefined,
121
+ ELLIPSOID_HAS_SHAPE_BOUNDS_LONGITUDE: undefined,
122
+ ELLIPSOID_HAS_SHAPE_BOUNDS_LONGITUDE_RANGE_EQUAL_ZERO: undefined,
123
+ ELLIPSOID_HAS_SHAPE_BOUNDS_LONGITUDE_MIN_MAX_REVERSED: undefined,
124
+ ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE: undefined,
125
+ ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_UNDER_HALF: undefined,
126
+ ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_EQUAL_HALF: undefined,
127
+ ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_OVER_HALF: undefined,
128
+ ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_UNDER_HALF: undefined,
129
+ ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_EQUAL_HALF: undefined,
130
+ ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_OVER_HALF: undefined,
131
+ ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_RANGE_EQUAL_ZERO: undefined,
132
+ ELLIPSOID_HAS_SHAPE_BOUNDS_LATITUDE: undefined,
133
+ ELLIPSOID_HAS_SHAPE_BOUNDS_LATITUDE_RANGE_EQUAL_ZERO: undefined,
134
+ ELLIPSOID_HAS_RENDER_BOUNDS_HEIGHT_MIN: undefined,
135
+ ELLIPSOID_HAS_SHAPE_BOUNDS_HEIGHT_MIN: undefined,
136
+ ELLIPSOID_HAS_SHAPE_BOUNDS_HEIGHT_FLAT: undefined,
137
+ ELLIPSOID_IS_SPHERE: undefined,
138
+ ELLIPSOID_INTERSECTION_INDEX_LONGITUDE: undefined,
139
+ ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MAX: undefined,
140
+ ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MIN: undefined,
141
+ ELLIPSOID_INTERSECTION_INDEX_HEIGHT_MAX: undefined,
142
+ ELLIPSOID_INTERSECTION_INDEX_HEIGHT_MIN: undefined,
143
+ };
144
+
145
+ /**
146
+ * The maximum number of intersections against the shape for any ray direction.
147
+ * @type {Number}
148
+ * @readonly
149
+ */
150
+ this.shaderMaximumIntersectionsLength = 0; // not known until update
151
+ }
152
+
153
+ const scratchScale = new Cartesian3();
154
+ const scratchRotationScale = new Matrix3();
155
+ const scratchShapeOuterExtent = new Cartesian3();
156
+ const scratchShapeInnerExtent = new Cartesian3();
157
+ const scratchRenderOuterExtent = new Cartesian3();
158
+ const scratchRenderInnerExtent = new Cartesian3();
159
+ const scratchRenderRectangle = new Rectangle();
160
+
161
+ /**
162
+ * Update the shape's state.
163
+ *
164
+ * @param {Matrix4} modelMatrix The model matrix.
165
+ * @param {Cartesian3} minBounds The minimum bounds.
166
+ * @param {Cartesian3} maxBounds The maximum bounds.
167
+ * @param {Cartesian3} [clipMinBounds=VoxelEllipsoidShape.DefaultMinBounds] The minimum clip bounds.
168
+ * @param {Cartesian3} [clipMaxBounds=VoxelEllipsoidShape.DefaultMaxBounds] The maximum clip bounds.
169
+ * @returns {Boolean} Whether the shape is visible.
170
+ */
171
+ VoxelEllipsoidShape.prototype.update = function (
172
+ modelMatrix,
173
+ minBounds,
174
+ maxBounds,
175
+ clipMinBounds,
176
+ clipMaxBounds
177
+ ) {
178
+ clipMinBounds = defaultValue(
179
+ clipMinBounds,
180
+ VoxelEllipsoidShape.DefaultMinBounds
181
+ );
182
+ clipMaxBounds = defaultValue(
183
+ clipMaxBounds,
184
+ VoxelEllipsoidShape.DefaultMaxBounds
185
+ );
186
+ //>>includeStart('debug', pragmas.debug);
187
+ Check.typeOf.object("modelMatrix", modelMatrix);
188
+ Check.typeOf.object("minBounds", minBounds);
189
+ Check.typeOf.object("maxBounds", maxBounds);
190
+ //>>includeEnd('debug');
191
+
192
+ const defaultMinLongitude = VoxelEllipsoidShape.DefaultMinBounds.x;
193
+ const defaultMaxLongitude = VoxelEllipsoidShape.DefaultMaxBounds.x;
194
+ const defaultLongitudeRange = defaultMaxLongitude - defaultMinLongitude;
195
+ const defaultLongitudeRangeHalf = 0.5 * defaultLongitudeRange;
196
+ const defaultMinLatitude = VoxelEllipsoidShape.DefaultMinBounds.y;
197
+ const defaultMaxLatitude = VoxelEllipsoidShape.DefaultMaxBounds.y;
198
+ const defaultLatitudeRange = defaultMaxLatitude - defaultMinLatitude;
199
+
200
+ const epsilonZeroScale = CesiumMath.EPSILON10;
201
+ const epsilonLongitudeDiscontinuity = CesiumMath.EPSILON3; // 0.001 radians = 0.05729578 degrees
202
+ const epsilonLongitude = CesiumMath.EPSILON10;
203
+ const epsilonLatitude = CesiumMath.EPSILON10;
204
+ const epsilonLatitudeFlat = CesiumMath.EPSILON3; // 0.001 radians = 0.05729578 degrees
205
+
206
+ // Clamp the longitude / latitude to the valid range
207
+ const shapeMinLongitude = CesiumMath.clamp(
208
+ minBounds.x,
209
+ defaultMinLongitude,
210
+ defaultMaxLongitude
211
+ );
212
+ const shapeMaxLongitude = CesiumMath.clamp(
213
+ maxBounds.x,
214
+ defaultMinLongitude,
215
+ defaultMaxLongitude
216
+ );
217
+ const clipMinLongitude = CesiumMath.clamp(
218
+ clipMinBounds.x,
219
+ defaultMinLongitude,
220
+ defaultMaxLongitude
221
+ );
222
+ const clipMaxLongitude = CesiumMath.clamp(
223
+ clipMaxBounds.x,
224
+ defaultMinLongitude,
225
+ defaultMaxLongitude
226
+ );
227
+ const renderMinLongitude = Math.max(shapeMinLongitude, clipMinLongitude);
228
+ const renderMaxLongitude = Math.min(shapeMaxLongitude, clipMaxLongitude);
229
+
230
+ const shapeMinLatitude = CesiumMath.clamp(
231
+ minBounds.y,
232
+ defaultMinLatitude,
233
+ defaultMaxLatitude
234
+ );
235
+ const shapeMaxLatitude = CesiumMath.clamp(
236
+ maxBounds.y,
237
+ defaultMinLatitude,
238
+ defaultMaxLatitude
239
+ );
240
+ const clipMinLatitude = CesiumMath.clamp(
241
+ clipMinBounds.y,
242
+ defaultMinLatitude,
243
+ defaultMaxLatitude
244
+ );
245
+ const clipMaxLatitude = CesiumMath.clamp(
246
+ clipMaxBounds.y,
247
+ defaultMinLatitude,
248
+ defaultMaxLatitude
249
+ );
250
+
251
+ const renderMinLatitude = Math.max(shapeMinLatitude, clipMinLatitude);
252
+ const renderMaxLatitude = Math.min(shapeMaxLatitude, clipMaxLatitude);
253
+
254
+ // Don't let the height go below the center of the ellipsoid.
255
+ const radii = Matrix4.getScale(modelMatrix, scratchScale);
256
+ const isSphere = radii.x === radii.y && radii.y === radii.z;
257
+ const minRadius = Cartesian3.minimumComponent(radii);
258
+ const shapeMinHeight = Math.max(minBounds.z, -minRadius);
259
+ const shapeMaxHeight = Math.max(maxBounds.z, -minRadius);
260
+ const clipMinHeight = Math.max(clipMinBounds.z, -minRadius);
261
+ const clipMaxHeight = Math.max(clipMaxBounds.z, -minRadius);
262
+ const renderMinHeight = Math.max(shapeMinHeight, clipMinHeight);
263
+ const renderMaxHeight = Math.min(shapeMaxHeight, clipMaxHeight);
264
+
265
+ // Compute the closest and farthest a point can be from the center of the ellipsoid.
266
+ const shapeInnerExtent = Cartesian3.add(
267
+ radii,
268
+ Cartesian3.fromElements(
269
+ shapeMinHeight,
270
+ shapeMinHeight,
271
+ shapeMinHeight,
272
+ scratchShapeInnerExtent
273
+ ),
274
+ scratchShapeInnerExtent
275
+ );
276
+ const shapeOuterExtent = Cartesian3.add(
277
+ radii,
278
+ Cartesian3.fromElements(
279
+ shapeMaxHeight,
280
+ shapeMaxHeight,
281
+ shapeMaxHeight,
282
+ scratchShapeOuterExtent
283
+ ),
284
+ scratchShapeOuterExtent
285
+ );
286
+ const shapeMaxExtent = Cartesian3.maximumComponent(shapeOuterExtent);
287
+
288
+ const renderInnerExtent = Cartesian3.add(
289
+ radii,
290
+ Cartesian3.fromElements(
291
+ renderMinHeight,
292
+ renderMinHeight,
293
+ renderMinHeight,
294
+ scratchRenderInnerExtent
295
+ ),
296
+ scratchRenderInnerExtent
297
+ );
298
+ const renderOuterExtent = Cartesian3.add(
299
+ radii,
300
+ Cartesian3.fromElements(
301
+ renderMaxHeight,
302
+ renderMaxHeight,
303
+ renderMaxHeight,
304
+ scratchRenderOuterExtent
305
+ ),
306
+ scratchRenderOuterExtent
307
+ );
308
+ const renderMaxExtent = Cartesian3.maximumComponent(renderOuterExtent);
309
+
310
+ // Exit early if the shape is not visible.
311
+ // Note that minLongitude may be greater than maxLongitude when crossing the 180th meridian.
312
+ if (
313
+ renderMinLatitude > renderMaxLatitude ||
314
+ renderMinLatitude === defaultMaxLatitude ||
315
+ renderMaxLatitude === defaultMinLatitude ||
316
+ renderMinHeight > renderMaxHeight ||
317
+ CesiumMath.equalsEpsilon(
318
+ renderOuterExtent,
319
+ Cartesian3.ZERO,
320
+ undefined,
321
+ epsilonZeroScale
322
+ )
323
+ ) {
324
+ return false;
325
+ }
326
+
327
+ this._rectangle = Rectangle.fromRadians(
328
+ shapeMinLongitude,
329
+ shapeMinLatitude,
330
+ shapeMaxLongitude,
331
+ shapeMaxLatitude
332
+ );
333
+ this._translation = Matrix4.getTranslation(modelMatrix, this._translation);
334
+ this._rotation = Matrix4.getRotation(modelMatrix, this._rotation);
335
+ this._ellipsoid = Ellipsoid.fromCartesian3(radii, this._ellipsoid);
336
+ this._minimumHeight = shapeMinHeight;
337
+ this._maximumHeight = shapeMaxHeight;
338
+
339
+ const renderRectangle = Rectangle.fromRadians(
340
+ renderMinLongitude,
341
+ renderMinLatitude,
342
+ renderMaxLongitude,
343
+ renderMaxLatitude,
344
+ scratchRenderRectangle
345
+ );
346
+
347
+ this.orientedBoundingBox = getEllipsoidChunkObb(
348
+ renderRectangle,
349
+ renderMinHeight,
350
+ renderMaxHeight,
351
+ this._ellipsoid,
352
+ this._translation,
353
+ this._rotation,
354
+ this.orientedBoundingBox
355
+ );
356
+
357
+ this.shapeTransform = Matrix4.fromRotationTranslation(
358
+ Matrix3.setScale(this._rotation, renderOuterExtent, scratchRotationScale),
359
+ this._translation,
360
+ this.shapeTransform
361
+ );
362
+
363
+ this.boundTransform = Matrix4.fromRotationTranslation(
364
+ this.orientedBoundingBox.halfAxes,
365
+ this.orientedBoundingBox.center,
366
+ this.boundTransform
367
+ );
368
+
369
+ this.boundingSphere = BoundingSphere.fromOrientedBoundingBox(
370
+ this.orientedBoundingBox,
371
+ this.boundingSphere
372
+ );
373
+
374
+ // Longitude
375
+ const renderIsLongitudeReversed = renderMaxLongitude < renderMinLongitude;
376
+ const renderLongitudeRange =
377
+ renderMaxLongitude -
378
+ renderMinLongitude +
379
+ renderIsLongitudeReversed * defaultLongitudeRange;
380
+ const renderIsLongitudeRangeZero = renderLongitudeRange <= epsilonLongitude;
381
+ const renderIsLongitudeRangeUnderHalf =
382
+ renderLongitudeRange > defaultLongitudeRangeHalf + epsilonLongitude &&
383
+ renderLongitudeRange < defaultLongitudeRange - epsilonLongitude;
384
+ const renderIsLongitudeRangeHalf =
385
+ renderLongitudeRange >= defaultLongitudeRangeHalf - epsilonLongitude &&
386
+ renderLongitudeRange <= defaultLongitudeRangeHalf + epsilonLongitude;
387
+ const renderIsLongitudeRangeOverHalf =
388
+ renderLongitudeRange > epsilonLongitude &&
389
+ renderLongitudeRange < defaultLongitudeRangeHalf - epsilonLongitude;
390
+ const renderHasLongitude =
391
+ renderIsLongitudeRangeZero ||
392
+ renderIsLongitudeRangeUnderHalf ||
393
+ renderIsLongitudeRangeHalf ||
394
+ renderIsLongitudeRangeOverHalf;
395
+
396
+ const shapeIsLongitudeReversed = renderMaxLongitude < renderMinLongitude;
397
+ const shapeLongitudeRange =
398
+ shapeMaxLongitude -
399
+ shapeMinLongitude +
400
+ shapeIsLongitudeReversed * defaultLongitudeRange;
401
+ const shapeIsLongitudeRangeZero = shapeLongitudeRange <= epsilonLongitude;
402
+ const shapeIsLongitudeRangeUnderHalf =
403
+ shapeLongitudeRange > defaultLongitudeRangeHalf + epsilonLongitude &&
404
+ shapeLongitudeRange < defaultLongitudeRange - epsilonLongitude;
405
+ const shapeIsLongitudeRangeHalf =
406
+ shapeLongitudeRange >= defaultLongitudeRangeHalf - epsilonLongitude &&
407
+ shapeLongitudeRange <= defaultLongitudeRangeHalf + epsilonLongitude;
408
+ const shapeIsLongitudeRangeOverHalf =
409
+ shapeLongitudeRange > epsilonLongitude &&
410
+ shapeLongitudeRange < defaultLongitudeRangeHalf - epsilonLongitude;
411
+ const shapeHasLongitude =
412
+ shapeIsLongitudeRangeZero ||
413
+ shapeIsLongitudeRangeUnderHalf ||
414
+ shapeIsLongitudeRangeHalf ||
415
+ shapeIsLongitudeRangeOverHalf;
416
+
417
+ // Latitude
418
+ const renderIsLatitudeMaxUnderHalf = renderMaxLatitude < -epsilonLatitudeFlat;
419
+ const renderIsLatitudeMaxHalf =
420
+ renderMaxLatitude >= -epsilonLatitudeFlat &&
421
+ renderMaxLatitude <= +epsilonLatitudeFlat;
422
+ const renderIsLatitudeMaxOverHalf =
423
+ renderMaxLatitude > +epsilonLatitudeFlat &&
424
+ renderMaxLatitude < defaultMaxLatitude - epsilonLatitude;
425
+ const renderHasLatitudeMax =
426
+ renderIsLatitudeMaxUnderHalf ||
427
+ renderIsLatitudeMaxHalf ||
428
+ renderIsLatitudeMaxOverHalf;
429
+ const renderIsLatitudeMinUnderHalf =
430
+ renderMinLatitude > defaultMinLatitude + epsilonLatitude &&
431
+ renderMinLatitude < -epsilonLatitudeFlat;
432
+ const renderIsLatitudeMinHalf =
433
+ renderMinLatitude >= -epsilonLatitudeFlat &&
434
+ renderMinLatitude <= +epsilonLatitudeFlat;
435
+ const renderIsLatitudeMinOverHalf = renderMinLatitude > +epsilonLatitudeFlat;
436
+ const renderHasLatitudeMin =
437
+ renderIsLatitudeMinUnderHalf ||
438
+ renderIsLatitudeMinHalf ||
439
+ renderIsLatitudeMinOverHalf;
440
+ const renderHasLatitude = renderHasLatitudeMax || renderHasLatitudeMin;
441
+
442
+ const shapeLatitudeRange = shapeMaxLatitude - shapeMinLatitude;
443
+ const shapeIsLatitudeMaxUnderHalf = shapeMaxLatitude < -epsilonLatitudeFlat;
444
+ const shapeIsLatitudeMaxHalf =
445
+ shapeMaxLatitude >= -epsilonLatitudeFlat &&
446
+ shapeMaxLatitude <= +epsilonLatitudeFlat;
447
+ const shapeIsLatitudeMaxOverHalf =
448
+ shapeMaxLatitude > +epsilonLatitudeFlat &&
449
+ shapeMaxLatitude < defaultMaxLatitude - epsilonLatitude;
450
+ const shapeHasLatitudeMax =
451
+ shapeIsLatitudeMaxUnderHalf ||
452
+ shapeIsLatitudeMaxHalf ||
453
+ shapeIsLatitudeMaxOverHalf;
454
+ const shapeIsLatitudeMinUnderHalf =
455
+ shapeMinLatitude > defaultMinLatitude + epsilonLatitude &&
456
+ shapeMinLatitude < -epsilonLatitudeFlat;
457
+ const shapeIsLatitudeMinHalf =
458
+ shapeMinLatitude >= -epsilonLatitudeFlat &&
459
+ shapeMinLatitude <= +epsilonLatitudeFlat;
460
+ const shapeIsLatitudeMinOverHalf = shapeMinLatitude > +epsilonLatitudeFlat;
461
+ const shapeHasLatitudeMin =
462
+ shapeIsLatitudeMinUnderHalf ||
463
+ shapeIsLatitudeMinHalf ||
464
+ shapeIsLatitudeMinOverHalf;
465
+ const shapeHasLatitude = shapeHasLatitudeMax || shapeHasLatitudeMin;
466
+
467
+ // Height
468
+ const renderHasMinHeight = !Cartesian3.equals(
469
+ renderInnerExtent,
470
+ Cartesian3.ZERO
471
+ );
472
+ const renderHasMaxHeight = !Cartesian3.equals(
473
+ renderOuterExtent,
474
+ Cartesian3.ZERO
475
+ );
476
+ const renderHasHeight = renderHasMinHeight || renderHasMaxHeight;
477
+ const renderHeightRange = renderMaxHeight - renderMinHeight;
478
+ const shapeHasMinHeight = !Cartesian3.equals(
479
+ shapeInnerExtent,
480
+ Cartesian3.ZERO
481
+ );
482
+ const shapeHasMaxHeight = !Cartesian3.equals(
483
+ shapeOuterExtent,
484
+ Cartesian3.ZERO
485
+ );
486
+ const shapeHasHeight = shapeHasMinHeight || shapeHasMaxHeight;
487
+
488
+ const shaderUniforms = this.shaderUniforms;
489
+ const shaderDefines = this.shaderDefines;
490
+
491
+ // To keep things simple, clear the defines every time
492
+ for (const key in shaderDefines) {
493
+ if (shaderDefines.hasOwnProperty(key)) {
494
+ shaderDefines[key] = undefined;
495
+ }
496
+ }
497
+
498
+ // The ellipsoid radii scaled to [0,1]. The max ellipsoid radius will be 1.0 and others will be less.
499
+ shaderUniforms.ellipsoidRadiiUv = Cartesian3.divideByScalar(
500
+ shapeOuterExtent,
501
+ shapeMaxExtent,
502
+ shaderUniforms.ellipsoidRadiiUv
503
+ );
504
+
505
+ // Used to compute geodetic surface normal.
506
+ shaderUniforms.ellipsoidInverseRadiiSquaredUv = Cartesian3.divideComponents(
507
+ Cartesian3.ONE,
508
+ Cartesian3.multiplyComponents(
509
+ shaderUniforms.ellipsoidRadiiUv,
510
+ shaderUniforms.ellipsoidRadiiUv,
511
+ shaderUniforms.ellipsoidInverseRadiiSquaredUv
512
+ ),
513
+ shaderUniforms.ellipsoidInverseRadiiSquaredUv
514
+ );
515
+
516
+ // Keep track of how many intersections there are going to be.
517
+ let intersectionCount = 0;
518
+
519
+ // Intersects an outer ellipsoid for the max height.
520
+ shaderDefines["ELLIPSOID_INTERSECTION_INDEX_HEIGHT_MAX"] = intersectionCount;
521
+ intersectionCount += 1;
522
+
523
+ if (renderHasHeight) {
524
+ if (renderHeightRange === 0.0) {
525
+ shaderDefines["ELLIPSOID_HAS_RENDER_BOUNDS_HEIGHT_FLAT"] = true;
526
+ }
527
+
528
+ if (renderHasMinHeight) {
529
+ shaderDefines["ELLIPSOID_HAS_RENDER_BOUNDS_HEIGHT_MIN"] = true;
530
+ shaderDefines[
531
+ "ELLIPSOID_INTERSECTION_INDEX_HEIGHT_MIN"
532
+ ] = intersectionCount;
533
+ intersectionCount += 1;
534
+
535
+ // The inverse of the percent of space that is taken up by the inner ellipsoid.
536
+ // 1.0 / (1.0 - thickness) // thickness = percent of space that is between the min and max height.
537
+ // 1.0 / (1.0 - (renderMaxHeight - renderMinHeight) / renderMaxExtent)
538
+ // renderMaxExtent / (renderMaxExtent - (renderMaxHeight - renderMinHeight))
539
+ shaderUniforms.ellipsoidInverseInnerScaleUv =
540
+ renderMaxExtent / (renderMaxExtent - renderHeightRange);
541
+ }
542
+ }
543
+
544
+ if (shapeHasHeight) {
545
+ if (shapeHasMinHeight) {
546
+ shaderDefines["ELLIPSOID_HAS_SHAPE_BOUNDS_HEIGHT_MIN"] = true;
547
+
548
+ // The percent of space that is between the inner and outer ellipsoid.
549
+ const thickness = (shapeMaxHeight - shapeMinHeight) / shapeMaxExtent;
550
+ shaderUniforms.ellipsoidInverseHeightDifferenceUv = 1.0 / thickness;
551
+ shaderUniforms.ellipseInnerRadiiUv = Cartesian2.fromElements(
552
+ shaderUniforms.ellipsoidRadiiUv.x * (1.0 - thickness),
553
+ shaderUniforms.ellipsoidRadiiUv.z * (1.0 - thickness),
554
+ shaderUniforms.ellipseInnerRadiiUv
555
+ );
556
+ }
557
+ if (shapeMinHeight === shapeMaxHeight) {
558
+ shaderDefines["ELLIPSOID_HAS_SHAPE_BOUNDS_HEIGHT_FLAT"] = true;
559
+ }
560
+ }
561
+
562
+ // Intersects a wedge for the min and max longitude.
563
+ if (renderHasLongitude) {
564
+ shaderDefines["ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE"] = true;
565
+ shaderDefines["ELLIPSOID_INTERSECTION_INDEX_LONGITUDE"] = intersectionCount;
566
+
567
+ if (renderIsLongitudeRangeUnderHalf) {
568
+ shaderDefines[
569
+ "ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_UNDER_HALF"
570
+ ] = true;
571
+ intersectionCount += 1;
572
+ } else if (renderIsLongitudeRangeOverHalf) {
573
+ shaderDefines[
574
+ "ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_OVER_HALF"
575
+ ] = true;
576
+ intersectionCount += 2;
577
+ } else if (renderIsLongitudeRangeHalf) {
578
+ shaderDefines[
579
+ "ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_EQUAL_HALF"
580
+ ] = true;
581
+ intersectionCount += 1;
582
+ } else if (renderIsLongitudeRangeZero) {
583
+ shaderDefines[
584
+ "ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_RANGE_EQUAL_ZERO"
585
+ ] = true;
586
+ intersectionCount += 2;
587
+ }
588
+
589
+ shaderUniforms.ellipsoidRenderLongitudeMinMax = Cartesian2.fromElements(
590
+ renderMinLongitude,
591
+ renderMaxLongitude,
592
+ shaderUniforms.ellipsoidRenderLongitudeMinMax
593
+ );
594
+ }
595
+
596
+ if (shapeHasLongitude) {
597
+ shaderDefines["ELLIPSOID_HAS_SHAPE_BOUNDS_LONGITUDE"] = true;
598
+
599
+ const shapeIsLongitudeReversed = shapeMaxLongitude < shapeMinLongitude;
600
+
601
+ if (shapeIsLongitudeReversed) {
602
+ shaderDefines[
603
+ "ELLIPSOID_HAS_SHAPE_BOUNDS_LONGITUDE_MIN_MAX_REVERSED"
604
+ ] = true;
605
+ }
606
+
607
+ // delerp(longitudeUv, minLongitudeUv, maxLongitudeUv)
608
+ // (longitudeUv - minLongitudeUv) / (maxLongitudeUv - minLongitudeUv)
609
+ // longitudeUv / (maxLongitudeUv - minLongitudeUv) - minLongitudeUv / (maxLongitudeUv - minLongitudeUv)
610
+ // scale = 1.0 / (maxLongitudeUv - minLongitudeUv)
611
+ // scale = 1.0 / (((maxLongitude - pi) / (2.0 * pi)) - ((minLongitude - pi) / (2.0 * pi)))
612
+ // scale = 2.0 * pi / (maxLongitude - minLongitude)
613
+ // offset = -minLongitudeUv / (maxLongitudeUv - minLongitudeUv)
614
+ // offset = -((minLongitude - pi) / (2.0 * pi)) / (((maxLongitude - pi) / (2.0 * pi)) - ((minLongitude - pi) / (2.0 * pi)))
615
+ // offset = -(minLongitude - pi) / (maxLongitude - minLongitude)
616
+ const scale = defaultLongitudeRange / shapeLongitudeRange;
617
+ const offset =
618
+ -(shapeMinLongitude - defaultMinLongitude) / shapeLongitudeRange;
619
+ shaderUniforms.ellipsoidUvToShapeUvLongitude = Cartesian2.fromElements(
620
+ scale,
621
+ offset,
622
+ shaderUniforms.ellipsoidUvToShapeUvLongitude
623
+ );
624
+ }
625
+
626
+ if (renderHasLongitude) {
627
+ const renderIsMinLongitudeDiscontinuity = CesiumMath.equalsEpsilon(
628
+ renderMinLongitude,
629
+ defaultMinLongitude,
630
+ undefined,
631
+ epsilonLongitudeDiscontinuity
632
+ );
633
+ const renderIsMaxLongitudeDiscontinuity = CesiumMath.equalsEpsilon(
634
+ renderMaxLongitude,
635
+ defaultMaxLongitude,
636
+ undefined,
637
+ epsilonLongitudeDiscontinuity
638
+ );
639
+
640
+ if (renderIsMinLongitudeDiscontinuity) {
641
+ shaderDefines[
642
+ "ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_MIN_DISCONTINUITY"
643
+ ] = true;
644
+ }
645
+ if (renderIsMaxLongitudeDiscontinuity) {
646
+ shaderDefines[
647
+ "ELLIPSOID_HAS_RENDER_BOUNDS_LONGITUDE_MAX_DISCONTINUITY"
648
+ ] = true;
649
+ }
650
+ const uvShapeMinLongitude =
651
+ (shapeMinLongitude - defaultMinLongitude) / defaultLongitudeRange;
652
+ const uvShapeMaxLongitude =
653
+ (shapeMaxLongitude - defaultMinLongitude) / defaultLongitudeRange;
654
+
655
+ const uvRenderMaxLongitude =
656
+ (renderMaxLongitude - defaultMinLongitude) / defaultLongitudeRange;
657
+ const uvRenderLongitudeRangeZero =
658
+ 1.0 - renderLongitudeRange / defaultLongitudeRange;
659
+ const uvRenderLongitudeRangeZeroMid =
660
+ (uvRenderMaxLongitude + 0.5 * uvRenderLongitudeRangeZero) % 1.0;
661
+
662
+ shaderUniforms.ellipsoidShapeUvLongitudeMinMaxMid = Cartesian3.fromElements(
663
+ uvShapeMinLongitude,
664
+ uvShapeMaxLongitude,
665
+ uvRenderLongitudeRangeZeroMid,
666
+ shaderUniforms.ellipsoidShapeUvLongitudeMinMaxMid
667
+ );
668
+ }
669
+
670
+ if (renderHasLatitude) {
671
+ shaderDefines["ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE"] = true;
672
+
673
+ // Intersects a cone for min latitude
674
+ if (renderHasLatitudeMin) {
675
+ shaderDefines["ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN"] = true;
676
+ shaderDefines[
677
+ "ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MIN"
678
+ ] = intersectionCount;
679
+
680
+ if (renderIsLatitudeMinUnderHalf) {
681
+ shaderDefines[
682
+ "ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_UNDER_HALF"
683
+ ] = true;
684
+ intersectionCount += 1;
685
+ } else if (renderIsLatitudeMinHalf) {
686
+ shaderDefines[
687
+ "ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_EQUAL_HALF"
688
+ ] = true;
689
+ intersectionCount += 1;
690
+ } else if (renderIsLatitudeMinOverHalf) {
691
+ shaderDefines[
692
+ "ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MIN_OVER_HALF"
693
+ ] = true;
694
+ intersectionCount += 2;
695
+ }
696
+ }
697
+
698
+ // Intersects a cone for max latitude
699
+ if (renderHasLatitudeMax) {
700
+ shaderDefines["ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX"] = true;
701
+ shaderDefines[
702
+ "ELLIPSOID_INTERSECTION_INDEX_LATITUDE_MAX"
703
+ ] = intersectionCount;
704
+
705
+ if (renderIsLatitudeMaxUnderHalf) {
706
+ shaderDefines[
707
+ "ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_UNDER_HALF"
708
+ ] = true;
709
+ intersectionCount += 2;
710
+ } else if (renderIsLatitudeMaxHalf) {
711
+ shaderDefines[
712
+ "ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_EQUAL_HALF"
713
+ ] = true;
714
+ intersectionCount += 1;
715
+ } else if (renderIsLatitudeMaxOverHalf) {
716
+ shaderDefines[
717
+ "ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_MAX_OVER_HALF"
718
+ ] = true;
719
+ intersectionCount += 1;
720
+ }
721
+ }
722
+
723
+ if (renderMinLatitude === renderMaxLatitude) {
724
+ shaderDefines[
725
+ "ELLIPSOID_HAS_RENDER_BOUNDS_LATITUDE_RANGE_EQUAL_ZERO"
726
+ ] = true;
727
+ }
728
+
729
+ const minCosHalfAngleSqr = Math.pow(
730
+ Math.cos(CesiumMath.PI_OVER_TWO - Math.abs(renderMinLatitude)),
731
+ 2.0
732
+ );
733
+ const maxCosHalfAngleSqr = Math.pow(
734
+ Math.cos(CesiumMath.PI_OVER_TWO - Math.abs(renderMaxLatitude)),
735
+ 2.0
736
+ );
737
+ shaderUniforms.ellipsoidRenderLatitudeCosSqrHalfMinMax = Cartesian2.fromElements(
738
+ minCosHalfAngleSqr,
739
+ maxCosHalfAngleSqr,
740
+ shaderUniforms.ellipsoidRenderLatitudeCosSqrHalfMinMax
741
+ );
742
+ }
743
+
744
+ if (shapeHasLatitude) {
745
+ shaderDefines["ELLIPSOID_HAS_SHAPE_BOUNDS_LATITUDE"] = true;
746
+
747
+ if (shapeMinLatitude === shapeMaxLatitude) {
748
+ shaderDefines[
749
+ "ELLIPSOID_HAS_SHAPE_BOUNDS_LATITUDE_RANGE_EQUAL_ZERO"
750
+ ] = true;
751
+ }
752
+
753
+ // delerp(latitudeUv, minLatitudeUv, maxLatitudeUv)
754
+ // (latitudeUv - minLatitudeUv) / (maxLatitudeUv - minLatitudeUv)
755
+ // latitudeUv / (maxLatitudeUv - minLatitudeUv) - minLatitudeUv / (maxLatitudeUv - minLatitudeUv)
756
+ // scale = 1.0 / (maxLatitudeUv - minLatitudeUv)
757
+ // scale = 1.0 / (((maxLatitude - pi) / (2.0 * pi)) - ((minLatitude - pi) / (2.0 * pi)))
758
+ // scale = 2.0 * pi / (maxLatitude - minLatitude)
759
+ // offset = -minLatitudeUv / (maxLatitudeUv - minLatitudeUv)
760
+ // offset = -((minLatitude - -pi) / (2.0 * pi)) / (((maxLatitude - pi) / (2.0 * pi)) - ((minLatitude - pi) / (2.0 * pi)))
761
+ // offset = -(minLatitude - -pi) / (maxLatitude - minLatitude)
762
+ // offset = (-pi - minLatitude) / (maxLatitude - minLatitude)
763
+ const scale = defaultLatitudeRange / shapeLatitudeRange;
764
+ const offset = (defaultMinLatitude - shapeMinLatitude) / shapeLatitudeRange;
765
+ shaderUniforms.ellipsoidUvToShapeUvLatitude = Cartesian2.fromElements(
766
+ scale,
767
+ offset,
768
+ shaderUniforms.ellipsoidUvToShapeUvLatitude
769
+ );
770
+ }
771
+
772
+ if (isSphere) {
773
+ shaderDefines["ELLIPSOID_IS_SPHERE"] = true;
774
+ }
775
+
776
+ this.shaderMaximumIntersectionsLength = intersectionCount;
777
+
778
+ return true;
779
+ };
780
+
781
+ const scratchRectangle = new Rectangle();
782
+
783
+ /**
784
+ * Computes an oriented bounding box for a specified tile.
785
+ * The update function must be called before calling this function.
786
+ *
787
+ * @param {Number} tileLevel The tile's level.
788
+ * @param {Number} tileX The tile's x coordinate.
789
+ * @param {Number} tileY The tile's y coordinate.
790
+ * @param {Number} tileZ The tile's z coordinate.
791
+ * @param {OrientedBoundingBox} result The oriented bounding box that will be set to enclose the specified tile
792
+ * @returns {OrientedBoundingBox} The oriented bounding box.
793
+ */
794
+ VoxelEllipsoidShape.prototype.computeOrientedBoundingBoxForTile = function (
795
+ tileLevel,
796
+ tileX,
797
+ tileY,
798
+ tileZ,
799
+ result
800
+ ) {
801
+ //>>includeStart('debug', pragmas.debug);
802
+ Check.typeOf.number("tileLevel", tileLevel);
803
+ Check.typeOf.number("tileX", tileX);
804
+ Check.typeOf.number("tileY", tileY);
805
+ Check.typeOf.number("tileZ", tileZ);
806
+ Check.typeOf.object("result", result);
807
+ //>>includeEnd('debug');
808
+
809
+ const sizeAtLevel = 1.0 / Math.pow(2.0, tileLevel);
810
+ const minLongitudeLerp = tileX * sizeAtLevel;
811
+ const maxLongitudeLerp = (tileX + 1) * sizeAtLevel;
812
+ const minLatitudeLerp = tileY * sizeAtLevel;
813
+ const maxLatitudeLerp = (tileY + 1) * sizeAtLevel;
814
+ const minHeightLerp = tileZ * sizeAtLevel;
815
+ const maxHeightLerp = (tileZ + 1) * sizeAtLevel;
816
+
817
+ const rectangle = Rectangle.subsection(
818
+ this._rectangle,
819
+ minLongitudeLerp,
820
+ minLatitudeLerp,
821
+ maxLongitudeLerp,
822
+ maxLatitudeLerp,
823
+ scratchRectangle
824
+ );
825
+
826
+ const minHeight = CesiumMath.lerp(
827
+ this._minimumHeight,
828
+ this._maximumHeight,
829
+ minHeightLerp
830
+ );
831
+
832
+ const maxHeight = CesiumMath.lerp(
833
+ this._minimumHeight,
834
+ this._maximumHeight,
835
+ maxHeightLerp
836
+ );
837
+
838
+ return getEllipsoidChunkObb(
839
+ rectangle,
840
+ minHeight,
841
+ maxHeight,
842
+ this._ellipsoid,
843
+ this._translation,
844
+ this._rotation,
845
+ result
846
+ );
847
+ };
848
+
849
+ /**
850
+ * Computes an approximate step size for raymarching the root tile of a voxel grid.
851
+ * The update function must be called before calling this function.
852
+ *
853
+ * @param {Cartesian3} dimensions The voxel grid dimensions for a tile.
854
+ * @returns {Number} The step size.
855
+ */
856
+ VoxelEllipsoidShape.prototype.computeApproximateStepSize = function (
857
+ dimensions
858
+ ) {
859
+ //>>includeStart('debug', pragmas.debug);
860
+ Check.typeOf.object("dimensions", dimensions);
861
+ //>>includeEnd('debug');
862
+
863
+ const ellipsoid = this._ellipsoid;
864
+ const ellipsoidMaximumRadius = ellipsoid.maximumRadius;
865
+ const minimumHeight = this._minimumHeight;
866
+ const maximumHeight = this._maximumHeight;
867
+
868
+ const shellToEllipsoidRatio =
869
+ (maximumHeight - minimumHeight) / (ellipsoidMaximumRadius + maximumHeight);
870
+ const stepSize = (0.5 * shellToEllipsoidRatio) / dimensions.z;
871
+ return stepSize;
872
+ };
873
+
874
+ /**
875
+ * Computes an {@link OrientedBoundingBox} for a subregion of the shape.
876
+ *
877
+ * @function
878
+ *
879
+ * @param {Rectangle} rectangle The rectangle.
880
+ * @param {Number} minHeight The minimumZ.
881
+ * @param {Number} maxHeight The maximumZ.
882
+ * @param {Ellipsoid} ellipsoid The ellipsoid.
883
+ * @param {Cartesian3} translation The translation applied to the shape
884
+ * @param {Matrix3} rotation The rotation applied to the shape
885
+ * @param {OrientedBoundingBox} result The object onto which to store the result.
886
+ * @returns {OrientedBoundingBox} The oriented bounding box that contains this subregion.
887
+ *
888
+ * @private
889
+ */
890
+ function getEllipsoidChunkObb(
891
+ rectangle,
892
+ minHeight,
893
+ maxHeight,
894
+ ellipsoid,
895
+ translation,
896
+ rotation,
897
+ result
898
+ ) {
899
+ result = OrientedBoundingBox.fromRectangle(
900
+ rectangle,
901
+ minHeight,
902
+ maxHeight,
903
+ ellipsoid,
904
+ result
905
+ );
906
+ result.center = Cartesian3.add(result.center, translation, result.center);
907
+ result.halfAxes = Matrix3.multiply(
908
+ result.halfAxes,
909
+ rotation,
910
+ result.halfAxes
911
+ );
912
+ return result;
913
+ }
914
+
915
+ /**
916
+ * Defines the minimum bounds of the shape. Corresponds to minimum longitude, latitude, height.
917
+ *
918
+ * @type {Cartesian3}
919
+ * @constant
920
+ * @readonly
921
+ */
922
+ VoxelEllipsoidShape.DefaultMinBounds = Object.freeze(
923
+ new Cartesian3(-CesiumMath.PI, -CesiumMath.PI_OVER_TWO, -Number.MAX_VALUE)
924
+ );
925
+
926
+ /**
927
+ * Defines the maximum bounds of the shape. Corresponds to maximum longitude, latitude, height.
928
+ *
929
+ * @type {Cartesian3}
930
+ * @constant
931
+ * @readonly
932
+ */
933
+ VoxelEllipsoidShape.DefaultMaxBounds = Object.freeze(
934
+ new Cartesian3(+CesiumMath.PI, +CesiumMath.PI_OVER_TWO, +Number.MAX_VALUE)
935
+ );
936
+
937
+ export default VoxelEllipsoidShape;