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

Invert classification #5836

Merged
merged 21 commits into from
Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from 12 commits
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
252 changes: 126 additions & 126 deletions Apps/Sandcastle/gallery/Classification.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,111 @@
var scene = viewer.scene;
var camera = scene.camera;

var buildingHighlight;
var treeHighlight1;
var treeHighlight2;
var treeHighlight3;
var treeHighlight4;

function removePrimitives() {
if (Cesium.defined(buildingHighlight)) {
scene.primitives.remove(buildingHighlight);
}
if (Cesium.defined(treeHighlight1)) {
scene.primitives.remove(treeHighlight1);
scene.primitives.remove(treeHighlight2);
scene.primitives.remove(treeHighlight3);
scene.primitives.remove(treeHighlight4);
}
}
var center = new Cesium.Cartesian3(1216378.730451297, -4736275.917774027, 4081266.871000864);
var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
var hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-2.619728786416368, 0.0, 0.0));
var hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(0.0, 0.0, -2.0));
Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix);

var buildingHighlight = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : Cesium.BoxGeometry.fromDimensions({
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
dimensions : new Cesium.Cartesian3(8.0, 5.0, 8.0)
}),
modelMatrix : modelMatrix,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 0.0, 0.0, 0.5)),
show : new Cesium.ShowGeometryInstanceAttribute(true)
},
id : 'volume'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));

function highlightBuilding() {
Sandcastle.declare(highlightBuilding);

removePrimitives();

var center = new Cesium.Cartesian3(1216378.730451297, -4736275.917774027, 4081266.871000864);
var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
var hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-2.619728786416368, 0.0, 0.0));
var hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(0.0, 0.0, -2.0));
Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix);

buildingHighlight = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : Cesium.BoxGeometry.fromDimensions({
vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
dimensions : new Cesium.Cartesian3(8.0, 5.0, 8.0)
}),
modelMatrix : modelMatrix,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 0.0, 0.0, 0.5))
},
id : 'volume'
center = new Cesium.Cartesian3(1216398.6054139996, -4736204.533089285, 4081338.6585485404);
modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0));
hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(0.4, 0.0, -2.0));
Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix);

var treeHighlight1 = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.EllipsoidGeometry({
radii : new Cesium.Cartesian3(3.25, 5.0, 4.0)
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));
modelMatrix : modelMatrix,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString('#F26419').withAlpha(0.5)),
show : new Cesium.ShowGeometryInstanceAttribute(true)
},
id : 'volume 1'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));

center = new Cesium.Cartesian3(1216394.3346955755, -4736207.431365568, 4081336.7768881875);
modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0));
hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(-0.25, 0.0, -2.0));
Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix);

var treeHighlight2 = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.EllipsoidGeometry({
radii : new Cesium.Cartesian3(3.25, 5.0, 4.0)
}),
modelMatrix : modelMatrix,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString('#F03A47').withAlpha(0.5)),
show : new Cesium.ShowGeometryInstanceAttribute(true)
},
id : 'volume 2'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));

center = new Cesium.Cartesian3(1216388.1664430483, -4736210.034324032, 4081332.9324705894);
modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
var translation = Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(0.0, 0.0, -2.0));
Cesium.Matrix4.multiply(modelMatrix, translation, modelMatrix);

var treeHighlight3 = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.EllipsoidGeometry({
radii : new Cesium.Cartesian3(2.45, 2.45, 3.0)
}),
modelMatrix : modelMatrix,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString('#004FFF').withAlpha(0.5)),
show : new Cesium.ShowGeometryInstanceAttribute(true)
},
id : 'volume 3'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));

center = new Cesium.Cartesian3(1216383.1478702603, -4736211.716097012, 4081329.551077661);
modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
translation = Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(0.0, 0.0, -1.0));
Cesium.Matrix4.multiply(modelMatrix, translation, modelMatrix);

var treeHighlight4 = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.SphereGeometry({
radius : 2.0
}),
modelMatrix : modelMatrix,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString('#55DDE0').withAlpha(0.5)),
show : new Cesium.ShowGeometryInstanceAttribute(true)
},
id : 'volume 4'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));

function highlightBuilding() {
camera.setView({
destination : new Cesium.Cartesian3(1216390.8470847877, -4736277.616363206, 4081242.6450737054),
orientation : {
Expand All @@ -85,88 +146,6 @@
}

function highlightTrees() {
Sandcastle.declare(highlightTrees);

removePrimitives();

var center = new Cesium.Cartesian3(1216398.6054139996, -4736204.533089285, 4081338.6585485404);
var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
var hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0));
var hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(0.4, 0.0, -2.0));
Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix);

