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

Clipping Planes #6026

Merged
merged 78 commits into from
Dec 5, 2017
Merged
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
05a4387
Put clipping planes shader code in model
ggetz Oct 17, 2017
5d0d22e
Tileset clippingPlanes
ggetz Oct 17, 2017
cb685e4
Added sandcastle example
ggetz Oct 18, 2017
5512b11
Point clouds
ggetz Oct 18, 2017
ff35a7d
Fix error, cleanup
ggetz Oct 18, 2017
c3945d1
Plane relative to model origin
ggetz Oct 18, 2017
9252ad5
Sandcastle updates, point cloud update
ggetz Oct 18, 2017
2b342c0
Refactoring, update CHANGES.md
ggetz Oct 19, 2017
7a56927
Fix shader
ggetz Oct 25, 2017
1513f0c
Point cloud uniforms
ggetz Oct 25, 2017
d25a825
Cleanup sandcastle
ggetz Oct 25, 2017
8642cf7
Sandcastle cleanup, fix shaders
ggetz Oct 27, 2017
f843aa3
Fix scaling
ggetz Oct 27, 2017
d9a2c56
Updating clipping plane model scaling
ggetz Oct 30, 2017
bb4c63f
Updating clipping plane model scaling
ggetz Oct 30, 2017
5be9ef6
Clipping planes use computed model matrix
ggetz Oct 31, 2017
973ae3a
Apply scaling to clipping planes
ggetz Oct 31, 2017
7d6cba2
Packed planes class member
ggetz Nov 1, 2017
1c101a8
Formatting
ggetz Nov 2, 2017
b01ffa9
Check for undefined
ggetz Nov 2, 2017
7567c0c
Merge pull request #5913 from ggetz/clipping-planes-models
lilleyse Nov 2, 2017
271dade
Tileset traversal with clipping planes
ggetz Nov 3, 2017
d188014
Add plane geometry
ggetz Nov 6, 2017
5bd4ad6
Cleanup debug, use 'Check' in Plane, update CHANGES.md
ggetz Nov 6, 2017
ad4f9e5
Cleanup CullingVolume changes
ggetz Nov 6, 2017
02bdf52
Flip 'inside' and 'outside' for clipping
ggetz Nov 6, 2017
8ef6754
Merge branch 'clipping-planes-tileset-traversal' into clipping-planes…
ggetz Nov 6, 2017
072400c
Disable clipping in shader when tile will not be clipped
ggetz Nov 7, 2017
8330177
Doc fixes and sandcastle updates
ggetz Nov 7, 2017
45a48d0
Doc udates
ggetz Nov 8, 2017
a7fe4db
Allow undefined clipping planes, updated shader
ggetz Nov 8, 2017
f1197cd
Refactor name
ggetz Nov 8, 2017
e161b31
Performance fixes
ggetz Nov 8, 2017
51f28d0
Merge branch 'clipping-planes-tileset-traversal' into clipping-planes…
ggetz Nov 8, 2017
d142b0f
Added plane graphics and geometries, update clipping planes example
ggetz Nov 9, 2017
4dfea3a
Cleanup
ggetz Nov 9, 2017
ee8b97a
Update sandcastle demo, colors and scenario
ggetz Nov 10, 2017
33eb86a
Clipping planes on terrain
ggetz Nov 12, 2017
951a33b
Modified shaders to highlight clipping edge
ggetz Nov 13, 2017
8981779
Add demo
ggetz Nov 13, 2017
a0932d5
Merge branch 'clipping-planes-edge-styling' into clipping-planes-terr…
ggetz Nov 13, 2017
c0ec2c4
Add highlighting to terrain edges
ggetz Nov 13, 2017
5ec1058
Multiple clipping planes && together, define terrain clipping plane o…
ggetz Nov 14, 2017
48190c7
Merge branch 'clipping-planes-terrain-and-highlight-edges' into clipp…
ggetz Nov 17, 2017
443f73a
Add ClippingPlaneCollection
ggetz Nov 17, 2017
910e1c6
Fixed scaling in demo
ggetz Nov 17, 2017
6d67925
Optimize globe tile loading with clipping planes
ggetz Nov 20, 2017
32b01c1
Cleanup
ggetz Nov 21, 2017
261d0fc
Merge pull request #5966 from ggetz/clipping-planes-tileset-traversal
lilleyse Nov 21, 2017
086a03b
Cleanup docs
ggetz Nov 21, 2017
af21899
Updated CHANGES.md
ggetz Nov 21, 2017
7487847
Tweak doc
ggetz Nov 21, 2017
ea2d8da
Merge remote-tracking branch 'cesium/clip-planes-master' into clippin…
ggetz Nov 22, 2017
227698c
Update Sandcastle example, fix sandcastle images
ggetz Nov 22, 2017
e8e14f2
Refactor clipping planes
ggetz Nov 27, 2017
4a37690
Fix Plane geometry classes
ggetz Nov 27, 2017
93a2940
Fix doc
ggetz Nov 27, 2017
8d41a56
Pixel width for edge highlighting, fix model transforms
ggetz Nov 27, 2017
b4c9a8d
Point cloud clipping fix
ggetz Nov 27, 2017
627b8d4
Update clipping planes example
ggetz Nov 27, 2017
fd151a0
Indent includes
lilleyse Nov 28, 2017
5b75ee5
Cleanup and add plane geometry sandcastle example
ggetz Nov 29, 2017
92fc2bb
Fix failing tests
ggetz Nov 30, 2017
0af0db6
Specs
ggetz Nov 30, 2017
77457f5
Fix errors
ggetz Nov 30, 2017
47e0ec3
Cleanup, update specs
ggetz Dec 1, 2017
5680c34
Fix plane geometry surface
ggetz Dec 1, 2017
21c96e9
Draw commands in specs
ggetz Dec 1, 2017
3b069ca
Model and PlaneGeometry Specs
ggetz Dec 1, 2017
82a2780
Cleanup
ggetz Dec 1, 2017
ca40033
i3dm tileset in specs
ggetz Dec 1, 2017
31079f7
Added i3dm tilesets
ggetz Dec 1, 2017
b83e288
i3dm specs
ggetz Dec 1, 2017
2d855b8
Add instanced tileset to sandcastle example
ggetz Dec 2, 2017
c8cd6fa
Tweak sandcastle example
ggetz Dec 4, 2017
66d6e05
Merge pull request #5996 from ggetz/clipping-planes-terrain
lilleyse Dec 4, 2017
fc71bca
Merge remote-tracking branch 'cesium/master' into clip-planes-master
ggetz Dec 4, 2017
77c711c
Update CHANGES.md, cleanup docs
ggetz Dec 5, 2017
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
279 changes: 279 additions & 0 deletions Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
<!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="User-defined clipping planes applied to a batched 3D Tileset, point cloud, and model.">
<meta name="cesium-sandcastle-labels" content="Showcases, 3D Tiles">
<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);
#toolbar {
background: rgba(42, 42, 42, 0.8);
padding: 4px;
border-radius: 4px;
}
#toolbar input {
vertical-align: middle;
padding-top: 2px;
padding-bottom: 2px;
}
#toolbar .header {
font-weight: bold;
}
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar">
<select data-bind="options: exampleTypes, value: currentExampleType"></select>
<input type="checkbox" value="false" data-bind="checked: debugBoundingVolumesEnabled, valueUpdate: 'input'"> Show bounding volume
<input type="checkbox" value="true" data-bind="checked: edgeStylingEnabled, valueUpdate: 'input'"> Enable edge styling
</div>

