-
Notifications
You must be signed in to change notification settings - Fork 0
/
cesium-project_fin.html
376 lines (314 loc) · 18.4 KB
/
cesium-project_fin.html
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/******
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright ©Cesium
https://github.com/CesiumGS
https://cesium.com/
https://cesium.com/platform/cesiumjs/
******/
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cesium.com/downloads/cesiumjs/releases/1.100/Build/Cesium/Cesium.js"></script>
<link
href="https://cesium.com/downloads/cesiumjs/releases/1.100/Build/Cesium/Widgets/widgets.css"
rel="stylesheet"
/>
</head>
<body>
<div id="cesiumContainer"></div>
<script>
Cesium.Ion.defaultAccessToken = "";
const viewer = new Cesium.Viewer("cesiumContainer", {terrainProvider: Cesium.createWorldTerrain(), });
/*****OFF-LINE*****
1.
Cesium.Ion.defaultAccessToken = null;
const viewer = new Cesium.Viewer("cesiumContainer", {
imageryProvider: false,
baseLayerPicker: false,
geocoder: false, });
viewer.imageryLayers.addImageryProvider(new Cesium.TileMapServiceImageryProvider({
url: Cesium.buildModuleUrl("Assets/Textures/NaturalEarthII"),})); //>> 저화질
viewer.imageryLayers.addImageryProvider(new Cesium.WebMapServiceImageryProvider({
url: 'url', layers: 'cartographie:worldMix', ...})); //>> 고화질 (WMS, 웹 사이트 ...)
정상적으로 요청은 되지만 화면에 뜨지 않는 상태 => CORS
2. webpack
3D files can be placed under the same location where the required static Cesium files are, just make a separate directory for 3d files and reference the files with something like that:
You may need to adjust the path a bit, I am using react in my case and that is the path I am using to access the 3d asset from the React component with the Cesium viewer element, i.e. assets are under public/static/3d-models
model: {uri: “…/static/3d-models/GroundVehicle.glb”},
https://community.cesium.com/t/3d-models-failed-to-external-gltf-file/1990
https://community.cesium.com/t/i-cant-import-my-gltf-3dmodel/2293/3
https://community.cesium.com/t/using-cesiumjs-on-a-closed-network/19697/5
https://github.com/CesiumGS/cesium/tree/main/Documentation/OfflineGuide
*******************/
//quaternionData : ECI to bodyframe
const quaternionData = JSON.parse();
//positionData : positon (ECI)
const positionData = JSON.parse();
//antenna Data : Antenna pointing (azimuth, elevation)
const AntennaData = JSON.parse();
//modeData : for TEXT
const modeData = JSON.parse();
const coneLengthArr = [];
const eciposition = [];
const AntennaElements = [];
const modeNames = []; //for Callback func
const timeStepInSeconds = 30;
const totalSeconds = timeStepInSeconds * (positionData.length);
const start = Cesium.JulianDate.fromIso8601("2022-09-26T22:37:24Z");
const stop = Cesium.JulianDate.addSeconds(start, totalSeconds, new Cesium.JulianDate());
viewer.clock.startTime = start.clone();
viewer.clock.stopTime = stop.clone();
viewer.clock.currentTime = start.clone();
viewer.timeline.zoomTo(start, stop);
viewer.clock.multiplier = 120;
viewer.clock.shouldAnimate = true;
viewer.scene.globe.enableLighting = true;
viewer.scene.globe.depthTestAgainstTerrain = false;
const timeInterval = new Cesium.TimeInterval({start: start, stop: stop, });
const bodyframePropertyX = new Cesium.SampledPositionProperty(1, 0);
const bodyframePropertyY = new Cesium.SampledPositionProperty(1, 0);
const bodyframePropertyZ = new Cesium.SampledPositionProperty(1, 0);
const AntennaframeZ = new Cesium.SampledPositionProperty(1, 0); //pointing axis
const sunpositionProperty = new Cesium.SampledPositionProperty(1, 0);
const positionProperty = new Cesium.SampledPositionProperty(1, 0);
const attitudeProperty = new Cesium.SampledProperty(Cesium.Quaternion);
const conemidpositionProperty = new Cesium.SampledPositionProperty(1, 0);
const conelengthProperty = new Cesium.SampledProperty(Number);
const modetextProperty = new Cesium.SampledProperty(String);
const AntennapositionProperty = new Cesium.SampledPositionProperty(1, 0);
const AntennaattitudeProperty = new Cesium.SampledProperty(Cesium.Quaternion);
const origin = Cesium.Cartesian3.ZERO;
const EnuToEcefMatrix4 = Cesium.Transforms.eastNorthUpToFixedFrame(origin);
const EnuToEcefMatrix3 = Cesium.Matrix4.getRotation(EnuToEcefMatrix4, new Cesium.Matrix3());
const EnuToEcefQuaternion = Cesium.Quaternion.fromRotationMatrix(EnuToEcefMatrix3);
Cesium.Quaternion.normalize(EnuToEcefQuaternion, EnuToEcefQuaternion);
const EcefToEnuQuaternion = Cesium.Quaternion.conjugate(EnuToEcefQuaternion, new Cesium.Quaternion());
const unitX = Cesium.Cartesian3.UNIT_X;
const unitY = Cesium.Cartesian3.UNIT_Y;
const unitZ = Cesium.Cartesian3.UNIT_Z;
function makeQuaternion(mntheadingval, mntpitchval, mntrollval, azimuth, elevation, SatelliteQuaternion) {
const MntHeading = Cesium.Math.toRadians(mntheadingval);
const MntPitch = Cesium.Math.toRadians(mntpitchval);
const MntRoll = Cesium.Math.toRadians(mntrollval);
const MntHeadingPitchRoll = new Cesium.HeadingPitchRoll(-MntHeading, -MntPitch, MntRoll);
const AntennaHeading = Cesium.Math.toRadians(azimuth + PI/2);
const AntennaPitch = Cesium.Math.toRadians(elevation);
const AntennaRoll = Cesium.Math.toRadians(0);
const AntennaHeadingPitchRoll = new Cesium.HeadingPitchRoll(-AntennaHeading, AntennaPitch, AntennaRoll);
const EcefToMntQuaternion = Cesium.Transforms.headingPitchRollQuaternion(origin, MntHeadingPitchRoll);
const BodyToMntQuaternion = Cesium.Quaternion.multiply(EcefToEnuQuaternion, EcefToMntQuaternion, new Cesium.Quaternion());
const EcefToAntennaQuaternion = Cesium.Transforms.headingPitchRollQuaternion(origin, AntennaHeadingPitchRoll);
const MntToAntennaQuaternion = Cesium.Quaternion.multiply(EcefToEnuQuaternion, EcefToAntennaQuaternion, new Cesium.Quaternion());
const EciToMntQuaternion = Cesium.Quaternion.multiply(SatelliteQuaternion, BodyToMntQuaternion, new Cesium.Quaternion());
const EciToAntennaQuaternion = Cesium.Quaternion.multiply(EciToMntQuaternion, MntToAntennaQuaternion, new Cesium.Quaternion());
return EciToAntennaQuaternion;
}
function makePointingAxis(EciToAntennaQuaternion, unitZ, conelength, eciposition) {
const EciToAntennaMatrix = Cesium.Matrix3.fromQuaternion(EciToAntennaQuaternion, new Cesium.Matrix3());
const AntennaframeUnitZ = Cesium.Matrix3.multiplyByVector(EciToAntennaMatrix, unitZ, new Cesium.Cartesian3());
const AntennaframeNtiemsZ = Cesium.Cartesian3.multiplyByScalar(AntennaframeUnitZ, conelength/2, new Cesium.Cartesian3());
const AntennaframeZ = Cesium.Cartesian3.add(eciposition, AntennaframeNtiemsZ, new Cesium.Cartesian3());
return AntennaframeZ;
}
for (let i = 0; i < positionData.length; i++) {
const positionElements = positionData[i];
const quaternionElements = quaternionData[i];
modeNames.push(modeData[i]);
AntennaElements.push(AntennaData[i]);
const time = Cesium.JulianDate.addSeconds(start, i * timeStepInSeconds, new Cesium.JulianDate());
const SatelliteQuaternion = new Cesium.Quaternion(quaternionElements.q1, quaternionElements.q2, quaternionElements.q3, quaternionElements.q4);
const positionKm = Cesium.Cartesian3.fromElements(positionElements.x, positionElements.y, positionElements.z);
const positionMeter = Cesium.Cartesian3.multiplyByScalar(positionKm, 1000, new Cesium.Cartesian3());
eciposition.push(positionMeter);
positionProperty.addSample(time, positionMeter);
const coneLength = Cesium.Cartesian3.magnitude(positionMeter);
coneLengthArr.push(coneLength);
conelengthProperty.addSample(time, coneLength);
const sunposition = Cesium.Simon1994PlanetaryPositions.computeSunPositionInEarthInertialFrame(time);
sunpositionProperty.addSample(time, sunposition);
const EcefToBody = new Cesium.Quaternion();
const waiting = Cesium.Transforms.preloadIcrfFixed(timeInterval);
waiting.then(function() {
const EciToEcefMatrix = Cesium.Transforms.computeIcrfToFixedMatrix(time);
if (Cesium.defined(EciToEcefMatrix)) {
const EciToEcef = Cesium.Quaternion.fromRotationMatrix(EciToEcefMatrix);
Cesium.Quaternion.multiply(EciToEcef, SatelliteQuaternion, EcefToBody);
attitudeProperty.addSample(time, EcefToBody);
if ("Antenna1" === AntennaElements[i].id) {
const EciToAntennaQuaternion = makeQuaternion(80, 10, 0, AntennaElements[i].az, AntennaElements[i].el, SatelliteQuaternion); //eci to Antenna
const EcefToAntennaQuaternion = Cesium.Quaternion.multiply(EciToEcef, EciToAntennaQuaternion, new Cesium.Quaternion());
AntennaattitudeProperty.addSample(time, EcefToAntennaQuaternion);
const PointingAxis = makePointingAxis(EciToAntennaQuaternion, unitZ, coneLengthArr[i], eciposition[i]);
conemidpositionProperty.addSample(time, PointingAxis);
AntennaframeZ.addSample(time, PointingAxis);
}
else if ("Antenna2" === AntennaElements[i].id) {
const EciToAntennaQuaternion = makeQuaternion(-80, 10, 0, AntennaElements[i].az, AntennaElements[i].el, SatelliteQuaternion); //eci to Antenna
const EcefToAntennaQuaternion = Cesium.Quaternion.multiply(EciToEcef, EciToAntennaQuaternion, new Cesium.Quaternion());
AntennaattitudeProperty.addSample(time, EcefToAntennaQuaternion);
const PointingAxis = makePointingAxis(EciToAntennaQuaternion, unitZ, coneLengthArr[i], eciposition[i]);
conemidpositionProperty.addSample(time, PointingAxis);
AntennaframeZ.addSample(time, PointingAxis);
}
}
});
const EciToBodyMatrix = Cesium.Matrix3.fromQuaternion(SatelliteQuaternion);
const BodyframeUnitX = Cesium.Matrix3.multiplyByVector(EciToBodyMatrix, unitX, new Cesium.Cartesian3());
const BodyframeUnitY = Cesium.Matrix3.multiplyByVector(EciToBodyMatrix, unitY, new Cesium.Cartesian3());
const BodyframeUnitZ = Cesium.Matrix3.multiplyByVector(EciToBodyMatrix, unitZ, new Cesium.Cartesian3());
const BodyframeNtimesX = Cesium.Cartesian3.multiplyByScalar(BodyframeUnitX, 10e5, new Cesium.Cartesian3());
const BodyframeNtimesY = Cesium.Cartesian3.multiplyByScalar(BodyframeUnitY, 10e5, new Cesium.Cartesian3());
const BodyframeNtimesZ = Cesium.Cartesian3.multiplyByScalar(BodyframeUnitZ, 10e5, new Cesium.Cartesian3());
const BodyframeX = Cesium.Cartesian3.add(positionMeter, BodyframeNtimesX, new Cesium.Cartesian3());
const BodyframeY = Cesium.Cartesian3.add(positionMeter, BodyframeNtimesY, new Cesium.Cartesian3());
const BodyframeZ = Cesium.Cartesian3.add(positionMeter, BodyframeNtimesZ, new Cesium.Cartesian3());
bodyframePropertyX.addSample(time, BodyframeX);
bodyframePropertyY.addSample(time, BodyframeY);
bodyframePropertyZ.addSample(time, BodyframeZ);
}
//satellite
async function loadModel() {
const SatelliteUri = await Cesium.IonResource.fromAssetId(); //satellite model
const SatelliteEntity = viewer.entities.add({
availability: new Cesium.TimeIntervalCollection([timeInterval]),
position: positionProperty,
orientation: attitudeProperty,
model: {
uri: SatelliteUri,
minimumPixelSize: 200.0
},
path: new Cesium.PathGraphics({
width: 2,
leadTime: 0,
trailTime: 2 * 60 * 60,
}),
viewFrom: positionProperty, //zoom out
});
viewer.trackedEntity = SatelliteEntity;
}
//Antenna cone
viewer.entities.add({
position: conemidpositionProperty,
orientation: AntennaattitudeProperty,
cylinder: {
length: conelengthProperty,
topRadius: 1000000.0,
bottomRadius: 0.0,
material: Cesium.Color.DARKORANGE.withAlpha(0.5),
},
});
//sun vector
viewer.entities.add({
polyline: {
positions: new Cesium.CallbackProperty(function (time, result) {
return [
positionProperty.getValue(viewer.clock.currentTime),
sunpositionProperty.getValue(viewer.clock.currentTime),
];
}),
width: 1,
arcType: Cesium.ArcType.NONE,
material: Cesium.Color.RED,
},
});
//center of earth vector
viewer.entities.add({
polyline: {
positions: new Cesium.CallbackProperty(function (time, result) {
return [
positionProperty.getValue(viewer.clock.currentTime),
Cesium.Cartesian3.fromElements(0, 0, 0),
];
}),
width: 1,
arcType: Cesium.ArcType.NONE,
material: Cesium.Color.GREEN,
},
});
//satellite bodyframe x
viewer.entities.add({
polyline: {
positions: new Cesium.CallbackProperty(function (time, result) {
return [
positionProperty.getValue(viewer.clock.currentTime),
bodyframePropertyX.getValue(viewer.clock.currentTime),
];
}),
width: 3,
arcType: Cesium.ArcType.NONE,
material: Cesium.Color.AQUA,
},
});
//satellite bodyframe y
viewer.entities.add({
polyline: {
positions: new Cesium.CallbackProperty(function (time, result) {
return [
positionProperty.getValue(viewer.clock.currentTime),
bodyframePropertyY.getValue(viewer.clock.currentTime),
];
}),
width: 3,
arcType: Cesium.ArcType.NONE,
material: Cesium.Color.GOLD,
},
});
//satellite bodyframe z
viewer.entities.add({
polyline: {
positions: new Cesium.CallbackProperty(function (time, result) {
return [
positionProperty.getValue(viewer.clock.currentTime),
bodyframePropertyZ.getValue(viewer.clock.currentTime),
];
}),
width: 3,
arcType: Cesium.ArcType.NONE,
material: Cesium.Color.LIME,
},
});
//pointing vector
viewer.entities.add({
polyline: {
positions: new Cesium.CallbackProperty(function (time, result) {
return [
positionProperty.getValue(viewer.clock.currentTime),
AntennaframeZ.getValue(viewer.clock.currentTime),
];
}),
width: 6,
arcType: Cesium.ArcType.NONE,
material: Cesium.Color.YELLOW,
},
});
//location
viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(126, 37),
label: {
text: "seoul",
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
horizontalOrigin: Cesium.HorizontalOrigin.RIGHT,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
},
});
//dynamic text -> callback : using time
viewer.entities.add({
position: positionProperty,
label: {
text: new Cesium.CallbackProperty(function() {
const modeText = modeNames[parseInt(((viewer.clock.currentTime.dayNumber * 86400 + viewer.clock.currentTime.secondsOfDay) - (viewer.clock.startTime.dayNumber * 86400 + viewer.clock.startTime.secondsOfDay)) / timeStepInSeconds)];
if (modeText.PLTmode === ""){
return modeText.Mode_A;
}
else {
return modeText.Mode_B;
}}, false),
pixelOffset: new Cesium.Cartesian2(100, -100),
},
});
loadModel();
</script>
</body>
</html>