treeHighlight1 = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.EllipsoidGeometry({
radii : new Cesium.Cartesian3(3.25, 5.0, 4.0)
}),
modelMatrix : modelMatrix,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString('#F26419').withAlpha(0.5))
},
id : 'volume 1'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));

center = new Cesium.Cartesian3(1216394.3346955755, -4736207.431365568, 4081336.7768881875);
modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
hprRotation = Cesium.Matrix3.fromHeadingPitchRoll(new Cesium.HeadingPitchRoll(-5.785339046755887, 0.0, 0.0));
hpr = Cesium.Matrix4.fromRotationTranslation(hprRotation, new Cesium.Cartesian3(-0.25, 0.0, -2.0));
Cesium.Matrix4.multiply(modelMatrix, hpr, modelMatrix);

treeHighlight2 = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.EllipsoidGeometry({
radii : new Cesium.Cartesian3(3.25, 5.0, 4.0)
}),
modelMatrix : modelMatrix,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString('#F03A47').withAlpha(0.5))
},
id : 'volume 2'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));

center = new Cesium.Cartesian3(1216388.1664430483, -4736210.034324032, 4081332.9324705894);
modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
var translation = Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(0.0, 0.0, -2.0));
Cesium.Matrix4.multiply(modelMatrix, translation, modelMatrix);

treeHighlight3 = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.EllipsoidGeometry({
radii : new Cesium.Cartesian3(2.45, 2.45, 3.0)
}),
modelMatrix : modelMatrix,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString('#004FFF').withAlpha(0.5))
},
id : 'volume 3'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));

center = new Cesium.Cartesian3(1216383.1478702603, -4736211.716097012, 4081329.551077661);
modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
translation = Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(0.0, 0.0, -1.0));
Cesium.Matrix4.multiply(modelMatrix, translation, modelMatrix);

treeHighlight4 = scene.primitives.add(new Cesium.ClassificationPrimitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.SphereGeometry({
radius : 2.0
}),
modelMatrix : modelMatrix,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.fromCssColorString('#55DDE0').withAlpha(0.5))
},
id : 'volume 4'
}),
classificationType : Cesium.ClassificationType.CESIUM_3D_TILE
}));

camera.setView({
destination : new Cesium.Cartesian3(1216424.420697336, -4736234.517874706, 4081307.8699144847),
orientation : {
Expand All @@ -176,13 +155,25 @@
});
}

function invertClassification(checked) {
viewer.scene.invertClassification = checked;
viewer.scene.invertClassificationColor = new Cesium.Color(0.25, 0.25, 0.25, 1.0);

buildingHighlight.getGeometryInstanceAttributes('volume').show = Cesium.ShowGeometryInstanceAttribute.toValue(!checked);
treeHighlight1.getGeometryInstanceAttributes('volume 1').show = Cesium.ShowGeometryInstanceAttribute.toValue(!checked);
treeHighlight2.getGeometryInstanceAttributes('volume 2').show = Cesium.ShowGeometryInstanceAttribute.toValue(!checked);
treeHighlight3.getGeometryInstanceAttributes('volume 3').show = Cesium.ShowGeometryInstanceAttribute.toValue(!checked);
treeHighlight4.getGeometryInstanceAttributes('volume 4').show = Cesium.ShowGeometryInstanceAttribute.toValue(!checked);
}

var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url : 'https://beta.cesium.com/api/assets/1458?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIxYmJiNTAxOC1lOTg5LTQzN2EtODg1OC0zMWJjM2IxNGNlYmMiLCJpZCI6NDQsImFzc2V0cyI6WzE0NThdLCJpYXQiOjE0OTkyNjM4MjB9.1WKijRa-ILkmG6utrhDWX6rDgasjD7dZv-G5ZyCmkKg'
}));

tileset.readyPromise.then(function() {
Sandcastle.addToolbarButton('Highlight building face', highlightBuilding);
Sandcastle.addToolbarButton('Highlight trees', highlightTrees);
Sandcastle.addToggleButton('Invert classification', false, invertClassification);

highlightTrees();
}).otherwise(function(error) {
Expand All @@ -192,6 +183,8 @@
var currentObjectId;
var currentPrimitive;
var currentColor;
var currentShow;
var attributes;

var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
Expand All @@ -202,21 +195,28 @@
}

if (Cesium.defined(currentObjectId)) {
currentPrimitive.getGeometryInstanceAttributes(currentObjectId).color = currentColor;
attributes = currentPrimitive.getGeometryInstanceAttributes(currentObjectId);
attributes.color = currentColor;
attributes.show = currentShow;
currentObjectId = undefined;
currentPrimitive = undefined;
currentColor = undefined;
currentShow = undefined;
}
}

