-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexport_upgrade.html
243 lines (187 loc) · 7.21 KB
/
export_upgrade.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
<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 src="jsroot/scripts/JSRootCore.js?geom&onload=init" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>
</head>
<body>
<script>
var container, stats;
var camera, scene, renderer, controls;
var mouse = new THREE.Vector2(),
INTERSECTED;
var alllines = new THREE.Object3D();
var rootgeom;
var detector;
var detector;
var to_hide = []
// "HcalInstallationlvHcalInnerSupportFrame",
// "MagnetYoke", "ITlvAirVolume", "EcalModules", "HcalModules", "VeloVacTank", "VeloRFBox",
// "VeloRFFoil", "PipeSection", "Rich1lvRich1Mgs", "Rich1lvRich1MagSh", "Rich1lvRich1Exit",
// "Velo2Rich", "Rich2lvRich2MagSh", "Rich2lvRich2Tube"];
var hide_children = []
//"HcalInstallationlvHcal_4825", "EcalInstallationEcal_4826"];
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;
}
}
for (let i = 0; i < hide_children.length; i++) {
item = hide_children[i];
//console.log("Checking:", item);
if (tmpname.startsWith(item)) {
node.fVolume.fGeoAtt = 4;
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) {
// 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]);
var obj3d = JSROOT.GEO.build(obj, opt, display_geometry);
}
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() {
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();
var filename = "lhcb_upgrade.root"
JSROOT.OpenFile(filename, function (file) {
file.ReadObject("Default;1", add_geometry);
});
}
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_upgrade.gltf"
});
// Save the file
saveAs(fileToSave, "lhcb_upgrade.gltf");
downloadJSON(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>
function init() {
console.log("In init");
loadgeo();
}
</script>
</body>