import Axis from "../Axis.js"; import B3dmParser from "../B3dmParser.js"; import Cartesian3 from "../../Core/Cartesian3.js"; import Cesium3DTileFeatureTable from "../Cesium3DTileFeatureTable.js"; import Check from "../../Core/Check.js"; import ComponentDatatype from "../../Core/ComponentDatatype.js"; import defaultValue from "../../Core/defaultValue.js"; import defined from "../../Core/defined.js"; import StructuralMetadata from "../StructuralMetadata.js"; import GltfLoader from "../GltfLoader.js"; import Matrix4 from "../../Core/Matrix4.js"; import MetadataClass from "../MetadataClass.js"; import ModelComponents from "../ModelComponents.js"; import ModelUtility from "./ModelUtility.js"; import parseBatchTable from "../parseBatchTable.js"; import PropertyTable from "../PropertyTable.js"; import ResourceLoader from "../ResourceLoader.js"; import VertexAttributeSemantic from "../VertexAttributeSemantic.js"; const B3dmLoaderState = { UNLOADED: 0, LOADING: 1, PROCESSING: 2, READY: 3, FAILED: 4, }; const FeatureIdAttribute = ModelComponents.FeatureIdAttribute; /** * Loads a Batched 3D Model. *
* Implements the {@link ResourceLoader} interface. *
* * @alias B3dmLoader * @constructor * @augments ResourceLoader * @private * * @param {object} options Object with the following properties: * @param {Resource} options.b3dmResource The {@link Resource} containing the b3dm. * @param {ArrayBuffer} options.arrayBuffer The array buffer of the b3dm contents. * @param {number} [options.byteOffset] The byte offset to the beginning of the b3dm contents in the array buffer. * @param {Resource} [options.baseResource] The {@link Resource} that paths in the glTF JSON are relative to. * @param {boolean} [options.releaseGltfJson=false] When true, the glTF JSON is released once the glTF is loaded. This is especially useful for cases like 3D Tiles, where each .gltf model is unique and caching the glTF JSON is not effective. * @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. * @param {boolean} [options.incrementallyLoadTextures=true] Determine if textures may continue to stream in after the glTF is loaded. * @param {Axis} [options.upAxis=Axis.Y] The up-axis of the glTF model. * @param {Axis} [options.forwardAxis=Axis.X] The forward-axis of the glTF model. * @param {boolean} [options.loadAttributesAsTypedArray=false] Iftrue
, load all attributes as typed arrays instead of GPU buffers. If the attributes are interleaved in the glTF they will be de-interleaved in the typed array.
* @param {boolean} [options.loadAttributesFor2D=false] If true
, load the positions buffer and any instanced attribute buffers as typed arrays for accurately projecting models to 2D.
* @param {boolean} [options.loadIndicesForWireframe=false] If true
, load the index buffer as a typed array. This is useful for creating wireframe indices in WebGL1.
* @param {boolean} [options.loadPrimitiveOutline=true] If true
, load outlines from the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. This can be set false to avoid post-processing geometry at load time.
* @param {boolean} [options.loadForClassification=false] If true
and if the model has feature IDs, load the feature IDs and indices as typed arrays. This is useful for batching features for classification.
* */
function B3dmLoader(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
const b3dmResource = options.b3dmResource;
let baseResource = options.baseResource;
const arrayBuffer = options.arrayBuffer;
const byteOffset = defaultValue(options.byteOffset, 0);
const releaseGltfJson = defaultValue(options.releaseGltfJson, false);
const asynchronous = defaultValue(options.asynchronous, true);
const incrementallyLoadTextures = defaultValue(
options.incrementallyLoadTextures,
true
);
const upAxis = defaultValue(options.upAxis, Axis.Y);
const forwardAxis = defaultValue(options.forwardAxis, Axis.X);
const loadAttributesAsTypedArray = defaultValue(
options.loadAttributesAsTypedArray,
false
);
const loadAttributesFor2D = defaultValue(options.loadAttributesFor2D, false);
const loadIndicesForWireframe = defaultValue(
options.loadIndicesForWireframe,
false
);
const loadPrimitiveOutline = defaultValue(options.loadPrimitiveOutline, true);
const loadForClassification = defaultValue(
options.loadForClassification,
false
);
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object("options.b3dmResource", b3dmResource);
Check.typeOf.object("options.arrayBuffer", arrayBuffer);
//>>includeEnd('debug');
baseResource = defined(baseResource) ? baseResource : b3dmResource.clone();
this._b3dmResource = b3dmResource;
this._baseResource = baseResource;
this._arrayBuffer = arrayBuffer;
this._byteOffset = byteOffset;
this._releaseGltfJson = releaseGltfJson;
this._asynchronous = asynchronous;
this._incrementallyLoadTextures = incrementallyLoadTextures;
this._upAxis = upAxis;
this._forwardAxis = forwardAxis;
this._loadAttributesAsTypedArray = loadAttributesAsTypedArray;
this._loadAttributesFor2D = loadAttributesFor2D;
this._loadIndicesForWireframe = loadIndicesForWireframe;
this._loadPrimitiveOutline = loadPrimitiveOutline;
this._loadForClassification = loadForClassification;
this._state = B3dmLoaderState.UNLOADED;
this._promise = undefined;
this._gltfLoader = undefined;
// Loaded results.
this._batchLength = 0;
this._propertyTable = undefined;
// The batch table object contains a json and a binary component access using keys of the same name.
this._batchTable = undefined;
this._components = undefined;
this._transform = Matrix4.IDENTITY;
}
if (defined(Object.create)) {
B3dmLoader.prototype = Object.create(ResourceLoader.prototype);
B3dmLoader.prototype.constructor = B3dmLoader;
}
Object.defineProperties(B3dmLoader.prototype, {
/**
* true if textures are loaded, useful when incrementallyLoadTextures is true
*
* @memberof B3dmLoader.prototype
*
* @type {boolean}
* @readonly
* @private
*/
texturesLoaded: {
get: function () {
return this._gltfLoader?.texturesLoaded;
},
},
/**
* The cache key of the resource
*
* @memberof B3dmLoader.prototype
*
* @type {string}
* @readonly
* @private
*/
cacheKey: {
get: function () {
return undefined;
},
},
/**
* The loaded components.
*
* @memberof B3dmLoader.prototype
*
* @type {ModelComponents.Components}
* @readonly
* @private
*/
components: {
get: function () {
return this._components;
},
},
});
/**
* Loads the resource.
* @returns {Promise