-
Notifications
You must be signed in to change notification settings - Fork 4
/
SunflowAPIAPI.java
executable file
·1729 lines (1522 loc) · 70 KB
/
SunflowAPIAPI.java
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
import java.awt.Color;
import org.sunflow.SunflowAPI;
import org.sunflow.core.Display;
import org.sunflow.core.ParameterList.FloatParameter;
import org.sunflow.core.display.FileDisplay;
import org.sunflow.math.Matrix4;
import org.sunflow.math.Point3;
import org.sunflow.math.Vector3;
public class SunflowAPIAPI {
private String currShader;
private String currModifier;
private String currCamera;
private String currBucketOrder;
private String currFilter;
private String cameraType;
private String modifierType;
private SunflowAPI sunflow;
private Display windowDisplay;
private FileDisplay fileDisplay;
public final String SHADER_AMBIENT_OCCLUSION = "ambient_occlusion";
public final String SHADER_TEXTURED_AMBIENT_OCCLUSION = "textured_ambient_occlusion";
public final String SHADER_CONSTANT = "constant";
public final String SHADER_DIFFUSE = "diffuse";
public final String SHADER_TEXTURED_DIFFUSE = "textured_diffuse";
public final String SHADER_GLASS = "glass";
public final String SHADER_MIRROR = "mirror";
public final String SHADER_PHONG = "phong";
public final String SHADER_TEXTURED_PHONG = "textured_phong";
public final String SHADER_SHINY_DIFFUSE = "shiny_diffuse";
public final String SHADER_TEXTURED_SHINY_DIFFUSE = "textured_shiny_diffuse";
public final String SHADER_UBER = "uber";
public final String SHADER_WARD = "ward";
public final String SHADER_TEXTURED_WARD = "textured_ward";
public final String SHADER_WIREFRAME = "wireframe";
public final String COLORSPACE_SRGB_NONLINEAR = "sRGB nonlinear";
public final String COLORSPACE_SRGB_LINEAR = "sRGB linear";
public final String COLORSPACE_XYZ = "XYZ";
private String colorSpace = COLORSPACE_SRGB_NONLINEAR;
public final String CAMERA_PINHOLE = "pinhole";
public final String CAMERA_THINLENS = "thinlens";
public final String CAMERA_FISHEYE = "fisheye";
public final String CAMERA_SPHERICAL = "spherical";
public final String GI_AMBIENT_OCCLUSION = "ambocc";
public final String GI_FAKE = "fake";
public final String GI_INSTANT_GI = "igi";
public final String GI_IRRADIANCE_CACHE = "irr-cache";
public final String GI_PATH = "path";
public final String LIGHT_DIRECTIONAL = "directional";
public final String LIGHT_IMAGEBASED = "ibl";
public final String LIGHT_POINT = "point";
public final String LIGHT_SPHERE = "sphere";
public final String LIGHT_SUNSKY = "sunsky";
public final String LIGHT_MESH = "triangle_mesh";
public final String BUCKET_ORDER_COLUMN = "column";
public final String BUCKET_ORDER_DIAGONAL = "diagonal";
public final String BUCKET_ORDER_HILBERT = "hilbert";
public final String BUCKET_ORDER_RANDOM = "random";
public final String BUCKET_ORDER_ROW = "row";
public final String BUCKET_ORDER_SPIRAL = "spiral";
public final String FILTER_BLACKMAN_HARRIS = "blackman-harris";
public final String FILTER_BOX = "box";
public final String FILTER_CATMULL_ROM = "catmull-rom";
public final String FILTER_GAUSSIAN = "gaussian";
public final String FILTER_LANCZOS = "lanczos";
public final String FILTER_MITCHELL = "mitchell";
public final String FILTER_SINC = "sinc";
public final String FILTER_TRIANGLE = "triangle";
public final String FILTER_BSPLINE = "bspline";
public final String MODIFIER_BUMP_MAP = "bump_map";
public final String MODIFIER_NORMAL_MAP = "normal_map";
public final String MODIFIER_PERLIN_MAP = "perlin";
private Point3 eye;
private Point3 target;
private Vector3 up;
private int sides;
private float fov;
private float aspect;
private float shiftX;
private float shiftY;
private float focusDistance;
private float lensRadius;
private float lensRotation;
private int tileX;
private int tileY;
// modifier parameters
private int modifiercount = 0;
private boolean isModifiers = false;
private boolean useJitter = true;
private int aaMin = 1;
private int aaMax = 2;
private int previewAaMin = 0;
private int previewAaMax = 1;
private int width = 640;
private int height = 480;
public SunflowAPIAPI() {
sunflow = new SunflowAPI();
// set default values
// camera position
eye = new Point3(0, 10, 15);
target = new Point3(0, 0, 0);
up = new Vector3(0, 1, 0);
// camera default values
fov = 50;
aspect = width/height;
currCamera = "internal_defaultcamera";
focusDistance = 1;
lensRadius = 0;
fov = 90;
aspect = 1;
sides = 0;
lensRotation = 0;
// set camera
this.setThinlensCamera("internal_defaultcamera", fov, aspect);
// shader
this.setAmbientOcclusionShader("internal_defaultshader", new Color(1f,1f,1f), new Color(0f,0f,0f), 16, 5);
// bucket order
currBucketOrder = BUCKET_ORDER_SPIRAL;
// filter
currFilter = FILTER_MITCHELL;
}
/*
* --------------------------------------------------------------------------------------
* LIGHTS
*/
/**
* sets directional light
* @param name Individual name
* @param source light position
* @param direction light direction
* @param radius light radius
* @param color light color
*/
public void setDirectionalLight(String name, Point3 source, Vector3 direction, float radius, Color color) {
sunflow.parameter("source", source);
sunflow.parameter("dir", direction);
sunflow.parameter("radius", radius);
sunflow.parameter("radiance", colorSpace, color.getRed()/(float)255, color.getGreen()/(float)255, color.getBlue()/(float)255);
sunflow.light( name, LIGHT_DIRECTIONAL );
}
/**
* Sets Image based light
* @param name Individual name
* @param center Light position
* @param up ?
* @param samples Detail, the higher the slower and smoother
* @param lowSamples ?
* @param texture Path to texture file
*/
public void setImageBasedLight(String name, Vector3 center, Vector3 up, int samples, int lowSamples, String texture) {
sunflow.parameter("center", center);
sunflow.parameter("up", up);
sunflow.parameter("samples", samples);
sunflow.parameter("lowsamples",lowSamples);
sunflow.parameter("texture", texture);
sunflow.light( name, this.LIGHT_IMAGEBASED );
}
/**
* Sets point light
* @param name Individual name
* @param center Light position
* @param color light color
*/
public void setPointLight(String name, Point3 center, Color color) {
sunflow.parameter("center", center);
sunflow.parameter("power", colorSpace, color.getRed()/(float)255, color.getGreen()/(float)255, color.getBlue()/(float)255);
sunflow.light( name, this.LIGHT_POINT );
}
/**
* Sets sphere light
* @param name individual name
* @param center light position
* @param color light color
* @param samples Detail, the highe the smoother and slower
* @param radius light size
*/
public void setSphereLight(String name, Point3 center, Color color, int samples, float radius) {
sunflow.parameter("center", center);
sunflow.parameter("radiance", colorSpace, color.getRed()/(float)255, color.getGreen()/(float)255, color.getBlue()/(float)255);
sunflow.parameter("samples", samples);
sunflow.parameter("radius", radius);
sunflow.light( name, LIGHT_SPHERE );
}
/**
* sets sunsky light
* @param name Individual name
*/
public void setSunSkyLight(String name) {
sunflow.parameter( "up", new Vector3( 0, 0, 1 ) );
sunflow.parameter( "east", new Vector3( 0, 1, 0 ) );
sunflow.parameter( "sundir", new Vector3( 1, -1, 0.31f ) );
sunflow.parameter( "turbidity", 2f );
sunflow.parameter( "samples", 16 );
sunflow.light( name, this.LIGHT_SUNSKY );
}
/**
* sets sunsky light
* @param name Individual name
* @param up ? direction
* @param east ? direction
* @param direction light direction
* @param color light color
* @param samples Detail
* @param turbidity ?
* @param groundExtendSky ?
*/
public void setSunSkyLight(String name, Vector3 up, Vector3 east, Vector3 direction, Color color, int samples, float turbidity, boolean groundExtendSky) {
sunflow.parameter("up", up);
sunflow.parameter("east", east);
sunflow.parameter("sundir", direction);
sunflow.parameter("ground.color", colorSpace, color.getRed()/(float)255, color.getGreen()/(float)255, color.getBlue()/(float)255);
sunflow.parameter("samples", samples);
sunflow.parameter("turbidity", turbidity);
sunflow.parameter("ground.extendsky", groundExtendSky);
sunflow.light( name, this.LIGHT_SUNSKY );
}
/**
* sets mesh light
* @param name Individual name
* @param color light color
* @param samples Detail
* @param vertices Float array with coordinates (like [x0,y0,z0,x1,y1,z1,x2,y2,z2])
* @param triangles int array connecting the vertices (like [0,1,2])
*/
public void drawMeshLight(String name, Color color, int samples, float[] vertices, int[] triangles) {
sunflow.parameter("points", "point", "vertex", vertices);
sunflow.parameter("triangles", triangles);
sunflow.parameter("radiance", colorSpace, color.getRed()/(float)255, color.getGreen()/(float)255, color.getBlue()/(float)255);
sunflow.parameter("samples", samples);
sunflow.light( name, this.LIGHT_MESH);
}
/*
* END OF LIGHTS
* --------------------------------------------------------------------------------------
*/
/*
* --------------------------------------------------------------------------------------
* SHADER
*/
/**
* Sets Ambient Occlusion Shader
* @param name Individual Name
* @param bright Highlight Color
* @param dark Dark Color
* @param samples Detail, the higher the slower and smoother
* @param maxDist ?
*/
public void setAmbientOcclusionShader(String name, Color bright, Color dark, int samples, float maxDist) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("bright", colorSpace, bright.getRed()/(float)255, bright.getGreen()/(float)255, bright.getBlue()/(float)255);
sunflow.parameter("dark", colorSpace, dark.getRed()/(float)255, dark.getGreen()/(float)255, dark.getBlue()/(float)255);
sunflow.parameter("samples", samples);
sunflow.parameter("maxdist", maxDist);
// set shader
sunflow.shader(currShader, SHADER_AMBIENT_OCCLUSION);
}
/**
* Sets Ambient Occlusion Shader
* @param name Individual Name
* @param bright Highlight Color
* @param dark Dark Color
* @param samples Detail, the higher the slower and smoother
* @param maxDist ?
* @param texture Path to texture file
*/
public void setAmbientOcclusionShader(String name, Color bright, Color dark, int samples, float maxDist, String texture) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("bright", colorSpace, bright.getRed()/(float)255, bright.getGreen()/(float)255, bright.getBlue()/(float)255);
sunflow.parameter("dark", colorSpace, dark.getRed()/(float)255, dark.getGreen()/(float)255, dark.getBlue()/(float)255);
sunflow.parameter("samples", samples);
sunflow.parameter("maxdist", maxDist);
sunflow.parameter("texture", texture);
// set shader
sunflow.shader(currShader, SHADER_TEXTURED_AMBIENT_OCCLUSION);
}
/**
* Sets constant shader
* @param name Individual Name
* @param color Color
*/
public void setConstantShader(String name, Color color) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("color", colorSpace, color.getRed()/(float)255, color.getGreen()/(float)255, color.getBlue()/(float)255);
// set shader
sunflow.shader(currShader, SHADER_CONSTANT);
}
/**
* Sets Diffuse Shader
* @param name Individial Name
* @param color Color
*/
public void setDiffuseShader(String name, Color color) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("diffuse", colorSpace, color.getRed()/(float)255, color.getGreen()/(float)255, color.getBlue()/(float)255);
// set shader
sunflow.shader(currShader, SHADER_DIFFUSE);
}
/**
* Sets Diffuse Shader
* @param name Individial Name
* @param color Color
* @param texture Path to texture file
*/
public void setDiffuseShader(String name, Color color, String texture) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("diffuse", colorSpace, color.getRed()/(float)255, color.getGreen()/(float)255, color.getBlue()/(float)255);
sunflow.parameter("texture", texture);
// set shader
sunflow.shader(currShader, SHADER_TEXTURED_DIFFUSE);
}
/**
* Sets Glass Shader
* @param name Individual Name
* @param color Color
* @param eta ?
* @param absorptionDistance ?
* @param absorptionColor Color
*/
public void setGlassShader(String name, Color color, float eta, float absorptionDistance, Color absorptionColor) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("color", colorSpace, color.getRed()/(float)255, color.getGreen()/(float)255, color.getBlue()/(float)255);
sunflow.parameter("eta", eta);
sunflow.parameter("absorption.distance", absorptionDistance);
sunflow.parameter("absorption.color", colorSpace, absorptionColor.getRed()/(float)255, absorptionColor.getGreen()/(float)255, absorptionColor.getBlue()/(float)255);
// set shader
sunflow.shader(currShader, SHADER_GLASS);
}
/**
* Sets Mirror Shader
* @param name Individial Name
* @param color Color
*/
public void setMirrorShader(String name, Color color) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("color", colorSpace, color.getRed()/(float)255, color.getGreen()/(float)255, color.getBlue()/(float)255);
// set shader
sunflow.shader(currShader, SHADER_MIRROR);
}
/**
* Sets Phong Shader
* @param name Individual Name
* @param diffuse Diffuse Color
* @param specular Specular Color
* @param power ?
* @param samples Detail, the higher the slower and smoother
*/
public void setPhongShader(String name, Color diffuse, Color specular, float power, int samples) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("diffuse", colorSpace, diffuse.getRed()/(float)255, diffuse.getGreen()/(float)255, diffuse.getBlue()/(float)255);
sunflow.parameter("specular", colorSpace, specular.getRed()/(float)255, specular.getGreen()/(float)255, specular.getBlue()/(float)255);
sunflow.parameter("power", power);
sunflow.parameter("samples", samples);
// set shader
sunflow.shader(currShader, SHADER_PHONG);
}
/**
* Sets Phong Shader
* @param name Individual Name
* @param diffuse Diffuse Color
* @param specular Specular Color
* @param power ?
* @param samples Detail, the higher the slower and smoother
* @param texture Path to texture file
*/
public void setPhongShader(String name, Color diffuse, Color specular, float power, int samples, String texture) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("diffuse", colorSpace, diffuse.getRed()/(float)255, diffuse.getGreen()/(float)255, diffuse.getBlue()/(float)255);
sunflow.parameter("specular", colorSpace, specular.getRed()/(float)255, specular.getGreen()/(float)255, specular.getBlue()/(float)255);
sunflow.parameter("power", power);
sunflow.parameter("samples", samples);
sunflow.parameter("texture", texture);
// set shader
sunflow.shader(currShader, SHADER_TEXTURED_PHONG);
}
/**
* Sets Shiny Diffuse Shader
* @param name Individual Name
* @param color Color
* @param shiny shinyness, the bigger the more
*/
public void setShinyDiffuseShader(String name, Color color, float shiny) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("diffuse", colorSpace, color.getRed()/(float)255, color.getGreen()/(float)255, color.getBlue()/(float)255);
sunflow.parameter("shiny", shiny);
// set shader
sunflow.shader(currShader, SHADER_SHINY_DIFFUSE);
}
/**
* Sets Shiny Diffuse Shader
* @param name Individual Name
* @param color Color
* @param shiny shinyness, the bigger the more
* @param texture Path to texture file
*/
public void setShinyDiffuseShader(String name, Color color, float shiny, String texture) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("diffuse", colorSpace, color.getRed()/(float)255, color.getGreen()/(float)255, color.getBlue()/(float)255);
sunflow.parameter("shiny", shiny);
sunflow.parameter("texture", texture);
// set shader
sunflow.shader(currShader, SHADER_TEXTURED_SHINY_DIFFUSE);
}
/**
* Sets Uber Shader
* @param name Individual Name
* @param diffuse Diffuse Color
* @param specular Specular Color
* @param diffuseTexture Diffuse Texture
* @param specularTexture Specular Texture
* @param diffuseBlend Diffuse Blendamount
* @param specularBlend Specular Blendamount
* @param glossyness glossyness
* @param samples samples
*/
public void setUberShader(String name, Color diffuse, Color specular, String diffuseTexture, String specularTexture, float diffuseBlend, float specularBlend, float glossyness, int samples) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("diffuse", colorSpace, diffuse.getRed()/(float)255, diffuse.getGreen()/(float)255, diffuse.getBlue()/(float)255);
sunflow.parameter("specular", colorSpace, specular.getRed()/(float)255, specular.getGreen()/(float)255, specular.getBlue()/(float)255);
sunflow.parameter("diffuse.texture", diffuseTexture);
sunflow.parameter("specular.texture", specularTexture);
sunflow.parameter("diffuse.blend", diffuseBlend);
sunflow.parameter("specular.blend", specularBlend);
sunflow.parameter("glossyness", glossyness);
sunflow.parameter("samples", samples);
// set shader
sunflow.shader(currShader, SHADER_UBER);
}
/**
* Sets Anisotropic Ward Shader
* @param name Individual Name
* @param diffuse Diffuse Color
* @param specular Specular Color
* @param roughnessX Roughness in x axis
* @param roughnessY Roughness in y axis
* @param samples Detail, the more the slower and smoother
*/
public void setWardShader(String name, Color diffuse, Color specular, float roughnessX, float roughnessY, int samples) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("diffuse", colorSpace, diffuse.getRed()/(float)255, diffuse.getGreen()/(float)255, diffuse.getBlue()/(float)255);
sunflow.parameter("specular", colorSpace, specular.getRed()/(float)255, specular.getGreen()/(float)255, specular.getBlue()/(float)255);
sunflow.parameter("roughnessX", roughnessX);
sunflow.parameter("roughnessY", roughnessY);
sunflow.parameter("samples", samples);
// set shader
sunflow.shader(currShader, SHADER_WARD);
}
/**
* Sets Anisotropic Ward Shader
* @param name Individual Name
* @param diffuse Diffuse Color
* @param specular Specular Color
* @param roughnessX Roughness in x axis
* @param roughnessY Roughness in y axis
* @param samples Detail, the more the slower and smoother
* @param texture Path to texture file
*/
public void setWardShader(String name, Color diffuse, Color specular, float roughnessX, float roughnessY, int samples, String texture) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("diffuse", colorSpace, diffuse.getRed()/(float)255, diffuse.getGreen()/(float)255, diffuse.getBlue()/(float)255);
sunflow.parameter("specular", colorSpace, specular.getRed()/(float)255, specular.getGreen()/(float)255, specular.getBlue()/(float)255);
sunflow.parameter("roughnessX", roughnessX);
sunflow.parameter("roughnessY", roughnessY);
sunflow.parameter("samples", samples);
sunflow.parameter("texture", texture);
// set shader
sunflow.shader(currShader, SHADER_TEXTURED_WARD);
}
/**
* Sets Wireframe Shader
* @param name Individual Name
* @param lineColor line color
* @param fillColor fill color
* @param width stroke width ?
*/
public void setWireframeShader(String name, Color lineColor, Color fillColor, float width) {
// save name for use with primitives
currShader = name;
// set parameter
sunflow.parameter("line", colorSpace, lineColor.getRed()/(float)255, lineColor.getGreen()/(float)255, lineColor.getBlue()/(float)255);
sunflow.parameter("fill", colorSpace, fillColor.getRed()/(float)255, fillColor.getGreen()/(float)255, fillColor.getBlue()/(float)255);
sunflow.parameter("width", width);
// set shader
sunflow.shader(currShader, SHADER_WIREFRAME);
}
/*
* END OF SHADER
* --------------------------------------------------------------------------------------
*/
/*
* --------------------------------------------------------------------------------------
* MODIFIERS
*/
public void setPerlinModifier(String name, int function, float size, float scale) {
currModifier = name + modifiercount;
modifierType = MODIFIER_PERLIN_MAP;
sunflow.parameter("function", function);
sunflow.parameter("size", size);
sunflow.parameter("scale", scale);
sunflow.modifier(currModifier, modifierType);
modifiercount++;
isModifiers = true;
}
/*
* END OF MODIFIERS
* --------------------------------------------------------------------------------------
*/
/*
* --------------------------------------------------------------------------------------
* PRIMITIVES
*/
/**
* draws a mesh primitive
* @param name individual name of primitive
* @param vertices Float array with coordinates (like [x0,y0,z0,x1,y1,z1,x2,y2,z2])
* @param triangles int array connecting the vertices (like [0,1,2])
*/
public void drawMesh(String name, float[] vertices, int[] triangles) {
sunflow.parameter("points", "point", "vertex", vertices);
sunflow.parameter("triangles", triangles);
sunflow.geometry( name, "triangle_mesh" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.instance( name + ".instance", name );
}
/**
* draws a mesh primitive which can be rotated and scaled
* @param name individual name of primitive
* @param vertices Float array with coordinates (like [x0,y0,z0,x1,y1,z1,x2,y2,z2])
* @param triangles int array connecting the vertices (like [0,1,2])
* @param size size
* @param xRotation x rotation
* @param yRotation y rotation
* @param zRotation z rotation
*/
public void drawMesh(String name, float[] vertices, int[] triangles, float size, float xRotation, float yRotation, float zRotation) {
Matrix4 scale = Matrix4.IDENTITY.multiply( Matrix4.scale(size, size, size) );
Matrix4 rotate = Matrix4.IDENTITY
.multiply( Matrix4.rotateZ(zRotation) )
.multiply( Matrix4.rotateX(xRotation) )
.multiply( Matrix4.rotateY(yRotation) );
Matrix4 m = Matrix4.IDENTITY;
m = scale.multiply(m);
m = rotate.multiply(m);
sunflow.parameter("points", "point", "vertex", vertices);
sunflow.parameter("triangles", triangles);
sunflow.geometry( name, "triangle_mesh" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.parameter( "transform", m );
sunflow.instance( name + ".instance", name );
}
/**
* draws a bezier patch
* @param name individual name of primitive
* @param subdivs int value of how much subdivisions
* @param smooth boolean is bezier patch set to smooth
* @param quads boolean if patch uses quads
* @param nu number of points in vertical direction
* @param nv number of points in horizontal direction
* @param uwrap boolean ? best is to use false
* @param vwrap boolean ? best is to use false
* @param points Float array with coordinates (like [x0,y0,z0,x1,y1,z1,x2,y2,z2])
*/
public void drawBezierMesh(String name, int subdivs, boolean smooth, boolean quads, int nu, int nv, boolean uwrap, boolean vwrap, float[] points) {
sunflow.parameter("subdivs", subdivs);
sunflow.parameter("smooth", smooth);
sunflow.parameter("quads", quads);
sunflow.parameter("nu", nu);
sunflow.parameter("nv", nv);
sunflow.parameter("uwrap", uwrap);
sunflow.parameter("vwrap", vwrap);
sunflow.parameter("points", "point", "vertex", points);
sunflow.geometry( name, "bezier_mesh" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.instance( name + ".instance", name );
}
/**
* draws a sphere
* @param name Individual name
*/
public void drawSphere(String name) {
sunflow.geometry( name, "sphere" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.instance( name + ".instance", name );
}
/**
* draws a sphere
* @param name Individual name
* @param x x position
* @param y y position
* @param z z position
* @param size size
*/
public void drawSphere(String name, float x, float y, float z, float size) {
Matrix4 translate = Matrix4.IDENTITY.multiply( Matrix4.translation(x, y, z ));
Matrix4 scale = Matrix4.IDENTITY.multiply( Matrix4.scale(size, size, size) );
Matrix4 m = Matrix4.IDENTITY;
m = scale.multiply(m);
m = translate.multiply(m);
sunflow.geometry( name, "sphere" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.parameter( "transform", m );
sunflow.instance( name + ".instance", name );
}
/**
* Draws a box
* @param name Individual name
*/
public void drawBox(String name) {
sunflow.geometry( name, "box" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.instance( name + ".instance", name );
}
/**
* Draws a box
* @param name
* @param name Individual name
* @param x x position
* @param y y position
* @param z z position
* @param size size
*/
public void drawBox(String name, float x, float y, float z, float size) {
Matrix4 translate = Matrix4.IDENTITY.multiply( Matrix4.translation(x, y, z ));
Matrix4 scale = Matrix4.IDENTITY.multiply( Matrix4.scale(size, size, size) );
Matrix4 m = Matrix4.IDENTITY;
m = scale.multiply(m);
m = translate.multiply(m);
sunflow.geometry( name, "box" );
sunflow.parameter( "shaders", currShader);
sunflow.parameter( "transform", m );
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.instance( name + ".instance", name );
}
/**
* Draws a box
* @param name
* @param name Individual name
* @param x x position
* @param y y position
* @param z z position
* @param size size
* @param xRotation x rotation
* @param yRotation y rotation
* @param zRotation z rotation
*/
public void drawBox(String name, float size, float x, float y, float z, float xRotation, float yRotation, float zRotation) {
Matrix4 translate = Matrix4.IDENTITY.multiply( Matrix4.translation(x, y, z ));
Matrix4 scale = Matrix4.IDENTITY.multiply( Matrix4.scale(size, size, size) );
Matrix4 rotate = Matrix4.IDENTITY
.multiply( Matrix4.rotateZ(zRotation) )
.multiply( Matrix4.rotateX(xRotation) )
.multiply( Matrix4.rotateY(yRotation) );
Matrix4 m = Matrix4.IDENTITY;
m = scale.multiply(m);
m = rotate.multiply(m);
m = translate.multiply(m);
sunflow.geometry( name, "box" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.parameter( "transform", m );
sunflow.instance( name + ".instance", name );
}
/**
* Draws a box
* @param name
* @param name Individual name
* @param xSize size on x axis
* @param ySize size on y axis
* @param zSize size on z axis
* @param x x position
* @param y y position
* @param z z position
* @param xRotation x rotation
* @param yRotation y rotation
* @param zRotation z rotation
*/
public void drawBox(String name, float xSize, float ySize, float zSize, float x, float y, float z, float xRotation, float yRotation, float zRotation) {
Matrix4 translate = Matrix4.IDENTITY.multiply( Matrix4.translation(x, y, z ));
Matrix4 scale = Matrix4.IDENTITY.multiply( Matrix4.scale(xSize, ySize, zSize) );
Matrix4 rotate = Matrix4.IDENTITY
.multiply( Matrix4.rotateZ(zRotation) )
.multiply( Matrix4.rotateX(xRotation) )
.multiply( Matrix4.rotateY(yRotation) );
Matrix4 m = Matrix4.IDENTITY;
m = scale.multiply(m);
m = rotate.multiply(m);
m = translate.multiply(m);
sunflow.geometry( name, "box" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.parameter( "transform", m );
sunflow.instance( name + ".instance", name );
}
/**
* Draws a cylinder
* @param name Individual name
*/
public void drawCylinder(String name) {
sunflow.geometry( name, "cylinder" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.instance( name + ".instance", name );
}
/**
* Draws a cylinder
* @param name Individual name
* @param x x position
* @param y y position
* @param z z position
* @param size size
*/
public void drawCylinder(String name, float x, float y, float z, float size) {
Matrix4 translate = Matrix4.IDENTITY.multiply( Matrix4.translation(x, y, z ));
Matrix4 scale = Matrix4.IDENTITY.multiply( Matrix4.scale(size, size, size) );
Matrix4 m = Matrix4.IDENTITY;
m = scale.multiply(m);
m = translate.multiply(m);
sunflow.geometry( name, "cylinder" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.parameter( "transform", m );
sunflow.instance( name + ".instance", name );
}
/**
* Draws a cylinder
* @param name Individual name
* @param x x position
* @param y y position
* @param z z position
* @param size size
* @param xRotation x rotation
* @param yRotation y rotation
* @param zRotation z rotation
*/
public void drawCylinder(String name, float x, float y, float z, float size, float xRotation, float yRotation, float zRotation) {
Matrix4 translate = Matrix4.IDENTITY.multiply( Matrix4.translation(x, y, z ));
Matrix4 scale = Matrix4.IDENTITY.multiply( Matrix4.scale(size, size, size) );
Matrix4 rotate = Matrix4.IDENTITY
.multiply( Matrix4.rotateZ(zRotation) )
.multiply( Matrix4.rotateX(xRotation) )
.multiply( Matrix4.rotateY(yRotation) );
Matrix4 m = Matrix4.IDENTITY;
m = scale.multiply(m);
m = rotate.multiply(m);
m = translate.multiply(m);
sunflow.geometry( name, "cylinder" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.parameter( "transform", m );
sunflow.instance( name + ".instance", name );
}
/**
* Draws a Cylinder
* @param name
* @param name Individual name
* @param xSize size on x axis
* @param ySize size on y axis
* @param zSize size on z axis
* @param x x position
* @param y y position
* @param z z position
* @param xRotation x rotation
* @param yRotation y rotation
* @param zRotation z rotation
*/
public void drawCylinder(String name, float xSize, float ySize, float zSize, float x, float y, float z, float xRotation, float yRotation, float zRotation) {
Matrix4 translate = Matrix4.IDENTITY.multiply( Matrix4.translation(x, y, z ));
Matrix4 scale = Matrix4.IDENTITY.multiply( Matrix4.scale(xSize, ySize, zSize) );
Matrix4 rotate = Matrix4.IDENTITY
.multiply( Matrix4.rotateZ(zRotation) )
.multiply( Matrix4.rotateX(xRotation) )
.multiply( Matrix4.rotateY(yRotation) );
Matrix4 m = Matrix4.IDENTITY;
m = scale.multiply(m);
m = rotate.multiply(m);
m = translate.multiply(m);
sunflow.geometry( name, "cylinder" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.parameter( "transform", m );
sunflow.instance( name + ".instance", name );
}
/**
* Draws a Banchoff Surface
* @param name Individual name
*/
public void drawBanchoffSurface(String name) {
sunflow.geometry( name, "banchoff" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.instance( name + ".instance", name );
}
/**
* Draws a Banchoff Surface
* @param name Individual name
* @param x x position
* @param y y position
* @param z z position
* @param size size
*/
public void drawBanchoffSurface(String name, float x, float y, float z, float size) {
Matrix4 translate = Matrix4.IDENTITY.multiply( Matrix4.translation(x, y, z ));
Matrix4 scale = Matrix4.IDENTITY.multiply( Matrix4.scale(size, size, size) );
Matrix4 m = Matrix4.IDENTITY;
m = scale.multiply(m);
m = translate.multiply(m);
sunflow.geometry( name, "banchoff" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.parameter( "transform", m );
sunflow.instance( name + ".instance", name );
}
/**
* Draws a Banchoff Surface
* @param name Individual name
* @param x x position
* @param y y position
* @param z z position
* @param size size
* @param xRotation x rotation
* @param yRotation y rotation
* @param zRotation z rotation
*/
public void drawBanchoffSurface(String name, float x, float y, float z, float size, float xRotation, float yRotation, float zRotation) {
Matrix4 translate = Matrix4.IDENTITY.multiply( Matrix4.translation(x, y, z ));
Matrix4 scale = Matrix4.IDENTITY.multiply( Matrix4.scale(size, size, size) );
Matrix4 rotate = Matrix4.IDENTITY
.multiply( Matrix4.rotateZ(zRotation) )
.multiply( Matrix4.rotateX(xRotation) )
.multiply( Matrix4.rotateY(yRotation) );
Matrix4 m = Matrix4.IDENTITY;
m = scale.multiply(m);
m = rotate.multiply(m);
m = translate.multiply(m);
sunflow.geometry( name, "banchoff" );
sunflow.parameter( "shaders", currShader);
if(isModifiers) sunflow.parameter("modifiers", currModifier);
sunflow.parameter( "transform", m );
sunflow.instance( name + ".instance", name );
}
/**
* Draws a Julia
* @param name Individual name
* @param x x position
* @param y y position
* @param z z position
* @param size size