Skip to content

Commit

Permalink
Merge pull request #5625 from AnalyticalGraphicsInc/classification-pr…
Browse files Browse the repository at this point in the history
…imitive

Classification primitive
  • Loading branch information
pjcozzi authored Jul 21, 2017
2 parents 796b114 + 1ccd15b commit 69a7cc8
Show file tree
Hide file tree
Showing 15 changed files with 2,171 additions and 503 deletions.
232 changes: 232 additions & 0 deletions Apps/Sandcastle/gallery/Classification.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> <!-- Use Chrome Frame in IE -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Draw the intersection of a volume and a photgrammetry dataset.">
<meta name="cesium-sandcastle-labels" content="Tutorials, Showcases">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
@import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;
var camera = scene.camera;

scene.globe.depthTestAgainstTerrain = true;

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);
}
}

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'
})
}));

camera.setView({
destination : new Cesium.Cartesian3(1216390.8470847877, -4736277.616363206, 4081242.6450737054),
orientation : {
heading : 5.761321440006161,
pitch : 0.2784799327743841
}
});
}

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'
})
}));

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'
})
}));

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'
})
}));

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'
})
}));

camera.setView({
destination : new Cesium.Cartesian3(1216424.420697336, -4736234.517874706, 4081307.8699144847),
orientation : {
heading : 5.785339046755887,
pitch : -0.2622665042613537
}
});
}

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);

highlightBuilding();
}).otherwise(function(error) {
throw(error);
});

var currentObjectId;
var currentPrimitive;
var currentColor;

var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
var pickedObject = scene.pick(movement.endPosition);
if (Cesium.defined(pickedObject) && Cesium.defined(pickedObject.id)) {
if (pickedObject.id === currentObjectId) {
return;
}

if (Cesium.defined(currentObjectId)) {
currentPrimitive.getGeometryInstanceAttributes(currentObjectId).color = currentColor;
currentObjectId = undefined;
currentPrimitive = undefined;
currentColor = 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);
currentColor = attributes.color;
attributes.color = [255, 0, 255, 128];
} else if (Cesium.defined(currentObjectId)) {
currentPrimitive.getGeometryInstanceAttributes(currentObjectId).color = currentColor;
currentObjectId = undefined;
currentPrimitive = undefined;
currentColor = undefined;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
Binary file added Apps/Sandcastle/gallery/Classification.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Change Log
* Updated `Billboard`, `Label` and `PointPrimitive` constructors to clone `NearFarScale` parameters [#5654](https://github.com/AnalyticalGraphicsInc/cesium/pull/5654)
* Added `FrustumGeometry` and `FrustumOutlineGeometry`. [#5649](https://github.com/AnalyticalGraphicsInc/cesium/pull/5649)
* Added an `options` parameter to the constructors of `PerspectiveFrustum`, `PerspectiveOffCenterFrustum`, `OrthographicFrustum`, and `OrthographicOffCenterFrustum` to set properties. [#5649](https://github.com/AnalyticalGraphicsInc/cesium/pull/5649)
* Added `ClassificationPrimitive` which defines a volume and draws the intersection of the volume and terrain or 3D Tiles. [#5625](https://github.com/AnalyticalGraphicsInc/cesium/pull/5625)

### 1.35.2 - 2017-07-11

Expand Down
3 changes: 3 additions & 0 deletions Source/Scene/Batched3DModel3DTileContent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ define([
'../Core/getStringFromTypedArray',
'../Core/RequestType',
'../Core/RuntimeError',
'../Renderer/Pass',
'./Cesium3DTileBatchTable',
'./Cesium3DTileFeature',
'./Cesium3DTileFeatureTable',
Expand All @@ -33,6 +34,7 @@ define([
getStringFromTypedArray,
RequestType,
RuntimeError,
Pass,
Cesium3DTileBatchTable,
Cesium3DTileFeature,
Cesium3DTileFeatureTable,
Expand Down Expand Up @@ -352,6 +354,7 @@ define([
gltf : gltfView,
cull : false, // The model is already culled by 3D Tiles
releaseGltfJson : true, // Models are unique and will not benefit from caching so save memory
opaquePass : Pass.CESIUM_3D_TILE, // Draw opaque portions of the model during the 3D Tiles pass
basePath : basePath,
requestType : RequestType.TILES3D,
modelMatrix : tile.computedTransform,
Expand Down
4 changes: 0 additions & 4 deletions Source/Scene/Cesium3DTileBatchTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1305,10 +1305,6 @@ define([
// even though their style is opaque.
var translucentCommand = (derivedCommand.pass === Pass.TRANSLUCENT);

if (!translucentCommand) {
derivedCommand.pass = Pass.CESIUM_3D_TILE;
}

derivedCommand.uniformMap = defined(derivedCommand.uniformMap) ? derivedCommand.uniformMap : {};
derivedCommand.uniformMap.tile_translucentCommand = function() {
return translucentCommand;
Expand Down
Loading

0 comments on commit 69a7cc8

Please sign in to comment.