12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787 |
- import BoundingSphere from "../Core/BoundingSphere.js";
- import Cartesian3 from "../Core/Cartesian3.js";
- import Color from "../Core/Color.js";
- import ColorGeometryInstanceAttribute from "../Core/ColorGeometryInstanceAttribute.js";
- import CullingVolume from "../Core/CullingVolume.js";
- import defaultValue from "../Core/defaultValue.js";
- import defined from "../Core/defined.js";
- import deprecationWarning from "../Core/deprecationWarning.js";
- import destroyObject from "../Core/destroyObject.js";
- import Ellipsoid from "../Core/Ellipsoid.js";
- import getMagic from "../Core/getMagic.js";
- import Intersect from "../Core/Intersect.js";
- import JulianDate from "../Core/JulianDate.js";
- import CesiumMath from "../Core/Math.js";
- import Matrix3 from "../Core/Matrix3.js";
- import Matrix4 from "../Core/Matrix4.js";
- import OrientedBoundingBox from "../Core/OrientedBoundingBox.js";
- import OrthographicFrustum from "../Core/OrthographicFrustum.js";
- import Rectangle from "../Core/Rectangle.js";
- import Request from "../Core/Request.js";
- import RequestScheduler from "../Core/RequestScheduler.js";
- import RequestState from "../Core/RequestState.js";
- import RequestType from "../Core/RequestType.js";
- import Resource from "../Core/Resource.js";
- import RuntimeError from "../Core/RuntimeError.js";
- import when from "../ThirdParty/when.js";
- import Cesium3DTileContentFactory from "./Cesium3DTileContentFactory.js";
- import Cesium3DTileContentState from "./Cesium3DTileContentState.js";
- import Cesium3DTileOptimizationHint from "./Cesium3DTileOptimizationHint.js";
- import Cesium3DTilePass from "./Cesium3DTilePass.js";
- import Cesium3DTileRefine from "./Cesium3DTileRefine.js";
- import Empty3DTileContent from "./Empty3DTileContent.js";
- import SceneMode from "./SceneMode.js";
- import TileBoundingRegion from "./TileBoundingRegion.js";
- import TileBoundingSphere from "./TileBoundingSphere.js";
- import TileOrientedBoundingBox from "./TileOrientedBoundingBox.js";
- function Cesium3DTile(tileset, baseResource, header, parent) {
- this._tileset = tileset;
- this._header = header;
- var contentHeader = header.content;
-
- this.transform = defined(header.transform)
- ? Matrix4.unpack(header.transform)
- : Matrix4.clone(Matrix4.IDENTITY);
- var parentTransform = defined(parent)
- ? parent.computedTransform
- : tileset.modelMatrix;
- var computedTransform = Matrix4.multiply(
- parentTransform,
- this.transform,
- new Matrix4()
- );
- var parentInitialTransform = defined(parent)
- ? parent._initialTransform
- : Matrix4.IDENTITY;
- this._initialTransform = Matrix4.multiply(
- parentInitialTransform,
- this.transform,
- new Matrix4()
- );
-
- this.computedTransform = computedTransform;
- this._boundingVolume = this.createBoundingVolume(
- header.boundingVolume,
- computedTransform
- );
- this._boundingVolume2D = undefined;
- var contentBoundingVolume;
- if (defined(contentHeader) && defined(contentHeader.boundingVolume)) {
-
-
-
-
-
- contentBoundingVolume = this.createBoundingVolume(
- contentHeader.boundingVolume,
- computedTransform
- );
- }
- this._contentBoundingVolume = contentBoundingVolume;
- this._contentBoundingVolume2D = undefined;
- var viewerRequestVolume;
- if (defined(header.viewerRequestVolume)) {
- viewerRequestVolume = this.createBoundingVolume(
- header.viewerRequestVolume,
- computedTransform
- );
- }
- this._viewerRequestVolume = viewerRequestVolume;
-
- this.geometricError = header.geometricError;
- this._geometricError = header.geometricError;
- if (!defined(this._geometricError)) {
- this._geometricError = defined(parent)
- ? parent.geometricError
- : tileset._geometricError;
- Cesium3DTile._deprecationWarning(
- "geometricErrorUndefined",
- "Required property geometricError is undefined for this tile. Using parent's geometric error instead."
- );
- }
- this.updateGeometricErrorScale();
- var refine;
- if (defined(header.refine)) {
- if (header.refine === "replace" || header.refine === "add") {
- Cesium3DTile._deprecationWarning(
- "lowercase-refine",
- 'This tile uses a lowercase refine "' +
- header.refine +
- '". Instead use "' +
- header.refine.toUpperCase() +
- '".'
- );
- }
- refine =
- header.refine.toUpperCase() === "REPLACE"
- ? Cesium3DTileRefine.REPLACE
- : Cesium3DTileRefine.ADD;
- } else if (defined(parent)) {
-
- refine = parent.refine;
- } else {
- refine = Cesium3DTileRefine.REPLACE;
- }
-
- this.refine = refine;
-
- this.children = [];
-
- this.parent = parent;
- var content;
- var hasEmptyContent;
- var contentState;
- var contentResource;
- var serverKey;
- baseResource = Resource.createIfNeeded(baseResource);
- if (defined(contentHeader)) {
- var contentHeaderUri = contentHeader.uri;
- if (defined(contentHeader.url)) {
- Cesium3DTile._deprecationWarning(
- "contentUrl",
- 'This tileset JSON uses the "content.url" property which has been deprecated. Use "content.uri" instead.'
- );
- contentHeaderUri = contentHeader.url;
- }
- hasEmptyContent = false;
- contentState = Cesium3DTileContentState.UNLOADED;
- contentResource = baseResource.getDerivedResource({
- url: contentHeaderUri,
- });
- serverKey = RequestScheduler.getServerKey(
- contentResource.getUrlComponent()
- );
- } else {
- content = new Empty3DTileContent(tileset, this);
- hasEmptyContent = true;
- contentState = Cesium3DTileContentState.READY;
- }
- this._content = content;
- this._contentResource = contentResource;
- this._contentState = contentState;
- this._contentReadyToProcessPromise = undefined;
- this._contentReadyPromise = undefined;
- this._expiredContent = undefined;
- this._serverKey = serverKey;
-
- this.hasEmptyContent = hasEmptyContent;
-
- this.hasTilesetContent = false;
-
- this.cacheNode = undefined;
- var expire = header.expire;
- var expireDuration;
- var expireDate;
- if (defined(expire)) {
- expireDuration = expire.duration;
- if (defined(expire.date)) {
- expireDate = JulianDate.fromIso8601(expire.date);
- }
- }
-
- this.expireDuration = expireDuration;
-
- this.expireDate = expireDate;
-
- this.lastStyleTime = 0.0;
-
- this._optimChildrenWithinParent = Cesium3DTileOptimizationHint.NOT_COMPUTED;
-
- this.clippingPlanesDirty = false;
-
- this.priorityDeferred = false;
-
- this._distanceToCamera = 0.0;
- this._centerZDepth = 0.0;
- this._screenSpaceError = 0.0;
- this._screenSpaceErrorProgressiveResolution = 0.0;
- this._visibilityPlaneMask = 0;
- this._visible = false;
- this._inRequestVolume = false;
- this._finalResolution = true;
- this._depth = 0;
- this._stackLength = 0;
- this._selectionDepth = 0;
- this._updatedVisibilityFrame = 0;
- this._touchedFrame = 0;
- this._visitedFrame = 0;
- this._selectedFrame = 0;
- this._requestedFrame = 0;
- this._ancestorWithContent = undefined;
- this._ancestorWithContentAvailable = undefined;
- this._refines = false;
- this._shouldSelect = false;
- this._isClipped = true;
- this._clippingPlanesState = 0;
- this._debugBoundingVolume = undefined;
- this._debugContentBoundingVolume = undefined;
- this._debugViewerRequestVolume = undefined;
- this._debugColor = Color.fromRandom({ alpha: 1.0 });
- this._debugColorizeTiles = false;
- this._priority = 0.0;
- this._priorityHolder = this;
- this._priorityProgressiveResolution = false;
- this._priorityProgressiveResolutionScreenSpaceErrorLeaf = false;
- this._priorityReverseScreenSpaceError = 0.0;
- this._foveatedFactor = 0.0;
- this._wasMinPriorityChild = false;
- this._loadTimestamp = new JulianDate();
- this._commandsLength = 0;
- this._color = undefined;
- this._colorDirty = false;
- this._request = undefined;
- }
- Cesium3DTile._deprecationWarning = deprecationWarning;
- Object.defineProperties(Cesium3DTile.prototype, {
-
- tileset: {
- get: function () {
- return this._tileset;
- },
- },
-
- content: {
- get: function () {
- return this._content;
- },
- },
-
- boundingVolume: {
- get: function () {
- return this._boundingVolume;
- },
- },
-
- contentBoundingVolume: {
- get: function () {
- return defaultValue(this._contentBoundingVolume, this._boundingVolume);
- },
- },
-
- boundingSphere: {
- get: function () {
- return this._boundingVolume.boundingSphere;
- },
- },
-
- extras: {
- get: function () {
- return this._header.extras;
- },
- },
-
- color: {
- get: function () {
- if (!defined(this._color)) {
- this._color = new Color();
- }
- return Color.clone(this._color);
- },
- set: function (value) {
- this._color = Color.clone(value, this._color);
- this._colorDirty = true;
- },
- },
-
- contentAvailable: {
- get: function () {
- return (
- (this.contentReady &&
- !this.hasEmptyContent &&
- !this.hasTilesetContent) ||
- (defined(this._expiredContent) && !this.contentFailed)
- );
- },
- },
-
- contentReady: {
- get: function () {
- return this._contentState === Cesium3DTileContentState.READY;
- },
- },
-
- contentUnloaded: {
- get: function () {
- return this._contentState === Cesium3DTileContentState.UNLOADED;
- },
- },
-
- contentExpired: {
- get: function () {
- return this._contentState === Cesium3DTileContentState.EXPIRED;
- },
- },
-
- contentFailed: {
- get: function () {
- return this._contentState === Cesium3DTileContentState.FAILED;
- },
- },
-
- contentReadyToProcessPromise: {
- get: function () {
- if (defined(this._contentReadyToProcessPromise)) {
- return this._contentReadyToProcessPromise.promise;
- }
- return undefined;
- },
- },
-
- contentReadyPromise: {
- get: function () {
- if (defined(this._contentReadyPromise)) {
- return this._contentReadyPromise.promise;
- }
- return undefined;
- },
- },
-
- commandsLength: {
- get: function () {
- return this._commandsLength;
- },
- },
- });
- var scratchCartesian = new Cartesian3();
- function isPriorityDeferred(tile, frameState) {
- var tileset = tile._tileset;
-
- var camera = frameState.camera;
- var boundingSphere = tile.boundingSphere;
- var radius = boundingSphere.radius;
- var scaledCameraDirection = Cartesian3.multiplyByScalar(
- camera.directionWC,
- tile._centerZDepth,
- scratchCartesian
- );
- var closestPointOnLine = Cartesian3.add(
- camera.positionWC,
- scaledCameraDirection,
- scratchCartesian
- );
-
- var toLine = Cartesian3.subtract(
- closestPointOnLine,
- boundingSphere.center,
- scratchCartesian
- );
- var distanceToCenterLine = Cartesian3.magnitude(toLine);
- var notTouchingSphere = distanceToCenterLine > radius;
-
-
-
-
- if (notTouchingSphere) {
- var toLineNormalized = Cartesian3.normalize(toLine, scratchCartesian);
- var scaledToLine = Cartesian3.multiplyByScalar(
- toLineNormalized,
- radius,
- scratchCartesian
- );
- var closestOnSphere = Cartesian3.add(
- boundingSphere.center,
- scaledToLine,
- scratchCartesian
- );
- var toClosestOnSphere = Cartesian3.subtract(
- closestOnSphere,
- camera.positionWC,
- scratchCartesian
- );
- var toClosestOnSphereNormalize = Cartesian3.normalize(
- toClosestOnSphere,
- scratchCartesian
- );
- tile._foveatedFactor =
- 1.0 -
- Math.abs(Cartesian3.dot(camera.directionWC, toClosestOnSphereNormalize));
- } else {
- tile._foveatedFactor = 0.0;
- }
-
-
- var replace = tile.refine === Cesium3DTileRefine.REPLACE;
- var skipLevelOfDetail = tileset._skipLevelOfDetail;
- if (
- (replace && !skipLevelOfDetail) ||
- !tileset.foveatedScreenSpaceError ||
- tileset.foveatedConeSize === 1.0 ||
- (tile._priorityProgressiveResolution && replace && skipLevelOfDetail) ||
- tileset._pass === Cesium3DTilePass.PRELOAD_FLIGHT ||
- tileset._pass === Cesium3DTilePass.PRELOAD
- ) {
- return false;
- }
- var maximumFovatedFactor = 1.0 - Math.cos(camera.frustum.fov * 0.5);
- var foveatedConeFactor = tileset.foveatedConeSize * maximumFovatedFactor;
-
- if (tile._foveatedFactor <= foveatedConeFactor) {
- return false;
- }
-
- var range = maximumFovatedFactor - foveatedConeFactor;
- var normalizedFoveatedFactor = CesiumMath.clamp(
- (tile._foveatedFactor - foveatedConeFactor) / range,
- 0.0,
- 1.0
- );
- var sseRelaxation = tileset.foveatedInterpolationCallback(
- tileset.foveatedMinimumScreenSpaceErrorRelaxation,
- tileset.maximumScreenSpaceError,
- normalizedFoveatedFactor
- );
- var sse =
- tile._screenSpaceError === 0.0 && defined(tile.parent)
- ? tile.parent._screenSpaceError * 0.5
- : tile._screenSpaceError;
- return tileset.maximumScreenSpaceError - sseRelaxation <= sse;
- }
- var scratchJulianDate = new JulianDate();
- Cesium3DTile.prototype.getScreenSpaceError = function (
- frameState,
- useParentGeometricError,
- progressiveResolutionHeightFraction
- ) {
- var tileset = this._tileset;
- var heightFraction = defaultValue(progressiveResolutionHeightFraction, 1.0);
- var parentGeometricError = defined(this.parent)
- ? this.parent.geometricError
- : tileset._geometricError;
- var geometricError = useParentGeometricError
- ? parentGeometricError
- : this.geometricError;
- if (geometricError === 0.0) {
-
- return 0.0;
- }
- var camera = frameState.camera;
- var frustum = camera.frustum;
- var context = frameState.context;
- var width = context.drawingBufferWidth;
- var height = context.drawingBufferHeight * heightFraction;
- var error;
- if (
- frameState.mode === SceneMode.SCENE2D ||
- frustum instanceof OrthographicFrustum
- ) {
- if (defined(frustum._offCenterFrustum)) {
- frustum = frustum._offCenterFrustum;
- }
- var pixelSize =
- Math.max(frustum.top - frustum.bottom, frustum.right - frustum.left) /
- Math.max(width, height);
- error = geometricError / pixelSize;
- } else {
-
- var distance = Math.max(this._distanceToCamera, CesiumMath.EPSILON7);
- var sseDenominator = camera.frustum.sseDenominator;
- error = (geometricError * height) / (distance * sseDenominator);
- if (tileset.dynamicScreenSpaceError) {
- var density = tileset._dynamicScreenSpaceErrorComputedDensity;
- var factor = tileset.dynamicScreenSpaceErrorFactor;
- var dynamicError = CesiumMath.fog(distance, density) * factor;
- error -= dynamicError;
- }
- }
- error /= frameState.pixelRatio;
- return error;
- };
- function isPriorityProgressiveResolution(tileset, tile) {
- if (
- tileset.progressiveResolutionHeightFraction <= 0.0 ||
- tileset.progressiveResolutionHeightFraction > 0.5
- ) {
- return false;
- }
- var isProgressiveResolutionTile =
- tile._screenSpaceErrorProgressiveResolution >
- tileset._maximumScreenSpaceError;
- tile._priorityProgressiveResolutionScreenSpaceErrorLeaf = false;
- var parent = tile.parent;
- var maximumScreenSpaceError = tileset._maximumScreenSpaceError;
- var tilePasses =
- tile._screenSpaceErrorProgressiveResolution <= maximumScreenSpaceError;
- var parentFails =
- defined(parent) &&
- parent._screenSpaceErrorProgressiveResolution > maximumScreenSpaceError;
- if (tilePasses && parentFails) {
-
- tile._priorityProgressiveResolutionScreenSpaceErrorLeaf = true;
- isProgressiveResolutionTile = true;
- }
- return isProgressiveResolutionTile;
- }
- function getPriorityReverseScreenSpaceError(tileset, tile) {
- var parent = tile.parent;
- var useParentScreenSpaceError =
- defined(parent) &&
- (!tileset._skipLevelOfDetail ||
- tile._screenSpaceError === 0.0 ||
- parent.hasTilesetContent);
- var screenSpaceError = useParentScreenSpaceError
- ? parent._screenSpaceError
- : tile._screenSpaceError;
- return tileset.root._screenSpaceError - screenSpaceError;
- }
- Cesium3DTile.prototype.updateVisibility = function (frameState) {
- var parent = this.parent;
- var tileset = this._tileset;
- var parentTransform = defined(parent)
- ? parent.computedTransform
- : tileset.modelMatrix;
- var parentVisibilityPlaneMask = defined(parent)
- ? parent._visibilityPlaneMask
- : CullingVolume.MASK_INDETERMINATE;
- this.updateTransform(parentTransform);
- this._distanceToCamera = this.distanceToTile(frameState);
- this._centerZDepth = this.distanceToTileCenter(frameState);
- this._screenSpaceError = this.getScreenSpaceError(frameState, false);
- this._screenSpaceErrorProgressiveResolution = this.getScreenSpaceError(
- frameState,
- false,
- tileset.progressiveResolutionHeightFraction
- );
- this._visibilityPlaneMask = this.visibility(
- frameState,
- parentVisibilityPlaneMask
- );
- this._visible = this._visibilityPlaneMask !== CullingVolume.MASK_OUTSIDE;
- this._inRequestVolume = this.insideViewerRequestVolume(frameState);
- this._priorityReverseScreenSpaceError = getPriorityReverseScreenSpaceError(
- tileset,
- this
- );
- this._priorityProgressiveResolution = isPriorityProgressiveResolution(
- tileset,
- this
- );
- this.priorityDeferred = isPriorityDeferred(this, frameState);
- };
- Cesium3DTile.prototype.updateExpiration = function () {
- if (defined(this.expireDate) && this.contentReady && !this.hasEmptyContent) {
- var now = JulianDate.now(scratchJulianDate);
- if (JulianDate.lessThan(this.expireDate, now)) {
- this._contentState = Cesium3DTileContentState.EXPIRED;
- this._expiredContent = this._content;
- }
- }
- };
- function updateExpireDate(tile) {
- if (defined(tile.expireDuration)) {
- var expireDurationDate = JulianDate.now(scratchJulianDate);
- JulianDate.addSeconds(
- expireDurationDate,
- tile.expireDuration,
- expireDurationDate
- );
- if (defined(tile.expireDate)) {
- if (JulianDate.lessThan(tile.expireDate, expireDurationDate)) {
- JulianDate.clone(expireDurationDate, tile.expireDate);
- }
- } else {
- tile.expireDate = JulianDate.clone(expireDurationDate);
- }
- }
- }
- function getContentFailedFunction(tile, tileset) {
- return function (error) {
- if (tile._contentState === Cesium3DTileContentState.PROCESSING) {
- --tileset.statistics.numberOfTilesProcessing;
- } else {
- --tileset.statistics.numberOfPendingRequests;
- }
- tile._contentState = Cesium3DTileContentState.FAILED;
- tile._contentReadyPromise.reject(error);
- tile._contentReadyToProcessPromise.reject(error);
- };
- }
- function createPriorityFunction(tile) {
- return function () {
- return tile._priority;
- };
- }
- Cesium3DTile.prototype.requestContent = function () {
- var that = this;
- var tileset = this._tileset;
- if (this.hasEmptyContent) {
- return false;
- }
- var resource = this._contentResource.clone();
- var expired = this.contentExpired;
- if (expired) {
-
- resource.setQueryParameters({
- expired: this.expireDate.toString(),
- });
- }
- var request = new Request({
- throttle: true,
- throttleByServer: true,
- type: RequestType.TILES3D,
- priorityFunction: createPriorityFunction(this),
- serverKey: this._serverKey,
- });
- this._request = request;
- resource.request = request;
- var promise = resource.fetchArrayBuffer();
- if (!defined(promise)) {
- return false;
- }
- var contentState = this._contentState;
- this._contentState = Cesium3DTileContentState.LOADING;
- this._contentReadyToProcessPromise = when.defer();
- this._contentReadyPromise = when.defer();
- var contentFailedFunction = getContentFailedFunction(this, tileset);
- promise
- .then(function (arrayBuffer) {
- if (that.isDestroyed()) {
-
- contentFailedFunction();
- return;
- }
- var uint8Array = new Uint8Array(arrayBuffer);
- var magic = getMagic(uint8Array);
- var contentFactory = Cesium3DTileContentFactory[magic];
- var content;
-
- tileset._disableSkipLevelOfDetail =
- tileset._disableSkipLevelOfDetail ||
- magic === "vctr" ||
- magic === "geom";
- if (defined(contentFactory)) {
- content = contentFactory(
- tileset,
- that,
- that._contentResource,
- arrayBuffer,
- 0
- );
- } else {
-
- content = Cesium3DTileContentFactory.json(
- tileset,
- that,
- that._contentResource,
- arrayBuffer,
- 0
- );
- that.hasTilesetContent = true;
- }
- if (expired) {
- that.expireDate = undefined;
- }
- that._content = content;
- that._contentState = Cesium3DTileContentState.PROCESSING;
- that._contentReadyToProcessPromise.resolve(content);
- return content.readyPromise.then(function (content) {
- if (that.isDestroyed()) {
-
- contentFailedFunction();
- return;
- }
- updateExpireDate(that);
-
- that._selectedFrame = 0;
- that.lastStyleTime = 0.0;
- JulianDate.now(that._loadTimestamp);
- that._contentState = Cesium3DTileContentState.READY;
- that._contentReadyPromise.resolve(content);
- });
- })
- .otherwise(function (error) {
- if (request.state === RequestState.CANCELLED) {
-
- that._contentState = contentState;
- --tileset.statistics.numberOfPendingRequests;
- ++tileset.statistics.numberOfAttemptedRequests;
- return;
- }
- contentFailedFunction(error);
- });
- return true;
- };
- Cesium3DTile.prototype.unloadContent = function () {
- if (this.hasEmptyContent || this.hasTilesetContent) {
- return;
- }
- this._content = this._content && this._content.destroy();
- this._contentState = Cesium3DTileContentState.UNLOADED;
- this._contentReadyToProcessPromise = undefined;
- this._contentReadyPromise = undefined;
- this.lastStyleTime = 0.0;
- this.clippingPlanesDirty = this._clippingPlanesState === 0;
- this._clippingPlanesState = 0;
- this._debugColorizeTiles = false;
- this._debugBoundingVolume =
- this._debugBoundingVolume && this._debugBoundingVolume.destroy();
- this._debugContentBoundingVolume =
- this._debugContentBoundingVolume &&
- this._debugContentBoundingVolume.destroy();
- this._debugViewerRequestVolume =
- this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();
- };
- var scratchProjectedBoundingSphere = new BoundingSphere();
- function getBoundingVolume(tile, frameState) {
- if (
- frameState.mode !== SceneMode.SCENE3D &&
- !defined(tile._boundingVolume2D)
- ) {
- var boundingSphere = tile._boundingVolume.boundingSphere;
- var sphere = BoundingSphere.projectTo2D(
- boundingSphere,
- frameState.mapProjection,
- scratchProjectedBoundingSphere
- );
- tile._boundingVolume2D = new TileBoundingSphere(
- sphere.center,
- sphere.radius
- );
- }
- return frameState.mode !== SceneMode.SCENE3D
- ? tile._boundingVolume2D
- : tile._boundingVolume;
- }
- function getContentBoundingVolume(tile, frameState) {
- if (
- frameState.mode !== SceneMode.SCENE3D &&
- !defined(tile._contentBoundingVolume2D)
- ) {
- var boundingSphere = tile._contentBoundingVolume.boundingSphere;
- var sphere = BoundingSphere.projectTo2D(
- boundingSphere,
- frameState.mapProjection,
- scratchProjectedBoundingSphere
- );
- tile._contentBoundingVolume2D = new TileBoundingSphere(
- sphere.center,
- sphere.radius
- );
- }
- return frameState.mode !== SceneMode.SCENE3D
- ? tile._contentBoundingVolume2D
- : tile._contentBoundingVolume;
- }
- Cesium3DTile.prototype.visibility = function (
- frameState,
- parentVisibilityPlaneMask
- ) {
- var cullingVolume = frameState.cullingVolume;
- var boundingVolume = getBoundingVolume(this, frameState);
- var tileset = this._tileset;
- var clippingPlanes = tileset.clippingPlanes;
- if (defined(clippingPlanes) && clippingPlanes.enabled) {
- var intersection = clippingPlanes.computeIntersectionWithBoundingVolume(
- boundingVolume,
- tileset.clippingPlanesOriginMatrix
- );
- this._isClipped = intersection !== Intersect.INSIDE;
- if (intersection === Intersect.OUTSIDE) {
- return CullingVolume.MASK_OUTSIDE;
- }
- }
- return cullingVolume.computeVisibilityWithPlaneMask(
- boundingVolume,
- parentVisibilityPlaneMask
- );
- };
- Cesium3DTile.prototype.contentVisibility = function (frameState) {
-
-
- if (!defined(this._contentBoundingVolume)) {
- return Intersect.INSIDE;
- }
- if (this._visibilityPlaneMask === CullingVolume.MASK_INSIDE) {
-
-
- return Intersect.INSIDE;
- }
-
-
- var cullingVolume = frameState.cullingVolume;
- var boundingVolume = getContentBoundingVolume(this, frameState);
- var tileset = this._tileset;
- var clippingPlanes = tileset.clippingPlanes;
- if (defined(clippingPlanes) && clippingPlanes.enabled) {
- var intersection = clippingPlanes.computeIntersectionWithBoundingVolume(
- boundingVolume,
- tileset.clippingPlanesOriginMatrix
- );
- this._isClipped = intersection !== Intersect.INSIDE;
- if (intersection === Intersect.OUTSIDE) {
- return Intersect.OUTSIDE;
- }
- }
- return cullingVolume.computeVisibility(boundingVolume);
- };
- Cesium3DTile.prototype.distanceToTile = function (frameState) {
- var boundingVolume = getBoundingVolume(this, frameState);
- return boundingVolume.distanceToCamera(frameState);
- };
- var scratchToTileCenter = new Cartesian3();
- Cesium3DTile.prototype.distanceToTileCenter = function (frameState) {
- var tileBoundingVolume = getBoundingVolume(this, frameState);
- var boundingVolume = tileBoundingVolume.boundingVolume;
- var toCenter = Cartesian3.subtract(
- boundingVolume.center,
- frameState.camera.positionWC,
- scratchToTileCenter
- );
- return Cartesian3.dot(frameState.camera.directionWC, toCenter);
- };
- Cesium3DTile.prototype.insideViewerRequestVolume = function (frameState) {
- var viewerRequestVolume = this._viewerRequestVolume;
- return (
- !defined(viewerRequestVolume) ||
- viewerRequestVolume.distanceToCamera(frameState) === 0.0
- );
- };
- var scratchMatrix = new Matrix3();
- var scratchScale = new Cartesian3();
- var scratchHalfAxes = new Matrix3();
- var scratchCenter = new Cartesian3();
- var scratchRectangle = new Rectangle();
- var scratchOrientedBoundingBox = new OrientedBoundingBox();
- var scratchTransform = new Matrix4();
- function createBox(box, transform, result) {
- var center = Cartesian3.fromElements(box[0], box[1], box[2], scratchCenter);
- var halfAxes = Matrix3.fromArray(box, 3, scratchHalfAxes);
-
- center = Matrix4.multiplyByPoint(transform, center, center);
- var rotationScale = Matrix4.getMatrix3(transform, scratchMatrix);
- halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);
- if (defined(result)) {
- result.update(center, halfAxes);
- return result;
- }
- return new TileOrientedBoundingBox(center, halfAxes);
- }
- function createBoxFromTransformedRegion(
- region,
- transform,
- initialTransform,
- result
- ) {
- var rectangle = Rectangle.unpack(region, 0, scratchRectangle);
- var minimumHeight = region[4];
- var maximumHeight = region[5];
- var orientedBoundingBox = OrientedBoundingBox.fromRectangle(
- rectangle,
- minimumHeight,
- maximumHeight,
- Ellipsoid.WGS84,
- scratchOrientedBoundingBox
- );
- var center = orientedBoundingBox.center;
- var halfAxes = orientedBoundingBox.halfAxes;
-
-
-
- transform = Matrix4.multiplyTransformation(
- transform,
- Matrix4.inverseTransformation(initialTransform, scratchTransform),
- scratchTransform
- );
- center = Matrix4.multiplyByPoint(transform, center, center);
- var rotationScale = Matrix4.getMatrix3(transform, scratchMatrix);
- halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);
- if (defined(result) && result instanceof TileOrientedBoundingBox) {
- result.update(center, halfAxes);
- return result;
- }
- return new TileOrientedBoundingBox(center, halfAxes);
- }
- function createRegion(region, transform, initialTransform, result) {
- if (
- !Matrix4.equalsEpsilon(transform, initialTransform, CesiumMath.EPSILON8)
- ) {
- return createBoxFromTransformedRegion(
- region,
- transform,
- initialTransform,
- result
- );
- }
- if (defined(result)) {
- return result;
- }
- var rectangleRegion = Rectangle.unpack(region, 0, scratchRectangle);
- return new TileBoundingRegion({
- rectangle: rectangleRegion,
- minimumHeight: region[4],
- maximumHeight: region[5],
- });
- }
- function createSphere(sphere, transform, result) {
- var center = Cartesian3.fromElements(
- sphere[0],
- sphere[1],
- sphere[2],
- scratchCenter
- );
- var radius = sphere[3];
-
- center = Matrix4.multiplyByPoint(transform, center, center);
- var scale = Matrix4.getScale(transform, scratchScale);
- var uniformScale = Cartesian3.maximumComponent(scale);
- radius *= uniformScale;
- if (defined(result)) {
- result.update(center, radius);
- return result;
- }
- return new TileBoundingSphere(center, radius);
- }
- Cesium3DTile.prototype.createBoundingVolume = function (
- boundingVolumeHeader,
- transform,
- result
- ) {
- if (!defined(boundingVolumeHeader)) {
- throw new RuntimeError("boundingVolume must be defined");
- }
- if (defined(boundingVolumeHeader.box)) {
- return createBox(boundingVolumeHeader.box, transform, result);
- }
- if (defined(boundingVolumeHeader.region)) {
- return createRegion(
- boundingVolumeHeader.region,
- transform,
- this._initialTransform,
- result
- );
- }
- if (defined(boundingVolumeHeader.sphere)) {
- return createSphere(boundingVolumeHeader.sphere, transform, result);
- }
- throw new RuntimeError(
- "boundingVolume must contain a sphere, region, or box"
- );
- };
- Cesium3DTile.prototype.updateTransform = function (parentTransform) {
- parentTransform = defaultValue(parentTransform, Matrix4.IDENTITY);
- var computedTransform = Matrix4.multiply(
- parentTransform,
- this.transform,
- scratchTransform
- );
- var transformChanged = !Matrix4.equals(
- computedTransform,
- this.computedTransform
- );
- if (!transformChanged) {
- return;
- }
- Matrix4.clone(computedTransform, this.computedTransform);
-
- var header = this._header;
- var content = this._header.content;
- this._boundingVolume = this.createBoundingVolume(
- header.boundingVolume,
- this.computedTransform,
- this._boundingVolume
- );
- if (defined(this._contentBoundingVolume)) {
- this._contentBoundingVolume = this.createBoundingVolume(
- content.boundingVolume,
- this.computedTransform,
- this._contentBoundingVolume
- );
- }
- if (defined(this._viewerRequestVolume)) {
- this._viewerRequestVolume = this.createBoundingVolume(
- header.viewerRequestVolume,
- this.computedTransform,
- this._viewerRequestVolume
- );
- }
- this.updateGeometricErrorScale();
-
- this._debugBoundingVolume =
- this._debugBoundingVolume && this._debugBoundingVolume.destroy();
- this._debugContentBoundingVolume =
- this._debugContentBoundingVolume &&
- this._debugContentBoundingVolume.destroy();
- this._debugViewerRequestVolume =
- this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();
- };
- Cesium3DTile.prototype.updateGeometricErrorScale = function () {
- var scale = Matrix4.getScale(this.computedTransform, scratchScale);
- var uniformScale = Cartesian3.maximumComponent(scale);
- this.geometricError = this._geometricError * uniformScale;
- };
- function applyDebugSettings(tile, tileset, frameState, passOptions) {
- if (!passOptions.isRender) {
- return;
- }
- var hasContentBoundingVolume =
- defined(tile._header.content) &&
- defined(tile._header.content.boundingVolume);
- var empty = tile.hasEmptyContent || tile.hasTilesetContent;
- var showVolume =
- tileset.debugShowBoundingVolume ||
- (tileset.debugShowContentBoundingVolume && !hasContentBoundingVolume);
- if (showVolume) {
- var color;
- if (!tile._finalResolution) {
- color = Color.YELLOW;
- } else if (empty) {
- color = Color.DARKGRAY;
- } else {
- color = Color.WHITE;
- }
- if (!defined(tile._debugBoundingVolume)) {
- tile._debugBoundingVolume = tile._boundingVolume.createDebugVolume(color);
- }
- tile._debugBoundingVolume.update(frameState);
- var attributes = tile._debugBoundingVolume.getGeometryInstanceAttributes(
- "outline"
- );
- attributes.color = ColorGeometryInstanceAttribute.toValue(
- color,
- attributes.color
- );
- } else if (!showVolume && defined(tile._debugBoundingVolume)) {
- tile._debugBoundingVolume = tile._debugBoundingVolume.destroy();
- }
- if (tileset.debugShowContentBoundingVolume && hasContentBoundingVolume) {
- if (!defined(tile._debugContentBoundingVolume)) {
- tile._debugContentBoundingVolume = tile._contentBoundingVolume.createDebugVolume(
- Color.BLUE
- );
- }
- tile._debugContentBoundingVolume.update(frameState);
- } else if (
- !tileset.debugShowContentBoundingVolume &&
- defined(tile._debugContentBoundingVolume)
- ) {
- tile._debugContentBoundingVolume = tile._debugContentBoundingVolume.destroy();
- }
- if (
- tileset.debugShowViewerRequestVolume &&
- defined(tile._viewerRequestVolume)
- ) {
- if (!defined(tile._debugViewerRequestVolume)) {
- tile._debugViewerRequestVolume = tile._viewerRequestVolume.createDebugVolume(
- Color.YELLOW
- );
- }
- tile._debugViewerRequestVolume.update(frameState);
- } else if (
- !tileset.debugShowViewerRequestVolume &&
- defined(tile._debugViewerRequestVolume)
- ) {
- tile._debugViewerRequestVolume = tile._debugViewerRequestVolume.destroy();
- }
- var debugColorizeTilesOn =
- (tileset.debugColorizeTiles && !tile._debugColorizeTiles) ||
- defined(tileset._heatmap.tilePropertyName);
- var debugColorizeTilesOff =
- !tileset.debugColorizeTiles && tile._debugColorizeTiles;
- if (debugColorizeTilesOn) {
- tileset._heatmap.colorize(tile, frameState);
- tile._debugColorizeTiles = true;
- tile.color = tile._debugColor;
- } else if (debugColorizeTilesOff) {
- tile._debugColorizeTiles = false;
- tile.color = Color.WHITE;
- }
- if (tile._colorDirty) {
- tile._colorDirty = false;
- tile._content.applyDebugSettings(true, tile._color);
- }
- if (debugColorizeTilesOff) {
- tileset.makeStyleDirty();
- }
- }
- function updateContent(tile, tileset, frameState) {
- var content = tile._content;
- var expiredContent = tile._expiredContent;
- if (defined(expiredContent)) {
- if (!tile.contentReady) {
-
- expiredContent.update(tileset, frameState);
- return;
- }
-
- tile._expiredContent.destroy();
- tile._expiredContent = undefined;
- }
- content.update(tileset, frameState);
- }
- function updateClippingPlanes(tile, tileset) {
-
-
-
-
- var clippingPlanes = tileset.clippingPlanes;
- var currentClippingPlanesState = 0;
- if (defined(clippingPlanes) && tile._isClipped && clippingPlanes.enabled) {
- currentClippingPlanesState = clippingPlanes.clippingPlanesState;
- }
-
- if (currentClippingPlanesState !== tile._clippingPlanesState) {
- tile._clippingPlanesState = currentClippingPlanesState;
- tile.clippingPlanesDirty = true;
- }
- }
- Cesium3DTile.prototype.update = function (tileset, frameState, passOptions) {
- var initCommandLength = frameState.commandList.length;
- updateClippingPlanes(this, tileset);
- applyDebugSettings(this, tileset, frameState, passOptions);
- updateContent(this, tileset, frameState);
- this._commandsLength = frameState.commandList.length - initCommandLength;
- this.clippingPlanesDirty = false;
- };
- var scratchCommandList = [];
- Cesium3DTile.prototype.process = function (tileset, frameState) {
- var savedCommandList = frameState.commandList;
- frameState.commandList = scratchCommandList;
- this._content.update(tileset, frameState);
- scratchCommandList.length = 0;
- frameState.commandList = savedCommandList;
- };
- function isolateDigits(normalizedValue, numberOfDigits, leftShift) {
- var scaled = normalizedValue * Math.pow(10, numberOfDigits);
- var integer = parseInt(scaled);
- return integer * Math.pow(10, leftShift);
- }
- function priorityNormalizeAndClamp(value, minimum, maximum) {
- return Math.max(
- CesiumMath.normalize(value, minimum, maximum) - CesiumMath.EPSILON7,
- 0.0
- );
- }
- Cesium3DTile.prototype.updatePriority = function () {
- var tileset = this.tileset;
- var preferLeaves = tileset.preferLeaves;
- var minimumPriority = tileset._minimumPriority;
- var maximumPriority = tileset._maximumPriority;
-
-
-
-
-
-
-
-
- var digitsForANumber = 4;
- var digitsForABoolean = 1;
- var preferredSortingLeftShift = 0;
- var preferredSortingDigitsCount = digitsForANumber;
- var foveatedLeftShift =
- preferredSortingLeftShift + preferredSortingDigitsCount;
- var foveatedDigitsCount = digitsForANumber;
- var preloadProgressiveResolutionLeftShift =
- foveatedLeftShift + foveatedDigitsCount;
- var preloadProgressiveResolutionDigitsCount = digitsForABoolean;
- var preloadProgressiveResolutionScale = Math.pow(
- 10,
- preloadProgressiveResolutionLeftShift
- );
- var foveatedDeferLeftShift =
- preloadProgressiveResolutionLeftShift +
- preloadProgressiveResolutionDigitsCount;
- var foveatedDeferDigitsCount = digitsForABoolean;
- var foveatedDeferScale = Math.pow(10, foveatedDeferLeftShift);
- var preloadFlightLeftShift =
- foveatedDeferLeftShift + foveatedDeferDigitsCount;
- var preloadFlightScale = Math.pow(10, preloadFlightLeftShift);
-
- var depthDigits = priorityNormalizeAndClamp(
- this._depth,
- minimumPriority.depth,
- maximumPriority.depth
- );
- depthDigits = preferLeaves ? 1.0 - depthDigits : depthDigits;
-
- var useDistance =
- !tileset._skipLevelOfDetail && this.refine === Cesium3DTileRefine.REPLACE;
- var normalizedPreferredSorting = useDistance
- ? priorityNormalizeAndClamp(
- this._priorityHolder._distanceToCamera,
- minimumPriority.distance,
- maximumPriority.distance
- )
- : priorityNormalizeAndClamp(
- this._priorityReverseScreenSpaceError,
- minimumPriority.reverseScreenSpaceError,
- maximumPriority.reverseScreenSpaceError
- );
- var preferredSortingDigits = isolateDigits(
- normalizedPreferredSorting,
- preferredSortingDigitsCount,
- preferredSortingLeftShift
- );
- var preloadProgressiveResolutionDigits = this._priorityProgressiveResolution
- ? 0
- : preloadProgressiveResolutionScale;
- var normalizedFoveatedFactor = priorityNormalizeAndClamp(
- this._priorityHolder._foveatedFactor,
- minimumPriority.foveatedFactor,
- maximumPriority.foveatedFactor
- );
- var foveatedDigits = isolateDigits(
- normalizedFoveatedFactor,
- foveatedDigitsCount,
- foveatedLeftShift
- );
- var foveatedDeferDigits = this.priorityDeferred ? foveatedDeferScale : 0;
- var preloadFlightDigits =
- tileset._pass === Cesium3DTilePass.PRELOAD_FLIGHT ? 0 : preloadFlightScale;
-
- this._priority =
- depthDigits +
- preferredSortingDigits +
- preloadProgressiveResolutionDigits +
- foveatedDigits +
- foveatedDeferDigits +
- preloadFlightDigits;
- };
- Cesium3DTile.prototype.isDestroyed = function () {
- return false;
- };
- Cesium3DTile.prototype.destroy = function () {
-
- this._content = this._content && this._content.destroy();
- this._expiredContent =
- this._expiredContent &&
- !this._expiredContent.isDestroyed() &&
- this._expiredContent.destroy();
- this._debugBoundingVolume =
- this._debugBoundingVolume && this._debugBoundingVolume.destroy();
- this._debugContentBoundingVolume =
- this._debugContentBoundingVolume &&
- this._debugContentBoundingVolume.destroy();
- this._debugViewerRequestVolume =
- this._debugViewerRequestVolume && this._debugViewerRequestVolume.destroy();
- return destroyObject(this);
- };
- export default Cesium3DTile;
|