|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| 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="Explore node transformations of 3D models."> |
| 8 | + <meta name="cesium-sandcastle-labels" content="Development"> |
| 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 | + if(typeof require === 'function') { |
| 14 | + require.config({ |
| 15 | + baseUrl : '../../../Source', |
| 16 | + waitSeconds : 120 |
| 17 | + }); |
| 18 | + } |
| 19 | + </script> |
| 20 | +</head> |
| 21 | +<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html"> |
| 22 | +<style> |
| 23 | + @import url(../templates/bucket.css); |
| 24 | + #toolbar { |
| 25 | + background: rgba(42, 42, 42, 0.8); |
| 26 | + padding: 4px; |
| 27 | + border-radius: 4px; |
| 28 | + } |
| 29 | + #toolbar input { |
| 30 | + vertical-align: middle; |
| 31 | + padding-top: 2px; |
| 32 | + padding-bottom: 2px; |
| 33 | + } |
| 34 | +</style> |
| 35 | +<div id="cesiumContainer" class="fullSize"></div> |
| 36 | +<div id="loadingOverlay"><h1>Loading...</h1></div> |
| 37 | +<div id="toolbar"> |
| 38 | + <div>Articulation: |
| 39 | + <select class="cesium-button" data-bind="options: articulations, |
| 40 | + optionsText: 'name', |
| 41 | + value: selectedArticulation"></select> |
| 42 | + </div> |
| 43 | + <table> |
| 44 | + <tbody data-bind="foreach: stages"> |
| 45 | + <tr> |
| 46 | + <td data-bind="text: name"></td> |
| 47 | + <td> |
| 48 | + <input type="range" min="-3" max="3" step="0.01" data-bind="value: current, |
| 49 | + valueUpdate: 'input', |
| 50 | + attr: { |
| 51 | + min: minimum, |
| 52 | + max: maximum |
| 53 | + }"> |
| 54 | + <input type="text" size="2" data-bind="value: currentText"> |
| 55 | + </td> |
| 56 | + </tr> |
| 57 | + </tbody> |
| 58 | + </table> |
| 59 | +</div> |
| 60 | +<script id="cesium_sandcastle_script"> |
| 61 | +function startup(Cesium) { |
| 62 | + 'use strict'; |
| 63 | +//Sandcastle_Begin |
| 64 | +// this can be changed to any glTF model |
| 65 | +var modelUrl = 'https://assets.agi.com/models/launchvehicle.glb'; |
| 66 | + |
| 67 | +var viewModel = { |
| 68 | + articulations: [], |
| 69 | + stages: [], |
| 70 | + selectedArticulation: undefined |
| 71 | +}; |
| 72 | + |
| 73 | +Cesium.knockout.track(viewModel); |
| 74 | + |
| 75 | +Cesium.knockout.getObservable(viewModel, 'selectedArticulation').subscribe(function(newArticulation) { |
| 76 | + viewModel.stages = newArticulation.stages; |
| 77 | +}); |
| 78 | + |
| 79 | +var toolbar = document.getElementById('toolbar'); |
| 80 | +Cesium.knockout.applyBindings(viewModel, toolbar); |
| 81 | + |
| 82 | +var viewer = new Cesium.Viewer('cesiumContainer'); |
| 83 | +var scene = viewer.scene; |
| 84 | + |
| 85 | +var height = 220000.0; |
| 86 | +var origin = Cesium.Cartesian3.fromDegrees(-74.693, 28.243, height); |
| 87 | +var modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(origin, new Cesium.HeadingPitchRoll()); |
| 88 | + |
| 89 | +var model = scene.primitives.add(Cesium.Model.fromGltf({ |
| 90 | + url : modelUrl, |
| 91 | + modelMatrix : modelMatrix, |
| 92 | + minimumPixelSize : 128 |
| 93 | +})); |
| 94 | + |
| 95 | +model.readyPromise.then(function(model) { |
| 96 | + var camera = viewer.camera; |
| 97 | + |
| 98 | + // Zoom to model |
| 99 | + var controller = scene.screenSpaceCameraController; |
| 100 | + var r = 2.0 * Math.max(model.boundingSphere.radius, camera.frustum.near); |
| 101 | + controller.minimumZoomDistance = r * 0.2; |
| 102 | + |
| 103 | + var center = Cesium.Matrix4.multiplyByPoint(model.modelMatrix, Cesium.Cartesian3.ZERO, new Cesium.Cartesian3()); |
| 104 | + var heading = Cesium.Math.toRadians(0.0); |
| 105 | + var pitch = Cesium.Math.toRadians(-10.0); |
| 106 | + camera.lookAt(center, new Cesium.HeadingPitchRange(heading, pitch, r * 0.8)); |
| 107 | + |
| 108 | + viewModel.articulations = Object.keys(model._runtime.articulationsByName).map(function(articulationName) { |
| 109 | + return { |
| 110 | + name: articulationName, |
| 111 | + stages: model._runtime.articulationsByName[articulationName].stages.map(function(stage) { |
| 112 | + var stageModel = { |
| 113 | + name: stage.name, |
| 114 | + minimum: stage.minimumValue, |
| 115 | + maximum: stage.maximumValue, |
| 116 | + current: stage.currentValue |
| 117 | + }; |
| 118 | + Cesium.knockout.track(stageModel); |
| 119 | + Cesium.knockout.defineProperty(stageModel, 'currentText', { |
| 120 | + get: function() { |
| 121 | + return stageModel.current.toString(); |
| 122 | + }, |
| 123 | + set: function(value) { |
| 124 | + // coerce values to number |
| 125 | + stageModel.current = +value; |
| 126 | + } |
| 127 | + }); |
| 128 | + Cesium.knockout.getObservable(stageModel, 'current').subscribe(function(newValue) { |
| 129 | + model.setArticulationStage(articulationName + ' ' + stage.name, +stageModel.current); |
| 130 | + model.applyArticulations(); |
| 131 | + }); |
| 132 | + return stageModel; |
| 133 | + }) |
| 134 | + }; |
| 135 | + }); |
| 136 | + viewModel.selectedArticulation = viewModel.articulations[0]; |
| 137 | + |
| 138 | +}).otherwise(function(error){ |
| 139 | + console.error(error); |
| 140 | +}); |
| 141 | + |
| 142 | +//Sandcastle_End |
| 143 | + Sandcastle.finishedLoading(); |
| 144 | +} |
| 145 | +if (typeof Cesium !== 'undefined') { |
| 146 | + startup(Cesium); |
| 147 | +} else if (typeof require === 'function') { |
| 148 | + require(['Cesium'], startup); |
| 149 | +} |
| 150 | +</script> |
| 151 | +</body> |
| 152 | +</html> |
0 commit comments