|
| 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 | + <table><tbody> |
| 40 | + <tr> |
| 41 | + <td>Type</td> |
| 42 | + <td><select data-bind="options: exampleTypes, value: exampleType"></select></td> |
| 43 | + </tr> |
| 44 | + <tr> |
| 45 | + <td>x</td> |
| 46 | + <td> |
| 47 | + <input type="range" min="-100" max="100" step="1" data-bind="value: xOffset, valueUpdate: 'input'"> |
| 48 | + <input type="text" size="2" data-bind="value: xOffset"> |
| 49 | + </td> |
| 50 | + </tr> |
| 51 | + <tr> |
| 52 | + <td>y</td> |
| 53 | + <td> |
| 54 | + <input type="range" min="-100" max="100" step="1" data-bind="value: yOffset, valueUpdate: 'input'"> |
| 55 | + <input type="text" size="2" data-bind="value: yOffset"> |
| 56 | + </td> |
| 57 | + </tr> |
| 58 | + <tr> |
| 59 | + <td>z</td> |
| 60 | + <td> |
| 61 | + <input type="range" min="-100" max="100" step="1" data-bind="value: zOffset, valueUpdate: 'input'"> |
| 62 | + <input type="text" size="2" data-bind="value: zOffset"> |
| 63 | + </td> |
| 64 | + </tr> |
| 65 | + </tbody></table> |
| 66 | +</div> |
| 67 | + |
| 68 | +<script id="cesium_sandcastle_script"> |
| 69 | +function startup(Cesium) { |
| 70 | + 'use strict'; |
| 71 | +//Sandcastle_Begin |
| 72 | +var viewer = new Cesium.Viewer('cesiumContainer'); |
| 73 | + |
| 74 | +var defaultClippingPlanes = [ |
| 75 | + new Cesium.Plane(new Cesium.Cartesian3(-1, 0, 0), 0.0), |
| 76 | + new Cesium.Plane(new Cesium.Cartesian3(0, -1, 0), 100.0), |
| 77 | + new Cesium.Plane(new Cesium.Cartesian3(0, 0, 1), 100.0) |
| 78 | +]; |
| 79 | + |
| 80 | +function loadTileset (url) { |
| 81 | + reset(); |
| 82 | + |
| 83 | + var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ |
| 84 | + url : url |
| 85 | + })); |
| 86 | + |
| 87 | + tileset.readyPromise.then(function() { |
| 88 | + var boundingSphere = tileset.boundingSphere; |
| 89 | + viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.5, -0.2, boundingSphere.radius * 4.0)); |
| 90 | + viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY); |
| 91 | + }).otherwise(function(error) { |
| 92 | + throw(error); |
| 93 | + }); |
| 94 | + |
| 95 | + tileset.clippingPlanes = defaultClippingPlanes; |
| 96 | + return tileset.clippingPlanes; |
| 97 | +} |
| 98 | + |
| 99 | +function loadModel (url) { |
| 100 | + reset(); |
| 101 | + |
| 102 | + var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 100.0); |
| 103 | + var heading = Cesium.Math.toRadians(135); |
| 104 | + var pitch = 0; |
| 105 | + var roll = 0; |
| 106 | + var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll); |
| 107 | + var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr); |
| 108 | + |
| 109 | + var entity = viewer.entities.add({ |
| 110 | + name : url, |
| 111 | + position : position, |
| 112 | + orientation : orientation, |
| 113 | + model : { |
| 114 | + uri : url, |
| 115 | + scale: 8, |
| 116 | + minimumPixelSize: 100.0 |
| 117 | + } |
| 118 | + }); |
| 119 | + |
| 120 | + viewer.trackedEntity = entity; |
| 121 | + |
| 122 | + entity.model.clippingPlanes = defaultClippingPlanes; |
| 123 | + return entity.model.clippingPlanes.getValue(); |
| 124 | +} |
| 125 | + |
| 126 | +// Power Plant design model provided by Bentley Systems |
| 127 | +var bimUrl = 'https://beta.cesium.com/api/assets/1459?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIzNjUyM2I5Yy01YmRhLTQ0MjktOGI0Zi02MDdmYzBjMmY0MjYiLCJpZCI6NDQsImFzc2V0cyI6WzE0NTldLCJpYXQiOjE0OTkyNjQ3ODF9.SW_rwY-ic0TwQBeiweXNqFyywoxnnUBtcVjeCmDGef4'; |
| 128 | +var pointCloudUrl = 'https://beta.cesium.com/api/assets/1460?access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyMzk2YzJiOS1jZGFmLTRlZmYtYmQ4MS00NTA3NjEwMzViZTkiLCJpZCI6NDQsImFzc2V0cyI6WzE0NjBdLCJpYXQiOjE0OTkyNjQ3NTV9.oWjvN52CRQ-dk3xtvD4e8ZnOHZhoWSpJLlw115mbQJM'; |
| 129 | +var modelUrl = '../../SampleData/models/CesiumAir/Cesium_Air.glb'; |
| 130 | + |
| 131 | +var clippingPlanes = loadTileset(bimUrl); |
| 132 | + |
| 133 | +// Track and create the bindings for the view model |
| 134 | + |
| 135 | +var viewModel = { |
| 136 | + exampleType : 'BIM', |
| 137 | + exampleTypes : ['BIM', 'Model', 'Point Cloud'], |
| 138 | + xOffset : 0.0, |
| 139 | + yOffset: 100.0, |
| 140 | + zOffset: 100.0 |
| 141 | +}; |
| 142 | +var toolbar = document.getElementById('toolbar'); |
| 143 | +Cesium.knockout.track(viewModel); |
| 144 | +Cesium.knockout.applyBindings(viewModel, toolbar); |
| 145 | + |
| 146 | +Cesium.knockout.getObservable(viewModel, 'xOffset').subscribe(function(newValue) { |
| 147 | + clippingPlanes[0].distance = parseFloat(newValue); |
| 148 | +}); |
| 149 | + |
| 150 | +Cesium.knockout.getObservable(viewModel, 'yOffset').subscribe(function(newValue) { |
| 151 | + clippingPlanes[1].distance = parseFloat(newValue); |
| 152 | +}); |
| 153 | + |
| 154 | +Cesium.knockout.getObservable(viewModel, 'zOffset').subscribe(function(newValue) { |
| 155 | + clippingPlanes[2].distance = parseFloat(newValue); |
| 156 | +}); |
| 157 | + |
| 158 | +Cesium.knockout.getObservable(viewModel, 'exampleType').subscribe( |
| 159 | + function(newValue) { |
| 160 | + if (newValue === 'BIM') { |
| 161 | + clippingPlanes = loadTileset(bimUrl); |
| 162 | + } else if (newValue === 'Point Cloud') { |
| 163 | + clippingPlanes = loadTileset(pointCloudUrl); |
| 164 | + } else { |
| 165 | + clippingPlanes = loadModel(modelUrl); |
| 166 | + } |
| 167 | + } |
| 168 | +); |
| 169 | + |
| 170 | +function reset () { |
| 171 | + viewer.entities.removeAll(); |
| 172 | + viewer.scene.primitives.removeAll(); |
| 173 | + |
| 174 | + if (Cesium.defined(viewModel)) { |
| 175 | + viewModel.xOffset = 0.0; |
| 176 | + viewModel.yOffset = 100.0; |
| 177 | + viewModel.zOffset = 100.0; |
| 178 | + } |
| 179 | +} |
| 180 | + |
| 181 | +//Sandcastle_End |
| 182 | +Sandcastle.finishedLoading(); |
| 183 | +} |
| 184 | +if (typeof Cesium !== "undefined") { |
| 185 | + startup(Cesium); |
| 186 | +} else if (typeof require === "function") { |
| 187 | + require(["Cesium"], startup); |
| 188 | +} |
| 189 | +</script> |
| 190 | +</body> |
| 191 | +</html> |
0 commit comments