-
Notifications
You must be signed in to change notification settings - Fork 6
/
mcc2_3js_r79.html
1961 lines (1570 loc) · 63.6 KB
/
mcc2_3js_r79.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
<!-- js_iteration_1/mcc2_3js_r79.html -->
<html>
<head>
<meta charset="utf-8"/>
</head>
<style>
.stat-panel{
position:fixed;
top:0px;
right:0px;
width:100px;
/* z-index:1000; */
}
.mycanvas {
/* width: 100%; */
/* Will not work ion canvas, because the size is later changed by JS code.
Note that "width=" attriute and css width are independent:
one is the pixels resolution and the other one is appearance only,
regarless of the actual pixels (resolution). */
}
</style>
<body>
<canvas class=mycanvas id="my_canvas"></canvas>
<!-- To show the histogram: Uncomment the following <div> to reveal the histogram graph, also uncomment the line that says: //hist_delayed(); -->
<div id="chart_div" class="stat-panel" no_style="width: 900px; height: 500px;">
</div>
This file uses ImpliSolid's Geometry class. (unlike <a href="mcc2_3js.html">mcc2_3js.html</a>).
<br/>
Press SHIFT to animate. *
</body>
<!--
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r77/three.js">
</script> -->
<!--script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r73/three.js">
</script-->
<!--<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r71/three.js">
</script>-->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r79/three.js">
</script>
<!--script type="text/javascript" src="./three_r79.js">
</script-->
<!-- <script type="text/javascript" src="./three-r77.js"></script> -->
<!--script type="text/javascript" src="https://raw.githubusercontent.com/mrdoob/three.js/69079243426506ed86d0d0ea71b4fdda9dbb2f88/examples/js/controls/OrbitControls.js"></script
-->
<!-- Refused to execute script '...' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
-->
<script>
// Default (mock) OrbitControl to void breaking the program if the orbitcontrol is not found.
THREE.OrbitControls = function() {
this.target = new THREE.Vector3();
this.addEventListener = function(){};
}
</script>
<script type="text/javascript" src="../examples/js-lib/OrbitControls_r79-copy.js"></script>
<script>
function my_assert(cond, text){
if (!cond) {
console.error("ASSERT FAILED: ");
if(text)
console.log(text);
}
}
function my_assert(cond, message) {
if (!cond) {
if (message)
console.error("assert failed: ", message);
else
console.error("assert failed");
throw new Error("assert failed: ", message);
}
}
assert = my_assert;
function _expect(cond, message) {
if (!cond) {
console.error(message);
}
}
</script>
<!-- function callMultipleTimes (implisolid_, update_callback, burst_count, interval_msec): -->
<script type="text/javascript" src="../js_iteration_2/js/call_multiple_times.js"></script>
<!--script type="text/javascript" src="./legacy/geometry77.js"></script-->
<script type="text/javascript" src="../js_iteration_2/geometry79.js"></script>
<!--<script type="text/javascript" src="../js_iteration_2/js/geometry73.js"></script>-->
<!-- <script type="text/javascript" src="../js_iteration_2/bbox_calculations.js"></script> -->
<script type="text/javascript" src="../js_iteration_2/implisolid_main.js"></script>
<script type="text/javascript" src="../examples/js-lib/example_objects.js"></script>
<script type="text/javascript" src="../js_iteration_2/js/js_utils.js"></script> <!-- stuff used by pointset_utils.js -->
<script type="text/javascript" src="../js_iteration_2/js/pointset_utils.js"></script>
<script type="text/javascript" src="../js_iteration_2/js/arrow_utils.js"></script>
<script type="text/javascript" src="../examples/js-lib/example_materials.js"></script>
<script type="text/javascript" src="../examples/js-lib/performance_graphs.js"></script>
<script type="text/javascript" src="../examples/js-lib/misc_props.js"></script>
<!-- Graph -->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<!--<div id="chart_div" style="width: 900px; height: 500px;"></div>-->
<script>
'use strict';
const THREEJS_R71 = "r71";
const THREEJS_R77 = "r77";
const THREEJS_R79 = "r79";
const threejs_rev = THREEJS_R79;
var produce_object;
var main;
</script>
<!--
<script>
// This method creates an object which is identical to ImpliSolid object in implisolid.js
// Todo: merge these two and remove this.
// polygoniser_service
function __init_polygonizer()
{
//too late for pre-run
//Module.preRun.push(letmeknow,memoryprofiler_add_hooks, letmeknow = function (){console.log("ok");});
//Module={preRun:[letmeknow, memoryprofiler_add_hooks]};
//main = Module.cwrap('main', 'number', []);
// produce_object = Module.cwrap('produce_object_old2', null, ['number', 'number', 'number', 'number', 'number']);
var s_service={};
s_service.build_geometry = Module.cwrap('build_geometry', null, [ 'string', 'string']);
s_service.get_v_size = Module.cwrap('get_v_size', 'number', []);
s_service.get_f_size = Module.cwrap('get_f_size', 'number', []);
s_service.get_v = Module.cwrap('get_v', null, ['number']);
s_service.get_f = Module.cwrap('get_f', null, ['number']);
s_service.get_v_ptr = Module.cwrap('get_v_ptr', 'number', []);
s_service.get_f_ptr = Module.cwrap('get_f_ptr', 'number', []);
s_service.finish_geometry = Module.cwrap('finish_geometry', null, []);
s_service.set_object = Module.cwrap('set_object', 'number', ['string', 'number']);
s_service.unset_object = Module.cwrap('unset_object', 'number', ['number']);
s_service.set_x = Module.cwrap('set_x', 'number', ['number', 'number']);
s_service.unset_x = Module.cwrap('unset_x', null, []);
s_service.calculate_implicit_values = Module.cwrap('calculate_implicit_values', null, []);
s_service.get_values_ptr = Module.cwrap('get_values_ptr', 'number', []);
s_service.get_values_size = Module.cwrap('get_values_size', 'number', []);
s_service.calculate_implicit_gradients = Module.cwrap('calculate_implicit_gradients', null, []);
s_service.get_gradients_ptr = Module.cwrap('get_gradients_ptr', 'number', []);
s_service.get_gradients_size = Module.cwrap('get_gradients_size', 'number', []);
s_service.get_pointset_ptr = Module.cwrap('get_pointset_ptr', 'number', ['string']);
s_service.get_pointset_size = Module.cwrap('get_pointset_size', 'number', ['string']);
s_service.about = Module.cwrap('about', null, []);
s_service.init = function(){ s_service.needs_deallocation = false; }
s_service.finish_with = function (){
//after the last round.
if(!implisolid_.needs_deallocation)
console.error("cannot `finish_geometry()`. Geometry not produced.");
//todo: try-catch
//d(1);
implisolid_.finish_geometry();
implisolid_.needs_deallocation = false;
//todo(sohail): Why implisolid_ is used here? We should use 'this'.
}
s_service.set_vect = function (float32Array){
if (float32Array.length % 3 != 0) {console.error("bad input array");};
var nverts = float32Array.length / 3;
const _FLOAT_SIZE = Float32Array.BYTES_PER_ELEMENT;
var verts_space = Module._malloc(_FLOAT_SIZE*3*nverts);
Module.HEAPF32.subarray(verts_space/_FLOAT_SIZE, verts_space/_FLOAT_SIZE + 3*nverts).set(float32Array);
var result = this.set_x(verts_space, nverts);
console.log("set_x() result: "+result);
if (!result) {console.error("Something went wrong: ", result);}
Module._free( verts_space );
}
s_service={}; //destroying. for test
s_service.__update_geometry = function(geometry, ignoreNormals) {
// refactor as: get_latest_vf()
var implicit_service = this;
const _FLOAT_SIZE = Float32Array.BYTES_PER_ELEMENT;
const _INT_SIZE = Uint32Array.BYTES_PER_ELEMENT;
const POINTS_PER_FACE = 3;
var nverts = implicit_service.get_v_size();
var nfaces = implicit_service.get_f_size();
if(nfaces > 0){
var verts_address = implicit_service.get_v_ptr();
var faces_address = implicit_service.get_f_ptr();
var verts = Module.HEAPF32.subarray(
verts_address/_FLOAT_SIZE,
verts_address/_FLOAT_SIZE + 3*nverts);
var faces = Module.HEAPU32.subarray(
faces_address/_INT_SIZE,
faces_address/_INT_SIZE + nfaces * POINTS_PER_FACE);
}
else{
console.log("empty implicit");
var verts = new Float32Array([0,0,0, 1,0,0, 1,1,0, 0,1,0, 0,0,1, 1,0,1, 1,1,1, 0,1,1 ]);
var faces = new Uint32Array([0,1,2, 0,2,3, 0,4,5, 0,5,1, 1,5,6, 1,6,2, 2,6,3, 3,6,7, 4,5,6, 5,6,7]);
}
return geometry.update_geometry1(verts, faces, ignoreNormals, false);
};
s_service.make_normals_into_geometry = function(geom, mp5_str, x, ignore_root_matrix) {
var implicit_service = s_service;
const _FLOAT_SIZE = Float32Array.BYTES_PER_ELEMENT;
var result1 =
implicit_service.set_object(mp5_str, ignore_root_matrix);
console.log("SET_OBJECT() RESULTS:", result1);
implicit_service.set_vect(x); // overhead
implicit_service.calculate_implicit_gradients(true); // Why TRUE doe snot have any effect?
var ptr = implicit_service.get_gradients_ptr();
var ptr_len = implicit_service.get_gradients_size();
var gradients = Module.HEAPF32.subarray(ptr/_FLOAT_SIZE, ptr/_FLOAT_SIZE + ptr_len);
//console.log("grad len = " + ptr_len+ " grad = " + gradients); // x 4
//for( var i = 0 ; i < ptr_len; i++) {
// gradients[i] += Math.random() * 0.2;
//}
/*
for( var i = 0 ; i < ptr_len; i++) {
gradients[i] += (Math.random()*2-1) * 0.2*10;
}
*/
/*
for( var i = 0 ; i < ptr_len/3; i++) {
var x = gradients[i * 3 + 0 ];
var y = gradients[i * 3 + 1 ];
var z = gradients[i * 3 + 2 ];
gradients[i * 3 + 0 ] = z;
gradients[i * 3 + 1 ] = x;
gradients[i * 3 + 2 ] = y;
}
*/
geom.update_normals_from_array(gradients);
implicit_service.unset_x();
var result1 =
implicit_service.unset_object(1);
console.log("UNSET_OBJ() RESULTS:", result1);
};
s_service={}; //destroying. for test
s_service.init();
//console.log("ok");
//return s_service;
return {};
}
</script>
-->
<script>
'use strict';
</script>
<script>
</script>
<script>
'use strict'; //'use asm';
//Version 1 has flaws: _free()s before returning the verts.
//var CALL_VERSION = 2; //1 or 2
const VERBOSE = false;
var global_time = 0;
'use strict';
var global_verts_copy = null;
var global_gradients_copy = null;
// const MESH_SCALE = 300/10;
const MESH_SCALE = 1.0;
const ARROWS_COUNT = 20*10;
//globals.global_mp5 = "***";
// some code moved into js_utils.js
/*
Three ways:
1- make_geometry_oldold()
2- make_geometry_old1()
3- make_geometry_new2()
*/
/*
function ___make_geometry_new2(implisolid_, shape_json, polygonization_json, re_allocate_buffers, geom_callback)
{
//console.log(shape_json);
//console.log(polygonization_json);
// reusable_geometry =null, is not used;
var startTime = new Date();
if(implisolid_.needs_deallocation) { // Remove data from last round.
//console.log("implisolid_.needs_deallocation " + implisolid_.needs_deallocation);
//d(1);
implisolid_.finish_geometry();
implisolid_.needs_deallocation = false;
}
else{
//console.error("Should not get here");
//implisolid_.finish_geometry();
//implisolid_.needs_deallocation = false;
}
//implisolid_.finish_geometry();
//d("2 G");
//28*2 --> 27 sec 28->3.75--7 msec?
//////////////////////
//var mp5_json = "";
//var mc_properties_json = "";
//implisolid_.build_geometry( 28, mc_properties, "sphere", subjective_time);
//implisolid_.build_geometry( mp5_json , mc_properties_json);
try{
implisolid_.build_geometry( shape_json , polygonization_json);
} catch(e) {
console.error(e);
Module={}; // avoids calling Module.dynCall_vii(), etc.
}
//implicit_double_mushroom center will be zero.
implisolid_.needs_deallocation = true;
var nverts = implisolid_.get_v_size();
var nfaces = implisolid_.get_f_size();
if(VERBOSE){
console.log(nverts);
}
var verts_address = implisolid_.get_v_ptr();
var faces_address = implisolid_.get_f_ptr();
//no need to free anymore!
const _FLOAT_SIZE = Float32Array.BYTES_PER_ELEMENT;
var verts = Module.HEAPF32.subarray(verts_address/_FLOAT_SIZE, verts_address/_FLOAT_SIZE + 3*nverts);
const _INT_SIZE = Uint32Array.BYTES_PER_ELEMENT;
var faces = Module.HEAPU32.subarray(faces_address/_INT_SIZE, faces_address/_INT_SIZE + 3*nfaces);
var geom = geom_callback(verts,faces, re_allocate_buffers);
var endTime = new Date();
var timeDiff = endTime - startTime;
//console.log("Time: "+timeDiff+ " msec.");
report_time(timeDiff, function(){hist();});
return geom;
}
*/
var geom_callback__1 = function (verts, faces, re_allocate_buffers) {
/*
// Uncomment for visualising the mesh's normals when set according to Implicit gradients.
var gradients = prepare_gradients1(implisolid_, shape_json, verts);
global_verts_copy = clone_array_float(verts);
global_gradients_copy = clone_array_float(gradients);
*/
//verts[2] -= 0.1;
//verts[2 + nverts*3-3] += 0.3;
/*
//var geom = new WGeometry77(verts, faces);
//var geom = new MyBufferGeometry77(verts, faces, re_allocate_buffers);
if(threejs_rev === THREEJS_R71) {
var geom = new LiveBufferGeometry71(verts, faces, re_allocate_buffers);
} else if(threejs_rev === THREEJS_R77) {
var geom = new MyBufferGeometry77(verts, faces, re_allocate_buffers);
} else if(threejs_rev === THREEJS_R79) {
//LiveBufferGeometry79( verts_, faces_, pre_allocate_, min_faces_capacity_, min_verts_capacity_)
var min_faces_capacity_ = 0, min_verts_capacity_ = 0;
var geom = new LiveBufferGeometry79(
verts, faces,
re_allocate_buffers,
min_faces_capacity_, min_verts_capacity_);
//, gradients); // Alternative: specify normals at creation of LiveGeometry. But this is fine.
*/
var min_faces_capacity_ = 0, min_verts_capacity_ = 0; // force zero initial allocation
var geom = new LiveBufferGeometry79(
verts, faces,
re_allocate_buffers,
min_faces_capacity_, min_verts_capacity_);
//geom.update_geometry(implisolid_, true);
//implisolid_.update_geometry(geom, true);
IMPLICIT.update_geometry(geom, true);
// Alternative: specify normals at creation of LiveGeometry. But this is fine.
// implisolid_.make_normals_into_geometry(geom, shape_json, verts, false);
IMPLICIT.make_normals_into_geometry(geom, shape_json, verts, false);
/*
var n = implisolid_.get_pointset_size("post_p_centroids");
var centroids = PS_UTILS.get_emc_array(
implisolid_.get_pointset_ptr("post_p_centroids")
, n * 3 );
implisolid_.make_normals_into_geometry(geom, shape_json, centroids, false);
*/
/*
}
*/
/*
release_gradients1(implisolid_);
*/
if(VERBOSE){
console.log("nverts : "+ nverts);
console.log("nfaces : "+ nfaces);
}
return geom;
}
//unload
function __update_reused_geometry(implisolid_, mp5_json, mc_properties_json, geometry) {
//console.log(mp5_json);
//console.log(mc_properties_json);
var startTime = new Date();
//console.log(implisolid_.needs_deallocation);
if(implisolid_.needs_deallocation) { // Remove data from last round.
//d(1);
implisolid_.finish_geometry();
implisolid_.needs_deallocation = false;
}
if(implisolid_.needs_deallocation)
console.error("not deallocated.");
try{
implisolid_.build_geometry( mp5_json , mc_properties_json);
//implicit_double_mushroom center will be zero.
implisolid_.needs_deallocation = true;
}catch(err){
console.error("An error occured during MCC C++")
console.info(err);
}finally {
}
var ignore_normals = false
// geometry. update_geometry (implisolid_, ignore_normals);
// called after build_geometry()
implisolid_. update_geometry (geometry, ignore_normals);
var endTime = new Date();
var timeDiff = endTime - startTime;
//console.log(nv3 + " , " + nf3);
//console.log("Time: "+timeDiff+ " msec.");
report_time(timeDiff);
}
'use strict';
// **************************************************************
// global variables for meshes that are accessed and updated in the render loop, etc.
var globals = {};
globals.mesh_solid = null;
globals.mesh_wireframe = null;
globals.normals = null;
globals.arrows = null;
globals.chosen_matrial = null;
globals.global_mp5 = "***";
var mesh2_tiny_box_wireframe;
var materials_list; //, material_f;
var material_wireframe;
//var last_geometry = null;
// DEMO CONFIGURATIONS
const CHOSEN_MATERIAL_INDEX = 2; //14;
//2; nice //3;
// 7 = colourful
// 3 = ?
//1: grayscale boring phong.
//2: faceted. (good for debug / shape study)
//3: colorful
//4: semi opaque (good for debug / shape study)
//6: striped
//7: rainbow
//8 is wireframe
//9: plain white?
//10: changing peach
//11: changing cyan
//12: ??? white?
//13: proper Phong (As in WeDesign.Live)
//14: Phong but semi-transparent
const SHOW_WIREFRAME = false;
const SHOW_SOLID = true;
const PERSPECTIVE = false;
function init_scene(IMPLICIT, shape_json, polygonization_json) {
// determins the size & location of the grid, the location of the camera, and the size of the small cube in center (reference cube).
var GRID_CELL_SIZE = 1.0;
scene = new THREE.Scene();
//var WIDTH = 300, HEIGHT = 300;
var WIDTH = window.innerWidth,
HEIGHT = window.innerHeight - 0*200; //for memory profiler
if (PERSPECTIVE) {
camera = new THREE.PerspectiveCamera( 75, WIDTH / HEIGHT, 1, 10000 );
// ( fov, aspect, near, far )
} else {
// Use Orthogaphic camera
var span_per_pixel = 1.0/800.0*2000.0/30.0;
var x0 = WIDTH/2.0*span_per_pixel;
var y0 = HEIGHT/2.0*span_per_pixel;
camera = new THREE.OrthographicCamera( -x0, +x0, -y0, +y0, 1, 10000 ); // ( left, right, top, bottom, near, far )
}
camera.position.set(0, 0, 40*GRID_CELL_SIZE); // 40*25; //1000;
// Grid
var grid = grid_bed(GRID_CELL_SIZE);
// scene.add( grid );
materials_list = look_nice();
globals.chosen_matrial = materials_list[CHOSEN_MATERIAL_INDEX];
//globals.chosen_matrial = new THREE.MeshBasicMaterial( {
// color: 0xaaffff, wireframe: false, opacity:0.5, transparent: true,
// side:THREE.DoubleSide } );
//THREE.FrontSide or THREE.BackSide or THREE.DoubleSide.
material_wireframe = new THREE.MeshBasicMaterial( {
color: 0xff0000, wireframe: true, opacity:0.3, transparent: true,} );
// //if(delta_t === undefined)
// var delta_t = 0.2;
// // Subjective time!
// global_time += delta_t;
var geometry = null;
//geometry = new THREE.BoxGeometry( 200, 200, 200 );
/*
if(CALL_VERSION==1){
//geometry = make_geometry_oldold(shape_json, polygonization_json);
}
else
*/
{
/* OLD
geometry = make_geometry_new2(implisolid_, shape_json, polygonization_json, true, geom_callback__1);
*/
var ignore_root_matrix = false;
console.warn("bad: ignore_root_matrix not known", ignore_root_matrix);
geometry = IMPLICIT.getLiveGeometry_from_json(shape_json, polygonization_json, true, geom_callback__1, ignore_root_matrix);
}
//last_geometry = geometry;
if(SHOW_WIREFRAME){
globals.mesh_wireframe = new THREE.Mesh( geometry, material_wireframe );
globals.mesh_wireframe.position.set( 0, 0, 0 );
globals.mesh_wireframe.scale.set( MESH_SCALE, MESH_SCALE, MESH_SCALE );
scene.add( globals.mesh_wireframe );
}
//this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
//material_f = new THREE.MeshBasicMaterial( { color: 0xffffff, wireframe: false, opacity:0.4, transparent: true } );
if(SHOW_SOLID){
//globals.mesh_solid = new THREE.Mesh( geometry, material_f );
//nice ones: 2, 3, (checked until 4)
globals.mesh_solid = new THREE.Mesh( geometry, globals.chosen_matrial );
globals.mesh_solid.position.set( 0, 0, 0 );
globals.mesh_solid.scale.set( MESH_SCALE, MESH_SCALE, MESH_SCALE );
scene.add( globals.mesh_solid );
}
/*
var points2 = PS_UTILS.make_pointset("pre_resampling_vertices", 8.0 / 4.0, 0.9, 0.0, 0.0); // Red: before
scene.add( points2 );
var points1 = PS_UTILS.make_pointset("post_resampling_vertices", 10.0 / 4.0, 0.9, 0.9, 0.0); // Yellow: after
scene.add( points1 );
*/
/*
var points2 = PS_UTILS.make_pointset("pre_qem_verts", 2.0 / 30.0, 0.9, 0.0, 0.0); // Red: before
scene.add( points2 );
*/
/*
var points1q = PS_UTILS.make_pointset("post_qem_verts", 2.5 / 30.0 * 6.0, 0.9, 0.9, 0.0); // Yellow: after
scene.add( points1q );
*/
var alpha1 = -0.3, alpha2 = -0.6;
var norms_ = PS_UTILS.visualise_normals(shape_json, "post_p_centroids", alpha1, alpha2, 0x009900); // 0x00ff00 // 0x88ff00
if (norms_) {
scene.add(norms_);
}
globals.normals = norms_;
var points2 = PS_UTILS.make_pointset("pre_p_centroids", 8.0 / 4.0*2 / 30.0, 0.9, 0.0, 0.0); // Red: before
// scene.add( points2 );
var points1 = PS_UTILS.make_pointset("post_p_centroids", 10.0 / 4.0 / 30.0, 0.9, 0.9, 0.0); // Yellow: after
scene.add( points1 );
/*
// "Centroid Projection"'s result.
var vectorfield = PS_UTILS.make_vectorfield_flow_lines_v1("pre_p_centroids", "post_p_centroids");
scene.add( vectorfield );
*/
// "QEM"'s result.
var vectorfield = PS_UTILS.make_vectorfield_flow_lines_v1("pre_qem_verts", "post_qem_verts");
scene.add( vectorfield );
// Visualising the normal vectors as queried and applied on t geometry. Normal vector for vertices is a bad idea. Need to see how normal vectors can be specified for facets of BufferGeometry.
if ( global_verts_copy && global_gradients_copy ) {
var hairy_m = PS_UTILS.hairy_object_based_on_vectors(global_verts_copy, global_gradients_copy, 0.0, 1.0, 0x777700);
scene.add( hairy_m );
}
// choose what is visible and what is not
// globals.mesh_solid.visible = false;
// points1.visible = false;
//points2.visible = false;
// globals.mesh_wireframe.visible = false;
// vectorfield.visiable = false;
// norms_.visible = false;
// globals.normals.visible = false;
/*
var points2 = PS_UTILS.make_pointset("pre_qem_verts", 8.0 / 4.0, 0.9, 0.0, 0.0); // Red: before
scene.add( points2 );
var points1 = PS_UTILS.make_pointset("post_qem_verts", 10.0 / 4.0, 0.9, 0.9, 0.0); // Yellow: after
scene.add( points1 );
*/
// Show a cube in center
var geo2 = new THREE.BoxGeometry( GRID_CELL_SIZE, GRID_CELL_SIZE, GRID_CELL_SIZE );
mesh2_tiny_box_wireframe = new THREE.Mesh( geo2, material_wireframe );
mesh2_tiny_box_wireframe .position.set( 0, 0, 0 );
// scene.add( mesh2_tiny_box_wireframe ); box wire
//mesh2_tiny_box_wireframe .scale.set( 10, 10, 10 );
var dirLight = new THREE.DirectionalLight(0xffffff, 1);
dirLight.position.set(100, 100, 50);
scene.add(dirLight);
var dirLight2 = new THREE.DirectionalLight(0x00ffff, 1);
dirLight2.position.set(-100, -100, -50);
scene.add(dirLight2);
//var arrow = make_arrow();
//global_arrow = arrow;
var arrows__ = make_multiple_arrows(ARROWS_COUNT);
globals.arrows = arrows__;
if(VERBOSE){
console.log("RENDERER");
}
var render_canvas = document.getElementById( 'my_canvas' );
my_assert(render_canvas);
console.log(render_canvas);
renderer = new THREE.WebGLRenderer( { antialias: true, canvas: render_canvas } );
//renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setSize( WIDTH, HEIGHT );
document.body.appendChild( renderer.domElement );
/*
function callMultipleTimes() {
var mc_icounter=0;
var delta_t = 0.2/10.*5;
setInterval(function(){ if(mc_icounter<10) update_mc(implisolid_, delta_t); mc_icounter++; }, 30);
}
*/
function doKeyDownListener(event) {
return ; // tiger debug
const CONTROL_KEY = 17;
const SHIFT_KEY = 16;
if ( event.keyCode == SHIFT_KEY ) {
var BURST_COUNT = 5; // 50;
var INTERVAL_MSEC = 100; // 8-1; //40 // 1 // in Milliseconds
var delta_t = 0.2/10.*5 /5. * 5;
//update_mc(implisolid_);
callMultipleTimes (BURST_COUNT, INTERVAL_MSEC, function(){
update_mc(IMPLICIT, delta_t);
});
//change_arrow(arrow, implisolid_, globals.global_mp5);
}
else
console.log("\"keydown\" code", event.keyCode);
}
window.addEventListener( "keydown", doKeyDownListener, false ); // keydown keypress
// CONTROLS
//see https://github.com/mrdoob/three.js/blob/master/examples/webgl_geometry_teapot.html
var cameraControls = new THREE.OrbitControls( camera, renderer.domElement );
cameraControls.rotateSpeed = 1.5;
cameraControls.zoomSpeed = 1.2;
cameraControls.panSpeed = 0.8;
cameraControls.enableZoom = true;
cameraControls.enablePan = true;
cameraControls.enableDamping = true;
cameraControls.dampingFactor = 0.6; //0.9; // 1.0; //motile: 0.3;
/*
cameraControls.constraint.smoothZoom = true;
cameraControls.constraint.zoomDampingFactor = 0.2;
cameraControls.constraint.smoothZoomSpeed = 5.0;
*/
cameraControls.target.set( 0, 0, 0 );
cameraControls.addEventListener( 'change', function () {;} );
}
function update_mc(implisolid_, delta_t){
assert(delta_t !== undefined)
// delta_t = 0.2 * 5;
// Subjective time!
console.log("delta_t", delta_t);
global_time += delta_t;
var tuple = provide_input(global_time, 1, {}, globals);
var shape_json = tuple.shape_json;
var polygonization_json = tuple.polygonization_json;
assert(typeof polygonization_json !== "string");
//Three modes of speed here for (UPDATE_SAME_GEOM_OBJECT, EVEN_REUSE_MESH_OBJECT):
// (false, false) // Creates a new Geometry object at each loop iteration.
// (true, false) // Keeps geometry object instance
// (true, true) // Keeps mesh instance (as well as geometry)
var UPDATE_SAME_GEOM_OBJECT = true; //Will not even call the constructor
var EVEN_REUSE_MESH_OBJECT = true;
if( EVEN_REUSE_MESH_OBJECT && ! UPDATE_SAME_GEOM_OBJECT)
console.error("Wrong condition.");
if(SHOW_SOLID){
var p1 = [globals.mesh_solid.position, globals.mesh_solid.rotation];
}
if(SHOW_WIREFRAME){
var p2 = [globals.mesh_wireframe.position, globals.mesh_wireframe.rotation];
}
// g i.e. actual_current_active_geom
var g = null;
if(SHOW_SOLID){
g = globals.mesh_solid.geometry;
}
if(SHOW_WIREFRAME){
g = globals.mesh_wireframe.geometry;
}
my_assert(g, "SHOW_SOLID and SHOW_WIREFRAME cannot be both false.");
if(!EVEN_REUSE_MESH_OBJECT){
if(SHOW_SOLID){
scene.remove(globals.mesh_solid);
}
if(SHOW_WIREFRAME){
scene.remove(globals.mesh_wireframe);
}
}
var reused_last_geom = g;
//Not sure about the condision
if(!UPDATE_SAME_GEOM_OBJECT){
if(SHOW_SOLID){
g.dispose();
g = null;
// reused_last_geom is not null and will remain. It is not recommended to use reused_last_geom.
}
//globals.mesh_wireframe.geometry.dispose(); // Don't do it twice!
}
// var reused_last_geom = g;
if(!EVEN_REUSE_MESH_OBJECT){
globals.mesh_solid = null;
globals.mesh_wireframe = null;
}
var geometry = null;
if(UPDATE_SAME_GEOM_OBJECT) {
geometry = g;
//update_reused_geometry(implisolid_, global_time, geometry);
// shape_json: from update,
//OLD// update_reused_geometry(implisolid_, shape_json, polygonization_json, geometry);
var ignoreNormals = false;
IMPLICIT.update_geometry_from_json(geometry, shape_json, polygonization_json, ignoreNormals)
}
else {
/*
if(CALL_VERSION==1){
//geometry = make_geometry_oldold(shape_json, polygonization_json);
}
else
*/
{
//reused_last_geom = null;
//OLD// geometry = make_geometry_new2(implisolid_, shape_json, polygonization_json, false, geom_callback__1); //FALSE??
}
var ignoreNormals = false;
geometry = IMPLICIT.getLiveGeometry(shape_json, polygonization_json, ignoreNormals)
};
/*
"";
for(var i=0;i<10*3;i++){
//geometry.attributes.position.setXYZ( i, x, y, z );
geometry.attributes.position.array[i] += 0.0002 * (i% 2);
//geometry.index.array[ i ] += (i % 2)*40 ;
var nverts = geometry.attributes.position.count/3;
geometry.index.array[ i ] = (geometry.index.array[ i ] % (nverts));
}
//geometry.attributes.position.needsUpdate = true;
//geometry.index.needsUpdate = true;
"";
*/
/*
// SLOW. But using -o3 compilation it can make a nice live smooth QEM demo.
if (globals.normals) {
scene.remove(globals.normals);
globals.normals = null
}
var alpha = 60.0;
var norms_ = PS_UTILS.visualise_normals(globals.global_mp5, "post_p_centroids", 0, alpha, 0x009900); // 0x00ff00 // 0x88ff00
scene.add(norms_);
globals.normals = norms_;
*/
/*
var ignore_root_matrix = false;
update_arrows(globals.arrows, implisolid_, globals.global_mp5, ARROWS_COUNT, ignore_root_matrix);
*/
if(!EVEN_REUSE_MESH_OBJECT){
if(SHOW_WIREFRAME){
globals.mesh_wireframe = new THREE.Mesh( geometry, material_wireframe );
globals.mesh_wireframe.scale.set( MESH_SCALE, MESH_SCALE, MESH_SCALE );
//copy so that we dont lose the rotation, position of the meshes.
globals.mesh_wireframe.position.copy(p2[0]);
globals.mesh_wireframe.rotation.copy(p2[1]);
scene.add( globals.mesh_wireframe );
}
/*var material1 = new THREE.MeshPhongMaterial( {
color: 0xaaaaaa, specular: 0xffffff, shininess: 250,
side: THREE.DoubleSide, vertexColors: THREE.VertexColors
} );
globals.mesh_solid = new THREE.Mesh( geometry, material1 );
*/
if(SHOW_SOLID){
globals.mesh_solid = new THREE.Mesh( geometry, globals.chosen_matrial );
// //globals.mesh_solid.position.set( 0, 0, 0 );
globals.mesh_solid.scale.set( MESH_SCALE, MESH_SCALE, MESH_SCALE );
globals.mesh_solid.position.copy(p1[0]);
globals.mesh_solid.rotation.copy(p1[1]);
scene.add( globals.mesh_solid );
}
}
}
function animate() {
requestAnimationFrame( animate );
//Updating the meshes
var SPEED = 0 * 3. / 100;
if(globals.mesh_wireframe){
globals.mesh_wireframe.rotation.x += 0.01*SPEED;
globals.mesh_wireframe.rotation.y += 0.02*SPEED;
}
if(globals.mesh_solid){
globals.mesh_solid.rotation.x += 0.01*SPEED;
globals.mesh_solid.rotation.y += 0.02*SPEED;
}
mesh2_tiny_box_wireframe .rotation.z += 0.01*SPEED;
mesh2_tiny_box_wireframe .rotation.y += 0.02*SPEED;
//Updating the matrials
//material update callback
//materials_list[ materials_list.length - 2 ].emissive.setHSL( 0.54, 1, 0.35 * ( 0.5 + 0.5 * Math.sin( 35 * global_time / 20. ) ) );
//materials_list[ materials_list.length - 3 ].emissive.setHSL( 0.04, 1, 0.35 * ( 0.5 + 0.5 * Math.cos( 35 * global_time / 20.) ) );
renderer.render( scene, camera );
}
var scene, camera, renderer;
//var geometry;
</script>
<!--script type="text/javascript" src="wwexample1.js"></script-->
<script type="text/javascript">