@cesium/engine 2.1.0 → 2.2.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.
- package/Build/Workers/{AxisAlignedBoundingBox-a6f9f0e5.js → AxisAlignedBoundingBox-379015ef.js} +1 -1
- package/Build/Workers/{BoundingRectangle-b0a68595.js → BoundingRectangle-57f2b24f.js} +1 -1
- package/Build/Workers/{BoxGeometry-baedd794.js → BoxGeometry-ecabfc78.js} +1 -1
- package/Build/Workers/{Color-f85df1be.js → Color-14d1a36d.js} +1 -1
- package/Build/Workers/{CoplanarPolygonGeometryLibrary-30516950.js → CoplanarPolygonGeometryLibrary-048c3c14.js} +1 -1
- package/Build/Workers/{CorridorGeometryLibrary-5d5d3b3a.js → CorridorGeometryLibrary-520c8619.js} +1 -1
- package/Build/Workers/{CylinderGeometry-d899ae26.js → CylinderGeometry-119068b8.js} +1 -1
- package/Build/Workers/{EllipseGeometry-a49f8449.js → EllipseGeometry-2dfc3523.js} +1 -1
- package/Build/Workers/{EllipseGeometryLibrary-cba7edde.js → EllipseGeometryLibrary-0a1e0170.js} +1 -1
- package/Build/Workers/{EllipseOutlineGeometry-8095c8cb.js → EllipseOutlineGeometry-c5251669.js} +1 -1
- package/Build/Workers/{EllipsoidGeometry-ed93f571.js → EllipsoidGeometry-d10a5221.js} +1 -1
- package/Build/Workers/{EllipsoidOutlineGeometry-e4854854.js → EllipsoidOutlineGeometry-7039a0ae.js} +1 -1
- package/Build/Workers/{EllipsoidTangentPlane-7ae1aa9a.js → EllipsoidTangentPlane-857186be.js} +1 -1
- package/Build/Workers/{FrustumGeometry-b62db3e3.js → FrustumGeometry-400fa1b7.js} +2 -2
- package/Build/Workers/{GeometryAttribute-780af4fa.js → GeometryAttribute-7a2de5c6.js} +1 -1
- package/Build/Workers/{GeometryPipeline-36b61c99.js → GeometryPipeline-916636fa.js} +1 -1
- package/Build/Workers/{IntersectionTests-e889fcf0.js → IntersectionTests-b4d02d4d.js} +1 -1
- package/Build/Workers/{OrientedBoundingBox-43478ac8.js → OrientedBoundingBox-96fe1752.js} +5 -3
- package/Build/Workers/{PolygonGeometryLibrary-38a98276.js → PolygonGeometryLibrary-931f1ec6.js} +1 -1
- package/Build/Workers/{PolygonPipeline-d31ff61c.js → PolygonPipeline-32fc92cc.js} +1 -1
- package/Build/Workers/{PolylinePipeline-30e4cec9.js → PolylinePipeline-6d5c63e5.js} +1 -1
- package/Build/Workers/{PolylineVolumeGeometryLibrary-90551d26.js → PolylineVolumeGeometryLibrary-f068c1fb.js} +1 -1
- package/Build/Workers/{PrimitivePipeline-558d9cb0.js → PrimitivePipeline-879f996a.js} +1 -1
- package/Build/Workers/{RectangleGeometryLibrary-815c68df.js → RectangleGeometryLibrary-2d6f36f3.js} +1 -1
- package/Build/Workers/{TerrainEncoding-341ead52.js → TerrainEncoding-82882059.js} +1 -1
- package/Build/Workers/{Transforms-9e9df299.js → Transforms-9052372a.js} +6 -5
- package/Build/Workers/{WallGeometryLibrary-ccf90976.js → WallGeometryLibrary-db7a64fb.js} +1 -1
- package/Build/Workers/cesiumWorkerBootstrapper.js +1 -1
- package/Build/Workers/combineGeometry.js +1 -1
- package/Build/Workers/createBoxGeometry.js +1 -1
- package/Build/Workers/createBoxOutlineGeometry.js +1 -1
- package/Build/Workers/createCircleGeometry.js +1 -1
- package/Build/Workers/createCircleOutlineGeometry.js +1 -1
- package/Build/Workers/createCoplanarPolygonGeometry.js +1 -1
- package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +1 -1
- package/Build/Workers/createCorridorGeometry.js +1 -1
- package/Build/Workers/createCorridorOutlineGeometry.js +1 -1
- package/Build/Workers/createCylinderGeometry.js +1 -1
- package/Build/Workers/createCylinderOutlineGeometry.js +1 -1
- package/Build/Workers/createEllipseGeometry.js +1 -1
- package/Build/Workers/createEllipseOutlineGeometry.js +1 -1
- package/Build/Workers/createEllipsoidGeometry.js +1 -1
- package/Build/Workers/createEllipsoidOutlineGeometry.js +1 -1
- package/Build/Workers/createFrustumGeometry.js +1 -1
- package/Build/Workers/createFrustumOutlineGeometry.js +1 -1
- package/Build/Workers/createGeometry.js +1 -1
- package/Build/Workers/createGroundPolylineGeometry.js +1 -1
- package/Build/Workers/createPlaneGeometry.js +1 -1
- package/Build/Workers/createPlaneOutlineGeometry.js +1 -1
- package/Build/Workers/createPolygonGeometry.js +1 -1
- package/Build/Workers/createPolygonOutlineGeometry.js +1 -1
- package/Build/Workers/createPolylineGeometry.js +1 -1
- package/Build/Workers/createPolylineVolumeGeometry.js +1 -1
- package/Build/Workers/createPolylineVolumeOutlineGeometry.js +1 -1
- package/Build/Workers/createRectangleGeometry.js +1 -1
- package/Build/Workers/createRectangleOutlineGeometry.js +1 -1
- package/Build/Workers/createSimplePolylineGeometry.js +1 -1
- package/Build/Workers/createSphereGeometry.js +1 -1
- package/Build/Workers/createSphereOutlineGeometry.js +1 -1
- package/Build/Workers/createVectorTileGeometries.js +1 -1
- package/Build/Workers/createVectorTilePolygons.js +1 -1
- package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +1 -1
- package/Build/Workers/createVerticesFromHeightmap.js +1 -1
- package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +10 -15
- package/Build/Workers/createWallGeometry.js +1 -1
- package/Build/Workers/createWallOutlineGeometry.js +1 -1
- package/Build/Workers/package.js +1 -1
- package/Build/Workers/transferTypedArrayTest.js +1 -1
- package/Build/Workers/upsampleQuantizedTerrainMesh.js +1 -1
- package/Source/Core/ArcGISTiledElevationTerrainProvider.js +291 -191
- package/Source/Core/CesiumTerrainProvider.js +571 -434
- package/Source/Core/CustomHeightmapTerrainProvider.js +12 -0
- package/Source/Core/EllipsoidTerrainProvider.js +17 -10
- package/Source/Core/FrustumGeometry.js +1 -1
- package/Source/Core/GoogleEarthEnterpriseMetadata.js +86 -34
- package/Source/Core/GoogleEarthEnterpriseTerrainProvider.js +119 -82
- package/Source/Core/Ion.js +1 -1
- package/Source/Core/IonResource.js +14 -3
- package/Source/Core/OrientedBoundingBox.js +4 -2
- package/Source/Core/RequestScheduler.js +1 -1
- package/Source/Core/Resource.js +2 -2
- package/Source/Core/TerrainProvider.js +9 -14
- package/Source/Core/TileProviderError.js +8 -8
- package/Source/Core/VRTheWorldTerrainProvider.js +193 -124
- package/Source/Core/buildModuleUrl.js +4 -3
- package/Source/Core/createWorldTerrain.js +20 -2
- package/Source/Core/createWorldTerrainAsync.js +48 -0
- package/Source/Core/sampleTerrain.js +9 -10
- package/Source/Core/sampleTerrainMostDetailed.js +66 -72
- package/Source/DataSources/Cesium3DTilesetVisualizer.js +37 -26
- package/Source/DataSources/Entity.js +6 -1
- package/Source/DataSources/ModelVisualizer.js +99 -31
- package/Source/DataSources/PolygonGraphics.js +1 -1
- package/Source/Scene/ArcGisMapServerImageryProvider.js +552 -376
- package/Source/Scene/BingMapsImageryProvider.js +511 -305
- package/Source/Scene/BufferLoader.js +29 -34
- package/Source/Scene/Cesium3DTile.js +388 -251
- package/Source/Scene/Cesium3DTileBatchTable.js +2 -2
- package/Source/Scene/Cesium3DTileContent.js +16 -0
- package/Source/Scene/Cesium3DTileContentFactory.js +4 -4
- package/Source/Scene/Cesium3DTilePass.js +8 -11
- package/Source/Scene/Cesium3DTileStyleEngine.js +1 -1
- package/Source/Scene/Cesium3DTilesVoxelProvider.js +225 -117
- package/Source/Scene/Cesium3DTileset.js +755 -481
- package/Source/Scene/Cesium3DTilesetBaseTraversal.js +301 -0
- package/Source/Scene/Cesium3DTilesetMostDetailedTraversal.js +33 -46
- package/Source/Scene/Cesium3DTilesetSkipTraversal.js +421 -0
- package/Source/Scene/Cesium3DTilesetTraversal.js +219 -671
- package/Source/Scene/ClassificationPrimitive.js +7 -0
- package/Source/Scene/Composite3DTileContent.js +69 -26
- package/Source/Scene/CreditDisplay.js +20 -4
- package/Source/Scene/DepthPlane.js +1 -1
- package/Source/Scene/Empty3DTileContent.js +31 -1
- package/Source/Scene/Geometry3DTileContent.js +47 -7
- package/Source/Scene/Globe.js +5 -1
- package/Source/Scene/GlobeSurfaceTile.js +2 -1
- package/Source/Scene/GlobeSurfaceTileProvider.js +50 -27
- package/Source/Scene/GltfBufferViewLoader.js +47 -91
- package/Source/Scene/GltfDracoLoader.js +110 -112
- package/Source/Scene/GltfImageLoader.js +71 -78
- package/Source/Scene/GltfIndexBufferLoader.js +108 -121
- package/Source/Scene/GltfJsonLoader.js +75 -74
- package/Source/Scene/GltfLoader.js +392 -280
- package/Source/Scene/GltfStructuralMetadataLoader.js +109 -110
- package/Source/Scene/GltfTextureLoader.js +97 -96
- package/Source/Scene/GltfVertexBufferLoader.js +128 -133
- package/Source/Scene/GoogleEarthEnterpriseImageryProvider.js +353 -225
- package/Source/Scene/GoogleEarthEnterpriseMapsProvider.js +491 -331
- package/Source/Scene/GridImageryProvider.js +267 -104
- package/Source/Scene/GroundPolylinePrimitive.js +12 -1
- package/Source/Scene/GroundPrimitive.js +8 -1
- package/Source/Scene/I3SDataProvider.js +214 -113
- package/Source/Scene/I3SFeature.js +7 -6
- package/Source/Scene/I3SLayer.js +26 -37
- package/Source/Scene/I3SNode.js +59 -66
- package/Source/Scene/Imagery.js +6 -1
- package/Source/Scene/ImageryLayer.js +299 -48
- package/Source/Scene/ImageryLayerCollection.js +26 -0
- package/Source/Scene/ImageryProvider.js +129 -111
- package/Source/Scene/Implicit3DTileContent.js +72 -23
- package/Source/Scene/ImplicitSubtree.js +66 -45
- package/Source/Scene/IonImageryProvider.js +471 -264
- package/Source/Scene/MapboxImageryProvider.js +272 -112
- package/Source/Scene/MapboxStyleImageryProvider.js +270 -111
- package/Source/Scene/MetadataSchemaLoader.js +26 -36
- package/Source/Scene/Model/B3dmLoader.js +42 -46
- package/Source/Scene/Model/GeoJsonLoader.js +8 -32
- package/Source/Scene/Model/I3dmLoader.js +48 -74
- package/Source/Scene/Model/Model.js +470 -132
- package/Source/Scene/Model/Model3DTileContent.js +83 -31
- package/Source/Scene/Model/ModelAnimationCollection.js +3 -3
- package/Source/Scene/Model/ModelDrawCommand.js +15 -26
- package/Source/Scene/Model/ModelUtility.js +16 -16
- package/Source/Scene/Model/PntsLoader.js +27 -32
- package/Source/Scene/Multiple3DTileContent.js +134 -115
- package/Source/Scene/PointCloud.js +11 -19
- package/Source/Scene/Primitive.js +20 -0
- package/Source/Scene/QuadtreePrimitive.js +2 -0
- package/Source/Scene/QuadtreeTileProvider.js +4 -8
- package/Source/Scene/ResourceCache.js +47 -105
- package/Source/Scene/ResourceCacheStatistics.js +24 -58
- package/Source/Scene/ResourceLoader.js +5 -17
- package/Source/Scene/ResourceLoaderState.js +12 -4
- package/Source/Scene/Scene.js +65 -0
- package/Source/Scene/ScreenSpaceCameraController.js +1 -1
- package/Source/Scene/SingleTileImageryProvider.js +382 -209
- package/Source/Scene/Terrain.js +196 -0
- package/Source/Scene/TileCoordinatesImageryProvider.js +267 -104
- package/Source/Scene/TileMapServiceImageryProvider.js +177 -85
- package/Source/Scene/Tileset3DTileContent.js +47 -5
- package/Source/Scene/TimeDynamicPointCloud.js +15 -2
- package/Source/Scene/UrlTemplateImageryProvider.js +343 -215
- package/Source/Scene/Vector3DTileClampedPolylines.js +96 -84
- package/Source/Scene/Vector3DTileContent.js +47 -22
- package/Source/Scene/Vector3DTileGeometry.js +57 -52
- package/Source/Scene/Vector3DTilePoints.js +72 -68
- package/Source/Scene/Vector3DTilePolygons.js +118 -117
- package/Source/Scene/Vector3DTilePolylines.js +86 -82
- package/Source/Scene/Vector3DTilePrimitive.js +0 -1
- package/Source/Scene/VoxelContent.js +61 -63
- package/Source/Scene/VoxelPrimitive.js +39 -91
- package/Source/Scene/VoxelProvider.js +2 -2
- package/Source/Scene/WebMapServiceImageryProvider.js +272 -111
- package/Source/Scene/WebMapTileServiceImageryProvider.js +270 -107
- package/Source/Scene/computeFlyToLocationForRectangle.js +33 -37
- package/Source/Scene/createOsmBuildings.js +6 -0
- package/Source/Scene/createOsmBuildingsAsync.js +82 -0
- package/Source/Scene/createWorldImagery.js +14 -5
- package/Source/Scene/createWorldImageryAsync.js +39 -0
- package/Source/Widget/CesiumWidget.js +55 -27
- package/index.d.ts +2158 -1395
- package/index.js +58 -51
- package/package.json +1 -1
|
@@ -87,7 +87,6 @@ function GltfBufferViewLoader(options) {
|
|
|
87
87
|
this._typedArray = undefined;
|
|
88
88
|
this._state = ResourceLoaderState.UNLOADED;
|
|
89
89
|
this._promise = undefined;
|
|
90
|
-
this._process = function (loader, frameState) {};
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
if (defined(Object.create)) {
|
|
@@ -96,20 +95,6 @@ if (defined(Object.create)) {
|
|
|
96
95
|
}
|
|
97
96
|
|
|
98
97
|
Object.defineProperties(GltfBufferViewLoader.prototype, {
|
|
99
|
-
/**
|
|
100
|
-
* A promise that resolves to the resource when the resource is ready, or undefined if the resource hasn't started loading.
|
|
101
|
-
*
|
|
102
|
-
* @memberof GltfBufferViewLoader.prototype
|
|
103
|
-
*
|
|
104
|
-
* @type {Promise<GltfBufferViewLoader>|undefined}
|
|
105
|
-
* @readonly
|
|
106
|
-
* @private
|
|
107
|
-
*/
|
|
108
|
-
promise: {
|
|
109
|
-
get: function () {
|
|
110
|
-
return this._promise;
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
98
|
/**
|
|
114
99
|
* The cache key of the resource.
|
|
115
100
|
*
|
|
@@ -140,31 +125,28 @@ Object.defineProperties(GltfBufferViewLoader.prototype, {
|
|
|
140
125
|
},
|
|
141
126
|
});
|
|
142
127
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
GltfBufferViewLoader.prototype.load = function () {
|
|
149
|
-
const bufferLoader = getBufferLoader(this);
|
|
150
|
-
this._bufferLoader = bufferLoader;
|
|
151
|
-
this._state = ResourceLoaderState.LOADING;
|
|
128
|
+
async function loadResources(loader) {
|
|
129
|
+
try {
|
|
130
|
+
const bufferLoader = getBufferLoader(loader);
|
|
131
|
+
loader._bufferLoader = bufferLoader;
|
|
132
|
+
await bufferLoader.load();
|
|
152
133
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
if (!loader._hasMeshopt) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
134
|
+
if (loader.isDestroyed()) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
159
137
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
138
|
+
const bufferTypedArray = bufferLoader.typedArray;
|
|
139
|
+
const bufferViewTypedArray = new Uint8Array(
|
|
140
|
+
bufferTypedArray.buffer,
|
|
141
|
+
bufferTypedArray.byteOffset + loader._byteOffset,
|
|
142
|
+
loader._byteLength
|
|
143
|
+
);
|
|
163
144
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
145
|
+
// Unload the buffer
|
|
146
|
+
loader.unload();
|
|
167
147
|
|
|
148
|
+
loader._typedArray = bufferViewTypedArray;
|
|
149
|
+
if (loader._hasMeshopt) {
|
|
168
150
|
const count = loader._meshoptCount;
|
|
169
151
|
const byteStride = loader._meshoptByteStride;
|
|
170
152
|
const result = new Uint8Array(count * byteStride);
|
|
@@ -176,47 +158,35 @@ GltfBufferViewLoader.prototype.load = function () {
|
|
|
176
158
|
loader._meshoptMode,
|
|
177
159
|
loader._meshoptFilter
|
|
178
160
|
);
|
|
179
|
-
|
|
180
161
|
loader._typedArray = result;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
);
|
|
197
|
-
|
|
198
|
-
// Unload the buffer
|
|
199
|
-
that.unload();
|
|
200
|
-
|
|
201
|
-
that._typedArray = bufferViewTypedArray;
|
|
202
|
-
if (that._hasMeshopt) {
|
|
203
|
-
that._state = ResourceLoaderState.PROCESSING;
|
|
204
|
-
return bufferViewPromise;
|
|
205
|
-
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
loader._state = ResourceLoaderState.READY;
|
|
165
|
+
return loader;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
if (loader.isDestroyed()) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
loader.unload();
|
|
172
|
+
loader._state = ResourceLoaderState.FAILED;
|
|
173
|
+
const errorMessage = "Failed to load buffer view";
|
|
174
|
+
throw loader.getError(errorMessage, error);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
206
177
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const errorMessage = "Failed to load buffer view";
|
|
217
|
-
return Promise.reject(that.getError(errorMessage, error));
|
|
218
|
-
});
|
|
178
|
+
/**
|
|
179
|
+
* Loads the resource.
|
|
180
|
+
* @returns {Promise<GltfBufferViewLoader>} A promise which resolves to the loader when the resource loading is completed.
|
|
181
|
+
* @private
|
|
182
|
+
*/
|
|
183
|
+
GltfBufferViewLoader.prototype.load = async function () {
|
|
184
|
+
if (defined(this._promise)) {
|
|
185
|
+
return this._promise;
|
|
186
|
+
}
|
|
219
187
|
|
|
188
|
+
this._state = ResourceLoaderState.LOADING;
|
|
189
|
+
this._promise = loadResources(this);
|
|
220
190
|
return this._promise;
|
|
221
191
|
};
|
|
222
192
|
|
|
@@ -228,36 +198,22 @@ function getBufferLoader(bufferViewLoader) {
|
|
|
228
198
|
const resource = baseResource.getDerivedResource({
|
|
229
199
|
url: buffer.uri,
|
|
230
200
|
});
|
|
231
|
-
return resourceCache.
|
|
201
|
+
return resourceCache.getExternalBufferLoader({
|
|
232
202
|
resource: resource,
|
|
233
203
|
});
|
|
234
204
|
}
|
|
235
|
-
return resourceCache.
|
|
205
|
+
return resourceCache.getEmbeddedBufferLoader({
|
|
236
206
|
parentResource: bufferViewLoader._gltfResource,
|
|
237
207
|
bufferId: bufferViewLoader._bufferId,
|
|
238
208
|
});
|
|
239
209
|
}
|
|
240
210
|
|
|
241
|
-
/**
|
|
242
|
-
* Processes the resources. For a BufferView that does not have the EXT_meshopt_compression extension, there
|
|
243
|
-
* is no processing that needs to happen, so this function returns immediately.
|
|
244
|
-
*
|
|
245
|
-
* @param {FrameState} frameState The frame state.
|
|
246
|
-
*/
|
|
247
|
-
GltfBufferViewLoader.prototype.process = function (frameState) {
|
|
248
|
-
//>>includeStart('debug', pragmas.debug);
|
|
249
|
-
Check.typeOf.object("frameState", frameState);
|
|
250
|
-
//>>includeEnd('debug');
|
|
251
|
-
|
|
252
|
-
return this._process(this, frameState);
|
|
253
|
-
};
|
|
254
|
-
|
|
255
211
|
/**
|
|
256
212
|
* Unloads the resource.
|
|
257
213
|
* @private
|
|
258
214
|
*/
|
|
259
215
|
GltfBufferViewLoader.prototype.unload = function () {
|
|
260
|
-
if (defined(this._bufferLoader)) {
|
|
216
|
+
if (defined(this._bufferLoader) && !this._bufferLoader.isDestroyed()) {
|
|
261
217
|
this._resourceCache.unload(this._bufferLoader);
|
|
262
218
|
}
|
|
263
219
|
|
|
@@ -54,7 +54,7 @@ function GltfDracoLoader(options) {
|
|
|
54
54
|
this._decodedData = undefined;
|
|
55
55
|
this._state = ResourceLoaderState.UNLOADED;
|
|
56
56
|
this._promise = undefined;
|
|
57
|
-
this.
|
|
57
|
+
this._dracoError = undefined;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
if (defined(Object.create)) {
|
|
@@ -63,20 +63,6 @@ if (defined(Object.create)) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
Object.defineProperties(GltfDracoLoader.prototype, {
|
|
66
|
-
/**
|
|
67
|
-
* A promise that resolves to the resource when the resource is ready.
|
|
68
|
-
*
|
|
69
|
-
* @memberof GltfDracoLoader.prototype
|
|
70
|
-
*
|
|
71
|
-
* @type {Promise<GltfDracoLoader>}
|
|
72
|
-
* @readonly
|
|
73
|
-
* @private
|
|
74
|
-
*/
|
|
75
|
-
promise: {
|
|
76
|
-
get: function () {
|
|
77
|
-
return this._promise;
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
66
|
/**
|
|
81
67
|
* The cache key of the resource.
|
|
82
68
|
*
|
|
@@ -107,107 +93,46 @@ Object.defineProperties(GltfDracoLoader.prototype, {
|
|
|
107
93
|
},
|
|
108
94
|
});
|
|
109
95
|
|
|
96
|
+
async function loadResources(loader) {
|
|
97
|
+
const resourceCache = loader._resourceCache;
|
|
98
|
+
try {
|
|
99
|
+
const bufferViewLoader = resourceCache.getBufferViewLoader({
|
|
100
|
+
gltf: loader._gltf,
|
|
101
|
+
bufferViewId: loader._draco.bufferView,
|
|
102
|
+
gltfResource: loader._gltfResource,
|
|
103
|
+
baseResource: loader._baseResource,
|
|
104
|
+
});
|
|
105
|
+
loader._bufferViewLoader = bufferViewLoader;
|
|
106
|
+
await bufferViewLoader.load();
|
|
107
|
+
|
|
108
|
+
if (loader.isDestroyed()) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
loader._bufferViewTypedArray = bufferViewLoader.typedArray;
|
|
113
|
+
loader._state = ResourceLoaderState.PROCESSING;
|
|
114
|
+
return loader;
|
|
115
|
+
} catch (error) {
|
|
116
|
+
if (loader.isDestroyed()) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
handleError(loader, error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
110
124
|
/**
|
|
111
125
|
* Loads the resource.
|
|
112
126
|
* @returns {Promise<GltfDracoLoader>} A promise which resolves to the loader when the resource loading is completed.
|
|
113
127
|
* @private
|
|
114
128
|
*/
|
|
115
|
-
GltfDracoLoader.prototype.load = function () {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
bufferViewId: this._draco.bufferView,
|
|
120
|
-
gltfResource: this._gltfResource,
|
|
121
|
-
baseResource: this._baseResource,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
this._bufferViewLoader = bufferViewLoader;
|
|
125
|
-
this._state = ResourceLoaderState.LOADING;
|
|
126
|
-
const that = this;
|
|
127
|
-
const dracoPromise = new Promise(function (resolve, reject) {
|
|
128
|
-
that._process = function (loader, frameState) {
|
|
129
|
-
if (!defined(loader._bufferViewTypedArray)) {
|
|
130
|
-
// Not ready to decode the Draco buffer
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (defined(loader._decodePromise)) {
|
|
135
|
-
// Currently decoding
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const draco = loader._draco;
|
|
140
|
-
const gltf = loader._gltf;
|
|
141
|
-
const bufferViews = gltf.bufferViews;
|
|
142
|
-
const bufferViewId = draco.bufferView;
|
|
143
|
-
const bufferView = bufferViews[bufferViewId];
|
|
144
|
-
const compressedAttributes = draco.attributes;
|
|
145
|
-
|
|
146
|
-
const decodeOptions = {
|
|
147
|
-
// Need to make a copy of the typed array otherwise the underlying
|
|
148
|
-
// ArrayBuffer may be accessed on both the worker and the main thread. This
|
|
149
|
-
// leads to errors such as "ArrayBuffer at index 0 is already detached".
|
|
150
|
-
// PERFORMANCE_IDEA: Look into SharedArrayBuffer to get around this.
|
|
151
|
-
array: new Uint8Array(loader._bufferViewTypedArray),
|
|
152
|
-
bufferView: bufferView,
|
|
153
|
-
compressedAttributes: compressedAttributes,
|
|
154
|
-
dequantizeInShader: true,
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const decodePromise = DracoLoader.decodeBufferView(decodeOptions);
|
|
158
|
-
|
|
159
|
-
if (!defined(decodePromise)) {
|
|
160
|
-
// Cannot schedule task this frame
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
loader._decodePromise = decodePromise
|
|
165
|
-
.then(function (results) {
|
|
166
|
-
if (loader.isDestroyed()) {
|
|
167
|
-
resolve();
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Unload everything except the decoded data
|
|
172
|
-
loader.unload();
|
|
173
|
-
|
|
174
|
-
loader._decodedData = {
|
|
175
|
-
indices: results.indexArray,
|
|
176
|
-
vertexAttributes: results.attributeData,
|
|
177
|
-
};
|
|
178
|
-
loader._state = ResourceLoaderState.READY;
|
|
179
|
-
resolve(loader);
|
|
180
|
-
})
|
|
181
|
-
.catch(function (e) {
|
|
182
|
-
if (loader.isDestroyed()) {
|
|
183
|
-
resolve();
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
reject(e);
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
this._promise = bufferViewLoader.promise
|
|
193
|
-
.then(function () {
|
|
194
|
-
if (that.isDestroyed()) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
// Now wait for process() to run to finish loading
|
|
198
|
-
that._bufferViewTypedArray = bufferViewLoader.typedArray;
|
|
199
|
-
that._state = ResourceLoaderState.PROCESSING;
|
|
200
|
-
|
|
201
|
-
return dracoPromise;
|
|
202
|
-
})
|
|
203
|
-
.catch(function (error) {
|
|
204
|
-
if (that.isDestroyed()) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return handleError(that, error);
|
|
209
|
-
});
|
|
129
|
+
GltfDracoLoader.prototype.load = async function () {
|
|
130
|
+
if (defined(this._promise)) {
|
|
131
|
+
return this._promise;
|
|
132
|
+
}
|
|
210
133
|
|
|
134
|
+
this._state = ResourceLoaderState.LOADING;
|
|
135
|
+
this._promise = loadResources(this);
|
|
211
136
|
return this._promise;
|
|
212
137
|
};
|
|
213
138
|
|
|
@@ -215,7 +140,33 @@ function handleError(dracoLoader, error) {
|
|
|
215
140
|
dracoLoader.unload();
|
|
216
141
|
dracoLoader._state = ResourceLoaderState.FAILED;
|
|
217
142
|
const errorMessage = "Failed to load Draco";
|
|
218
|
-
|
|
143
|
+
throw dracoLoader.getError(errorMessage, error);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function processDecode(loader, decodePromise) {
|
|
147
|
+
try {
|
|
148
|
+
const results = await decodePromise;
|
|
149
|
+
if (loader.isDestroyed()) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Unload everything except the decoded data
|
|
154
|
+
loader.unload();
|
|
155
|
+
|
|
156
|
+
loader._decodedData = {
|
|
157
|
+
indices: results.indexArray,
|
|
158
|
+
vertexAttributes: results.attributeData,
|
|
159
|
+
};
|
|
160
|
+
loader._state = ResourceLoaderState.READY;
|
|
161
|
+
return loader._baseResource;
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (loader.isDestroyed()) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Capture this error so it can be thrown on the next `process` call
|
|
168
|
+
loader._dracoError = error;
|
|
169
|
+
}
|
|
219
170
|
}
|
|
220
171
|
|
|
221
172
|
/**
|
|
@@ -229,7 +180,54 @@ GltfDracoLoader.prototype.process = function (frameState) {
|
|
|
229
180
|
Check.typeOf.object("frameState", frameState);
|
|
230
181
|
//>>includeEnd('debug');
|
|
231
182
|
|
|
232
|
-
|
|
183
|
+
if (this._state === ResourceLoaderState.READY) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (this._state !== ResourceLoaderState.PROCESSING) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (defined(this._dracoError)) {
|
|
192
|
+
handleError(this, this._dracoError);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (!defined(this._bufferViewTypedArray)) {
|
|
196
|
+
// Not ready to decode the Draco buffer
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (defined(this._decodePromise)) {
|
|
201
|
+
// Currently decoding
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const draco = this._draco;
|
|
206
|
+
const gltf = this._gltf;
|
|
207
|
+
const bufferViews = gltf.bufferViews;
|
|
208
|
+
const bufferViewId = draco.bufferView;
|
|
209
|
+
const bufferView = bufferViews[bufferViewId];
|
|
210
|
+
const compressedAttributes = draco.attributes;
|
|
211
|
+
|
|
212
|
+
const decodeOptions = {
|
|
213
|
+
// Need to make a copy of the typed array otherwise the underlying
|
|
214
|
+
// ArrayBuffer may be accessed on both the worker and the main thread. This
|
|
215
|
+
// leads to errors such as "ArrayBuffer at index 0 is already detached".
|
|
216
|
+
// PERFORMANCE_IDEA: Look into SharedArrayBuffer to get around this.
|
|
217
|
+
array: new Uint8Array(this._bufferViewTypedArray),
|
|
218
|
+
bufferView: bufferView,
|
|
219
|
+
compressedAttributes: compressedAttributes,
|
|
220
|
+
dequantizeInShader: true,
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const decodePromise = DracoLoader.decodeBufferView(decodeOptions);
|
|
224
|
+
|
|
225
|
+
if (!defined(decodePromise)) {
|
|
226
|
+
// Cannot schedule task this frame
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
this._decodePromise = processDecode(this, decodePromise);
|
|
233
231
|
};
|
|
234
232
|
|
|
235
233
|
/**
|
|
@@ -68,20 +68,6 @@ if (defined(Object.create)) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
Object.defineProperties(GltfImageLoader.prototype, {
|
|
71
|
-
/**
|
|
72
|
-
* A promise that resolves to the resource when the resource is ready, or undefined if the resource hasn't started loading.
|
|
73
|
-
*
|
|
74
|
-
* @memberof GltfImageLoader.prototype
|
|
75
|
-
*
|
|
76
|
-
* @type {Promise<GltfImageLoader>|undefined}
|
|
77
|
-
* @readonly
|
|
78
|
-
* @private
|
|
79
|
-
*/
|
|
80
|
-
promise: {
|
|
81
|
-
get: function () {
|
|
82
|
-
return this._promise;
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
71
|
/**
|
|
86
72
|
* The cache key of the resource.
|
|
87
73
|
*
|
|
@@ -132,6 +118,10 @@ Object.defineProperties(GltfImageLoader.prototype, {
|
|
|
132
118
|
* @private
|
|
133
119
|
*/
|
|
134
120
|
GltfImageLoader.prototype.load = function () {
|
|
121
|
+
if (defined(this._promise)) {
|
|
122
|
+
return this._promise;
|
|
123
|
+
}
|
|
124
|
+
|
|
135
125
|
if (defined(this._bufferViewId)) {
|
|
136
126
|
this._promise = loadFromBufferView(this);
|
|
137
127
|
return this._promise;
|
|
@@ -158,78 +148,78 @@ function getImageAndMipLevels(image) {
|
|
|
158
148
|
};
|
|
159
149
|
}
|
|
160
150
|
|
|
161
|
-
function loadFromBufferView(imageLoader) {
|
|
151
|
+
async function loadFromBufferView(imageLoader) {
|
|
152
|
+
imageLoader._state = ResourceLoaderState.LOADING;
|
|
162
153
|
const resourceCache = imageLoader._resourceCache;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
154
|
+
try {
|
|
155
|
+
const bufferViewLoader = resourceCache.getBufferViewLoader({
|
|
156
|
+
gltf: imageLoader._gltf,
|
|
157
|
+
bufferViewId: imageLoader._bufferViewId,
|
|
158
|
+
gltfResource: imageLoader._gltfResource,
|
|
159
|
+
baseResource: imageLoader._baseResource,
|
|
160
|
+
});
|
|
161
|
+
imageLoader._bufferViewLoader = bufferViewLoader;
|
|
162
|
+
await bufferViewLoader.load();
|
|
169
163
|
|
|
170
|
-
|
|
171
|
-
|
|
164
|
+
if (imageLoader.isDestroyed()) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
172
167
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
.catch(function (error) {
|
|
197
|
-
if (imageLoader.isDestroyed()) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
return handleError(imageLoader, error, "Failed to load embedded image");
|
|
201
|
-
});
|
|
168
|
+
const typedArray = bufferViewLoader.typedArray;
|
|
169
|
+
const image = await loadImageFromBufferTypedArray(typedArray);
|
|
170
|
+
if (imageLoader.isDestroyed()) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const imageAndMipLevels = getImageAndMipLevels(image);
|
|
175
|
+
|
|
176
|
+
// Unload everything except the image
|
|
177
|
+
imageLoader.unload();
|
|
178
|
+
|
|
179
|
+
imageLoader._image = imageAndMipLevels.image;
|
|
180
|
+
imageLoader._mipLevels = imageAndMipLevels.mipLevels;
|
|
181
|
+
imageLoader._state = ResourceLoaderState.READY;
|
|
182
|
+
|
|
183
|
+
return imageLoader;
|
|
184
|
+
} catch (error) {
|
|
185
|
+
if (imageLoader.isDestroyed()) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return handleError(imageLoader, error, "Failed to load embedded image");
|
|
190
|
+
}
|
|
202
191
|
}
|
|
203
192
|
|
|
204
|
-
function loadFromUri(imageLoader) {
|
|
193
|
+
async function loadFromUri(imageLoader) {
|
|
194
|
+
imageLoader._state = ResourceLoaderState.LOADING;
|
|
205
195
|
const baseResource = imageLoader._baseResource;
|
|
206
196
|
const uri = imageLoader._uri;
|
|
207
197
|
const resource = baseResource.getDerivedResource({
|
|
208
198
|
url: uri,
|
|
209
199
|
});
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
200
|
+
|
|
201
|
+
try {
|
|
202
|
+
const image = await loadImageFromUri(resource);
|
|
203
|
+
if (imageLoader.isDestroyed()) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const imageAndMipLevels = getImageAndMipLevels(image);
|
|
208
|
+
|
|
209
|
+
// Unload everything except the image
|
|
210
|
+
imageLoader.unload();
|
|
211
|
+
|
|
212
|
+
imageLoader._image = imageAndMipLevels.image;
|
|
213
|
+
imageLoader._mipLevels = imageAndMipLevels.mipLevels;
|
|
214
|
+
imageLoader._state = ResourceLoaderState.READY;
|
|
215
|
+
|
|
216
|
+
return imageLoader;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (imageLoader.isDestroyed()) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
return handleError(imageLoader, error, `Failed to load image: ${uri}`);
|
|
222
|
+
}
|
|
233
223
|
}
|
|
234
224
|
|
|
235
225
|
function handleError(imageLoader, error, errorMessage) {
|
|
@@ -269,7 +259,7 @@ function getMimeTypeFromTypedArray(typedArray) {
|
|
|
269
259
|
throw new RuntimeError("Image format is not recognized");
|
|
270
260
|
}
|
|
271
261
|
|
|
272
|
-
function loadImageFromBufferTypedArray(typedArray) {
|
|
262
|
+
async function loadImageFromBufferTypedArray(typedArray) {
|
|
273
263
|
const mimeType = getMimeTypeFromTypedArray(typedArray);
|
|
274
264
|
if (mimeType === "image/ktx2") {
|
|
275
265
|
// Need to make a copy of the embedded KTX2 buffer otherwise the underlying
|
|
@@ -310,7 +300,10 @@ function loadImageFromUri(resource) {
|
|
|
310
300
|
* @private
|
|
311
301
|
*/
|
|
312
302
|
GltfImageLoader.prototype.unload = function () {
|
|
313
|
-
if (
|
|
303
|
+
if (
|
|
304
|
+
defined(this._bufferViewLoader) &&
|
|
305
|
+
!this._bufferViewLoader.isDestroyed()
|
|
306
|
+
) {
|
|
314
307
|
this._resourceCache.unload(this._bufferViewLoader);
|
|
315
308
|
}
|
|
316
309
|
|