<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin

// Add a clipping plane, a plane geometry to show the representation of the
// plane, and control the magnitude of the plane distance with the mouse.

var viewer = new Cesium.Viewer('cesiumContainer', {
infoBox: false,
selectionIndicator: false
});
var scene = viewer.scene;

var clipObjects = ['BIM', 'Point Cloud', 'Instanced', 'Model'];
var viewModel = {
debugBoundingVolumesEnabled : false,
edgeStylingEnabled : true,
exampleTypes : clipObjects,
currentExampleType : clipObjects[0]
};

var targetY = 0.0;
var planeEntities = [];
var selectedPlane;

// Select plane when mouse down
var downHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
downHandler.setInputAction(function(movement) {
var pickedObject = scene.pick(movement.position);
if (Cesium.defined(pickedObject) &&
Cesium.defined(pickedObject.id) &&
Cesium.defined(pickedObject.id.plane)) {
selectedPlane = pickedObject.id.plane;
selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.05);
selectedPlane.outlineColor = Cesium.Color.WHITE;
scene.screenSpaceCameraController.enableInputs = false;
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);

// Release plane on mouse up
var upHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
upHandler.setInputAction(function() {
if (Cesium.defined(selectedPlane)) {
selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.1);
selectedPlane.outlineColor = Cesium.Color.WHITE;
selectedPlane = undefined;
}

scene.screenSpaceCameraController.enableInputs = true;
}, Cesium.ScreenSpaceEventType.LEFT_UP);

