@cesium/engine 0.1.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/Build/Workers/{AttributeCompression-4589338a.js → AttributeCompression-b646d393.js} +1 -1
  2. package/Build/Workers/{AxisAlignedBoundingBox-bfb1234f.js → AxisAlignedBoundingBox-a4321399.js} +1 -1
  3. package/Build/Workers/{BoundingRectangle-7ffc2153.js → BoundingRectangle-80d8801f.js} +1 -1
  4. package/Build/Workers/{BoxGeometry-93f344a3.js → BoxGeometry-33c10a4f.js} +1 -1
  5. package/Build/Workers/{Color-0c5aaf47.js → Color-1bf9a6e0.js} +1 -1
  6. package/Build/Workers/{CoplanarPolygonGeometryLibrary-6597982a.js → CoplanarPolygonGeometryLibrary-5c5b981b.js} +1 -1
  7. package/Build/Workers/{CorridorGeometryLibrary-2119580e.js → CorridorGeometryLibrary-7cbae7a0.js} +1 -1
  8. package/Build/Workers/{CylinderGeometry-f9503c6d.js → CylinderGeometry-42740df0.js} +1 -1
  9. package/Build/Workers/{EllipseGeometry-fedf72d5.js → EllipseGeometry-49a3ac21.js} +1 -1
  10. package/Build/Workers/{EllipseGeometryLibrary-4ea68687.js → EllipseGeometryLibrary-b891b2f8.js} +1 -1
  11. package/Build/Workers/{EllipseOutlineGeometry-e2ae6a35.js → EllipseOutlineGeometry-fbd72e07.js} +1 -1
  12. package/Build/Workers/{EllipsoidGeodesic-16de63ea.js → EllipsoidGeodesic-98c62a56.js} +1 -1
  13. package/Build/Workers/{EllipsoidGeometry-95c0330e.js → EllipsoidGeometry-a351dba8.js} +1 -1
  14. package/Build/Workers/{EllipsoidOutlineGeometry-d6d2ceec.js → EllipsoidOutlineGeometry-3e8779bf.js} +1 -1
  15. package/Build/Workers/{EllipsoidRhumbLine-ae5e65e0.js → EllipsoidRhumbLine-19756602.js} +1 -1
  16. package/Build/Workers/{EllipsoidTangentPlane-bfc674bf.js → EllipsoidTangentPlane-cfb50678.js} +1 -1
  17. package/Build/Workers/{EncodedCartesian3-f473ea18.js → EncodedCartesian3-81f70735.js} +1 -1
  18. package/Build/Workers/{FrustumGeometry-3bf2e4eb.js → FrustumGeometry-c5754412.js} +1 -1
  19. package/Build/Workers/{GeometryAttribute-df5f473e.js → GeometryAttribute-0bfd05e8.js} +1 -1
  20. package/Build/Workers/{GeometryInstance-aa75b4cf.js → GeometryInstance-451dc1cd.js} +1 -1
  21. package/Build/Workers/{GeometryPipeline-f0e46c42.js → GeometryPipeline-0166905d.js} +1 -1
  22. package/Build/Workers/{IntersectionTests-9de29d51.js → IntersectionTests-a93d3de9.js} +1 -1
  23. package/Build/Workers/{Matrix2-ce637455.js → Matrix2-13178034.js} +4 -2
  24. package/Build/Workers/{Matrix3-4f4df527.js → Matrix3-315394f6.js} +2 -1
  25. package/Build/Workers/{OrientedBoundingBox-d3ff3d4d.js → OrientedBoundingBox-b450cb61.js} +5 -5
  26. package/Build/Workers/{Plane-b81241c2.js → Plane-900aa728.js} +1 -1
  27. package/Build/Workers/{PolygonGeometryLibrary-6f4937bb.js → PolygonGeometryLibrary-f918ac26.js} +1 -1
  28. package/Build/Workers/PolygonPipeline-f59a8f0a.js +1345 -0
  29. package/Build/Workers/{PolylinePipeline-2e2b015c.js → PolylinePipeline-d8e6bd9b.js} +1 -1
  30. package/Build/Workers/{PolylineVolumeGeometryLibrary-7ee1d449.js → PolylineVolumeGeometryLibrary-125d2edf.js} +1 -1
  31. package/Build/Workers/{PrimitivePipeline-a9b7aae0.js → PrimitivePipeline-0d7b5ed4.js} +1 -1
  32. package/Build/Workers/{RectangleGeometryLibrary-9aa6c8f6.js → RectangleGeometryLibrary-0768db63.js} +1 -1
  33. package/Build/Workers/{TerrainEncoding-b52dcfc5.js → TerrainEncoding-06470d7f.js} +1 -1
  34. package/Build/Workers/{Transforms-2f755df8.js → Transforms-26539bce.js} +97 -83
  35. package/Build/Workers/{WallGeometryLibrary-ab19a93d.js → WallGeometryLibrary-6167b0fc.js} +1 -1
  36. package/Build/Workers/{WebMercatorProjection-9f25de49.js → WebMercatorProjection-13a90d41.js} +1 -1
  37. package/Build/Workers/cesiumWorkerBootstrapper.js +25 -1
  38. package/Build/Workers/combineGeometry.js +1 -1
  39. package/Build/Workers/createBoxGeometry.js +1 -1
  40. package/Build/Workers/createBoxOutlineGeometry.js +1 -1
  41. package/Build/Workers/createCircleGeometry.js +1 -1
  42. package/Build/Workers/createCircleOutlineGeometry.js +1 -1
  43. package/Build/Workers/createCoplanarPolygonGeometry.js +1 -1
  44. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +1 -1
  45. package/Build/Workers/createCorridorGeometry.js +1 -1
  46. package/Build/Workers/createCorridorOutlineGeometry.js +1 -1
  47. package/Build/Workers/createCylinderGeometry.js +1 -1
  48. package/Build/Workers/createCylinderOutlineGeometry.js +1 -1
  49. package/Build/Workers/createEllipseGeometry.js +1 -1
  50. package/Build/Workers/createEllipseOutlineGeometry.js +1 -1
  51. package/Build/Workers/createEllipsoidGeometry.js +1 -1
  52. package/Build/Workers/createEllipsoidOutlineGeometry.js +1 -1
  53. package/Build/Workers/createFrustumGeometry.js +1 -1
  54. package/Build/Workers/createFrustumOutlineGeometry.js +1 -1
  55. package/Build/Workers/createGeometry.js +1 -1
  56. package/Build/Workers/createGroundPolylineGeometry.js +1 -1
  57. package/Build/Workers/createPlaneGeometry.js +1 -1
  58. package/Build/Workers/createPlaneOutlineGeometry.js +1 -1
  59. package/Build/Workers/createPolygonGeometry.js +1 -1
  60. package/Build/Workers/createPolygonOutlineGeometry.js +1 -1
  61. package/Build/Workers/createPolylineGeometry.js +1 -1
  62. package/Build/Workers/createPolylineVolumeGeometry.js +1 -1
  63. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +1 -1
  64. package/Build/Workers/createRectangleGeometry.js +1 -1
  65. package/Build/Workers/createRectangleOutlineGeometry.js +1 -1
  66. package/Build/Workers/createSimplePolylineGeometry.js +1 -1
  67. package/Build/Workers/createSphereGeometry.js +1 -1
  68. package/Build/Workers/createSphereOutlineGeometry.js +1 -1
  69. package/Build/Workers/createVectorTileClampedPolylines.js +1 -1
  70. package/Build/Workers/createVectorTileGeometries.js +1 -1
  71. package/Build/Workers/createVectorTilePoints.js +1 -1
  72. package/Build/Workers/createVectorTilePolygons.js +1 -1
  73. package/Build/Workers/createVectorTilePolylines.js +1 -1
  74. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +1 -1
  75. package/Build/Workers/createVerticesFromHeightmap.js +7 -3
  76. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +1 -1
  77. package/Build/Workers/createWallGeometry.js +1 -1
  78. package/Build/Workers/createWallOutlineGeometry.js +1 -1
  79. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +95 -76
  80. package/Build/Workers/decodeI3S.js +1 -1
  81. package/Build/Workers/package.js +25 -1
  82. package/Build/Workers/transferTypedArrayTest.js +25 -1
  83. package/Build/Workers/upsampleQuantizedTerrainMesh.js +1 -1
  84. package/README.md +9 -9
  85. package/Source/Core/EarthOrientationParameters.js +67 -63
  86. package/Source/Core/Ion.js +1 -1
  87. package/Source/Core/Matrix2.js +2 -1
  88. package/Source/Core/Matrix3.js +2 -1
  89. package/Source/Core/Matrix4.js +1 -0
  90. package/Source/Core/OrientedBoundingBox.js +4 -4
  91. package/Source/Core/S2Cell.js +3 -3
  92. package/Source/Core/Transforms.js +3 -7
  93. package/Source/DataSources/GpxDataSource.js +4 -6
  94. package/Source/DataSources/KmlDataSource.js +3 -5
  95. package/Source/Renderer/Context.js +230 -177
  96. package/Source/Renderer/Pass.js +3 -2
  97. package/Source/Scene/Cesium3DTileContentType.js +19 -0
  98. package/Source/Scene/Cesium3DTilesVoxelProvider.js +482 -0
  99. package/Source/Scene/Cesium3DTilesetMetadata.js +2 -2
  100. package/Source/Scene/ContentMetadata.js +2 -2
  101. package/Source/Scene/DerivedCommand.js +7 -0
  102. package/Source/Scene/Expression.js +1 -1
  103. package/Source/Scene/Globe.js +10 -0
  104. package/Source/Scene/GlobeSurfaceTileProvider.js +7 -0
  105. package/Source/Scene/GltfImageLoader.js +1 -1
  106. package/Source/Scene/GltfVertexBufferLoader.js +10 -2
  107. package/Source/Scene/GroupMetadata.js +2 -2
  108. package/Source/Scene/I3SDataProvider.js +2 -1
  109. package/Source/Scene/I3SFeature.js +1 -1
  110. package/Source/Scene/I3SLayer.js +64 -2
  111. package/Source/Scene/I3SNode.js +50 -6
  112. package/Source/Scene/ImplicitMetadataView.js +2 -2
  113. package/Source/Scene/ImplicitSubtreeCache.js +127 -0
  114. package/Source/Scene/ImplicitSubtreeMetadata.js +2 -2
  115. package/Source/Scene/ImplicitTileset.js +3 -2
  116. package/Source/Scene/KeyframeNode.js +47 -0
  117. package/Source/Scene/Megatexture.js +490 -0
  118. package/Source/Scene/MetadataClass.js +60 -25
  119. package/Source/Scene/MetadataClassProperty.js +132 -68
  120. package/Source/Scene/MetadataComponentType.js +78 -57
  121. package/Source/Scene/MetadataEnum.js +59 -23
  122. package/Source/Scene/MetadataEnumValue.js +49 -15
  123. package/Source/Scene/MetadataSchema.js +53 -24
  124. package/Source/Scene/MetadataSchemaLoader.js +2 -2
  125. package/Source/Scene/MetadataTableProperty.js +2 -2
  126. package/Source/Scene/MetadataType.js +6 -14
  127. package/Source/Scene/Model/GeoJsonLoader.js +1 -1
  128. package/Source/Scene/Model/Model.js +38 -6
  129. package/Source/Scene/Model/buildDrawCommand.js +19 -11
  130. package/Source/Scene/PointCloud.js +1 -1
  131. package/Source/Scene/PropertyAttribute.js +2 -2
  132. package/Source/Scene/PropertyAttributeProperty.js +2 -2
  133. package/Source/Scene/PropertyTable.js +2 -2
  134. package/Source/Scene/PropertyTexture.js +2 -2
  135. package/Source/Scene/PropertyTextureProperty.js +2 -2
  136. package/Source/Scene/ResourceCache.js +9 -1
  137. package/Source/Scene/ResourceCacheKey.js +9 -1
  138. package/Source/Scene/Scene.js +20 -50
  139. package/Source/Scene/SpatialNode.js +375 -0
  140. package/Source/Scene/StructuralMetadata.js +2 -2
  141. package/Source/Scene/TileMetadata.js +2 -2
  142. package/Source/Scene/TilesetMetadata.js +2 -2
  143. package/Source/Scene/VoxelBoxShape.js +527 -0
  144. package/Source/Scene/VoxelContent.js +169 -0
  145. package/Source/Scene/VoxelCylinderShape.js +937 -0
  146. package/Source/Scene/VoxelEllipsoidShape.js +937 -0
  147. package/Source/Scene/VoxelPrimitive.js +1919 -0
  148. package/Source/Scene/VoxelProvider.js +255 -0
  149. package/Source/Scene/VoxelRenderResources.js +224 -0
  150. package/Source/Scene/VoxelShape.js +152 -0
  151. package/Source/Scene/VoxelShapeType.js +105 -0
  152. package/Source/Scene/VoxelTraversal.js +1144 -0
  153. package/Source/Scene/buildVoxelDrawCommands.js +116 -0
  154. package/Source/Scene/parseBatchTable.js +18 -2
  155. package/Source/Scene/preprocess3DTileContent.js +8 -0
  156. package/Source/Scene/processVoxelProperties.js +455 -0
  157. package/Source/Shaders/BillboardCollectionVS.glsl +1 -1
  158. package/Source/Shaders/BillboardCollectionVS.js +1 -1
  159. package/Source/Shaders/Builtin/Constants/passOverlay.glsl +1 -1
  160. package/Source/Shaders/Builtin/Constants/passOverlay.js +1 -1
  161. package/Source/Shaders/Builtin/Constants/passVoxels.glsl +9 -0
  162. package/Source/Shaders/Builtin/Constants/passVoxels.js +11 -0
  163. package/Source/Shaders/Builtin/CzmBuiltins.js +2 -0
  164. package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.glsl +55 -43
  165. package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.js +55 -43
  166. package/Source/Shaders/GlobeFS.glsl +2 -1
  167. package/Source/Shaders/GlobeFS.js +2 -1
  168. package/Source/Shaders/PointPrimitiveCollectionVS.glsl +5 -2
  169. package/Source/Shaders/PointPrimitiveCollectionVS.js +5 -2
  170. package/Source/Shaders/Voxels/IntersectBox.glsl +79 -0
  171. package/Source/Shaders/Voxels/IntersectBox.js +81 -0
  172. package/Source/Shaders/Voxels/IntersectClippingPlanes.glsl +70 -0
  173. package/Source/Shaders/Voxels/IntersectClippingPlanes.js +72 -0
  174. package/Source/Shaders/Voxels/IntersectCylinder.glsl +273 -0
  175. package/Source/Shaders/Voxels/IntersectCylinder.js +275 -0
  176. package/Source/Shaders/Voxels/IntersectDepth.glsl +23 -0
  177. package/Source/Shaders/Voxels/IntersectDepth.js +25 -0
  178. package/Source/Shaders/Voxels/IntersectEllipsoid.glsl +337 -0
  179. package/Source/Shaders/Voxels/IntersectEllipsoid.js +339 -0
  180. package/Source/Shaders/Voxels/Intersection.glsl +54 -0
  181. package/Source/Shaders/Voxels/Intersection.js +56 -0
  182. package/Source/Shaders/Voxels/IntersectionUtils.glsl +151 -0
  183. package/Source/Shaders/Voxels/IntersectionUtils.js +153 -0
  184. package/Source/Shaders/Voxels/Megatexture.glsl +136 -0
  185. package/Source/Shaders/Voxels/Megatexture.js +138 -0
  186. package/Source/Shaders/Voxels/Octree.glsl +221 -0
  187. package/Source/Shaders/Voxels/Octree.js +223 -0
  188. package/Source/Shaders/Voxels/VoxelFS.glsl +150 -0
  189. package/Source/Shaders/Voxels/VoxelFS.js +152 -0
  190. package/Source/Shaders/Voxels/VoxelVS.glsl +11 -0
  191. package/Source/Shaders/Voxels/VoxelVS.js +13 -0
  192. package/Source/Shaders/Voxels/convertUvToBox.glsl +16 -0
  193. package/Source/Shaders/Voxels/convertUvToBox.js +18 -0
  194. package/Source/Shaders/Voxels/convertUvToCylinder.glsl +79 -0
  195. package/Source/Shaders/Voxels/convertUvToCylinder.js +81 -0
  196. package/Source/Shaders/Voxels/convertUvToEllipsoid.glsl +133 -0
  197. package/Source/Shaders/Voxels/convertUvToEllipsoid.js +135 -0
  198. package/Source/ThirdParty/Workers/draco_decoder_nodejs.js +100 -101
  199. package/Source/ThirdParty/Workers/pako_deflate.min.js +2 -2
  200. package/Source/ThirdParty/Workers/pako_inflate.min.js +2 -2
  201. package/Source/ThirdParty/draco_decoder.wasm +0 -0
  202. package/Source/Widget/CesiumWidget.js +1 -1
  203. package/index.d.ts +961 -56
  204. package/index.js +92 -60
  205. package/package.json +6 -4
  206. package/Build/ThirdParty/Workers/basis_transcoder.js +0 -2233
  207. package/Build/ThirdParty/Workers/draco_decoder_nodejs.js +0 -1872
  208. package/Build/ThirdParty/Workers/package.json +0 -1
  209. package/Build/ThirdParty/Workers/pako_deflate.min.js +0 -589
  210. package/Build/ThirdParty/Workers/pako_inflate.min.js +0 -798
  211. package/Build/ThirdParty/Workers/z-worker-pako.js +0 -503
  212. package/Build/ThirdParty/basis_transcoder.wasm +0 -0
  213. package/Build/ThirdParty/draco_decoder.wasm +0 -0
  214. package/Build/ThirdParty/google-earth-dbroot-parser.js +0 -8019
  215. package/Build/Widget/CesiumWidget.css +0 -120
  216. package/Build/Widget/lighter.css +0 -13
  217. package/Build/Workers/PolygonPipeline-774a8aaf.js +0 -1341
