123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455 |
- import Check from '../../Core/Check.js';
- import Color from '../../Core/Color.js';
- import defined from '../../Core/defined.js';
- import defineProperties from '../../Core/defineProperties.js';
- import destroyObject from '../../Core/destroyObject.js';
- import ScreenSpaceEventHandler from '../../Core/ScreenSpaceEventHandler.js';
- import ScreenSpaceEventType from '../../Core/ScreenSpaceEventType.js';
- import Cesium3DTileColorBlendMode from '../../Scene/Cesium3DTileColorBlendMode.js';
- import Cesium3DTileFeature from '../../Scene/Cesium3DTileFeature.js';
- import Cesium3DTilePass from '../../Scene/Cesium3DTilePass.js';
- import Cesium3DTileset from '../../Scene/Cesium3DTileset.js';
- import Cesium3DTileStyle from '../../Scene/Cesium3DTileStyle.js';
- import PerformanceDisplay from '../../Scene/PerformanceDisplay.js';
- import knockout from '../../ThirdParty/knockout.js';
- function getPickTileset(viewModel) {
- return function(e) {
- var 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) {
- var 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
- viewModel.picking = viewModel.picking; // eslint-disable-line no-self-assign
- }
- }
- var stringOptions = {
- maximumFractionDigits : 3
- };
- function formatMemoryString(memorySizeInBytes) {
- var 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 '';
- }
- var 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.
- var 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;
- }
- var colorBlendModes = [{
- text : 'Highlight',
- value : Cesium3DTileColorBlendMode.HIGHLIGHT
- }, {
- text : 'Replace',
- value : Cesium3DTileColorBlendMode.REPLACE
- }, {
- text : 'Mix',
- value : Cesium3DTileColorBlendMode.MIX
- }];
- var highlightColor = new Color(1.0, 1.0, 0.0, 0.4);
- var scratchColor = new Color();
- var 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');
- var that = this;
- var 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._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 false
- */
- this.showPickStatistics = true;
- /**
- * 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 = '{}';
- this._tileset = undefined;
- this._feature = undefined;
- this._tile = undefined;
- knockout.track(this, ['performance', 'inspectorVisible', '_statisticsText', '_pickStatisticsText', '_editorError', 'showPickStatistics', 'showStatistics',
- 'tilesetVisible', 'displayVisible', 'updateVisible', 'loggingVisible', 'styleVisible', 'optimizationVisible',
- 'tileDebugLabelsVisible', 'styleString', '_feature', '_tile']);
- 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() {
- var names = [];
- var properties = that._properties();
- for (var prop in properties) {
- if (properties.hasOwnProperty(prop)) {
- names.push(prop);
- }
- }
- return names;
- });
- var 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;
- var 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;
- var picking = knockout.observable();
- knockout.defineProperty(this, 'picking', {
- get : function() {
- return picking();
- },
- set : function(value) {
- picking(value);
- if (value) {
- that._eventHandler.setInputAction(function(e) {
- var 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)) { //eslint-disable-line no-use-before-define
- var 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;
- var 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;
- var 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;
- var 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;
- var 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;
- var 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;
- var 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;
- var showOnlyPickedTileDebugLabel = knockout.observable();
- 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;
- var 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;
- var 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;
- var 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;
- var 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;
- var 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;
- var 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));
- }
- });
- var 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;
- var pickTileset = getPickTileset(this);
- var 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);
- }
- }
- });
- var 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;
- var 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;
- var 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;
- var 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;
- var 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;
- var 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;
- var 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;
- var 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;
- var 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;
- var 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;
- var 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;
- var 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;
- var 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);
- }
- }
- 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 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)) {
- var that = this;
- tileset.readyPromise.then(function(t) {
- if (!that.isDestroyed()) {
- that._properties(t.properties);
- }
- });
- // update tileset with existing settings
- var settings = ['colorize',
- 'wireframe',
- 'showBoundingVolumes',
- 'showContentBoundingVolumes',
- 'showRequestVolumes',
- 'freezeFrame',
- 'showOnlyPickedTileDebugLabel',
- 'showGeometricError',
- 'showRenderingStatistics',
- 'showMemoryUsage',
- 'showUrl'];
- var length = settings.length;
- for (var i = 0; i < length; ++i) {
- var setting = settings[i];
- this[setting] = this[setting]; // eslint-disable-line no-self-assign
- }
- // 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;
- var 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);
- 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;
- }
- var 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;
- }
- var 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 (content.featuresLength > 0) {
- return true;
- }
- var innerContents = content.innerContents;
- if (defined(innerContents)) {
- var length = innerContents.length;
- for (var 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() {
- var 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();
- var textArea = event.target;
- var start = textArea.selectionStart;
- var end = textArea.selectionEnd;
- var newEnd = end;
- var selected = textArea.value.slice(start, end);
- var lines = selected.split('\n');
- var length = lines.length;
- var 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;
- }
- }
- }
- }
- var 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() {
- var 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;
- }
- var 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);
- }
- };
- /**
- * @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();
- var 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;
|