// Update plane on mouse move
var moveHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
moveHandler.setInputAction(function(movement) {
if (Cesium.defined(selectedPlane)) {
var deltaY = movement.endPosition.y - movement.startPosition.y;
targetY += deltaY;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

var scratchPlane = new Cesium.Plane(Cesium.Cartesian3.UNIT_X, 0.0);
function createPlaneUpdateFunction(plane, transform) {
return function () {
plane.distance = targetY;

var transformedPlane = Cesium.Plane.transform(plane, transform, scratchPlane);
transformedPlane.distance = -transformedPlane.distance;
return transformedPlane;
};
}

var tileset;
function loadTileset(url) {
var clippingPlanes = [
new Cesium.Plane(new Cesium.Cartesian3(0.0, 0.0, -1.0), -100.0)
];

tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
url : url,
clippingPlanes : new Cesium.ClippingPlanesCollection({
planes : clippingPlanes,
edgeWidth : viewModel.edgeStylingEnabled ? 1.0 : 0.0
})
}));

tileset.readyPromise.then(function() {
var boundingSphere = tileset.boundingSphere;
var radius = boundingSphere.radius;

viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.5, -0.2, radius * 4.0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);

for (var i = 0; i < clippingPlanes.length; ++i) {
var plane = clippingPlanes[i];
var planeEntity = viewer.entities.add({
position : boundingSphere.center,
plane : {
dimensions : new Cesium.Cartesian2(radius * 2.5, radius * 2.5),
material : Cesium.Color.WHITE.withAlpha(0.1),
plane : new Cesium.CallbackProperty(createPlaneUpdateFunction(plane, tileset.modelMatrix), false),
outline : true,
outlineColor : Cesium.Color.WHITE
}
});

planeEntities.push(planeEntity);
}
}).otherwise(function(error) {
throw(error);
});

tileset.debugShowBoundingVolume = viewModel.debugBoundingVolumesEnabled;
}

var modelEntityClippingPlanes;
function loadModel(url) {
var clippingPlanes = [
new Cesium.Plane(new Cesium.Cartesian3(0.0, 0.0, -1.0), -100.0)
];

modelEntityClippingPlanes = new Cesium.ClippingPlanesCollection({
planes : clippingPlanes,
edgeWidth : viewModel.edgeStylingEnabled ? 1.0 : 0.0
});

function updateClippingPlanes() {
return modelEntityClippingPlanes;
}

var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 100.0);
var heading = Cesium.Math.toRadians(135.0);
var pitch = 0.0;
var roll = 0.0;
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
var entity = viewer.entities.add({
name : url,
position : position,
orientation : orientation,
model : {
uri : url,
scale : 8,
minimumPixelSize : 100.0,
clippingPlanes : new Cesium.CallbackProperty(updateClippingPlanes, false)
}
});

viewer.trackedEntity = entity;

for (var i = 0; i < clippingPlanes.length; ++i) {
var plane = clippingPlanes[i];
var planeEntity = viewer.entities.add({
position : position,
plane : {
dimensions : new Cesium.Cartesian2(300.0, 300.0),
material : Cesium.Color.WHITE.withAlpha(0.1),
plane : new Cesium.CallbackProperty(createPlaneUpdateFunction(plane, Cesium.Matrix4.IDENTITY), false),
outline : true,
outlineColor : Cesium.Color.WHITE
}
});

planeEntities.push(planeEntity);
}
}

