Cesium3DTileset.js 118 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437
  1. import ApproximateTerrainHeights from "../Core/ApproximateTerrainHeights.js";
  2. import Cartesian2 from "../Core/Cartesian2.js";
  3. import Cartesian3 from "../Core/Cartesian3.js";
  4. import Cartographic from "../Core/Cartographic.js";
  5. import Check from "../Core/Check.js";
  6. import clone from "../Core/clone.js";
  7. import Color from "../Core/Color.js";
  8. import Credit from "../Core/Credit.js";
  9. import defaultValue from "../Core/defaultValue.js";
  10. import defined from "../Core/defined.js";
  11. import deprecationWarning from "../Core/deprecationWarning.js";
  12. import destroyObject from "../Core/destroyObject.js";
  13. import Ellipsoid from "../Core/Ellipsoid.js";
  14. import Event from "../Core/Event.js";
  15. import ImageBasedLighting from "./ImageBasedLighting.js";
  16. import IonResource from "../Core/IonResource.js";
  17. import JulianDate from "../Core/JulianDate.js";
  18. import ManagedArray from "../Core/ManagedArray.js";
  19. import CesiumMath from "../Core/Math.js";
  20. import Matrix4 from "../Core/Matrix4.js";
  21. import Resource from "../Core/Resource.js";
  22. import RuntimeError from "../Core/RuntimeError.js";
  23. import Transforms from "../Core/Transforms.js";
  24. import ClearCommand from "../Renderer/ClearCommand.js";
  25. import Pass from "../Renderer/Pass.js";
  26. import RenderState from "../Renderer/RenderState.js";
  27. import Axis from "./Axis.js";
  28. import Cesium3DTile from "./Cesium3DTile.js";
  29. import Cesium3DTileColorBlendMode from "./Cesium3DTileColorBlendMode.js";
  30. import Cesium3DTileContentState from "./Cesium3DTileContentState.js";
  31. import Cesium3DTilesetMetadata from "./Cesium3DTilesetMetadata.js";
  32. import Cesium3DTileOptimizations from "./Cesium3DTileOptimizations.js";
  33. import Cesium3DTilePass from "./Cesium3DTilePass.js";
  34. import Cesium3DTileRefine from "./Cesium3DTileRefine.js";
  35. import Cesium3DTilesetCache from "./Cesium3DTilesetCache.js";
  36. import Cesium3DTilesetHeatmap from "./Cesium3DTilesetHeatmap.js";
  37. import Cesium3DTilesetStatistics from "./Cesium3DTilesetStatistics.js";
  38. import Cesium3DTileStyleEngine from "./Cesium3DTileStyleEngine.js";
  39. import ClippingPlaneCollection from "./ClippingPlaneCollection.js";
  40. import hasExtension from "./hasExtension.js";
  41. import ImplicitTileset from "./ImplicitTileset.js";
  42. import ImplicitTileCoordinates from "./ImplicitTileCoordinates.js";
  43. import LabelCollection from "./LabelCollection.js";
  44. import oneTimeWarning from "../Core/oneTimeWarning.js";
  45. import PointCloudEyeDomeLighting from "./PointCloudEyeDomeLighting.js";
  46. import PointCloudShading from "./PointCloudShading.js";
  47. import ResourceCache from "./ResourceCache.js";
  48. import SceneMode from "./SceneMode.js";
  49. import ShadowMode from "./ShadowMode.js";
  50. import SplitDirection from "./SplitDirection.js";
  51. import StencilConstants from "./StencilConstants.js";
  52. import TileBoundingRegion from "./TileBoundingRegion.js";
  53. import TileBoundingSphere from "./TileBoundingSphere.js";
  54. import TileOrientedBoundingBox from "./TileOrientedBoundingBox.js";
  55. import Cesium3DTilesetMostDetailedTraversal from "./Cesium3DTilesetMostDetailedTraversal.js";
  56. import Cesium3DTilesetBaseTraversal from "./Cesium3DTilesetBaseTraversal.js";
  57. import Cesium3DTilesetSkipTraversal from "./Cesium3DTilesetSkipTraversal.js";
  58. /**
  59. * @typedef {Object} Cesium3DTileset.ConstructorOptions
  60. *
  61. * Initialization options for the Cesium3DTileset constructor
  62. *
  63. * @property {Resource|string|Promise<Resource>|Promise<string>} [.url] The url to a tileset JSON file. Deprecated.
  64. * @property {boolean} [show=true] Determines if the tileset will be shown.
  65. * @property {Matrix4} [modelMatrix=Matrix4.IDENTITY] A 4x4 transformation matrix that transforms the tileset's root tile.
  66. * @property {Axis} [modelUpAxis=Axis.Y] Which axis is considered up when loading models for tile contents.
  67. * @property {Axis} [modelForwardAxis=Axis.X] Which axis is considered forward when loading models for tile contents.
  68. * @property {ShadowMode} [shadows=ShadowMode.ENABLED] Determines whether the tileset casts or receives shadows from light sources.
  69. * @property {number} [maximumScreenSpaceError=16] The maximum screen space error used to drive level of detail refinement.
  70. * @property {number} [maximumMemoryUsage=512] The maximum amount of memory in MB that can be used by the tileset.
  71. * @property {boolean} [cullWithChildrenBounds=true] Optimization option. Whether to cull tiles using the union of their children bounding volumes.
  72. * @property {boolean} [cullRequestsWhileMoving=true] Optimization option. Don't request tiles that will likely be unused when they come back because of the camera's movement. This optimization only applies to stationary tilesets.
  73. * @property {number} [cullRequestsWhileMovingMultiplier=60.0] Optimization option. Multiplier used in culling requests while moving. Larger is more aggressive culling, smaller less aggressive culling.
  74. * @property {boolean} [preloadWhenHidden=false] Preload tiles when <code>tileset.show</code> is <code>false</code>. Loads tiles as if the tileset is visible but does not render them.
  75. * @property {boolean} [preloadFlightDestinations=true] Optimization option. Preload tiles at the camera's flight destination while the camera is in flight.
  76. * @property {boolean} [preferLeaves=false] Optimization option. Prefer loading of leaves first.
  77. * @property {boolean} [dynamicScreenSpaceError=false] Optimization option. Reduce the screen space error for tiles that are further away from the camera.
  78. * @property {number} [dynamicScreenSpaceErrorDensity=0.00278] Density used to adjust the dynamic screen space error, similar to fog density.
  79. * @property {number} [dynamicScreenSpaceErrorFactor=4.0] A factor used to increase the computed dynamic screen space error.
  80. * @property {number} [dynamicScreenSpaceErrorHeightFalloff=0.25] A ratio of the tileset's height at which the density starts to falloff.
  81. * @property {number} [progressiveResolutionHeightFraction=0.3] Optimization option. If between (0.0, 0.5], tiles at or above the screen space error for the reduced screen resolution of <code>progressiveResolutionHeightFraction*screenHeight</code> will be prioritized first. This can help get a quick layer of tiles down while full resolution tiles continue to load.
  82. * @property {boolean} [foveatedScreenSpaceError=true] Optimization option. Prioritize loading tiles in the center of the screen by temporarily raising the screen space error for tiles around the edge of the screen. Screen space error returns to normal once all the tiles in the center of the screen as determined by the {@link Cesium3DTileset#foveatedConeSize} are loaded.
  83. * @property {number} [foveatedConeSize=0.1] Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control the cone size that determines which tiles are deferred. Tiles that are inside this cone are loaded immediately. Tiles outside the cone are potentially deferred based on how far outside the cone they are and their screen space error. This is controlled by {@link Cesium3DTileset#foveatedInterpolationCallback} and {@link Cesium3DTileset#foveatedMinimumScreenSpaceErrorRelaxation}. Setting this to 0.0 means the cone will be the line formed by the camera position and its view direction. Setting this to 1.0 means the cone encompasses the entire field of view of the camera, disabling the effect.
  84. * @property {number} [foveatedMinimumScreenSpaceErrorRelaxation=0.0] Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control the starting screen space error relaxation for tiles outside the foveated cone. The screen space error will be raised starting with tileset value up to {@link Cesium3DTileset#maximumScreenSpaceError} based on the provided {@link Cesium3DTileset#foveatedInterpolationCallback}.
  85. * @property {Cesium3DTileset.foveatedInterpolationCallback} [foveatedInterpolationCallback=Math.lerp] Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control how much to raise the screen space error for tiles outside the foveated cone, interpolating between {@link Cesium3DTileset#foveatedMinimumScreenSpaceErrorRelaxation} and {@link Cesium3DTileset#maximumScreenSpaceError}
  86. * @property {number} [foveatedTimeDelay=0.2] Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control how long in seconds to wait after the camera stops moving before deferred tiles start loading in. This time delay prevents requesting tiles around the edges of the screen when the camera is moving. Setting this to 0.0 will immediately request all tiles in any given view.
  87. * @property {boolean} [skipLevelOfDetail=false] Optimization option. Determines if level of detail skipping should be applied during the traversal.
  88. * @property {number} [baseScreenSpaceError=1024] When <code>skipLevelOfDetail</code> is <code>true</code>, the screen space error that must be reached before skipping levels of detail.
  89. * @property {number} [skipScreenSpaceErrorFactor=16] When <code>skipLevelOfDetail</code> is <code>true</code>, a multiplier defining the minimum screen space error to skip. Used in conjunction with <code>skipLevels</code> to determine which tiles to load.
  90. * @property {number} [skipLevels=1] When <code>skipLevelOfDetail</code> is <code>true</code>, a constant defining the minimum number of levels to skip when loading tiles. When it is 0, no levels are skipped. Used in conjunction with <code>skipScreenSpaceErrorFactor</code> to determine which tiles to load.
  91. * @property {boolean} [immediatelyLoadDesiredLevelOfDetail=false] When <code>skipLevelOfDetail</code> is <code>true</code>, only tiles that meet the maximum screen space error will ever be downloaded. Skipping factors are ignored and just the desired tiles are loaded.
  92. * @property {boolean} [loadSiblings=false] When <code>skipLevelOfDetail</code> is <code>true</code>, determines whether siblings of visible tiles are always downloaded during traversal.
  93. * @property {ClippingPlaneCollection} [clippingPlanes] The {@link ClippingPlaneCollection} used to selectively disable rendering the tileset.
  94. * @property {ClassificationType} [classificationType] Determines whether terrain, 3D Tiles or both will be classified by this tileset. See {@link Cesium3DTileset#classificationType} for details about restrictions and limitations.
  95. * @property {Ellipsoid} [ellipsoid=Ellipsoid.WGS84] The ellipsoid determining the size and shape of the globe.
  96. * @property {object} [pointCloudShading] Options for constructing a {@link PointCloudShading} object to control point attenuation based on geometric error and lighting.
  97. * @property {Cartesian3} [lightColor] The light color when shading models. When <code>undefined</code> the scene's light color is used instead.
  98. * @property {ImageBasedLighting} [imageBasedLighting] The properties for managing image-based lighting for this tileset.
  99. * @property {boolean} [backFaceCulling=true] Whether to cull back-facing geometry. When true, back face culling is determined by the glTF material's doubleSided property; when false, back face culling is disabled.
  100. * @property {boolean} [enableShowOutline=true] Whether to enable outlines for models using the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. This can be set to false to avoid the additional processing of geometry at load time. When false, the showOutlines and outlineColor options are ignored.
  101. * @property {boolean} [showOutline=true] Whether to display the outline for models using the {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension. When true, outlines are displayed. When false, outlines are not displayed.
  102. * @property {Color} [outlineColor=Color.BLACK] The color to use when rendering outlines.
  103. * @property {boolean} [vectorClassificationOnly=false] Indicates that only the tileset's vector tiles should be used for classification.
  104. * @property {boolean} [vectorKeepDecodedPositions=false] Whether vector tiles should keep decoded positions in memory. This is used with {@link Cesium3DTileFeature.getPolylinePositions}.
  105. * @property {string|number} [featureIdLabel="featureId_0"] Label of the feature ID set to use for picking and styling. For EXT_mesh_features, this is the feature ID's label property, or "featureId_N" (where N is the index in the featureIds array) when not specified. EXT_feature_metadata did not have a label field, so such feature ID sets are always labeled "featureId_N" where N is the index in the list of all feature Ids, where feature ID attributes are listed before feature ID textures. If featureIdLabel is an integer N, it is converted to the string "featureId_N" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.
  106. * @property {string|number} [instanceFeatureIdLabel="instanceFeatureId_0"] Label of the instance feature ID set used for picking and styling. If instanceFeatureIdLabel is set to an integer N, it is converted to the string "instanceFeatureId_N" automatically. If both per-primitive and per-instance feature IDs are present, the instance feature IDs take priority.
  107. * @property {boolean} [showCreditsOnScreen=false] Whether to display the credits of this tileset on screen.
  108. * @property {SplitDirection} [splitDirection=SplitDirection.NONE] The {@link SplitDirection} split to apply to this tileset.
  109. * @property {boolean} [projectTo2D=false] Whether to accurately project the tileset to 2D. If this is true, the tileset will be projected accurately to 2D, but it will use more memory to do so. If this is false, the tileset will use less memory and will still render in 2D / CV mode, but its projected positions may be inaccurate. This cannot be set after the tileset has loaded.
  110. * @property {string} [debugHeatmapTilePropertyName] The tile variable to colorize as a heatmap. All rendered tiles will be colorized relative to each other's specified variable value.
  111. * @property {boolean} [debugFreezeFrame=false] For debugging only. Determines if only the tiles from last frame should be used for rendering.
  112. * @property {boolean} [debugColorizeTiles=false] For debugging only. When true, assigns a random color to each tile.
  113. * @property {boolean} [enableDebugWireframe] For debugging only. This must be true for debugWireframe to work in WebGL1. This cannot be set after the tileset has loaded.
  114. * @property {boolean} [debugWireframe=false] For debugging only. When true, render's each tile's content as a wireframe.
  115. * @property {boolean} [debugShowBoundingVolume=false] For debugging only. When true, renders the bounding volume for each tile.
  116. * @property {boolean} [debugShowContentBoundingVolume=false] For debugging only. When true, renders the bounding volume for each tile's content.
  117. * @property {boolean} [debugShowViewerRequestVolume=false] For debugging only. When true, renders the viewer request volume for each tile.
  118. * @property {boolean} [debugShowGeometricError=false] For debugging only. When true, draws labels to indicate the geometric error of each tile.
  119. * @property {boolean} [debugShowRenderingStatistics=false] For debugging only. When true, draws labels to indicate the number of commands, points, triangles and features for each tile.
  120. * @property {boolean} [debugShowMemoryUsage=false] For debugging only. When true, draws labels to indicate the texture and geometry memory in megabytes used by each tile.
  121. * @property {boolean} [debugShowUrl=false] For debugging only. When true, draws labels to indicate the url of each tile.
  122. */
  123. /**
  124. * A {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles tileset},
  125. * used for streaming massive heterogeneous 3D geospatial datasets.
  126. *
  127. * <div class="notice">
  128. * This object is normally not instantiated directly, use {@link Cesium3DTileset.fromUrl}.
  129. * </div>
  130. *
  131. * @alias Cesium3DTileset
  132. * @constructor
  133. *
  134. * @param {Cesium3DTileset.ConstructorOptions} options An object describing initialization options
  135. *
  136. * @exception {DeveloperError} The tileset must be 3D Tiles version 0.0 or 1.0.
  137. *
  138. * @example
  139. * try {
  140. * const tileset = await Cesium.Cesium3DTileset.fromUrl(
  141. * "http://localhost:8002/tilesets/Seattle/tileset.json"
  142. * );
  143. * scene.primitives.add(tileset);
  144. * } catch (error) {
  145. * console.error(`Error creating tileset: ${error}`);
  146. * }
  147. *
  148. * @example
  149. * // Common setting for the skipLevelOfDetail optimization
  150. * const tileset = await Cesium.Cesium3DTileset.fromUrl(
  151. * "http://localhost:8002/tilesets/Seattle/tileset.json", {
  152. * skipLevelOfDetail: true,
  153. * baseScreenSpaceError: 1024,
  154. * skipScreenSpaceErrorFactor: 16,
  155. * skipLevels: 1,
  156. * immediatelyLoadDesiredLevelOfDetail: false,
  157. * loadSiblings: false,
  158. * cullWithChildrenBounds: true
  159. * });
  160. * scene.primitives.add(tileset);
  161. *
  162. * @example
  163. * // Common settings for the dynamicScreenSpaceError optimization
  164. * const tileset = await Cesium.Cesium3DTileset.fromUrl(
  165. * "http://localhost:8002/tilesets/Seattle/tileset.json", {
  166. * dynamicScreenSpaceError: true,
  167. * dynamicScreenSpaceErrorDensity: 0.00278,
  168. * dynamicScreenSpaceErrorFactor: 4.0,
  169. * dynamicScreenSpaceErrorHeightFalloff: 0.25
  170. * });
  171. * scene.primitives.add(tileset);
  172. *
  173. * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles specification}
  174. */
  175. function Cesium3DTileset(options) {
  176. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  177. this._url = undefined;
  178. this._basePath = undefined;
  179. this._root = undefined;
  180. this._resource = undefined;
  181. this._asset = undefined; // Metadata for the entire tileset
  182. this._properties = undefined; // Metadata for per-model/point/etc properties
  183. this._geometricError = undefined; // Geometric error when the tree is not rendered at all
  184. this._scaledGeometricError = undefined; // Geometric error scaled by root tile scale
  185. this._extensionsUsed = undefined;
  186. this._extensions = undefined;
  187. this._modelUpAxis = undefined;
  188. this._modelForwardAxis = undefined;
  189. this._cache = new Cesium3DTilesetCache();
  190. this._processingQueue = [];
  191. this._selectedTiles = [];
  192. this._emptyTiles = [];
  193. this._requestedTiles = [];
  194. this._selectedTilesToStyle = [];
  195. this._loadTimestamp = undefined;
  196. this._timeSinceLoad = 0.0;
  197. this._updatedVisibilityFrame = 0;
  198. this._updatedModelMatrixFrame = 0;
  199. this._modelMatrixChanged = false;
  200. this._previousModelMatrix = undefined;
  201. this._extras = undefined;
  202. this._credits = undefined;
  203. this._showCreditsOnScreen = defaultValue(options.showCreditsOnScreen, false);
  204. this._cullWithChildrenBounds = defaultValue(
  205. options.cullWithChildrenBounds,
  206. true
  207. );
  208. this._allTilesAdditive = true;
  209. this._hasMixedContent = false;
  210. this._stencilClearCommand = undefined;
  211. this._backfaceCommands = new ManagedArray();
  212. this._maximumScreenSpaceError = defaultValue(
  213. options.maximumScreenSpaceError,
  214. 16
  215. );
  216. this._maximumMemoryUsage = defaultValue(options.maximumMemoryUsage, 512);
  217. this._styleEngine = new Cesium3DTileStyleEngine();
  218. this._styleApplied = false;
  219. this._modelMatrix = defined(options.modelMatrix)
  220. ? Matrix4.clone(options.modelMatrix)
  221. : Matrix4.clone(Matrix4.IDENTITY);
  222. this._statistics = new Cesium3DTilesetStatistics();
  223. this._statisticsLast = new Cesium3DTilesetStatistics();
  224. this._statisticsPerPass = new Array(Cesium3DTilePass.NUMBER_OF_PASSES);
  225. for (let i = 0; i < Cesium3DTilePass.NUMBER_OF_PASSES; ++i) {
  226. this._statisticsPerPass[i] = new Cesium3DTilesetStatistics();
  227. }
  228. this._requestedTilesInFlight = [];
  229. this._maximumPriority = {
  230. foveatedFactor: -Number.MAX_VALUE,
  231. depth: -Number.MAX_VALUE,
  232. distance: -Number.MAX_VALUE,
  233. reverseScreenSpaceError: -Number.MAX_VALUE,
  234. };
  235. this._minimumPriority = {
  236. foveatedFactor: Number.MAX_VALUE,
  237. depth: Number.MAX_VALUE,
  238. distance: Number.MAX_VALUE,
  239. reverseScreenSpaceError: Number.MAX_VALUE,
  240. };
  241. this._heatmap = new Cesium3DTilesetHeatmap(
  242. options.debugHeatmapTilePropertyName
  243. );
  244. /**
  245. * Optimization option. Don't request tiles that will likely be unused when they come back because of the camera's movement. This optimization only applies to stationary tilesets.
  246. *
  247. * @type {boolean}
  248. * @default true
  249. */
  250. this.cullRequestsWhileMoving = defaultValue(
  251. options.cullRequestsWhileMoving,
  252. true
  253. );
  254. this._cullRequestsWhileMoving = false;
  255. /**
  256. * Optimization option. Multiplier used in culling requests while moving. Larger is more aggressive culling, smaller less aggressive culling.
  257. *
  258. * @type {number}
  259. * @default 60.0
  260. */
  261. this.cullRequestsWhileMovingMultiplier = defaultValue(
  262. options.cullRequestsWhileMovingMultiplier,
  263. 60.0
  264. );
  265. /**
  266. * Optimization option. If between (0.0, 0.5], tiles at or above the screen space error for the reduced screen resolution of <code>progressiveResolutionHeightFraction*screenHeight</code> will be prioritized first. This can help get a quick layer of tiles down while full resolution tiles continue to load.
  267. *
  268. * @type {number}
  269. * @default 0.3
  270. */
  271. this.progressiveResolutionHeightFraction = CesiumMath.clamp(
  272. defaultValue(options.progressiveResolutionHeightFraction, 0.3),
  273. 0.0,
  274. 0.5
  275. );
  276. /**
  277. * Optimization option. Prefer loading of leaves first.
  278. *
  279. * @type {boolean}
  280. * @default false
  281. */
  282. this.preferLeaves = defaultValue(options.preferLeaves, false);
  283. this._tilesLoaded = false;
  284. this._initialTilesLoaded = false;
  285. this._tileDebugLabels = undefined;
  286. this._classificationType = options.classificationType;
  287. this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);
  288. this._initialClippingPlanesOriginMatrix = Matrix4.IDENTITY; // Computed from the tileset JSON.
  289. this._clippingPlanesOriginMatrix = undefined; // Combines the above with any run-time transforms.
  290. this._clippingPlanesOriginMatrixDirty = true;
  291. this._vectorClassificationOnly = defaultValue(
  292. options.vectorClassificationOnly,
  293. false
  294. );
  295. this._vectorKeepDecodedPositions = defaultValue(
  296. options.vectorKeepDecodedPositions,
  297. false
  298. );
  299. /**
  300. * Preload tiles when <code>tileset.show</code> is <code>false</code>. Loads tiles as if the tileset is visible but does not render them.
  301. *
  302. * @type {boolean}
  303. * @default false
  304. */
  305. this.preloadWhenHidden = defaultValue(options.preloadWhenHidden, false);
  306. /**
  307. * Optimization option. Fetch tiles at the camera's flight destination while the camera is in flight.
  308. *
  309. * @type {boolean}
  310. * @default true
  311. */
  312. this.preloadFlightDestinations = defaultValue(
  313. options.preloadFlightDestinations,
  314. true
  315. );
  316. this._pass = undefined; // Cesium3DTilePass
  317. /**
  318. * Optimization option. Whether the tileset should refine based on a dynamic screen space error. Tiles that are further
  319. * away will be rendered with lower detail than closer tiles. This improves performance by rendering fewer
  320. * tiles and making less requests, but may result in a slight drop in visual quality for tiles in the distance.
  321. * The algorithm is biased towards "street views" where the camera is close to the ground plane of the tileset and looking
  322. * at the horizon. In addition results are more accurate for tightly fitting bounding volumes like box and region.
  323. *
  324. * @type {boolean}
  325. * @default false
  326. */
  327. this.dynamicScreenSpaceError = defaultValue(
  328. options.dynamicScreenSpaceError,
  329. false
  330. );
  331. /**
  332. * Optimization option. Prioritize loading tiles in the center of the screen by temporarily raising the
  333. * screen space error for tiles around the edge of the screen. Screen space error returns to normal once all
  334. * the tiles in the center of the screen as determined by the {@link Cesium3DTileset#foveatedConeSize} are loaded.
  335. *
  336. * @type {boolean}
  337. * @default true
  338. */
  339. this.foveatedScreenSpaceError = defaultValue(
  340. options.foveatedScreenSpaceError,
  341. true
  342. );
  343. this._foveatedConeSize = defaultValue(options.foveatedConeSize, 0.1);
  344. this._foveatedMinimumScreenSpaceErrorRelaxation = defaultValue(
  345. options.foveatedMinimumScreenSpaceErrorRelaxation,
  346. 0.0
  347. );
  348. /**
  349. * Gets or sets a callback to control how much to raise the screen space error for tiles outside the foveated cone,
  350. * interpolating between {@link Cesium3DTileset#foveatedMinimumScreenSpaceErrorRelaxation} and {@link Cesium3DTileset#maximumScreenSpaceError}.
  351. *
  352. * @type {Cesium3DTileset.foveatedInterpolationCallback}
  353. */
  354. this.foveatedInterpolationCallback = defaultValue(
  355. options.foveatedInterpolationCallback,
  356. CesiumMath.lerp
  357. );
  358. /**
  359. * Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control
  360. * how long in seconds to wait after the camera stops moving before deferred tiles start loading in.
  361. * This time delay prevents requesting tiles around the edges of the screen when the camera is moving.
  362. * Setting this to 0.0 will immediately request all tiles in any given view.
  363. *
  364. * @type {number}
  365. * @default 0.2
  366. */
  367. this.foveatedTimeDelay = defaultValue(options.foveatedTimeDelay, 0.2);
  368. /**
  369. * A scalar that determines the density used to adjust the dynamic screen space error, similar to {@link Fog}. Increasing this
  370. * value has the effect of increasing the maximum screen space error for all tiles, but in a non-linear fashion.
  371. * The error starts at 0.0 and increases exponentially until a midpoint is reached, and then approaches 1.0 asymptotically.
  372. * This has the effect of keeping high detail in the closer tiles and lower detail in the further tiles, with all tiles
  373. * beyond a certain distance all roughly having an error of 1.0.
  374. * <p>
  375. * The dynamic error is in the range [0.0, 1.0) and is multiplied by <code>dynamicScreenSpaceErrorFactor</code> to produce the
  376. * final dynamic error. This dynamic error is then subtracted from the tile's actual screen space error.
  377. * </p>
  378. * <p>
  379. * Increasing <code>dynamicScreenSpaceErrorDensity</code> has the effect of moving the error midpoint closer to the camera.
  380. * It is analogous to moving fog closer to the camera.
  381. * </p>
  382. *
  383. * @type {number}
  384. * @default 0.00278
  385. */
  386. this.dynamicScreenSpaceErrorDensity = 0.00278;
  387. /**
  388. * A factor used to increase the screen space error of tiles for dynamic screen space error. As this value increases less tiles
  389. * are requested for rendering and tiles in the distance will have lower detail. If set to zero, the feature will be disabled.
  390. *
  391. * @type {number}
  392. * @default 4.0
  393. */
  394. this.dynamicScreenSpaceErrorFactor = 4.0;
  395. /**
  396. * A ratio of the tileset's height at which the density starts to falloff. If the camera is below this height the
  397. * full computed density is applied, otherwise the density falls off. This has the effect of higher density at
  398. * street level views.
  399. * <p>
  400. * Valid values are between 0.0 and 1.0.
  401. * </p>
  402. *
  403. * @type {number}
  404. * @default 0.25
  405. */
  406. this.dynamicScreenSpaceErrorHeightFalloff = 0.25;
  407. this._dynamicScreenSpaceErrorComputedDensity = 0.0; // Updated based on the camera position and direction
  408. /**
  409. * Determines whether the tileset casts or receives shadows from light sources.
  410. * <p>
  411. * Enabling shadows has a performance impact. A tileset that casts shadows must be rendered twice, once from the camera and again from the light's point of view.
  412. * </p>
  413. * <p>
  414. * Shadows are rendered only when {@link Viewer#shadows} is <code>true</code>.
  415. * </p>
  416. *
  417. * @type {ShadowMode}
  418. * @default ShadowMode.ENABLED
  419. */
  420. this.shadows = defaultValue(options.shadows, ShadowMode.ENABLED);
  421. /**
  422. * Determines if the tileset will be shown.
  423. *
  424. * @type {boolean}
  425. * @default true
  426. */
  427. this.show = defaultValue(options.show, true);
  428. /**
  429. * Defines how per-feature colors set from the Cesium API or declarative styling blend with the source colors from
  430. * the original feature, e.g. glTF material or per-point color in the tile.
  431. *
  432. * @type {Cesium3DTileColorBlendMode}
  433. * @default Cesium3DTileColorBlendMode.HIGHLIGHT
  434. */
  435. this.colorBlendMode = Cesium3DTileColorBlendMode.HIGHLIGHT;
  436. /**
  437. * Defines the value used to linearly interpolate between the source color and feature color when the {@link Cesium3DTileset#colorBlendMode} is <code>MIX</code>.
  438. * A value of 0.0 results in the source color while a value of 1.0 results in the feature color, with any value in-between
  439. * resulting in a mix of the source color and feature color.
  440. *
  441. * @type {number}
  442. * @default 0.5
  443. */
  444. this.colorBlendAmount = 0.5;
  445. this._pointCloudShading = new PointCloudShading(options.pointCloudShading);
  446. this._pointCloudEyeDomeLighting = new PointCloudEyeDomeLighting();
  447. /**
  448. * The event fired to indicate progress of loading new tiles. This event is fired when a new tile
  449. * is requested, when a requested tile is finished downloading, and when a downloaded tile has been
  450. * processed and is ready to render.
  451. * <p>
  452. * The number of pending tile requests, <code>numberOfPendingRequests</code>, and number of tiles
  453. * processing, <code>numberOfTilesProcessing</code> are passed to the event listener.
  454. * </p>
  455. * <p>
  456. * This event is fired at the end of the frame after the scene is rendered.
  457. * </p>
  458. *
  459. * @type {Event}
  460. * @default new Event()
  461. *
  462. * @example
  463. * tileset.loadProgress.addEventListener(function(numberOfPendingRequests, numberOfTilesProcessing) {
  464. * if ((numberOfPendingRequests === 0) && (numberOfTilesProcessing === 0)) {
  465. * console.log('Stopped loading');
  466. * return;
  467. * }
  468. *
  469. * console.log(`Loading: requests: ${numberOfPendingRequests}, processing: ${numberOfTilesProcessing}`);
  470. * });
  471. */
  472. this.loadProgress = new Event();
  473. /**
  474. * The event fired to indicate that all tiles that meet the screen space error this frame are loaded. The tileset
  475. * is completely loaded for this view.
  476. * <p>
  477. * This event is fired at the end of the frame after the scene is rendered.
  478. * </p>
  479. *
  480. * @type {Event}
  481. * @default new Event()
  482. *
  483. * @example
  484. * tileset.allTilesLoaded.addEventListener(function() {
  485. * console.log('All tiles are loaded');
  486. * });
  487. *
  488. * @see Cesium3DTileset#tilesLoaded
  489. */
  490. this.allTilesLoaded = new Event();
  491. /**
  492. * The event fired to indicate that all tiles that meet the screen space error this frame are loaded. This event
  493. * is fired once when all tiles in the initial view are loaded.
  494. * <p>
  495. * This event is fired at the end of the frame after the scene is rendered.
  496. * </p>
  497. *
  498. * @type {Event}
  499. * @default new Event()
  500. *
  501. * @example
  502. * tileset.initialTilesLoaded.addEventListener(function() {
  503. * console.log('Initial tiles are loaded');
  504. * });
  505. *
  506. * @see Cesium3DTileset#allTilesLoaded
  507. */
  508. this.initialTilesLoaded = new Event();
  509. /**
  510. * The event fired to indicate that a tile's content was loaded.
  511. * <p>
  512. * The loaded {@link Cesium3DTile} is passed to the event listener.
  513. * </p>
  514. * <p>
  515. * This event is fired during the tileset traversal while the frame is being rendered
  516. * so that updates to the tile take effect in the same frame. Do not create or modify
  517. * Cesium entities or primitives during the event listener.
  518. * </p>
  519. *
  520. * @type {Event}
  521. * @default new Event()
  522. *
  523. * @example
  524. * tileset.tileLoad.addEventListener(function(tile) {
  525. * console.log('A tile was loaded.');
  526. * });
  527. */
  528. this.tileLoad = new Event();
  529. /**
  530. * The event fired to indicate that a tile's content was unloaded.
  531. * <p>
  532. * The unloaded {@link Cesium3DTile} is passed to the event listener.
  533. * </p>
  534. * <p>
  535. * This event is fired immediately before the tile's content is unloaded while the frame is being
  536. * rendered so that the event listener has access to the tile's content. Do not create
  537. * or modify Cesium entities or primitives during the event listener.
  538. * </p>
  539. *
  540. * @type {Event}
  541. * @default new Event()
  542. *
  543. * @example
  544. * tileset.tileUnload.addEventListener(function(tile) {
  545. * console.log('A tile was unloaded from the cache.');
  546. * });
  547. *
  548. * @see Cesium3DTileset#maximumMemoryUsage
  549. * @see Cesium3DTileset#trimLoadedTiles
  550. */
  551. this.tileUnload = new Event();
  552. /**
  553. * The event fired to indicate that a tile's content failed to load.
  554. * <p>
  555. * If there are no event listeners, error messages will be logged to the console.
  556. * </p>
  557. * <p>
  558. * The error object passed to the listener contains two properties:
  559. * <ul>
  560. * <li><code>url</code>: the url of the failed tile.</li>
  561. * <li><code>message</code>: the error message.</li>
  562. * </ul>
  563. * <p>
  564. * If multiple contents are present, this event is raised once per inner content with errors.
  565. * </p>
  566. *
  567. * @type {Event}
  568. * @default new Event()
  569. *
  570. * @example
  571. * tileset.tileFailed.addEventListener(function(error) {
  572. * console.log(`An error occurred loading tile: ${error.url}`);
  573. * console.log(`Error: ${error.message}`);
  574. * });
  575. */
  576. this.tileFailed = new Event();
  577. /**
  578. * This event fires once for each visible tile in a frame. This can be used to manually
  579. * style a tileset.
  580. * <p>
  581. * The visible {@link Cesium3DTile} is passed to the event listener.
  582. * </p>
  583. * <p>
  584. * This event is fired during the tileset traversal while the frame is being rendered
  585. * so that updates to the tile take effect in the same frame. Do not create or modify
  586. * Cesium entities or primitives during the event listener.
  587. * </p>
  588. *
  589. * @type {Event}
  590. * @default new Event()
  591. *
  592. * @example
  593. * tileset.tileVisible.addEventListener(function(tile) {
  594. * if (tile.content instanceof Cesium.Model3DTileContent) {
  595. * console.log('A 3D model tile is visible.');
  596. * }
  597. * });
  598. *
  599. * @example
  600. * // Apply a red style and then manually set random colors for every other feature when the tile becomes visible.
  601. * tileset.style = new Cesium.Cesium3DTileStyle({
  602. * color : 'color("red")'
  603. * });
  604. * tileset.tileVisible.addEventListener(function(tile) {
  605. * const content = tile.content;
  606. * const featuresLength = content.featuresLength;
  607. * for (let i = 0; i < featuresLength; i+=2) {
  608. * content.getFeature(i).color = Cesium.Color.fromRandom();
  609. * }
  610. * });
  611. */
  612. this.tileVisible = new Event();
  613. /**
  614. * Optimization option. Determines if level of detail skipping should be applied during the traversal.
  615. * <p>
  616. * The common strategy for replacement-refinement traversal is to store all levels of the tree in memory and require
  617. * all children to be loaded before the parent can refine. With this optimization levels of the tree can be skipped
  618. * entirely and children can be rendered alongside their parents. The tileset requires significantly less memory when
  619. * using this optimization.
  620. * </p>
  621. *
  622. * @type {boolean}
  623. * @default false
  624. */
  625. this.skipLevelOfDetail = defaultValue(options.skipLevelOfDetail, false);
  626. this._disableSkipLevelOfDetail = false;
  627. /**
  628. * The screen space error that must be reached before skipping levels of detail.
  629. * <p>
  630. * Only used when {@link Cesium3DTileset#skipLevelOfDetail} is <code>true</code>.
  631. * </p>
  632. *
  633. * @type {number}
  634. * @default 1024
  635. */
  636. this.baseScreenSpaceError = defaultValue(options.baseScreenSpaceError, 1024);
  637. /**
  638. * Multiplier defining the minimum screen space error to skip.
  639. * For example, if a tile has screen space error of 100, no tiles will be loaded unless they
  640. * are leaves or have a screen space error <code><= 100 / skipScreenSpaceErrorFactor</code>.
  641. * <p>
  642. * Only used when {@link Cesium3DTileset#skipLevelOfDetail} is <code>true</code>.
  643. * </p>
  644. *
  645. * @type {number}
  646. * @default 16
  647. */
  648. this.skipScreenSpaceErrorFactor = defaultValue(
  649. options.skipScreenSpaceErrorFactor,
  650. 16
  651. );
  652. /**
  653. * Constant defining the minimum number of levels to skip when loading tiles. When it is 0, no levels are skipped.
  654. * For example, if a tile is level 1, no tiles will be loaded unless they are at level greater than 2.
  655. * <p>
  656. * Only used when {@link Cesium3DTileset#skipLevelOfDetail} is <code>true</code>.
  657. * </p>
  658. *
  659. * @type {number}
  660. * @default 1
  661. */
  662. this.skipLevels = defaultValue(options.skipLevels, 1);
  663. /**
  664. * When true, only tiles that meet the maximum screen space error will ever be downloaded.
  665. * Skipping factors are ignored and just the desired tiles are loaded.
  666. * <p>
  667. * Only used when {@link Cesium3DTileset#skipLevelOfDetail} is <code>true</code>.
  668. * </p>
  669. *
  670. * @type {boolean}
  671. * @default false
  672. */
  673. this.immediatelyLoadDesiredLevelOfDetail = defaultValue(
  674. options.immediatelyLoadDesiredLevelOfDetail,
  675. false
  676. );
  677. /**
  678. * Determines whether siblings of visible tiles are always downloaded during traversal.
  679. * This may be useful for ensuring that tiles are already available when the viewer turns left/right.
  680. * <p>
  681. * Only used when {@link Cesium3DTileset#skipLevelOfDetail} is <code>true</code>.
  682. * </p>
  683. *
  684. * @type {boolean}
  685. * @default false
  686. */
  687. this.loadSiblings = defaultValue(options.loadSiblings, false);
  688. this._clippingPlanes = undefined;
  689. this.clippingPlanes = options.clippingPlanes;
  690. if (defined(options.imageBasedLighting)) {
  691. this._imageBasedLighting = options.imageBasedLighting;
  692. this._shouldDestroyImageBasedLighting = false;
  693. } else {
  694. this._imageBasedLighting = new ImageBasedLighting();
  695. this._shouldDestroyImageBasedLighting = true;
  696. }
  697. /**
  698. * The light color when shading models. When <code>undefined</code> the scene's light color is used instead.
  699. * <p>
  700. * For example, disabling additional light sources by setting
  701. * <code>tileset.imageBasedLighting.imageBasedLightingFactor = new Cartesian2(0.0, 0.0)</code>
  702. * will make the tileset much darker. Here, increasing the intensity of the light source will make the tileset brighter.
  703. * </p>
  704. *
  705. * @type {Cartesian3}
  706. * @default undefined
  707. */
  708. this.lightColor = options.lightColor;
  709. /**
  710. * Whether to cull back-facing geometry. When true, back face culling is determined
  711. * by the glTF material's doubleSided property; when false, back face culling is disabled.
  712. *
  713. * @type {boolean}
  714. * @default true
  715. */
  716. this.backFaceCulling = defaultValue(options.backFaceCulling, true);
  717. this._enableShowOutline = defaultValue(options.enableShowOutline, true);
  718. /**
  719. * Whether to display the outline for models using the
  720. * {@link https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/CESIUM_primitive_outline|CESIUM_primitive_outline} extension.
  721. * When true, outlines are displayed. When false, outlines are not displayed.
  722. *
  723. * @type {boolean}
  724. * @default true
  725. */
  726. this.showOutline = defaultValue(options.showOutline, true);
  727. /**
  728. * The color to use when rendering outlines.
  729. *
  730. * @type {Color}
  731. * @default Color.BLACK
  732. */
  733. this.outlineColor = defaultValue(options.outlineColor, Color.BLACK);
  734. /**
  735. * The {@link SplitDirection} to apply to this tileset.
  736. *
  737. * @type {SplitDirection}
  738. * @default {@link SplitDirection.NONE}
  739. */
  740. this.splitDirection = defaultValue(
  741. options.splitDirection,
  742. SplitDirection.NONE
  743. );
  744. this._projectTo2D = defaultValue(options.projectTo2D, false);
  745. /**
  746. * This property is for debugging only; it is not optimized for production use.
  747. * <p>
  748. * Determines if only the tiles from last frame should be used for rendering. This
  749. * effectively "freezes" the tileset to the previous frame so it is possible to zoom
  750. * out and see what was rendered.
  751. * </p>
  752. *
  753. * @type {boolean}
  754. * @default false
  755. */
  756. this.debugFreezeFrame = defaultValue(options.debugFreezeFrame, false);
  757. /**
  758. * This property is for debugging only; it is not optimized for production use.
  759. * <p>
  760. * When true, assigns a random color to each tile. This is useful for visualizing
  761. * what features belong to what tiles, especially with additive refinement where features
  762. * from parent tiles may be interleaved with features from child tiles.
  763. * </p>
  764. *
  765. * @type {boolean}
  766. * @default false
  767. */
  768. this.debugColorizeTiles = defaultValue(options.debugColorizeTiles, false);
  769. this._enableDebugWireframe = defaultValue(
  770. options.enableDebugWireframe,
  771. false
  772. );
  773. /**
  774. * This property is for debugging only; it is not optimized for production use.
  775. * <p>
  776. * When true, renders each tile's content as a wireframe.
  777. * </p>
  778. *
  779. * @type {boolean}
  780. * @default false
  781. */
  782. this.debugWireframe = defaultValue(options.debugWireframe, false);
  783. // Warning for improper setup of debug wireframe
  784. if (this.debugWireframe === true && this._enableDebugWireframe === false) {
  785. oneTimeWarning(
  786. "tileset-debug-wireframe-ignored",
  787. "enableDebugWireframe must be set to true in the Cesium3DTileset constructor, otherwise debugWireframe will be ignored."
  788. );
  789. }
  790. /**
  791. * This property is for debugging only; it is not optimized for production use.
  792. * <p>
  793. * When true, renders the bounding volume for each visible tile. The bounding volume is
  794. * white if the tile has a content bounding volume or is empty; otherwise, it is red. Tiles that don't meet the
  795. * screen space error and are still refining to their descendants are yellow.
  796. * </p>
  797. *
  798. * @type {boolean}
  799. * @default false
  800. */
  801. this.debugShowBoundingVolume = defaultValue(
  802. options.debugShowBoundingVolume,
  803. false
  804. );
  805. /**
  806. * This property is for debugging only; it is not optimized for production use.
  807. * <p>
  808. * When true, renders the bounding volume for each visible tile's content. The bounding volume is
  809. * blue if the tile has a content bounding volume; otherwise it is red.
  810. * </p>
  811. *
  812. * @type {boolean}
  813. * @default false
  814. */
  815. this.debugShowContentBoundingVolume = defaultValue(
  816. options.debugShowContentBoundingVolume,
  817. false
  818. );
  819. /**
  820. * This property is for debugging only; it is not optimized for production use.
  821. * <p>
  822. * When true, renders the viewer request volume for each tile.
  823. * </p>
  824. *
  825. * @type {boolean}
  826. * @default false
  827. */
  828. this.debugShowViewerRequestVolume = defaultValue(
  829. options.debugShowViewerRequestVolume,
  830. false
  831. );
  832. /**
  833. * @private
  834. * @type {LabelCollection|undefined}
  835. */
  836. this._tileDebugLabels = undefined;
  837. this.debugPickedTileLabelOnly = false;
  838. this.debugPickedTile = undefined;
  839. this.debugPickPosition = undefined;
  840. /**
  841. * This property is for debugging only; it is not optimized for production use.
  842. * <p>
  843. * When true, draws labels to indicate the geometric error of each tile.
  844. * </p>
  845. *
  846. * @type {boolean}
  847. * @default false
  848. */
  849. this.debugShowGeometricError = defaultValue(
  850. options.debugShowGeometricError,
  851. false
  852. );
  853. /**
  854. * This property is for debugging only; it is not optimized for production use.
  855. * <p>
  856. * When true, draws labels to indicate the number of commands, points, triangles and features of each tile.
  857. * </p>
  858. *
  859. * @type {boolean}
  860. * @default false
  861. */
  862. this.debugShowRenderingStatistics = defaultValue(
  863. options.debugShowRenderingStatistics,
  864. false
  865. );
  866. /**
  867. * This property is for debugging only; it is not optimized for production use.
  868. * <p>
  869. * When true, draws labels to indicate the geometry and texture memory usage of each tile.
  870. * </p>
  871. *
  872. * @type {boolean}
  873. * @default false
  874. */
  875. this.debugShowMemoryUsage = defaultValue(options.debugShowMemoryUsage, false);
  876. /**
  877. * This property is for debugging only; it is not optimized for production use.
  878. * <p>
  879. * When true, draws labels to indicate the url of each tile.
  880. * </p>
  881. *
  882. * @type {boolean}
  883. * @default false
  884. */
  885. this.debugShowUrl = defaultValue(options.debugShowUrl, false);
  886. /**
  887. * Function for examining vector lines as they are being streamed.
  888. *
  889. * @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.
  890. *
  891. * @type {Function}
  892. */
  893. this.examineVectorLinesFunction = undefined;
  894. // this is the underlying Cesium3DTileMetadata object, whether it came from
  895. // the 3DTILES_metadata extension or a 3D Tiles 1.1 tileset JSON. Getters
  896. // like tileset.metadata and tileset.schema will delegate to this object.
  897. this._metadataExtension = undefined;
  898. this._customShader = options.customShader;
  899. let featureIdLabel = defaultValue(options.featureIdLabel, "featureId_0");
  900. if (typeof featureIdLabel === "number") {
  901. featureIdLabel = `featureId_${featureIdLabel}`;
  902. }
  903. this._featureIdLabel = featureIdLabel;
  904. let instanceFeatureIdLabel = defaultValue(
  905. options.instanceFeatureIdLabel,
  906. "instanceFeatureId_0"
  907. );
  908. if (typeof instanceFeatureIdLabel === "number") {
  909. instanceFeatureIdLabel = `instanceFeatureId_${instanceFeatureIdLabel}`;
  910. }
  911. this._instanceFeatureIdLabel = instanceFeatureIdLabel;
  912. if (defined(options.url)) {
  913. deprecationWarning(
  914. "Cesium3DTileset options.url",
  915. "Cesium3DTileset constructor parameter options.url was deprecated in CesiumJS 1.104. It will be removed in 1.107. Use Cesium3DTileset.fromUrl instead."
  916. );
  917. const that = this;
  918. let resource;
  919. this._readyPromise = Promise.resolve(options.url)
  920. .then(function (url) {
  921. let basePath;
  922. resource = Resource.createIfNeeded(url);
  923. that._resource = resource;
  924. // ion resources have a credits property we can use for additional attribution.
  925. that._credits = resource.credits;
  926. if (resource.extension === "json") {
  927. basePath = resource.getBaseUri(true);
  928. } else if (resource.isDataUri) {
  929. basePath = "";
  930. }
  931. that._url = resource.url;
  932. that._basePath = basePath;
  933. return Cesium3DTileset.loadJson(resource);
  934. })
  935. .then(function (tilesetJson) {
  936. if (that.isDestroyed()) {
  937. return;
  938. }
  939. // This needs to be called before loadTileset() so tile metadata
  940. // can be initialized synchronously in the Cesium3DTile constructor
  941. return processMetadataExtension(resource, tilesetJson).then(
  942. (metadata) => {
  943. that._metadataExtension = metadata;
  944. return tilesetJson;
  945. }
  946. );
  947. })
  948. .then(function (tilesetJson) {
  949. if (that.isDestroyed()) {
  950. return;
  951. }
  952. // Set these before loading the tileset since _geometricError
  953. // and _scaledGeometricError get accessed during tile creation
  954. that._geometricError = tilesetJson.geometricError;
  955. that._scaledGeometricError = tilesetJson.geometricError;
  956. that._root = that.loadTileset(resource, tilesetJson);
  957. // Handle legacy gltfUpAxis option
  958. const gltfUpAxis = defined(tilesetJson.asset.gltfUpAxis)
  959. ? Axis.fromName(tilesetJson.asset.gltfUpAxis)
  960. : Axis.Y;
  961. const modelUpAxis = defaultValue(options.modelUpAxis, gltfUpAxis);
  962. const modelForwardAxis = defaultValue(options.modelForwardAxis, Axis.X);
  963. const asset = tilesetJson.asset;
  964. that._asset = asset;
  965. that._properties = tilesetJson.properties;
  966. that._extensionsUsed = tilesetJson.extensionsUsed;
  967. that._extensions = tilesetJson.extensions;
  968. that._modelUpAxis = modelUpAxis;
  969. that._modelForwardAxis = modelForwardAxis;
  970. that._extras = tilesetJson.extras;
  971. const extras = asset.extras;
  972. if (
  973. defined(extras) &&
  974. defined(extras.cesium) &&
  975. defined(extras.cesium.credits)
  976. ) {
  977. const extraCredits = extras.cesium.credits;
  978. let credits = that._credits;
  979. if (!defined(credits)) {
  980. credits = [];
  981. that._credits = credits;
  982. }
  983. for (let i = 0; i < extraCredits.length; ++i) {
  984. const credit = extraCredits[i];
  985. credits.push(new Credit(credit.html, that._showCreditsOnScreen));
  986. }
  987. }
  988. // Save the original, untransformed bounding volume position so we can apply
  989. // the tile transform and model matrix at run time
  990. const boundingVolume = that._root.createBoundingVolume(
  991. tilesetJson.root.boundingVolume,
  992. Matrix4.IDENTITY
  993. );
  994. const clippingPlanesOrigin = boundingVolume.boundingSphere.center;
  995. // If this origin is above the surface of the earth
  996. // we want to apply an ENU orientation as our best guess of orientation.
  997. // Otherwise, we assume it gets its position/orientation completely from the
  998. // root tile transform and the tileset's model matrix
  999. const originCartographic = that._ellipsoid.cartesianToCartographic(
  1000. clippingPlanesOrigin
  1001. );
  1002. if (
  1003. defined(originCartographic) &&
  1004. originCartographic.height >
  1005. ApproximateTerrainHeights._defaultMinTerrainHeight
  1006. ) {
  1007. that._initialClippingPlanesOriginMatrix = Transforms.eastNorthUpToFixedFrame(
  1008. clippingPlanesOrigin
  1009. );
  1010. }
  1011. that._clippingPlanesOriginMatrix = Matrix4.clone(
  1012. that._initialClippingPlanesOriginMatrix
  1013. );
  1014. return that;
  1015. });
  1016. }
  1017. }
  1018. Object.defineProperties(Cesium3DTileset.prototype, {
  1019. /**
  1020. * NOTE: This getter exists so that `Picking.js` can differentiate between
  1021. * PrimitiveCollection and Cesium3DTileset objects without inflating
  1022. * the size of the module via `instanceof Cesium3DTileset`
  1023. * @private
  1024. */
  1025. isCesium3DTileset: {
  1026. get: function () {
  1027. return true;
  1028. },
  1029. },
  1030. /**
  1031. * Gets the tileset's asset object property, which contains metadata about the tileset.
  1032. * <p>
  1033. * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification#reference-asset|asset schema reference}
  1034. * in the 3D Tiles spec for the full set of properties.
  1035. * </p>
  1036. *
  1037. * @memberof Cesium3DTileset.prototype
  1038. *
  1039. * @type {object}
  1040. * @readonly
  1041. */
  1042. asset: {
  1043. get: function () {
  1044. return this._asset;
  1045. },
  1046. },
  1047. /**
  1048. * Gets the tileset's extensions object property.
  1049. *
  1050. * @memberof Cesium3DTileset.prototype
  1051. *
  1052. * @type {object}
  1053. * @readonly
  1054. */
  1055. extensions: {
  1056. get: function () {
  1057. return this._extensions;
  1058. },
  1059. },
  1060. /**
  1061. * The {@link ClippingPlaneCollection} used to selectively disable rendering the tileset.
  1062. *
  1063. * @memberof Cesium3DTileset.prototype
  1064. *
  1065. * @type {ClippingPlaneCollection}
  1066. */
  1067. clippingPlanes: {
  1068. get: function () {
  1069. return this._clippingPlanes;
  1070. },
  1071. set: function (value) {
  1072. ClippingPlaneCollection.setOwner(value, this, "_clippingPlanes");
  1073. },
  1074. },
  1075. /**
  1076. * Gets the tileset's properties dictionary object, which contains metadata about per-feature properties.
  1077. * <p>
  1078. * See the {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification#reference-properties|properties schema reference}
  1079. * in the 3D Tiles spec for the full set of properties.
  1080. * </p>
  1081. *
  1082. * @memberof Cesium3DTileset.prototype
  1083. *
  1084. * @type {object}
  1085. * @readonly
  1086. *
  1087. * @example
  1088. * console.log(`Maximum building height: ${tileset.properties.height.maximum}`);
  1089. * console.log(`Minimum building height: ${tileset.properties.height.minimum}`);
  1090. *
  1091. * @see Cesium3DTileFeature#getProperty
  1092. * @see Cesium3DTileFeature#setProperty
  1093. */
  1094. properties: {
  1095. get: function () {
  1096. return this._properties;
  1097. },
  1098. },
  1099. /**
  1100. * When <code>true</code>, the tileset's root tile is loaded and the tileset is ready to render.
  1101. *
  1102. * @memberof Cesium3DTileset.prototype
  1103. *
  1104. * @type {boolean}
  1105. * @readonly
  1106. *
  1107. * @default false
  1108. */
  1109. ready: {
  1110. get: function () {
  1111. deprecationWarning(
  1112. "Cesium3DTileset.ready",
  1113. "Cesium3DTileset.ready was deprecated in CesiumJS 1.104. It will be removed in 1.107. Use Cesium3DTileset.fromUrl instead."
  1114. );
  1115. return defined(this._root);
  1116. },
  1117. },
  1118. /**
  1119. * Gets the promise that will be resolved when the tileset's root tile is loaded and the tileset is ready to render.
  1120. * <p>
  1121. * This promise is resolved at the end of the frame before the first frame the tileset is rendered in.
  1122. * </p>
  1123. *
  1124. * @memberof Cesium3DTileset.prototype
  1125. *
  1126. * @type {Promise<Cesium3DTileset>}
  1127. * @readonly
  1128. * @deprecated
  1129. *
  1130. * @example
  1131. * tileset.readyPromise.then(function(tileset) {
  1132. * // tile.properties is not defined until readyPromise resolves.
  1133. * const properties = tileset.properties;
  1134. * if (Cesium.defined(properties)) {
  1135. * for (const name in properties) {
  1136. * console.log(properties[name]);
  1137. * }
  1138. * }
  1139. * });
  1140. */
  1141. readyPromise: {
  1142. get: function () {
  1143. deprecationWarning(
  1144. "Cesium3DTileset.readyPromise",
  1145. "Cesium3DTileset.readyPromise was deprecated in CesiumJS 1.104. It will be removed in 1.107. Use Cesium3DTileset.fromUrl instead."
  1146. );
  1147. return this._readyPromise;
  1148. },
  1149. },
  1150. /**
  1151. * When <code>true</code>, all tiles that meet the screen space error this frame are loaded. The tileset is
  1152. * completely loaded for this view.
  1153. *
  1154. * @memberof Cesium3DTileset.prototype
  1155. *
  1156. * @type {boolean}
  1157. * @readonly
  1158. *
  1159. * @default false
  1160. *
  1161. * @see Cesium3DTileset#allTilesLoaded
  1162. */
  1163. tilesLoaded: {
  1164. get: function () {
  1165. return this._tilesLoaded;
  1166. },
  1167. },
  1168. /**
  1169. * The resource used to fetch the tileset JSON file
  1170. *
  1171. * @memberof Cesium3DTileset.prototype
  1172. *
  1173. * @type {Resource}
  1174. * @readonly
  1175. */
  1176. resource: {
  1177. get: function () {
  1178. return this._resource;
  1179. },
  1180. },
  1181. /**
  1182. * The base path that non-absolute paths in tileset JSON file are relative to.
  1183. *
  1184. * @memberof Cesium3DTileset.prototype
  1185. *
  1186. * @type {string}
  1187. * @readonly
  1188. * @deprecated
  1189. */
  1190. basePath: {
  1191. get: function () {
  1192. deprecationWarning(
  1193. "Cesium3DTileset.basePath",
  1194. "Cesium3DTileset.basePath has been deprecated. All tiles are relative to the url of the tileset JSON file that contains them. Use the url property instead."
  1195. );
  1196. return this._basePath;
  1197. },
  1198. },
  1199. /**
  1200. * The style, defined using the
  1201. * {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Styling|3D Tiles Styling language},
  1202. * applied to each feature in the tileset.
  1203. * <p>
  1204. * Assign <code>undefined</code> to remove the style, which will restore the visual
  1205. * appearance of the tileset to its default when no style was applied.
  1206. * </p>
  1207. * <p>
  1208. * The style is applied to a tile before the {@link Cesium3DTileset#tileVisible}
  1209. * event is raised, so code in <code>tileVisible</code> can manually set a feature's
  1210. * properties (e.g. color and show) after the style is applied. When
  1211. * a new style is assigned any manually set properties are overwritten.
  1212. * </p>
  1213. * <p>
  1214. * Use an always "true" condition to specify the Color for all objects that are not
  1215. * overridden by pre-existing conditions. Otherwise, the default color Cesium.Color.White
  1216. * will be used. Similarly, use an always "true" condition to specify the show property
  1217. * for all objects that are not overridden by pre-existing conditions. Otherwise, the
  1218. * default show value true will be used.
  1219. * </p>
  1220. *
  1221. * @memberof Cesium3DTileset.prototype
  1222. *
  1223. * @type {Cesium3DTileStyle|undefined}
  1224. *
  1225. * @default undefined
  1226. *
  1227. * @example
  1228. * tileset.style = new Cesium.Cesium3DTileStyle({
  1229. * color : {
  1230. * conditions : [
  1231. * ['${Height} >= 100', 'color("purple", 0.5)'],
  1232. * ['${Height} >= 50', 'color("red")'],
  1233. * ['true', 'color("blue")']
  1234. * ]
  1235. * },
  1236. * show : '${Height} > 0',
  1237. * meta : {
  1238. * description : '"Building id ${id} has height ${Height}."'
  1239. * }
  1240. * });
  1241. *
  1242. * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification/Styling|3D Tiles Styling language}
  1243. */
  1244. style: {
  1245. get: function () {
  1246. return this._styleEngine.style;
  1247. },
  1248. set: function (value) {
  1249. this._styleEngine.style = value;
  1250. },
  1251. },
  1252. /**
  1253. * A custom shader to apply to all tiles in the tileset. Only used for
  1254. * contents that use {@link Model}. Using custom shaders with a
  1255. * {@link Cesium3DTileStyle} may lead to undefined behavior.
  1256. *
  1257. * @memberof Cesium3DTileset.prototype
  1258. *
  1259. * @type {CustomShader|undefined}
  1260. *
  1261. * @default undefined
  1262. *
  1263. * @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.
  1264. */
  1265. customShader: {
  1266. get: function () {
  1267. return this._customShader;
  1268. },
  1269. set: function (value) {
  1270. this._customShader = value;
  1271. },
  1272. },
  1273. /**
  1274. * Whether the tileset is rendering different levels of detail in the same view.
  1275. * Only relevant if {@link Cesium3DTileset.isSkippingLevelOfDetail} is true.
  1276. *
  1277. * @memberof Cesium3DTileset.prototype
  1278. *
  1279. * @type {boolean}
  1280. * @private
  1281. */
  1282. hasMixedContent: {
  1283. get: function () {
  1284. return this._hasMixedContent;
  1285. },
  1286. set: function (value) {
  1287. //>>includeStart('debug', pragmas.debug);
  1288. Check.typeOf.bool("value", value);
  1289. //>>includeEnd('debug');
  1290. this._hasMixedContent = value;
  1291. },
  1292. },
  1293. /**
  1294. * Whether this tileset is actually skipping levels of detail.
  1295. * The user option may have been disabled if all tiles are using additive refinement,
  1296. * or if some tiles have a content type for which rendering does not support skipping
  1297. *
  1298. * @memberof Cesium3DTileset.prototype
  1299. *
  1300. * @type {boolean}
  1301. * @private
  1302. * @readonly
  1303. */
  1304. isSkippingLevelOfDetail: {
  1305. get: function () {
  1306. return (
  1307. this.skipLevelOfDetail &&
  1308. !defined(this._classificationType) &&
  1309. !this._disableSkipLevelOfDetail &&
  1310. !this._allTilesAdditive
  1311. );
  1312. },
  1313. },
  1314. /**
  1315. * The tileset's schema, groups, tileset metadata and other details from the
  1316. * 3DTILES_metadata extension or a 3D Tiles 1.1 tileset JSON. This getter is
  1317. * for internal use by other classes.
  1318. *
  1319. * @memberof Cesium3DTileset.prototype
  1320. * @type {Cesium3DTilesetMetadata}
  1321. * @private
  1322. * @readonly
  1323. *
  1324. * @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.
  1325. */
  1326. metadataExtension: {
  1327. get: function () {
  1328. return this._metadataExtension;
  1329. },
  1330. },
  1331. /**
  1332. * The metadata properties attached to the tileset as a whole.
  1333. *
  1334. * @memberof Cesium3DTileset.prototype
  1335. *
  1336. * @type {TilesetMetadata}
  1337. * @private
  1338. * @readonly
  1339. *
  1340. * @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.
  1341. */
  1342. metadata: {
  1343. get: function () {
  1344. if (defined(this._metadataExtension)) {
  1345. return this._metadataExtension.tileset;
  1346. }
  1347. return undefined;
  1348. },
  1349. },
  1350. /**
  1351. * The metadata schema used in this tileset. Shorthand for
  1352. * <code>tileset.metadataExtension.schema</code>
  1353. *
  1354. * @memberof Cesium3DTileset.prototype
  1355. *
  1356. * @type {MetadataSchema}
  1357. * @private
  1358. * @readonly
  1359. *
  1360. * @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.
  1361. */
  1362. schema: {
  1363. get: function () {
  1364. if (defined(this._metadataExtension)) {
  1365. return this._metadataExtension.schema;
  1366. }
  1367. return undefined;
  1368. },
  1369. },
  1370. /**
  1371. * The maximum screen space error used to drive level of detail refinement. This value helps determine when a tile
  1372. * refines to its descendants, and therefore plays a major role in balancing performance with visual quality.
  1373. * <p>
  1374. * A tile's screen space error is roughly equivalent to the number of pixels wide that would be drawn if a sphere with a
  1375. * radius equal to the tile's <b>geometric error</b> were rendered at the tile's position. If this value exceeds
  1376. * <code>maximumScreenSpaceError</code> the tile refines to its descendants.
  1377. * </p>
  1378. * <p>
  1379. * Depending on the tileset, <code>maximumScreenSpaceError</code> may need to be tweaked to achieve the right balance.
  1380. * Higher values provide better performance but lower visual quality.
  1381. * </p>
  1382. *
  1383. * @memberof Cesium3DTileset.prototype
  1384. *
  1385. * @type {number}
  1386. * @default 16
  1387. *
  1388. * @exception {DeveloperError} <code>maximumScreenSpaceError</code> must be greater than or equal to zero.
  1389. */
  1390. maximumScreenSpaceError: {
  1391. get: function () {
  1392. return this._maximumScreenSpaceError;
  1393. },
  1394. set: function (value) {
  1395. //>>includeStart('debug', pragmas.debug);
  1396. Check.typeOf.number.greaterThanOrEquals(
  1397. "maximumScreenSpaceError",
  1398. value,
  1399. 0
  1400. );
  1401. //>>includeEnd('debug');
  1402. this._maximumScreenSpaceError = value;
  1403. },
  1404. },
  1405. /**
  1406. * The maximum amount of GPU memory (in MB) that may be used to cache tiles. This value is estimated from
  1407. * geometry, textures, and batch table textures of loaded tiles. For point clouds, this value also
  1408. * includes per-point metadata.
  1409. * <p>
  1410. * Tiles not in view are unloaded to enforce this.
  1411. * </p>
  1412. * <p>
  1413. * If decreasing this value results in unloading tiles, the tiles are unloaded the next frame.
  1414. * </p>
  1415. * <p>
  1416. * If tiles sized more than <code>maximumMemoryUsage</code> are needed
  1417. * to meet the desired screen space error, determined by {@link Cesium3DTileset#maximumScreenSpaceError},
  1418. * for the current view, then the memory usage of the tiles loaded will exceed
  1419. * <code>maximumMemoryUsage</code>. For example, if the maximum is 256 MB, but
  1420. * 300 MB of tiles are needed to meet the screen space error, then 300 MB of tiles may be loaded. When
  1421. * these tiles go out of view, they will be unloaded.
  1422. * </p>
  1423. *
  1424. * @memberof Cesium3DTileset.prototype
  1425. *
  1426. * @type {number}
  1427. * @default 512
  1428. *
  1429. * @exception {DeveloperError} <code>maximumMemoryUsage</code> must be greater than or equal to zero.
  1430. * @see Cesium3DTileset#totalMemoryUsageInBytes
  1431. */
  1432. maximumMemoryUsage: {
  1433. get: function () {
  1434. return this._maximumMemoryUsage;
  1435. },
  1436. set: function (value) {
  1437. //>>includeStart('debug', pragmas.debug);
  1438. Check.typeOf.number.greaterThanOrEquals("value", value, 0);
  1439. //>>includeEnd('debug');
  1440. this._maximumMemoryUsage = value;
  1441. },
  1442. },
  1443. /**
  1444. * Options for controlling point size based on geometric error and eye dome lighting.
  1445. *
  1446. * @memberof Cesium3DTileset.prototype
  1447. *
  1448. * @type {PointCloudShading}
  1449. */
  1450. pointCloudShading: {
  1451. get: function () {
  1452. return this._pointCloudShading;
  1453. },
  1454. set: function (value) {
  1455. //>>includeStart('debug', pragmas.debug);
  1456. Check.defined("pointCloudShading", value);
  1457. //>>includeEnd('debug');
  1458. this._pointCloudShading = value;
  1459. },
  1460. },
  1461. /**
  1462. * The root tile.
  1463. *
  1464. * @memberOf Cesium3DTileset.prototype
  1465. *
  1466. * @type {Cesium3DTile}
  1467. * @readonly
  1468. */
  1469. root: {
  1470. get: function () {
  1471. return this._root;
  1472. },
  1473. },
  1474. /**
  1475. * The tileset's bounding sphere.
  1476. *
  1477. * @memberof Cesium3DTileset.prototype
  1478. *
  1479. * @type {BoundingSphere}
  1480. * @readonly
  1481. *
  1482. * @example
  1483. * const tileset = await Cesium.Cesium3DTileset.fromUrl("http://localhost:8002/tilesets/Seattle/tileset.json");
  1484. *
  1485. * viewer.scene.primitives.add(tileset);
  1486. *
  1487. * // Set the camera to view the newly added tileset
  1488. * viewer.camera.viewBoundingSphere(tileset.boundingSphere, new Cesium.HeadingPitchRange(0, -0.5, 0));
  1489. */
  1490. boundingSphere: {
  1491. get: function () {
  1492. this._root.updateTransform(this._modelMatrix);
  1493. return this._root.boundingSphere;
  1494. },
  1495. },
  1496. /**
  1497. * A 4x4 transformation matrix that transforms the entire tileset.
  1498. *
  1499. * @memberof Cesium3DTileset.prototype
  1500. *
  1501. * @type {Matrix4}
  1502. * @default Matrix4.IDENTITY
  1503. *
  1504. * @example
  1505. * // Adjust a tileset's height from the globe's surface.
  1506. * const heightOffset = 20.0;
  1507. * const boundingSphere = tileset.boundingSphere;
  1508. * const cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
  1509. * const surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
  1510. * const offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, heightOffset);
  1511. * const translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
  1512. * tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
  1513. */
  1514. modelMatrix: {
  1515. get: function () {
  1516. return this._modelMatrix;
  1517. },
  1518. set: function (value) {
  1519. this._modelMatrix = Matrix4.clone(value, this._modelMatrix);
  1520. },
  1521. },
  1522. /**
  1523. * Returns the time, in milliseconds, since the tileset was loaded and first updated.
  1524. *
  1525. * @memberof Cesium3DTileset.prototype
  1526. *
  1527. * @type {number}
  1528. * @readonly
  1529. */
  1530. timeSinceLoad: {
  1531. get: function () {
  1532. return this._timeSinceLoad;
  1533. },
  1534. },
  1535. /**
  1536. * The total amount of GPU memory in bytes used by the tileset. This value is estimated from
  1537. * geometry, texture, batch table textures, and binary metadata of loaded tiles.
  1538. *
  1539. * @memberof Cesium3DTileset.prototype
  1540. *
  1541. * @type {number}
  1542. * @readonly
  1543. *
  1544. * @see Cesium3DTileset#maximumMemoryUsage
  1545. */
  1546. totalMemoryUsageInBytes: {
  1547. get: function () {
  1548. const statistics = this._statistics;
  1549. return (
  1550. statistics.texturesByteLength +
  1551. statistics.geometryByteLength +
  1552. statistics.batchTableByteLength
  1553. );
  1554. },
  1555. },
  1556. /**
  1557. * @private
  1558. */
  1559. clippingPlanesOriginMatrix: {
  1560. get: function () {
  1561. if (!defined(this._clippingPlanesOriginMatrix)) {
  1562. return Matrix4.IDENTITY;
  1563. }
  1564. if (this._clippingPlanesOriginMatrixDirty) {
  1565. Matrix4.multiply(
  1566. this.root.computedTransform,
  1567. this._initialClippingPlanesOriginMatrix,
  1568. this._clippingPlanesOriginMatrix
  1569. );
  1570. this._clippingPlanesOriginMatrixDirty = false;
  1571. }
  1572. return this._clippingPlanesOriginMatrix;
  1573. },
  1574. },
  1575. /**
  1576. * @private
  1577. */
  1578. styleEngine: {
  1579. get: function () {
  1580. return this._styleEngine;
  1581. },
  1582. },
  1583. /**
  1584. * @private
  1585. */
  1586. statistics: {
  1587. get: function () {
  1588. return this._statistics;
  1589. },
  1590. },
  1591. /**
  1592. * Determines whether terrain, 3D Tiles, or both will be classified by this tileset.
  1593. * <p>
  1594. * This option is only applied to tilesets containing batched 3D models,
  1595. * glTF content, geometry data, or vector data. Even when undefined, vector
  1596. * and geometry data must render as classifications and will default to
  1597. * rendering on both terrain and other 3D Tiles tilesets.
  1598. * </p>
  1599. * <p>
  1600. * When enabled for batched 3D model and glTF tilesets, there are a few
  1601. * requirements/limitations on the glTF:
  1602. * <ul>
  1603. * <li>The glTF cannot contain morph targets, skins, or animations.</li>
  1604. * <li>The glTF cannot contain the <code>EXT_mesh_gpu_instancing</code> extension.</li>
  1605. * <li>Only meshes with TRIANGLES can be used to classify other assets.</li>
  1606. * <li>The <code>POSITION</code> semantic is required.</li>
  1607. * <li>If <code>_BATCHID</code>s and an index buffer are both present, all indices with the same batch id must occupy contiguous sections of the index buffer.</li>
  1608. * <li>If <code>_BATCHID</code>s are present with no index buffer, all positions with the same batch id must occupy contiguous sections of the position buffer.</li>
  1609. * </ul>
  1610. * </p>
  1611. * <p>
  1612. * Additionally, classification is not supported for points or instanced 3D
  1613. * models.
  1614. * </p>
  1615. *
  1616. * @memberof Cesium3DTileset.prototype
  1617. *
  1618. * @type {ClassificationType}
  1619. * @default undefined
  1620. *
  1621. * @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.
  1622. * @readonly
  1623. */
  1624. classificationType: {
  1625. get: function () {
  1626. return this._classificationType;
  1627. },
  1628. },
  1629. /**
  1630. * Gets an ellipsoid describing the shape of the globe.
  1631. *
  1632. * @memberof Cesium3DTileset.prototype
  1633. *
  1634. * @type {Ellipsoid}
  1635. * @readonly
  1636. */
  1637. ellipsoid: {
  1638. get: function () {
  1639. return this._ellipsoid;
  1640. },
  1641. },
  1642. /**
  1643. * Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control the cone size that determines which tiles are deferred.
  1644. * Tiles that are inside this cone are loaded immediately. Tiles outside the cone are potentially deferred based on how far outside the cone they are and {@link Cesium3DTileset#foveatedInterpolationCallback} and {@link Cesium3DTileset#foveatedMinimumScreenSpaceErrorRelaxation}.
  1645. * Setting this to 0.0 means the cone will be the line formed by the camera position and its view direction. Setting this to 1.0 means the cone encompasses the entire field of view of the camera, essentially disabling the effect.
  1646. *
  1647. * @memberof Cesium3DTileset.prototype
  1648. *
  1649. * @type {number}
  1650. * @default 0.3
  1651. */
  1652. foveatedConeSize: {
  1653. get: function () {
  1654. return this._foveatedConeSize;
  1655. },
  1656. set: function (value) {
  1657. //>>includeStart('debug', pragmas.debug);
  1658. Check.typeOf.number.greaterThanOrEquals("foveatedConeSize", value, 0.0);
  1659. Check.typeOf.number.lessThanOrEquals("foveatedConeSize", value, 1.0);
  1660. //>>includeEnd('debug');
  1661. this._foveatedConeSize = value;
  1662. },
  1663. },
  1664. /**
  1665. * Optimization option. Used when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control the starting screen space error relaxation for tiles outside the foveated cone.
  1666. * The screen space error will be raised starting with this value up to {@link Cesium3DTileset#maximumScreenSpaceError} based on the provided {@link Cesium3DTileset#foveatedInterpolationCallback}.
  1667. *
  1668. * @memberof Cesium3DTileset.prototype
  1669. *
  1670. * @type {number}
  1671. * @default 0.0
  1672. */
  1673. foveatedMinimumScreenSpaceErrorRelaxation: {
  1674. get: function () {
  1675. return this._foveatedMinimumScreenSpaceErrorRelaxation;
  1676. },
  1677. set: function (value) {
  1678. //>>includeStart('debug', pragmas.debug);
  1679. Check.typeOf.number.greaterThanOrEquals(
  1680. "foveatedMinimumScreenSpaceErrorRelaxation",
  1681. value,
  1682. 0.0
  1683. );
  1684. Check.typeOf.number.lessThanOrEquals(
  1685. "foveatedMinimumScreenSpaceErrorRelaxation",
  1686. value,
  1687. this.maximumScreenSpaceError
  1688. );
  1689. //>>includeEnd('debug');
  1690. this._foveatedMinimumScreenSpaceErrorRelaxation = value;
  1691. },
  1692. },
  1693. /**
  1694. * Returns the <code>extras</code> property at the top-level of the tileset JSON, which contains application specific metadata.
  1695. * Returns <code>undefined</code> if <code>extras</code> does not exist.
  1696. *
  1697. * @memberof Cesium3DTileset.prototype
  1698. *
  1699. * @type {*}
  1700. * @readonly
  1701. *
  1702. * @see {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification#specifying-extensions-and-application-specific-extras|Extras in the 3D Tiles specification.}
  1703. */
  1704. extras: {
  1705. get: function () {
  1706. return this._extras;
  1707. },
  1708. },
  1709. /**
  1710. * The properties for managing image-based lighting on this tileset.
  1711. *
  1712. * @memberof Cesium3DTileset.prototype
  1713. *
  1714. * @type {ImageBasedLighting}
  1715. */
  1716. imageBasedLighting: {
  1717. get: function () {
  1718. return this._imageBasedLighting;
  1719. },
  1720. set: function (value) {
  1721. //>>includeStart('debug', pragmas.debug);
  1722. Check.typeOf.object("imageBasedLighting", this._imageBasedLighting);
  1723. //>>includeEnd('debug');
  1724. if (value !== this._imageBasedLighting) {
  1725. if (
  1726. this._shouldDestroyImageBasedLighting &&
  1727. !this._imageBasedLighting.isDestroyed()
  1728. ) {
  1729. this._imageBasedLighting.destroy();
  1730. }
  1731. this._imageBasedLighting = value;
  1732. this._shouldDestroyImageBasedLighting = false;
  1733. }
  1734. },
  1735. },
  1736. /**
  1737. * Indicates that only the tileset's vector tiles should be used for classification.
  1738. *
  1739. * @memberof Cesium3DTileset.prototype
  1740. *
  1741. * @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.
  1742. *
  1743. * @type {boolean}
  1744. * @default false
  1745. */
  1746. vectorClassificationOnly: {
  1747. get: function () {
  1748. return this._vectorClassificationOnly;
  1749. },
  1750. },
  1751. /**
  1752. * Whether vector tiles should keep decoded positions in memory.
  1753. * This is used with {@link Cesium3DTileFeature.getPolylinePositions}.
  1754. *
  1755. * @memberof Cesium3DTileset.prototype
  1756. *
  1757. * @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.
  1758. *
  1759. * @type {boolean}
  1760. * @default false
  1761. */
  1762. vectorKeepDecodedPositions: {
  1763. get: function () {
  1764. return this._vectorKeepDecodedPositions;
  1765. },
  1766. },
  1767. /**
  1768. * Determines whether the credits of the tileset will be displayed on the screen
  1769. *
  1770. * @memberof Cesium3DTileset.prototype
  1771. *
  1772. * @type {boolean}
  1773. * @default false
  1774. */
  1775. showCreditsOnScreen: {
  1776. get: function () {
  1777. return this._showCreditsOnScreen;
  1778. },
  1779. set: function (value) {
  1780. this._showCreditsOnScreen = value;
  1781. },
  1782. },
  1783. /**
  1784. * Label of the feature ID set to use for picking and styling.
  1785. * <p>
  1786. * For EXT_mesh_features, this is the feature ID's label property, or
  1787. * "featureId_N" (where N is the index in the featureIds array) when not
  1788. * specified. EXT_feature_metadata did not have a label field, so such
  1789. * feature ID sets are always labeled "featureId_N" where N is the index in
  1790. * the list of all feature Ids, where feature ID attributes are listed before
  1791. * feature ID textures.
  1792. * </p>
  1793. * <p>
  1794. * If featureIdLabel is set to an integer N, it is converted to
  1795. * the string "featureId_N" automatically. If both per-primitive and
  1796. * per-instance feature IDs are present, the instance feature IDs take
  1797. * priority.
  1798. * </p>
  1799. *
  1800. * @memberof Cesium3DTileset.prototype
  1801. *
  1802. * @type {string}
  1803. * @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.
  1804. */
  1805. featureIdLabel: {
  1806. get: function () {
  1807. return this._featureIdLabel;
  1808. },
  1809. set: function (value) {
  1810. // indices get converted into featureId_N
  1811. if (typeof value === "number") {
  1812. value = `featureId_${value}`;
  1813. }
  1814. //>>includeStart('debug', pragmas.debug);
  1815. Check.typeOf.string("value", value);
  1816. //>>includeEnd('debug');
  1817. this._featureIdLabel = value;
  1818. },
  1819. },
  1820. /**
  1821. * Label of the instance feature ID set used for picking and styling.
  1822. * <p>
  1823. * If instanceFeatureIdLabel is set to an integer N, it is converted to
  1824. * the string "instanceFeatureId_N" automatically.
  1825. * If both per-primitive and per-instance feature IDs are present, the
  1826. * instance feature IDs take priority.
  1827. * </p>
  1828. *
  1829. * @memberof Cesium3DTileset.prototype
  1830. *
  1831. * @type {string}
  1832. * @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.
  1833. */
  1834. instanceFeatureIdLabel: {
  1835. get: function () {
  1836. return this._instanceFeatureIdLabel;
  1837. },
  1838. set: function (value) {
  1839. // indices get converted into instanceFeatureId_N
  1840. if (typeof value === "number") {
  1841. value = `instanceFeatureId_${value}`;
  1842. }
  1843. //>>includeStart('debug', pragmas.debug);
  1844. Check.typeOf.string("value", value);
  1845. //>>includeEnd('debug');
  1846. this._instanceFeatureIdLabel = value;
  1847. },
  1848. },
  1849. });
  1850. /**
  1851. * Creates a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles tileset},
  1852. * used for streaming massive heterogeneous 3D geospatial datasets, from a Cesium ion asset ID.
  1853. *
  1854. * @param {number} assetId The Cesium ion asset id.
  1855. * @param {Cesium3DTileset.ConstructorOptions} options An object describing initialization options
  1856. * @returns {Promise<Cesium3DTileset>}
  1857. *
  1858. * @exception {DeveloperError} The tileset must be 3D Tiles version 0.0 or 1.0.
  1859. *
  1860. * @see Cesium3DTileset#fromUrl
  1861. *
  1862. * @example
  1863. * // Load a Cesium3DTileset with a Cesium ion asset ID of 124624234
  1864. * try {
  1865. * const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(124624234);
  1866. * scene.primitives.add(tileset);
  1867. * } catch (error) {
  1868. * console.error(`Error creating tileset: ${error}`);
  1869. * }
  1870. */
  1871. Cesium3DTileset.fromIonAssetId = async function (assetId, options) {
  1872. //>>includeStart('debug', pragmas.debug);
  1873. Check.defined("assetId", assetId);
  1874. //>>includeEnd('debug');
  1875. const resource = await IonResource.fromAssetId(assetId);
  1876. return Cesium3DTileset.fromUrl(resource, options);
  1877. };
  1878. /**
  1879. * Creates a {@link https://github.com/CesiumGS/3d-tiles/tree/main/specification|3D Tiles tileset},
  1880. * used for streaming massive heterogeneous 3D geospatial datasets.
  1881. *
  1882. * @param {Resource|string} url The url to a tileset JSON file.
  1883. * @param {Cesium3DTileset.ConstructorOptions} [options] An object describing initialization options
  1884. * @returns {Promise<Cesium3DTileset>}
  1885. *
  1886. * @exception {DeveloperError} The tileset must be 3D Tiles version 0.0 or 1.0.
  1887. *
  1888. * @see Cesium3DTileset#fromIonAssetId
  1889. *
  1890. * @example
  1891. * try {
  1892. * const tileset = await Cesium.Cesium3DTileset.fromUrl(
  1893. * "http://localhost:8002/tilesets/Seattle/tileset.json"
  1894. * );
  1895. * scene.primitives.add(tileset);
  1896. * } catch (error) {
  1897. * console.error(`Error creating tileset: ${error}`);
  1898. * }
  1899. *
  1900. * @example
  1901. * // Common setting for the skipLevelOfDetail optimization
  1902. * const tileset = await Cesium.Cesium3DTileset.fromUrl(
  1903. * "http://localhost:8002/tilesets/Seattle/tileset.json", {
  1904. * skipLevelOfDetail: true,
  1905. * baseScreenSpaceError: 1024,
  1906. * skipScreenSpaceErrorFactor: 16,
  1907. * skipLevels: 1,
  1908. * immediatelyLoadDesiredLevelOfDetail: false,
  1909. * loadSiblings: false,
  1910. * cullWithChildrenBounds: true
  1911. * });
  1912. * scene.primitives.add(tileset);
  1913. *
  1914. * @example
  1915. * // Common settings for the dynamicScreenSpaceError optimization
  1916. * const tileset = await Cesium.Cesium3DTileset.fromUrl(
  1917. * "http://localhost:8002/tilesets/Seattle/tileset.json", {
  1918. * dynamicScreenSpaceError: true,
  1919. * dynamicScreenSpaceErrorDensity: 0.00278,
  1920. * dynamicScreenSpaceErrorFactor: 4.0,
  1921. * dynamicScreenSpaceErrorHeightFalloff: 0.25
  1922. * });
  1923. * scene.primitives.add(tileset);
  1924. */
  1925. Cesium3DTileset.fromUrl = async function (url, options) {
  1926. //>>includeStart('debug', pragmas.debug);
  1927. Check.defined("url", url);
  1928. //>>includeEnd('debug');
  1929. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  1930. const resource = Resource.createIfNeeded(url);
  1931. let basePath;
  1932. if (resource.extension === "json") {
  1933. basePath = resource.getBaseUri(true);
  1934. } else if (resource.isDataUri) {
  1935. basePath = "";
  1936. }
  1937. const tilesetJson = await Cesium3DTileset.loadJson(resource);
  1938. const metadataExtension = await processMetadataExtension(
  1939. resource,
  1940. tilesetJson
  1941. );
  1942. const tileset = new Cesium3DTileset(options);
  1943. tileset._resource = resource;
  1944. tileset._url = resource.url;
  1945. tileset._basePath = basePath;
  1946. tileset._metadataExtension = metadataExtension;
  1947. // Set these before loading the tileset since _geometricError
  1948. // and _scaledGeometricError get accessed during tile creation
  1949. tileset._geometricError = tilesetJson.geometricError;
  1950. tileset._scaledGeometricError = tilesetJson.geometricError;
  1951. const asset = tilesetJson.asset;
  1952. tileset._asset = asset;
  1953. tileset._extras = tilesetJson.extras;
  1954. let credits = resource.credits;
  1955. if (!defined(credits)) {
  1956. credits = [];
  1957. }
  1958. const assetExtras = asset.extras;
  1959. if (
  1960. defined(assetExtras) &&
  1961. defined(assetExtras.cesium) &&
  1962. defined(assetExtras.cesium.credits)
  1963. ) {
  1964. const extraCredits = assetExtras.cesium.credits;
  1965. for (let i = 0; i < extraCredits.length; ++i) {
  1966. const credit = extraCredits[i];
  1967. credits.push(new Credit(credit.html, tileset._showCreditsOnScreen));
  1968. }
  1969. }
  1970. tileset._credits = credits;
  1971. // Handle legacy gltfUpAxis option
  1972. const gltfUpAxis = defined(tilesetJson.asset.gltfUpAxis)
  1973. ? Axis.fromName(tilesetJson.asset.gltfUpAxis)
  1974. : Axis.Y;
  1975. const modelUpAxis = defaultValue(options.modelUpAxis, gltfUpAxis);
  1976. const modelForwardAxis = defaultValue(options.modelForwardAxis, Axis.X);
  1977. tileset._properties = tilesetJson.properties;
  1978. tileset._extensionsUsed = tilesetJson.extensionsUsed;
  1979. tileset._extensions = tilesetJson.extensions;
  1980. tileset._modelUpAxis = modelUpAxis;
  1981. tileset._modelForwardAxis = modelForwardAxis;
  1982. tileset._root = tileset.loadTileset(resource, tilesetJson);
  1983. // Save the original, untransformed bounding volume position so we can apply
  1984. // the tile transform and model matrix at run time
  1985. const boundingVolume = tileset._root.createBoundingVolume(
  1986. tilesetJson.root.boundingVolume,
  1987. Matrix4.IDENTITY
  1988. );
  1989. const clippingPlanesOrigin = boundingVolume.boundingSphere.center;
  1990. // If this origin is above the surface of the earth
  1991. // we want to apply an ENU orientation as our best guess of orientation.
  1992. // Otherwise, we assume it gets its position/orientation completely from the
  1993. // root tile transform and the tileset's model matrix
  1994. const originCartographic = tileset._ellipsoid.cartesianToCartographic(
  1995. clippingPlanesOrigin
  1996. );
  1997. if (
  1998. defined(originCartographic) &&
  1999. originCartographic.height >
  2000. ApproximateTerrainHeights._defaultMinTerrainHeight
  2001. ) {
  2002. tileset._initialClippingPlanesOriginMatrix = Transforms.eastNorthUpToFixedFrame(
  2003. clippingPlanesOrigin
  2004. );
  2005. }
  2006. tileset._clippingPlanesOriginMatrix = Matrix4.clone(
  2007. tileset._initialClippingPlanesOriginMatrix
  2008. );
  2009. tileset._readyPromise = Promise.resolve(tileset);
  2010. tileset._ready = true;
  2011. return tileset;
  2012. };
  2013. /**
  2014. * Provides a hook to override the method used to request the tileset json
  2015. * useful when fetching tilesets from remote servers
  2016. * @param {Resource|string} tilesetUrl The url of the json file to be fetched
  2017. * @returns {Promise<object>} A promise that resolves with the fetched json data
  2018. */
  2019. Cesium3DTileset.loadJson = function (tilesetUrl) {
  2020. const resource = Resource.createIfNeeded(tilesetUrl);
  2021. return resource.fetchJson();
  2022. };
  2023. /**
  2024. * Marks the tileset's {@link Cesium3DTileset#style} as dirty, which forces all
  2025. * features to re-evaluate the style in the next frame each is visible.
  2026. */
  2027. Cesium3DTileset.prototype.makeStyleDirty = function () {
  2028. this._styleEngine.makeDirty();
  2029. };
  2030. /**
  2031. * Loads the main tileset JSON file or a tileset JSON file referenced from a tile.
  2032. *
  2033. * @private
  2034. */
  2035. Cesium3DTileset.prototype.loadTileset = function (
  2036. resource,
  2037. tilesetJson,
  2038. parentTile
  2039. ) {
  2040. const asset = tilesetJson.asset;
  2041. if (!defined(asset)) {
  2042. throw new RuntimeError("Tileset must have an asset property.");
  2043. }
  2044. if (
  2045. asset.version !== "0.0" &&
  2046. asset.version !== "1.0" &&
  2047. asset.version !== "1.1"
  2048. ) {
  2049. throw new RuntimeError(
  2050. "The tileset must be 3D Tiles version 0.0, 1.0, or 1.1"
  2051. );
  2052. }
  2053. if (defined(tilesetJson.extensionsRequired)) {
  2054. Cesium3DTileset.checkSupportedExtensions(tilesetJson.extensionsRequired);
  2055. }
  2056. const statistics = this._statistics;
  2057. const tilesetVersion = asset.tilesetVersion;
  2058. if (defined(tilesetVersion)) {
  2059. // Append the tileset version to the resource
  2060. this._basePath += `?v=${tilesetVersion}`;
  2061. resource = resource.clone();
  2062. resource.setQueryParameters({ v: tilesetVersion });
  2063. }
  2064. // A tileset JSON file referenced from a tile may exist in a different directory than the root tileset.
  2065. // Get the basePath relative to the external tileset.
  2066. const rootTile = makeTile(this, resource, tilesetJson.root, parentTile);
  2067. // If there is a parentTile, add the root of the currently loading tileset
  2068. // to parentTile's children, and update its _depth.
  2069. if (defined(parentTile)) {
  2070. parentTile.children.push(rootTile);
  2071. rootTile._depth = parentTile._depth + 1;
  2072. }
  2073. const stack = [];
  2074. stack.push(rootTile);
  2075. while (stack.length > 0) {
  2076. const tile = stack.pop();
  2077. ++statistics.numberOfTilesTotal;
  2078. this._allTilesAdditive =
  2079. this._allTilesAdditive && tile.refine === Cesium3DTileRefine.ADD;
  2080. const children = tile._header.children;
  2081. if (defined(children)) {
  2082. for (let i = 0; i < children.length; ++i) {
  2083. const childHeader = children[i];
  2084. const childTile = makeTile(this, resource, childHeader, tile);
  2085. tile.children.push(childTile);
  2086. childTile._depth = tile._depth + 1;
  2087. stack.push(childTile);
  2088. }
  2089. }
  2090. if (this._cullWithChildrenBounds) {
  2091. Cesium3DTileOptimizations.checkChildrenWithinParent(tile);
  2092. }
  2093. }
  2094. return rootTile;
  2095. };
  2096. /**
  2097. * Make a {@link Cesium3DTile} for a specific tile. If the tile's header has implicit
  2098. * tiling (3D Tiles 1.1) or uses the <code>3DTILES_implicit_tiling</code> extension,
  2099. * it creates a placeholder tile instead for lazy evaluation of the implicit tileset.
  2100. *
  2101. * @param {Cesium3DTileset} tileset The tileset
  2102. * @param {Resource} baseResource The base resource for the tileset
  2103. * @param {object} tileHeader The JSON header for the tile
  2104. * @param {Cesium3DTile} [parentTile] The parent tile of the new tile
  2105. * @returns {Cesium3DTile} The newly created tile
  2106. *
  2107. * @private
  2108. */
  2109. function makeTile(tileset, baseResource, tileHeader, parentTile) {
  2110. const hasImplicitTiling =
  2111. defined(tileHeader.implicitTiling) ||
  2112. hasExtension(tileHeader, "3DTILES_implicit_tiling");
  2113. if (!hasImplicitTiling) {
  2114. return new Cesium3DTile(tileset, baseResource, tileHeader, parentTile);
  2115. }
  2116. const metadataSchema = tileset.schema;
  2117. const implicitTileset = new ImplicitTileset(
  2118. baseResource,
  2119. tileHeader,
  2120. metadataSchema
  2121. );
  2122. const rootCoordinates = new ImplicitTileCoordinates({
  2123. subdivisionScheme: implicitTileset.subdivisionScheme,
  2124. subtreeLevels: implicitTileset.subtreeLevels,
  2125. level: 0,
  2126. x: 0,
  2127. y: 0,
  2128. // The constructor will only use this for octrees.
  2129. z: 0,
  2130. });
  2131. // Create a placeholder Cesium3DTile that has an ImplicitTileset
  2132. // object and whose content will resolve to an Implicit3DTileContent
  2133. const contentUri = implicitTileset.subtreeUriTemplate.getDerivedResource({
  2134. templateValues: rootCoordinates.getTemplateValues(),
  2135. }).url;
  2136. const deepCopy = true;
  2137. const tileJson = clone(tileHeader, deepCopy);
  2138. // Replace contents with the subtree
  2139. tileJson.contents = [
  2140. {
  2141. uri: contentUri,
  2142. },
  2143. ];
  2144. delete tileJson.content;
  2145. // The placeholder tile does not have any extensions. If there are any
  2146. // extensions beyond 3DTILES_implicit_tiling, Implicit3DTileContent will
  2147. // copy them to the transcoded tiles.
  2148. delete tileJson.extensions;
  2149. const tile = new Cesium3DTile(tileset, baseResource, tileJson, parentTile);
  2150. tile.implicitTileset = implicitTileset;
  2151. tile.implicitCoordinates = rootCoordinates;
  2152. return tile;
  2153. }
  2154. /**
  2155. * If tileset metadata is present, initialize the {@link Cesium3DTilesetMetadata}
  2156. * instance. This is asynchronous since metadata schemas may be external.
  2157. *
  2158. * @param {Cesium3DTileset} tileset The tileset
  2159. * @param {object} tilesetJson The tileset JSON
  2160. * @return {Promise<Cesium3DTilesetMetadata>} The loaded Cesium3DTilesetMetadata
  2161. * @private
  2162. */
  2163. async function processMetadataExtension(resource, tilesetJson) {
  2164. const metadataJson = hasExtension(tilesetJson, "3DTILES_metadata")
  2165. ? tilesetJson.extensions["3DTILES_metadata"]
  2166. : tilesetJson;
  2167. let schemaLoader;
  2168. if (defined(metadataJson.schemaUri)) {
  2169. resource = resource.getDerivedResource({
  2170. url: metadataJson.schemaUri,
  2171. });
  2172. schemaLoader = ResourceCache.getSchemaLoader({
  2173. resource: resource,
  2174. });
  2175. } else if (defined(metadataJson.schema)) {
  2176. schemaLoader = ResourceCache.getSchemaLoader({
  2177. schema: metadataJson.schema,
  2178. });
  2179. } else {
  2180. return;
  2181. }
  2182. await schemaLoader.load();
  2183. const metadataExtension = new Cesium3DTilesetMetadata({
  2184. schema: schemaLoader.schema,
  2185. metadataJson: metadataJson,
  2186. });
  2187. ResourceCache.unload(schemaLoader);
  2188. return metadataExtension;
  2189. }
  2190. const scratchPositionNormal = new Cartesian3();
  2191. const scratchCartographic = new Cartographic();
  2192. const scratchMatrix = new Matrix4();
  2193. const scratchCenter = new Cartesian3();
  2194. const scratchPosition = new Cartesian3();
  2195. const scratchDirection = new Cartesian3();
  2196. /**
  2197. * @private
  2198. * @param {Cesium3DTileset} tileset
  2199. * @param {FrameState} frameState
  2200. */
  2201. function updateDynamicScreenSpaceError(tileset, frameState) {
  2202. let up;
  2203. let direction;
  2204. let height;
  2205. let minimumHeight;
  2206. let maximumHeight;
  2207. const camera = frameState.camera;
  2208. const root = tileset._root;
  2209. const tileBoundingVolume = root.contentBoundingVolume;
  2210. if (tileBoundingVolume instanceof TileBoundingRegion) {
  2211. up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
  2212. direction = camera.directionWC;
  2213. height = camera.positionCartographic.height;
  2214. minimumHeight = tileBoundingVolume.minimumHeight;
  2215. maximumHeight = tileBoundingVolume.maximumHeight;
  2216. } else {
  2217. // Transform camera position and direction into the local coordinate system of the tileset
  2218. const transformLocal = Matrix4.inverseTransformation(
  2219. root.computedTransform,
  2220. scratchMatrix
  2221. );
  2222. const ellipsoid = frameState.mapProjection.ellipsoid;
  2223. const boundingVolume = tileBoundingVolume.boundingVolume;
  2224. const centerLocal = Matrix4.multiplyByPoint(
  2225. transformLocal,
  2226. boundingVolume.center,
  2227. scratchCenter
  2228. );
  2229. if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {
  2230. // The tileset is defined in WGS84. Approximate the minimum and maximum height.
  2231. const centerCartographic = Cartographic.fromCartesian(
  2232. centerLocal,
  2233. ellipsoid,
  2234. scratchCartographic
  2235. );
  2236. up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
  2237. direction = camera.directionWC;
  2238. height = camera.positionCartographic.height;
  2239. minimumHeight = 0.0;
  2240. maximumHeight = centerCartographic.height * 2.0;
  2241. } else {
  2242. // The tileset is defined in local coordinates (z-up)
  2243. const positionLocal = Matrix4.multiplyByPoint(
  2244. transformLocal,
  2245. camera.positionWC,
  2246. scratchPosition
  2247. );
  2248. up = Cartesian3.UNIT_Z;
  2249. direction = Matrix4.multiplyByPointAsVector(
  2250. transformLocal,
  2251. camera.directionWC,
  2252. scratchDirection
  2253. );
  2254. direction = Cartesian3.normalize(direction, direction);
  2255. height = positionLocal.z;
  2256. if (tileBoundingVolume instanceof TileOrientedBoundingBox) {
  2257. // Assuming z-up, the last component stores the half-height of the box
  2258. const boxHeight = root._header.boundingVolume.box[11];
  2259. minimumHeight = centerLocal.z - boxHeight;
  2260. maximumHeight = centerLocal.z + boxHeight;
  2261. } else if (tileBoundingVolume instanceof TileBoundingSphere) {
  2262. const radius = boundingVolume.radius;
  2263. minimumHeight = centerLocal.z - radius;
  2264. maximumHeight = centerLocal.z + radius;
  2265. }
  2266. }
  2267. }
  2268. // The range where the density starts to lessen. Start at the quarter height of the tileset.
  2269. const heightFalloff = tileset.dynamicScreenSpaceErrorHeightFalloff;
  2270. const heightClose =
  2271. minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;
  2272. const heightFar = maximumHeight;
  2273. const t = CesiumMath.clamp(
  2274. (height - heightClose) / (heightFar - heightClose),
  2275. 0.0,
  2276. 1.0
  2277. );
  2278. // Increase density as the camera tilts towards the horizon
  2279. let horizonFactor = 1.0 - Math.abs(Cartesian3.dot(direction, up));
  2280. // Weaken the horizon factor as the camera height increases, implying the camera is further away from the tileset.
  2281. // The goal is to increase density for the "street view", not when viewing the tileset from a distance.
  2282. horizonFactor = horizonFactor * (1.0 - t);
  2283. tileset._dynamicScreenSpaceErrorComputedDensity =
  2284. tileset.dynamicScreenSpaceErrorDensity * horizonFactor;
  2285. }
  2286. /**
  2287. * @private
  2288. * @param {Cesium3DTileset} tileset
  2289. * @param {Cesium3DTile} tile
  2290. */
  2291. function requestContent(tileset, tile) {
  2292. if (tile.hasEmptyContent) {
  2293. return;
  2294. }
  2295. const { statistics } = tileset;
  2296. const contentExpired = tile.contentExpired;
  2297. const promise = tile.requestContent();
  2298. if (!defined(promise)) {
  2299. return;
  2300. }
  2301. promise
  2302. .then((content) => {
  2303. if (!defined(content) || tile.isDestroyed() || tileset.isDestroyed()) {
  2304. return;
  2305. }
  2306. tileset._processingQueue.push(tile);
  2307. ++statistics.numberOfTilesProcessing;
  2308. })
  2309. .catch((error) => {
  2310. handleTileFailure(error, tileset, tile);
  2311. });
  2312. if (contentExpired) {
  2313. if (tile.hasTilesetContent || tile.hasImplicitContent) {
  2314. destroySubtree(tileset, tile);
  2315. } else {
  2316. statistics.decrementLoadCounts(tile.content);
  2317. --statistics.numberOfTilesWithContentReady;
  2318. }
  2319. }
  2320. tileset._requestedTilesInFlight.push(tile);
  2321. }
  2322. function sortRequestByPriority(a, b) {
  2323. return a._priority - b._priority;
  2324. }
  2325. /**
  2326. * Perform any pass invariant tasks here. Called after the render pass.
  2327. * @private
  2328. * @param {FrameState} frameState
  2329. */
  2330. Cesium3DTileset.prototype.postPassesUpdate = function (frameState) {
  2331. if (!defined(this._root)) {
  2332. return;
  2333. }
  2334. cancelOutOfViewRequests(this, frameState);
  2335. raiseLoadProgressEvent(this, frameState);
  2336. this._cache.unloadTiles(this, unloadTile);
  2337. // If the style wasn't able to be applied this frame (for example,
  2338. // the tileset was hidden), keep it dirty so the engine can try
  2339. // to apply the style next frame.
  2340. if (this._styleApplied) {
  2341. this._styleEngine.resetDirty();
  2342. }
  2343. this._styleApplied = false;
  2344. };
  2345. /**
  2346. * Perform any pass invariant tasks here. Called before any passes are executed.
  2347. * @private
  2348. * @param {FrameState} frameState
  2349. */
  2350. Cesium3DTileset.prototype.prePassesUpdate = function (frameState) {
  2351. if (!defined(this._root)) {
  2352. return;
  2353. }
  2354. processTiles(this, frameState);
  2355. // Update clipping planes
  2356. const clippingPlanes = this._clippingPlanes;
  2357. this._clippingPlanesOriginMatrixDirty = true;
  2358. if (defined(clippingPlanes) && clippingPlanes.enabled) {
  2359. clippingPlanes.update(frameState);
  2360. }
  2361. if (!defined(this._loadTimestamp)) {
  2362. this._loadTimestamp = JulianDate.clone(frameState.time);
  2363. }
  2364. this._timeSinceLoad = Math.max(
  2365. JulianDate.secondsDifference(frameState.time, this._loadTimestamp) * 1000,
  2366. 0.0
  2367. );
  2368. if (this.dynamicScreenSpaceError) {
  2369. updateDynamicScreenSpaceError(this, frameState);
  2370. }
  2371. if (frameState.newFrame) {
  2372. this._cache.reset();
  2373. }
  2374. };
  2375. /**
  2376. * @private
  2377. * @param {Cesium3DTileset} tileset
  2378. * @param {FrameState} frameState
  2379. */
  2380. function cancelOutOfViewRequests(tileset, frameState) {
  2381. const requestedTilesInFlight = tileset._requestedTilesInFlight;
  2382. let removeCount = 0;
  2383. for (let i = 0; i < requestedTilesInFlight.length; ++i) {
  2384. const tile = requestedTilesInFlight[i];
  2385. // NOTE: This is framerate dependant so make sure the threshold check is small
  2386. const outOfView = frameState.frameNumber - tile._touchedFrame >= 1;
  2387. if (tile._contentState !== Cesium3DTileContentState.LOADING) {
  2388. // No longer fetching from host, don't need to track it anymore. Gets marked as LOADING in Cesium3DTile::requestContent().
  2389. ++removeCount;
  2390. continue;
  2391. } else if (outOfView) {
  2392. // RequestScheduler will take care of cancelling it
  2393. tile.cancelRequests();
  2394. ++removeCount;
  2395. continue;
  2396. }
  2397. if (removeCount > 0) {
  2398. requestedTilesInFlight[i - removeCount] = tile;
  2399. }
  2400. }
  2401. requestedTilesInFlight.length -= removeCount;
  2402. }
  2403. /**
  2404. * Sort requests by priority before making any requests.
  2405. * This makes it less likely that requests will be cancelled after being issued.
  2406. * @private
  2407. * @param {Cesium3DTileset} tileset
  2408. */
  2409. function requestTiles(tileset) {
  2410. const requestedTiles = tileset._requestedTiles;
  2411. requestedTiles.sort(sortRequestByPriority);
  2412. for (let i = 0; i < requestedTiles.length; ++i) {
  2413. requestContent(tileset, requestedTiles[i]);
  2414. }
  2415. }
  2416. /**
  2417. * @private
  2418. * @param {Error} error
  2419. * @param {Cesium3DTileset} tileset
  2420. * @param {Cesium3DTile} tile
  2421. */
  2422. function handleTileFailure(error, tileset, tile) {
  2423. if (tileset.isDestroyed()) {
  2424. return;
  2425. }
  2426. let url;
  2427. if (!tile.isDestroyed()) {
  2428. url = tile._contentResource.url;
  2429. }
  2430. const message = defined(error.message) ? error.message : error.toString();
  2431. if (tileset.tileFailed.numberOfListeners > 0) {
  2432. tileset.tileFailed.raiseEvent({
  2433. url: url,
  2434. message: message,
  2435. });
  2436. } else {
  2437. console.log(`A 3D tile failed to load: ${url}`);
  2438. console.log(`Error: ${message}`);
  2439. }
  2440. }
  2441. /**
  2442. * @private
  2443. * @param {Cesium3DTileset} tileset
  2444. */
  2445. function filterProcessingQueue(tileset) {
  2446. const tiles = tileset._processingQueue;
  2447. let removeCount = 0;
  2448. for (let i = 0; i < tiles.length; ++i) {
  2449. const tile = tiles[i];
  2450. if (
  2451. tile.isDestroyed() ||
  2452. tile._contentState !== Cesium3DTileContentState.PROCESSING
  2453. ) {
  2454. ++removeCount;
  2455. continue;
  2456. }
  2457. if (removeCount > 0) {
  2458. tiles[i - removeCount] = tile;
  2459. }
  2460. }
  2461. tiles.length -= removeCount;
  2462. }
  2463. /**
  2464. * Process tiles in the PROCESSING state so they will eventually move to the READY state.
  2465. * @private
  2466. * @param {Cesium3DTileset} tileset
  2467. * @param {Cesium3DTile} tile
  2468. */
  2469. function processTiles(tileset, frameState) {
  2470. filterProcessingQueue(tileset);
  2471. const tiles = tileset._processingQueue;
  2472. const statistics = tileset._statistics;
  2473. let tile;
  2474. for (let i = 0; i < tiles.length; ++i) {
  2475. tile = tiles[i];
  2476. try {
  2477. tile.process(tileset, frameState);
  2478. if (tile.contentReady) {
  2479. --statistics.numberOfTilesProcessing;
  2480. tileset.tileLoad.raiseEvent(tile);
  2481. }
  2482. } catch (error) {
  2483. --statistics.numberOfTilesProcessing;
  2484. handleTileFailure(error, tileset, tile);
  2485. }
  2486. }
  2487. }
  2488. const scratchCartesian = new Cartesian3();
  2489. const stringOptions = {
  2490. maximumFractionDigits: 3,
  2491. };
  2492. /**
  2493. * @private
  2494. * @param {number} memorySizeInBytes
  2495. * @returns {string}
  2496. */
  2497. function formatMemoryString(memorySizeInBytes) {
  2498. const memoryInMegabytes = memorySizeInBytes / 1048576;
  2499. if (memoryInMegabytes < 1.0) {
  2500. return memoryInMegabytes.toLocaleString(undefined, stringOptions);
  2501. }
  2502. return Math.round(memoryInMegabytes).toLocaleString();
  2503. }
  2504. /**
  2505. * @private
  2506. * @param {Cesium3DTile} tile
  2507. * @returns {Cartesian3}
  2508. */
  2509. function computeTileLabelPosition(tile) {
  2510. const { halfAxes, radius, center } = tile.boundingVolume.boundingVolume;
  2511. let position = Cartesian3.clone(center, scratchCartesian);
  2512. if (defined(halfAxes)) {
  2513. position.x += 0.75 * (halfAxes[0] + halfAxes[3] + halfAxes[6]);
  2514. position.y += 0.75 * (halfAxes[1] + halfAxes[4] + halfAxes[7]);
  2515. position.z += 0.75 * (halfAxes[2] + halfAxes[5] + halfAxes[8]);
  2516. } else if (defined(radius)) {
  2517. let normal = Cartesian3.normalize(center, scratchCartesian);
  2518. normal = Cartesian3.multiplyByScalar(
  2519. normal,
  2520. 0.75 * radius,
  2521. scratchCartesian
  2522. );
  2523. position = Cartesian3.add(normal, center, scratchCartesian);
  2524. }
  2525. return position;
  2526. }
  2527. /**
  2528. * @private
  2529. * @param {Cesium3DTile} tile
  2530. * @param {Cesium3DTileset} tileset
  2531. * @param {Cartesian3} position
  2532. * @returns {Label}
  2533. */
  2534. function addTileDebugLabel(tile, tileset, position) {
  2535. let labelString = "";
  2536. let attributes = 0;
  2537. if (tileset.debugShowGeometricError) {
  2538. labelString += `\nGeometric error: ${tile.geometricError}`;
  2539. attributes++;
  2540. }
  2541. if (tileset.debugShowRenderingStatistics) {
  2542. labelString += `\nCommands: ${tile.commandsLength}`;
  2543. attributes++;
  2544. // Don't display number of points or triangles if 0.
  2545. const numberOfPoints = tile.content.pointsLength;
  2546. if (numberOfPoints > 0) {
  2547. labelString += `\nPoints: ${tile.content.pointsLength}`;
  2548. attributes++;
  2549. }
  2550. const numberOfTriangles = tile.content.trianglesLength;
  2551. if (numberOfTriangles > 0) {
  2552. labelString += `\nTriangles: ${tile.content.trianglesLength}`;
  2553. attributes++;
  2554. }
  2555. labelString += `\nFeatures: ${tile.content.featuresLength}`;
  2556. attributes++;
  2557. }
  2558. if (tileset.debugShowMemoryUsage) {
  2559. labelString += `\nTexture Memory: ${formatMemoryString(
  2560. tile.content.texturesByteLength
  2561. )}`;
  2562. labelString += `\nGeometry Memory: ${formatMemoryString(
  2563. tile.content.geometryByteLength
  2564. )}`;
  2565. attributes += 2;
  2566. }
  2567. if (tileset.debugShowUrl) {
  2568. if (tile.hasMultipleContents) {
  2569. labelString += "\nUrls:";
  2570. const urls = tile.content.innerContentUrls;
  2571. for (let i = 0; i < urls.length; i++) {
  2572. labelString += `\n- ${urls[i]}`;
  2573. }
  2574. attributes += urls.length;
  2575. } else {
  2576. labelString += `\nUrl: ${tile._contentHeader.uri}`;
  2577. attributes++;
  2578. }
  2579. }
  2580. const newLabel = {
  2581. text: labelString.substring(1),
  2582. position: position,
  2583. font: `${19 - attributes}px sans-serif`,
  2584. showBackground: true,
  2585. disableDepthTestDistance: Number.POSITIVE_INFINITY,
  2586. };
  2587. return tileset._tileDebugLabels.add(newLabel);
  2588. }
  2589. /**
  2590. * @private
  2591. * @param {Cesium3DTileset} tileset
  2592. * @param {FrameState} frameState
  2593. */
  2594. function updateTileDebugLabels(tileset, frameState) {
  2595. const selectedTiles = tileset._selectedTiles;
  2596. const selectedLength = selectedTiles.length;
  2597. const emptyTiles = tileset._emptyTiles;
  2598. const emptyLength = emptyTiles.length;
  2599. tileset._tileDebugLabels.removeAll();
  2600. if (tileset.debugPickedTileLabelOnly) {
  2601. if (defined(tileset.debugPickedTile)) {
  2602. const position = defined(tileset.debugPickPosition)
  2603. ? tileset.debugPickPosition
  2604. : computeTileLabelPosition(tileset.debugPickedTile);
  2605. const label = addTileDebugLabel(
  2606. tileset.debugPickedTile,
  2607. tileset,
  2608. position
  2609. );
  2610. label.pixelOffset = new Cartesian2(15, -15); // Offset to avoid picking the label.
  2611. }
  2612. } else {
  2613. for (let i = 0; i < selectedLength; ++i) {
  2614. const tile = selectedTiles[i];
  2615. addTileDebugLabel(tile, tileset, computeTileLabelPosition(tile));
  2616. }
  2617. for (let i = 0; i < emptyLength; ++i) {
  2618. const tile = emptyTiles[i];
  2619. if (tile.hasTilesetContent || tile.hasImplicitContent) {
  2620. addTileDebugLabel(tile, tileset, computeTileLabelPosition(tile));
  2621. }
  2622. }
  2623. }
  2624. tileset._tileDebugLabels.update(frameState);
  2625. }
  2626. /**
  2627. * @private
  2628. * @param {Cesium3DTileset} tileset
  2629. * @param {FrameState} frameState
  2630. * @param {object} passOptions
  2631. */
  2632. function updateTiles(tileset, frameState, passOptions) {
  2633. tileset._styleEngine.applyStyle(tileset);
  2634. tileset._styleApplied = true;
  2635. const { commandList, context } = frameState;
  2636. const numberOfInitialCommands = commandList.length;
  2637. const selectedTiles = tileset._selectedTiles;
  2638. const bivariateVisibilityTest =
  2639. tileset.isSkippingLevelOfDetail &&
  2640. tileset._hasMixedContent &&
  2641. context.stencilBuffer &&
  2642. selectedTiles.length > 0;
  2643. tileset._backfaceCommands.length = 0;
  2644. if (bivariateVisibilityTest) {
  2645. if (!defined(tileset._stencilClearCommand)) {
  2646. tileset._stencilClearCommand = new ClearCommand({
  2647. stencil: 0,
  2648. pass: Pass.CESIUM_3D_TILE,
  2649. renderState: RenderState.fromCache({
  2650. stencilMask: StencilConstants.SKIP_LOD_MASK,
  2651. }),
  2652. });
  2653. }
  2654. commandList.push(tileset._stencilClearCommand);
  2655. }
  2656. const { statistics, tileVisible } = tileset;
  2657. const isRender = passOptions.isRender;
  2658. const lengthBeforeUpdate = commandList.length;
  2659. for (let i = 0; i < selectedTiles.length; ++i) {
  2660. const tile = selectedTiles[i];
  2661. // Raise the tileVisible event before update in case the tileVisible event
  2662. // handler makes changes that update needs to apply to WebGL resources
  2663. if (isRender) {
  2664. tileVisible.raiseEvent(tile);
  2665. }
  2666. tile.update(tileset, frameState, passOptions);
  2667. statistics.incrementSelectionCounts(tile.content);
  2668. ++statistics.selected;
  2669. }
  2670. const emptyTiles = tileset._emptyTiles;
  2671. for (let i = 0; i < emptyTiles.length; ++i) {
  2672. const tile = emptyTiles[i];
  2673. tile.update(tileset, frameState, passOptions);
  2674. }
  2675. let addedCommandsLength = commandList.length - lengthBeforeUpdate;
  2676. tileset._backfaceCommands.trim();
  2677. if (bivariateVisibilityTest) {
  2678. /*
  2679. * Consider 'effective leaf' tiles as selected tiles that have no selected descendants. They may have children,
  2680. * but they are currently our effective leaves because they do not have selected descendants. These tiles
  2681. * are those where with tile._finalResolution === true.
  2682. * Let 'unresolved' tiles be those with tile._finalResolution === false.
  2683. *
  2684. * 1. Render just the backfaces of unresolved tiles in order to lay down z
  2685. * 2. Render all frontfaces wherever tile._selectionDepth > stencilBuffer.
  2686. * Replace stencilBuffer with tile._selectionDepth, when passing the z test.
  2687. * Because children are always drawn before ancestors {@link Cesium3DTilesetTraversal#traverseAndSelect},
  2688. * this effectively draws children first and does not draw ancestors if a descendant has already
  2689. * been drawn at that pixel.
  2690. * Step 1 prevents child tiles from appearing on top when they are truly behind ancestor content.
  2691. * If they are behind the backfaces of the ancestor, then they will not be drawn.
  2692. *
  2693. * NOTE: Step 2 sometimes causes visual artifacts when backfacing child content has some faces that
  2694. * partially face the camera and are inside of the ancestor content. Because they are inside, they will
  2695. * not be culled by the depth writes in Step 1, and because they partially face the camera, the stencil tests
  2696. * will draw them on top of the ancestor content.
  2697. *
  2698. * NOTE: Because we always render backfaces of unresolved tiles, if the camera is looking at the backfaces
  2699. * of an object, they will always be drawn while loading, even if backface culling is enabled.
  2700. */
  2701. const backfaceCommands = tileset._backfaceCommands.values;
  2702. const backfaceCommandsLength = backfaceCommands.length;
  2703. commandList.length += backfaceCommandsLength;
  2704. // copy commands to the back of the commandList
  2705. for (let i = addedCommandsLength - 1; i >= 0; --i) {
  2706. commandList[lengthBeforeUpdate + backfaceCommandsLength + i] =
  2707. commandList[lengthBeforeUpdate + i];
  2708. }
  2709. // move backface commands to the front of the commandList
  2710. for (let i = 0; i < backfaceCommandsLength; ++i) {
  2711. commandList[lengthBeforeUpdate + i] = backfaceCommands[i];
  2712. }
  2713. }
  2714. // Number of commands added by each update above
  2715. addedCommandsLength = commandList.length - numberOfInitialCommands;
  2716. statistics.numberOfCommands = addedCommandsLength;
  2717. if (!isRender) {
  2718. return;
  2719. }
  2720. // Only run EDL if simple attenuation is on
  2721. if (
  2722. tileset.pointCloudShading.attenuation &&
  2723. tileset.pointCloudShading.eyeDomeLighting &&
  2724. addedCommandsLength > 0
  2725. ) {
  2726. tileset._pointCloudEyeDomeLighting.update(
  2727. frameState,
  2728. numberOfInitialCommands,
  2729. tileset.pointCloudShading,
  2730. tileset.boundingSphere
  2731. );
  2732. }
  2733. if (
  2734. tileset.debugShowGeometricError ||
  2735. tileset.debugShowRenderingStatistics ||
  2736. tileset.debugShowMemoryUsage ||
  2737. tileset.debugShowUrl
  2738. ) {
  2739. if (!defined(tileset._tileDebugLabels)) {
  2740. tileset._tileDebugLabels = new LabelCollection();
  2741. }
  2742. updateTileDebugLabels(tileset, frameState);
  2743. } else {
  2744. tileset._tileDebugLabels =
  2745. tileset._tileDebugLabels && tileset._tileDebugLabels.destroy();
  2746. }
  2747. }
  2748. const scratchStack = [];
  2749. /**
  2750. * @private
  2751. * @param {Cesium3DTileset} tileset
  2752. * @param {Cesium3DTile} tile
  2753. */
  2754. function destroySubtree(tileset, tile) {
  2755. const root = tile;
  2756. const stack = scratchStack;
  2757. stack.push(tile);
  2758. while (stack.length > 0) {
  2759. tile = stack.pop();
  2760. const children = tile.children;
  2761. for (let i = 0; i < children.length; ++i) {
  2762. stack.push(children[i]);
  2763. }
  2764. if (tile !== root) {
  2765. destroyTile(tileset, tile);
  2766. --tileset._statistics.numberOfTilesTotal;
  2767. }
  2768. }
  2769. root.children = [];
  2770. }
  2771. /**
  2772. * @private
  2773. * @param {Cesium3DTileset} tileset
  2774. * @param {Cesium3DTile} tile
  2775. */
  2776. function unloadTile(tileset, tile) {
  2777. tileset.tileUnload.raiseEvent(tile);
  2778. tileset._statistics.decrementLoadCounts(tile.content);
  2779. --tileset._statistics.numberOfTilesWithContentReady;
  2780. tile.unloadContent();
  2781. }
  2782. /**
  2783. * @private
  2784. * @param {Cesium3DTileset} tileset
  2785. * @param {Cesium3DTile} tile
  2786. */
  2787. function destroyTile(tileset, tile) {
  2788. tileset._cache.unloadTile(tileset, tile, unloadTile);
  2789. tile.destroy();
  2790. }
  2791. /**
  2792. * Unloads all tiles that weren't selected the previous frame. This can be used to
  2793. * explicitly manage the tile cache and reduce the total number of tiles loaded below
  2794. * {@link Cesium3DTileset#maximumMemoryUsage}.
  2795. * <p>
  2796. * Tile unloads occur at the next frame to keep all the WebGL delete calls
  2797. * within the render loop.
  2798. * </p>
  2799. */
  2800. Cesium3DTileset.prototype.trimLoadedTiles = function () {
  2801. this._cache.trim();
  2802. };
  2803. /**
  2804. * @private
  2805. * @param {Cesium3DTileset} tileset
  2806. * @param {FrameState} frameState
  2807. */
  2808. function raiseLoadProgressEvent(tileset, frameState) {
  2809. const statistics = tileset._statistics;
  2810. const statisticsLast = tileset._statisticsLast;
  2811. const numberOfPendingRequests = statistics.numberOfPendingRequests;
  2812. const numberOfTilesProcessing = statistics.numberOfTilesProcessing;
  2813. const lastNumberOfPendingRequest = statisticsLast.numberOfPendingRequests;
  2814. const lastNumberOfTilesProcessing = statisticsLast.numberOfTilesProcessing;
  2815. Cesium3DTilesetStatistics.clone(statistics, statisticsLast);
  2816. const progressChanged =
  2817. numberOfPendingRequests !== lastNumberOfPendingRequest ||
  2818. numberOfTilesProcessing !== lastNumberOfTilesProcessing;
  2819. if (progressChanged) {
  2820. frameState.afterRender.push(function () {
  2821. tileset.loadProgress.raiseEvent(
  2822. numberOfPendingRequests,
  2823. numberOfTilesProcessing
  2824. );
  2825. return true;
  2826. });
  2827. }
  2828. tileset._tilesLoaded =
  2829. statistics.numberOfPendingRequests === 0 &&
  2830. statistics.numberOfTilesProcessing === 0 &&
  2831. statistics.numberOfAttemptedRequests === 0;
  2832. // Events are raised (added to the afterRender queue) here since promises
  2833. // may resolve outside of the update loop that then raise events, e.g.,
  2834. // model's readyEvent
  2835. if (progressChanged && tileset._tilesLoaded) {
  2836. frameState.afterRender.push(function () {
  2837. tileset.allTilesLoaded.raiseEvent();
  2838. return true;
  2839. });
  2840. if (!tileset._initialTilesLoaded) {
  2841. tileset._initialTilesLoaded = true;
  2842. frameState.afterRender.push(function () {
  2843. tileset.initialTilesLoaded.raiseEvent();
  2844. return true;
  2845. });
  2846. }
  2847. }
  2848. }
  2849. /**
  2850. * @private
  2851. * @param {Cesium3DTileset} tileset
  2852. */
  2853. function resetMinimumMaximum(tileset) {
  2854. tileset._heatmap.resetMinimumMaximum();
  2855. tileset._minimumPriority.depth = Number.MAX_VALUE;
  2856. tileset._maximumPriority.depth = -Number.MAX_VALUE;
  2857. tileset._minimumPriority.foveatedFactor = Number.MAX_VALUE;
  2858. tileset._maximumPriority.foveatedFactor = -Number.MAX_VALUE;
  2859. tileset._minimumPriority.distance = Number.MAX_VALUE;
  2860. tileset._maximumPriority.distance = -Number.MAX_VALUE;
  2861. tileset._minimumPriority.reverseScreenSpaceError = Number.MAX_VALUE;
  2862. tileset._maximumPriority.reverseScreenSpaceError = -Number.MAX_VALUE;
  2863. }
  2864. /**
  2865. * @private
  2866. * @param {Cesium3DTileset} tileset
  2867. * @param {FrameState} frameState
  2868. */
  2869. function detectModelMatrixChanged(tileset, frameState) {
  2870. if (
  2871. frameState.frameNumber === tileset._updatedModelMatrixFrame &&
  2872. defined(tileset._previousModelMatrix)
  2873. ) {
  2874. return;
  2875. }
  2876. tileset._updatedModelMatrixFrame = frameState.frameNumber;
  2877. tileset._modelMatrixChanged = !Matrix4.equals(
  2878. tileset.modelMatrix,
  2879. tileset._previousModelMatrix
  2880. );
  2881. if (tileset._modelMatrixChanged) {
  2882. tileset._previousModelMatrix = Matrix4.clone(
  2883. tileset.modelMatrix,
  2884. tileset._previousModelMatrix
  2885. );
  2886. }
  2887. }
  2888. /**
  2889. * @private
  2890. * @param {Cesium3DTileset} tileset
  2891. * @param {FrameState} frameState
  2892. * @param {Cesium3DTilesetStatistics} passStatistics
  2893. * @param {object} passOptions
  2894. * @returns {boolean}
  2895. */
  2896. function update(tileset, frameState, passStatistics, passOptions) {
  2897. if (frameState.mode === SceneMode.MORPHING) {
  2898. return false;
  2899. }
  2900. if (!defined(tileset._root)) {
  2901. return false;
  2902. }
  2903. const statistics = tileset._statistics;
  2904. statistics.clear();
  2905. // Resets the visibility check for each pass
  2906. ++tileset._updatedVisibilityFrame;
  2907. // Update any tracked min max values
  2908. resetMinimumMaximum(tileset);
  2909. detectModelMatrixChanged(tileset, frameState);
  2910. tileset._cullRequestsWhileMoving =
  2911. tileset.cullRequestsWhileMoving && !tileset._modelMatrixChanged;
  2912. const ready = tileset
  2913. .getTraversal(passOptions)
  2914. .selectTiles(tileset, frameState);
  2915. if (passOptions.requestTiles) {
  2916. requestTiles(tileset);
  2917. }
  2918. updateTiles(tileset, frameState, passOptions);
  2919. // Update pass statistics
  2920. Cesium3DTilesetStatistics.clone(statistics, passStatistics);
  2921. if (passOptions.isRender) {
  2922. const credits = tileset._credits;
  2923. if (defined(credits) && statistics.selected !== 0) {
  2924. for (let i = 0; i < credits.length; ++i) {
  2925. const credit = credits[i];
  2926. credit.showOnScreen = tileset._showCreditsOnScreen;
  2927. frameState.creditDisplay.addCreditToNextFrame(credit);
  2928. }
  2929. }
  2930. }
  2931. return ready;
  2932. }
  2933. /**
  2934. * @private
  2935. * @param {object} passOptions
  2936. * @returns {Cesium3DTilesetTraversal}
  2937. */
  2938. Cesium3DTileset.prototype.getTraversal = function (passOptions) {
  2939. const { pass } = passOptions;
  2940. if (
  2941. pass === Cesium3DTilePass.MOST_DETAILED_PRELOAD ||
  2942. pass === Cesium3DTilePass.MOST_DETAILED_PICK
  2943. ) {
  2944. return Cesium3DTilesetMostDetailedTraversal;
  2945. }
  2946. return this.isSkippingLevelOfDetail
  2947. ? Cesium3DTilesetSkipTraversal
  2948. : Cesium3DTilesetBaseTraversal;
  2949. };
  2950. /**
  2951. * @private
  2952. * @param {FrameState} frameState
  2953. */
  2954. Cesium3DTileset.prototype.update = function (frameState) {
  2955. this.updateForPass(frameState, frameState.tilesetPassState);
  2956. };
  2957. /**
  2958. * @private
  2959. * @param {FrameState} frameState
  2960. * @param {object} tilesetPassState
  2961. */
  2962. Cesium3DTileset.prototype.updateForPass = function (
  2963. frameState,
  2964. tilesetPassState
  2965. ) {
  2966. //>>includeStart('debug', pragmas.debug);
  2967. Check.typeOf.object("frameState", frameState);
  2968. Check.typeOf.object("tilesetPassState", tilesetPassState);
  2969. //>>includeEnd('debug');
  2970. const pass = tilesetPassState.pass;
  2971. if (
  2972. (pass === Cesium3DTilePass.PRELOAD &&
  2973. (!this.preloadWhenHidden || this.show)) ||
  2974. (pass === Cesium3DTilePass.PRELOAD_FLIGHT &&
  2975. (!this.preloadFlightDestinations ||
  2976. (!this.show && !this.preloadWhenHidden))) ||
  2977. (pass === Cesium3DTilePass.REQUEST_RENDER_MODE_DEFER_CHECK &&
  2978. ((!this._cullRequestsWhileMoving && this.foveatedTimeDelay <= 0) ||
  2979. !this.show))
  2980. ) {
  2981. return;
  2982. }
  2983. const originalCommandList = frameState.commandList;
  2984. const originalCamera = frameState.camera;
  2985. const originalCullingVolume = frameState.cullingVolume;
  2986. tilesetPassState.ready = false;
  2987. const passOptions = Cesium3DTilePass.getPassOptions(pass);
  2988. const ignoreCommands = passOptions.ignoreCommands;
  2989. const commandList = defaultValue(
  2990. tilesetPassState.commandList,
  2991. originalCommandList
  2992. );
  2993. const commandStart = commandList.length;
  2994. frameState.commandList = commandList;
  2995. frameState.camera = defaultValue(tilesetPassState.camera, originalCamera);
  2996. frameState.cullingVolume = defaultValue(
  2997. tilesetPassState.cullingVolume,
  2998. originalCullingVolume
  2999. );
  3000. const passStatistics = this._statisticsPerPass[pass];
  3001. if (this.show || ignoreCommands) {
  3002. this._pass = pass;
  3003. tilesetPassState.ready = update(
  3004. this,
  3005. frameState,
  3006. passStatistics,
  3007. passOptions
  3008. );
  3009. }
  3010. if (ignoreCommands) {
  3011. commandList.length = commandStart;
  3012. }
  3013. frameState.commandList = originalCommandList;
  3014. frameState.camera = originalCamera;
  3015. frameState.cullingVolume = originalCullingVolume;
  3016. };
  3017. /**
  3018. * <code>true</code> if the tileset JSON file lists the extension in extensionsUsed; otherwise, <code>false</code>.
  3019. * @param {string} extensionName The name of the extension to check.
  3020. *
  3021. * @returns {boolean} <code>true</code> if the tileset JSON file lists the extension in extensionsUsed; otherwise, <code>false</code>.
  3022. */
  3023. Cesium3DTileset.prototype.hasExtension = function (extensionName) {
  3024. if (!defined(this._extensionsUsed)) {
  3025. return false;
  3026. }
  3027. return this._extensionsUsed.indexOf(extensionName) > -1;
  3028. };
  3029. /**
  3030. * Returns true if this object was destroyed; otherwise, false.
  3031. * <br /><br />
  3032. * If this object was destroyed, it should not be used; calling any function other than
  3033. * <code>isDestroyed</code> will result in a {@link DeveloperError} exception.
  3034. *
  3035. * @returns {boolean} <code>true</code> if this object was destroyed; otherwise, <code>false</code>.
  3036. *
  3037. * @see Cesium3DTileset#destroy
  3038. */
  3039. Cesium3DTileset.prototype.isDestroyed = function () {
  3040. return false;
  3041. };
  3042. /**
  3043. * Destroys the WebGL resources held by this object. Destroying an object allows for deterministic
  3044. * release of WebGL resources, instead of relying on the garbage collector to destroy this object.
  3045. * <br /><br />
  3046. * Once an object is destroyed, it should not be used; calling any function other than
  3047. * <code>isDestroyed</code> will result in a {@link DeveloperError} exception. Therefore,
  3048. * assign the return value (<code>undefined</code>) to the object as done in the example.
  3049. *
  3050. * @exception {DeveloperError} This object was destroyed, i.e., destroy() was called.
  3051. *
  3052. * @example
  3053. * tileset = tileset && tileset.destroy();
  3054. *
  3055. * @see Cesium3DTileset#isDestroyed
  3056. */
  3057. Cesium3DTileset.prototype.destroy = function () {
  3058. this._tileDebugLabels =
  3059. this._tileDebugLabels && this._tileDebugLabels.destroy();
  3060. this._clippingPlanes = this._clippingPlanes && this._clippingPlanes.destroy();
  3061. // Traverse the tree and destroy all tiles
  3062. if (defined(this._root)) {
  3063. const stack = scratchStack;
  3064. stack.push(this._root);
  3065. while (stack.length > 0) {
  3066. const tile = stack.pop();
  3067. tile.destroy();
  3068. const children = tile.children;
  3069. for (let i = 0; i < children.length; ++i) {
  3070. stack.push(children[i]);
  3071. }
  3072. }
  3073. }
  3074. this._root = undefined;
  3075. if (
  3076. this._shouldDestroyImageBasedLighting &&
  3077. !this._imageBasedLighting.isDestroyed()
  3078. ) {
  3079. this._imageBasedLighting.destroy();
  3080. }
  3081. this._imageBasedLighting = undefined;
  3082. return destroyObject(this);
  3083. };
  3084. Cesium3DTileset.supportedExtensions = {
  3085. "3DTILES_metadata": true,
  3086. "3DTILES_implicit_tiling": true,
  3087. "3DTILES_content_gltf": true,
  3088. "3DTILES_multiple_contents": true,
  3089. "3DTILES_bounding_volume_S2": true,
  3090. "3DTILES_batch_table_hierarchy": true,
  3091. "3DTILES_draco_point_compression": true,
  3092. MAXAR_content_geojson: true,
  3093. };
  3094. /**
  3095. * Checks to see if a given extension is supported by Cesium3DTileset. If
  3096. * the extension is not supported by Cesium3DTileset, it throws a RuntimeError.
  3097. *
  3098. * @param {object} extensionsRequired The extensions we wish to check
  3099. *
  3100. * @private
  3101. */
  3102. Cesium3DTileset.checkSupportedExtensions = function (extensionsRequired) {
  3103. for (let i = 0; i < extensionsRequired.length; i++) {
  3104. if (!Cesium3DTileset.supportedExtensions[extensionsRequired[i]]) {
  3105. throw new RuntimeError(
  3106. `Unsupported 3D Tiles Extension: ${extensionsRequired[i]}`
  3107. );
  3108. }
  3109. }
  3110. };
  3111. /**
  3112. * Optimization option. Used as a callback when {@link Cesium3DTileset#foveatedScreenSpaceError} is true to control how much to raise the screen space error for tiles outside the foveated cone,
  3113. * interpolating between {@link Cesium3DTileset#foveatedMinimumScreenSpaceErrorRelaxation} and {@link Cesium3DTileset#maximumScreenSpaceError}.
  3114. *
  3115. * @callback Cesium3DTileset.foveatedInterpolationCallback
  3116. * @default Math.lerp
  3117. *
  3118. * @param {number} p The start value to interpolate.
  3119. * @param {number} q The end value to interpolate.
  3120. * @param {number} time The time of interpolation generally in the range <code>[0.0, 1.0]</code>.
  3121. * @returns {number} The interpolated value.
  3122. */
  3123. export default Cesium3DTileset;