@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 defaultValue from "../Core/defaultValue.js";
2
+ import BoundingSphere from "../Core/BoundingSphere.js";
3
+ import Cartesian2 from "../Core/Cartesian2.js";
4
+ import Cartesian3 from "../Core/Cartesian3.js";
5
+ import Check from "../Core/Check.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 Cartesian4 from "../Core/Cartesian4.js";
11
+
12
+ /**
13
+ * A cylinder {@link VoxelShape}.
14
+ *
15
+ * @alias VoxelCylinderShape
16
+ * @constructor
17
+ *
18
+ * @see VoxelShape
19
+ * @see VoxelBoxShape
20
+ * @see VoxelEllipsoidShape
21
+ * @see VoxelShapeType
22
+ *
23
+ * @private
24
+ */
25
+ function VoxelCylinderShape() {
26
+ /**
27
+ * An oriented bounding box containing the bounded shape.
28
+ * The update function must be called before accessing this value.
29
+ * @type {OrientedBoundingBox}
30
+ * @readonly
31
+ */
32
+ this.orientedBoundingBox = new OrientedBoundingBox();
33
+
34
+ /**
35
+ * A bounding sphere containing the bounded shape.
36
+ * The update function must be called before accessing this value.
37
+ * @type {BoundingSphere}
38
+ * @readonly
39
+ */
40
+ this.boundingSphere = new BoundingSphere();
41
+
42
+ /**
43
+ * A transformation matrix containing the bounded shape.
44
+ * The update function must be called before accessing this value.
45
+ * @type {Matrix4}
46
+ * @readonly
47
+ */
48
+ this.boundTransform = new Matrix4();
49
+
50
+ /**
51
+ * A transformation matrix containing the shape, ignoring the bounds.
52
+ * The update function must be called before accessing this value.
53
+ * @type {Matrix4}
54
+ * @readonly
55
+ */
56
+ this.shapeTransform = new Matrix4();
57
+
58
+ /**
59
+ * @type {Number}
60
+ * @private
61
+ */
62
+ this._minimumRadius = VoxelCylinderShape.DefaultMinBounds.x;
63
+
64
+ /**
65
+ * @type {Number}
66
+ * @private
67
+ */
68
+ this._maximumRadius = VoxelCylinderShape.DefaultMaxBounds.x;
69
+
70
+ /**
71
+ * @type {Number}
72
+ * @private
73
+ */
74
+ this._minimumHeight = VoxelCylinderShape.DefaultMinBounds.y;
75
+
76
+ /**
77
+ * @type {Number}
78
+ * @private
79
+ */
80
+ this._maximumHeight = VoxelCylinderShape.DefaultMaxBounds.y;
81
+
82
+ /**
83
+ * @type {Number}
84
+ * @private
85
+ */
86
+ this._minimumAngle = VoxelCylinderShape.DefaultMinBounds.z;
87
+
88
+ /**
89
+ * @type {Number}
90
+ * @private
91
+ */
92
+ this._maximumAngle = VoxelCylinderShape.DefaultMaxBounds.z;
93
+
94
+ /**
95
+ * @type {Object.<string, any>}
96
+ * @readonly
97
+ */
98
+ this.shaderUniforms = {
99
+ cylinderUvToRenderBoundsScale: new Cartesian3(),
100
+ cylinderUvToRenderBoundsTranslate: new Cartesian3(),
101
+ cylinderUvToRenderRadiusMin: 0.0,
102
+ cylinderRenderAngleMinMax: new Cartesian2(),
103
+ cylinderUvToShapeUvRadius: new Cartesian2(),
104
+ cylinderUvToShapeUvHeight: new Cartesian2(),
105
+ cylinderUvToShapeUvAngle: new Cartesian2(),
106
+ cylinderShapeUvAngleMinMax: new Cartesian2(),
107
+ cylinderShapeUvAngleRangeZeroMid: 0.0,
108
+ };
109
+
110
+ /**
111
+ * @type {Object.<string, any>}
112
+ * @readonly
113
+ */
114
+ this.shaderDefines = {
115
+ CYLINDER_HAS_RENDER_BOUNDS_RADIUS_MIN: undefined,
116
+ CYLINDER_HAS_RENDER_BOUNDS_RADIUS_MAX: undefined,
117
+ CYLINDER_HAS_RENDER_BOUNDS_RADIUS_FLAT: undefined,
118
+ CYLINDER_HAS_RENDER_BOUNDS_HEIGHT: undefined,
119
+ CYLINDER_HAS_RENDER_BOUNDS_HEIGHT_FLAT: undefined,
120
+ CYLINDER_HAS_RENDER_BOUNDS_ANGLE: undefined,
121
+ CYLINDER_HAS_RENDER_BOUNDS_ANGLE_RANGE_EQUAL_ZERO: undefined,
122
+ CYLINDER_HAS_RENDER_BOUNDS_ANGLE_RANGE_UNDER_HALF: undefined,
123
+ CYLINDER_HAS_RENDER_BOUNDS_ANGLE_RANGE_EQUAL_HALF: undefined,
124
+ CYLINDER_HAS_RENDER_BOUNDS_ANGLE_RANGE_OVER_HALF: undefined,
125
+
126
+ CYLINDER_HAS_SHAPE_BOUNDS_RADIUS: undefined,
127
+ CYLINDER_HAS_SHAPE_BOUNDS_RADIUS_FLAT: undefined,
128
+ CYLINDER_HAS_SHAPE_BOUNDS_HEIGHT: undefined,
129
+ CYLINDER_HAS_SHAPE_BOUNDS_HEIGHT_FLAT: undefined,
130
+ CYLINDER_HAS_SHAPE_BOUNDS_ANGLE: undefined,
131
+ CYLINDER_HAS_SHAPE_BOUNDS_ANGLE_RANGE_EQUAL_ZERO: undefined,
132
+ CYLINDER_HAS_SHAPE_BOUNDS_ANGLE_MIN_DISCONTINUITY: undefined,
133
+ CYLINDER_HAS_SHAPE_BOUNDS_ANGLE_MAX_DISCONTINUITY: undefined,
134
+ CYLINDER_HAS_SHAPE_BOUNDS_ANGLE_MIN_MAX_REVERSED: undefined,
135
+
136
+ CYLINDER_INTERSECTION_INDEX_RADIUS_MAX: undefined,
137
+ CYLINDER_INTERSECTION_INDEX_RADIUS_MIN: undefined,
138
+ CYLINDER_INTERSECTION_INDEX_ANGLE: undefined,
139
+ };
140
+
141
+ /**
142
+ * The maximum number of intersections against the shape for any ray direction.
143
+ * @type {Number}
144
+ * @readonly
145
+ */
146
+ this.shaderMaximumIntersectionsLength = 0; // not known until update
147
+ }
148
+
149
+ const scratchScale = new Cartesian3();
150
+ const scratchBoundsTranslation = new Cartesian3();
151
+ const scratchBoundsScale = new Cartesian3();
152
+ const scratchBoundsScaleMatrix = new Matrix3();
153
+ const scratchTransformLocalToBounds = new Matrix4();
154
+ const scratchTransformUvToBounds = new Matrix4();
155
+
156
+ const transformUvToLocal = Matrix4.fromRotationTranslation(
157
+ Matrix3.fromUniformScale(2.0, new Matrix3()),
158
+ new Cartesian3(-1.0, -1.0, -1.0),
159
+ new Matrix4()
160
+ );
161
+
162
+ /**
163
+ * Update the shape's state.
164
+ *
165
+ * @param {Matrix4} modelMatrix The model matrix.
166
+ * @param {Cartesian3} minBounds The minimum bounds.
167
+ * @param {Cartesian3} maxBounds The maximum bounds.
168
+ * @param {Cartesian3} [clipMinBounds=VoxelCylinderShape.DefaultMinBounds] The minimum clip bounds.
169
+ * @param {Cartesian3} [clipMaxBounds=VoxelCylinderShape.DefaultMaxBounds] The maximum clip bounds.
170
+ * @returns {Boolean} Whether the shape is visible.
171
+ */
172
+ VoxelCylinderShape.prototype.update = function (
173
+ modelMatrix,
174
+ minBounds,
175
+ maxBounds,
176
+ clipMinBounds,
177
+ clipMaxBounds
178
+ ) {
179
+ clipMinBounds = defaultValue(
180
+ clipMinBounds,
181
+ VoxelCylinderShape.DefaultMinBounds
182
+ );
183
+ clipMaxBounds = defaultValue(
184
+ clipMaxBounds,
185
+ VoxelCylinderShape.DefaultMaxBounds
186
+ );
187
+ //>>includeStart('debug', pragmas.debug);
188
+ Check.typeOf.object("modelMatrix", modelMatrix);
189
+ Check.typeOf.object("minBounds", minBounds);
190
+ Check.typeOf.object("maxBounds", maxBounds);
191
+ //>>includeEnd('debug');
192
+
193
+ const defaultMinRadius = VoxelCylinderShape.DefaultMinBounds.x;
194
+ const defaultMaxRadius = VoxelCylinderShape.DefaultMaxBounds.x;
195
+ const defaultMinHeight = VoxelCylinderShape.DefaultMinBounds.y;
196
+ const defaultMaxHeight = VoxelCylinderShape.DefaultMaxBounds.y;
197
+ const defaultMinAngle = VoxelCylinderShape.DefaultMinBounds.z;
198
+ const defaultMaxAngle = VoxelCylinderShape.DefaultMaxBounds.z;
199
+ const defaultAngleRange = defaultMaxAngle - defaultMinAngle;
200
+ const defaultAngleRangeHalf = 0.5 * defaultAngleRange;
201
+
202
+ const epsilonZeroScale = CesiumMath.EPSILON10;
203
+ const epsilonAngleDiscontinuity = CesiumMath.EPSILON3; // 0.001 radians = 0.05729578 degrees
204
+ const epsilonAngle = CesiumMath.EPSILON10;
205
+
206
+ // Clamp the radii to the valid range
207
+ const shapeMinRadius = CesiumMath.clamp(
208
+ minBounds.x,
209
+ defaultMinRadius,
210
+ defaultMaxRadius
211
+ );
212
+ const shapeMaxRadius = CesiumMath.clamp(
213
+ maxBounds.x,
214
+ defaultMinRadius,
215
+ defaultMaxRadius
216
+ );
217
+ const clipMinRadius = CesiumMath.clamp(
218
+ clipMinBounds.x,
219
+ defaultMinRadius,
220
+ defaultMaxRadius
221
+ );
222
+ const clipMaxRadius = CesiumMath.clamp(
223
+ clipMaxBounds.x,
224
+ defaultMinRadius,
225
+ defaultMaxRadius
226
+ );
227
+ const renderMinRadius = Math.max(shapeMinRadius, clipMinRadius);
228
+ const renderMaxRadius = Math.min(shapeMaxRadius, clipMaxRadius);
229
+
230
+ // Clamp the heights to the valid range
231
+ const shapeMinHeight = CesiumMath.clamp(
232
+ minBounds.y,
233
+ defaultMinHeight,
234
+ defaultMaxHeight
235
+ );
236
+ const shapeMaxHeight = CesiumMath.clamp(
237
+ maxBounds.y,
238
+ defaultMinHeight,
239
+ defaultMaxHeight
240
+ );
241
+ const clipMinHeight = CesiumMath.clamp(
242
+ clipMinBounds.y,
243
+ defaultMinHeight,
244
+ defaultMaxHeight
245
+ );
246
+ const clipMaxHeight = CesiumMath.clamp(
247
+ clipMaxBounds.y,
248
+ defaultMinHeight,
249
+ defaultMaxHeight
250
+ );
251
+ const renderMinHeight = Math.max(shapeMinHeight, clipMinHeight);
252
+ const renderMaxHeight = Math.min(shapeMaxHeight, clipMaxHeight);
253
+
254
+ // Clamp the angles to the valid range
255
+ const shapeMinAngle = CesiumMath.negativePiToPi(minBounds.z);
256
+ const shapeMaxAngle = CesiumMath.negativePiToPi(maxBounds.z);
257
+ const clipMinAngle = CesiumMath.negativePiToPi(clipMinBounds.z);
258
+ const clipMaxAngle = CesiumMath.negativePiToPi(clipMaxBounds.z);
259
+ const renderMinAngle = Math.max(shapeMinAngle, clipMinAngle);
260
+ const renderMaxAngle = Math.min(shapeMaxAngle, clipMaxAngle);
261
+
262
+ const scale = Matrix4.getScale(modelMatrix, scratchScale);
263
+
264
+ // Exit early if the shape is not visible.
265
+ // Note that minAngle may be greater than maxAngle when crossing the 180th meridian.
266
+
267
+ // Cylinder is not visible if:
268
+ // - maxRadius is zero (line)
269
+ // - minRadius is greater than maxRadius
270
+ // - minHeight is greater than maxHeight
271
+ // - scale is 0 for any component (too annoying to reconstruct rotation matrix)
272
+ if (
273
+ renderMaxRadius === 0.0 ||
274
+ renderMinRadius > renderMaxRadius ||
275
+ renderMinHeight > renderMaxHeight ||
276
+ CesiumMath.equalsEpsilon(scale.x, 0.0, undefined, epsilonZeroScale) ||
277
+ CesiumMath.equalsEpsilon(scale.y, 0.0, undefined, epsilonZeroScale) ||
278
+ CesiumMath.equalsEpsilon(scale.z, 0.0, undefined, epsilonZeroScale)
279
+ ) {
280
+ return false;
281
+ }
282
+
283
+ this._minimumRadius = shapeMinRadius; // [0,1]
284
+ this._maximumRadius = shapeMaxRadius; // [0,1]
285
+ this._minimumHeight = shapeMinHeight; // [-1,+1]
286
+ this._maximumHeight = shapeMaxHeight; // [-1,+1]
287
+ this._minimumAngle = shapeMinAngle; // [-pi,+pi]
288
+ this._maximumAngle = shapeMaxAngle; // [-pi,+pi]
289
+
290
+ this.shapeTransform = Matrix4.clone(modelMatrix, this.shapeTransform);
291
+
292
+ this.orientedBoundingBox = getCylinderChunkObb(
293
+ renderMinRadius,
294
+ renderMaxRadius,
295
+ renderMinHeight,
296
+ renderMaxHeight,
297
+ renderMinAngle,
298
+ renderMaxAngle,
299
+ this.shapeTransform,
300
+ this.orientedBoundingBox
301
+ );
302
+
303
+ this.boundTransform = Matrix4.fromRotationTranslation(
304
+ this.orientedBoundingBox.halfAxes,
305
+ this.orientedBoundingBox.center,
306
+ this.boundTransform
307
+ );
308
+
309
+ this.boundingSphere = BoundingSphere.fromOrientedBoundingBox(
310
+ this.orientedBoundingBox,
311
+ this.boundingSphere
312
+ );
313
+
314
+ const shapeIsDefaultMaxRadius = shapeMaxRadius === defaultMaxRadius;
315
+ const shapeIsDefaultMinRadius = shapeMinRadius === defaultMinRadius;
316
+ const shapeIsDefaultRadius =
317
+ shapeIsDefaultMinRadius && shapeIsDefaultMaxRadius;
318
+ const shapeIsDefaultHeight =
319
+ shapeMinHeight === defaultMinHeight && shapeMaxHeight === defaultMaxHeight;
320
+ const shapeIsAngleReversed = shapeMaxAngle < shapeMinAngle;
321
+ const shapeAngleRange =
322
+ shapeMaxAngle - shapeMinAngle + shapeIsAngleReversed * defaultAngleRange;
323
+ const shapeIsAngleRegular =
324
+ shapeAngleRange > defaultAngleRangeHalf + epsilonAngle &&
325
+ shapeAngleRange < defaultAngleRange - epsilonAngle;
326
+ const shapeIsAngleFlipped =
327
+ shapeAngleRange > epsilonAngle &&
328
+ shapeAngleRange < defaultAngleRangeHalf - epsilonAngle;
329
+ const shapeIsAngleRangeHalf =
330
+ shapeAngleRange >= defaultAngleRangeHalf - epsilonAngle &&
331
+ shapeAngleRange <= defaultAngleRangeHalf + epsilonAngle;
332
+ const shapeIsAngleRangeZero = shapeAngleRange <= epsilonAngle;
333
+ const shapeHasAngle =
334
+ shapeIsAngleRegular ||
335
+ shapeIsAngleFlipped ||
336
+ shapeIsAngleRangeHalf ||
337
+ shapeIsAngleRangeZero;
338
+ const shapeIsMinAngleDiscontinuity = CesiumMath.equalsEpsilon(
339
+ shapeMinAngle,
340
+ defaultMinAngle,
341
+ undefined,
342
+ epsilonAngleDiscontinuity
343
+ );
344
+ const shapeIsMaxAngleDiscontinuity = CesiumMath.equalsEpsilon(
345
+ shapeMaxAngle,
346
+ defaultMaxAngle,
347
+ undefined,
348
+ epsilonAngleDiscontinuity
349
+ );
350
+
351
+ const renderIsDefaultMaxRadius = renderMaxRadius === defaultMaxRadius;
352
+ const renderIsDefaultMinRadius = renderMinRadius === defaultMinRadius;
353
+ const renderIsDefaultHeight =
354
+ renderMinHeight === defaultMinHeight &&
355
+ renderMaxHeight === defaultMaxHeight;
356
+ const renderIsAngleReversed = renderMaxAngle < renderMinAngle;
357
+ const renderAngleRange =
358
+ renderMaxAngle - renderMinAngle + renderIsAngleReversed * defaultAngleRange;
359
+ const renderIsAngleRegular =
360
+ renderAngleRange > defaultAngleRangeHalf + epsilonAngle &&
361
+ renderAngleRange < defaultAngleRange - epsilonAngle;
362
+ const renderIsAngleFlipped =
363
+ renderAngleRange > epsilonAngle &&
364
+ renderAngleRange < defaultAngleRangeHalf - epsilonAngle;
365
+ const renderIsAngleRangeHalf =
366
+ renderAngleRange >= defaultAngleRangeHalf - epsilonAngle &&
367
+ renderAngleRange <= defaultAngleRangeHalf + epsilonAngle;
368
+ const renderIsAngleRangeZero = renderAngleRange <= epsilonAngle;
369
+ const renderHasAngle =
370
+ renderIsAngleRegular ||
371
+ renderIsAngleFlipped ||
372
+ renderIsAngleRangeHalf ||
373
+ renderIsAngleRangeZero;
374
+
375
+ const shaderUniforms = this.shaderUniforms;
376
+ const shaderDefines = this.shaderDefines;
377
+
378
+ // To keep things simple, clear the defines every time
379
+ for (const key in shaderDefines) {
380
+ if (shaderDefines.hasOwnProperty(key)) {
381
+ shaderDefines[key] = undefined;
382
+ }
383
+ }
384
+
385
+ // Keep track of how many intersections there are going to be.
386
+ let intersectionCount = 0;
387
+
388
+ shaderDefines["CYLINDER_INTERSECTION_INDEX_RADIUS_MAX"] = intersectionCount;
389
+ intersectionCount += 1;
390
+
391
+ if (!renderIsDefaultMinRadius) {
392
+ shaderDefines["CYLINDER_HAS_RENDER_BOUNDS_RADIUS_MIN"] = true;
393
+ shaderDefines["CYLINDER_INTERSECTION_INDEX_RADIUS_MIN"] = intersectionCount;
394
+ intersectionCount += 1;
395
+
396
+ shaderUniforms.cylinderUvToRenderRadiusMin =
397
+ renderMaxRadius / renderMinRadius;
398
+ }
399
+ if (!renderIsDefaultMaxRadius) {
400
+ shaderDefines["CYLINDER_HAS_RENDER_BOUNDS_RADIUS_MAX"] = true;
401
+ }
402
+ if (renderMinRadius === renderMaxRadius) {
403
+ shaderDefines["CYLINDER_HAS_RENDER_BOUNDS_RADIUS_FLAT"] = true;
404
+ }
405
+ if (!renderIsDefaultHeight) {
406
+ shaderDefines["CYLINDER_HAS_RENDER_BOUNDS_HEIGHT"] = true;
407
+ }
408
+ if (renderMinHeight === renderMaxHeight) {
409
+ shaderDefines["CYLINDER_HAS_RENDER_BOUNDS_HEIGHT_FLAT"] = true;
410
+ }
411
+ if (shapeMinHeight === shapeMaxHeight) {
412
+ shaderDefines["CYLINDER_HAS_SHAPE_BOUNDS_HEIGHT_FLAT"] = true;
413
+ }
414
+ if (shapeMinRadius === shapeMaxRadius) {
415
+ shaderDefines["CYLINDER_HAS_SHAPE_BOUNDS_RADIUS_FLAT"] = true;
416
+ }
417
+ if (!shapeIsDefaultRadius) {
418
+ shaderDefines["CYLINDER_HAS_SHAPE_BOUNDS_RADIUS"] = true;
419
+
420
+ // delerp(radius, minRadius, maxRadius)
421
+ // (radius - minRadius) / (maxRadius - minRadius)
422
+ // radius / (maxRadius - minRadius) - minRadius / (maxRadius - minRadius)
423
+ // scale = 1.0 / (maxRadius - minRadius)
424
+ // offset = -minRadius / (maxRadius - minRadius)
425
+ // offset = minRadius / (minRadius - maxRadius)
426
+ const scale = 1.0 / (shapeMaxRadius - shapeMinRadius);
427
+ const offset = shapeMinRadius / (shapeMinRadius - shapeMaxRadius);
428
+ shaderUniforms.cylinderUvToShapeUvRadius = Cartesian2.fromElements(
429
+ scale,
430
+ offset,
431
+ shaderUniforms.cylinderUvToShapeUvRadius
432
+ );
433
+ }
434
+
435
+ if (!shapeIsDefaultHeight) {
436
+ shaderDefines["CYLINDER_HAS_SHAPE_BOUNDS_HEIGHT"] = true;
437
+
438
+ // delerp(heightUv, minHeightUv, maxHeightUv)
439
+ // (heightUv - minHeightUv) / (maxHeightUv - minHeightUv)
440
+ // heightUv / (maxHeightUv - minHeightUv) - minHeightUv / (maxHeightUv - minHeightUv)
441
+ // scale = 1.0 / (maxHeightUv - minHeightUv)
442
+ // scale = 1.0 / ((maxHeight * 0.5 + 0.5) - (minHeight * 0.5 + 0.5))
443
+ // scale = 2.0 / (maxHeight - minHeight)
444
+ // offset = -minHeightUv / (maxHeightUv - minHeightUv)
445
+ // offset = -minHeightUv / ((maxHeight * 0.5 + 0.5) - (minHeight * 0.5 + 0.5))
446
+ // offset = -2.0 * (minHeight * 0.5 + 0.5) / (maxHeight - minHeight)
447
+ // offset = -(minHeight + 1.0) / (maxHeight - minHeight)
448
+ // offset = (minHeight + 1.0) / (minHeight - maxHeight)
449
+ const scale = 2.0 / (shapeMaxHeight - shapeMinHeight);
450
+ const offset = (shapeMinHeight + 1.0) / (shapeMinHeight - shapeMaxHeight);
451
+ shaderUniforms.cylinderUvToShapeUvHeight = Cartesian2.fromElements(
452
+ scale,
453
+ offset,
454
+ shaderUniforms.cylinderUvToShapeUvHeight
455
+ );
456
+ }
457
+
458
+ if (!renderIsDefaultMaxRadius || !renderIsDefaultHeight) {
459
+ const heightScale = 0.5 * (renderMaxHeight - renderMinHeight);
460
+ const scaleLocalToBounds = Cartesian3.fromElements(
461
+ 1.0 / renderMaxRadius,
462
+ 1.0 / renderMaxRadius,
463
+ 1.0 / (heightScale === 0.0 ? 1.0 : heightScale),
464
+ scratchBoundsScale
465
+ );
466
+ // -inverse(scale) * translation // affine inverse
467
+ // -inverse(scale) * 0.5 * (minHeight + maxHeight)
468
+ const translateLocalToBounds = Cartesian3.fromElements(
469
+ 0.0,
470
+ 0.0,
471
+ -scaleLocalToBounds.z * 0.5 * (renderMinHeight + renderMaxHeight),
472
+ scratchBoundsTranslation
473
+ );
474
+ const transformLocalToBounds = Matrix4.fromRotationTranslation(
475
+ Matrix3.fromScale(scaleLocalToBounds, scratchBoundsScaleMatrix),
476
+ translateLocalToBounds,
477
+ scratchTransformLocalToBounds
478
+ );
479
+ const transformUvToBounds = Matrix4.multiplyTransformation(
480
+ transformLocalToBounds,
481
+ transformUvToLocal,
482
+ scratchTransformUvToBounds
483
+ );
484
+ shaderUniforms.cylinderUvToRenderBoundsScale = Matrix4.getScale(
485
+ transformUvToBounds,
486
+ shaderUniforms.cylinderUvToRenderBoundsScale
487
+ );
488
+ shaderUniforms.cylinderUvToRenderBoundsTranslate = Matrix4.getTranslation(
489
+ transformUvToBounds,
490
+ shaderUniforms.cylinderUvToRenderBoundsTranslate
491
+ );
492
+ }
493
+
494
+ if (shapeIsAngleReversed) {
495
+ shaderDefines["CYLINDER_HAS_SHAPE_BOUNDS_ANGLE_MIN_MAX_REVERSED"] = true;
496
+ }
497
+
498
+ if (renderHasAngle) {
499
+ shaderDefines["CYLINDER_HAS_RENDER_BOUNDS_ANGLE"] = true;
500
+ shaderDefines["CYLINDER_INTERSECTION_INDEX_ANGLE"] = intersectionCount;
501
+
502
+ if (renderIsAngleRegular) {
503
+ shaderDefines["CYLINDER_HAS_RENDER_BOUNDS_ANGLE_RANGE_UNDER_HALF"] = true;
504
+ intersectionCount += 1;
505
+ } else if (renderIsAngleFlipped) {
506
+ shaderDefines["CYLINDER_HAS_RENDER_BOUNDS_ANGLE_RANGE_OVER_HALF"] = true;
507
+ intersectionCount += 2;
508
+ } else if (renderIsAngleRangeHalf) {
509
+ shaderDefines["CYLINDER_HAS_RENDER_BOUNDS_ANGLE_RANGE_EQUAL_HALF"] = true;
510
+ intersectionCount += 1;
511
+ } else if (renderIsAngleRangeZero) {
512
+ shaderDefines["CYLINDER_HAS_RENDER_BOUNDS_ANGLE_RANGE_EQUAL_ZERO"] = true;
513
+ intersectionCount += 2;
514
+ }
515
+
516
+ shaderUniforms.cylinderRenderAngleMinMax = Cartesian2.fromElements(
517
+ renderMinAngle,
518
+ renderMaxAngle,
519
+ shaderUniforms.cylinderAngleMinMax
520
+ );
521
+ }
522
+
523
+ if (shapeHasAngle) {
524
+ shaderDefines["CYLINDER_HAS_SHAPE_BOUNDS_ANGLE"] = true;
525
+ if (shapeIsAngleRangeZero) {
526
+ shaderDefines["CYLINDER_HAS_SHAPE_BOUNDS_ANGLE_RANGE_EQUAL_ZERO"] = true;
527
+ }
528
+ if (shapeIsMinAngleDiscontinuity) {
529
+ shaderDefines["CYLINDER_HAS_SHAPE_BOUNDS_ANGLE_MIN_DISCONTINUITY"] = true;
530
+ }
531
+ if (shapeIsMaxAngleDiscontinuity) {
532
+ shaderDefines["CYLINDER_HAS_SHAPE_BOUNDS_ANGLE_MAX_DISCONTINUITY"] = true;
533
+ }
534
+
535
+ const uvMinAngle = (shapeMinAngle - defaultMinAngle) / defaultAngleRange;
536
+ const uvMaxAngle = (shapeMaxAngle - defaultMinAngle) / defaultAngleRange;
537
+ const uvAngleRangeZero = 1.0 - shapeAngleRange / defaultAngleRange;
538
+
539
+ shaderUniforms.cylinderShapeUvAngleMinMax = Cartesian2.fromElements(
540
+ uvMinAngle,
541
+ uvMaxAngle,
542
+ shaderUniforms.cylinderShapeUvAngleMinMax
543
+ );
544
+ shaderUniforms.cylinderShapeUvAngleRangeZeroMid =
545
+ (uvMaxAngle + 0.5 * uvAngleRangeZero) % 1.0;
546
+
547
+ // delerp(angleUv, uvMinAngle, uvMaxAngle)
548
+ // (angelUv - uvMinAngle) / (uvMaxAngle - uvMinAngle)
549
+ // angleUv / (uvMaxAngle - uvMinAngle) - uvMinAngle / (uvMaxAngle - uvMinAngle)
550
+ // scale = 1.0 / (uvMaxAngle - uvMinAngle)
551
+ // scale = 1.0 / (((maxAngle - pi) / (2.0 * pi)) - ((minAngle - pi) / (2.0 * pi)))
552
+ // scale = 2.0 * pi / (maxAngle - minAngle)
553
+ // offset = -uvMinAngle / (uvMaxAngle - uvMinAngle)
554
+ // offset = -((minAngle - pi) / (2.0 * pi)) / (((maxAngle - pi) / (2.0 * pi)) - ((minAngle - pi) / (2.0 * pi)))
555
+ // offset = -(minAngle - pi) / (maxAngle - minAngle)
556
+ const scale = defaultAngleRange / shapeAngleRange;
557
+ const offset = -(shapeMinAngle - defaultMinAngle) / shapeAngleRange;
558
+ shaderUniforms.cylinderUvToShapeUvAngle = Cartesian2.fromElements(
559
+ scale,
560
+ offset,
561
+ shaderUniforms.cylinderUvToShapeUvAngle
562
+ );
563
+ }
564
+
565
+ this.shaderMaximumIntersectionsLength = intersectionCount;
566
+
567
+ return true;
568
+ };
569
+
570
+ /**
571
+ * Computes an oriented bounding box for a specified tile.
572
+ * The update function must be called before calling this function.
573
+ *
574
+ * @param {Number} tileLevel The tile's level.
575
+ * @param {Number} tileX The tile's x coordinate.
576
+ * @param {Number} tileY The tile's y coordinate.
577
+ * @param {Number} tileZ The tile's z coordinate.
578
+ * @param {OrientedBoundingBox} result The oriented bounding box that will be set to enclose the specified tile
579
+ * @returns {OrientedBoundingBox} The oriented bounding box.
580
+ */
581
+ VoxelCylinderShape.prototype.computeOrientedBoundingBoxForTile = function (
582
+ tileLevel,
583
+ tileX,
584
+ tileY,
585
+ tileZ,
586
+ result
587
+ ) {
588
+ //>>includeStart('debug', pragmas.debug);
589
+ Check.typeOf.number("tileLevel", tileLevel);
590
+ Check.typeOf.number("tileX", tileX);
591
+ Check.typeOf.number("tileY", tileY);
592
+ Check.typeOf.number("tileZ", tileZ);
593
+ Check.typeOf.object("result", result);
594
+ //>>includeEnd('debug');
595
+
596
+ const minimumRadius = this._minimumRadius;
597
+ const maximumRadius = this._maximumRadius;
598
+ const minimumHeight = this._minimumHeight;
599
+ const maximumHeight = this._maximumHeight;
600
+ const minimumAngle = this._minimumAngle;
601
+ const maximumAngle = this._maximumAngle;
602
+
603
+ const sizeAtLevel = 1.0 / Math.pow(2.0, tileLevel);
604
+
605
+ const radiusStart = CesiumMath.lerp(
606
+ minimumRadius,
607
+ maximumRadius,
608
+ tileX * sizeAtLevel
609
+ );
610
+ const radiusEnd = CesiumMath.lerp(
611
+ minimumRadius,
612
+ maximumRadius,
613
+ (tileX + 1) * sizeAtLevel
614
+ );
615
+ const heightStart = CesiumMath.lerp(
616
+ minimumHeight,
617
+ maximumHeight,
618
+ tileY * sizeAtLevel
619
+ );
620
+ const heightEnd = CesiumMath.lerp(
621
+ minimumHeight,
622
+ maximumHeight,
623
+ (tileY + 1) * sizeAtLevel
624
+ );
625
+ const angleStart = CesiumMath.lerp(
626
+ minimumAngle,
627
+ maximumAngle,
628
+ tileZ * sizeAtLevel
629
+ );
630
+ const angleEnd = CesiumMath.lerp(
631
+ minimumAngle,
632
+ maximumAngle,
633
+ (tileZ + 1) * sizeAtLevel
634
+ );
635
+
636
+ return getCylinderChunkObb(
637
+ radiusStart,
638
+ radiusEnd,
639
+ heightStart,
640
+ heightEnd,
641
+ angleStart,
642
+ angleEnd,
643
+ this.shapeTransform,
644
+ result
645
+ );
646
+ };
647
+
648
+ const scratchOrientedBoundingBox = new OrientedBoundingBox();
649
+ const scratchVoxelScale = new Cartesian3();
650
+ const scratchRootScale = new Cartesian3();
651
+ const scratchScaleRatio = new Cartesian3();
652
+
653
+ /**
654
+ * Computes an approximate step size for raymarching the root tile of a voxel grid.
655
+ * The update function must be called before calling this function.
656
+ *
657
+ * @param {Cartesian3} dimensions The voxel grid dimensions for a tile.
658
+ * @returns {Number} The step size.
659
+ */
660
+ VoxelCylinderShape.prototype.computeApproximateStepSize = function (
661
+ dimensions
662
+ ) {
663
+ //>>includeStart('debug', pragmas.debug);
664
+ Check.typeOf.object("dimensions", dimensions);
665
+ //>>includeEnd('debug');
666
+
667
+ const shapeTransform = this.shapeTransform;
668
+ const minRadius = this._minimumRadius;
669
+ const maxRadius = this._maximumRadius;
670
+ const minHeight = this._minimumHeight;
671
+ const maxHeight = this._maximumHeight;
672
+ const minAngle = this._minimumAngle;
673
+ const maxAngle = this._maximumAngle;
674
+
675
+ const lerpRadius = 1.0 - 1.0 / dimensions.x;
676
+ const lerpHeight = 1.0 - 1.0 / dimensions.y;
677
+ const lerpAngle = 1.0 - 1.0 / dimensions.z;
678
+
679
+ // Compare the size of an outermost cylinder voxel to the total cylinder
680
+ const voxelMinimumRadius = CesiumMath.lerp(minRadius, maxRadius, lerpRadius);
681
+ const voxelMinimumHeight = CesiumMath.lerp(minHeight, maxHeight, lerpHeight);
682
+ const voxelMinimumAngle = CesiumMath.lerp(minAngle, maxAngle, lerpAngle);
683
+ const voxelMaximumRadius = maxRadius;
684
+ const voxelMaximumHeight = maxHeight;
685
+ const voxelMaximumAngle = maxAngle;
686
+
687
+ const voxelObb = getCylinderChunkObb(
688
+ voxelMinimumRadius,
689
+ voxelMaximumRadius,
690
+ voxelMinimumHeight,
691
+ voxelMaximumHeight,
692
+ voxelMinimumAngle,
693
+ voxelMaximumAngle,
694
+ shapeTransform,
695
+ scratchOrientedBoundingBox
696
+ );
697
+
698
+ const voxelScale = Matrix3.getScale(voxelObb.halfAxes, scratchVoxelScale);
699
+ const rootScale = Matrix4.getScale(shapeTransform, scratchRootScale);
700
+ const scaleRatio = Cartesian3.divideComponents(
701
+ voxelScale,
702
+ rootScale,
703
+ scratchScaleRatio
704
+ );
705
+ const stepSize = Cartesian3.minimumComponent(scaleRatio);
706
+ return stepSize;
707
+ };
708
+
709
+ /**
710
+ * Defines the minimum bounds of the shape. Corresponds to minimum radius, height, angle.
711
+ *
712
+ * @type {Cartesian3}
713
+ * @constant
714
+ * @readonly
715
+ *
716
+ * @private
717
+ */
718
+ VoxelCylinderShape.DefaultMinBounds = Object.freeze(
719
+ new Cartesian3(0.0, -1.0, -CesiumMath.PI)
720
+ );
721
+
722
+ /**
723
+ * Defines the maximum bounds of the shape. Corresponds to maximum radius, height, angle.
724
+ *
725
+ * @type {Cartesian3}
726
+ * @constant
727
+ * @readonly
728
+ *
729
+ * @private
730
+ */
731
+ VoxelCylinderShape.DefaultMaxBounds = Object.freeze(
732
+ new Cartesian3(1.0, +1.0, +CesiumMath.PI)
733
+ );
734
+
735
+ const maxTestAngles = 5;
736
+ const scratchTestAngles = new Array(maxTestAngles);
737
+ const scratchTranslation = new Cartesian3();
738
+ const scratchRotation = new Matrix3();
739
+ const scratchTranslationMatrix = new Matrix4();
740
+ const scratchRotationMatrix = new Matrix4();
741
+ const scratchScaleMatrix = new Matrix4();
742
+ const scratchMatrix = new Matrix4();
743
+ const scratchColumn0 = new Cartesian3();
744
+ const scratchColumn1 = new Cartesian3();
745
+ const scratchColumn2 = new Cartesian3();
746
+ const scratchCorners = new Array(8);
747
+ for (let i = 0; i < 8; i++) {
748
+ scratchCorners[i] = new Cartesian3();
749
+ }
750
+
751
+ function orthogonal(a, b, epsilon) {
752
+ return Math.abs(Cartesian4.dot(a, b)) < epsilon;
753
+ }
754
+
755
+ function isValidOrientedBoundingBoxTransformation(matrix) {
756
+ const column0 = Matrix4.getColumn(matrix, 0, scratchColumn0);
757
+ const column1 = Matrix4.getColumn(matrix, 1, scratchColumn1);
758
+ const column2 = Matrix4.getColumn(matrix, 2, scratchColumn2);
759
+
760
+ const epsilon = CesiumMath.EPSILON4;
761
+
762
+ return (
763
+ orthogonal(column0, column1, epsilon) &&
764
+ orthogonal(column1, column2, epsilon)
765
+ );
766
+ }
767
+
768
+ function computeLooseOrientedBoundingBox(matrix, result) {
769
+ const corners = scratchCorners;
770
+ Cartesian3.fromElements(-0.5, -0.5, -0.5, corners[0]);
771
+ Cartesian3.fromElements(-0.5, -0.5, 0.5, corners[1]);
772
+ Cartesian3.fromElements(-0.5, 0.5, -0.5, corners[2]);
773
+ Cartesian3.fromElements(-0.5, 0.5, 0.5, corners[3]);
774
+ Cartesian3.fromElements(0.5, -0.5, -0.5, corners[4]);
775
+ Cartesian3.fromElements(0.5, -0.5, 0.5, corners[5]);
776
+ Cartesian3.fromElements(0.5, 0.5, -0.5, corners[6]);
777
+ Cartesian3.fromElements(0.5, 0.5, 0.5, corners[7]);
778
+
779
+ for (let i = 0; i < 8; ++i) {
780
+ Matrix4.multiplyByPoint(matrix, corners[i], corners[i]);
781
+ }
782
+
783
+ return OrientedBoundingBox.fromPoints(corners, result);
784
+ }
785
+
786
+ /**
787
+ * Computes an {@link OrientedBoundingBox} for a subregion of the shape.
788
+ *
789
+ * @function
790
+ *
791
+ * @param {Number} radiusStart The radiusStart.
792
+ * @param {Number} radiusEnd The radiusEnd.
793
+ * @param {Number} heightStart The heightStart.
794
+ * @param {Number} heightEnd The heightEnd.
795
+ * @param {Number} angleStart The angleStart.
796
+ * @param {Number} angleEnd The angleEnd.
797
+ * @param {Matrix4} matrix The matrix to transform the points.
798
+ * @param {OrientedBoundingBox} result The object onto which to store the result.
799
+ * @returns {OrientedBoundingBox} The oriented bounding box that contains this subregion.
800
+ *
801
+ * @private
802
+ */
803
+ function getCylinderChunkObb(
804
+ radiusStart,
805
+ radiusEnd,
806
+ heightStart,
807
+ heightEnd,
808
+ angleStart,
809
+ angleEnd,
810
+ matrix,
811
+ result
812
+ ) {
813
+ const defaultMinBounds = VoxelCylinderShape.DefaultMinBounds;
814
+ const defaultMaxBounds = VoxelCylinderShape.DefaultMaxBounds;
815
+ const defaultMinRadius = defaultMinBounds.x; // 0
816
+ const defaultMaxRadius = defaultMaxBounds.x; // 1
817
+ const defaultMinHeight = defaultMinBounds.y; // -1
818
+ const defaultMaxHeight = defaultMaxBounds.y; // +1
819
+ const defaultMinAngle = defaultMinBounds.z; // -pi
820
+ const defaultMaxAngle = defaultMaxBounds.z; // +pi
821
+
822
+ // Return early if using the default bounds
823
+ if (
824
+ radiusStart === defaultMinRadius &&
825
+ radiusEnd === defaultMaxRadius &&
826
+ heightStart === defaultMinHeight &&
827
+ heightEnd === defaultMaxHeight &&
828
+ angleStart === defaultMinAngle &&
829
+ angleEnd === defaultMaxAngle
830
+ ) {
831
+ result.center = Matrix4.getTranslation(matrix, result.center);
832
+ result.halfAxes = Matrix4.getMatrix3(matrix, result.halfAxes);
833
+ return result;
834
+ }
835
+
836
+ const isAngleReversed = angleEnd < angleStart;
837
+
838
+ if (isAngleReversed) {
839
+ angleEnd += CesiumMath.TWO_PI;
840
+ }
841
+
842
+ const angleRange = angleEnd - angleStart;
843
+ const angleMid = angleStart + angleRange * 0.5;
844
+
845
+ const testAngles = scratchTestAngles;
846
+ let testAngleCount = 0;
847
+
848
+ testAngles[testAngleCount++] = angleStart;
849
+ testAngles[testAngleCount++] = angleEnd;
850
+ testAngles[testAngleCount++] = angleMid;
851
+
852
+ if (angleRange > CesiumMath.PI) {
853
+ testAngles[testAngleCount++] = angleMid - CesiumMath.PI_OVER_TWO;
854
+ testAngles[testAngleCount++] = angleMid + CesiumMath.PI_OVER_TWO;
855
+ }
856
+
857
+ // Find bounding box in shape space relative to angleMid
858
+ let minX = 1.0;
859
+ let minY = 1.0;
860
+ let maxX = -1.0;
861
+ let maxY = -1.0;
862
+
863
+ for (let i = 0; i < testAngleCount; ++i) {
864
+ const angle = testAngles[i] - angleMid;
865
+ const cosAngle = Math.cos(angle);
866
+ const sinAngle = Math.sin(angle);
867
+ const x1 = cosAngle * radiusStart;
868
+ const y1 = sinAngle * radiusStart;
869
+ const x2 = cosAngle * radiusEnd;
870
+ const y2 = sinAngle * radiusEnd;
871
+
872
+ minX = Math.min(minX, x1);
873
+ minY = Math.min(minY, y1);
874
+ minX = Math.min(minX, x2);
875
+ minY = Math.min(minY, y2);
876
+ maxX = Math.max(maxX, x1);
877
+ maxY = Math.max(maxY, y1);
878
+ maxX = Math.max(maxX, x2);
879
+ maxY = Math.max(maxY, y2);
880
+ }
881
+
882
+ const extentX = maxX - minX;
883
+ const extentY = maxY - minY;
884
+ const extentZ = heightEnd - heightStart;
885
+
886
+ const centerX = (minX + maxX) * 0.5;
887
+ const centerY = (minY + maxY) * 0.5;
888
+ const centerZ = (heightStart + heightEnd) * 0.5;
889
+
890
+ const translation = Cartesian3.fromElements(
891
+ centerX,
892
+ centerY,
893
+ centerZ,
894
+ scratchTranslation
895
+ );
896
+
897
+ const rotation = Matrix3.fromRotationZ(angleMid, scratchRotation);
898
+
899
+ const scale = Cartesian3.fromElements(
900
+ extentX,
901
+ extentY,
902
+ extentZ,
903
+ scratchScale
904
+ );
905
+
906
+ const scaleMatrix = Matrix4.fromScale(scale, scratchScaleMatrix);
907
+ const rotationMatrix = Matrix4.fromRotation(rotation, scratchRotationMatrix);
908
+ const translationMatrix = Matrix4.fromTranslation(
909
+ translation,
910
+ scratchTranslationMatrix
911
+ );
912
+
913
+ // Shape space matrix = R * T * S
914
+ const localMatrix = Matrix4.multiplyTransformation(
915
+ rotationMatrix,
916
+ Matrix4.multiplyTransformation(
917
+ translationMatrix,
918
+ scaleMatrix,
919
+ scratchMatrix
920
+ ),
921
+ scratchMatrix
922
+ );
923
+
924
+ const globalMatrix = Matrix4.multiplyTransformation(
925
+ matrix,
926
+ localMatrix,
927
+ scratchMatrix
928
+ );
929
+
930
+ if (!isValidOrientedBoundingBoxTransformation(globalMatrix)) {
931
+ return computeLooseOrientedBoundingBox(globalMatrix, result);
932
+ }
933
+
934
+ return OrientedBoundingBox.fromTransformation(globalMatrix, result);
935
+ }
936
+
937
+ export default VoxelCylinderShape;