Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | 102x 102x 102x 101x 100x 99x 98x 97x 1x 96x 96x 96x 96x 96x 96x 96x 96x 96x 96x 96x 96x 96x 96x 96x 96x 96x 1x 1x 1x 1x 98x 96x 96x 96x 96x 96x 93x 2x 91x 91x 91x 3x 3x 3x 3x 3x 1x 96x 96x 96x 96x 93x 235x 235x 235x 235x 235x 235x 235x 235x 8x 235x 63x 6x 13x 13x 13x 13x 13x 13x 13x 13x 13x 4x 92x 92x 92x 65x 93x 93x 92x 4x 4x 4x 4x 6x 6x 6x 6x 6x 4x 96x 92x 4x 96x 96x 323x 323x 323x 323x 323x 96x 92x 92x 92x 24x 32x 32x 32x 32x 92x 32x 48x 48x 48x 4x 4x 4x 1x 1x 1x 1x 1x 1x 4x 1x 1x 1x 1x 1x 96x 92x 4x 96x 96x 96x 96x 96x 96x 96x 96x 33x 33x 33x 33x 33x 96x 96x 96x 20x 20x 76x 96x 96x 95x 93x 1x 251x 251x 3x 248x 157x 91x 91x 91x 91x 23x 23x 23x 91x 91x 91x 91x 293x 293x 293x 293x 293x 91x 91x 23x 23x 23x 23x 91x 87x 4x 91x 91x 91x 170x 170x 170x 323x 170x 170x 79x 79x 79x 29x 79x 79x 1x 79x 79x 79x 79x 79x 79x | import Check from "../Core/Check.js";
import Frozen from "../Core/Frozen.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import parseStructuralMetadata from "./parseStructuralMetadata.js";
import parseFeatureMetadataLegacy from "./parseFeatureMetadataLegacy.js";
import ResourceCache from "./ResourceCache.js";
import ResourceLoader from "./ResourceLoader.js";
import ResourceLoaderState from "./ResourceLoaderState.js";
/**
* Loads glTF structural metadata
* <p>
* Implements the {@link ResourceLoader} interface.
* </p>
*
* @alias GltfStructuralMetadataLoader
* @constructor
* @augments ResourceLoader
*
* @param {object} options Object with the following properties:
* @param {object} options.gltf The glTF JSON.
* @param {string} [options.extension] The <code>EXT_structural_metadata</code> extension object. If this is undefined, then extensionLegacy must be defined.
* @param {string} [options.extensionLegacy] The legacy <code>EXT_feature_metadata</code> extension for backwards compatibility.
* @param {Resource} options.gltfResource The {@link Resource} containing the glTF.
* @param {Resource} options.baseResource The {@link Resource} that paths in the glTF JSON are relative to.
* @param {SupportedImageFormats} options.supportedImageFormats The supported image formats.
* @param {FrameState} options.frameState The frame state.
* @param {string} [options.cacheKey] The cache key of the resource.
* @param {boolean} [options.asynchronous=true] Determines if WebGL resource creation will be spread out over several frames or block until all WebGL resources are created.
*
* @private
* @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.
*/
function GltfStructuralMetadataLoader(options) {
options = options ?? Frozen.EMPTY_OBJECT;
const {
gltf,
extension,
extensionLegacy,
gltfResource,
baseResource,
supportedImageFormats,
frameState,
cacheKey,
asynchronous = true,
} = options;
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object("options.gltf", gltf);
Check.typeOf.object("options.gltfResource", gltfResource);
Check.typeOf.object("options.baseResource", baseResource);
Check.typeOf.object("options.supportedImageFormats", supportedImageFormats);
Check.typeOf.object("options.frameState", frameState);
if (!defined(options.extension) && !defined(options.extensionLegacy)) {
throw new DeveloperError(
"One of options.extension or options.extensionLegacy must be specified",
);
}
//>>includeEnd('debug');
this._gltfResource = gltfResource;
this._baseResource = baseResource;
this._gltf = gltf;
this._extension = extension;
this._extensionLegacy = extensionLegacy;
this._supportedImageFormats = supportedImageFormats;
this._frameState = frameState;
this._cacheKey = cacheKey;
this._asynchronous = asynchronous;
this._bufferViewLoaders = [];
this._bufferViewIds = [];
this._textureLoaders = [];
this._textureIds = [];
this._schemaLoader = undefined;
this._structuralMetadata = undefined;
this._state = ResourceLoaderState.UNLOADED;
this._promise = undefined;
}
Eif (defined(Object.create)) {
GltfStructuralMetadataLoader.prototype = Object.create(
ResourceLoader.prototype,
);
GltfStructuralMetadataLoader.prototype.constructor =
GltfStructuralMetadataLoader;
}
Object.defineProperties(GltfStructuralMetadataLoader.prototype, {
/**
* The cache key of the resource.
*
* @memberof GltfStructuralMetadataLoader.prototype
*
* @type {string}
* @readonly
* @private
*/
cacheKey: {
get: function () {
return this._cacheKey;
},
},
/**
* The parsed structural metadata
*
* @memberof GltfStructuralMetadataLoader.prototype
*
* @type {StructuralMetadata}
* @readonly
* @private
*/
structuralMetadata: {
get: function () {
return this._structuralMetadata;
},
},
});
async function loadResources(loader) {
try {
const bufferViewsPromise = loadBufferViews(loader);
const texturesPromise = loadTextures(loader);
const schemaPromise = loadSchema(loader);
await Promise.all([bufferViewsPromise, texturesPromise, schemaPromise]);
if (loader.isDestroyed()) {
return;
}
loader._gltf = undefined; // No longer need to hold onto the glTF
loader._state = ResourceLoaderState.LOADED;
return loader;
} catch (error) {
Iif (loader.isDestroyed()) {
return;
}
loader.unload();
loader._state = ResourceLoaderState.FAILED;
const errorMessage = "Failed to load structural metadata";
throw loader.getError(errorMessage, error);
}
}
/**
* Loads the resource.
* @returns {Promise<GltfStructuralMetadataLoader>} A promise which resolves to the loader when the resource loading is completed.
* @private
*/
GltfStructuralMetadataLoader.prototype.load = function () {
Iif (defined(this._promise)) {
return this._promise;
}
this._state = ResourceLoaderState.LOADING;
this._promise = loadResources(this);
return this._promise;
};
function gatherBufferViewIdsFromProperties(properties, bufferViewIdSet) {
for (const propertyId in properties) {
Eif (properties.hasOwnProperty(propertyId)) {
const property = properties[propertyId];
const values = property.values;
const arrayOffsets = property.arrayOffsets;
const stringOffsets = property.stringOffsets;
// Using an object like a mathematical set
Eif (defined(values)) {
bufferViewIdSet[values] = true;
}
if (defined(arrayOffsets)) {
bufferViewIdSet[arrayOffsets] = true;
}
if (defined(stringOffsets)) {
bufferViewIdSet[stringOffsets] = true;
}
}
}
}
function gatherBufferViewIdsFromPropertiesLegacy(properties, bufferViewIdSet) {
for (const propertyId in properties) {
Eif (properties.hasOwnProperty(propertyId)) {
const property = properties[propertyId];
const bufferView = property.bufferView;
const arrayOffsetBufferView = property.arrayOffsetBufferView;
const stringOffsetBufferView = property.stringOffsetBufferView;
// Using an object like a mathematical set
Eif (defined(bufferView)) {
bufferViewIdSet[bufferView] = true;
}
Iif (defined(arrayOffsetBufferView)) {
bufferViewIdSet[arrayOffsetBufferView] = true;
}
if (defined(stringOffsetBufferView)) {
bufferViewIdSet[stringOffsetBufferView] = true;
}
}
}
}
function gatherUsedBufferViewIds(extension) {
const propertyTables = extension.propertyTables;
const bufferViewIdSet = {};
if (defined(propertyTables)) {
for (let i = 0; i < propertyTables.length; i++) {
const propertyTable = propertyTables[i];
gatherBufferViewIdsFromProperties(
propertyTable.properties,
bufferViewIdSet,
);
}
}
return bufferViewIdSet;
}
function gatherUsedBufferViewIdsLegacy(extensionLegacy) {
const featureTables = extensionLegacy.featureTables;
const bufferViewIdSet = {};
Eif (defined(featureTables)) {
for (const featureTableId in featureTables) {
Eif (featureTables.hasOwnProperty(featureTableId)) {
const featureTable = featureTables[featureTableId];
const properties = featureTable.properties;
Eif (defined(properties)) {
gatherBufferViewIdsFromPropertiesLegacy(properties, bufferViewIdSet);
}
}
}
}
return bufferViewIdSet;
}
async function loadBufferViews(structuralMetadataLoader) {
let bufferViewIds;
if (defined(structuralMetadataLoader._extension)) {
bufferViewIds = gatherUsedBufferViewIds(
structuralMetadataLoader._extension,
);
} else {
bufferViewIds = gatherUsedBufferViewIdsLegacy(
structuralMetadataLoader._extensionLegacy,
);
}
// Load the buffer views
const bufferViewPromises = [];
for (const bufferViewId in bufferViewIds) {
Eif (bufferViewIds.hasOwnProperty(bufferViewId)) {
const bufferViewLoader = ResourceCache.getBufferViewLoader({
gltf: structuralMetadataLoader._gltf,
bufferViewId: parseInt(bufferViewId),
gltfResource: structuralMetadataLoader._gltfResource,
baseResource: structuralMetadataLoader._baseResource,
});
structuralMetadataLoader._bufferViewLoaders.push(bufferViewLoader);
structuralMetadataLoader._bufferViewIds.push(bufferViewId);
bufferViewPromises.push(bufferViewLoader.load());
}
}
return Promise.all(bufferViewPromises);
}
function gatherUsedTextureIds(structuralMetadataExtension) {
// Gather the used textures
const textureIds = {};
const propertyTextures = structuralMetadataExtension.propertyTextures;
if (defined(propertyTextures)) {
for (let i = 0; i < propertyTextures.length; i++) {
const propertyTexture = propertyTextures[i];
const properties = propertyTexture.properties;
Eif (defined(properties)) {
gatherTextureIdsFromProperties(properties, textureIds);
}
}
}
return textureIds;
}
function gatherTextureIdsFromProperties(properties, textureIds) {
for (const propertyId in properties) {
Eif (properties.hasOwnProperty(propertyId)) {
// in EXT_structural_metadata the property is a valid textureInfo.
const textureInfo = properties[propertyId];
textureIds[textureInfo.index] = textureInfo;
}
}
}
function gatherUsedTextureIdsLegacy(extensionLegacy) {
// Gather the used textures
const textureIds = {};
const featureTextures = extensionLegacy.featureTextures;
if (defined(featureTextures)) {
for (const featureTextureId in featureTextures) {
Eif (featureTextures.hasOwnProperty(featureTextureId)) {
const featureTexture = featureTextures[featureTextureId];
const properties = featureTexture.properties;
Eif (defined(properties)) {
gatherTextureIdsFromPropertiesLegacy(properties, textureIds);
}
}
}
}
return textureIds;
}
function gatherTextureIdsFromPropertiesLegacy(properties, textureIds) {
for (const propertyId in properties) {
Eif (properties.hasOwnProperty(propertyId)) {
const property = properties[propertyId];
const textureInfo = property.texture;
textureIds[textureInfo.index] = textureInfo;
}
}
}
function loadTextures(structuralMetadataLoader) {
let textureIds;
if (defined(structuralMetadataLoader._extension)) {
textureIds = gatherUsedTextureIds(structuralMetadataLoader._extension);
} else {
textureIds = gatherUsedTextureIdsLegacy(
structuralMetadataLoader._extensionLegacy,
);
}
const gltf = structuralMetadataLoader._gltf;
const gltfResource = structuralMetadataLoader._gltfResource;
const baseResource = structuralMetadataLoader._baseResource;
const supportedImageFormats = structuralMetadataLoader._supportedImageFormats;
const frameState = structuralMetadataLoader._frameState;
const asynchronous = structuralMetadataLoader._asynchronous;
// Load the textures
const texturePromises = [];
for (const textureId in textureIds) {
Eif (textureIds.hasOwnProperty(textureId)) {
const textureLoader = ResourceCache.getTextureLoader({
gltf: gltf,
textureInfo: textureIds[textureId],
gltfResource: gltfResource,
baseResource: baseResource,
supportedImageFormats: supportedImageFormats,
frameState: frameState,
asynchronous: asynchronous,
});
structuralMetadataLoader._textureLoaders.push(textureLoader);
structuralMetadataLoader._textureIds.push(textureId);
texturePromises.push(textureLoader.load());
}
}
return Promise.all(texturePromises);
}
async function loadSchema(structuralMetadataLoader) {
const extension =
structuralMetadataLoader._extension ??
structuralMetadataLoader._extensionLegacy;
let schemaLoader;
if (defined(extension.schemaUri)) {
const resource = structuralMetadataLoader._baseResource.getDerivedResource({
url: extension.schemaUri,
});
schemaLoader = ResourceCache.getSchemaLoader({
resource: resource,
});
} else {
schemaLoader = ResourceCache.getSchemaLoader({
schema: extension.schema,
});
}
structuralMetadataLoader._schemaLoader = schemaLoader;
await schemaLoader.load();
if (!schemaLoader.isDestroyed()) {
return schemaLoader.schema;
}
}
/**
* Processes the resource until it becomes ready.
*
* @param {FrameState} frameState The frame state.
* @private
*/
GltfStructuralMetadataLoader.prototype.process = function (frameState) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object("frameState", frameState);
//>>includeEnd('debug');
if (this._state === ResourceLoaderState.READY) {
return true;
}
if (this._state !== ResourceLoaderState.LOADED) {
return false;
}
const textureLoaders = this._textureLoaders;
const textureLoadersLength = textureLoaders.length;
let ready = true;
for (let i = 0; i < textureLoadersLength; ++i) {
const textureLoader = textureLoaders[i];
const textureReady = textureLoader.process(frameState);
ready = ready && textureReady;
}
Iif (!ready) {
return false;
}
const schema = this._schemaLoader.schema;
const bufferViews = {};
for (let i = 0; i < this._bufferViewIds.length; ++i) {
const bufferViewId = this._bufferViewIds[i];
const bufferViewLoader = this._bufferViewLoaders[i];
Eif (!bufferViewLoader.isDestroyed()) {
// Copy the typed array and let the underlying ArrayBuffer be freed
const bufferViewTypedArray = new Uint8Array(bufferViewLoader.typedArray);
bufferViews[bufferViewId] = bufferViewTypedArray;
}
}
const textures = {};
for (let i = 0; i < this._textureIds.length; ++i) {
const textureId = this._textureIds[i];
const textureLoader = textureLoaders[i];
Eif (!textureLoader.isDestroyed()) {
textures[textureId] = textureLoader.texture;
}
}
if (defined(this._extension)) {
this._structuralMetadata = parseStructuralMetadata({
extension: this._extension,
schema: schema,
bufferViews: bufferViews,
textures: textures,
});
} else {
this._structuralMetadata = parseFeatureMetadataLegacy({
extension: this._extensionLegacy,
schema: schema,
bufferViews: bufferViews,
textures: textures,
});
}
// Buffer views can be unloaded after the data has been copied
unloadBufferViews(this);
this._state = ResourceLoaderState.READY;
return true;
};
function unloadBufferViews(structuralMetadataLoader) {
const bufferViewLoaders = structuralMetadataLoader._bufferViewLoaders;
const bufferViewLoadersLength = bufferViewLoaders.length;
for (let i = 0; i < bufferViewLoadersLength; ++i) {
ResourceCache.unload(bufferViewLoaders[i]);
}
structuralMetadataLoader._bufferViewLoaders.length = 0;
structuralMetadataLoader._bufferViewIds.length = 0;
}
function unloadTextures(structuralMetadataLoader) {
const textureLoaders = structuralMetadataLoader._textureLoaders;
const textureLoadersLength = textureLoaders.length;
for (let i = 0; i < textureLoadersLength; ++i) {
ResourceCache.unload(textureLoaders[i]);
}
structuralMetadataLoader._textureLoaders.length = 0;
structuralMetadataLoader._textureIds.length = 0;
}
/**
* Unloads the resource.
* @private
*/
GltfStructuralMetadataLoader.prototype.unload = function () {
unloadBufferViews(this);
unloadTextures(this);
Eif (defined(this._schemaLoader)) {
ResourceCache.unload(this._schemaLoader);
}
this._schemaLoader = undefined;
this._structuralMetadata = undefined;
};
export default GltfStructuralMetadataLoader;
|