-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
1462 lines (1126 loc) · 40.6 KB
/
main.js
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
var scene, camera, myExporter, geoBuf, mirrorGeoBuf, particleSystem, indexArray, nLayers, nSegments, boolRot, boolSlice, params, extrudePath;
var box, horizontalPlane, cameraOrtho, sceneOrtho, sliceLine, sliceGeometry, mirrorTog, mirrorType, axisline, columngeoBuf, path3d, mergeMesh;
var mirrorObjMaterial, arrowHelper, mergeMesh;
var iterations = new function() {
this.number = 1 ;
}
var xSin = new function() {
this.xfrequency = 0.0;
this.xamplitude = 0.0;
this.xphase = 0.0;
this.xoffset = 0.0;
}
var zSin = new function() {
this.zfrequency = 0.0;
this.zamplitude = 0.0;
this.zphase = 0.0;
this.zoffset = 0.0;
}
var pSin = new function() {
this.pfrequency = 0.0;
this.pamplitude = 0.0;
this.pphase = 1.0;
this.poffset = 0.0;
}
var mAttr =new function() {
this.mType = "parallel to xx' axis" ;
this.distance = 0.0;
this.mm = 0.0;
this.mc = 0.0;
}
var pAttr = new function() {
this.bool = false
this.orType = "Simple Noise"
}
var fourier = new function(){
this.bool = "false";
this.ite = 1 ;
}
var params = new function(){
this.radiusSegments = 12 ;
};
mirrorTog = false;
boolSlice = false;
concreteTog = false;
extrudeTog = false;
function vertexShader() {
return `
varying vec3 world_pos;
varying vec3 normalInterp;
varying float frequency;
void main() {
vec3 p = position;
frequency = 1.8;
float top_thickness = 0.83;
if (abs(position.y) > 0.3){
p.x += max( 0.0, abs(sin( p.y * frequency )) * 1. );
p.z += max( 0.0, abs(cos( p.y * frequency )) * 1. );
} else {
p.x *= top_thickness;
p.z *= top_thickness;
}
gl_Position = projectionMatrix * modelViewMatrix * vec4( p, 1.0 );
world_pos = p;
normalInterp = normal;
}
`
}
function fragmentShader() {
return `
precision mediump float; // set float to medium precision
uniform vec3 lightPos1;
uniform vec3 lightPos2;
uniform vec3 lightPos3;
uniform sampler2D texture1;
varying vec3 world_pos;
varying vec3 normalInterp;
varying float frequency;
// const vec3 ambientColor = vec3(0.870, 0.831, 0.721);
// const vec3 diffuseColor = vec3(0.870, 0.831, 0.721);
// const vec3 specColor = vec3(0.870, 0.831, 0.721);
vec3 getPosNormalized(){
float x = world_pos.x / 80.0 ;
float y = world_pos.y / 300. + 1. ;
float z = world_pos.z / 80.0 ;
return vec3(x, y, z);
}
vec2 getZylindricalUvs(){
vec3 pos_n = getPosNormalized();
float a = atan(pos_n.x, -pos_n.z) /3.14;
float us = mod( ((a + 1.)) * 0.5 * 4.0, 1.0); // from 0 to 1
float vs = mod( pos_n.y * 12., 1.0) ; // from 0 to 1
return vec2(us, vs);
}
void main() {
//calculate uvs
vec2 vUv = getZylindricalUvs();
// look up texture
highp vec2 tex2 = vec2(vUv.x, vUv.y);
vec4 texColor = texture2D(texture1, tex2);
//normal and light direction
vec3 normal = normalize(normalInterp);
vec3 light1 = normalize(lightPos1 - world_pos);
vec3 light2 = normalize(lightPos2 - world_pos);
vec3 light3 = normalize(lightPos3 - world_pos);
float lambert = max(0.0, dot(normal,light1))
+ max(0.0, dot(normal,light2))
+ max(0.0, dot(normal,light3) + 0.05);
// ambient term
vec3 ambient = texColor.xyz;
// diffuse term
vec3 diffuse = texColor.xyz * lambert; // diffuse term
// (fake) specular term
vec3 eye = normalize(-world_pos);
vec3 r1 = 2.0*lambert* normal - light1;
vec3 r2 = 2.0*lambert* normal - light2;
vec3 r3 = 2.0*lambert* normal - light3;
float spec_intensity = sin( (world_pos.y -2. ) * frequency * 2.)
*( pow(max(0.0, -dot(eye, r1) - 0.4), 3.0)
+ pow(max(0.0, -dot(eye, r2) - 0.4), 3.0) );
// + pow(max(0.0, -dot(eye, r3)), 3.0) );
vec3 specular = texColor.xyz * spec_intensity;
// (fake) occclusion
float occlusion = 1.0 - 0.4 * sin( (world_pos.y+ 1.5) * frequency * 2.) ;
vec3 color = 0.65 * ambient - 0.1 * occlusion
+ 0.65 * diffuse - 0.1 * occlusion
+ specular * 0.03;
gl_FragColor = vec4(color , 1.0);
}
`
}
function getCustomMaterial(){
uniforms = {
lightPos1 : {type: 'vec3', value: [-300, 200, 40]},
lightPos2 : {type: 'vec3', value: [300, 200, 40]},
lightPos3 : {type: 'vec3', value: [0, 100, 30]},
texture1: { type: 't', value: THREE.ImageUtils.loadTexture( 'assets/textures/AS2_concrete_13.jpg' ) } //concrete_texture
}
selectedMaterial = new THREE.ShaderMaterial({
side: THREE.DoubleSide,
uniforms: uniforms,
fragmentShader: fragmentShader(),
vertexShader: vertexShader(),
})
return selectedMaterial;
}
function getCurvatureMaterial(geo){
// after curvatureApproximation is called, curvature attribute is added to geoBuf, so then the shader can read it?
geoBuf = curvatureApproximation(geo, "both")[0];
console.log(curvatureApproximation(geo)[1]);
console.log(curvatureApproximation(geo)[2]);
uniforms = {
Cmin : {type: 'float', value: curvatureApproximation(geo)[1]},
Cmax : {type: 'float', value: curvatureApproximation(geo)[2]}
}
materialRaw = new THREE.ShaderMaterial({
side: THREE.DoubleSide,
uniforms: uniforms,
vertexShader: document.getElementById( 'vertexShaderRaw' ).textContent,
fragmentShader: document.getElementById( 'fragmentShaderRaw' ).textContent,
})
//console.log(materialRaw);
return [materialRaw, geoBuf];
}
function getOverhangMaterial(geo){
// after curvatureApproximation is called, curvature attribute is added to geoBuf, so then the shader can read it?
geoBuf = overhangApproximation(geo)[0];
uniforms = {
Omin : {type: 'float', value: overhangApproximation(geo)[1]},
Omax : {type: 'float', value: overhangApproximation(geo)[2]}
}
materialRaw = new THREE.ShaderMaterial({
side: THREE.DoubleSide,
uniforms: uniforms,
vertexShader: document.getElementById( 'vertexShaderOverhang' ).textContent,
fragmentShader: document.getElementById( 'fragmentShaderOverhang' ).textContent,
})
return [materialRaw, geoBuf];
}
function bothAddTube(){
extrudeTog = !(extrudeTog);
addTube()
}
function addTube() {
if (mergeMesh !== undefined){
scene.remove(mergeMesh);
}
if (extrudeTog === true) {
//hide column
scene.remove(geoBuf);
if (mirrorGeoBuf !== undefined){
scene.remove(mirrorGeoBuf);
}
helperDataSt = geoBuf.geometry.getAttribute('position').array;
//////////////////////make a sausage/////////////////////////
pts = [];
numPts = 5;
layerHeight = 0.5;
layerWidth = 2.5 - 2 * layerHeight;
for ( var i = 0; i < numPts * 2; i ++ ) {
var a = i / numPts * Math.PI;
pts.push( new THREE.Vector2( Math.sin( a ) * 0.3 , Math.cos( a ) * 0.3 ) );
}
h = 0;
for (p of pts){
if ( (h<=2) || (h>7) ){
p.add( new THREE.Vector2(0,0.9) )
}else if( (h>2) && (h<=7)){
p.add( new THREE.Vector2(0,-0.9) )
}
if ((h === 2) || (h===3)) {
p.x = 0.25;
}
if ((h === 8) || (h===7)) {
p.x = - 0.25;
}
h +=1
}
var shape = new THREE.Shape( pts );
//////////////////////make a sausage/////////////////////////
geos = [];
var material = getMaterial('lambert', 'rgb( 255, 255, 255)');
for (var l = 0; l < nLayers; l++){
newHelper = [];
for (var i = 600*l; i < (l+1) * (helperDataSt.length/nLayers-1); i+=3) {
//console.log(i);
newHelper.push( new THREE.Vector3( helperDataSt[i], helperDataSt[i+1], helperDataSt[i+2] ) )
}
//apply pattern
if (pAttr.bool === "true"){
if( pAttr.orType === "Simple Pattern"){
newHelper = applySimplePattern(newHelper, l, pSin, zSin);
}else if(pAttr.orType === "Simple Noise"){
newHelper = applySimpleNoise(newHelper, l);
}else if(pAttr.orType === "Faced Based Pattern"){
applyFacedBasedPattern()
}else if( pAttr.orType === "Curvature Based Pattern"){
applyCurvatureBasedPattern()
}else{
applyCrossingPattern()
}
}
var closedSpline = new THREE.CatmullRomCurve3(newHelper );
closedSpline.curveType = 'catmullrom';
closedSpline.closed = true;
extrudeSettings = {
steps: 800,
bevelEnabled: false,
extrudePath: closedSpline
};
var testGeometry = new THREE.ExtrudeBufferGeometry( shape, extrudeSettings );
geos.push(testGeometry);
}
//var tubeGeometry = new THREE.TubeBufferGeometry( extrudePath, newHelper.length*2, 0.3, params.radiusSegments, false );
//mesh = new THREE.Mesh(singleGeometry, material);
mesh = THREE.BufferGeometryUtils.mergeBufferGeometries(geos);
mergeMesh = new THREE.Mesh(mesh, material);
scene.add(mergeMesh);
}else{
//if new thing exists delete it
if (path3d !== undefined){
scene.remove(path3d);
}
addGeo(objMaterial, true, xSin, zSin, pSin,mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog);
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog,curvatureTog, overhangTog );
}
}
}
function addGeo(objMaterial, tog, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog ) {
if ( geoBuf !== undefined ) {
scene.remove( geoBuf );
}
columngeoBuf = getGeometry('myCylinder', 5, objMaterial, xSin, zSin, pSin, tog, 0, mAttr, iterations, fourier);
if (concreteTog === true){
objMaterial = getCustomMaterial(); /// Custom shader mtl
}
if (curvatureTog === true){
values = getCurvatureMaterial(geoBuf)
objMaterial = values[0];
//console.log( objMaterial);
columngeoBuf = values[1].geometry;
}
if (overhangTog === true){
values = getOverhangMaterial(geoBuf)
objMaterial = values[0];
console.log( objMaterial);
columngeoBuf = values[1].geometry;
}
geoBuf = new THREE.Mesh(columngeoBuf, objMaterial);
geoBuf.castShadow = true;
geoBuf.name = 'column-1';
scene.add(geoBuf);
}
function addMirrorGeo(mirrorObjMaterial, tog, xSin, zSin, pSin,mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog ) {
if ( mirrorGeoBuf !== undefined ) {
scene.remove( mirrorGeoBuf );
//mirrorGeo.geometry.dispose();
}
mirrorcolumnGeoBuf = getGeometry('myCylinder', 5, mirrorObjMaterial, xSin, zSin, pSin, tog, 1, mAttr, iterations, fourier);
// mirrorcolumnGeoBuf = new THREE.BufferGeometry().fromGeometry( mirrorcolumnGeo );
if (concreteTog === true){
mirrorObjMaterial = getCustomMaterial(); /// Custom shader mtl
}
if (curvatureTog === true){
mirrorObjMaterial = getCurvatureMaterial( mirrorGeoBuf);
}
if (overhangTog === true){
mirrorObjMaterial = getOverhangMaterial();
}
mirrorGeoBuf = new THREE.Mesh(mirrorcolumnGeoBuf, mirrorObjMaterial);
mirrorGeoBuf.castShadow = true;
mirrorGeoBuf.name = 'column-2'
scene.add(mirrorGeoBuf);
}
function zoomIn(){
camera.position.x = 0;
camera.position.y = -50;
camera.position.z = -100;
camX = camera.position.x
camY = camera.position.y
camZ = camera.position.z
controls.object.position.set(camX, camY, camZ);
//camera.zoom = 2;
targetX = 20;
targetY = -100;
targetZ = 20;
controls.target = new THREE.Vector3(targetX, targetY, targetZ);
boolRot = false;
}
function zoomOut(){
camera.position.x = -300;
camera.position.y = 100;
camera.position.z = 50;
camX = camera.position.x
camY = camera.position.y
camZ = camera.position.z
controls.object.position.set(camX, camY, camZ);
targetX = 0;
targetY = -100;
targetZ = 0;
controls.target = new THREE.Vector3(targetX, targetY, targetZ);
boolRot = true;
}
function addSlice(ch, sliceLine, sliceGeometry, c, type) {
//here update slicer
for(var i=0; i < sceneOrtho.children.length; i++){
obj = sceneOrtho.children[i];
if ( (type === 0) && (obj.name === 'column') ){
sceneOrtho.remove(obj);
}else if( (type === 1) && (obj.name === "mirror")){
sceneOrtho.remove(obj);
}
}
helperDataSt = ch.geometry.getAttribute('position').array;
horizontalc = horizontalPlane.constant;
layerIndex = Math.floor(600 + horizontalPlane.constant*2);
sliceGeometry = new THREE.Geometry();
var sliceMaterial = new THREE.LineBasicMaterial( { color: c, linewidth: 1 } );
vertex1 = new THREE.Vector3( helperDataSt[3*((layerIndex)*(nSegments)+1)]*5, helperDataSt[3*((layerIndex)*(nSegments)+1)+2]*5,0)
for (var ka = 3*((layerIndex)*(nSegments)+1); ka < 3*(layerIndex+1)*(nSegments); ka+=3) {
sliceGeometry.vertices.push( new THREE.Vector3( helperDataSt[ka]*5 , helperDataSt[ka+2]*5 , 0 ));
}
sliceGeometry.vertices.push(vertex1);
var sliceLine = new THREE.Line( sliceGeometry, sliceMaterial );
sliceLine.rotation.z = Math.PI*0.5;
w = window.innerWidth
h = window.innerHeight
squareSize = 460;
sliceLine.position.x = - w - margin + squareSize*0.5 + 48;
sliceLine.position.z = 0;
sliceLine.position.y = -h - margin + squareSize*0.5 + 50;
if (type === 0){
sliceLine.name = "column"
}else{
sliceLine.name = "mirror"
}
sceneOrtho.add(sliceLine)
}
function addLineShape(layer) {
var material = new THREE.LineBasicMaterial( { color: 0x0000ff } );
var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3( -10, 0, 0) );
geometry.vertices.push(new THREE.Vector3( 0, 10, 0) );
geometry.vertices.push(new THREE.Vector3( 10, 0, 0) );
var line = new THREE.Line( geometry, material );
}
function addMirrorAxis() {
var test = sceneOrtho.getObjectByName("axis");
if (test !== undefined){
sceneOrtho.remove(test)
}
var axisMaterial = new THREE.LineDashedMaterial( {color: 0x336597, linewidth: 100, scale: 5, dashSize: 40, gapSize: 25 } );
var axisGeometry = new THREE.Geometry();
if (mAttr.mType === "parallel to xx' axis" ){
mirrorType = 0;
}else{
mirrorType = 1;
}
if (mirrorType === 0){
axisGeometry.vertices.push(new THREE.Vector3( -w + margin, -h + margin + 0.5* squareSize + ( 5*mAttr.distance), 0) );
axisGeometry.vertices.push(new THREE.Vector3( -w + margin + squareSize , -h + margin + 0.5* squareSize + (5*mAttr.distance), 0) );
axisline = new THREE.Line( axisGeometry, axisMaterial );
}else if(mirrorType === 1){
axisGeometry.vertices.push(new THREE.Vector3( -w + margin + 0.5* squareSize - ( 5*mAttr.distance), -h + margin, 0) );
axisGeometry.vertices.push(new THREE.Vector3( -w + margin + 0.5* squareSize - ( 5*mAttr.distance) , -h + margin + squareSize, 0) );
axisline = new THREE.Line( axisGeometry, axisMaterial );
}else{
axisGeometry.vertices.push(new THREE.Vector3( 0, mAttr.mc, 0) );
axisGeometry.vertices.push(new THREE.Vector3( 100, -300 + mAttr.mc , 0) );
axisline = new THREE.Line( axisGeometry, axisMaterial );
axisline.position.x = -w + margin + 0.5* squareSize
axisline.position.y = -h + margin + 0.5* squareSize
axisline.position.z = 0;
}
axisline.computeLineDistances()
axisline.name = "axis";
sceneOrtho.add(axisline);
}
function init() {
var gui = new dat.GUI();
var gui2 = new dat.GUI();
scene = new THREE.Scene();
sceneOrtho = new THREE.Scene();
var stats = new Stats();
stats.showPanel( 0 );
document.body.appendChild(stats.dom);
//add simple square around slice
var squareMaterial = new THREE.LineBasicMaterial( { color: 0xffffff, linewidth: 30 } );
var squareGeometry = new THREE.Geometry();
w = window.innerWidth;
h = window.innerHeight;
squareSize = 460;
margin = 26;
squareGeometry.vertices.push(new THREE.Vector3( -w + margin, -h + margin, 0) );
squareGeometry.vertices.push(new THREE.Vector3( -w + margin, -h + margin + squareSize , 0) );
squareGeometry.vertices.push(new THREE.Vector3( -w + margin + squareSize , -h + margin + squareSize , 0) );
squareGeometry.vertices.push(new THREE.Vector3( -w + margin + squareSize , -h + margin, 0) );
squareGeometry.vertices.push(new THREE.Vector3( -w + margin, -h + margin, 0) )
var line = new THREE.Line( squareGeometry, squareMaterial );
line.name = 'rec';
sceneOrtho.add(line);
var clock = new THREE.Clock();
myExporter = new THREE.STLExporter();
// ***** Clipping planes: *****
horizontalPlane = new THREE.Plane( new THREE.Vector3( 0, - 1, 0 ), 0.3 );
var folder2 = gui.addFolder('iterations');
folder2.add( iterations, 'number', 1, 4, 1).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin,mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 1 );
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0);
}
} );
folder2.open();
var folder3 = gui.addFolder('xSin');
folder3.add(xSin, 'xfrequency', 0.0, 10).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 1 );
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0);
}
} );
folder3.add(xSin, 'xamplitude', 0.0, 10);
folder3.add(xSin, 'xphase', 0, 0.5 * Math.PI);
folder3.add(xSin, 'xoffset', 0, 3); //0.5 *z/nLayers
// folder3.open();
var folder5 = gui.addFolder('pSin');
folder5.add(pSin, 'pfrequency', 0.0, 10,1).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 1 )
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0)
}
} );
folder5.add(pSin, 'pamplitude', 0.0, 10).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 1 )
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0)
}
} );
folder5.add(pSin, 'pphase', 1, 10, 0.1).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 1 )
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0)
}
} );
folder5.add(pSin, 'poffset', 0, 10, 0.1).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 1 )
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0)
}
} );
folder5.open();
var folder4 = gui.addFolder('zSin');
folder4.add(zSin, 'zfrequency', 0.0, 10).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb(220, 220, 220)', 1 )
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0);
}
} );
folder4.add(zSin, 'zamplitude', 0.0, 10).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 1 )
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0)
}
} );
folder4.add(zSin, 'zphase', 0.0, 2 * Math.PI).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin,mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 1 )
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0)
}
} );
folder4.add(zSin, 'zoffset', 0.0, 3).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 1 )
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0)
}
} );
folder4.open();
var folderf = gui.addFolder('fourier');
folderf.add(fourier, 'bool', ["true", "false"]).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 1 )
addMirrorAxis()
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0)
}
} );
folderf.add(fourier, 'ite', 1, 5, 1).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 1 )
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0)
}
} );
folderf.open();
var folder6 = gui.addFolder('mAttr');
folder6.add(mAttr, 'mType', ["parallel to xx' axis", "parallel to yy' axis"]).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 1 )
addMirrorAxis()
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0)
}
} );
folder6.add(mAttr, 'distance', -10, 10, 1).onChange( function () {
addGeo(objMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
if (mirrorTog === true){
addMirrorGeo(mirrorObjMaterial, true, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog )
if (boolSlice === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 1 )
addMirrorAxis()
}
}
if (boolSlice === true){
addSlice(geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0)
}
} );
folder6.open();
var folder7 = gui.addFolder('extrusion path');
folder7.add(params, 'radiusSegments', 2, 12, 1).onChange( function() {
addTube();
} );
folder7.open();
var folder8 = gui.addFolder('material driven ornament');
folder8.add( pAttr, 'bool', ["true", "false"]).onChange( function () {
extrudeTog = true;
addTube();
} );
//"Faced Based Pattern","Curvature Based Pattern", "Crossing Pattern"
folder8.add( pAttr, 'orType', [ "Simple Pattern", "Simple Noise"] ).onChange( function () {
addTube();
} );
folder8.open();
gui.domElement.style.marginTop = "10px";
//console.log(window.innerWidth);
gui.domElement.style.marginLeft = new String(window.innerWidth - 530)+"px";
gui2.domElement.style.marginTop = new String(window.innerHeight - squareSize + 113)+"px";
// initialize objects
concreteTog = false;
curvatureTog = false;
overhangTog = false;
objMaterial = getMaterial('lambert', 'rgb( 255, 255, 255)');
mirrorObjMaterial = getMaterial('lambert', 'rgb( 255, 255, 255)');
addGeo(objMaterial, false, xSin, zSin, pSin, mAttr, iterations, fourier, concreteTog, curvatureTog, overhangTog)
//'rgb(255, 220, 180)'
col = 'rgb(235, 235, 225)'
var lightLeft = getSpotLight(1, col);
var lightRight = getSpotLight(1, col );
var lightBottom = getPointLight(0.33, col );
lightLeft.position.x = -300;
lightLeft.position.y = 200;
lightLeft.position.z = 40;
lightRight.position.x = 300;
lightRight.position.y = 200;
lightRight.position.z = 40;
lightBottom.position.x = 0;
lightBottom.position.y = 10;
lightBottom.position.z = 0;
// dat.gui
// var folder1 = gui.addFolder('lightLeft');
// folder1.add(lightLeft, 'intensity', 0, 10);
// folder1.add(lightLeft.position, 'x', -500, 500);
// folder1.add(lightLeft.position, 'y', -500, 500);
// folder1.add(lightLeft.position, 'z', -500, 500);
// var folder2 = gui.addFolder('lightRight');
// folder2.add(lightRight, 'intensity', 0, 10);
// folder2.add(lightRight.position, 'x', -500, 500);
// folder2.add(lightRight.position, 'y', -500, 500);
// folder2.add(lightRight.position, 'z', -500, 500);
// add other objects to the scene
scene.add(lightLeft);
scene.add(lightRight);
scene.add(lightBottom);
//scene.add(helper);
// camera
cameraOrtho = new THREE.OrthographicCamera( - window.innerWidth , window.innerWidth, window.innerHeight, - window.innerHeight , -10000, 10000 );
var cameraGroup = new THREE.Group();
camera = new THREE.PerspectiveCamera(
50, // field of view
window.innerWidth / window.innerHeight, // aspect ratio
1, // near clipping plane
1000 // far clipping plane
);
camera.position.x = -300;
camera.position.y = 100;
camera.position.z = 50;
cameraGroup.add(camera);
cameraGroup.name = 'sceneCameraGroup';
scene.add(cameraGroup);
// renderer
renderer = new THREE.WebGLRenderer({ antialias: true } );
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.autoClear = false; // to allow overlay
document.body.appendChild(renderer.domElement);
renderer.localClippingEnabled = true;
var controls = new THREE.OrbitControls(camera, renderer.domElement);
camX = camera.position.x
camY = camera.position.y
camZ = camera.position.z
controls.object.position.set(camX, camY, camZ);
targetX = 0;
targetY = -100;
targetZ = 0;
controls.target = new THREE.Vector3(targetX, targetY, targetZ);
// GUI
folderHorizontal = gui2.addFolder( 'Horizontal Clipping' ),
propsHorizontal = {
get 'Enabled'() {
return renderer.localClippingEnabled;
},
set 'Enabled'( v ) {
renderer.localClippingEnabled = v;
},
get 'Plane'() {
return horizontalPlane.constant;
},
set 'Plane'( v ) {
horizontalPlane.constant = v;
}
};
folderHorizontal.open();
folderHorizontal.add( propsHorizontal, 'Enabled' );
folderHorizontal.add( propsHorizontal, 'Plane', -300.3, 0.3, -5.0 ).onChange( function () {
if ( boolSlice == true){
addSlice( geoBuf, sliceLine, sliceGeometry, 'rgb( 255, 255, 255)', 0)
}
if (mirrorTog === true){
addSlice(mirrorGeoBuf, sliceLine, sliceGeometry,'rgb( 255, 255, 255)', 1 )
}
} );
myExporter.name = 'exp'
var buttonExportStl = document.getElementById( 'exportStl' );
buttonExportStl.addEventListener( 'click', exportSTL );
var buttonNormals = document.getElementById( 'normals' );
buttonNormals.addEventListener( 'click', normals );
var buttonReset = document.getElementById( 'reset' );
buttonReset.addEventListener( 'click', reset );
var buttonConcrete = document.getElementById('concrete');
buttonConcrete.addEventListener( 'click', concrete );
var buttonCurvature = document.getElementById('curvature');
buttonCurvature.addEventListener( 'click', showCurvature );
var buttonOverhang = document.getElementById('overhang');
buttonOverhang.addEventListener( 'click', showOverhang );
var buttonMirror = document.getElementById( 'mirror' );
buttonMirror.addEventListener( 'click', mirror );
var buttonZoomIn = document.getElementById( 'in' );
buttonZoomIn.addEventListener( 'click', zoomIn );
var buttonZoomOut = document.getElementById( 'out' );
buttonZoomOut.addEventListener( 'click', zoomOut );
window.addEventListener( 'resize', onWindowResize, false );
boolRot = true;
var buttonRotate = document.getElementById( 'rotate' );
buttonRotate.addEventListener( 'click', rotateGeo );