@@ -0,0 +1,490 @@
1
+ import Cartesian2 from "../Core/Cartesian2.js";
2
+ import Cartesian3 from "../Core/Cartesian3.js";
3
+ import ComponentDatatype from "../Core/ComponentDatatype.js";
4
+ import ContextLimits from "../Renderer/ContextLimits.js";
5
+ import defaultValue from "../Core/defaultValue.js";
6
+ import defined from "../Core/defined.js";
7
+ import destroyObject from "../Core/destroyObject.js";
8
+ import DeveloperError from "../Core/DeveloperError.js";
9
+ import CesiumMath from "../Core/Math.js";
10
+ import MetadataComponentType from "./MetadataComponentType.js";
11
+ import PixelDatatype from "../Renderer/PixelDatatype.js";
12
+ import PixelFormat from "../Core/PixelFormat.js";
13
+ import RuntimeError from "../Core/RuntimeError.js";
14
+ import Sampler from "../Renderer/Sampler.js";
15
+ import Texture from "../Renderer/Texture.js";
16
+ import TextureMagnificationFilter from "../Renderer/TextureMagnificationFilter.js";
17
+ import TextureMinificationFilter from "../Renderer/TextureMinificationFilter.js";
18
+ import TextureWrap from "../Renderer/TextureWrap.js";
19
+
20
+ /**
21
+ * @alias Megatexture
22
+ * @constructor
23
+ *
24
+ * @param {Context} context
25
+ * @param {Cartesian3} dimensions
26
+ * @param {Number} channelCount
27
+ * @param {MetadataComponentType} componentType
28
+ * @param {Number} [textureMemoryByteLength]
29
+ *
30
+ * @private
31
+ */
32
+ function Megatexture(
33
+ context,
34
+ dimensions,
35
+ channelCount,
36
+ componentType,
37
+ textureMemoryByteLength
38
+ ) {
39
+ // TODO there are a lot of texture packing rules, see https://github.com/CesiumGS/cesium/issues/9572
40
+ // Unsigned short textures not allowed in webgl 1, so treat as float
41
+ if (componentType === MetadataComponentType.UNSIGNED_SHORT) {
42
+ componentType = MetadataComponentType.FLOAT32;
43
+ }
44
+
45
+ const supportsFloatingPointTexture = context.floatingPointTexture;
46
+ if (
47
+ componentType === MetadataComponentType.FLOAT32 &&
48
+ !supportsFloatingPointTexture
49
+ ) {
50
+ throw new RuntimeError("Floating point texture not supported");
51
+ }
52
+
53
+ // TODO support more
54
+ let pixelType;
55
+ if (
56
+ componentType === MetadataComponentType.FLOAT32 ||
57
+ componentType === MetadataComponentType.FLOAT64
58
+ ) {
59
+ pixelType = PixelDatatype.FLOAT;
60
+ } else if (componentType === MetadataComponentType.UINT8) {
61
+ pixelType = PixelDatatype.UNSIGNED_BYTE;
62
+ }
63
+
64
+ let pixelFormat;
65
+ if (channelCount === 1) {
66
+ pixelFormat = PixelFormat.LUMINANCE;
67
+ } else if (channelCount === 2) {
68
+ pixelFormat = PixelFormat.LUMINANCE_ALPHA;
69
+ } else if (channelCount === 3) {
70
+ pixelFormat = PixelFormat.RGB;
71
+ } else if (channelCount === 4) {
72
+ pixelFormat = PixelFormat.RGBA;
73
+ }
74
+
75
+ const maximumTextureMemoryByteLength = 512 * 1024 * 1024;
76
+ const defaultTextureMemoryByteLength = 128 * 1024 * 1024;
77
+ textureMemoryByteLength = Math.min(
78
+ defaultValue(textureMemoryByteLength, defaultTextureMemoryByteLength),
79
+ maximumTextureMemoryByteLength
80
+ );
81
+ const maximumTextureDimensionContext = ContextLimits.maximumTextureSize;
82
+ const componentTypeByteLength = MetadataComponentType.getSizeInBytes(
83
+ componentType
84
+ );
85
+ const texelCount = Math.floor(
86
+ textureMemoryByteLength / (channelCount * componentTypeByteLength)
87
+ );
88
+ const textureDimension = Math.min(
89
+ maximumTextureDimensionContext,
90
+ CesiumMath.previousPowerOfTwo(Math.floor(Math.sqrt(texelCount)))
91
+ );
92
+
93
+ const sliceCountPerRegionX = Math.ceil(Math.sqrt(dimensions.x));
94
+ const sliceCountPerRegionY = Math.ceil(dimensions.z / sliceCountPerRegionX);
95
+ const voxelCountPerRegionX = sliceCountPerRegionX * dimensions.x;
96
+ const voxelCountPerRegionY = sliceCountPerRegionY * dimensions.y;
97
+ const regionCountPerMegatextureX = Math.floor(
98
+ textureDimension / voxelCountPerRegionX
99
+ );
100
+ const regionCountPerMegatextureY = Math.floor(
101
+ textureDimension / voxelCountPerRegionY
102
+ );
103
+
104
+ if (regionCountPerMegatextureX === 0 || regionCountPerMegatextureY === 0) {
105
+ throw new RuntimeError("Tileset is too large to fit into megatexture");
106
+ }
107
+
108
+ /**
109
+ * @type {Number}
110
+ * @readonly
111
+ */
112
+ this.channelCount = channelCount;
113
+
114
+ /**
115
+ * @type {MetadataComponentType}
116
+ * @readonly
117
+ */
118
+ this.componentType = componentType;
119
+
120
+ /**
121
+ * @type {Cartesian3}
122
+ * @readonly
123
+ */
124
+ this.voxelCountPerTile = Cartesian3.clone(dimensions, new Cartesian3());
125
+
126
+ /**
127
+ * @type {Number}
128
+ * @readonly
129
+ */
130
+ this.maximumTileCount =
131
+ regionCountPerMegatextureX * regionCountPerMegatextureY;
132
+
133
+ /**
134
+ * @type {Cartesian2}
135
+ * @readonly
136
+ */
137
+ this.regionCountPerMegatexture = new Cartesian2(
138
+ regionCountPerMegatextureX,
139
+ regionCountPerMegatextureY
140
+ );
141
+
142
+ /**
143
+ * @type {Cartesian2}
144
+ * @readonly
145
+ */
146
+ this.voxelCountPerRegion = new Cartesian2(
147
+ voxelCountPerRegionX,
148
+ voxelCountPerRegionY
149
+ );
150
+
151
+ /**
152
+ * @type {Cartesian2}
153
+ * @readonly
154
+ */
155
+ this.sliceCountPerRegion = new Cartesian2(
156
+ sliceCountPerRegionX,
157
+ sliceCountPerRegionY
158
+ );
159
+
160
+ /**
161
+ * @type {Cartesian2}
162
+ * @readonly
163
+ */
164
+ this.voxelSizeUv = new Cartesian2(
165
+ 1.0 / textureDimension,
166
+ 1.0 / textureDimension
167
+ );
168
+
169
+ /**
170
+ * @type {Cartesian2}
171
+ * @readonly
172
+ */
173
+ this.sliceSizeUv = new Cartesian2(
174
+ dimensions.x / textureDimension,
175
+ dimensions.y / textureDimension
176
+ );
177
+
178
+ /**
179
+ * @type {Cartesian2}
180
+ * @readonly
181
+ */
182
+ this.regionSizeUv = new Cartesian2(
183
+ voxelCountPerRegionX / textureDimension,
184
+ voxelCountPerRegionY / textureDimension
185
+ );
186
+
187
+ /**
188
+ * @type {Texture}
189
+ * @readonly
190
+ */
191
+ this.texture = new Texture({
192
+ context: context,
193
+ pixelFormat: pixelFormat,
194
+ pixelDatatype: pixelType,
195
+ flipY: false,
196
+ width: textureDimension,
197
+ height: textureDimension,
198
+ sampler: new Sampler({
199
+ wrapS: TextureWrap.CLAMP_TO_EDGE,
200
+ wrapT: TextureWrap.CLAMP_TO_EDGE,
201
+ minificationFilter: TextureMinificationFilter.LINEAR,
202
+ magnificationFilter: TextureMagnificationFilter.LINEAR,
203
+ }),
204
+ });
205
+
206
+ const componentDatatype = MetadataComponentType.toComponentDatatype(
207
+ componentType
208
+ );
209
+
210
+ /**
211
+ * @type {Array}
212
+ */
213
+ this.tileVoxelDataTemp = ComponentDatatype.createTypedArray(
214
+ componentDatatype,
215
+ voxelCountPerRegionX * voxelCountPerRegionY * channelCount
216
+ );
217
+
218
+ /**
219
+ * @type {MegatextureNode[]}
220
+ * @readonly
221
+ */
222
+ this.nodes = new Array(this.maximumTileCount);
223
+ for (let tileIndex = 0; tileIndex < this.maximumTileCount; tileIndex++) {
224
+ this.nodes[tileIndex] = new MegatextureNode(tileIndex);
225
+ }
226
+ for (let tileIndex = 0; tileIndex < this.maximumTileCount; tileIndex++) {
227
+ const node = this.nodes[tileIndex];
228
+ node.previousNode = tileIndex > 0 ? this.nodes[tileIndex - 1] : undefined;
229
+ node.nextNode =
230
+ tileIndex < this.maximumTileCount - 1
231
+ ? this.nodes[tileIndex + 1]
232
+ : undefined;
233
+ }
234
+
235
+ /**
236
+ * @type {MegatextureNode}
237
+ * @readonly
238
+ */
239
+ this.occupiedList = undefined;
240
+
241
+ /**
242
+ * @type {MegatextureNode}
243
+ * @readonly
244
+ */
245
+ this.emptyList = this.nodes[0];
246
+
247
+ /**
248
+ * @type {Number}
249
+ * @readonly
250
+ */
251
+ this.occupiedCount = 0;
252
+ }
253
+
254
+ /**
255
+ * @alias MegatextureNode
256
+ * @constructor
257
+ *
258
+ * @param {Number} index
259
+ *
260
+ * @private
261
+ */
262
+ function MegatextureNode(index) {
263
+ /**
264
+ * @type {Number}
265
+ */
266
+ this.index = index;
267
+
268
+ /**
269
+ * @type {MegatextureNode}
270
+ */
271
+ this.nextNode = undefined;
272
+
273
+ /**
274
+ * @type {MegatextureNode}
275
+ */
276
+ this.previousNode = undefined;
277
+ }
278
+
279
+ /**
280
+ * @param {Array} data
281
+ * @returns {Number}
282
+ */
283
+ Megatexture.prototype.add = function (data) {
284
+ if (this.isFull()) {
285
+ throw new DeveloperError("Trying to add when there are no empty spots");
286
+ }
287
+
288
+ // remove head of empty list
289
+ const node = this.emptyList;
290
+ this.emptyList = this.emptyList.nextNode;
291
+ if (defined(this.emptyList)) {
292
+ this.emptyList.previousNode = undefined;
293
+ }
294
+
295
+ // make head of occupied list
296
+ node.nextNode = this.occupiedList;
297
+ if (defined(node.nextNode)) {
298
+ node.nextNode.previousNode = node;
299
+ }
300
+ this.occupiedList = node;
301
+
302
+ const index = node.index;
303
+ this.writeDataToTexture(index, data);
304
+
305
+ this.occupiedCount++;
306
+ return index;
307
+ };
308
+
309
+ /**
310
+ * @param {Number} index
311
+ */
312
+ Megatexture.prototype.remove = function (index) {
313
+ if (index < 0 || index >= this.maximumTileCount) {
314
+ throw new DeveloperError("Megatexture index out of bounds");
315
+ }
316
+
317
+ // remove from list
318
+ const node = this.nodes[index];
319
+ if (defined(node.previousNode)) {
320
+ node.previousNode.nextNode = node.nextNode;
321
+ }
322
+ if (defined(node.nextNode)) {
323
+ node.nextNode.previousNode = node.previousNode;
324
+ }
325
+
326
+ // make head of empty list
327
+ node.nextNode = this.emptyList;
328
+ if (defined(node.nextNode)) {
329
+ node.nextNode.previousNode = node;
330
+ }
331
+ node.previousNode = undefined;
332
+ this.emptyList = node;
333
+ this.occupiedCount--;
334
+ };
335
+
336
+ /**
337
+ * @returns {Boolean}
338
+ */
339
+ Megatexture.prototype.isFull = function () {
340
+ return this.emptyList === undefined;
341
+ };
342
+
343
+ /**
344
+ * @param {Number} tileCount
345
+ * @param {Cartesian3} dimensions
346
+ * @param {Number} channelCount number of channels in the metadata. Must be 1 to 4.
347
+ * @param {MetadataComponentType} componentType
348
+ * @returns {Number}
349
+ */
350
+ Megatexture.getApproximateTextureMemoryByteLength = function (
351
+ tileCount,
352
+ dimensions,
353
+ channelCount,
354
+ componentType
355
+ ) {
356
+ // TODO there's a lot of code duplicate with Megatexture constructor
357
+
358
+ // Unsigned short textures not allowed in webgl 1, so treat as float
359
+ if (componentType === MetadataComponentType.UNSIGNED_SHORT) {
360
+ componentType = MetadataComponentType.FLOAT32;
361
+ }
362
+
363
+ const datatypeSizeInBytes = MetadataComponentType.getSizeInBytes(
364
+ componentType
365
+ );
366
+ const voxelCountTotal =
367
+ tileCount * dimensions.x * dimensions.y * dimensions.z;
368
+
369
+ const sliceCountPerRegionX = Math.ceil(Math.sqrt(dimensions.z));
370
+ const sliceCountPerRegionY = Math.ceil(dimensions.z / sliceCountPerRegionX);
371
+ const voxelCountPerRegionX = sliceCountPerRegionX * dimensions.x;
372
+ const voxelCountPerRegionY = sliceCountPerRegionY * dimensions.y;
373
+
374
+ // Find the power of two that can fit all tile data, accounting for slices.
375
+ // There's probably a non-iterative solution for this, but this is good enough for now.
376
+ let textureDimension = CesiumMath.previousPowerOfTwo(
377
+ Math.floor(Math.sqrt(voxelCountTotal))
378
+ );
379
+ for (;;) {
380
+ const regionCountX = Math.floor(textureDimension / voxelCountPerRegionX);
381
+ const regionCountY = Math.floor(textureDimension / voxelCountPerRegionY);
382
+ const regionCount = regionCountX * regionCountY;
383
+ if (regionCount >= tileCount) {
384
+ break;
385
+ } else {
386
+ textureDimension *= 2;
387
+ }
388
+ }
389
+
390
+ const textureMemoryByteLength =
391
+ textureDimension * textureDimension * channelCount * datatypeSizeInBytes;
392
+ return textureMemoryByteLength;
393
+ };
394
+
395
+ /**
396
+ * @param {Number} index
397
+ * @param {Float32Array|Uint16Array|Uint8Array} data
398
+ */
399
+ Megatexture.prototype.writeDataToTexture = function (index, data) {
400
+ // Unsigned short textures not allowed in webgl 1, so treat as float
401
+ const tileData =
402
+ data.constructor === Uint16Array ? new Float32Array(data) : data;
403
+
404
+ const voxelDimensionsPerTile = this.voxelCountPerTile;
405
+ const sliceDimensionsPerRegion = this.sliceCountPerRegion;
406
+ const voxelDimensionsPerRegion = this.voxelCountPerRegion;
407
+ const channelCount = this.channelCount;
408
+
409
+ const tileVoxelData = this.tileVoxelDataTemp;
410
+ for (let z = 0; z < voxelDimensionsPerTile.z; z++) {
411
+ const sliceVoxelOffsetX =
412
+ (z % sliceDimensionsPerRegion.x) * voxelDimensionsPerTile.x;
413
+ const sliceVoxelOffsetY =
414
+ Math.floor(z / sliceDimensionsPerRegion.x) * voxelDimensionsPerTile.y;
415
+ for (let y = 0; y < voxelDimensionsPerTile.y; y++) {
416
+ for (let x = 0; x < voxelDimensionsPerTile.x; x++) {
417
+ const readIndex =
418
+ z * voxelDimensionsPerTile.y * voxelDimensionsPerTile.x +
419
+ y * voxelDimensionsPerTile.x +
420
+ x;
421
+ const writeIndex =
422
+ (sliceVoxelOffsetY + y) * voxelDimensionsPerRegion.x +
423
+ (sliceVoxelOffsetX + x);
424
+ for (let c = 0; c < channelCount; c++) {
425
+ tileVoxelData[writeIndex * channelCount + c] =
426
+ tileData[readIndex * channelCount + c];
427
+ }
428
+ }
429
+ }
430
+ }
431
+
432
+ const regionDimensionsPerMegatexture = this.regionCountPerMegatexture;
433
+ const voxelWidth = voxelDimensionsPerRegion.x;
434
+ const voxelHeight = voxelDimensionsPerRegion.y;
435
+ const voxelOffsetX =
436
+ (index % regionDimensionsPerMegatexture.x) * voxelDimensionsPerRegion.x;
437
+ const voxelOffsetY =
438
+ Math.floor(index / regionDimensionsPerMegatexture.x) *
439
+ voxelDimensionsPerRegion.y;
440
+
441
+ const source = {
442
+ arrayBufferView: tileVoxelData,
443
+ width: voxelWidth,
444
+ height: voxelHeight,
445
+ };
446
+
447
+ const copyOptions = {
448
+ source: source,
449
+ xOffset: voxelOffsetX,
450
+ yOffset: voxelOffsetY,
451
+ };
452
+
453
+ this.texture.copyFrom(copyOptions);
454
+ };
455
+
456
+ /**
457
+ * Returns true if this object was destroyed; otherwise, false.
458
+ * <br /><br />
459
+ * If this object was destroyed, it should not be used; calling any function other than
460
+ * <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
461
+ *
462
+ * @returns {Boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
463
+ *
464
+ * @see Megatexture#destroy
465
+ */
466
+ Megatexture.prototype.isDestroyed = function () {
467
+ return false;
468
+ };
469
+
470
+ /**
471
+ * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic
472
+ * release of WebGL resources, instead of relying on the garbage collector to destroy this object.
473
+ * <br /><br />
474
+ * Once an object is destroyed, it should not be used; calling any function other than
475
+ * <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
476
+ * assign the return value (<code>undefined</code>) to the object as done in the example.
477
+ *
478
+ * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
479
+ *
480
+ * @see Megatexture#isDestroyed
481
+ *
482
+ * @example
483
+ * megatexture = megatexture && megatexture.destroy();
484
+ */
485
+ Megatexture.prototype.destroy = function () {
486
+ this.texture = this.texture && this.texture.destroy();
487
+ return destroyObject(this);
488
+ };
489
+
490
+ export default Megatexture;
@@ -1,4 +1,5 @@
1
1
  import Check from "../Core/Check.js";