// Power Plant design model provided by Bentley Systems
var bimUrl = 'https://beta.cesium.com/api/assets/1459?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzNjUyM2I5Yy01YmRhLTQ0MjktOGI0Zi02MDdmYzBjMmY0MjYiLCJpZCI6NDQsImFzc2V0cyI6WzE0NTldLCJpYXQiOjE0OTkyNjQ3ODF9.SW_rwY-ic0TwQBeiweXNqFyywoxnnUBtcVjeCmDGef4';
var pointCloudUrl = 'https://beta.cesium.com/api/assets/1460?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyMzk2YzJiOS1jZGFmLTRlZmYtYmQ4MS00NTA3NjEwMzViZTkiLCJpZCI6NDQsImFzc2V0cyI6WzE0NjBdLCJpYXQiOjE0OTkyNjQ3NTV9.oWjvN52CRQ-dk3xtvD4e8ZnOHZhoWSpJLlw115mbQJM';
var instancedUrl = '../../../Specs/Data/Cesium3DTiles/Instanced/InstancedOrientation/';
var modelUrl = '../../SampleData/models/CesiumAir/Cesium_Air.glb';

loadTileset(bimUrl);

// Track and create the bindings for the view model
var toolbar = document.getElementById('toolbar');
Cesium.knockout.track(viewModel);
Cesium.knockout.applyBindings(viewModel, toolbar);

Cesium.knockout.getObservable(viewModel, 'currentExampleType').subscribe(function(newValue) {
reset();

if (newValue === clipObjects[0]) {
loadTileset(bimUrl);
} else if (newValue === clipObjects[1]) {
loadTileset(pointCloudUrl);
tileset.readyPromise.then(function () {
tileset.clippingPlanes.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center);
});
} else if (newValue === clipObjects[2]) {
loadTileset(instancedUrl);
tileset.readyPromise.then(function () {
tileset.clippingPlanes.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center);
});
} else {
loadModel(modelUrl);
}
});

Cesium.knockout.getObservable(viewModel, 'debugBoundingVolumesEnabled').subscribe(function(value) {
if (Cesium.defined(tileset)) {
tileset.debugShowBoundingVolume = value;
}
});

Cesium.knockout.getObservable(viewModel, 'edgeStylingEnabled').subscribe(function(value) {
var edgeWidth = value ? 1.0 : 0.0;

if (Cesium.defined(tileset)) {
tileset.clippingPlanes.edgeWidth = edgeWidth;
}

if (Cesium.defined(modelEntityClippingPlanes)) {
modelEntityClippingPlanes.edgeWidth = edgeWidth;
}
});

function reset() {
viewer.entities.removeAll();
viewer.scene.primitives.removeAll();
planeEntities = [];
targetY = 0.0;
}

//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions Apps/Sandcastle/gallery/Plane.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Draw a plane geometry.">
<meta name="cesium-sandcastle-labels" content="Geometries">
<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 bluePlane = viewer.entities.add({
name : 'Blue plane',
position: Cesium.Cartesian3.fromDegrees(-114.0, 40.0, 300000.0),
plane : {
plane : new Cesium.Plane(Cesium.Cartesian3.UNIT_X, 0.0),
dimensions : new Cesium.Cartesian2(400000.0, 300000.0),
material : Cesium.Color.BLUE
}
});

var redPlane = viewer.entities.add({
name : 'Red plane with black outline',
position: Cesium.Cartesian3.fromDegrees(-107.0, 40.0, 300000.0),
plane : {
plane : new Cesium.Plane(Cesium.Cartesian3.UNIT_Y, 0.0),
dimensions : new Cesium.Cartesian2(400000.0, 300000.0),
material : Cesium.Color.RED.withAlpha(0.5),
outline : true,
outlineColor : Cesium.Color.BLACK
}
});

var outlineOnly = viewer.entities.add({
name : 'Yellow plane outline',
position: Cesium.Cartesian3.fromDegrees(-100.0, 40.0, 300000.0),
plane : {
plane : new Cesium.Plane(Cesium.Cartesian3.UNIT_Z, 0.0),
dimensions : new Cesium.Cartesian2(400000.0, 300000.0),
fill : false,
outline : true,
outlineColor : Cesium.Color.YELLOW
}
});

viewer.zoomTo(viewer.entities);
//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/Plane.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading