import Check from "../Core/Check.js";
import clone from "../Core/clone.js";
import defined from "../Core/defined.js";
import Resource from "../Core/Resource.js";
import RuntimeError from "../Core/RuntimeError.js";
import hasExtension from "./hasExtension.js";
import ImplicitSubdivisionScheme from "./ImplicitSubdivisionScheme.js";
/**
* An ImplicitTileset is a simple struct that stores information about the
* structure of a single implicit tileset. This includes template URIs for
* locating resources, details from the implicit root tile (bounding volume,
* geometricError, etc.), and details about the subtrees (e.g. subtreeLevels,
* subdivisionScheme).
*
* @alias ImplicitTileset
* @constructor
*
* @param {Resource} baseResource The base resource for the tileset
* @param {object} tileJson The JSON header of the tile with either implicit tiling (3D Tiles 1.1) or the 3DTILES_implicit_tiling extension.
* @param {MetadataSchema} [metadataSchema] The metadata schema containing the implicit tile metadata class.
* @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 ImplicitTileset(baseResource, tileJson, metadataSchema) {
const implicitTiling = hasExtension(tileJson, "3DTILES_implicit_tiling")
? tileJson.extensions["3DTILES_implicit_tiling"]
: tileJson.implicitTiling;
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object("implicitTiling", implicitTiling);
//>>includeEnd('debug');
/**
* The base resource for the tileset. This is stored here as it is needed
* later when expanding Implicit3DTileContents so tile URLs are relative
* to the tileset, not the subtree file.
*
* @type {Resource}
* @readonly
* @private
*/
this.baseResource = baseResource;
/**
* The geometric error of the root tile
*
* @type {number}
* @readonly
* @private
*/
this.geometricError = tileJson.geometricError;
/**
* The metadata schema containing the implicit tile metadata class.
*
* @type {MetadataSchema|undefined}
* @readonly
* @private
*/
this.metadataSchema = metadataSchema;
const boundingVolume = tileJson.boundingVolume;
if (
!defined(boundingVolume.box) &&
!defined(boundingVolume.region) &&
!hasExtension(boundingVolume, "3DTILES_bounding_volume_S2") &&
!hasExtension(boundingVolume, "3DTILES_bounding_volume_cylinder")
) {
throw new RuntimeError(
"Only box, region, 3DTILES_bounding_volume_S2, and 3DTILES_bounding_volume_cylinder are supported for implicit tiling"
);
}
/**
* The JSON representation of a bounding volume. This is either a box or a
* region.
*
* @type {object}
* @readonly
* @private
*/
this.boundingVolume = boundingVolume;
/**
* The refine strategy as a string, either 'ADD' or 'REPLACE'
*
* @type {string}
* @readonly
* @private
*/
this.refine = tileJson.refine;
/**
* Template URI for the subtree resources, e.g.
* https://example.com/{level}/{x}/{y}.subtree
*
* @type {Resource}
* @readonly
* @private
*/
this.subtreeUriTemplate = new Resource({ url: implicitTiling.subtrees.uri });
/**
* Template URIs for locating content resources, e.g.
* https://example.com/{level}/{x}/{y}.b3dm
.
*
* This is an array to support multiple contents. *
* * @type {Resource[]} * @readonly * @private */ this.contentUriTemplates = []; /** * Store a copy of the content headers, so properties such as *extras
or extensions
are preserved when
* {@link Cesium3DTile}s are created for each tile.
* * This is an array to support multiple contents. *
* * @type {Object[]} * @readonly * @private */ this.contentHeaders = []; const contentHeaders = gatherContentHeaders(tileJson); for (let i = 0; i < contentHeaders.length; i++) { const contentHeader = contentHeaders[i]; this.contentHeaders.push(clone(contentHeader, true)); const contentResource = new Resource({ url: contentHeader.uri }); this.contentUriTemplates.push(contentResource); } /** * The maximum number of contents as well as content availability bitstreams. * This is used for loop bounds when checking content availability. * * @type {number} * @readonly * @private */ this.contentCount = this.contentHeaders.length; /** * Stores a copy of the root implicit tile's JSON header. This is used * as a template for creating {@link Cesium3DTile}s. The following properties * are removed: * *tile.implicitTiling
to prevent infinite loops of implicit tilingtile.extensions["3DTILES_implicit_tiling"]
, if used instead of tile.implicitTilingtile.contents
, since contents are handled separatelytile.content
, if used instead of tile.contentstile.extensions["3DTILES_multiple_contents"]
, if used instead of tile.contents or tile.content