-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5913 from ggetz/clipping-planes-models
Clipping planes for models, tilesets, point clouds
- Loading branch information
Showing
11 changed files
with
380 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
<!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"> | ||
<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="-100" max="100" 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="-100" max="100" 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="-100" max="100" step="1" data-bind="value: zOffset, valueUpdate: 'input'"> | ||
<input type="text" size="2" data-bind="value: zOffset"> | ||
</td> | ||
</tr> | ||
</tbody></table> | ||
</div> | ||
|
||
<script id="cesium_sandcastle_script"> | ||
function startup(Cesium) { | ||
'use strict'; | ||
//Sandcastle_Begin | ||
var viewer = new Cesium.Viewer('cesiumContainer'); | ||
|
||
var defaultClippingPlanes = [ | ||
new Cesium.Plane(new Cesium.Cartesian3(-1, 0, 0), 0.0), | ||
new Cesium.Plane(new Cesium.Cartesian3(0, -1, 0), 100.0), | ||
new Cesium.Plane(new Cesium.Cartesian3(0, 0, 1), 100.0) | ||
]; | ||
|
||
function loadTileset (url) { | ||
reset(); | ||
|
||
var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ | ||
url : url | ||
})); | ||
|
||
tileset.readyPromise.then(function() { | ||
var boundingSphere = tileset.boundingSphere; | ||
viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.5, -0.2, boundingSphere.radius * 4.0)); | ||
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY); | ||
}).otherwise(function(error) { | ||
throw(error); | ||
}); | ||
|
||
tileset.clippingPlanes = defaultClippingPlanes; | ||
return tileset.clippingPlanes; | ||
} | ||
|
||
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 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 | ||
} | ||
}); | ||
|
||
viewer.trackedEntity = entity; | ||
|
||
entity.model.clippingPlanes = defaultClippingPlanes; | ||
return entity.model.clippingPlanes.getValue(); | ||
} | ||
|
||
// 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 modelUrl = '../../SampleData/models/CesiumAir/Cesium_Air.glb'; | ||
|
||
var clippingPlanes = loadTileset(bimUrl); | ||
|
||
// Track and create the bindings for the view model | ||
|
||
var viewModel = { | ||
exampleType : 'BIM', | ||
exampleTypes : ['BIM', 'Model', 'Point Cloud'], | ||
xOffset : 0.0, | ||
yOffset: 100.0, | ||
zOffset: 100.0 | ||
}; | ||
var toolbar = document.getElementById('toolbar'); | ||
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, 'zOffset').subscribe(function(newValue) { | ||
clippingPlanes[2].distance = parseFloat(newValue); | ||
}); | ||
|
||
Cesium.knockout.getObservable(viewModel, 'exampleType').subscribe( | ||
function(newValue) { | ||
if (newValue === 'BIM') { | ||
clippingPlanes = loadTileset(bimUrl); | ||
} else if (newValue === 'Point Cloud') { | ||
clippingPlanes = loadTileset(pointCloudUrl); | ||
} else { | ||
clippingPlanes = loadModel(modelUrl); | ||
} | ||
} | ||
); | ||
|
||
function reset () { | ||
viewer.entities.removeAll(); | ||
viewer.scene.primitives.removeAll(); | ||
|
||
if (Cesium.defined(viewModel)) { | ||
viewModel.xOffset = 0.0; | ||
viewModel.yOffset = 100.0; | ||
viewModel.zOffset = 100.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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.