智慧水务管理系统 - 精河县供水工程综合管理平台

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