-
Notifications
You must be signed in to change notification settings - Fork 360
/
index.html
271 lines (238 loc) · 10.5 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>xeokit BIM Viewer</title>
<link rel="stylesheet" href="./lib/fontawesome-free-5.11.2-web/css/all.min.css" type="text/css" />
<link rel="stylesheet" href="../dist/xeokit-bim-viewer.css" type="text/css" />
<link rel="stylesheet" href="./css/style.css" />
</head>
<body>
<input type="checkbox" id="explorer_toggle" />
<label for="explorer_toggle" class="xeokit-i18n explorer_toggle_label xeokit-btn fas fa-2x fa-sitemap"
data-xeokit-i18ntip="toolbar.toggleExplorer" data-tippy-content="Toggle explorer"></label>
<input type="checkbox" id="inspector_toggle" />
<label id="inspector_toggle_label" for="inspector_toggle"
class="xeokit-i18n inspector_toggle_label xeokit-btn fas fa-info-circle fa-2x"
data-xeokit-i18ntip="toolbar.toggleProperties" data-tippy-content="Toggle properties"></label>
<div id="myExplorer"></div>
<div id="myToolbar"></div>
<div id="myInspector"></div>
<div id="myViewer">
<canvas id="myCanvas"></canvas>
<canvas id="myNavCubeCanvas"></canvas>
</div>
</body>
<!-- Tooltips libraries -->
<script src="./lib/popper.js"></script>
<script src="./lib/tippy.js"></script>
<script type="module">
import { Server, BIMViewer, LocaleService } from "../dist/xeokit-bim-viewer.es.js";
import { messages as localeMessages } from "../dist/messages.js";
window.onload = function () {
const requestParams = getRequestParams();
const locale = requestParams.locale || "en";
const projectId = requestParams.projectId;
if (!projectId) {
return;
}
const openExplorer = requestParams.openExplorer;
setExplorerOpen(openExplorer === "true");
const enableEditModels = (requestParams.enableEditModels === "true");
const server = new Server({
dataDir: requestParams.dataDir || "./data"
});
const bimViewer = new BIMViewer(server, {
localeService: new LocaleService({
messages: localeMessages,
locale: locale
}),
enableMeasurements: true,
canvasElement: document.getElementById("myCanvas"), // WebGL canvas
keyboardEventsElement: document, // Optional, defaults to document
explorerElement: document.getElementById("myExplorer"), // Left panel
toolbarElement: document.getElementById("myToolbar"), // Toolbar
inspectorElement: document.getElementById("myInspector"), // Right panel
navCubeCanvasElement: document.getElementById("myNavCubeCanvas"),
busyModelBackdropElement: document.getElementById("myViewer"),
enableEditModels: enableEditModels
});
bimViewer.localeService.on("updated", () => {
const localizedElements = document.querySelectorAll('.xeokit-i18n');
localizedElements.forEach((localizedElement) => {
if (localizedElement.dataset.xeokitI18n) {
localizedElement.innerText = bimViewer.localeService.translate(localizedElement.dataset.xeokitI18n);
}
if (localizedElement.dataset.xeokitI18ntip) {
const translation = bimViewer.localeService.translate(localizedElement.dataset.xeokitI18ntip);
if (translation) {
localizedElement.dataset.tippyContent = bimViewer.localeService.translate(localizedElement.dataset.xeokitI18ntip);
}
}
if (localizedElement.dataset.tippyContent) {
if (localizedElement._tippy) {
localizedElement._tippy.setContent(localizedElement.dataset.tippyContent);
} else {
tippy(localizedElement, {
appendTo: "parent",
zIndex: 1000000,
allowHTML: true
});
}
}
});
});
bimViewer.setConfigs({
"showSpaces": false, // Default
"selectedGlowThrough": true,
"highlightGlowThrough": true,
"dtxEnabled": true // Enable data texture scene representation for models - may be slow on low-spec GPUs
});
bimViewer.on("openExplorer", () => {
setExplorerOpen(true);
});
bimViewer.on("openInspector", () => {
setInspectorOpen(true);
});
bimViewer.on("addModel", (event) => { // "Add" selected in Models tab's context menu
console.log("addModel: " + JSON.stringify(event, null, "\t"));
});
bimViewer.on("editModel", (event) => { // "Edit" selected in Models tab's context menu
console.log("editModel: " + JSON.stringify(event, null, "\t"));
});
bimViewer.on("deleteModel", (event) => { // "Delete" selected in Models tab's context menu
console.log("deleteModel: " + JSON.stringify(event, null, "\t"));
});
const viewerConfigs = requestParams.configs;
if (viewerConfigs) {
const configNameVals = viewerConfigs.split(",");
for (let i = 0, len = configNameVals.length; i < len; i++) {
const configNameValStr = configNameVals[i];
const configNameVal = configNameValStr.split(":");
const configName = configNameVal[0];
const configVal = configNameVal[1];
bimViewer.setConfig(configName, configVal);
}
}
bimViewer.loadProject(projectId, () => {
const modelId = requestParams.modelId;
if (modelId) {
bimViewer.loadModel(modelId);
}
const tab = requestParams.tab;
if (tab) {
bimViewer.openTab(tab);
}
watchHashParams();
},
(errorMsg) => {
console.error(errorMsg);
});
function watchHashParams() {
let lastHash = "";
window.setInterval(() => {
const currentHash = window.location.hash;
if (currentHash !== lastHash) {
parseHashParams();
lastHash = currentHash;
}
}, 400);
}
function parseHashParams() {
const params = getHashParams();
const actionsStr = params.actions;
if (!actionsStr) {
return;
}
const actions = actionsStr.split(",");
if (actions.length === 0) {
return;
}
for (let i = 0, len = actions.length; i < len; i++) {
const action = actions[i];
switch (action) {
case "focusObject":
const objectId = params.objectId;
if (!objectId) {
console.error("Param expected for `focusObject` action: 'objectId'");
break;
}
bimViewer.setAllObjectsSelected(false);
bimViewer.setObjectsSelected([objectId], true);
bimViewer.flyToObject(objectId, () => {
// FIXME: Showing objects in tabs involves scrolling the HTML within the tabs - disable until we know how to scroll the correct DOM element. Otherwise, that function works OK
// bimViewer.showObjectInObjectsTab(objectId);
// bimViewer.showObjectInClassesTab(objectId);
// bimViewer.showObjectInStoreysTab(objectId);
});
break;
case "focusObjects":
const objectIds = params.objectIds;
if (!objectIds) {
console.error("Param expected for `focusObjects` action: 'objectIds'");
break;
}
const objectIdArray = objectIds.split(",");
bimViewer.setAllObjectsSelected(false);
bimViewer.setObjectsSelected(objectIdArray, true);
bimViewer.viewFitObjects(objectIdArray, () => {
});
break;
case "clearFocusObjects":
bimViewer.setAllObjectsSelected(false);
bimViewer.viewFitAll();
// TODO: view fit nothing?
break;
case "openTab":
const tabId = params.tabId;
if (!tabId) {
console.error("Param expected for `openTab` action: 'tabId'");
break;
}
bimViewer.openTab(tabId);
break;
default:
console.error("Action not supported: '" + action + "'");
break;
}
}
}
function setExplorerOpen(explorerOpen) {
const toggle = document.getElementById("explorer_toggle");
if (toggle) {
toggle.checked = explorerOpen;
}
}
function setInspectorOpen(inspectorOpen) {
const toggle = document.getElementById("inspector_toggle");
if (toggle) {
toggle.checked = inspectorOpen;
}
}
function getRequestParams() {
const vars = {};
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, (m, key, value) => {
vars[key] = value;
});
return vars;
}
function getHashParams() {
const hashParams = {};
let e;
const a = /\+/g; // Regex for replacing addition symbol with a space
const r = /([^&;=]+)=?([^&;]*)/g;
const d = function (s) {
return decodeURIComponent(s.replace(a, " "));
};
const q = window.location.hash.substring(1);
while (e = r.exec(q)) {
hashParams[d(e[1])] = d(e[2]);
}
return hashParams;
}
window.bimViewer = bimViewer;
}
</script>
</html>