Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tile coloring #5358

Merged
merged 5 commits into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 44 additions & 6 deletions Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,13 @@ define([
this._debugBoundingVolume = undefined;
this._debugContentBoundingVolume = undefined;
this._debugViewerRequestVolume = undefined;
this._debugColor = new Color.fromRandom({ alpha : 1.0 });
this._debugColor = Color.fromRandom({ alpha : 1.0 });
this._debugColorizeTiles = false;

this._commandsLength = 0;

this._color = undefined;
this._colorDirty = false;
}

defineProperties(Cesium3DTile.prototype, {
Expand Down Expand Up @@ -401,6 +404,30 @@ define([
}
},

/**
* Gets and sets the tile's highlight color.
*
* @memberof Cesium3DTile.prototype
*
* @type {Color}
*
* @default {@link Color.WHITE}
*
* @private
*/
color : {
get : function() {
if (!defined(this._color)) {
this._color = new Color();
}
return Color.clone(this._color);
},
set : function(value) {
this._color = Color.clone(value, this._color);
this._colorDirty = true;
}
},

/**
* @readonly
* @private
Expand Down Expand Up @@ -914,13 +941,24 @@ define([
tile._debugViewerRequestVolume = tile._debugViewerRequestVolume.destroy();
}

if (tileset.debugColorizeTiles && !tile._debugColorizeTiles) {
var debugColorizeTilesOn = tileset.debugColorizeTiles && !tile._debugColorizeTiles;
var debugColorizeTilesOff = !tileset.debugColorizeTiles && tile._debugColorizeTiles;

if (debugColorizeTilesOn) {
tile._debugColorizeTiles = true;
tile._content.applyDebugSettings(true, tile._debugColor);
} else if (!tileset.debugColorizeTiles && tile._debugColorizeTiles) {
tile.color = tile._debugColor;
} else if (debugColorizeTilesOff) {
tile._debugColorizeTiles = false;
tile._content.applyDebugSettings(false, tile._debugColor);
tileset.makeStyleDirty(); //Re-apply style now that colorize is switched off
tile.color = Color.WHITE;
}

if (tile._colorDirty) {
tile._colorDirty = false;
tile._content.applyDebugSettings(true, tile._color);
}

if (debugColorizeTilesOff) {
tileset.makeStyleDirty(); // Re-apply style now that colorize is switched off
}
}

Expand Down
4 changes: 3 additions & 1 deletion Source/Scene/Cesium3DTileFeature.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/*global define*/
define([
'../Core/Color',
'../Core/defined',
'../Core/defineProperties'
], function(
Color,
defined,
defineProperties) {
'use strict';

Expand Down Expand Up @@ -91,7 +93,7 @@ define([
*/
color : {
get : function() {
if (!this._color) {
if (!defined(this._color)) {
this._color = new Color();
}
return this._content.batchTable.getColor(this._batchId, this._color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@ define([

this._tileset = undefined;
this._feature = undefined;
this._tile = undefined;

knockout.track(this, ['performance', 'inspectorVisible', '_statsText', '_pickStatsText', '_editorError', 'showPickStats', 'showStats',
'tilesetVisible', 'displayVisible', 'updateVisible', 'loggingVisible', 'styleVisible', 'tileDebugLabelsVisible', 'styleString', '_feature']);
'tilesetVisible', 'displayVisible', 'updateVisible', 'loggingVisible', 'styleVisible', 'tileDebugLabelsVisible', 'styleString', '_feature', '_tile']);

this._properties = knockout.observable({});
/**
Expand Down Expand Up @@ -326,11 +327,19 @@ define([
that._eventHandler.setInputAction(function(e) {
var picked = scene.pick(e.endPosition);
if (picked instanceof Cesium3DTileFeature) {
// Picked a feature
that.feature = picked;
that._pickStatsText = getStats(that._tileset, true);
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 (showOnlyPickedTileDebugLabel && defined(picked) && defined(picked.content)) {
var position;
if (scene.pickPositionSupported) {
Expand All @@ -346,6 +355,7 @@ define([
}, ScreenSpaceEventType.MOUSE_MOVE);
} else {
that.feature = undefined;
that.tile = undefined;
that._eventHandler.removeInputAction(ScreenSpaceEventType.MOUSE_MOVE);
}
}
Expand Down Expand Up @@ -758,6 +768,7 @@ define([
this._style = undefined;
this.styleString = '{}';
this.feature = undefined;
this.tile = undefined;

if (defined(tileset)) {
var that = this;
Expand Down Expand Up @@ -813,7 +824,7 @@ define([
return;
}
var currentFeature = this._feature;
if (defined(currentFeature) && defined(currentFeature.content.batchTable) && !currentFeature.content.batchTable.isDestroyed()) {
if (defined(currentFeature)) {
// Restore original color to feature that is no longer selected
var frameState = this._scene.frameState;
if (!this.colorize && defined(this._style)) {
Expand All @@ -829,6 +840,34 @@ define([
}
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.content.featuresLength === 0) {
// Restore original color to tile that is no longer selected
currentTile.color = oldColor;
}

if (defined(tile) && tile.content.featuresLength === 0) {
// Highlight new tile
Color.clone(tile.color, oldColor);
tile.color = highlightColor;
}
this._tile = tile;
}
}
});

Expand Down Expand Up @@ -918,6 +957,7 @@ define([

// set feature again so pick coloring is set
this.feature = this._feature;
this.tile = this._tile;
};

/**
Expand Down Expand Up @@ -987,6 +1027,7 @@ define([
}
if (this.showStats) {
this._statsText = getStats(tileset, false);
this._pickStatsText = getStats(tileset, true);
}
};

Expand Down
16 changes: 16 additions & 0 deletions Specs/Scene/Cesium3DTilesetSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,22 @@ defineSuite([
});
});

it('set tile color', function() {
return Cesium3DTilesTester.loadTileset(scene, noBatchIdsUrl).then(function(tileset) {
// Get initial color
var color;
Cesium3DTilesTester.expectRender(scene, tileset, function(rgba) {
color = rgba;
});

// Check for color
tileset._root.color = Color.RED;
Cesium3DTilesTester.expectRender(scene, tileset, function(rgba) {
expect(rgba).not.toEqual(color);
});
});
});

it('debugFreezeFrame', function() {
return Cesium3DTilesTester.loadTileset(scene, tilesetUrl).then(function(tileset) {
viewRootOnly();
Expand Down