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 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.
*/
export default function ImplicitTileset(
baseResource,
tileJson,
metadataSchema
) {
var extension = tileJson.extensions["3DTILES_implicit_tiling"];
//>>includeStart('debug', pragmas.debug);
Check.typeOf.object(
'tileJson.extensions["3DTILES_implicit_tiling"]',
extension
);
//>>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;
if (
!defined(tileJson.boundingVolume.box) &&
!defined(tileJson.boundingVolume.region) &&
!hasExtension(tileJson.boundingVolume, "3DTILES_bounding_volume_S2")
) {
throw new RuntimeError(
"Only box, region and 3DTILES_bounding_volume_S2 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 = tileJson.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: extension.subtrees.uri });
/**
* Template URIs for locating content resources, e.g.
* https://example.com/{level}/{x}/{y}.b3dm.
*
* This is an array to support 3DTILES_multiple_contents
*
extras or extensions are preserved when
* {@link Cesium3DTile}s are created for each tile.
*
* This is an array to support 3DTILES_multiple_contents
*
tile.extensions["3DTILES_implicit_tiling"] to prevent infinite loops of implicit tilingtile.content since this is handled separatelytile.extensions["3DTILES_multiple_contents"], again
* because contents are handled separately