2
+ import clone from "../Core/clone.js";
2
3
  import defaultValue from "../Core/defaultValue.js";
3
4
  import defined from "../Core/defined.js";
4
5
  import MetadataClassProperty from "./MetadataClassProperty.js";
@@ -7,22 +8,65 @@ import MetadataClassProperty from "./MetadataClassProperty.js";
7
8
  * A metadata class.
8
9
  *
9
10
  * <p>
10
- * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/extensions/3DTILES_metadata|3DTILES_metadata Extension} for 3D Tiles
11
+ * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Metadata|3D Metadata Specification} for 3D Tiles
11
12
  * </p>
12
13
  *
13
14
  * @param {Object} options Object with the following properties:
14
15
  * @param {String} options.id The ID of the class.
15
- * @param {Object} options.class The class JSON object.
16
- * @param {Object.<String, MetadataEnum>} [options.enums] A dictionary of enums.
16
+ * @param {String} [options.name] The name of the class.
17
+ * @param {String} [options.description] The description of the class.
18
+ * @param {Object.<String, MetadataClassProperty>} [options.properties] The class properties, where each key is the property ID.
19
+ * @param {*} [options.extras] Extra user-defined properties.
20
+ * @param {Object} [options.extensions] An object containing extensions.
17
21
  *
18
22
  * @alias MetadataClass
