-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
671 lines (545 loc) · 29.4 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NHP Patch Volume Renderer</title>
<link rel="icon" type="image/png" href="assets/image/CMU_Tartans.png">
<link rel="stylesheet" href="dist/style.css">
<!-- <script defer type="module" src="./src/index.js"></script> -->
</head>
<body class="bg-black-alt font-sans leading-normal tracking-normal">
<nav id="header" class="bg-gray-900 fixed w-full z-10 top-0 shadow">
<div class="w-full container mx-auto flex flex-wrap items-center mt-0 pt-3 pb-3 md:pb-0">
<div class="w-1/2 pl-2 md:pl-0">
<a class="text-gray-100 text-base xl:text-xl no-underline hover:no-underline font-bold" href="#">
<i class="fas fa-moon text-blue-400 pr-3"></i> NHP Patch Volume Renderer
</a>
</div>
<div class="w-1/2 pr-0">
<div class="flex relative inline-block float-center">
<div class="relative text-sm text-gray-100">
<button id="userButton" class="flex items-center focus:outline-none mr-3">
<img class="w-8 h-8 rounded-full mr-4" src="./assets/image/CMU_Tartans.png" alt="Avatar of User"> <span class="hidden md:inline-block text-gray-100">NML</span>
<svg class="pl-2 h-2 fill-current text-gray-100" version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 129 129" xmlns:xlink="http://www.w3.org/1999/xlink" enable-background="new 0 0 129 129"><g><path d="m121.3,34.6c-1.6-1.6-4.2-1.6-5.8,0l-51,51.1-51.1-51.1c-1.6-1.6-4.2-1.6-5.8,0-1.6,1.6-1.6,4.2 0,5.8l53.9,53.9c0.8,0.8 1.8,1.2 2.9,1.2 1,0 2.1-0.4 2.9-1.2l53.9-53.9c1.7-1.6 1.7-4.2 0.1-5.8z"/></g></svg>
</button>
<div id="userMenu" class="bg-gray-900 rounded shadow-md mt-2 absolute mt-12 top-0 right-0 min-w-full overflow-auto z-30 invisible">
<ul class="list-reset">
<li><a href="#" class="px-4 py-2 block text-gray-100 hover:bg-gray-800 no-underline hover:no-underline">My account</a></li>
<li><a href="#" class="px-4 py-2 block text-gray-100 hover:bg-gray-800 no-underline hover:no-underline">Notifications</a></li>
<li><hr class="border-t mx-2 border-gray-400"></li>
<li><a href="#" class="px-4 py-2 block text-gray-100 hover:bg-gray-800 no-underline hover:no-underline">Logout</a></li>
</ul>
</div>
</div>
<div class="block lg:hidden pr-4">
<button id="nav-toggle" class="flex items-center px-3 py-2 border rounded text-gray-500 border-gray-600 hover:text-gray-100 hover:border-teal-500 appearance-none focus:outline-none">
<svg class="fill-current h-3 w-3" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><title>Menu</title><path d="M0 3h20v2H0V3zm0 6h20v2H0V9zm0 6h20v2H0v-2z"/></svg>
</button>
</div>
</div>
</div>
<div class="w-full flex-grow lg:flex lg:items-center lg:w-auto hidden lg:block mt-2 lg:mt-0 bg-gray-900 z-20" id="nav-content">
<ul class="list-reset lg:flex flex-1 items-center px-4 md:px-0">
<li class="mr-6 my-2 md:my-0">
<a href="#" class="block py-1 md:py-3 pl-1 align-middle text-blue-400 no-underline hover:text-gray-100 border-b-2 border-blue-400 hover:border-blue-400">
<i class="fas fa-home fa-fw mr-3 text-blue-400"></i><span class="pb-1 md:pb-0 text-sm">Main</span>
</a>
</li>
<li class="mr-6 my-2 md:my-0">
<a href="#" class="block py-1 md:py-3 pl-1 align-middle text-gray-500 no-underline hover:text-gray-100 border-b-2 border-gray-900 hover:border-pink-400">
<i class="fas fa-tasks fa-fw mr-3"></i><span class="pb-1 md:pb-0 text-sm">Parameters</span>
</a>
</li>
<li class="mr-6 my-2 md:my-0">
<a href="#" class="block py-1 md:py-3 pl-1 align-middle text-gray-500 no-underline hover:text-gray-100 border-b-2 border-gray-900 hover:border-purple-400">
<i class="fa fa-envelope fa-fw mr-3"></i><span class="pb-1 md:pb-0 text-sm">Console</span>
</a>
</li>
<li class="mr-6 my-2 md:my-0">
<a href="#" class="block py-1 md:py-3 pl-1 align-middle text-gray-500 no-underline hover:text-gray-100 border-b-2 border-gray-900 hover:border-green-400">
<i class="fas fa-chart-area fa-fw mr-3"></i><span class="pb-1 md:pb-0 text-sm">Statistics</span>
</a>
</li>
<li class="mr-6 my-2 md:my-0">
<a href="#" class="block py-1 md:py-3 pl-1 align-middle text-gray-500 no-underline hover:text-gray-100 border-b-2 border-gray-900 hover:border-red-400">
<i class="fa fa-wallet fa-fw mr-3"></i><span class="pb-1 md:pb-0 text-sm">Notes</span>
</a>
</li>
<li class="mr-6 my-2 md:my-0">
<div class="relative pull-left pl-4 pr-4 md:pr-0">
<input type="search" placeholder="Search" class="w-full bg-gray-900 text-sm text-gray-400 transition border border-gray-800 focus:outline-none focus:border-gray-600 rounded py-1 px-2 pl-10 appearance-none leading-normal">
<div class="absolute search-icon" style="top: 0.375rem;left: 1.75rem;">
<svg class="fill-current pointer-events-none text-gray-500 w-4 h-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
<path d="M12.9 14.32a8 8 0 1 1 1.41-1.41l5.35 5.33-1.42 1.42-5.33-5.34zM8 14A6 6 0 1 0 8 2a6 6 0 0 0 0 12z"></path>
</svg>
</div>
</div>
</li>
</ul>
</div>
</div>
</nav>
<!--Container-->
<div class="container w-full mx-auto pt-20">
<div class="w-full px-4 md:px-0 md:mt-8 mb-16 text-gray-800 leading-normal", id="main_canvas">
<div class="flex flex-row flex-wrap flex-grow mt-2">
<div class="w-full">
<!--Graph Card-->
<div class="bg-gray-900 border border-gray-800 rounded shadow">
<div class="border-b border-gray-800 p-3">
<h5 class="font-bold uppercase text-gray-600">Map</h5>
</div>
<div class="p-5" id="canvas" name="main">
</div>
</div>
<!--/Graph Card-->
</div>
<div class="w-full p-3">
<!--Table Card
<div class="bg-gray-900 border border-gray-800 rounded shadow">
<div class="border-b border-gray-800 p-3">
<h5 class="font-bold uppercase text-gray-600">Table</h5>
</div>
<div class="p-5">
<table class="w-full p-5 text-gray-700">
<thead>
<tr>
<th class="text-left text-gray-600">Name</th>
<th class="text-left text-gray-600">Side</th>
<th class="text-left text-gray-600">Role</th>
</tr>
</thead>
<tbody>
<tr>
<td>Obi Wan Kenobi</td>
<td>Light</td>
<td>Jedi</td>
</tr>
<tr>
<td>Greedo</td>
<td>South</td>
<td>Scumbag</td>
</tr>
<tr>
<td>Darth Vader</td>
<td>Dark</td>
<td>Sith</td>
</tr>
</tbody>
</table>
<p class="py-2"><a href="#" class="text-white">See More issues...</a></p>
</div>
</div>
<!--/table Card-->
</div>
</div>
<!--Divider-->
<hr class="border-b-2 border-gray-600 my-8 mx-4">
<!--Console Content-->
<div class="flex flex-wrap">
<div class="w-full md:w-1/2 xl:w-1/3 p-3">
<!--Metric Card-->
<div class="bg-gray-900 border border-gray-800 rounded shadow p-2">
<div class="flex flex-row items-center">
<div class="flex-shrink pr-4">
<div class="rounded p-3 bg-yellow-600"><i class="fa fa-wallet fa-2x fa-fw fa-inverse"></i></div>
</div>
<div class="flex-1 text-right md:text-center">
<h5 class="font-bold uppercase text-gray-400">FCU</h5>
<h3 class="font-bold text-3xl text-gray-600" id="FCU">0 <span class="text-green-500"><i class="fas fa-caret-up"></i></span></h3>
</div>
</div>
</div>
<!--/Metric Card-->
</div>
<div class="w-full md:w-1/2 xl:w-1/3 p-3">
<!--Metric Card-->
<div class="bg-gray-900 border border-gray-800 rounded shadow p-2">
<div class="flex flex-row items-center">
<div class="flex-shrink pr-4">
<div class="rounded p-3 bg-yellow-600"><i class="fas fa-users fa-2x fa-fw fa-inverse"></i></div>
</div>
<div class="flex-1 text-right md:text-center">
<h5 class="font-bold uppercase text-gray-400">FCR</h5>
<h3 class="font-bold text-3xl text-gray-600" id="FCR">0<span class="text-pink-500"><i class="fas fa-exchange-alt"></i></span></h3>
</div>
</div>
</div>
<!--/Metric Card-->
</div>
<div class="w-full md:w-1/2 xl:w-1/3 p-3">
<!--Metric Card-->
<div class="bg-gray-900 border border-gray-800 rounded shadow p-2">
<div class="flex flex-row items-center">
<div class="flex-shrink pr-4">
<div class="rounded p-3 bg-pink-600"><i class="fas fa-user-plus fa-2x fa-fw fa-inverse"></i></div>
</div>
<div class="flex-1 text-right md:text-center">
<h5 class="font-bold uppercase text-gray-400">ED23</h5>
<h3 class="font-bold text-3xl text-gray-600" id="ED23">0 <span class="text-yellow-600"><i class="fas fa-caret-up"></i></span></h3>
</div>
</div>
</div>
<!--/Metric Card-->
</div>
<div class="w-full md:w-1/2 xl:w-1/3 p-3">
<!--Metric Card-->
<div class="bg-gray-900 border border-gray-800 rounded shadow p-2">
<div class="flex flex-row items-center">
<div class="flex-shrink pr-4">
<div class="rounded p-3 bg-red-600"><i class="fas fa-user-plus fa-2x fa-fw fa-inverse"></i></div>
</div>
<div class="flex-1 text-right md:text-center">
<h5 class="font-bold uppercase text-gray-400">ED45</h5>
<h3 class="font-bold text-3xl text-gray-600" id="ED45">0 <span class="text-yellow-600"><i class="fas fa-caret-up"></i></span></h3>
</div>
</div>
</div>
<!--/Metric Card-->
</div>
<div class="w-full md:w-1/2 xl:w-1/3 p-3">
<!--Metric Card-->
<div class="bg-gray-900 border border-gray-800 rounded shadow p-2">
<div class="flex flex-row items-center">
<div class="flex-shrink pr-4">
<div class="rounded p-3 bg-green-600"><i class="fas fa-user-plus fa-2x fa-fw fa-inverse"></i></div>
</div>
<div class="flex-1 text-right md:text-center">
<h5 class="font-bold uppercase text-gray-400">ECU</h5>
<h3 class="font-bold text-3xl text-gray-600" id="ECU">0 <span class="text-yellow-600"><i class="fas fa-caret-up"></i></span></h3>
</div>
</div>
</div>
<!--/Metric Card-->
</div>
<div class="w-full md:w-1/2 xl:w-1/3 p-3">
<!--Metric Card-->
<div class="bg-gray-900 border border-gray-800 rounded shadow p-2">
<div class="flex flex-row items-center">
<div class="flex-shrink pr-4">
<div class="rounded p-3 bg-green-600"><i class="fas fa-user-plus fa-2x fa-fw fa-inverse"></i></div>
</div>
<div class="flex-1 text-right md:text-center">
<h5 class="font-bold uppercase text-gray-400">EDC</h5>
<h3 class="font-bold text-3xl text-gray-600" id="EDC">0 <span class="text-yellow-600"><i class="fas fa-caret-up"></i></span></h3>
</div>
</div>
</div>
<!--/Metric Card-->
</div>
</div>
</div>
<!--/ Console Content-->
</div>
<!--/container-->
<!-- Dropdowns/Menus -->
<script>
/*Toggle dropdown list*/
/*https://gist.github.com/slavapas/593e8e50cf4cc16ac972afcbad4f70c8*/
var userMenuDiv = document.getElementById("userMenu");
var userMenu = document.getElementById("userButton");
var navMenuDiv = document.getElementById("nav-content");
var navMenu = document.getElementById("nav-toggle");
document.onclick = check;
function check(e){
var target = (e && e.target) || (event && event.srcElement);
//User Menu
if (!checkParent(target, userMenuDiv)) {
// click NOT on the menu
if (checkParent(target, userMenu)) {
// click on the link
if (userMenuDiv.classList.contains("invisible")) {
userMenuDiv.classList.remove("invisible");
} else {userMenuDiv.classList.add("invisible");}
} else {
// click both outside link and outside menu, hide menu
userMenuDiv.classList.add("invisible");
}
}
//Nav Menu
if (!checkParent(target, navMenuDiv)) {
// click NOT on the menu
if (checkParent(target, navMenu)) {
// click on the link
if (navMenuDiv.classList.contains("hidden")) {
navMenuDiv.classList.remove("hidden");
} else {navMenuDiv.classList.add("hidden");}
} else {
// click both outside link and outside menu, hide menu
navMenuDiv.classList.add("hidden");
}
}
}
function checkParent(t, elm) {
while(t.parentNode) {
if( t == elm ) {return true;}
t = t.parentNode;
}
return false;
}
</script>
<!-- Dropdowns/Menus -->
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"three": "https://cdnjs.cloudflare.com/ajax/libs/three.js/r134/three.module.min.js"
}
}
</script>
<script type="module">
import * as THREE from 'three';
import {GUI} from './src/lil-gui.module.min.js';
import { DragControls } from './src/DragControls.js';
import { MapControls } from './src/OrbitControls.js';
import { GLTFLoader } from './src/GLTFLoader.js';
const loader = new GLTFLoader();
let container;
let camera, scene, renderer, sba;
let shape_controls, cam_controls, group, geometry, gui;
let enableSelection = false;
const data = [
{
'name': 'FCU',
'color': 0xca8a04,
'count': 0,
'uuid': [],
'state': []
},
{
'name': 'FCR',
'color': 0xca8a04,
'count': 0,
'uuid': [],
'state': []
},
{
'name': 'ED23',
'color': 0xdc2626,
'count': 0,
'uuid': [],
'state': []
},
{
'name': 'ED45',
'color': 0xdc2626,
'count': 0,
'uuid': [],
'state': []
},
{
'name': 'EDC',
'color': 0x16a34a,
'count': 0,
'uuid': [],
'state': []
},
{
'name': 'ECU',
'color': 0x16a34a,
'count': 0,
'uuid': [],
'state': []
}
];
const data_cb = {
save() {
let file_name = `pattern_layout_${(new Date().toJSON().slice(0,10))}.txt`;
export_data_json(data, file_name)
}
}
var cur_shape, ORIG_W, ORIG_H;
const objects = [];
const mouse = new THREE.Vector2(0, 1), raycaster = new THREE.Raycaster();
init();
function init() {
container = document.getElementById("canvas");
// document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 100, window.innerWidth / window.innerHeight, 1, 5000 );
camera.position.z = 75;
camera.position.x = -10;
camera.position.y = 10;
scene = new THREE.Scene();
scene.background = new THREE.Color( 0xf0f0f0 );
loader.load("assets/Rhesus-Macaque-SBA.gltf", function (gltf) {
sba = gltf.scene;
sba.rotation.y = Math.PI/4;
sba.opacity = 0.5;
sba.transparent = true;
scene.add(gltf.scene);
}, function (progress) {
console.log(progress);
}, function (error) {
console.error(error);
})
scene.add( new THREE.AmbientLight( 0x505050 ) );
const dirLight1 = new THREE.DirectionalLight( 0xffffff );
dirLight1.position.set( 1, 1, 1 );
scene.add( dirLight1 );
const dirLight2 = new THREE.DirectionalLight( 0x002288 );
dirLight2.position.set( - 1, - 1, - 1 );
scene.add( dirLight2 );
const ambientLight = new THREE.AmbientLight( 0x222222 );
scene.add( ambientLight );
group = new THREE.Group();
scene.add( group );
const geometry = new THREE.ConeGeometry( 1.50, 0.6600, 10 );
const gui = new GUI();
gui.title("Controls");
const patterns = new GUI();
patterns.title("Patterns");
// Add some initial random shapes
for ( let i = 0; i < 6; i ++ ) {
let i_musc = Math.floor(Math.random()*data.length);
let name = data[i_musc].name;
let col = data[i_musc].color;
data[i_musc].count += 1;
let indicator = document.querySelector(`#${name}`);
console.log(data);
indicator.innerHTML = data[i_musc].count.toString();
let material = new THREE.MeshLambertMaterial( { color: col});
material.opacity = 0.5;
material.transparent = true;
const obj = new THREE.Mesh( geometry, material);
obj.name = `Pattern-${i}`;
data[i_musc].uuid.push(obj.uuid);
console.log(obj);
obj.position.x = Math.random() * 5.00 - 10.0;
obj.position.y = Math.random() * 2.50 + 10.0;
obj.position.z = 6.0;
obj.rotation.y = Math.PI/3;
obj.rotation.z = 0;
obj.rotation.x = -Math.PI/2;
obj.scale.x = Math.max(Math.random() * 2 + 1, 1.0);
obj.scale.y = 10.0;
obj.scale.z = obj.scale.x;
obj.castShadow = true;
obj.receiveShadow = true;
scene.add( obj );
const folder = patterns.addFolder(obj.name);
folder.add(obj.scale, 'y', 1.0, 100.0).name('Scale').onChange(val => {
obj.position.z = 6.0 - (val * obj.geometry.parameters.height - 3.3)/2;
});
folder.add(obj.position, 'x', -20.0, 0.0);
folder.add(obj.position, 'y', 0.0, 20.0);
folder.add(obj.position, 'z', 0.0, 10.0);
folder.close();
objects.push( obj );
data[i_musc].state.push({'position': obj.position, 'rotation': obj.rotation, 'scale': obj.scale, 'geometry': obj.geometry.parameters});
}
patterns.close();
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
const elem = document.querySelector("#main_canvas");
const rect = elem.getBoundingClientRect();
ORIG_W = rect.width*0.94;
ORIG_H = rect.height*0.80;
renderer.setSize(ORIG_W, ORIG_H);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFShadowMap;
container.appendChild( renderer.domElement );
shape_controls = new DragControls( [ ... objects ], camera, renderer.domElement );
shape_controls.addEventListener( 'drag', render );
// controls
cam_controls = new MapControls( camera, renderer.domElement );
cam_controls.addEventListener( 'change', render ); // call this only in static scenes (i.e., if there is no animation loop)
cam_controls.enableDamping = true; // an animation loop is required when either damping or auto-rotation are enabled
cam_controls.dampingFactor = 0.15;
cam_controls.screenSpacePanning = false;
cam_controls.minDistance = -50;
cam_controls.maxDistance = 100;
cam_controls.maxPolarAngle = Math.PI / 2;
window.addEventListener( 'resize', onWindowResize );
document.addEventListener( 'click', onClick );
window.addEventListener( 'keydown', onKeyDown );
window.addEventListener( 'keyup', onKeyUp );
shape_controls.addEventListener( 'dragstart', onDragStart );
shape_controls.addEventListener( 'dragend', onDragEnd );
const folder = gui.addFolder("View");
folder.add( cam_controls, 'screenSpacePanning' );
folder.add( cam_controls, 'enableRotate');
folder.add( cam_controls, 'enablePan');
folder.add( cam_controls, 'enableZoom');
folder.add( cam_controls, 'autoRotate');
folder.close();
gui.add(data_cb, 'save');
render();
}
function animate() {
requestAnimationFrame( animate );
cam_controls.update(); // only required if controls.enableDamping = true, or if controls.autoRotate = true
render();
}
function onWindowResize() {
const elem = document.querySelector("#main_canvas");
const rect = elem.getBoundingClientRect();
let w = Math.min(rect.width*0.94, ORIG_W);
let h = Math.min(rect.height*0.8, ORIG_H);
renderer.setSize(w, h);
// camera.aspect = w / h;
// camera.updateProjectionMatrix();
render();
}
function onKeyDown( event ) {
enableSelection = ( event.keyCode === 16 ) ? true : false;
}
function onKeyUp() {
enableSelection = false;
}
function onDragStart( event ) {
cam_controls.enabled = false;
}
function onDragEnd( event ) {
cam_controls.enabled = true;
}
function onClick( event ) {
event.preventDefault();
if ( enableSelection === true ) {
const draggableObjects = shape_controls.getObjects();
// draggableObjects.length = 0;
mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
raycaster.setFromCamera( mouse, camera );
const intersections = raycaster.intersectObjects( objects, true );
if ( intersections.length > 0 ) {
const object = intersections[ 0 ].object;
if ( group.children.includes( object ) === true ) {
object.material.emissive.set( 0x000000 );
scene.attach( object );
} else {
object.material.emissive.set( 0xaaaaaa );
group.attach( object );
}
shape_controls.transformGroup = true;
draggableObjects.push( group );
}
if ( group.children.length === 0 ) {
shape_controls.transformGroup = false;
draggableObjects.push( ...objects );
}
}
render();
}
function render() {
renderer.render( scene, camera );
}
function export_data_json(data_to_export, file_name) {
const a = document.createElement("a");
let my_json_str = JSON.stringify(data_to_export, null, 2);
console.log(my_json_str);
var file = new Blob([my_json_str], {
type: "text/plain"
});
a.href = URL.createObjectURL(file);
a.download = file_name;
a.click();
URL.revokeObjectURL(a.href);
console.log(`Data saved in ${file_name}`);
}
</script>
</body>
</html>