1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
| const viewer = new Cesium.Viewer("cesiumContainer", { terrain: Cesium.Terrain.fromWorldTerrain(), infoBox: false, shouldAnimate: true, });
const scene = viewer.scene; const osmBuildingsTileset = await Cesium.createOsmBuildingsAsync(); scene.primitives.add(osmBuildingsTileset);
Cesium.Math.setRandomNumberSeed(2.5); function getRandomNumberInRange(minValue, maxValue) { return minValue + Cesium.Math.nextRandomNumber() * (maxValue - minValue); }
const clouds = new Cesium.CloudCollection();
function createBackLayerClouds() { clouds.add({ position: Cesium.Cartesian3.fromDegrees(-122.6908, 45.496, 300), scale: new Cesium.Cartesian2(1500, 250), maximumSize: new Cesium.Cartesian3(50, 15, 13), slice: 0.3, });
clouds.add({ position: Cesium.Cartesian3.fromDegrees(-122.72, 45.5, 335), scale: new Cesium.Cartesian2(1500, 300), maximumSize: new Cesium.Cartesian3(50, 12, 15), slice: 0.36, });
clouds.add({ position: Cesium.Cartesian3.fromDegrees(-122.72, 45.51, 260), scale: new Cesium.Cartesian2(2000, 300), maximumSize: new Cesium.Cartesian3(50, 12, 15), slice: 0.49, });
clouds.add({ position: Cesium.Cartesian3.fromDegrees(-122.705, 45.52, 250), scale: new Cesium.Cartesian2(230, 110), maximumSize: new Cesium.Cartesian3(13, 13, 13), slice: 0.2, });
clouds.add({ position: Cesium.Cartesian3.fromDegrees(-122.71, 45.522, 270), scale: new Cesium.Cartesian2(1700, 300), maximumSize: new Cesium.Cartesian3(50, 12, 15), slice: 0.6, });
clouds.add({ position: Cesium.Cartesian3.fromDegrees(-122.705, 45.525, 250), scale: new Cesium.Cartesian2(230, 110), maximumSize: new Cesium.Cartesian3(15, 13, 15), slice: 0.35, });
clouds.add({ position: Cesium.Cartesian3.fromDegrees(-122.721, 45.53, 220), scale: new Cesium.Cartesian2(1500, 500), maximumSize: new Cesium.Cartesian3(30, 20, 17), slice: 0.45, }); }
let long, lat, height, scaleX, scaleY, aspectRatio, cloudHeight, depth, slice;
function createRandomClouds( numClouds, startLong, stopLong, startLat, stopLat, minHeight, maxHeight, ) { const rangeLong = stopLong - startLong; const rangeLat = stopLat - startLat; for (let i = 0; i < numClouds; i++) { long = startLong + getRandomNumberInRange(0, rangeLong); lat = startLat + getRandomNumberInRange(0, rangeLat); height = getRandomNumberInRange(minHeight, maxHeight); scaleX = getRandomNumberInRange(150, 350); scaleY = scaleX / 2.0 - getRandomNumberInRange(0, scaleX / 4.0); slice = getRandomNumberInRange(0.3, 0.7); depth = getRandomNumberInRange(5, 20); aspectRatio = getRandomNumberInRange(1.5, 2.1); cloudHeight = getRandomNumberInRange(5, 20); clouds.add({ position: Cesium.Cartesian3.fromDegrees(long, lat, height), scale: new Cesium.Cartesian2(scaleX, scaleY), maximumSize: new Cesium.Cartesian3( aspectRatio * cloudHeight, cloudHeight, depth, ), slice: slice, }); } }
const scratch = new Cesium.Cartesian3(); function createFrontLayerClouds() { clouds.add({ position: Cesium.Cartesian3.fromDegrees(-122.666, 45.5126, 97), scale: new Cesium.Cartesian2(400, 150), maximumSize: new Cesium.Cartesian3(25, 12, 15), slice: 0.36, });
clouds.add({ position: Cesium.Cartesian3.fromDegrees(-122.6665, 45.5262, 76), scale: new Cesium.Cartesian2(450, 200), maximumSize: new Cesium.Cartesian3(25, 14, 12), slice: 0.3, }); }
createBackLayerClouds(); createRandomClouds(8, -122.685, -122.67, 45.51, 45.525, 50, 250); createFrontLayerClouds();
scene.primitives.add(clouds);
const start = Cesium.JulianDate.fromDate(new Date(2021, 7, 21, 12)); const stop = Cesium.JulianDate.addSeconds(start, 90, new Cesium.JulianDate());
function computeBalloonFlight(long, lat, height0, height1) { const property = new Cesium.SampledPositionProperty(); const time0 = start.clone(); const time1 = Cesium.JulianDate.addSeconds(time0, 30, new Cesium.JulianDate()); const time2 = Cesium.JulianDate.addSeconds(time1, 15, new Cesium.JulianDate()); const time3 = Cesium.JulianDate.addSeconds(time2, 30, new Cesium.JulianDate()); const time4 = Cesium.JulianDate.addSeconds(time3, 15, new Cesium.JulianDate());
const position0 = Cesium.Cartesian3.fromDegrees(long, lat, height0); const position1 = Cesium.Cartesian3.fromDegrees(long, lat, height1);
property.addSample(time0, position0); property.addSample(time1, position1); property.addSample(time2, position1); property.addSample(time3, position0); property.addSample(time4, position0);
return property; }
const balloon0 = viewer.entities.add({ position: computeBalloonFlight(-122.661, 45.524, 400, 500), model: { uri: "../SampleData/models/CesiumBalloon/CesiumBalloon.glb", mininumPixelSize: 128, maximumScale: 20000, }, });
balloon0.position.setInterpolationOptions({ interpolationDegree: 2, interpolationAlgorithm: Cesium.HermitePolynomialApproximation, });
const balloon1 = viewer.entities.add({ position: computeBalloonFlight(-122.662, 45.517, 400, 300), model: { uri: "../SampleData/models/CesiumBalloon/CesiumBalloon.glb", mininumPixelSize: 128, maximumScale: 20000, }, });
balloon1.position.setInterpolationOptions({ interpolationDegree: 2, interpolationAlgorithm: Cesium.HermitePolynomialApproximation, });
viewer.clock.startTime = start.clone(); viewer.clock.stopTime = stop.clone(); viewer.clock.currentTime = start.clone(); viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP; viewer.clock.multiplier = 1.0;
scene.camera.flyTo({ destination: Cesium.Cartesian3.fromDegrees(-122.6515, 45.5252, 525), orientation: { heading: Cesium.Math.toRadians(-115), pitch: Cesium.Math.toRadians(-12), roll: 0.0, }, duration: 0, });
scene.fog.density = 1.15e-4;
|