19
23
  * @constructor
20
- * @private
21
24
  * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
22
25
  */
23
26
  function MetadataClass(options) {
24
27
  options = defaultValue(options, defaultValue.EMPTY_OBJECT);
25
28
  const id = options.id;
29
+
30
+ //>>includeStart('debug', pragmas.debug);
31
+ Check.typeOf.string("options.id", id);
32
+ //>>includeEnd('debug');
33
+
34
+ const properties = defaultValue(options.properties, {});
35
+ const propertiesBySemantic = {};
36
+ for (const propertyId in properties) {
37
+ if (properties.hasOwnProperty(propertyId)) {
38
+ const property = properties[propertyId];
39
+ if (defined(property.semantic)) {
40
+ propertiesBySemantic[property.semantic] = property;
41
+ }
42
+ }
43
+ }
44
+
45
+ this._id = id;
46
+ this._name = options.name;
47
+ this._description = options.description;
48
+ this._properties = properties;
49
+ this._propertiesBySemantic = propertiesBySemantic;
50
+ this._extras = clone(options.extras, true);
51
+ this._extensions = clone(options.extensions, true);
52
+ }
53
+
54
+ /**
55
+ * Creates a {@link MetadataClass} from either 3D Tiles 1.1, 3DTILES_metadata, EXT_structural_metadata, or EXT_feature_metadata.
56
+ *
57
+ * @param {Object} options Object with the following properties:
58
+ * @param {String} options.id The ID of the class.
59
+ * @param {Object} options.class The class JSON object.
60
+ * @param {Object.<String, MetadataEnum>} [options.enums] A dictionary of enums.
61
+ *
62
+ * @returns {MetadataClass} The newly created metadata class.
63
+ *
64
+ * @private
65
+ * @experimental This feature is using part of the 3D Tiles spec that is not final and is subject to change without Cesium's standard deprecation policy.
66
+ */
67
+ MetadataClass.fromJson = function (options) {
68
+ options = defaultValue(options, defaultValue.EMPTY_OBJECT);
69
+ const id = options.id;
26
70
  const classDefinition = options.class;
27
71
 
28
72
  //>>includeStart('debug', pragmas.debug);
@@ -31,29 +75,26 @@ function MetadataClass(options) {
31
75
  //>>includeEnd('debug');
32
76
 
33
77
  const properties = {};
34
- const propertiesBySemantic = {};
35
78
  for (const propertyId in classDefinition.properties) {
36
79
  if (classDefinition.properties.hasOwnProperty(propertyId)) {
37
- const property = new MetadataClassProperty({
80
+ const property = MetadataClassProperty.fromJson({
38
81
  id: propertyId,
39
82
  property: classDefinition.properties[propertyId],
40
83
  enums: options.enums,
41
84
  });
42
85
  properties[propertyId] = property;
43
- if (defined(property.semantic)) {
44
- propertiesBySemantic[property.semantic] = property;
45
- }
46
86
  }
47
87
  }
48
88
 
49
- this._properties = properties;
50
- this._propertiesBySemantic = propertiesBySemantic;
51
- this._id = id;
52
- this._name = classDefinition.name;
53
- this._description = classDefinition.description;
54
- this._extras = classDefinition.extras;
55
- this._extensions = classDefinition.extensions;
56
- }
89
+ return new MetadataClass({
90
+ id: id,
91
+ name: classDefinition.name,
92
+ description: classDefinition.description,
93
+ properties: properties,
94
+ extras: classDefinition.extras,
95
+ extensions: classDefinition.extensions,
96
+ });
97
+ };
57
98
 
58
99
  Object.defineProperties(MetadataClass.prototype, {
59
100
  /**
@@ -62,7 +103,6 @@ Object.defineProperties(MetadataClass.prototype, {
62
103
  * @memberof MetadataClass.prototype
63
104
  * @type {Object.<String, MetadataClassProperty>}
64
105
  * @readonly
65
- * @private
66
106
  */
67
107
  properties: {
68
108
  get: function () {
@@ -91,7 +131,6 @@ Object.defineProperties(MetadataClass.prototype, {
91
131
  * @memberof MetadataClass.prototype
92
132
  * @type {String}
93
133
  * @readonly
94
- * @private
95
134
  */
96
135
  id: {
97
136
  get: function () {
@@ -105,7 +144,6 @@ Object.defineProperties(MetadataClass.prototype, {
105
144
  * @memberof MetadataClass.prototype
106
145
  * @type {String}
107
146
  * @readonly
108
- * @private
109
147
  */
110
148
  name: {
111
149
  get: function () {
@@ -119,7 +157,6 @@ Object.defineProperties(MetadataClass.prototype, {
119
157
  * @memberof MetadataClass.prototype
120
158
  * @type {String}
121
159
  * @readonly
122
- * @private
123
160
  */
124
161
  description: {
125
162
  get: function () {
@@ -128,12 +165,11 @@ Object.defineProperties(MetadataClass.prototype, {
128
165
  },
129
166
 
130
167
  /**
131
- * Extras in the JSON object.
168
+ * Extra user-defined properties.
132
169
  *
133
170
  * @memberof MetadataClass.prototype
134
171
  * @type {*}
135
172
  * @readonly
136
- * @private
137
173
  */
138
174
  extras: {
139
175
  get: function () {
@@ -142,12 +178,11 @@ Object.defineProperties(MetadataClass.prototype, {
142
178
  },
143
179
 
144
180
  /**
145
- * Extensions in the JSON object.
181
+ * An object containing extensions.
146
182
  *
147
183
  * @memberof MetadataClass.prototype
148
184
  * @type {Object}
149
185
  * @readonly
150
- * @private
151
186
  */
152
187
  extensions: {
153
188
  get: function () {