Normand Briere
2019-08-12 b1d79b74514041a059b454a9f6fc3970773c0cb8
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 {
....@@ -8346,7 +8358,7 @@
83468358 // else
83478359 // if (!texname.startsWith("/"))
83488360 // texname = "/Users/nbriere/Textures/" + texname;
8349
- if (!FileExists(texname))
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
83508362 {
83518363 texname = fallbackTextureName;
83528364 }
....@@ -8429,6 +8441,15 @@
84298441 new Exception().printStackTrace();
84308442 } else
84318443 {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8449
+ else
8450
+ new Exception().printStackTrace();
8451
+ } else
8452
+ {
84328453 if (textureon)
84338454 {
84348455 String cachename = texname;
....@@ -8488,6 +8509,7 @@
84888509 texturecache = new CacheTexture(texturedata,resolution);
84898510 //texture = GetTexture(tex, bump);
84908511 }
8512
+ }
84918513 }
84928514 //}
84938515 }
....@@ -8932,7 +8954,7 @@
89328954
89338955 if (cubemap == null)
89348956 {
8935
- LoadEnvy(5);
8957
+ //LoadEnvy(1);
89368958 }
89378959
89388960 //cubemap.enable();
....@@ -9219,37 +9241,58 @@
92199241 cubemap = null;
92209242 return;
92219243 case 1:
9222
- name = "cubemaps/box_";
9223
- ext = "png";
9244
+ name = "cubemaps/rgb/";
9245
+ ext = "jpg";
92249246 reverseUP = false;
92259247 break;
92269248 case 2:
9227
- name = "cubemaps/uffizi_";
9228
- ext = "png";
9229
- break; // reverseUP = true; break;
9249
+ name = "cubemaps/uffizi/";
9250
+ ext = "jpg";
9251
+ reverseUP = false;
9252
+ break;
92309253 case 3:
9231
- name = "cubemaps/CloudyHills_";
9232
- ext = "tga";
9254
+ name = "cubemaps/CloudyHills/";
9255
+ ext = "jpg";
92339256 reverseUP = false;
92349257 break;
92359258 case 4:
9236
- name = "cubemaps/cornell_";
9259
+ name = "cubemaps/cornell/";
92379260 ext = "png";
92389261 reverseUP = false;
92399262 break;
9263
+ case 5:
9264
+ name = "cubemaps/skycube/";
9265
+ ext = "jpg";
9266
+ reverseUP = false;
9267
+ break;
9268
+ case 6:
9269
+ name = "cubemaps/SaintLazarusChurch3/";
9270
+ ext = "jpg";
9271
+ reverseUP = false;
9272
+ break;
9273
+ case 7:
9274
+ name = "cubemaps/Sodermalmsallen/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 8:
9279
+ name = "cubemaps/Sodermalmsallen2/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 9:
9284
+ name = "cubemaps/UnionSquare/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
92409288 default:
9241
- name = "cubemaps/rgb_";
9242
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9289
+ name = "cubemaps/box/";
9290
+ ext = "png"; /*mipmap = true;*/
9291
+ reverseUP = false;
92439292 break;
92449293 }
9245
-
9246
- try
9247
- {
9248
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9249
- } catch (IOException e)
9250
- {
9251
- throw new RuntimeException(e);
9252
- }
9294
+
9295
+ LoadSkybox(name, ext, mipmap);
92539296 }
92549297
92559298 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9281,8 +9324,12 @@
92819324 static double[] model = new double[16];
92829325 double[] camera2light = new double[16];
92839326 double[] light2camera = new double[16];
9284
- int newenvy = -1;
9285
- boolean envyoff = true; // false;
9327
+
9328
+ //int newenvy = -1;
9329
+ //boolean envyoff = false;
9330
+
9331
+ String loadedskyboxname;
9332
+
92869333 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92879334 //float[] light0 = { 0,0,0 };
92889335 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9762,10 +9809,12 @@
97629809 rati = 1 / rati;
97639810 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
97649811 }
9765
- assert (newenvy == -1);
9812
+
9813
+ //assert (newenvy == -1);
9814
+
97669815 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
97679816 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9768
- DrawSkyBox(gl);
9817
+ DrawSkyBox(gl, (float)rati);
97699818 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
97709819 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
97719820 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10802,7 +10851,7 @@
1080210851
1080310852 if (wait)
1080410853 {
10805
- Sleep(500);
10854
+ Sleep(200); // blocks everything
1080610855
1080710856 wait = false;
1080810857 }
....@@ -11018,13 +11067,27 @@
1101811067 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1101911068 }
1102011069
11021
- if (newenvy > -1)
11070
+// if (newenvy > -1)
11071
+// {
11072
+// LoadEnvy(newenvy);
11073
+// }
11074
+//
11075
+// newenvy = -1;
11076
+
11077
+ if (object.skyboxname != null)
1102211078 {
11023
- LoadEnvy(newenvy);
11079
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11080
+ {
11081
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11082
+ loadedskyboxname = object.skyboxname;
11083
+ }
1102411084 }
11025
-
11026
- newenvy = -1;
11027
-
11085
+ else
11086
+ {
11087
+ cubemap = null;
11088
+ loadedskyboxname = null;
11089
+ }
11090
+
1102811091 ratio = ((double) getWidth()) / getHeight();
1102911092 //System.out.println("ratio = " + ratio);
1103011093
....@@ -11040,7 +11103,7 @@
1104011103
1104111104 if (!IsFrozen() && !ambientOcclusion)
1104211105 {
11043
- DrawSkyBox(gl);
11106
+ DrawSkyBox(gl, (float)ratio);
1104411107 }
1104511108
1104611109 //if (selection_view == -1)
....@@ -11326,7 +11389,7 @@
1132611389
1132711390 // if (cam != lightCamera)
1132811391 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11329
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11392
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1133011393 }
1133111394
1133211395 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -12400,7 +12463,7 @@
1240012463
1240112464 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240212465
12403
- String program =
12466
+ String programmin =
1240412467 // Min shader
1240512468 "!!ARBfp1.0\n" +
1240612469 "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
....@@ -12451,7 +12514,8 @@
1245112514 //"SUB ndotl.y, zero123.y, ndotl.y;" +
1245212515 //"MUL ndotl.y, ndotl.y, pow2.z;" +
1245312516
12454
- "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12517
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12518
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
1245512519
1245612520 // Pigment
1245712521 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
....@@ -12466,7 +12530,7 @@
1246612530 "MOV result.color, temp;" +
1246712531 "END";
1246812532
12469
- String program2 =
12533
+ String programmax =
1247012534 "!!ARBfp1.0\n" +
1247112535
1247212536 //"OPTION ARB_fragment_program_shadow;" +
....@@ -12991,7 +13055,7 @@
1299113055 // display shadow only (fakedepth == 0)
1299213056 "SUB temp.x, half.x, shadow.x;" +
1299313057 "MOV temp.y, -params5.z;" + // params6.x;" +
12994
- "SLT temp.z, temp.y, -one2048th.x;" +
13058
+ "SLT temp.z, temp.y, -c256i.x;" +
1299513059 "SUB temp.y, one.x, temp.z;" +
1299613060 "MUL temp.x, temp.x, temp.y;" +
1299713061 "KIL temp.x;" +
....@@ -13322,6 +13386,13 @@
1332213386 //once = true;
1332313387 }
1332413388
13389
+ String program = programmax;
13390
+
13391
+ if (Globals.MINSHADER)
13392
+ {
13393
+ program = programmin;
13394
+ }
13395
+
1332513396 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1332613397 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1332713398 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -14571,9 +14642,9 @@
1457114642 MODIFIERS |= COMMAND;
1457214643 /**/
1457314644 if((mod&SHIFT) == SHIFT)
14574
- manipCamera.RotatePosition(0, -speed);
14575
- else
1457614645 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14646
+ else
14647
+ manipCamera.RotatePosition(0, -speed);
1457714648 /**/
1457814649 if ((mod & SHIFT) == SHIFT)
1457914650 {
....@@ -14592,9 +14663,9 @@
1459214663 MODIFIERS |= COMMAND;
1459314664 /**/
1459414665 if((mod&SHIFT) == SHIFT)
14595
- manipCamera.RotatePosition(0, speed);
14596
- else
1459714666 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14667
+ else
14668
+ manipCamera.RotatePosition(0, speed);
1459814669 /**/
1459914670 if ((mod & SHIFT) == SHIFT)
1460014671 {
....@@ -15315,20 +15386,24 @@
1531515386 OCCLUSION_CULLING ^= true;
1531615387 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1531715388 break;
15318
- case '0': envyoff ^= true; repaint(); break;
15389
+ //case '0': envyoff ^= true; repaint(); break;
1531915390 case '1':
1532015391 case '2':
1532115392 case '3':
1532215393 case '4':
1532315394 case '5':
15324
- newenvy = Character.getNumericValue(key);
15325
- repaint();
15326
- break;
1532715395 case '6':
1532815396 case '7':
1532915397 case '8':
1533015398 case '9':
15331
- BGcolor = (key - '6')/3.f;
15399
+ if (true) // envyoff)
15400
+ {
15401
+ BGcolor = (key - '1')/8.f;
15402
+ }
15403
+ else
15404
+ {
15405
+ //newenvy = Character.getNumericValue(key);
15406
+ }
1533215407 repaint();
1533315408 break;
1533415409 case '!':
....@@ -16033,7 +16108,7 @@
1603316108 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1603416109 break;
1603516110 case Object3D.hitScale: gr.setColor(Color.cyan);
16036
- gr.drawLine(X, Y, 0, 0);
16111
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1603716112 break;
1603816113 }
1603916114
....@@ -16519,6 +16594,8 @@
1651916594 private /*static*/ boolean firstime;
1652016595 private /*static*/ cVector newView = new cVector();
1652116596 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16597
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16598
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1652216599 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1652316600 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1652416601 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16531,29 +16608,67 @@
1653116608 {
1653216609 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1653316610
16611
+ int usedsuf = 0;
16612
+
1653416613 for (int i = 0; i < suffixes.length; i++)
1653516614 {
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)
16615
+ String[] suffixe = suffixes;
16616
+ String[] fallback = suffixes2;
16617
+ String[] fallfallback = suffixes3;
16618
+
16619
+ for (int c=usedsuf; --c>=0;)
1654116620 {
16542
- throw new IOException("Unable to load texture " + resourceName);
16621
+// String[] temp = suffixe;
16622
+// suffixe = fallback;
16623
+// fallback = fallfallback;
16624
+// fallfallback = temp;
1654316625 }
16626
+
16627
+ String resourceName = basename + suffixe[i] + "." + suffix;
16628
+ TextureData data;
16629
+
16630
+ try
16631
+ {
16632
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16633
+ mipmapped,
16634
+ FileUtil.getFileSuffix(resourceName));
16635
+ }
16636
+ catch (Exception e)
16637
+ {
16638
+ try
16639
+ {
16640
+ resourceName = basename + fallback[i] + "." + suffix;
16641
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16642
+ mipmapped,
16643
+ FileUtil.getFileSuffix(resourceName));
16644
+ }
16645
+ catch (Exception e2)
16646
+ {
16647
+ resourceName = basename + fallfallback[i] + "." + suffix;
16648
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16649
+ mipmapped,
16650
+ FileUtil.getFileSuffix(resourceName));
16651
+ }
16652
+ }
16653
+
1654416654 //System.out.println("Target = " + targets[i]);
1654516655 cubemap.updateImage(data, targets[i]);
1654616656 }
1654716657
1654816658 return cubemap;
1654916659 }
16660
+
1655016661 int bigsphere = -1;
1655116662
1655216663 float BGcolor = 0.5f;
1655316664
16554
- private void DrawSkyBox(GL gl)
16665
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16666
+
16667
+ private void DrawSkyBox(GL gl, float ratio)
1655516668 {
16556
- if (envyoff || cubemap == null)
16669
+ if (//envyoff ||
16670
+ WIREFRAME ||
16671
+ cubemap == null)
1655716672 {
1655816673 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1655916674 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16568,7 +16683,17 @@
1656816683 // Compensates for ExaminerViewer's modification of modelview matrix
1656916684 gl.glMatrixMode(GL.GL_MODELVIEW);
1657016685 gl.glLoadIdentity();
16686
+ gl.glScalef(1,ratio,1);
1657116687
16688
+// colorV[0] = 2;
16689
+// colorV[1] = 2;
16690
+// colorV[2] = 2;
16691
+// colorV[3] = 1;
16692
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16693
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16694
+//
16695
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16696
+
1657216697 //gl.glActiveTexture(GL.GL_TEXTURE1);
1657316698 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1657416699
....@@ -16600,6 +16725,7 @@
1660016725 {
1660116726 gl.glScalef(1.0f, -1.0f, 1.0f);
1660216727 }
16728
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1660316729 gl.glMultMatrixd(viewrot_1, 0);
1660416730 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1660516731 //viewer.updateInverseRotation(gl);
....@@ -16858,7 +16984,7 @@
1685816984 //new Exception().printStackTrace();
1685916985 System.out.println("select buffer init");
1686016986 // Use debug pipeline
16861
- drawable.setGL(new DebugGL(drawable.getGL()));
16987
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1686216988
1686316989 GL gl = drawable.getGL();
1686416990