-
Notifications
You must be signed in to change notification settings - Fork 8
/
export.html
274 lines (220 loc) · 8.83 KB
/
export.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
<html>
<head>
<meta charset=utf-8>
<title>Test display</title>
<style>
body {
margin: 0;
}
canvas {
width: 100%;
height: 100%
}
</style>
<script src="jsroot/node_modules/three/build/three.js"></script>
<script src="jsroot/node_modules/three/examples/js/controls/OrbitControls.js"></script>
<script src="GLTFExporter.js"> </script>
<script type="text/javascript" src="https://root.cern/js/latest/scripts/JSRoot.core.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>
</head>
<body>
<div id="mylog" style="block"></div>
<script>
var mylog = document.getElementById('mylog');
var container, stats;
var camera, scene, renderer, controls;
var mouse = new THREE.Vector2(),
INTERSECTED;
var alllines = new THREE.Object3D();
var rootgeom;
var detector;
/**
* Uncomment the following arrays to hide the parts that you need.
* You can remove specific strings from the arrays to hide specific parts!
*/
// var to_hide = [
// "MagnetYoke", "ITlvAirVolume", "VeloVacTank", "VeloRFBox",
// "VeloRFFoil", "PipeSection", "Rich1lvRich1Mgs", "Rich1lvRich1MagSh", "Rich1lvRich1Exit",
// "Velo2Rich", "Rich2lvRich2MagSh", "Rich2lvRich2Tube", "MagnetCoil_4844", "VeloSupports", "VeloSensors",
// "OTModules", "ITITS3", "Rich1lvRich1", "ITITS1l", "VeloWFConel", "ITITS2lv", "ITITS", "Rich1l", "Rich2l",
// "PrsInstallation", "PrsSteelSheet", "SpdInstallation"
// ];
// var hide_children = [];
// var hide_EcalHcal = [
// "EcalInstallation", "HcalInstallation"
// ];
// var hide_muon = [
// "Muon"
// ];
function process_root_node(node, level = 0, path = "") {
//mylog.innerHTML += path + " " + level + " " + node.fName + "\n";
tmpname = node.fName;
iterate_children = true;
//console.log("processing:", tmpname, path, node)
for (let i = 0; i < to_hide.length; i++) {
item = to_hide[i];
//console.log("Checking:", item);
if (tmpname.startsWith(item)) {
node.fVolume.fGeoAtt = 0;
}
}
// Hide Ecal, Hcal
for (let i = 0; i < hide_EcalHcal.length; i++) {
item = hide_EcalHcal[i];
//console.log("Checking:", item);
if (tmpname.startsWith(item)) {
node.fVolume.fGeoAtt = 0;
}
}
// Hide Muon
for (let i = 0; i < hide_muon.length; i++) {
item = hide_muon[i];
//console.log("Checking:", item);
if (tmpname.startsWith(item)) {
node.fVolume.fGeoAtt = 0;
}
}
for (let i = 0; i < hide_children.length; i++) {
item = hide_children[i];
//console.log("Checking:", item);
if (tmpname.startsWith(item)) {
node.fVolume.fGeoAtt = 0;
iterate_children = false;
//console.log("Matched", item, tmpname, path)
}
}
//console.log("subvolume:", tmpname, node);
if (node.fVolume.fNodes && iterate_children) {
for (let j = 0; j < node.fVolume.fNodes.arr.length; j++) {
snode = node.fVolume.fNodes.arr[j];
process_root_node(snode, level + 1, path + "/" + tmpname);
}
}
}
function add_geometry(obj) {
console.log("inside add_geometry");
// options for building three.js model
var opt = {
numfaces: 5000000,
numnodes: 50000,
dflt_colors: true,
vislevel: 4
};
console.log(obj);
rootgeom = obj;
process_root_node(obj.fNodes.arr[0], 0, "");
JSROOT.require('geom')
.then(geo => {
let obj3d = geo.build(obj, opt);
display_geometry(obj3d)
});
}
function display_geometry(obj3d) {
console.log("DISPLAYING", obj3d);
if (!obj3d) return;
detector = obj3d;
scene.add(obj3d);
var box3 = new THREE.Box3().setFromObject(obj3d);
geom_size = box3.getSize().length();
camera.far = geom_size * 5;
camera.updateProjectionMatrix();
postinit();
}
function loadgeo() {
console.log("inside loadgeo");
container = document.createElement('div');
document.body.appendChild(container);
// renderer
renderer = new THREE.WebGLRenderer();
renderer.setClearColor(0xFFFFFF);
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
//renderer.setFaceCulling(false);
renderer.sortObjects = false;
container.appendChild(renderer.domElement);
var info = document.createElement('div');
info.style.position = 'absolute';
info.style.top = '10px';
info.style.width = '100%';
info.style.textAlign = 'center';
// camera
camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.set(-10000, 1000, 3000);
//camera.up.set(0.0, 1.0, 0.0);
// controls
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.target.set(0.0, 0.0, 8);
// scene
scene = new THREE.Scene();
console.log("inside loadgeo_beforeFilename");
var filename = "https://root.cern/files/lhcbfull.root"
JSROOT.openFile(filename)
.then(file => file.readObject("Geometry;1"))
.then(obj => add_geometry(obj));
}
function postinit() {
// Particles
// line 1
var linegeometry1 = new THREE.Geometry();
var line1 = new THREE.Line(linegeometry1, new THREE.LineBasicMaterial({
color: 0x00033
}));
linegeometry1.vertices.push(new THREE.Vector3(0, 0, -1500));
linegeometry1.vertices.push(new THREE.Vector3(1000, 1000, 15000));
alllines.add(line1);
// line 2
var linegeometry2 = new THREE.Geometry();
var line2 = new THREE.Line(linegeometry2, new THREE.LineBasicMaterial({
color: 0x00033
}));
linegeometry2.vertices.push(new THREE.Vector3(0, 0, -1500));
linegeometry2.vertices.push(new THREE.Vector3(-1000, 1000, 15000));
alllines.add(line2);
//line 3
var linegeometry3 = new THREE.Geometry();
var line3 = new THREE.Line(linegeometry3, new THREE.LineBasicMaterial({
color: 0x00033
}));
linegeometry3.vertices.push(new THREE.Vector3(0, 0, -1500));
linegeometry3.vertices.push(new THREE.Vector3(-1000, -1000, 15000));
alllines.add(line3);
scene.add(alllines);
scene.add(new THREE.AmbientLight(0xff0000, 0.8));
var light = new THREE.DirectionalLight(0x00ff00, 1);
light.position.set(-100, 4000, -10000); //.normalize();
scene.add(light);
window.addEventListener('resize', onWindowResize, false);
var doexport = true;
if (doexport) {
options = {};
GLTFExporter.parse(detector, function(gltf) {
console.log(gltf);
var fileToSave = new Blob([JSON.stringify(gltf)], {
type: 'application/json',
name: "lhcb.gltf"
});
// Save the file
console.log("reached this point??");
saveAs(fileToSave, "./lhcb.gltf");
}, options);
}
animate();
}
function animate() {
requestAnimationFrame(animate);
render();
}
function render() {
renderer.render(scene, camera);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
}
</script>
<script>
loadgeo();
</script>
</body>