-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.ts
77 lines (59 loc) · 2.2 KB
/
demo.ts
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
import {ifcToGLTF} from './src/index.js';
import * as Cesium from '@cesium/engine';
import "@cesium/engine/Source/Widget/CesiumWidget.css";
window.CESIUM_BASE_URL = '/';
const {glb, coordinationMatrix, metadata} = await ifcToGLTF({
element: document.getElementById('threeJSContainer')!,
url: "https://thatopen.github.io/engine_components/resources/small.ifc",
})
console.log('Got GLTF for ', metadata, 'at', coordinationMatrix);
function download(file: File) {
const link = document.createElement("a");
link.href = URL.createObjectURL(file);
link.download = file.name;
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href);
link.remove();
}
const blob = new Blob([glb]);
// const exportedFile = new File([blob], "example.glb");
// download(exportedFile);
const modelOrigin = [6.137499506, 46.192506022, 425.999];
const modelOrientation = [90, 0, 0]
// Your access token can be found at: https://ion.cesium.com/tokens.
// Replace `your_access_token` with your Cesium ion access token.
// Initialize the Cesium Viewer in the HTML element with the `cesiumContainer` ID.
const viewer = new Cesium.CesiumWidget('cesiumContainer', {
terrain: Cesium.Terrain.fromWorldTerrain(),
});
viewer.camera.flyTo({
destination: Cesium.Cartesian3.fromDegrees(...modelOrigin),
duration: 0,
orientation: {
heading: Cesium.Math.toRadians(0.0),
pitch: Cesium.Math.toRadians(-15.0),
}
});
const fixedFrameTransform = Cesium.Transforms.localFrameToFixedFrameGenerator(
"north",
"west"
);
const modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(
Cesium.Cartesian3.fromDegrees(6.137499506, 46.192506022, 925.999),
new Cesium.HeadingPitchRoll(...modelOrientation.map(Cesium.Math.toRadians)),
Cesium.Ellipsoid.WGS84,
fixedFrameTransform
);
const blobURL = URL.createObjectURL(blob); // FIXME: when is this released?
console.log(blobURL)
const csModel = await Cesium.Model.fromGltfAsync({
modelMatrix: modelMatrix,
scene: viewer.scene,
url: blobURL,
silhouetteColor: Cesium.Color.WHITE.withAlpha(0.5),
silhouetteSize: 2.0,
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
});
URL.revokeObjectURL(blobURL);
viewer.scene.primitives.add(csModel);