|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> <!-- Use Chrome Frame in IE --> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"> |
| 7 | + <meta name="description" content="User-defined clipping planes applied to a batched 3D Tileset, point cloud, and model."> |
| 8 | + <meta name="cesium-sandcastle-labels" content="Showcases, 3D Tiles"> |
| 9 | + <title>Cesium Demo</title> |
| 10 | + <script type="text/javascript" src="../Sandcastle-header.js"></script> |
| 11 | + <script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script> |
| 12 | + <script type="text/javascript"> |
| 13 | + require.config({ |
| 14 | + baseUrl : '../../../Source', |
| 15 | + waitSeconds : 60 |
| 16 | + }); |
| 17 | + </script> |
| 18 | +</head> |
| 19 | +<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html"> |
| 20 | +<style> |
| 21 | + @import url(../templates/bucket.css); |
| 22 | + #toolbar { |
| 23 | + background: rgba(42, 42, 42, 0.8); |
| 24 | + padding: 4px; |
| 25 | + border-radius: 4px; |
| 26 | + } |
| 27 | + #toolbar input { |
| 28 | + vertical-align: middle; |
| 29 | + padding-top: 2px; |
| 30 | + padding-bottom: 2px; |
| 31 | + } |
| 32 | + #toolbar .header { |
| 33 | + font-weight: bold; |
| 34 | + } |
| 35 | +</style> |
| 36 | +<div id="cesiumContainer" class="fullSize"></div> |
| 37 | +<div id="loadingOverlay"><h1>Loading...</h1></div> |
| 38 | +<div id="toolbar"> |
| 39 | + <select data-bind="options: exampleTypes, value: currentExampleType"></select> |
| 40 | + <input type="checkbox" value="false" data-bind="checked: debugBoundingVolumesEnabled, valueUpdate: 'input'"> Show bounding volume |
| 41 | + <input type="checkbox" value="true" data-bind="checked: edgeStylingEnabled, valueUpdate: 'input'"> Enable edge styling |
| 42 | +</div> |
| 43 | + |
| 44 | +<script id="cesium_sandcastle_script"> |
| 45 | +function startup(Cesium) { |
| 46 | + 'use strict'; |
| 47 | +//Sandcastle_Begin |
| 48 | + |
| 49 | +// Add a clipping plane, a plane geometry to show the representation of the |
| 50 | +// plane, and control the magnitude of the plane distance with the mouse. |
| 51 | +// Clipping planes are not currently supported in Internet Explorer. |
| 52 | + |
| 53 | +var viewer = new Cesium.Viewer('cesiumContainer', { |
| 54 | + infoBox: false, |
| 55 | + selectionIndicator: false |
| 56 | +}); |
| 57 | +var scene = viewer.scene; |
| 58 | + |
| 59 | +var clipObjects = ['BIM', 'Point Cloud', 'Instanced', 'Model']; |
| 60 | +var viewModel = { |
| 61 | + debugBoundingVolumesEnabled : false, |
| 62 | + edgeStylingEnabled : true, |
| 63 | + exampleTypes : clipObjects, |
| 64 | + currentExampleType : clipObjects[0] |
| 65 | +}; |
| 66 | + |
| 67 | +var targetY = 0.0; |
| 68 | +var planeEntities = []; |
| 69 | +var selectedPlane; |
| 70 | + |
| 71 | +// Select plane when mouse down |
| 72 | +var downHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas); |
| 73 | +downHandler.setInputAction(function(movement) { |
| 74 | + var pickedObject = scene.pick(movement.position); |
| 75 | + if (Cesium.defined(pickedObject) && |
| 76 | + Cesium.defined(pickedObject.id) && |
| 77 | + Cesium.defined(pickedObject.id.plane)) { |
| 78 | + selectedPlane = pickedObject.id.plane; |
| 79 | + selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.05); |
| 80 | + selectedPlane.outlineColor = Cesium.Color.WHITE; |
| 81 | + scene.screenSpaceCameraController.enableInputs = false; |
| 82 | + } |
| 83 | +}, Cesium.ScreenSpaceEventType.LEFT_DOWN); |
| 84 | + |
| 85 | +// Release plane on mouse up |
| 86 | +var upHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas); |
| 87 | +upHandler.setInputAction(function() { |
| 88 | + if (Cesium.defined(selectedPlane)) { |
| 89 | + selectedPlane.material = Cesium.Color.WHITE.withAlpha(0.1); |
| 90 | + selectedPlane.outlineColor = Cesium.Color.WHITE; |
| 91 | + selectedPlane = undefined; |
| 92 | + } |
| 93 | + |
| 94 | + scene.screenSpaceCameraController.enableInputs = true; |
| 95 | +}, Cesium.ScreenSpaceEventType.LEFT_UP); |
| 96 | + |
| 97 | +// Update plane on mouse move |
| 98 | +var moveHandler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas); |
| 99 | +moveHandler.setInputAction(function(movement) { |
| 100 | + if (Cesium.defined(selectedPlane)) { |
| 101 | + var deltaY = movement.startPosition.y - movement.endPosition.y; |
| 102 | + targetY += deltaY; |
| 103 | + } |
| 104 | +}, Cesium.ScreenSpaceEventType.MOUSE_MOVE); |
| 105 | + |
| 106 | +var scratchPlane = new Cesium.Plane(Cesium.Cartesian3.UNIT_X, 0.0); |
| 107 | +function createPlaneUpdateFunction(plane, transform) { |
| 108 | + return function () { |
| 109 | + plane.distance = targetY; |
| 110 | + return Cesium.Plane.transform(plane, transform, scratchPlane); |
| 111 | + }; |
| 112 | +} |
| 113 | + |
| 114 | +var tileset; |
| 115 | +function loadTileset(url) { |
| 116 | + var clippingPlanes = [ |
| 117 | + new Cesium.Plane(new Cesium.Cartesian3(0.0, 0.0, -1.0), -100.0) |
| 118 | + ]; |
| 119 | + |
| 120 | + tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ |
| 121 | + url : url, |
| 122 | + clippingPlanes : new Cesium.ClippingPlaneCollection({ |
| 123 | + planes : clippingPlanes, |
| 124 | + edgeWidth : viewModel.edgeStylingEnabled ? 1.0 : 0.0 |
| 125 | + }) |
| 126 | + })); |
| 127 | + |
| 128 | + tileset.readyPromise.then(function() { |
| 129 | + var boundingSphere = tileset.boundingSphere; |
| 130 | + var radius = boundingSphere.radius; |
| 131 | + |
| 132 | + viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.5, -0.2, radius * 4.0)); |
| 133 | + viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY); |
| 134 | + |
| 135 | + for (var i = 0; i < clippingPlanes.length; ++i) { |
| 136 | + var plane = clippingPlanes[i]; |
| 137 | + var planeEntity = viewer.entities.add({ |
| 138 | + position : boundingSphere.center, |
| 139 | + plane : { |
| 140 | + dimensions : new Cesium.Cartesian2(radius * 2.5, radius * 2.5), |
| 141 | + material : Cesium.Color.WHITE.withAlpha(0.1), |
| 142 | + plane : new Cesium.CallbackProperty(createPlaneUpdateFunction(plane, tileset.modelMatrix), false), |
| 143 | + outline : true, |
| 144 | + outlineColor : Cesium.Color.WHITE |
| 145 | + } |
| 146 | + }); |
| 147 | + |
| 148 | + planeEntities.push(planeEntity); |
| 149 | + } |
| 150 | + }).otherwise(function(error) { |
| 151 | + throw(error); |
| 152 | + }); |
| 153 | + |
| 154 | + tileset.debugShowBoundingVolume = viewModel.debugBoundingVolumesEnabled; |
| 155 | +} |
| 156 | + |
| 157 | +var modelEntityClippingPlanes; |
| 158 | +function loadModel(url) { |
| 159 | + var clippingPlanes = [ |
| 160 | + new Cesium.Plane(new Cesium.Cartesian3(0.0, 0.0, -1.0), -100.0) |
| 161 | + ]; |
| 162 | + |
| 163 | + modelEntityClippingPlanes = new Cesium.ClippingPlaneCollection({ |
| 164 | + planes : clippingPlanes, |
| 165 | + edgeWidth : viewModel.edgeStylingEnabled ? 1.0 : 0.0 |
| 166 | + }); |
| 167 | + |
| 168 | + function updateClippingPlanes() { |
| 169 | + return modelEntityClippingPlanes; |
| 170 | + } |
| 171 | + |
| 172 | + var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 100.0); |
| 173 | + var heading = Cesium.Math.toRadians(135.0); |
| 174 | + var pitch = 0.0; |
| 175 | + var roll = 0.0; |
| 176 | + var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); |
| 177 | + var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr); |
| 178 | + var entity = viewer.entities.add({ |
| 179 | + name : url, |
| 180 | + position : position, |
| 181 | + orientation : orientation, |
| 182 | + model : { |
| 183 | + uri : url, |
| 184 | + scale : 8, |
| 185 | + minimumPixelSize : 100.0, |
| 186 | + clippingPlanes : new Cesium.CallbackProperty(updateClippingPlanes, false) |
| 187 | + } |
| 188 | + }); |
| 189 | + |
| 190 | + viewer.trackedEntity = entity; |
| 191 | + |
| 192 | + for (var i = 0; i < clippingPlanes.length; ++i) { |
| 193 | + var plane = clippingPlanes[i]; |
| 194 | + var planeEntity = viewer.entities.add({ |
| 195 | + position : position, |
| 196 | + plane : { |
| 197 | + dimensions : new Cesium.Cartesian2(300.0, 300.0), |
| 198 | + material : Cesium.Color.WHITE.withAlpha(0.1), |
| 199 | + plane : new Cesium.CallbackProperty(createPlaneUpdateFunction(plane, Cesium.Matrix4.IDENTITY), false), |
| 200 | + outline : true, |
| 201 | + outlineColor : Cesium.Color.WHITE |
| 202 | + } |
| 203 | + }); |
| 204 | + |
| 205 | + planeEntities.push(planeEntity); |
| 206 | + } |
| 207 | +} |
| 208 | + |
| 209 | +// Power Plant design model provided by Bentley Systems |
| 210 | +var bimUrl = 'https://beta.cesium.com/api/assets/1459?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzNjUyM2I5Yy01YmRhLTQ0MjktOGI0Zi02MDdmYzBjMmY0MjYiLCJpZCI6NDQsImFzc2V0cyI6WzE0NTldLCJpYXQiOjE0OTkyNjQ3ODF9.SW_rwY-ic0TwQBeiweXNqFyywoxnnUBtcVjeCmDGef4'; |
| 211 | +var pointCloudUrl = 'https://beta.cesium.com/api/assets/1460?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyMzk2YzJiOS1jZGFmLTRlZmYtYmQ4MS00NTA3NjEwMzViZTkiLCJpZCI6NDQsImFzc2V0cyI6WzE0NjBdLCJpYXQiOjE0OTkyNjQ3NTV9.oWjvN52CRQ-dk3xtvD4e8ZnOHZhoWSpJLlw115mbQJM'; |
| 212 | +var instancedUrl = '../../../Specs/Data/Cesium3DTiles/Instanced/InstancedOrientation/'; |
| 213 | +var modelUrl = '../../SampleData/models/CesiumAir/Cesium_Air.glb'; |
| 214 | + |
| 215 | +loadTileset(bimUrl); |
| 216 | + |
| 217 | +// Track and create the bindings for the view model |
| 218 | +var toolbar = document.getElementById('toolbar'); |
| 219 | +Cesium.knockout.track(viewModel); |
| 220 | +Cesium.knockout.applyBindings(viewModel, toolbar); |
| 221 | + |
| 222 | +Cesium.knockout.getObservable(viewModel, 'currentExampleType').subscribe(function(newValue) { |
| 223 | + reset(); |
| 224 | + |
| 225 | + if (newValue === clipObjects[0]) { |
| 226 | + loadTileset(bimUrl); |
| 227 | + } else if (newValue === clipObjects[1]) { |
| 228 | + loadTileset(pointCloudUrl); |
| 229 | + tileset.readyPromise.then(function () { |
| 230 | + tileset.clippingPlanes.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center); |
| 231 | + }); |
| 232 | + } else if (newValue === clipObjects[2]) { |
| 233 | + loadTileset(instancedUrl); |
| 234 | + tileset.readyPromise.then(function () { |
| 235 | + tileset.clippingPlanes.modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(tileset.boundingSphere.center); |
| 236 | + }); |
| 237 | + } else { |
| 238 | + loadModel(modelUrl); |
| 239 | + } |
| 240 | +}); |
| 241 | + |
| 242 | +Cesium.knockout.getObservable(viewModel, 'debugBoundingVolumesEnabled').subscribe(function(value) { |
| 243 | + if (Cesium.defined(tileset)) { |
| 244 | + tileset.debugShowBoundingVolume = value; |
| 245 | + } |
| 246 | +}); |
| 247 | + |
| 248 | +Cesium.knockout.getObservable(viewModel, 'edgeStylingEnabled').subscribe(function(value) { |
| 249 | + var edgeWidth = value ? 1.0 : 0.0; |
| 250 | + |
| 251 | + if (Cesium.defined(tileset)) { |
| 252 | + tileset.clippingPlanes.edgeWidth = edgeWidth; |
| 253 | + } |
| 254 | + |
| 255 | + if (Cesium.defined(modelEntityClippingPlanes)) { |
| 256 | + modelEntityClippingPlanes.edgeWidth = edgeWidth; |
| 257 | + } |
| 258 | +}); |
| 259 | + |
| 260 | +function reset() { |
| 261 | + viewer.entities.removeAll(); |
| 262 | + viewer.scene.primitives.removeAll(); |
| 263 | + planeEntities = []; |
| 264 | + targetY = 0.0; |
| 265 | +} |
| 266 | + |
| 267 | +//Sandcastle_End |
| 268 | +Sandcastle.finishedLoading(); |
| 269 | +} |
| 270 | +if (typeof Cesium !== "undefined") { |
| 271 | + startup(Cesium); |
| 272 | +} else if (typeof require === "function") { |
| 273 | + require(["Cesium"], startup); |
| 274 | +} |
| 275 | +</script> |
| 276 | +</body> |
| 277 | +</html> |
0 commit comments