-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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- Terrain & optimizations, and/or option, plane primitives, edge highlighting #5996
Changes from 21 commits
d188014
8ef6754
51f28d0
d142b0f
4dfea3a
ee8b97a
33eb86a
951a33b
8981779
a0932d5
c0ec2c4
5ec1058
48190c7
443f73a
910e1c6
6d67925
086a03b
af21899
7487847
ea2d8da
227698c
e8e14f2
4a37690
93a2940
8d41a56
b4c9a8d
627b8d4
fd151a0
5b75ee5
92fc2bb
0af0db6
77457f5
47e0ec3
5680c34
21c96e9
3b069ca
82a2780
ca40033
31079f7
b83e288
2d855b8
c8cd6fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,107 +36,170 @@ | |
<div id="cesiumContainer" class="fullSize"></div> | ||
<div id="loadingOverlay"><h1>Loading...</h1></div> | ||
<div id="toolbar"> | ||
<table><tbody> | ||
<tr> | ||
<td>Type</td> | ||
<td><select data-bind="options: exampleTypes, value: exampleType"></select></td> | ||
</tr> | ||
<tr> | ||
<td>x</td> | ||
<td> | ||
<input type="range" min="-150" max="150" step="1" data-bind="value: xOffset, valueUpdate: 'input'"> | ||
<input type="text" size="2" data-bind="value: xOffset"> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>y</td> | ||
<td> | ||
<input type="range" min="-150" max="150" step="1" data-bind="value: yOffset, valueUpdate: 'input'"> | ||
<input type="text" size="2" data-bind="value: yOffset"> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>z</td> | ||
<td> | ||
<input type="range" min="-150" max="150" step="1" data-bind="value: zOffset, valueUpdate: 'input'"> | ||
<input type="text" size="2" data-bind="value: zOffset"> | ||
</td> | ||
</tr> | ||
</tbody></table> | ||
<input type="checkbox" value="false" data-bind="checked: clippingPlanesEnabled, valueUpdate: 'input'"> Enable clipping planes | ||
<select data-bind="options: exampleTypes, value: currentExampleType"></select> | ||
<input type="checkbox" value="false" data-bind="checked: debugBoundingVolumesEnabled, valueUpdate: 'input'"> Show debug <code>boundingVolume</code> | ||
</div> | ||
|
||
<script id="cesium_sandcastle_script"> | ||
function startup(Cesium) { | ||
'use strict'; | ||
//Sandcastle_Begin | ||
var viewer = new Cesium.Viewer('cesiumContainer'); | ||
var viewer = new Cesium.Viewer('cesiumContainer', { | ||
infoBox: false, | ||
selectionIndicator: false | ||
}); | ||
var scene = viewer.scene; | ||
|
||
var clippingPlanes; | ||
var defaultClippingPlanes = [ | ||
new Cesium.Plane(new Cesium.Cartesian3(1.0, 0.0, 0.0), 0.0), | ||
new Cesium.Plane(new Cesium.Cartesian3(0.0, 1.0, 0.0), -100.0), | ||
new Cesium.Plane(new Cesium.Cartesian3(0.0, 0.0,-1.0), -100.0) | ||
]; | ||
|
||
var clipObjects = ['BIM', 'Point Cloud', 'Model']; | ||
var viewModel = { | ||
exampleType : 'BIM', | ||
exampleTypes : ['BIM', 'Model', 'Point Cloud'], | ||
clippingPlanesEnabled: true, | ||
xOffset : 0.0, | ||
yOffset: -100.0, | ||
zOffset: -100.0, | ||
debugBoundingVolumesEnabled: false | ||
debugBoundingVolumesEnabled : false, | ||
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.CYAN.withAlpha(0.1); | ||
selectedPlane.outlineColor = Cesium.Color.CYAN; | ||
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; | ||
//var screenScale = scene.camera.getPixelSize(tileset.boundingSphere, scene.drawingBufferWidth, scene.drawingBufferHeight); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and the line below, remove the commented out code? |
||
targetY += deltaY;// * screenScale; | ||
} | ||
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE); | ||
|
||
var scratchPlane = new Cesium.Plane(Cesium.Cartesian3.UNIT_X, 0.0); | ||
function createPlaneUpdateFunction(plane, transform) { | ||
return function () { | ||
plane.distance = Cesium.Math.lerp(plane.distance, targetY, 0.1); | ||
|
||
var transformedPlane = Cesium.Plane.transform(plane, transform, scratchPlane); | ||
transformedPlane.distance = -transformedPlane.distance; | ||
return transformedPlane; | ||
}; | ||
} | ||
|
||
var tileset; | ||
function loadTileset(url) { | ||
reset(); | ||
|
||
tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ | ||
url : url | ||
url : url, | ||
clippingPlanes : new Cesium.ClippingPlanesCollection({ | ||
planes : defaultClippingPlanes, | ||
edgeWidth: 1.0, | ||
edgeColor: Cesium.Color.CYAN | ||
}) | ||
})); | ||
|
||
tileset.readyPromise.then(function() { | ||
var boundingSphere = tileset.boundingSphere; | ||
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.5, -0.2, boundingSphere.radius * 4.0)); | ||
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 < defaultClippingPlanes.length; ++i) { | ||
var clippingPlanes = tileset.clippingPlanes; | ||
var plane = clippingPlanes.planes[i]; | ||
var planeEntity = viewer.entities.add({ | ||
position : boundingSphere.center, | ||
plane : { | ||
dimensions : new Cesium.Cartesian2(radius * 2.5, radius * 2.5), | ||
material : Cesium.Color.CYAN.withAlpha(0.1), | ||
plane: new Cesium.CallbackProperty(createPlaneUpdateFunction(plane, tileset.modelMatrix), false), | ||
outline: true, | ||
outlineColor: Cesium.Color.CYAN | ||
} | ||
}); | ||
|
||
planeEntities.push(planeEntity); | ||
} | ||
|
||
}).otherwise(function(error) { | ||
throw(error); | ||
}); | ||
|
||
tileset.debugShowBoundingVolume = viewModel.debugBoundingVolumesEnabled; | ||
tileset.clippingPlanesEnabled = viewModel.clippingPlanesEnabled; | ||
clippingPlanes = tileset.clippingPlanes = defaultClippingPlanes.slice(); | ||
} | ||
|
||
var model; | ||
var modelEntity; | ||
function loadModel(url) { | ||
reset(); | ||
|
||
var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 100.0); | ||
var heading = Cesium.Math.toRadians(135); | ||
var pitch = 0; | ||
var roll = 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 | ||
minimumPixelSize: 100.0, | ||
clippingPlanes : new Cesium.ClippingPlanesCollection({ | ||
planes : defaultClippingPlanes, | ||
edgeWidth: 1.0, | ||
edgeColor: Cesium.Color.CYAN, | ||
transformationMatrix: Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationX(-Cesium.Math.PI_OVER_TWO)) | ||
}) | ||
} | ||
}); | ||
|
||
viewer.trackedEntity = entity; | ||
model = entity.model; | ||
model.clippingPlanesEnabled = viewModel.clippingPlanesEnabled; | ||
clippingPlanes = model.clippingPlanes = defaultClippingPlanes.slice(); | ||
modelEntity = entity.model; | ||
|
||
console.log(modelEntity); | ||
|
||
for (var i = 0; i < defaultClippingPlanes.length; ++i) { | ||
var clippingPlanes = tileset.clippingPlanes; | ||
var plane = clippingPlanes.planes[i]; | ||
var planeEntity = viewer.entities.add({ | ||
position : position, | ||
plane : { | ||
dimensions : new Cesium.Cartesian2(300.0, 300.0), | ||
material : Cesium.Color.CYAN.withAlpha(0.1), | ||
plane: new Cesium.CallbackProperty(createPlaneUpdateFunction(plane, Cesium.Matrix4.IDENTITY), false), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and throughout, replace things like |
||
outline: true, | ||
outlineColor: Cesium.Color.CYAN | ||
} | ||
}); | ||
|
||
planeEntities.push(planeEntity); | ||
} | ||
} | ||
|
||
// Power Plant design model provided by Bentley Systems | ||
|
@@ -151,16 +214,19 @@ | |
Cesium.knockout.track(viewModel); | ||
Cesium.knockout.applyBindings(viewModel, toolbar); | ||
|
||
Cesium.knockout.getObservable(viewModel, 'xOffset').subscribe(function(newValue) { | ||
clippingPlanes[0].distance = parseFloat(newValue); | ||
}); | ||
|
||
Cesium.knockout.getObservable(viewModel, 'yOffset').subscribe(function(newValue) { | ||
clippingPlanes[1].distance = parseFloat(newValue); | ||
}); | ||
Cesium.knockout.getObservable(viewModel, 'currentExampleType').subscribe(function(newValue) { | ||
reset(); | ||
|
||
Cesium.knockout.getObservable(viewModel, 'zOffset').subscribe(function(newValue) { | ||
clippingPlanes[2].distance = parseFloat(newValue); | ||
if (newValue === clipObjects[0]) { | ||
loadTileset(bimUrl); | ||
} else if (newValue === clipObjects[1]) { | ||
loadTileset(pointCloudUrl); | ||
tileset.readyPromise.then(function () { | ||
tileset.clippingPlanes.transformationMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center); | ||
}); | ||
} else { | ||
loadModel(modelUrl); | ||
} | ||
}); | ||
|
||
Cesium.knockout.getObservable(viewModel, 'debugBoundingVolumesEnabled').subscribe(function(newValue) { | ||
|
@@ -169,34 +235,10 @@ | |
} | ||
}); | ||
|
||
Cesium.knockout.getObservable(viewModel, 'clippingPlanesEnabled').subscribe(function(newValue) { | ||
if (Cesium.defined(tileset)) { | ||
tileset.clippingPlanesEnabled = newValue; | ||
} | ||
}); | ||
|
||
Cesium.knockout.getObservable(viewModel, 'exampleType').subscribe( | ||
function(newValue) { | ||
if (newValue === 'BIM') { | ||
loadTileset(bimUrl); | ||
} else if (newValue === 'Point Cloud') { | ||
loadTileset(pointCloudUrl); | ||
} else { | ||
loadModel(modelUrl); | ||
} | ||
} | ||
); | ||
|
||
function reset () { | ||
function reset() { | ||
viewer.entities.removeAll(); | ||
viewer.scene.primitives.removeAll(); | ||
|
||
if (Cesium.defined(viewModel)) { | ||
viewModel.clippingPlanesEnabled = true; | ||
viewModel.xOffset = 0.0; | ||
viewModel.yOffset = -100.0; | ||
viewModel.zOffset = -100.0; | ||
} | ||
planeEntities = []; | ||
} | ||
|
||
//Sandcastle_End | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!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="Clipping planes on terrain."> | ||
<meta name="cesium-sandcastle-labels" content="Beginner, 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', { | ||
terrainExaggeration : 3.0 | ||
}); | ||
|
||
var cesiumTerrainProviderMeshes = new Cesium.CesiumTerrainProvider({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for |
||
url : 'https://assets.agi.com/stk-terrain/v1/tilesets/world/tiles', | ||
requestWaterMask : true, | ||
requestVertexNormals : true | ||
}); | ||
viewer.terrainProvider = cesiumTerrainProviderMeshes; | ||
|
||
var globe = viewer.scene.globe; | ||
globe.terrainClippingPlanes = new Cesium.ClippingPlanesCollection({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When terrain is not used - and just the WGS84 provider is - clipping planes still work, correct? Perhaps rename |
||
transformationMatrix : Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(0.0, 0.0, 3000000.0)), | ||
planes : [ | ||
new Cesium.Plane(new Cesium.Cartesian3(0.0, 0.0, -1.0), 0.0), | ||
new Cesium.Plane(new Cesium.Cartesian3(0.0, 0.0, 1.0), 1000000.0) | ||
] | ||
}); | ||
|
||
//Sandcastle_End | ||
Sandcastle.finishedLoading(); | ||
} | ||
if (typeof Cesium !== "undefined") { | ||
startup(Cesium); | ||
} else if (typeof require === "function") { | ||
require(["Cesium"], startup); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,11 @@ Change Log | |
|
||
## TODO release | ||
|
||
* Added `clippingPlanes` property to `ModelGraphics` and `Cesium3DTileset`, which specifies an array of planes to clip the object. [TODO]() | ||
* Added `clippingPlanes` property to `ModelGraphics` and `Cesium3DTileset`, which specifies a `ClippingPlanesCollection` to clip the object. [TODO]() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the TODO links? I think we can merge |
||
* Added `terrainClippingPlanes` property to `Globe` which specifies a `ClippingPlanesCollection` to clip the terrain. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tweak - assuming this clips more than the terrain. |
||
* Added `Plane.transformPlane` function to apply a transformation to a plane. [TODO]() | ||
* Added `PlaneGeometry` and `PlaneOutlineGeometry` primitives | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are not primitives. |
||
* Added `PlaneGraphics` and `plane` property to `Entity`. | ||
|
||
### 1.38 - 2017-10-02 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
define([ | ||
'./Cartesian3', | ||
'./Check', | ||
'./defaultValue', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
'./defined', | ||
'./DeveloperError', | ||
'./freezeObject', | ||
|
@@ -9,6 +10,7 @@ define([ | |
], function( | ||
Cartesian3, | ||
Check, | ||
defaultValue, | ||
defined, | ||
DeveloperError, | ||
freezeObject, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps rename the examples to