-
Notifications
You must be signed in to change notification settings - Fork 0
/
loading_VRML_Eplan.html
254 lines (203 loc) · 8.33 KB
/
loading_VRML_Eplan.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Minimal BIM Viewer for glTF Models</title>
<link href="css/styles.css" type="text/css" rel="stylesheet"/>
<style>
#treePanel {
padding-top: 25px;
pointer-events: all;
height: 100%;
overflow-y: scroll;
position: absolute;
background-color: rgba(255, 255, 255, 0.86);
color: black;
top: 0;
z-index: 200000;
float: left;
left: 0;
font-family: 'Roboto', sans-serif;
font-size: 15px;
user-select: none;
-ms-user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
width: 350px;
}
#myCanvas {
background: #ffffff;
}
</style>
<link href="./libs/inspire-tree/site-min.css" type="text/css" rel="stylesheet"/>
<script src="./libs/lodash.js"></script>
<script src="./libs/inspire-tree/inspire-tree.min.js"></script>
<script src="./libs/inspire-tree/inspire-tree-dom-min.js"></script>
</head>
<body>
<canvas id="myCanvas"></canvas>
<div id="treePanel" class="treePanel"></div>
<div id="info">
<h1>Loading a BIM Model from the File System</h1>
<ul>
<li>
<a target="_other"
href="./../docs/class/src/viewer/plugins/GLTFLoaderPlugin/GLTFLoaderPlugin.js~GLTFLoaderPlugin.html">GLTFLoaderPlugin</a>
- Loads model and IFC data from file system
</li>
<li>
<a target="_other"
href="http://openifcmodel.cs.auckland.ac.nz/Model/Details/274">Model source</a>
</li>
<li>
<a target="_other" href="https://github.com/xeolabs/xeokit-sdk/wiki/Viewing-BIM-Models-Offline">User Guide</a>
</li>
</ul>
</div>
</body>
<script type="module">
//------------------------------------------------------------------------------------------------------------------
// Import the modules we need for this example
//------------------------------------------------------------------------------------------------------------------
import {Viewer} from "../src/viewer/Viewer.js";
import {VRMLLoaderPlugin} from "../src/viewer/plugins/VRMLLoaderPlugin/VRMLLoaderPlugin.js";
//------------------------------------------------------------------------------------------------------------------
// Create a Viewer, arrange the camera, tweak xraying and highlight materials
//------------------------------------------------------------------------------------------------------------------
const viewer = new Viewer({
canvasId: "myCanvas",
transparent: true
});
viewer.camera.eye = [-3.9338698387145996, 2.8559818267822266, 27.018949508666992];
viewer.camera.look = [4.400000095367432, 3.7249999046325684, 8.899999618530273];
viewer.camera.up = [-0.018190976232290268, 0.999053955078125, 0.0395493358373642];
viewer.cameraFlight.fitFOV = 15;
viewer.scene.xrayMaterial.fillAlpha = 0.1;
viewer.scene.xrayMaterial.fillColor = [0, 0, 0];
viewer.scene.xrayMaterial.edgeAlpha = 0.4;
viewer.scene.xrayMaterial.edgeColor = [0, 0, 0];
viewer.scene.highlightMaterial.fillAlpha = 0.3;
viewer.scene.highlightMaterial.edgeColor = [1, 1, 0];
//------------------------------------------------------------------------------------------------------------------
// Load model and metadata
//------------------------------------------------------------------------------------------------------------------
const gltfLoader = new VRMLLoaderPlugin(viewer);
const model = gltfLoader.load({
id: "p10",
src: "./models/vrml/TEST.wrl",
metaModelSrc: "./models/vrml/TEST.wri", // Creates a MetaObject instances in scene.metaScene.metaObjects
edges: true
});
//------------------------------------------------------------------------------------------------------------------
// Mouse over Entities to highlight them
//------------------------------------------------------------------------------------------------------------------
var lastEntity = null;
viewer.scene.input.on("mousemove", function (coords) {
var hit = viewer.scene.pick({
canvasPos: coords
});
if (hit) {
if (!lastEntity || hit.entity.id !== lastEntity.id) {
if (lastEntity) {
lastEntity.highlighted = false;
}
lastEntity = hit.entity;
hit.entity.highlighted = true;
}
} else {
if (lastEntity) {
lastEntity.highlighted = false;
lastEntity = null;
}
}
});
//------------------------------------------------------------------------------------------------------------------
// When model loaded, create a tree view that toggles object xraying
//------------------------------------------------------------------------------------------------------------------
model.on("loaded", function () {
// Fit model to view
model.on("loaded", () => {
viewer.cameraFlight.jumpTo(model);
});
// Builds tree view data from MetaModel
var createData = function (metaModel) {
const data = [];
function visit(expand, data, metaObject) {
if (!metaObject) {
return;
}
for (var obj in metaModel.metaScene.metaObjects) {
var child = {
id: obj,
text: metaModel.metaScene.metaObjects[obj].name
};
data.push(child);
}
}
visit(true, data, metaModel.metaScene.metaObjects);
return data;
};
// Get MetaModel we loaded for our model
const modelId = model.id;
const metaModel = viewer.metaScene.metaModels[modelId];
var data;
// Create the tree view
var treeView = new InspireTree({
selection: {
autoSelectChildren: true,
autoDeselect: true,
mode: 'checkbox'
},
checkbox: {
autoCheckChildren: true
},
data: createData(metaModel)
});
new InspireTreeDOM(treeView, {
target: document.getElementById("treePanel")
});
// Initialize the tree view once loaded
treeView.on('model.loaded', function () {
treeView.select();
treeView.model.expand();
treeView.on('node.selected', function (event, node) {
const objectId = event.id;
viewer.scene.setObjectsXRayed(objectId, false);
viewer.scene.setObjectsCollidable(objectId, true);
viewer.scene.setObjectsPickable(objectId, true);
});
treeView.on('node.deselected', function (event, node) {
const objectId = event.id;
viewer.scene.setObjectsXRayed(objectId, true);
viewer.scene.setObjectsCollidable(objectId, false);
viewer.scene.setObjectsPickable(objectId, false);
});
});
});
//------------------------------------------------------------------------------------------------------------------
//
//------------------------------------------------------------------------------------------------------------------
viewer.scene.input.on("mouseclicked", function (coords) {
var hit = viewer.scene.pick({
canvasPos: coords
});
if (hit) {
var entity = hit.entity;
var metaObject = viewer.metaScene.metaObjects[entity.objectId];
if (metaObject) {
console.log(JSON.stringify(metaObject.getJSON(), null, "\t"));
} else {
const parent = entity.parent;
if (parent) {
metaObject = viewer.metaScene.metaObjects[parent.objectId];
if (metaObject) {
console.log(JSON.stringify(metaObject.getJSON(), null, "\t"));
}
}
}
}
});
window.viewer = viewer;
</script>
</html>