-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
157 lines (136 loc) · 3.48 KB
/
app.js
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
var viewer,
debugAxis,
showingBoundingVolume = false;
function initCesium(){
Cesium.BingMapsApi.defaultKey = "Ag-6WHiJUeX5dm4qedvjgqzGcB-mgrZe1KtjnNz-8gwzIP_8PUu9kVZUKXhuwRsX";
var globe = new Cesium.Globe();
globe.baseColor = Cesium.Color.WHITE;
viewer = new Cesium.Viewer('cesiumContainer',{
animation: false,
scene3DOnly: true,
globe: globe,
skyBox: false,
vrButton: true,
skyAtmosphere: false,
shadows: false,
baseLayerPicker: false,
geocoder: false,
homeButton: false,
fullscreenButton: true,
infoBox: false,
sceneModePicker: false,
selectionIndicator: false,
timeline: false,
navigationHelpButton: false,
navigationInstructionsInitiallyVisible: false
});
viewer.scene.backgroundColor = Cesium.Color.WHITE;
viewer.scene.imageryLayers.removeAll();
document.body.onkeydown = function(e){
switch((e.keyCode || e.which)){
case 70:
toggleDebugAxis();
break;
case 66:
toggleBoundingVolume();
break;
case 72:
toggleHelpCredits();
break;
}
};
}
function initDropzone(){
var reader = new FileReader();
reader.addEventListener("load", function () {
showGlTF(reader.result);
}, false);
["div#cesiumContainer", "div#home .dragndrop"].forEach(function(container){
var dz = new Dropzone(container, {
url: "#",
acceptedFiles: ".gltf,.glb",
maxFilesize: 1000,
clickable: container.indexOf("dragndrop") !== -1,
maxFiles: 1,
createImageThumbnails: false,
autoProcessQueue: false,
accept: function(file, done){
document.getElementById("home").style.display = 'none';
reader.readAsDataURL(file);
}
});
});
}
function getPrimitive(){
return viewer.scene.primitives.get(0);
}
function toggleHelpCredits(){
["credits", "instructions"].forEach(function(id){
var el = document.getElementById(id);
el.style.display = el.style.display === 'block' || el.style.display === '' ? 'none' : 'block';
});
}
function toggleBoundingVolume(){
showingBoundingVolume ? hideBoundingVolume() : showBoundingVolume();
}
function showBoundingVolume(){
getPrimitive().debugShowBoundingVolume = showingBoundingVolume = true;
}
function hideBoundingVolume(){
getPrimitive().debugShowBoundingVolume = showingBoundingVolume = false;
}
function toggleDebugAxis(){
if (viewer && getPrimitive().modelMatrix){
if (debugAxis){
hideDebugAxis();
}else{
showDebugAxis();
}
}
}
function showDebugAxis(){
debugAxis = viewer.scene.primitives.add(new Cesium.DebugModelMatrixPrimitive({
modelMatrix : getPrimitive().modelMatrix
}));
}
function hideDebugAxis(){
viewer.scene.primitives.remove(debugAxis);
debugAxis = null;
}
function showGlTF(uri){
if (!viewer){
initCesium();
}
viewer.entities.removeAll();
viewer.scene.primitives.removeAll();
var entity = viewer.entities.add({
position : Cesium.Cartesian3.fromDegrees(0, 0, 100000000000),
model : {
uri : uri,
minimumPixelSize : 128,
maximumScale : 20000
}
});
viewer.trackedEntity = entity;
function checkOnLoad(entity){
setTimeout(function(){
var boundingSphere = new Cesium.BoundingSphere();
var state = viewer.dataSourceDisplay.getBoundingSphere(entity, false, boundingSphere);
if (state === Cesium.BoundingSphereState.DONE) {
// Set camera
viewer.camera.moveBackward(2);
// Show debug
if (debugAxis){
showDebugAxis();
}
if (showingBoundingVolume){
showBoundingVolume();
}
}else{
checkOnLoad(entity);
}
}, 50);
}
checkOnLoad(entity);
}
initDropzone();