12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604 |
- import {
- Check,
- Color,
- defined,
- destroyObject,
- Cesium3DTileColorBlendMode,
- Cesium3DTileFeature,
- Cesium3DTilePass,
- Cesium3DTileset,
- Cesium3DTileStyle,
- PerformanceDisplay,
- ResourceCache,
- ScreenSpaceEventHandler,
- ScreenSpaceEventType,
- } from "@cesium/engine";
- import knockout from "../ThirdParty/knockout.js";
- function getPickTileset(viewModel) {
- return function (e) {
- const pick = viewModel._scene.pick(e.position);
- if (defined(pick) && pick.primitive instanceof Cesium3DTileset) {
- viewModel.tileset = pick.primitive;
- }
- viewModel.pickActive = false;
- };
- }
- function selectTilesetOnHover(viewModel, value) {
- if (value) {
- viewModel._eventHandler.setInputAction(function (e) {
- const pick = viewModel._scene.pick(e.endPosition);
- if (defined(pick) && pick.primitive instanceof Cesium3DTileset) {
- viewModel.tileset = pick.primitive;
- }
- }, ScreenSpaceEventType.MOUSE_MOVE);
- } else {
- viewModel._eventHandler.removeInputAction(ScreenSpaceEventType.MOUSE_MOVE);
- // Restore hover-over selection to its current value
- // eslint-disable-next-line no-self-assign
- viewModel.picking = viewModel.picking;
- }
- }
- const stringOptions = {
- maximumFractionDigits: 3,
- };
- function formatMemoryString(memorySizeInBytes) {
- const memoryInMegabytes = memorySizeInBytes / 1048576;
- if (memoryInMegabytes < 1.0) {
- return memoryInMegabytes.toLocaleString(undefined, stringOptions);
- }
- return Math.round(memoryInMegabytes).toLocaleString();
- }
- function getStatistics(tileset, isPick) {
- if (!defined(tileset)) {
- return "";
- }
- const statistics = isPick
- ? tileset._statisticsPerPass[Cesium3DTilePass.PICK]
- : tileset._statisticsPerPass[Cesium3DTilePass.RENDER];
- // Since the pick pass uses a smaller frustum around the pixel of interest,
- // the statistics will be different than the normal render pass.
- let s = '<ul class="cesium-cesiumInspector-statistics">';
- s +=
- // --- Rendering statistics
- `<li><strong>Visited: </strong>${statistics.visited.toLocaleString()}</li>` +
- // Number of commands returned is likely to be higher than the number of tiles selected
- // because of tiles that create multiple commands.
- `<li><strong>Selected: </strong>${statistics.selected.toLocaleString()}</li>` +
- // Number of commands executed is likely to be higher because of commands overlapping
- // multiple frustums.
- `<li><strong>Commands: </strong>${statistics.numberOfCommands.toLocaleString()}</li>`;
- s += "</ul>";
- if (!isPick) {
- s += '<ul class="cesium-cesiumInspector-statistics">';
- s +=
- // --- Cache/loading statistics
- `<li><strong>Requests: </strong>${statistics.numberOfPendingRequests.toLocaleString()}</li>` +
- `<li><strong>Attempted: </strong>${statistics.numberOfAttemptedRequests.toLocaleString()}</li>` +
- `<li><strong>Processing: </strong>${statistics.numberOfTilesProcessing.toLocaleString()}</li>` +
- `<li><strong>Content Ready: </strong>${statistics.numberOfTilesWithContentReady.toLocaleString()}</li>` +
- // Total number of tiles includes tiles without content, so "Ready" may never reach
- // "Total." Total also will increase when a tile with a tileset JSON content is loaded.
- `<li><strong>Total: </strong>${statistics.numberOfTilesTotal.toLocaleString()}</li>`;
- s += "</ul>";
- s += '<ul class="cesium-cesiumInspector-statistics">';
- s +=
- // --- Features statistics
- `<li><strong>Features Selected: </strong>${statistics.numberOfFeaturesSelected.toLocaleString()}</li>` +
- `<li><strong>Features Loaded: </strong>${statistics.numberOfFeaturesLoaded.toLocaleString()}</li>` +
- `<li><strong>Points Selected: </strong>${statistics.numberOfPointsSelected.toLocaleString()}</li>` +
- `<li><strong>Points Loaded: </strong>${statistics.numberOfPointsLoaded.toLocaleString()}</li>` +
- `<li><strong>Triangles Selected: </strong>${statistics.numberOfTrianglesSelected.toLocaleString()}</li>`;
- s += "</ul>";
- s += '<ul class="cesium-cesiumInspector-statistics">';
- s +=
- // --- Styling statistics
- `<li><strong>Tiles styled: </strong>${statistics.numberOfTilesStyled.toLocaleString()}</li>` +
- `<li><strong>Features styled: </strong>${statistics.numberOfFeaturesStyled.toLocaleString()}</li>`;
- s += "</ul>";
- s += '<ul class="cesium-cesiumInspector-statistics">';
- s +=
- // --- Optimization statistics
- `<li><strong>Children Union Culled: </strong>${statistics.numberOfTilesCulledWithChildrenUnion.toLocaleString()}</li>`;
- s += "</ul>";
- s += '<ul class="cesium-cesiumInspector-statistics">';
- s +=
- // --- Memory statistics
- `<li><strong>Geometry Memory (MB): </strong>${formatMemoryString(
- statistics.geometryByteLength
- )}</li>` +
- `<li><strong>Texture Memory (MB): </strong>${formatMemoryString(
- statistics.texturesByteLength
- )}</li>` +
- `<li><strong>Batch Table Memory (MB): </strong>${formatMemoryString(
- statistics.batchTableByteLength
- )}</li>`;
- s += "</ul>";
- }
- return s;
- }
- function getResourceCacheStatistics() {
- const statistics = ResourceCache.statistics;
- return `
- <ul class="cesium-cesiumInspector-statistics">
- <li><strong>Geometry Memory (MB): </strong>${formatMemoryString(
- statistics.geometryByteLength
- )}</li>
- <li><strong>Texture Memory (MB): </strong>${formatMemoryString(
- statistics.texturesByteLength
- )}</li>
- </ul>
- `;
- }
- const colorBlendModes = [
- {
- text: "Highlight",
- value: Cesium3DTileColorBlendMode.HIGHLIGHT,
- },
- {
- text: "Replace",
- value: Cesium3DTileColorBlendMode.REPLACE,
- },
- {
- text: "Mix",
- value: Cesium3DTileColorBlendMode.MIX,
- },
- ];
- const highlightColor = new Color(1.0, 1.0, 0.0, 0.4);
- const scratchColor = new Color();
- const oldColor = new Color();
- /**
- * The view model for {@link Cesium3DTilesInspector}.
- * @alias Cesium3DTilesInspectorViewModel
- * @constructor
- *
- * @param {Scene} scene The scene instance to use.
- * @param {HTMLElement} performanceContainer The container for the performance display
- */
- function Cesium3DTilesInspectorViewModel(scene, performanceContainer) {
- //>>includeStart('debug', pragmas.debug);
- Check.typeOf.object("scene", scene);
- Check.typeOf.object("performanceContainer", performanceContainer);
- //>>includeEnd('debug');
- const that = this;
- const canvas = scene.canvas;
- this._eventHandler = new ScreenSpaceEventHandler(canvas);
- this._scene = scene;
- this._performanceContainer = performanceContainer;
- this._canvas = canvas;
- this._performanceDisplay = new PerformanceDisplay({
- container: performanceContainer,
- });
- this._statisticsText = "";
- this._pickStatisticsText = "";
- this._resourceCacheStatisticsText = "";
- this._editorError = "";
- /**
- * Gets or sets the flag to enable performance display. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.performance = false;
- /**
- * Gets or sets the flag to show statistics. This property is observable.
- *
- * @type {boolean}
- * @default true
- */
- this.showStatistics = true;
- /**
- * Gets or sets the flag to show pick statistics. This property is observable.
- *
- * @type {boolean}
- * @default true
- */
- this.showPickStatistics = true;
- /**
- * Gets or sets the flag to show resource cache statistics. This property is
- * observable.
- *
- * @type {boolean}
- * @default false
- */
- this.showResourceCacheStatistics = false;
- /**
- * Gets or sets the flag to show the inspector. This property is observable.
- *
- * @type {boolean}
- * @default true
- */
- this.inspectorVisible = true;
- /**
- * Gets or sets the flag to show the tileset section. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.tilesetVisible = false;
- /**
- * Gets or sets the flag to show the display section. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.displayVisible = false;
- /**
- * Gets or sets the flag to show the update section. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.updateVisible = false;
- /**
- * Gets or sets the flag to show the logging section. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.loggingVisible = false;
- /**
- * Gets or sets the flag to show the style section. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.styleVisible = false;
- /**
- * Gets or sets the flag to show the tile info section. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.tileDebugLabelsVisible = false;
- /**
- * Gets or sets the flag to show the optimization info section. This property is observable.
- *
- * @type {boolean}
- * @default false;
- */
- this.optimizationVisible = false;
- /**
- * Gets or sets the JSON for the tileset style. This property is observable.
- *
- * @type {string}
- * @default '{}'
- */
- this.styleString = "{}";
- /**
- * Gets or sets the JSON for the tileset enableDebugWireframe attribute. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.hasEnabledWireframe = false;
- this._tileset = undefined;
- this._feature = undefined;
- this._tile = undefined;
- knockout.track(this, [
- "performance",
- "inspectorVisible",
- "_statisticsText",
- "_pickStatisticsText",
- "_resourceCacheStatisticsText",
- "_editorError",
- "showPickStatistics",
- "showStatistics",
- "showResourceCacheStatistics",
- "tilesetVisible",
- "displayVisible",
- "updateVisible",
- "loggingVisible",
- "styleVisible",
- "optimizationVisible",
- "tileDebugLabelsVisible",
- "styleString",
- "_feature",
- "_tile",
- "_tileset",
- "hasEnabledWireframe",
- ]);
- this._properties = knockout.observable({});
- /**
- * Gets the names of the properties in the tileset. This property is observable.
- * @type {string[]}
- * @readonly
- */
- this.properties = [];
- knockout.defineProperty(this, "properties", function () {
- const names = [];
- const properties = that._properties();
- for (const prop in properties) {
- if (properties.hasOwnProperty(prop)) {
- names.push(prop);
- }
- }
- return names;
- });
- const dynamicScreenSpaceError = knockout.observable();
- knockout.defineProperty(this, "dynamicScreenSpaceError", {
- get: function () {
- return dynamicScreenSpaceError();
- },
- set: function (value) {
- dynamicScreenSpaceError(value);
- if (defined(that._tileset)) {
- that._tileset.dynamicScreenSpaceError = value;
- }
- },
- });
- /**
- * Gets or sets the flag to enable dynamic screen space error. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.dynamicScreenSpaceError = false;
- const colorBlendMode = knockout.observable();
- knockout.defineProperty(this, "colorBlendMode", {
- get: function () {
- return colorBlendMode();
- },
- set: function (value) {
- colorBlendMode(value);
- if (defined(that._tileset)) {
- that._tileset.colorBlendMode = value;
- that._scene.requestRender();
- }
- },
- });
- /**
- * Gets or sets the color blend mode. This property is observable.
- *
- * @type {Cesium3DTileColorBlendMode}
- * @default Cesium3DTileColorBlendMode.HIGHLIGHT
- */
- this.colorBlendMode = Cesium3DTileColorBlendMode.HIGHLIGHT;
- const showOnlyPickedTileDebugLabel = knockout.observable();
- const picking = knockout.observable();
- knockout.defineProperty(this, "picking", {
- get: function () {
- return picking();
- },
- set: function (value) {
- picking(value);
- if (value) {
- that._eventHandler.setInputAction(function (e) {
- const picked = scene.pick(e.endPosition);
- if (picked instanceof Cesium3DTileFeature) {
- // Picked a feature
- that.feature = picked;
- that.tile = picked.content.tile;
- } else if (defined(picked) && defined(picked.content)) {
- // Picked a tile
- that.feature = undefined;
- that.tile = picked.content.tile;
- } else {
- // Picked nothing
- that.feature = undefined;
- that.tile = undefined;
- }
- if (!defined(that._tileset)) {
- return;
- }
- if (
- showOnlyPickedTileDebugLabel &&
- defined(picked) &&
- defined(picked.content)
- ) {
- let position;
- if (scene.pickPositionSupported) {
- position = scene.pickPosition(e.endPosition);
- if (defined(position)) {
- that._tileset.debugPickPosition = position;
- }
- }
- that._tileset.debugPickedTile = picked.content.tile;
- } else {
- that._tileset.debugPickedTile = undefined;
- }
- that._scene.requestRender();
- }, ScreenSpaceEventType.MOUSE_MOVE);
- } else {
- that.feature = undefined;
- that.tile = undefined;
- that._eventHandler.removeInputAction(ScreenSpaceEventType.MOUSE_MOVE);
- }
- },
- });
- /**
- * Gets or sets the flag to enable picking. This property is observable.
- *
- * @type {boolean}
- * @default true
- */
- this.picking = true;
- const colorize = knockout.observable();
- knockout.defineProperty(this, "colorize", {
- get: function () {
- return colorize();
- },
- set: function (value) {
- colorize(value);
- if (defined(that._tileset)) {
- that._tileset.debugColorizeTiles = value;
- that._scene.requestRender();
- }
- },
- });
- /**
- * Gets or sets the flag to colorize tiles. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.colorize = false;
- const wireframe = knockout.observable();
- knockout.defineProperty(this, "wireframe", {
- get: function () {
- return wireframe();
- },
- set: function (value) {
- wireframe(value);
- if (defined(that._tileset)) {
- that._tileset.debugWireframe = value;
- that._scene.requestRender();
- }
- },
- });
- /**
- * Gets or sets the flag to draw with wireframe. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.wireframe = false;
- const showBoundingVolumes = knockout.observable();
- knockout.defineProperty(this, "showBoundingVolumes", {
- get: function () {
- return showBoundingVolumes();
- },
- set: function (value) {
- showBoundingVolumes(value);
- if (defined(that._tileset)) {
- that._tileset.debugShowBoundingVolume = value;
- that._scene.requestRender();
- }
- },
- });
- /**
- * Gets or sets the flag to show bounding volumes. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.showBoundingVolumes = false;
- const showContentBoundingVolumes = knockout.observable();
- knockout.defineProperty(this, "showContentBoundingVolumes", {
- get: function () {
- return showContentBoundingVolumes();
- },
- set: function (value) {
- showContentBoundingVolumes(value);
- if (defined(that._tileset)) {
- that._tileset.debugShowContentBoundingVolume = value;
- that._scene.requestRender();
- }
- },
- });
- /**
- * Gets or sets the flag to show content volumes. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.showContentBoundingVolumes = false;
- const showRequestVolumes = knockout.observable();
- knockout.defineProperty(this, "showRequestVolumes", {
- get: function () {
- return showRequestVolumes();
- },
- set: function (value) {
- showRequestVolumes(value);
- if (defined(that._tileset)) {
- that._tileset.debugShowViewerRequestVolume = value;
- that._scene.requestRender();
- }
- },
- });
- /**
- * Gets or sets the flag to show request volumes. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.showRequestVolumes = false;
- const freezeFrame = knockout.observable();
- knockout.defineProperty(this, "freezeFrame", {
- get: function () {
- return freezeFrame();
- },
- set: function (value) {
- freezeFrame(value);
- if (defined(that._tileset)) {
- that._tileset.debugFreezeFrame = value;
- that._scene.debugShowFrustumPlanes = value;
- that._scene.requestRender();
- }
- },
- });
- /**
- * Gets or sets the flag to suspend updates. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.freezeFrame = false;
- knockout.defineProperty(this, "showOnlyPickedTileDebugLabel", {
- get: function () {
- return showOnlyPickedTileDebugLabel();
- },
- set: function (value) {
- showOnlyPickedTileDebugLabel(value);
- if (defined(that._tileset)) {
- that._tileset.debugPickedTileLabelOnly = value;
- that._scene.requestRender();
- }
- },
- });
- /**
- * Gets or sets the flag to show debug labels only for the currently picked tile. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.showOnlyPickedTileDebugLabel = false;
- const showGeometricError = knockout.observable();
- knockout.defineProperty(this, "showGeometricError", {
- get: function () {
- return showGeometricError();
- },
- set: function (value) {
- showGeometricError(value);
- if (defined(that._tileset)) {
- that._tileset.debugShowGeometricError = value;
- that._scene.requestRender();
- }
- },
- });
- /**
- * Gets or sets the flag to show tile geometric error. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.showGeometricError = false;
- const showRenderingStatistics = knockout.observable();
- knockout.defineProperty(this, "showRenderingStatistics", {
- get: function () {
- return showRenderingStatistics();
- },
- set: function (value) {
- showRenderingStatistics(value);
- if (defined(that._tileset)) {
- that._tileset.debugShowRenderingStatistics = value;
- that._scene.requestRender();
- }
- },
- });
- /**
- * Displays the number of commands, points, triangles and features used per tile. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.showRenderingStatistics = false;
- const showMemoryUsage = knockout.observable();
- knockout.defineProperty(this, "showMemoryUsage", {
- get: function () {
- return showMemoryUsage();
- },
- set: function (value) {
- showMemoryUsage(value);
- if (defined(that._tileset)) {
- that._tileset.debugShowMemoryUsage = value;
- that._scene.requestRender();
- }
- },
- });
- /**
- * Displays the memory used per tile. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.showMemoryUsage = false;
- const showUrl = knockout.observable();
- knockout.defineProperty(this, "showUrl", {
- get: function () {
- return showUrl();
- },
- set: function (value) {
- showUrl(value);
- if (defined(that._tileset)) {
- that._tileset.debugShowUrl = value;
- that._scene.requestRender();
- }
- },
- });
- /**
- * Gets or sets the flag to show the tile url. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.showUrl = false;
- const maximumScreenSpaceError = knockout.observable();
- knockout.defineProperty(this, "maximumScreenSpaceError", {
- get: function () {
- return maximumScreenSpaceError();
- },
- set: function (value) {
- value = Number(value);
- if (!isNaN(value)) {
- maximumScreenSpaceError(value);
- if (defined(that._tileset)) {
- that._tileset.maximumScreenSpaceError = value;
- }
- }
- },
- });
- /**
- * Gets or sets the maximum screen space error. This property is observable.
- *
- * @type {number}
- * @default 16
- */
- this.maximumScreenSpaceError = 16;
- const dynamicScreenSpaceErrorDensity = knockout.observable();
- knockout.defineProperty(this, "dynamicScreenSpaceErrorDensity", {
- get: function () {
- return dynamicScreenSpaceErrorDensity();
- },
- set: function (value) {
- value = Number(value);
- if (!isNaN(value)) {
- dynamicScreenSpaceErrorDensity(value);
- if (defined(that._tileset)) {
- that._tileset.dynamicScreenSpaceErrorDensity = value;
- }
- }
- },
- });
- /**
- * Gets or sets the dynamic screen space error density. This property is observable.
- *
- * @type {number}
- * @default 0.00278
- */
- this.dynamicScreenSpaceErrorDensity = 0.00278;
- /**
- * Gets or sets the dynamic screen space error density slider value.
- * This allows the slider to be exponential because values tend to be closer to 0 than 1.
- * This property is observable.
- *
- * @type {number}
- * @default 0.00278
- */
- this.dynamicScreenSpaceErrorDensitySliderValue = undefined;
- knockout.defineProperty(this, "dynamicScreenSpaceErrorDensitySliderValue", {
- get: function () {
- return Math.pow(dynamicScreenSpaceErrorDensity(), 1 / 6);
- },
- set: function (value) {
- dynamicScreenSpaceErrorDensity(Math.pow(value, 6));
- },
- });
- const dynamicScreenSpaceErrorFactor = knockout.observable();
- knockout.defineProperty(this, "dynamicScreenSpaceErrorFactor", {
- get: function () {
- return dynamicScreenSpaceErrorFactor();
- },
- set: function (value) {
- value = Number(value);
- if (!isNaN(value)) {
- dynamicScreenSpaceErrorFactor(value);
- if (defined(that._tileset)) {
- that._tileset.dynamicScreenSpaceErrorFactor = value;
- }
- }
- },
- });
- /**
- * Gets or sets the dynamic screen space error factor. This property is observable.
- *
- * @type {number}
- * @default 4.0
- */
- this.dynamicScreenSpaceErrorFactor = 4.0;
- const pickTileset = getPickTileset(this);
- const pickActive = knockout.observable();
- knockout.defineProperty(this, "pickActive", {
- get: function () {
- return pickActive();
- },
- set: function (value) {
- pickActive(value);
- if (value) {
- that._eventHandler.setInputAction(
- pickTileset,
- ScreenSpaceEventType.LEFT_CLICK
- );
- } else {
- that._eventHandler.removeInputAction(ScreenSpaceEventType.LEFT_CLICK);
- }
- },
- });
- const pointCloudShading = knockout.observable();
- knockout.defineProperty(this, "pointCloudShading", {
- get: function () {
- return pointCloudShading();
- },
- set: function (value) {
- pointCloudShading(value);
- if (defined(that._tileset)) {
- that._tileset.pointCloudShading.attenuation = value;
- }
- },
- });
- /**
- * Gets or sets the flag to enable point cloud shading. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.pointCloudShading = false;
- const geometricErrorScale = knockout.observable();
- knockout.defineProperty(this, "geometricErrorScale", {
- get: function () {
- return geometricErrorScale();
- },
- set: function (value) {
- value = Number(value);
- if (!isNaN(value)) {
- geometricErrorScale(value);
- if (defined(that._tileset)) {
- that._tileset.pointCloudShading.geometricErrorScale = value;
- }
- }
- },
- });
- /**
- * Gets or sets the geometric error scale. This property is observable.
- *
- * @type {number}
- * @default 1.0
- */
- this.geometricErrorScale = 1.0;
- const maximumAttenuation = knockout.observable();
- knockout.defineProperty(this, "maximumAttenuation", {
- get: function () {
- return maximumAttenuation();
- },
- set: function (value) {
- value = Number(value);
- if (!isNaN(value)) {
- maximumAttenuation(value);
- if (defined(that._tileset)) {
- that._tileset.pointCloudShading.maximumAttenuation =
- value === 0 ? undefined : value;
- }
- }
- },
- });
- /**
- * Gets or sets the maximum attenuation. This property is observable.
- *
- * @type {number}
- * @default 0
- */
- this.maximumAttenuation = 0;
- const baseResolution = knockout.observable();
- knockout.defineProperty(this, "baseResolution", {
- get: function () {
- return baseResolution();
- },
- set: function (value) {
- value = Number(value);
- if (!isNaN(value)) {
- baseResolution(value);
- if (defined(that._tileset)) {
- that._tileset.pointCloudShading.baseResolution =
- value === 0 ? undefined : value;
- }
- }
- },
- });
- /**
- * Gets or sets the base resolution. This property is observable.
- *
- * @type {number}
- * @default 0
- */
- this.baseResolution = 0;
- const eyeDomeLighting = knockout.observable();
- knockout.defineProperty(this, "eyeDomeLighting", {
- get: function () {
- return eyeDomeLighting();
- },
- set: function (value) {
- eyeDomeLighting(value);
- if (defined(that._tileset)) {
- that._tileset.pointCloudShading.eyeDomeLighting = value;
- }
- },
- });
- /**
- * Gets or sets the flag to enable eye dome lighting. This property is observable.
- *
- * @type {boolean}
- * @default false
- */
- this.eyeDomeLighting = false;
- const eyeDomeLightingStrength = knockout.observable();
- knockout.defineProperty(this, "eyeDomeLightingStrength", {
- get: function () {
- return eyeDomeLightingStrength();
- },
- set: function (value) {
- value = Number(value);
- if (!isNaN(value)) {
- eyeDomeLightingStrength(value);
- if (defined(that._tileset)) {
- that._tileset.pointCloudShading.eyeDomeLightingStrength = value;
- }
- }
- },
- });
- /**
- * Gets or sets the eye dome lighting strength. This property is observable.
- *
- * @type {number}
- * @default 1.0
- */
- this.eyeDomeLightingStrength = 1.0;
- const eyeDomeLightingRadius = knockout.observable();
- knockout.defineProperty(this, "eyeDomeLightingRadius", {
- get: function () {
- return eyeDomeLightingRadius();
- },
- set: function (value) {
- value = Number(value);
- if (!isNaN(value)) {
- eyeDomeLightingRadius(value);
- if (defined(that._tileset)) {
- that._tileset.pointCloudShading.eyeDomeLightingRadius = value;
- }
- }
- },
- });
- /**
- * Gets or sets the eye dome lighting radius. This property is observable.
- *
- * @type {number}
- * @default 1.0
- */
- this.eyeDomeLightingRadius = 1.0;
- /**
- * Gets or sets the pick state
- *
- * @type {boolean}
- * @default false
- */
- this.pickActive = false;
- const skipLevelOfDetail = knockout.observable();
- knockout.defineProperty(this, "skipLevelOfDetail", {
- get: function () {
- return skipLevelOfDetail();
- },
- set: function (value) {
- skipLevelOfDetail(value);
- if (defined(that._tileset)) {
- that._tileset.skipLevelOfDetail = value;
- }
- },
- });
- /**
- * Gets or sets the flag to determine if level of detail skipping should be applied during the traversal.
- * This property is observable.
- * @type {boolean}
- * @default true
- */
- this.skipLevelOfDetail = true;
- const skipScreenSpaceErrorFactor = knockout.observable();
- knockout.defineProperty(this, "skipScreenSpaceErrorFactor", {
- get: function () {
- return skipScreenSpaceErrorFactor();
- },
- set: function (value) {
- value = Number(value);
- if (!isNaN(value)) {
- skipScreenSpaceErrorFactor(value);
- if (defined(that._tileset)) {
- that._tileset.skipScreenSpaceErrorFactor = value;
- }
- }
- },
- });
- /**
- * Gets or sets the multiplier defining the minimum screen space error to skip. This property is observable.
- * @type {number}
- * @default 16
- */
- this.skipScreenSpaceErrorFactor = 16;
- const baseScreenSpaceError = knockout.observable();
- knockout.defineProperty(this, "baseScreenSpaceError", {
- get: function () {
- return baseScreenSpaceError();
- },
- set: function (value) {
- value = Number(value);
- if (!isNaN(value)) {
- baseScreenSpaceError(value);
- if (defined(that._tileset)) {
- that._tileset.baseScreenSpaceError = value;
- }
- }
- },
- });
- /**
- * Gets or sets the screen space error that must be reached before skipping levels of detail. This property is observable.
- * @type {number}
- * @default 1024
- */
- this.baseScreenSpaceError = 1024;
- const skipLevels = knockout.observable();
- knockout.defineProperty(this, "skipLevels", {
- get: function () {
- return skipLevels();
- },
- set: function (value) {
- value = Number(value);
- if (!isNaN(value)) {
- skipLevels(value);
- if (defined(that._tileset)) {
- that._tileset.skipLevels = value;
- }
- }
- },
- });
- /**
- * Gets or sets the constant defining the minimum number of levels to skip when loading tiles. This property is observable.
- * @type {number}
- * @default 1
- */
- this.skipLevels = 1;
- const immediatelyLoadDesiredLevelOfDetail = knockout.observable();
- knockout.defineProperty(this, "immediatelyLoadDesiredLevelOfDetail", {
- get: function () {
- return immediatelyLoadDesiredLevelOfDetail();
- },
- set: function (value) {
- immediatelyLoadDesiredLevelOfDetail(value);
- if (defined(that._tileset)) {
- that._tileset.immediatelyLoadDesiredLevelOfDetail = value;
- }
- },
- });
- /**
- * Gets or sets the flag which, when true, only tiles that meet the maximum screen space error will ever be downloaded.
- * This property is observable.
- * @type {boolean}
- * @default false
- */
- this.immediatelyLoadDesiredLevelOfDetail = false;
- const loadSiblings = knockout.observable();
- knockout.defineProperty(this, "loadSiblings", {
- get: function () {
- return loadSiblings();
- },
- set: function (value) {
- loadSiblings(value);
- if (defined(that._tileset)) {
- that._tileset.loadSiblings = value;
- }
- },
- });
- /**
- * Gets or sets the flag which determines whether siblings of visible tiles are always downloaded during traversal.
- * This property is observable
- * @type {boolean}
- * @default false
- */
- this.loadSiblings = false;
- this._style = undefined;
- this._shouldStyle = false;
- this._definedProperties = [
- "properties",
- "dynamicScreenSpaceError",
- "colorBlendMode",
- "picking",
- "colorize",
- "wireframe",
- "showBoundingVolumes",
- "showContentBoundingVolumes",
- "showRequestVolumes",
- "freezeFrame",
- "maximumScreenSpaceError",
- "dynamicScreenSpaceErrorDensity",
- "baseScreenSpaceError",
- "skipScreenSpaceErrorFactor",
- "skipLevelOfDetail",
- "skipLevels",
- "immediatelyLoadDesiredLevelOfDetail",
- "loadSiblings",
- "dynamicScreenSpaceErrorDensitySliderValue",
- "dynamicScreenSpaceErrorFactor",
- "pickActive",
- "showOnlyPickedTileDebugLabel",
- "showGeometricError",
- "showRenderingStatistics",
- "showMemoryUsage",
- "showUrl",
- "pointCloudShading",
- "geometricErrorScale",
- "maximumAttenuation",
- "baseResolution",
- "eyeDomeLighting",
- "eyeDomeLightingStrength",
- "eyeDomeLightingRadius",
- ];
- this._removePostRenderEvent = scene.postRender.addEventListener(function () {
- that._update();
- });
- if (!defined(this._tileset)) {
- selectTilesetOnHover(this, true);
- }
- }
- Object.defineProperties(Cesium3DTilesInspectorViewModel.prototype, {
- /**
- * Gets the scene
- * @memberof Cesium3DTilesInspectorViewModel.prototype
- * @type {Scene}
- * @readonly
- */
- scene: {
- get: function () {
- return this._scene;
- },
- },
- /**
- * Gets the performance container
- * @memberof Cesium3DTilesInspectorViewModel.prototype
- * @type {HTMLElement}
- * @readonly
- */
- performanceContainer: {
- get: function () {
- return this._performanceContainer;
- },
- },
- /**
- * Gets the statistics text. This property is observable.
- * @memberof Cesium3DTilesInspectorViewModel.prototype
- * @type {string}
- * @readonly
- */
- statisticsText: {
- get: function () {
- return this._statisticsText;
- },
- },
- /**
- * Gets the pick statistics text. This property is observable.
- * @memberof Cesium3DTilesInspectorViewModel.prototype
- * @type {string}
- * @readonly
- */
- pickStatisticsText: {
- get: function () {
- return this._pickStatisticsText;
- },
- },
- /**
- * Gets the resource cache statistics text. This property is observable.
- * @memberof Cesium3DTilesInspectorViewModel.prototype
- * @type {string}
- * @readonly
- */
- resourceCacheStatisticsText: {
- get: function () {
- return this._resourceCacheStatisticsText;
- },
- },
- /**
- * Gets the available blend modes
- * @memberof Cesium3DTilesInspectorViewModel.prototype
- * @type {Object[]}
- * @readonly
- */
- colorBlendModes: {
- get: function () {
- return colorBlendModes;
- },
- },
- /**
- * Gets the editor error message
- * @memberof Cesium3DTilesInspectorViewModel.prototype
- * @type {string}
- * @readonly
- */
- editorError: {
- get: function () {
- return this._editorError;
- },
- },
- /**
- * Gets or sets the tileset of the view model.
- * @memberof Cesium3DTilesInspectorViewModel.prototype
- * @type {Cesium3DTileset}
- */
- tileset: {
- get: function () {
- return this._tileset;
- },
- set: function (tileset) {
- this._tileset = tileset;
- this._style = undefined;
- this.styleString = "{}";
- this.feature = undefined;
- this.tile = undefined;
- if (defined(tileset)) {
- const that = this;
- // This is here for backwards compatibility. It can be removed when Cesium3DTileset.readyPromise is fully deprecated.
- tileset._readyPromise.then(function (t) {
- if (!that.isDestroyed()) {
- that._properties(t.properties);
- }
- });
- // update tileset with existing settings
- const settings = [
- "colorize",
- "wireframe",
- "showBoundingVolumes",
- "showContentBoundingVolumes",
- "showRequestVolumes",
- "freezeFrame",
- "showOnlyPickedTileDebugLabel",
- "showGeometricError",
- "showRenderingStatistics",
- "showMemoryUsage",
- "showUrl",
- ];
- const length = settings.length;
- for (let i = 0; i < length; ++i) {
- const setting = settings[i];
- //eslint-disable-next-line no-self-assign
- this[setting] = this[setting];
- }
- // update view model with existing tileset settings
- this.maximumScreenSpaceError = tileset.maximumScreenSpaceError;
- this.dynamicScreenSpaceError = tileset.dynamicScreenSpaceError;
- this.dynamicScreenSpaceErrorDensity =
- tileset.dynamicScreenSpaceErrorDensity;
- this.dynamicScreenSpaceErrorFactor =
- tileset.dynamicScreenSpaceErrorFactor;
- this.colorBlendMode = tileset.colorBlendMode;
- this.skipLevelOfDetail = tileset.skipLevelOfDetail;
- this.skipScreenSpaceErrorFactor = tileset.skipScreenSpaceErrorFactor;
- this.baseScreenSpaceError = tileset.baseScreenSpaceError;
- this.skipLevels = tileset.skipLevels;
- this.immediatelyLoadDesiredLevelOfDetail =
- tileset.immediatelyLoadDesiredLevelOfDetail;
- this.loadSiblings = tileset.loadSiblings;
- this.hasEnabledWireframe = tileset._enableDebugWireframe;
- const pointCloudShading = tileset.pointCloudShading;
- this.pointCloudShading = pointCloudShading.attenuation;
- this.geometricErrorScale = pointCloudShading.geometricErrorScale;
- this.maximumAttenuation = pointCloudShading.maximumAttenuation
- ? pointCloudShading.maximumAttenuation
- : 0.0;
- this.baseResolution = pointCloudShading.baseResolution
- ? pointCloudShading.baseResolution
- : 0.0;
- this.eyeDomeLighting = pointCloudShading.eyeDomeLighting;
- this.eyeDomeLightingStrength =
- pointCloudShading.eyeDomeLightingStrength;
- this.eyeDomeLightingRadius = pointCloudShading.eyeDomeLightingRadius;
- this._scene.requestRender();
- } else {
- this._properties({});
- }
- this._statisticsText = getStatistics(tileset, false);
- this._pickStatisticsText = getStatistics(tileset, true);
- this._resourceCacheStatisticsText = getResourceCacheStatistics();
- selectTilesetOnHover(this, false);
- },
- },
- /**
- * Gets the current feature of the view model.
- * @memberof Cesium3DTilesInspectorViewModel.prototype
- * @type {Cesium3DTileFeature}
- */
- feature: {
- get: function () {
- return this._feature;
- },
- set: function (feature) {
- if (this._feature === feature) {
- return;
- }
- const currentFeature = this._feature;
- if (defined(currentFeature) && !currentFeature.content.isDestroyed()) {
- // Restore original color to feature that is no longer selected
- if (!this.colorize && defined(this._style)) {
- currentFeature.color = defined(this._style.color)
- ? this._style.color.evaluateColor(currentFeature, scratchColor)
- : Color.WHITE;
- } else {
- currentFeature.color = oldColor;
- }
- this._scene.requestRender();
- }
- if (defined(feature)) {
- // Highlight new feature
- Color.clone(feature.color, oldColor);
- feature.color = highlightColor;
- this._scene.requestRender();
- }
- this._feature = feature;
- },
- },
- /**
- * Gets the current tile of the view model
- * @memberof Cesium3DTilesInspectorViewModel.prototype
- * @type {Cesium3DTile}
- */
- tile: {
- get: function () {
- return this._tile;
- },
- set: function (tile) {
- if (this._tile === tile) {
- return;
- }
- const currentTile = this._tile;
- if (
- defined(currentTile) &&
- !currentTile.isDestroyed() &&
- !hasFeatures(currentTile.content)
- ) {
- // Restore original color to tile that is no longer selected
- currentTile.color = oldColor;
- this._scene.requestRender();
- }
- if (defined(tile) && !hasFeatures(tile.content)) {
- // Highlight new tile
- Color.clone(tile.color, oldColor);
- tile.color = highlightColor;
- this._scene.requestRender();
- }
- this._tile = tile;
- },
- },
- });
- function hasFeatures(content) {
- if (!defined(content)) {
- return false;
- }
- if (content.featuresLength > 0) {
- return true;
- }
- const innerContents = content.innerContents;
- if (defined(innerContents)) {
- const length = innerContents.length;
- for (let i = 0; i < length; ++i) {
- if (!hasFeatures(innerContents[i])) {
- return false;
- }
- }
- return true;
- }
- return false;
- }
- /**
- * Toggles the pick tileset mode
- */
- Cesium3DTilesInspectorViewModel.prototype.togglePickTileset = function () {
- this.pickActive = !this.pickActive;
- };
- /**
- * Toggles the inspector visibility
- */
- Cesium3DTilesInspectorViewModel.prototype.toggleInspector = function () {
- this.inspectorVisible = !this.inspectorVisible;
- };
- /**
- * Toggles the visibility of the tileset section
- */
- Cesium3DTilesInspectorViewModel.prototype.toggleTileset = function () {
- this.tilesetVisible = !this.tilesetVisible;
- };
- /**
- * Toggles the visibility of the display section
- */
- Cesium3DTilesInspectorViewModel.prototype.toggleDisplay = function () {
- this.displayVisible = !this.displayVisible;
- };
- /**
- * Toggles the visibility of the update section
- */
- Cesium3DTilesInspectorViewModel.prototype.toggleUpdate = function () {
- this.updateVisible = !this.updateVisible;
- };
- /**
- * Toggles the visibility of the logging section
- */
- Cesium3DTilesInspectorViewModel.prototype.toggleLogging = function () {
- this.loggingVisible = !this.loggingVisible;
- };
- /**
- * Toggles the visibility of the style section
- */
- Cesium3DTilesInspectorViewModel.prototype.toggleStyle = function () {
- this.styleVisible = !this.styleVisible;
- };
- /**
- * Toggles the visibility of the tile Debug Info section
- */
- Cesium3DTilesInspectorViewModel.prototype.toggleTileDebugLabels = function () {
- this.tileDebugLabelsVisible = !this.tileDebugLabelsVisible;
- };
- /**
- * Toggles the visibility of the optimization section
- */
- Cesium3DTilesInspectorViewModel.prototype.toggleOptimization = function () {
- this.optimizationVisible = !this.optimizationVisible;
- };
- /**
- * Trims tile cache
- */
- Cesium3DTilesInspectorViewModel.prototype.trimTilesCache = function () {
- if (defined(this._tileset)) {
- this._tileset.trimLoadedTiles();
- }
- };
- /**
- * Compiles the style in the style editor.
- */
- Cesium3DTilesInspectorViewModel.prototype.compileStyle = function () {
- const tileset = this._tileset;
- if (!defined(tileset) || this.styleString === JSON.stringify(tileset.style)) {
- return;
- }
- this._editorError = "";
- try {
- if (this.styleString.length === 0) {
- this.styleString = "{}";
- }
- this._style = new Cesium3DTileStyle(JSON.parse(this.styleString));
- this._shouldStyle = true;
- this._scene.requestRender();
- } catch (err) {
- this._editorError = err.toString();
- }
- // set feature again so pick coloring is set
- this.feature = this._feature;
- this.tile = this._tile;
- };
- /**
- * Handles key press events on the style editor.
- */
- Cesium3DTilesInspectorViewModel.prototype.styleEditorKeyPress = function (
- sender,
- event
- ) {
- if (event.keyCode === 9) {
- //tab
- event.preventDefault();
- const textArea = event.target;
- const start = textArea.selectionStart;
- const end = textArea.selectionEnd;
- let newEnd = end;
- const selected = textArea.value.slice(start, end);
- const lines = selected.split("\n");
- const length = lines.length;
- let i;
- if (!event.shiftKey) {
- for (i = 0; i < length; ++i) {
- lines[i] = ` ${lines[i]}`;
- newEnd += 2;
- }
- } else {
- for (i = 0; i < length; ++i) {
- if (lines[i][0] === " ") {
- if (lines[i][1] === " ") {
- lines[i] = lines[i].substr(2);
- newEnd -= 2;
- } else {
- lines[i] = lines[i].substr(1);
- newEnd -= 1;
- }
- }
- }
- }
- const newText = lines.join("\n");
- textArea.value =
- textArea.value.slice(0, start) + newText + textArea.value.slice(end);
- textArea.selectionStart = start !== end ? start : newEnd;
- textArea.selectionEnd = newEnd;
- } else if (event.ctrlKey && (event.keyCode === 10 || event.keyCode === 13)) {
- //ctrl + enter
- this.compileStyle();
- }
- return true;
- };
- /**
- * Updates the values of view model
- * @private
- */
- Cesium3DTilesInspectorViewModel.prototype._update = function () {
- const tileset = this._tileset;
- if (this.performance) {
- this._performanceDisplay.update();
- }
- if (defined(tileset)) {
- if (tileset.isDestroyed()) {
- this.tile = undefined;
- this.feature = undefined;
- this.tileset = undefined;
- return;
- }
- const style = tileset.style;
- if (this._style !== tileset.style) {
- if (this._shouldStyle) {
- tileset.style = this._style;
- this._shouldStyle = false;
- } else {
- this._style = style;
- this.styleString = JSON.stringify(style.style, null, " ");
- }
- }
- }
- if (this.showStatistics) {
- this._statisticsText = getStatistics(tileset, false);
- this._pickStatisticsText = getStatistics(tileset, true);
- this._resourceCacheStatisticsText = getResourceCacheStatistics();
- }
- };
- /**
- * @returns {boolean} true if the object has been destroyed, false otherwise.
- */
- Cesium3DTilesInspectorViewModel.prototype.isDestroyed = function () {
- return false;
- };
- /**
- * Destroys the widget. Should be called if permanently
- * removing the widget from layout.
- */
- Cesium3DTilesInspectorViewModel.prototype.destroy = function () {
- this._eventHandler.destroy();
- this._removePostRenderEvent();
- const that = this;
- this._definedProperties.forEach(function (property) {
- knockout.getObservable(that, property).dispose();
- });
- return destroyObject(this);
- };
- /**
- * Generates an HTML string of the statistics
- *
- * @function
- * @param {Cesium3DTileset} tileset The tileset
- * @param {boolean} isPick Whether this is getting the statistics for the pick pass
- * @returns {string} The formatted statistics
- */
- Cesium3DTilesInspectorViewModel.getStatistics = getStatistics;
- export default Cesium3DTilesInspectorViewModel;
|