-
Notifications
You must be signed in to change notification settings - Fork 1
/
single_viewer.html
1730 lines (1531 loc) · 63.8 KB
/
single_viewer.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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" data-bs-theme="dark">
<head>
<meta content="charset=UTF-8"/>
<meta charset="UTF-8"/>
<title>Dynamic Collections</title>
<script src="js/jquery-3.6.4.min.js"></script>
<!-- Bootstrap -->
<link href="stylesheet/bootstrap.min.css" rel="stylesheet">
<script src="js/bootstrap.bundle.min.js"></script>
<!-- Bootstrap toggle-->
<link href="stylesheet/bootstrap4-toggle.min.css" rel="stylesheet">
<script src="js/bootstrap4-toggle.min.js"></script>
<!--STYLESHEET-->
<link type="text/css" rel="stylesheet" href="stylesheet/3dhop.css"/>
<!--COLLECTION STYLESHEET-->
<link type="text/css" rel="stylesheet" href="stylesheet/digitalCollection.css"/>
<!-- toastr -->
<link href="stylesheet/toastr.min.css" rel="stylesheet"/>
<script src="js/toastr.min.js"></script>
<!--SPIDERGL-->
<script type="text/javascript" src="js/spidergl.js"></script>
<!--PRESENTER-->
<script type="text/javascript" src="js/presenter.js"></script>
<!--3D MODELS LOADING AND RENDERING-->
<script type="text/javascript" src="js/nexus.js"></script>
<script type="text/javascript" src="js/ply.js"></script>
<!--TRACKBALLS-->
<script type="text/javascript" src="js/trackball_turntable.js"></script>
<script type="text/javascript" src="js/trackball_turntable_pan.js"></script>
<script type="text/javascript" src="js/trackball_sphere.js"></script>
<!--UTILITY-->
<script type="text/javascript" src="js/init.js"></script>
<script type="text/javascript" src="js/helpers.js"></script>
<!-- COLLECTION CLASS -->
<script src="js/collection.js"></script>
<!------ CONFIGURATION ------>
<script type="text/javascript" src="js/config_generic.js"></script>
<!------ CONFIGURATION ------>
</head>
<body onresize="onPageResize()">
<div class="h-100 container-fluid">
<div class="h-100 row">
<!--##############################################LEFT############################################-->
<div class="col-sm-9 border no-gutters p-0" style="height:100%">
<div id="3dhop" class="tdhop" onmousedown="if (event.preventDefault) event.preventDefault()"><div id="tdhlg"></div>
<div id="toolbar">
<img id="measure_on" title="Disable Measure Tool" src="skins/dark/measure_on.png" style="position:absolute; visibility:hidden;"/>
<img id="measure" title="Enable Measure Tool" src="skins/dark/measure.png"/><br/>
<img id="pick_on" title="Disable PickPoint Mode" src="skins/dark/pick_on.png" style="position:absolute; visibility:hidden;"/>
<img id="pick" title="Enable PickPoint Mode" src="skins/dark/pick.png"/><br/>
<img id="angle_on" title="Disable Angle Tool" src="skins/dark/angle_on.png" style="position:absolute; visibility:hidden;"/>
<img id="angle" title="Enable Angle Tool" src="skins/dark/angle.png"/><br/>
<img id="sections_on" title="Disable Plane Sections" src="skins/dark/sections_on.png" style="position:absolute; visibility:hidden;"/>
<img id="sections" title="Enable Plane Sections" src="skins/dark/sections.png"/>
</div>
<!--MEASURE-->
<div id="measure-box" class="output-box">Measured length<hr/><span id="measure-output" class="output-text" onmousedown="event.stopPropagation()">0.0</span></div>
<!--MEASURE-->
<!--POINT PICKING-->
<div id="pickpoint-box" class="output-box">XYZ picked point<hr/><span id="pickpoint-output" class="output-text" onmousedown="event.stopPropagation()">[ 0 , 0 , 0 ]</span></div>
<!--POINT PICKING-->
<!--ANGLE-->
<div id="angle-box" class="output-box">Angle<hr/><span id="angle-output" class="output-text" onmousedown="event.stopPropagation()">0.0°</span></div>
<!--ANGLE-->
<!--SECTIONS-->
<div id="sections-box" class="output-box">
<table class="output-table" onmousedown="event.stopPropagation()">
<tr><td>Plane</td><td>Position</td><td>Flip</td></tr>
<tr>
<td><img id="xplane_on" title="Disable X Axis Section" src="skins/icons/sectionX_on.png" onclick="sectionxSwitch()" style="position:absolute; visibility:hidden; border:1px inset;"/>
<img id="xplane" title="Enable X Axis Section" src="skins/icons/sectionX.png" onclick="sectionxSwitch()"/><br/></td>
<td><input id="xplaneSlider" class="output-input" type="range" title="Move X Axis Section Position"/></td>
<td><input id="xplaneFlip" class="output-input" type="checkbox" title="Flip X Axis Section Direction"/></td></tr>
<tr>
<td><img id="yplane_on" title="Disable Y Axis Section" src="skins/icons/sectionY_on.png" onclick="sectionySwitch()" style="position:absolute; visibility:hidden; border:1px inset;"/>
<img id="yplane" title="Enable Y Axis Section" src="skins/icons/sectionY.png" onclick="sectionySwitch()"/><br/></td>
<td><input id="yplaneSlider" class="output-input" type="range" title="Move Y Axis Section Position"/></td>
<td><input id="yplaneFlip" class="output-input" type="checkbox" title="Flip Y Axis Section Direction"/></td></tr>
<tr>
<td><img id="zplane_on" title="Disable Z Axis Section" src="skins/icons/sectionZ_on.png" onclick="sectionzSwitch()" style="position:absolute; visibility:hidden; border:1px inset;"/>
<img id="zplane" title="Enable Z Axis Section" src="skins/icons/sectionZ.png" onclick="sectionzSwitch()"/><br/></td>
<td><input id="zplaneSlider" class="output-input" type="range" title="Move Y Axis Section Position"/></td>
<td><input id="zplaneFlip" class="output-input" type="checkbox" title="Flip Z Axis Section Direction"/></td></tr></table>
<table class="output-table" onmousedown="event.stopPropagation()" style="text-align:right;">
<tr>
<td>Show planes<input id="showPlane" class="output-input" type="checkbox" title="Show Section Planes" style="bottom:-3px;"/></td>
<td>Show edges<input id="showBorder" class="output-input" type="checkbox" title="Show Section Edges" style="bottom:-3px;"/></td></tr></table>
</div>
<!--SECTIONS-->
<!--CUBE-->
<div style="position:absolute; top:0px; right:0px;">
<div class="cubeScene">
<div class="cube">
<div class="cube__face cube__face--front" onclick="viewFrom('front');">FRONT</div>
<div class="cube__face cube__face--back" onclick="viewFrom('back');">BACK</div>
<div class="cube__face cube__face--right" onclick="viewFrom('right');">RIGHT</div>
<div class="cube__face cube__face--left" onclick="viewFrom('left');">LEFT</div>
<div class="cube__face cube__face--top" onclick="viewFrom('top');">ABOVE</div>
<div class="cube__face cube__face--bottom" onclick="viewFrom('bottom');">BELOW</div>
</div>
</div>
</div>
<!--CUBE-->
<!--SPOTS DISPLAY-->
<div style="position:absolute; top:1rem; right:150px; width:75%; z-index:2; text-align:right;">
<span id="spot_display"></span>
</div>
<!--SPOTS DISPLAY-->
<!--INSTRUCTIONS-->
<div style="position:absolute; bottom:10px; left:10px; pointer-events: none;" >
<div id="panel_instructions" class="interfacePanel" style="max-width:300px; opacity: 0.7;">
</div>
</div>
<!--INSTRUCTIONS-->
<canvas id="draw-canvas"></canvas>
</div>
</div>
<!--##############################################LEFT############################################-->
<!--##############################################RIGHT#############################################-->
<div id="right_column" class="col-sm-3 justify-content-center overflow-hidden interfacePanel">
<!-- name & help -->
<div id="rr1" class="row justify-content-center">
<div class="col-sm-10 px-0 py-2" style="text-align:center">
<span id="sp_objDetails"></span>
</div>
<div class="col-sm-2 px-0" style="text-align:center">
<button class="btn btn-primary px-1 py-1 my-2" onclick="showHelp();"><img title="Help" src="skins/minimal_light/help.png" style="width:min(2.5vw,25px);"/></button>
</div>
</div>
<!-- name & help -->
<!-- home, zoom, canonical views -->
<div id="rr2" class="row my-0 border ">
<div class="col-sm-3 p-0 interfacePanel" style="text-align:center;">
<button class="btn btn-secondary px-1 py-1 my-2" onclick="home();"><img title="Home" src="skins/minimal_light/home.png" style="width:min(3vw,33px);"/></button>
</br></br>
<input id="i_orthoCamera" type="checkbox" style="width:20px; height:20px; cursor:hand;" onclick="updateOrtho(this.checked);"></input></br>
<h6 style='font-size:min(1.1vw, 1.1rem);'>ORTHO</h6>
</div>
<div class="col-sm-9 p-1" style="text-align:center;">
<center>
<table>
<tr><td></td><td><button class="btn btn-secondary side_bt" onclick="viewFrom('top');">TOP</button></td><td></td><td></td></tr>
<tr><td><button class="btn btn-secondary side_bt" onclick="viewFrom('left');">LEFT</button></td><td><button class="btn btn-secondary side_bt" onclick="viewFrom('front');">FRONT</button></td><td><button class="btn btn-secondary side_bt" onclick="viewFrom('right');">RIGHT</button></td><td><button class="btn btn-secondary side_bt" onclick="viewFrom('back');">BACK</button></td></tr>
<tr><td></td><td><button class="btn btn-secondary side_bt" onclick="viewFrom('bottom');">BOTTOM</button></td><td></td><td></td></tr>
</table>
</center>
</div>
</div>
<!-- home, zoom, canonical views -->
<!-- light & rendermodes -->
<div id="rr3" class="row my-0 border myCollapse interfacePanel" style="position:relative;">
<div class="col-1 p-1">
<img src="./media/restore.png" width="30px" height="30px" data-toggle="tooltip" data-placement="top" title="" onclick="resetViewState()" data-original-title="Reset Rendering">
</div>
<div class="col-5 p-1 d-flex align-items-center justify-content-center">
<canvas id="lightcontroller_canvas"/>
</div>
<div class="col-6 p-1" style="text-align:center">
<input class="resp_font" id="i_solidColor" type="checkbox" data-toggle="toggle" data-height="min(50px,20%)" data-width="min(130px,100%)" data-onstyle="secondary" data-offstyle="secondary" data-on="Plain Color" data-off="Texture" onchange="updateViewState('solid',this.checked);"/></br>
<input class="resp_font" id="i_transparency" type="checkbox" data-toggle="toggle" data-height="min(50px,20%)" data-width="min(130px,100%)" data-onstyle="secondary" data-offstyle="secondary" data-on="Transparent" data-off="Solid" onchange="updateViewState('transparency',this.checked);"/></br>
<input class="resp_font" id="i_useLighting" checked type="checkbox" data-toggle="toggle" data-height="min(50px,20%)" data-width="min(130px,100%)" data-onstyle="secondary" data-offstyle="secondary" data-on="Lighting" data-off="Unshaded" onchange="updateViewState('lighting',this.checked);"/></br>
<input class="resp_font" id="i_useSpecular" type="checkbox" data-toggle="toggle" data-height="min(50px,20%)" data-width="min(130px,100%)" data-onstyle="secondary" data-offstyle="secondary" data-on="Specular" data-off="Diffuse" onchange="updateViewState('specular',this.checked);"/></br>
</div>
<hr class="w-100 m-0 p-0"/>
<div class="col-sm-12 p-1 d-flex align-items-center justify-content-center resp_font">
Grid:
<select id="i_grid" name="grid" class="px-1 mx-2" onchange="changeGrid();">
<option value="off">Off</option>
<option selected=true value="flat">Base</option>
<option value="box">Box</option>
<option value="box">Fixed</option>
</select>
<input id="i_axes" type="checkbox" style="cursor:hand;" onclick="if(this.checked) addAxes(); else removeAxes();"> XYZ axes</input>
</div>
</div>
<!-- light & rendermodes -->
<!-- Other controls -->
<div id="rr5" class="row my-0 border interfacePanel">
<div class="col-sm-12 p-1 d-flex align-items-center justify-content-around">
<button class="btn btn-secondary p-1 resp_font" onclick="presenter.saveScreenshot();"><img src="skins/minimal_light/screenshot.png" style="width:min(3vw,33px);"/></br>Screenshot</button>
<div class="border p-1 resp_font">
<label>Annotations:</label></br>
<button id="bt_saveAnn" class="btn btn-warning btn-small py-0 px-1 resp_font" onclick="saveAnnotations();">Export</button>
<button id="bt_loadAnn" class="btn btn-warning btn-small py-0 px-1 resp_font"onclick="loadAnnotations();">Load</button>
</div>
<input type="file" id="i_JSON" accept=".json,.JSON,.Json" style="display:none" onchange="getJSON(this.files);"/>
</div>
</div>
<!-- Other controls -->
<!-- data -->
<div id="rr6" class="row my-0 border interfacePanel" style="overflow-y:auto">
<button class="btn btn-warning btn-small p-0 m-1" onclick="collapseControls()" style="width:20px; height:20px; z-index:10; position:absolute; right:20px;"><h6>⬍</h6></button>
<div class="col-sm-12 p-1">
<ul class="nav nav-tabs resp_font" id="myTab" role="tablist">
<li class="nav-item">
<button class="nav-link active px-1" id="info-tab" data-bs-toggle="tab" data-bs-target="#panel_info" type="button" role="tab">Object</button>
</li>
<li class="nav-item" id="scene-tab-li" style="display:none;">
<button class="nav-link px-1" id="scene-tab" data-bs-toggle="tab" data-bs-target="#panel_scene" type="button" role="tab">Scene</button>
</li>
<li class="nav-item">
<button class="nav-link px-1" id="notes-tab" data-bs-toggle="tab" data-bs-target="#panel_notes" type="button" role="tab">Notes</button>
</li>
<li class="nav-item">
<button class="nav-link px-1" id="views-tab" data-bs-toggle="tab" data-bs-target="#panel_views" type="button" role="tab">Views</button>
</li>
<li class="nav-item">
<button class="nav-link px-1" id="spots-tab" data-bs-toggle="tab" data-bs-target="#panel_spots" type="button" role="tab">Spots</button>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="panel_info" role="tabpanel">meta para data</div>
<div class="tab-pane fade" id="panel_notes" role="tabpanel"><h2>notes<h2></div>
<div class="tab-pane fade" id="panel_scene" role="tabpanel"><h2>elements<h2></div>
<div class="tab-pane fade" id="panel_views" role="tabpanel"><h2>views</h2></div>
<div class="tab-pane fade" id="panel_spots" role="tabpanel"><h2>spots</h2></div>
</div>
</div>
</div>
<!-- data -->
</div>
<!--##############################################RIGHT#############################################-->
<!--########################MODAL HELP PANEL########################-->
<div class="modal fade" id="helpPanel" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header" id="md1_head">
<h5 class="modal-title" id="myLabel">Dynamic Collections Help</h5>
<button type="button" class="close" data-dismiss="modal">
<span>×</span>
</button>
</div>
<div class="modal-body">
<table class="table" style="width:100%">
<tbody>
<tr><td colspan="2" align="center"><h4>Controls</h4></td></tr>
<tr><td>Left Mouse Button + Move</td><td>Rotate 3D Model</td></tr>
<tr><td>CTRL + Left Mouse Button + Move</td><td>Pan 3D Model</td></tr>
<tr><td>Middle Mouse Button + Move</td><td>Pan 3D Model</td></tr>
<tr><td>Mouse Wheel</td><td>Zoom In/Out</td></tr>
<tr><td>Double Click</td><td>Centers ont he clicked point and zoom</td></tr>
<tr><td colspan="3" align="center"><h4>Toolbar</h4></td></tr>
<tr><td align="center"><img src="skins/dark/measure.png" width="30px;"/></td><td>Measurement mode: measure point-to-point distance on the 3D model by clicking on two points.</td></tr>
<tr><td align="center"><img src="skins/dark/pick.png" width="30px;"/></td><td>Point-Picking mode: click on the model to know the XYZ coordinates of that point.</td></tr>
<tr><td align="center"><img src="skins/dark/sections.png" width="30px;"/></td><td>Cut-through Sections: open the section interface to interactively cut the model along the XYZ axes.</td></tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!--########################MODAL HELP PANEL########################-->
</div>
</div>
</body>
<script type="text/javascript">
//----------------------------------------------
var OBJCODE = null;
var SESSION_ID = null;
var ARCHIVE = new Archive();
var COLLECTION = null;
var COLLECTIONMODE = false; //true if the viewer is showing an object from a collection
var OBJECT_ANNOTATIONS = {
"version" : "1.5",
"objectID" : null,
"notes" : "",
"views" : {},
"spots" : {},
"newIndex" : 100,
};
var VIEW_STATE = {
"solid" : false,
"transparency" : false,
"lighting" : true,
"specular" : false,
"lightDir" : [-0.17,-0.17],
};
var MESSAGECHANNEL = null;
var IS_EDITING = false;
//----------------------------------------------
//angle measurement
var angleStage = 0;
var anglePoints = [[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0]];
//----------------------------------------------
//viewer state
var VIEWERSTATE = {};
//----------------------------------------------
var presenter = null;
//----------------------------------------------
function setup3dhop() {
var myScene = {
meshes: {
"sphere" : { url: "./models/sphere.ply" },
"cube" : { url: "./models/cube.ply" },
},
modelInstances: {
},
spots: {
},
trackball: {
type: TurntablePanTrackball,
trackOptions: {
startPhi: 15.0,
startTheta: 15.0,
startDistance: 2.0,
minMaxPhi: [-180, 180],
minMaxTheta: [-90.0, 90.0],
minMaxDist: [0.1, 3.0]
}
},
space: {
centerMode: "scene",
radiusMode: "scene",
cameraNearFar: [0.01, 5.0],
},
config: {
pickedpointColor : [1.0, 0.0, 1.0],
measurementColor : [0.5, 1.0, 0.5],
showClippingPlanes : true,
showClippingBorder : true,
clippingBorderSize : 0.5,
clippingBorderColor : [0.0, 1.0, 1.0]
}
};
if(ARCHIVE.data(OBJCODE,"MEASURE_UNIT") === "mm")
myScene.config.clippingBorderSize = 0.5;
if(ARCHIVE.data(OBJCODE,"MEASURE_UNIT") === "m")
myScene.config.clippingBorderSize = 0.0005;
var modelFiles = getModelFile(OBJCODE);
modelFiles.forEach((item, ind) => {
myScene.meshes["mesh_" + ind] = {};
myScene.meshes["mesh_" + ind].url = modelFiles[ind];
myScene.modelInstances["model_specimen_" +ind] = {};
myScene.modelInstances["model_specimen_" +ind].mesh = "mesh_" + ind;
myScene.modelInstances["model_specimen_" +ind].color = [0.5, 0.5, 0.5];
myScene.modelInstances["model_specimen_" +ind].backfaceColor = [0.5, 0.5, 0.5, 3.0];
myScene.modelInstances["model_specimen_" +ind].specularColor = [0.0, 0.0, 0.0, 256.0];
myScene.modelInstances["model_specimen_" +ind].tags = ["SPECIMEN"];
let transf = ARCHIVE.data(OBJCODE,"TRANSFORM");
if(transf){
myScene.modelInstances["model_specimen_" +ind].transform = JSON.parse(transf);
}
});
//DEBUG DEBUG
// myScene.config.screenshotBaseName = ARCHIVE.data(OBJCODE,"THUMBNAIL_ID");
presenter.setScene(myScene);
//--MEASURE--
presenter._onEndMeasurement = onEndMeasure;
//--MEASURE--
//--POINT PICKING--
presenter._onEndPickingPoint = onEndPick;
//--POINT PICKING--
//--SECTIONS--
sectiontoolInit();
//--SECTIONS--
}
function actionsToolbar(action) {
if(action=='measure') {
presenter.enablePickpointMode(false);
pickpointSwitch(false);
enableAngleMeasurement(false);
presenter.enableMeasurementTool(true);
measureSwitch(true);
setInstructions("pick two points A-B on the object to measure their distance");
}
if(action=='measure_on') {
presenter.enableMeasurementTool(false);
measureSwitch(false);
clearInstructions();
}
else if(action=='pick') {
presenter.enableMeasurementTool(false);
measureSwitch(false);
enableAngleMeasurement(false);
presenter.enablePickpointMode(true);
pickpointSwitch(true);
setInstructions("pick a point A on the object to read its coordinates");
}
else if(action=='pick_on') {
presenter._onEndPickingPoint = onEndPick;
presenter.enablePickpointMode(false);
pickpointSwitch(false);
clearInstructions();
}
else if(action=='angle') {
presenter.enableMeasurementTool(false);
measureSwitch(false);
presenter.enablePickpointMode(false);
pickpointSwitch(false);
enableAngleMeasurement(true);
setInstructions("pick three points A-O-B on the object to calculate the angle AÔB");
}
else if(action=='angle_on') {
enableAngleMeasurement(false);
clearInstructions();
}
else if(action=='sections') {
sectiontoolReset();
sectiontoolSwitch(true);
}
else if(action=='sections_on') {
sectiontoolReset();
sectiontoolSwitch(false);
}
}
//--------------------------------------------------------------------------------------------
function enableAngleMeasurement(state){
if(state){
jQuery('#angle').css("visibility", "hidden");
jQuery('#angle_on').css("visibility", "visible");
jQuery('#angle-box').fadeIn().css("display","table");
anchorAnglePanel();
resetAngle();
presenter._onEndPickingPoint = onAnglePick;
presenter.enablePickpointMode(true);
}
else{
jQuery('#angle').css("visibility", "visible");
jQuery('#angle_on').css("visibility", "hidden");
jQuery('#angle-box').css("display","none");
jQuery('#angle-output').html("0.0°");
presenter.deleteEntity("angleP");
presenter.deleteEntity("angleL");
presenter.deleteEntity("angleV");
presenter.enablePickpointMode(false);
presenter._onEndPickingPoint = onEndPick;
resetAngle();
}
}
function anchorAnglePanel(){
if (jQuery('#angle-box')[0] && jQuery('#angle')[0])
{
jQuery('#angle-box').css('left', (jQuery('#angle').position().left + jQuery('#angle').width() + jQuery('#toolbar').position().left + 5));
jQuery('#angle-box').css('top', (jQuery('#angle').position().top + jQuery('#toolbar').position().top));
}
}
//--------------------------------------------------------------------------------------------
var addGrid = addBaseGrid; //starting default
var sceneBB = [-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE];
function changeGrid() {
var GG = document.getElementById('i_grid').selectedIndex;
if (GG===0)
addGrid = removeGrid;
if (GG===1)
addGrid = addBaseGrid;
if (GG===2)
addGrid = addBoxGrid;
if (GG===3)
addGrid = addBBGrid;
removeGrid();
addGrid();
}
function computeSceneBB() {
for(inst in presenter._scene.modelInstances){
let bb = getBBox(inst);
if(bb[0] > sceneBB[0]) sceneBB[0] = bb[0];
if(bb[1] > sceneBB[1]) sceneBB[1] = bb[1];
if(bb[2] > sceneBB[2]) sceneBB[2] = bb[2];
if(bb[3] < sceneBB[3]) sceneBB[3] = bb[3];
if(bb[4] < sceneBB[4]) sceneBB[4] = bb[4];
if(bb[5] < sceneBB[5]) sceneBB[5] = bb[5];
}
}
function computeEncumbrance() {
computeSceneBB();
var gStep = 1.0;
if(ARCHIVE.data(OBJCODE,"MEASURE_UNIT") === "mm")
gStep = 10.0;
else if(ARCHIVE.data(OBJCODE,"MEASURE_UNIT") === "m")
gStep = 0.01;
var encumbrance = [0.0, 0.0, 0.0];
encumbrance[0] = Math.trunc(Math.ceil((sceneBB[0]-sceneBB[3])/gStep)+1);
encumbrance[1] = Math.trunc(Math.ceil((sceneBB[1]-sceneBB[4])/gStep)+1);
encumbrance[2] = Math.trunc(Math.ceil((sceneBB[2]-sceneBB[5])/gStep)+1);
ARCHIVE.objects[OBJCODE].ENCUMBRANCE = encumbrance[0] + " x " + encumbrance[1] + " x " + encumbrance[2] + " cm";
fillMetadataPanel();
}
function removeGrid() {
// base grid
presenter.deleteEntity("gridBase");
// box grid
presenter.deleteEntity("gridBox");
// bb grid
presenter.deleteEntity("gridBB");
}
function addBaseGrid() {
computeSceneBB();
var rad = 1.0 / presenter.sceneRadiusInv;
var XC = (sceneBB[0] + sceneBB[3]) / 2.0;
var YC = sceneBB[4];
var ZC = (sceneBB[2] + sceneBB[5]) / 2.0;
var gStep = 1.0;
if(ARCHIVE.data(OBJCODE,"MEASURE_UNIT") === "mm")
gStep = 10.0;
else if(ARCHIVE.data(OBJCODE,"MEASURE_UNIT") === "m")
gStep = 0.01;
var numDivMaj = Math.floor(rad/gStep);
var linesBuffer;
// major
var gridBase;
linesBuffer = [];
for (gg = -numDivMaj; gg <= numDivMaj; gg+=1)
{
linesBuffer.push([XC + (gg*gStep), YC, ZC + (-gStep*numDivMaj)]);
linesBuffer.push([XC + (gg*gStep), YC, ZC + ( gStep*numDivMaj)]);
linesBuffer.push([XC + (-gStep*numDivMaj), YC, ZC + (gg*gStep)]);
linesBuffer.push([XC + ( gStep*numDivMaj), YC, ZC + (gg*gStep)]);
}
gridBase = presenter.createEntity("gridBase", "lines", linesBuffer);
gridBase.color = [0.9, 0.9, 0.9, 1.0];
gridBase.zOff = 0.0;
presenter.repaint();
}
function addBoxGrid() {
computeSceneBB();
var Xsteps,Ysteps,Zsteps,ii;
var XC = (sceneBB[0] + sceneBB[3]) / 2.0;
var YC = (sceneBB[1] + sceneBB[4]) / 2.0;
var ZC = (sceneBB[2] + sceneBB[5]) / 2.0;
var gStep = 1.0;
if(ARCHIVE.data(OBJCODE,"MEASURE_UNIT") === "mm")
gStep = 10.0;
else if(ARCHIVE.data(OBJCODE,"MEASURE_UNIT") === "m")
gStep = 0.01;
Xsteps = Math.trunc(Math.ceil((sceneBB[0]-sceneBB[3])/gStep)+1);
Ysteps = Math.trunc(Math.ceil((sceneBB[1]-sceneBB[4])/gStep)+1);
Zsteps = Math.trunc(Math.ceil((sceneBB[2]-sceneBB[5])/gStep)+1);
var boxG = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0];
boxG[0] = XC + ((Xsteps/2.0) * gStep);
boxG[1] = YC + ((Ysteps/2.0) * gStep);
boxG[2] = ZC + ((Zsteps/2.0) * gStep);
boxG[3] = XC - ((Xsteps/2.0) * gStep);
boxG[4] = YC - ((Ysteps/2.0) * gStep);
boxG[5] = ZC - ((Zsteps/2.0) * gStep);
var gridBox;
var linesBuffer = [];
//--------------------X
for (ii=0; ii<=Ysteps; ii+=1)
{
linesBuffer.push([boxG[3], boxG[4]+(gStep*ii), boxG[2]]);
linesBuffer.push([boxG[3], boxG[4]+(gStep*ii), boxG[5]]);
linesBuffer.push([boxG[0], boxG[4]+(gStep*ii), boxG[2]]);
linesBuffer.push([boxG[0], boxG[4]+(gStep*ii), boxG[5]]);
}
for (ii=0; ii<=Zsteps; ii+=1)
{
linesBuffer.push([boxG[3], boxG[1], boxG[5]+(gStep*ii)]);
linesBuffer.push([boxG[3], boxG[4], boxG[5]+(gStep*ii)]);
linesBuffer.push([boxG[0], boxG[1], boxG[5]+(gStep*ii)]);
linesBuffer.push([boxG[0], boxG[4], boxG[5]+(gStep*ii)]);
}
//--------------------Y
for (ii =0; ii <= Xsteps; ii+=1)
{
linesBuffer.push([boxG[3]+(gStep*ii), boxG[4], boxG[2]]);
linesBuffer.push([boxG[3]+(gStep*ii), boxG[4], boxG[5]]);
linesBuffer.push([boxG[3]+(gStep*ii), boxG[1], boxG[2]]);
linesBuffer.push([boxG[3]+(gStep*ii), boxG[1], boxG[5]]);
}
for (ii = 0; ii <= Zsteps; ii+=1)
{
linesBuffer.push([boxG[0], boxG[4], boxG[5]+(gStep*ii)]);
linesBuffer.push([boxG[3], boxG[4], boxG[5]+(gStep*ii)]);
linesBuffer.push([boxG[0], boxG[1], boxG[5]+(gStep*ii)]);
linesBuffer.push([boxG[3], boxG[1], boxG[5]+(gStep*ii)]);
}
//--------------------Z
for (ii =0; ii <= Xsteps; ii+=1)
{
linesBuffer.push([boxG[3]+(gStep*ii), boxG[1], boxG[5]]);
linesBuffer.push([boxG[3]+(gStep*ii), boxG[4], boxG[5]]);
linesBuffer.push([boxG[3]+(gStep*ii), boxG[1], boxG[2]]);
linesBuffer.push([boxG[3]+(gStep*ii), boxG[4], boxG[2]]);
}
for (ii = 0; ii <= Ysteps; ii+=1)
{
linesBuffer.push([boxG[0], boxG[4]+(gStep*ii), boxG[5]]);
linesBuffer.push([boxG[3], boxG[4]+(gStep*ii), boxG[5]]);
linesBuffer.push([boxG[0], boxG[4]+(gStep*ii), boxG[2]]);
linesBuffer.push([boxG[3], boxG[4]+(gStep*ii), boxG[2]]);
}
gridBox = presenter.createEntity("gridBox", "lines", linesBuffer);
gridBox.color = [0.8, 0.8, 0.8, 0.5];
gridBox.zOff = 0.0;
gridBox.useTransparency = true;
presenter.repaint();
}
function addBBGrid() {
var rad = (1.0 / presenter.sceneRadiusInv) * 1.0;
var XC = 0.0;
var YC = 0.0;
var ZC = 0.0;
var gStep = 1.0;
if(ARCHIVE.data(OBJCODE,"MEASURE_UNIT") === "mm")
gStep = 10.0;
else if(ARCHIVE.data(OBJCODE,"MEASURE_UNIT") === "m")
gStep = 0.01;
var numDiv = Math.floor(rad / gStep);
var linesBuffer = [];
var gridBB;
for (gg = -numDiv; gg <= numDiv; gg+=1)
{
linesBuffer.push([XC + (gg*gStep), YC + (-gStep*numDiv), ZC]);
linesBuffer.push([XC + (gg*gStep), YC + ( gStep*numDiv), ZC]);
linesBuffer.push([XC + (-gStep*numDiv), YC + (gg*gStep), ZC]);
linesBuffer.push([XC + ( gStep*numDiv), YC + (gg*gStep), ZC]);
}
gridBB = presenter.createEntity("gridBB", "lines", linesBuffer);
gridBB.color = [0.7, 0.7, 0.7, 0.5];
gridBB.zOff = 0.5;
gridBB.useTransparency = true;
presenter.repaint();
}
function addAxes(){
var rad = (1.0 / presenter.sceneRadiusInv)/2.0;
var linesBuffer;
var point, tpoint;
point = [rad, 0.0, 0.0, 1.0]
tpoint = SglMat4.mul4(presenter._scene.modelInstances["model_specimen_0"].transform.matrix, point);
linesBuffer = [];
linesBuffer.push([0, 0, 0]);
linesBuffer.push([tpoint[0], tpoint[1], tpoint[2]]);
var axisX = presenter.createEntity("XXaxis", "lines", linesBuffer);
axisX.color = [1.0, 0.2, 0.2, 1.0];
axisX.zOff = 0.0;
point = [0.0, rad, 0.0, 1.0]
tpoint = SglMat4.mul4(presenter._scene.modelInstances["model_specimen_0"].transform.matrix, point);
linesBuffer = [];
linesBuffer.push([0, 0, 0]);
linesBuffer.push([tpoint[0], tpoint[1], tpoint[2]]);
var axisY = presenter.createEntity("YYaxis", "lines", linesBuffer);
axisY.color = [0.2, 1.0, 0.2, 1.0];
axisY.zOff = 0.0;
point = [0.0, 0.0, rad, 1.0]
tpoint = SglMat4.mul4(presenter._scene.modelInstances["model_specimen_0"].transform.matrix, point);
linesBuffer = [];
linesBuffer.push([0, 0, 0]);
linesBuffer.push([tpoint[0], tpoint[1], tpoint[2]]);
var axisZ = presenter.createEntity("ZZaxis", "lines", linesBuffer);
axisZ.color = [0.2, 0.2, 1.0, 1.0];
axisZ.zOff = 0.0;
presenter.repaint();
}
function removeAxes(){
presenter.deleteEntity("XXaxis");
presenter.deleteEntity("YYaxis");
presenter.deleteEntity("ZZaxis");
}
function getBBox(instance) {
var mname = presenter._scene.modelInstances[instance].mesh;
var vv = presenter._scene.meshes[mname].renderable.mesh.basev;
var bbox = [-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE];
var point,tpoint;
for(var vi=1; vi<(vv.length / 3); vi++){
point = [vv[(vi*3)+0], vv[(vi*3)+1], vv[(vi*3)+2], 1.0]
tpoint = SglMat4.mul4(presenter._scene.modelInstances[instance].transform.matrix, point);
if(tpoint[0] > bbox[0]) bbox[0] = tpoint[0];
if(tpoint[1] > bbox[1]) bbox[1] = tpoint[1];
if(tpoint[2] > bbox[2]) bbox[2] = tpoint[2];
if(tpoint[0] < bbox[3]) bbox[3] = tpoint[0];
if(tpoint[1] < bbox[4]) bbox[4] = tpoint[1];
if(tpoint[2] < bbox[5]) bbox[5] = tpoint[2];
}
return bbox;
}
//---------------------------------------------------------------------------------------
function resizeLightController(){
var lightControllerCanvas = document.getElementById("lightcontroller_canvas");
var dim = Math.min(150, Math.min(lightControllerCanvas.parentElement.clientWidth,lightControllerCanvas.parentElement.clientHeight));
lightControllerCanvas.width = dim;
lightControllerCanvas.height = dim;
}
function clickLightController(event) {
var lightControllerCanvas = document.getElementById("lightcontroller_canvas");
var cwidth = lightControllerCanvas.width;
var cheight = lightControllerCanvas.height;
var midpoint = [Math.floor(cwidth/2.0),Math.floor(cheight/2.0)];
var radius = Math.min(midpoint[0],midpoint[1]);
var XX = event.offsetX - midpoint[0];
var YY = event.offsetY - midpoint[1];
// check inside circle
if((XX*XX + YY*YY) < ((radius)*(radius))) {
var lx = (XX / radius)/2.0;
var ly = (YY / radius)/2.0;
VIEW_STATE.lightDir = [lx,ly];
presenter.rotateLight(VIEW_STATE.lightDir[0],-VIEW_STATE.lightDir[1]); // inverted y
updateLightController(VIEW_STATE.lightDir[0],VIEW_STATE.lightDir[1]);
(event.touches) ? lightControllerCanvas.addEventListener("touchmove", clickLightController, false) : lightControllerCanvas.addEventListener("mousemove", clickLightController, false);
}
}
function updateLightController(xx,yy) {
var lightControllerCanvas = document.getElementById("lightcontroller_canvas");
var cwidth = lightControllerCanvas.width;
var cheight = lightControllerCanvas.height;
var midpoint = [Math.floor(cwidth/2.0),Math.floor(cheight/2.0)];
var radius = Math.min(midpoint[0],midpoint[1]);
var context = lightControllerCanvas.getContext("2d");
context.clearRect(0, 0, cwidth, cheight);
context.beginPath();
context.arc(midpoint[0], midpoint[1], radius, 0, 2 * Math.PI, false);
var grd=context.createRadialGradient(midpoint[0]+(xx*(radius-3)*2),midpoint[1]+(yy*(radius-3)*2),3,midpoint[0], midpoint[1],radius);
grd.addColorStop(0,"yellow");
grd.addColorStop(1,"black");
context.fillStyle = grd;
context.fill();
context.lineWidth = 1;
context.strokeStyle = 'black';
context.stroke();
presenter.ui.postDrawEvent();
}
function setupLightController() {
// touch and click management
var lightControllerCanvas = document.getElementById("lightcontroller_canvas");
lightControllerCanvas.addEventListener("touchstart", clickLightController, false);
lightControllerCanvas.addEventListener("mousedown", clickLightController, false);
var canvas = document.getElementById("draw-canvas");
canvas.addEventListener("mouseup", function () {
lightControllerCanvas.removeEventListener("mousemove", clickLightController, false);
lightControllerCanvas.removeEventListener("touchmove", clickLightController, false);
}, false);
document.addEventListener("mouseup", function () {
lightControllerCanvas.removeEventListener("mousemove", clickLightController, false);
lightControllerCanvas.removeEventListener("touchmove", clickLightController, false);
}, false);
}
//---------------------------------------------------------------------------------------
function setInstructions(text){
$('#panel_instructions').html(text);
}
function clearInstructions(){
$('#panel_instructions').html("");
}
//---------------------------------------------------------------------------------------
function onEndMeasure(measure) {
var clampTo = (ARCHIVE.data(OBJCODE,"MEASURE_UNIT") == "m")? 3 : 2;
$('#measure-output').html(measure.toFixed(clampTo) + ARCHIVE.data(OBJCODE,"MEASURE_UNIT"));
}
//---------------------------------------------------------------------------------------
function onEndPick(point) {
var clampTo = (ARCHIVE.data(OBJCODE,"MEASURE_UNIT") == "m")? 3 : 2;
//undo object transform
var opoint = [point[0], point[1], point[2], 1.0];
var tpoint = SglMat4.mul4(SglMat4.inverse(presenter._scene.modelInstances["model_specimen_0"].transform.matrix), opoint);
var x = tpoint[0].toFixed(clampTo);
var y = tpoint[1].toFixed(clampTo);
var z = tpoint[2].toFixed(clampTo);
$('#pickpoint-output').html("[ "+x+" , "+y+" , "+z+" ]");
}
//---------------------------------------------------------------------------------------
function onAnglePick(point) {
if(angleStage == 3) angleStage = 0; //reset for new measure
anglePoints[angleStage] = [point[0],point[1],point[2]];
angleStage++;
displayAngle();
if(angleStage == 3) displayAngleEnd();
}
function displayAngle(){
var pointsBuffer = [];
var linesBuffer = [];
var ii = 0;
for(ii=0; ii<angleStage; ii++){
pointsBuffer.push(anglePoints[ii]);
}
for(ii=0; ii<angleStage-1; ii++){
linesBuffer.push(anglePoints[ii]);
linesBuffer.push(anglePoints[ii+1]);
}
var angleP = presenter.createEntity("angleP", "points", pointsBuffer);
angleP.color = [0.2, 0.3, 0.9, 1.0];
angleP.zOff = 0.001;
var angleL = presenter.createEntity("angleL", "lines", linesBuffer);
angleL.color = [0.2, 0.3, 0.9, 1.0];
angleL.zOff = 0.001;
presenter.deleteEntity("angleV");
presenter.repaint();
}
function displayAngleEnd(){
var v1 = SglVec3.normalize(SglVec3.sub(anglePoints[0], anglePoints[1]));
var v2 = SglVec3.normalize(SglVec3.sub(anglePoints[2], anglePoints[1]));
var angle = sglRadToDeg(Math.acos(SglVec3.dot(v1,v2)));
$('#angle-output').html(angle.toFixed(2) + "°");
var len = 0.75 * Math.min(SglVec3.length(SglVec3.sub(anglePoints[0], anglePoints[1])), SglVec3.length(SglVec3.sub(anglePoints[2], anglePoints[1])));
var triBuffer = [];
triBuffer.push(anglePoints[1]);
triBuffer.push(SglVec3.add(SglVec3.muls(v1,len),anglePoints[1]));
triBuffer.push(SglVec3.add(SglVec3.muls(v2,len),anglePoints[1]));
var angleV = presenter.createEntity("angleV", "triangles", triBuffer);
angleV.color = [0.2, 0.5, 0.7, 0.3];
angleV.zOff = 0.01;
angleV.useTransparency = true;
}
function resetAngle(){
angleStage = 0;
anglePoints = [[0.0,0.0,0.0],[0.0,0.0,0.0],[0.0,0.0,0.0]];
}
//---------------------------------------------------------------------------------------
function toolsReset(){
presenter.enablePickpointMode(false);
pickpointSwitch();
presenter.enableMeasurementTool(false);
measureSwitch();
jQuery('#angle').css("visibility", "visible");
jQuery('#angle_on').css("visibility", "hidden");
jQuery('#angle-box').css("display","none");
jQuery('#angle-output').html("0.0 °");
presenter.deleteEntity("angleP");
presenter.deleteEntity("angleL");
presenter.deleteEntity("angleV");
sectiontoolReset();
sectiontoolSwitch(false);
clearInstructions();
}
//---------------------------------------------------------------------------------------
function resetViewState(field, value){
VIEW_STATE["solid"] = false;
VIEW_STATE["transparency"] = false;
VIEW_STATE["lighting"] = true;
VIEW_STATE["specular"] = false;
VIEW_STATE["lightDir"] = [-0.17,-0.17];
displayViewState();
}
function updateViewState(field, value){
VIEW_STATE[field] = value;
displayViewState();
}
function displayViewState(){
$('#i_solidColor').bootstrapToggle((VIEW_STATE.solid)?'on':'off', true);
presenter.setInstanceSolidColor('SPECIMEN', VIEW_STATE.solid, false);
$('#i_transparency').bootstrapToggle((VIEW_STATE.transparency)?'on':'off', true);
presenter.setInstanceTransparency('SPECIMEN', VIEW_STATE.transparency, false);
$('#i_useLighting').bootstrapToggle((VIEW_STATE.lighting)?'on':'off', true);
presenter.enableSceneLighting(VIEW_STATE.lighting);
$('#i_useSpecular').bootstrapToggle((VIEW_STATE.specular)?'on':'off', true);
var newSpecular;
if(VIEW_STATE.specular)
newSpecular = [0.3,0.3,0.3,256.0];
else
newSpecular = [0.0,0.0,0.0,256.0];
for (inst in presenter._scene.modelInstances){
presenter._scene.modelInstances[inst].specularColor = newSpecular;
}
presenter.rotateLight(VIEW_STATE.lightDir[0],-VIEW_STATE.lightDir[1]); // inverted y
updateLightController(VIEW_STATE.lightDir[0],VIEW_STATE.lightDir[1]);
presenter.repaint();
}
function updateOrtho(value){
if(value){
presenter.setCameraOrthographic();
$('#i_orthoCamera')[0].checked = true;
}
else {
presenter.setCameraPerspective();
$('#i_orthoCamera')[0].checked = false;
}
}
//---------------------------------------------------------------------------------------
function showHelp(){
$('#helpPanel').modal("show");
}
//---------------------------------------------------------------------------------------
function home(){
presenter.resetTrackball();
// put back light as we want it, as resetTrackball() function resets it
presenter.rotateLight(VIEW_STATE.lightDir[0],-VIEW_STATE.lightDir[1]); // inverted y
updateLightController(VIEW_STATE.lightDir[0],VIEW_STATE.lightDir[1]);
}
//---------------------------------------------------------------------------------------
function viewFrom(direction){
var distance = 1.3;
switch(direction) {
case "front":
presenter.animateToTrackballPosition([0.0, 0.0, 0.0, 0.0, 0.0, distance]);
break;
case "back":
presenter.animateToTrackballPosition([180.0, 0.0, 0.0, 0.0, 0.0, distance]);
break;
case "top":
presenter.animateToTrackballPosition([0.0, 90.0, 0.0, 0.0, 0.0, distance]);
break;
case "bottom":
presenter.animateToTrackballPosition([0.0, -90.0, 0.0, 0.0, 0.0, distance]);
break;
case "left":
presenter.animateToTrackballPosition([270.0, 0.0, 0.0, 0.0, 0.0, distance]);
break;
case "right":
presenter.animateToTrackballPosition([90.0, 0.0, 0.0, 0.0, 0.0, distance]);
break;
}
}
//---------------------------------------------------------------------------------------
function onTrackballUpdate(trackState){
updateCube(-trackState[0], -trackState[1]);
updateGrid(trackState);