if (Cesium.defined(pickedObject) && Cesium.defined(pickedObject.primitive) && Cesium.defined(pickedObject.id) && Cesium.defined(pickedObject.primitive.getGeometryInstanceAttributes)) {
currentObjectId = pickedObject.id;
currentPrimitive = pickedObject.primitive;
var attributes = currentPrimitive.getGeometryInstanceAttributes(currentObjectId);
attributes = currentPrimitive.getGeometryInstanceAttributes(currentObjectId);
currentColor = attributes.color;
currentShow = attributes.show;
attributes.color = [255, 0, 255, 128];
attributes.show = [1];
} else if (Cesium.defined(currentObjectId)) {
currentPrimitive.getGeometryInstanceAttributes(currentObjectId).color = currentColor;
attributes = currentPrimitive.getGeometryInstanceAttributes(currentObjectId);
attributes.color = currentColor;
attributes.show = currentShow;
currentObjectId = undefined;
currentPrimitive = undefined;
currentColor = undefined;
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Change Log
* Fixed removing multiple event listeners within event callbacks. [#5827](https://github.com/AnalyticalGraphicsInc/cesium/issues/5827)
* Running `buildApps` now creates a built version of Sandcastle which uses the built version of Cesium for better performance.
* Fixed a tileset traversal bug when the `skipLevelOfDetail` optimization is off. [#5869](https://github.com/AnalyticalGraphicsInc/cesium/issues/5869)
* Adds `invertClassification` and `invertClassificationColor` to `Scene`. When `invertClassification` is `true`, any 3D Tiles geometry that is not classified will have its color multiplied by `invertClassificationColor`. [#5836](https://github.com/AnalyticalGraphicsInc/cesium/pull/5836)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also apply to the classification primitives? I think so, right? If so, then update this.

Otherwise, if this is 3D Tiles specific, maybe rename to invert3DTilesClassification and invert3DTilesClassificationColor?

Longer-term, would this move to per-primitive/tileset properties that could use the bounding volume as a scissor? Maybe an event could notify the scene when these are enabled so that the main rendering pipeline still has the information it needs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. It applies to ClassificationPrimitive and GroundPrimitive.

Yes, longer-term we could move this to per-primitive/tileset properties.


### 1.37 - 2017-09-01

Expand Down
14 changes: 14 additions & 0 deletions Source/Renderer/AutomaticUniforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,20 @@ define([
getValue : function(uniformState) {
return uniformState.minimumDisableDepthTestDistance;
}
}),

/**
* An automatic GLSL uniform that will be the highlight color of unclassified 3D Tiles.
*
* @alias czm_invertClassificationColor
* @glslUniform
*/
czm_invertClassificationColor : new AutomaticUniform({
size : 1,
datatype : WebGLConstants.FLOAT_VEC4,
getValue : function(uniformState) {
return uniformState.invertClassificationColor;
}
})
};

Expand Down
9 changes: 5 additions & 4 deletions Source/Renderer/Pass.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ define([
TERRAIN_CLASSIFICATION : 3,
CESIUM_3D_TILE : 4,
CESIUM_3D_TILE_CLASSIFICATION : 5,
OPAQUE : 6,
TRANSLUCENT : 7,
OVERLAY : 8,
NUMBER_OF_PASSES : 9
CESIUM_3D_TILE_CLASSIFICATION_IGNORE_SHOW : 6,
OPAQUE : 7,
TRANSLUCENT : 8,
OVERLAY : 9,
NUMBER_OF_PASSES : 10
};

return freezeObject(Pass);
Expand Down
16 changes: 16 additions & 0 deletions Source/Renderer/UniformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ define([

this._fogDensity = undefined;

this._invertClassificationColor = undefined;

this._imagerySplitPosition = 0.0;
this._pixelSizePerMeter = undefined;
this._geometricToleranceOverMeter = undefined;
Expand Down Expand Up @@ -847,6 +849,18 @@ define([
get : function() {
return this._minimumDisableDepthTestDistance;
}
},

/**
* The highlight color of unclassified 3D Tiles.
*
* @memberof UniformState.prototype
* @type {Color}
*/
invertClassificationColor : {
get : function() {
return this._invertClassificationColor;
}
}
});

Expand Down Expand Up @@ -1012,6 +1026,8 @@ define([

this._fogDensity = frameState.fog.density;

this._invertClassificationColor = frameState.invertClassificationColor;

this._frameState = frameState;
this._temeToPseudoFixed = Transforms.computeTemeToPseudoFixedMatrix(frameState.time, this._temeToPseudoFixed);

Expand Down
Loading