Normand Briere
2019-07-30 475f8cbdbd96fdbf8f5b216ffebb31a51f25c2f9
CameraPane.java
....@@ -187,6 +187,18 @@
187187 }
188188
189189 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
190202
191203 void SetAsGLRenderer(boolean b)
192204 {
....@@ -1485,6 +1497,8 @@
14851497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14861498 }
14871499
1500
+ float[] colorV = new float[4];
1501
+
14881502 void SetColor(Object3D obj, Vertex p0)
14891503 {
14901504 CameraPane display = this;
....@@ -1552,8 +1566,6 @@
15521566 {
15531567 return;
15541568 }
1555
-
1556
- float[] colorV = new float[3];
15571569
15581570 if (false) // marked)
15591571 {
....@@ -8932,7 +8944,7 @@
89328944
89338945 if (cubemap == null)
89348946 {
8935
- LoadEnvy(5);
8947
+ //LoadEnvy(1);
89368948 }
89378949
89388950 //cubemap.enable();
....@@ -9219,37 +9231,58 @@
92199231 cubemap = null;
92209232 return;
92219233 case 1:
9222
- name = "cubemaps/box_";
9223
- ext = "png";
9234
+ name = "cubemaps/rgb/";
9235
+ ext = "jpg";
92249236 reverseUP = false;
92259237 break;
92269238 case 2:
9227
- name = "cubemaps/uffizi_";
9228
- ext = "png";
9229
- break; // reverseUP = true; break;
9239
+ name = "cubemaps/uffizi/";
9240
+ ext = "jpg";
9241
+ reverseUP = false;
9242
+ break;
92309243 case 3:
9231
- name = "cubemaps/CloudyHills_";
9232
- ext = "tga";
9244
+ name = "cubemaps/CloudyHills/";
9245
+ ext = "jpg";
92339246 reverseUP = false;
92349247 break;
92359248 case 4:
9236
- name = "cubemaps/cornell_";
9249
+ name = "cubemaps/cornell/";
92379250 ext = "png";
92389251 reverseUP = false;
92399252 break;
9253
+ case 5:
9254
+ name = "cubemaps/skycube/";
9255
+ ext = "jpg";
9256
+ reverseUP = false;
9257
+ break;
9258
+ case 6:
9259
+ name = "cubemaps/SaintLazarusChurch3/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
9263
+ case 7:
9264
+ name = "cubemaps/Sodermalmsallen/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 8:
9269
+ name = "cubemaps/Sodermalmsallen2/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 9:
9274
+ name = "cubemaps/UnionSquare/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
92409278 default:
9241
- name = "cubemaps/rgb_";
9242
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9279
+ name = "cubemaps/box/";
9280
+ ext = "png"; /*mipmap = true;*/
9281
+ reverseUP = false;
92439282 break;
92449283 }
9245
-
9246
- try
9247
- {
9248
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9249
- } catch (IOException e)
9250
- {
9251
- throw new RuntimeException(e);
9252
- }
9284
+
9285
+ LoadSkybox(name, ext, mipmap);
92539286 }
92549287
92559288 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9281,8 +9314,12 @@
92819314 static double[] model = new double[16];
92829315 double[] camera2light = new double[16];
92839316 double[] light2camera = new double[16];
9284
- int newenvy = -1;
9285
- boolean envyoff = true; // false;
9317
+
9318
+ //int newenvy = -1;
9319
+ //boolean envyoff = false;
9320
+
9321
+ String loadedskyboxname;
9322
+
92869323 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92879324 //float[] light0 = { 0,0,0 };
92889325 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9762,10 +9799,12 @@
97629799 rati = 1 / rati;
97639800 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
97649801 }
9765
- assert (newenvy == -1);
9802
+
9803
+ //assert (newenvy == -1);
9804
+
97669805 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
97679806 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9768
- DrawSkyBox(gl);
9807
+ DrawSkyBox(gl, (float)rati);
97699808 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
97709809 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
97719810 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -11018,13 +11057,27 @@
1101811057 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1101911058 }
1102011059
11021
- if (newenvy > -1)
11060
+// if (newenvy > -1)
11061
+// {
11062
+// LoadEnvy(newenvy);
11063
+// }
11064
+//
11065
+// newenvy = -1;
11066
+
11067
+ if (object.skyboxname != null)
1102211068 {
11023
- LoadEnvy(newenvy);
11069
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11070
+ {
11071
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11072
+ loadedskyboxname = object.skyboxname;
11073
+ }
1102411074 }
11025
-
11026
- newenvy = -1;
11027
-
11075
+ else
11076
+ {
11077
+ cubemap = null;
11078
+ loadedskyboxname = null;
11079
+ }
11080
+
1102811081 ratio = ((double) getWidth()) / getHeight();
1102911082 //System.out.println("ratio = " + ratio);
1103011083
....@@ -11040,7 +11093,7 @@
1104011093
1104111094 if (!IsFrozen() && !ambientOcclusion)
1104211095 {
11043
- DrawSkyBox(gl);
11096
+ DrawSkyBox(gl, (float)ratio);
1104411097 }
1104511098
1104611099 //if (selection_view == -1)
....@@ -12400,7 +12453,7 @@
1240012453
1240112454 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240212455
12403
- String program =
12456
+ String program0 =
1240412457 // Min shader
1240512458 "!!ARBfp1.0\n" +
1240612459 "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
....@@ -12451,7 +12504,8 @@
1245112504 //"SUB ndotl.y, zero123.y, ndotl.y;" +
1245212505 //"MUL ndotl.y, ndotl.y, pow2.z;" +
1245312506
12454
- "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12507
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12508
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
1245512509
1245612510 // Pigment
1245712511 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
....@@ -12466,7 +12520,7 @@
1246612520 "MOV result.color, temp;" +
1246712521 "END";
1246812522
12469
- String program2 =
12523
+ String program =
1247012524 "!!ARBfp1.0\n" +
1247112525
1247212526 //"OPTION ARB_fragment_program_shadow;" +
....@@ -12991,7 +13045,7 @@
1299113045 // display shadow only (fakedepth == 0)
1299213046 "SUB temp.x, half.x, shadow.x;" +
1299313047 "MOV temp.y, -params5.z;" + // params6.x;" +
12994
- "SLT temp.z, temp.y, -one2048th.x;" +
13048
+ "SLT temp.z, temp.y, -c256i.x;" +
1299513049 "SUB temp.y, one.x, temp.z;" +
1299613050 "MUL temp.x, temp.x, temp.y;" +
1299713051 "KIL temp.x;" +
....@@ -15315,20 +15369,24 @@
1531515369 OCCLUSION_CULLING ^= true;
1531615370 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1531715371 break;
15318
- case '0': envyoff ^= true; repaint(); break;
15372
+ //case '0': envyoff ^= true; repaint(); break;
1531915373 case '1':
1532015374 case '2':
1532115375 case '3':
1532215376 case '4':
1532315377 case '5':
15324
- newenvy = Character.getNumericValue(key);
15325
- repaint();
15326
- break;
1532715378 case '6':
1532815379 case '7':
1532915380 case '8':
1533015381 case '9':
15331
- BGcolor = (key - '6')/3.f;
15382
+ if (true) // envyoff)
15383
+ {
15384
+ BGcolor = (key - '1')/8.f;
15385
+ }
15386
+ else
15387
+ {
15388
+ //newenvy = Character.getNumericValue(key);
15389
+ }
1533215390 repaint();
1533315391 break;
1533415392 case '!':
....@@ -16519,6 +16577,8 @@
1651916577 private /*static*/ boolean firstime;
1652016578 private /*static*/ cVector newView = new cVector();
1652116579 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16580
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16581
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1652216582 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1652316583 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1652416584 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16531,29 +16591,66 @@
1653116591 {
1653216592 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1653316593
16594
+ int usedsuf = 0;
16595
+
1653416596 for (int i = 0; i < suffixes.length; i++)
1653516597 {
16536
- String resourceName = basename + suffixes[i] + "." + suffix;
16537
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16538
- mipmapped,
16539
- FileUtil.getFileSuffix(resourceName));
16540
- if (data == null)
16598
+ String[] suffixe = suffixes;
16599
+ String[] fallback = suffixes2;
16600
+ String[] fallfallback = suffixes3;
16601
+
16602
+ for (int c=usedsuf; --c>=0;)
1654116603 {
16542
- throw new IOException("Unable to load texture " + resourceName);
16604
+// String[] temp = suffixe;
16605
+// suffixe = fallback;
16606
+// fallback = fallfallback;
16607
+// fallfallback = temp;
1654316608 }
16609
+
16610
+ String resourceName = basename + suffixe[i] + "." + suffix;
16611
+ TextureData data;
16612
+
16613
+ try
16614
+ {
16615
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16616
+ mipmapped,
16617
+ FileUtil.getFileSuffix(resourceName));
16618
+ }
16619
+ catch (Exception e)
16620
+ {
16621
+ try
16622
+ {
16623
+ resourceName = basename + fallback[i] + "." + suffix;
16624
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16625
+ mipmapped,
16626
+ FileUtil.getFileSuffix(resourceName));
16627
+ }
16628
+ catch (Exception e2)
16629
+ {
16630
+ resourceName = basename + fallfallback[i] + "." + suffix;
16631
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16632
+ mipmapped,
16633
+ FileUtil.getFileSuffix(resourceName));
16634
+ }
16635
+ }
16636
+
1654416637 //System.out.println("Target = " + targets[i]);
1654516638 cubemap.updateImage(data, targets[i]);
1654616639 }
1654716640
1654816641 return cubemap;
1654916642 }
16643
+
1655016644 int bigsphere = -1;
1655116645
1655216646 float BGcolor = 0.5f;
1655316647
16554
- private void DrawSkyBox(GL gl)
16648
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16649
+
16650
+ private void DrawSkyBox(GL gl, float ratio)
1655516651 {
16556
- if (envyoff || cubemap == null)
16652
+ if (//envyoff ||
16653
+ cubemap == null)
1655716654 {
1655816655 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1655916656 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16568,7 +16665,17 @@
1656816665 // Compensates for ExaminerViewer's modification of modelview matrix
1656916666 gl.glMatrixMode(GL.GL_MODELVIEW);
1657016667 gl.glLoadIdentity();
16668
+ gl.glScalef(1,ratio,1);
1657116669
16670
+ colorV[0] = 2;
16671
+ colorV[1] = 2;
16672
+ colorV[2] = 2;
16673
+ colorV[3] = 1;
16674
+ gl.glDisable(gl.GL_COLOR_MATERIAL);
16675
+ gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16676
+
16677
+ gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16678
+
1657216679 //gl.glActiveTexture(GL.GL_TEXTURE1);
1657316680 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1657416681
....@@ -16581,7 +16688,7 @@
1658116688 // GL_NORMAL_MAP texgen mode. Temporarily enabling lighting
1658216689 // causes the normals to be sent down. Thanks to Ken Dyke.
1658316690 //gl.glEnable(GL.GL_LIGHTING);
16584
- gl.glDisable(GL.GL_LIGHTING);
16691
+ gl.glEnable(GL.GL_LIGHTING);
1658516692
1658616693 gl.glTexGeni(GL.GL_S, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
1658716694 gl.glTexGeni(GL.GL_T, GL.GL_TEXTURE_GEN_MODE, GL.GL_NORMAL_MAP);
....@@ -16600,6 +16707,7 @@
1660016707 {
1660116708 gl.glScalef(1.0f, -1.0f, 1.0f);
1660216709 }
16710
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1660316711 gl.glMultMatrixd(viewrot_1, 0);
1660416712 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1660516713 //viewer.updateInverseRotation(gl);
....@@ -16858,7 +16966,7 @@
1685816966 //new Exception().printStackTrace();
1685916967 System.out.println("select buffer init");
1686016968 // Use debug pipeline
16861
- drawable.setGL(new DebugGL(drawable.getGL()));
16969
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1686216970
1686316971 GL gl = drawable.getGL();
1686416972