Normand Briere
2019-08-17 5892f05411c3d4dce2d8a59e0966dc2e1843a971
CameraPane.java
....@@ -110,7 +110,11 @@
110110 //private Mat4f spotlightTransform = new Mat4f();
111111 //private Mat4f spotlightInverseTransform = new Mat4f();
112112 static GLContext glcontext = null;
113
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
114118 boolean reverseUP = false;
115119 static boolean frozen = false;
116120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -164,7 +168,7 @@
164168
165169
166170 // OPTIONS
167
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
168172 boolean cameraLight = false;
169173 boolean UVdebug = false;
170174 boolean Udebug = false;
....@@ -173,7 +177,7 @@
173177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
174178 boolean anisotropy = true;
175179 boolean softshadow = true; // slower but better false;
176
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
177181
178182 boolean macromode = false;
179183
....@@ -187,6 +191,19 @@
187191 }
188192
189193 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
194
+
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
190207
191208 void SetAsGLRenderer(boolean b)
192209 {
....@@ -1485,6 +1502,8 @@
14851502 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14861503 }
14871504
1505
+ float[] colorV = new float[4];
1506
+
14881507 void SetColor(Object3D obj, Vertex p0)
14891508 {
14901509 CameraPane display = this;
....@@ -1552,8 +1571,6 @@
15521571 {
15531572 return;
15541573 }
1555
-
1556
- float[] colorV = new float[3];
15571574
15581575 if (false) // marked)
15591576 {
....@@ -2500,7 +2517,7 @@
25002517 com.sun.opengl.util.texture.TextureIO.newTextureData(
25012518 getClass().getClassLoader().getResourceAsStream(name),
25022519 true,
2503
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
25042521 } catch (java.io.IOException e)
25052522 {
25062523 throw new javax.media.opengl.GLException(e);
....@@ -8346,7 +8363,7 @@
83468363 // else
83478364 // if (!texname.startsWith("/"))
83488365 // texname = "/Users/nbriere/Textures/" + texname;
8349
- if (!FileExists(texname))
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
83508367 {
83518368 texname = fallbackTextureName;
83528369 }
....@@ -8429,6 +8446,15 @@
84298446 new Exception().printStackTrace();
84308447 } else
84318448 {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
8456
+ } else
8457
+ {
84328458 if (textureon)
84338459 {
84348460 String cachename = texname;
....@@ -8488,6 +8514,7 @@
84888514 texturecache = new CacheTexture(texturedata,resolution);
84898515 //texture = GetTexture(tex, bump);
84908516 }
8517
+ }
84918518 }
84928519 //}
84938520 }
....@@ -8756,10 +8783,12 @@
87568783
87578784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87588785 MAXSTACK = temp[0];
8759
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87608788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87618789 MAXSTACK = temp[0];
8762
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87638792
87648793 // Use debug pipeline
87658794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8767,7 +8796,8 @@
87678796 gl = drawable.getGL(); //
87688797
87698798 GL gl3 = getGL();
8770
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87718801
87728802
87738803 //float pos[] = { 100, 100, 100, 0 };
....@@ -8932,7 +8962,7 @@
89328962
89338963 if (cubemap == null)
89348964 {
8935
- LoadEnvy(5);
8965
+ //LoadEnvy(1);
89368966 }
89378967
89388968 //cubemap.enable();
....@@ -9208,6 +9238,8 @@
92089238
92099239 void LoadEnvy(int which)
92109240 {
9241
+ assert(false);
9242
+
92119243 String name;
92129244 String ext;
92139245
....@@ -9219,37 +9251,58 @@
92199251 cubemap = null;
92209252 return;
92219253 case 1:
9222
- name = "cubemaps/box_";
9223
- ext = "png";
9254
+ name = "cubemaps/rgb/";
9255
+ ext = "jpg";
92249256 reverseUP = false;
92259257 break;
92269258 case 2:
9227
- name = "cubemaps/uffizi_";
9228
- ext = "png";
9229
- break; // reverseUP = true; break;
9259
+ name = "cubemaps/uffizi/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
92309263 case 3:
9231
- name = "cubemaps/CloudyHills_";
9232
- ext = "tga";
9264
+ name = "cubemaps/CloudyHills/";
9265
+ ext = "jpg";
92339266 reverseUP = false;
92349267 break;
92359268 case 4:
9236
- name = "cubemaps/cornell_";
9269
+ name = "cubemaps/cornell/";
92379270 ext = "png";
92389271 reverseUP = false;
92399272 break;
9273
+ case 5:
9274
+ name = "cubemaps/skycube/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 6:
9279
+ name = "cubemaps/SaintLazarusChurch3/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 7:
9284
+ name = "cubemaps/Sodermalmsallen/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
9288
+ case 8:
9289
+ name = "cubemaps/Sodermalmsallen2/";
9290
+ ext = "jpg";
9291
+ reverseUP = false;
9292
+ break;
9293
+ case 9:
9294
+ name = "cubemaps/UnionSquare/";
9295
+ ext = "jpg";
9296
+ reverseUP = false;
9297
+ break;
92409298 default:
9241
- name = "cubemaps/rgb_";
9242
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9299
+ name = "cubemaps/box/";
9300
+ ext = "png"; /*mipmap = true;*/
9301
+ reverseUP = false;
92439302 break;
92449303 }
9245
-
9246
- try
9247
- {
9248
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9249
- } catch (IOException e)
9250
- {
9251
- throw new RuntimeException(e);
9252
- }
9304
+
9305
+ LoadSkybox(name, ext, mipmap);
92539306 }
92549307
92559308 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9281,8 +9334,12 @@
92819334 static double[] model = new double[16];
92829335 double[] camera2light = new double[16];
92839336 double[] light2camera = new double[16];
9284
- int newenvy = -1;
9285
- boolean envyoff = true; // false;
9337
+
9338
+ //int newenvy = -1;
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
9342
+
92869343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92879344 //float[] light0 = { 0,0,0 };
92889345 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9762,10 +9819,12 @@
97629819 rati = 1 / rati;
97639820 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
97649821 }
9765
- assert (newenvy == -1);
9822
+
9823
+ //assert (newenvy == -1);
9824
+
97669825 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
97679826 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9768
- DrawSkyBox(gl);
9827
+ DrawSkyBox(gl, (float)rati);
97699828 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
97709829 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
97719830 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10631,9 +10690,18 @@
1063110690 static boolean init = false;
1063210691
1063310692 double[][] matrix = LA.newMatrix();
10693
+
10694
+ // This is to refresh the UI of the material panel.
10695
+ ObjEditor patchMaterial;
1063410696
1063510697 public void display(GLAutoDrawable drawable)
1063610698 {
10699
+ if (patchMaterial.patchMaterial)
10700
+ {
10701
+ patchMaterial.patchMaterial = false;
10702
+ patchMaterial.objectPanel.setSelectedIndex(0);
10703
+ }
10704
+
1063710705 if (Grafreed.savesound && Grafreed.hassound)
1063810706 {
1063910707 Grafreed.wav.save();
....@@ -10802,7 +10870,7 @@
1080210870
1080310871 if (wait)
1080410872 {
10805
- Sleep(500);
10873
+ Sleep(200); // blocks everything
1080610874
1080710875 wait = false;
1080810876 }
....@@ -11018,13 +11086,43 @@
1101811086 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1101911087 }
1102011088
11021
- if (newenvy > -1)
11089
+// if (newenvy > -1)
11090
+// {
11091
+// LoadEnvy(newenvy);
11092
+// }
11093
+//
11094
+// newenvy = -1;
11095
+
11096
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1102211097 {
11023
- LoadEnvy(newenvy);
11098
+ if (cubemaprgb == null)
11099
+ {
11100
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11101
+ }
11102
+
11103
+ cubemap = cubemaprgb;
1102411104 }
11025
-
11026
- newenvy = -1;
11027
-
11105
+ else
11106
+ {
11107
+ if (object.skyboxname != null)
11108
+ {
11109
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11110
+ {
11111
+ if (cubemap != null && cubemap != cubemaprgb)
11112
+ cubemap.dispose();
11113
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11114
+ loadedskyboxname = object.skyboxname;
11115
+ }
11116
+ }
11117
+ else
11118
+ {
11119
+ cubemapcustom = null;
11120
+ loadedskyboxname = null;
11121
+ }
11122
+
11123
+ cubemap = cubemapcustom;
11124
+ }
11125
+
1102811126 ratio = ((double) getWidth()) / getHeight();
1102911127 //System.out.println("ratio = " + ratio);
1103011128
....@@ -11040,7 +11138,7 @@
1104011138
1104111139 if (!IsFrozen() && !ambientOcclusion)
1104211140 {
11043
- DrawSkyBox(gl);
11141
+ DrawSkyBox(gl, (float)ratio);
1104411142 }
1104511143
1104611144 //if (selection_view == -1)
....@@ -11326,7 +11424,7 @@
1132611424
1132711425 // if (cam != lightCamera)
1132811426 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11329
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11427
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1133011428 }
1133111429
1133211430 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -12400,7 +12498,7 @@
1240012498
1240112499 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240212500
12403
- String program =
12501
+ String programmin =
1240412502 // Min shader
1240512503 "!!ARBfp1.0\n" +
1240612504 "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
....@@ -12451,7 +12549,8 @@
1245112549 //"SUB ndotl.y, zero123.y, ndotl.y;" +
1245212550 //"MUL ndotl.y, ndotl.y, pow2.z;" +
1245312551
12454
- "MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12552
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12553
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
1245512554
1245612555 // Pigment
1245712556 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
....@@ -12466,7 +12565,7 @@
1246612565 "MOV result.color, temp;" +
1246712566 "END";
1246812567
12469
- String program2 =
12568
+ String programmax =
1247012569 "!!ARBfp1.0\n" +
1247112570
1247212571 //"OPTION ARB_fragment_program_shadow;" +
....@@ -12991,7 +13090,7 @@
1299113090 // display shadow only (fakedepth == 0)
1299213091 "SUB temp.x, half.x, shadow.x;" +
1299313092 "MOV temp.y, -params5.z;" + // params6.x;" +
12994
- "SLT temp.z, temp.y, -one2048th.x;" +
13093
+ "SLT temp.z, temp.y, -c256i.x;" +
1299513094 "SUB temp.y, one.x, temp.z;" +
1299613095 "MUL temp.x, temp.x, temp.y;" +
1299713096 "KIL temp.x;" +
....@@ -13322,8 +13421,19 @@
1332213421 //once = true;
1332313422 }
1332413423
13325
- System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13326
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13424
+ String program = programmax;
13425
+
13426
+ if (Globals.MINSHADER)
13427
+ {
13428
+ program = programmin;
13429
+ }
13430
+
13431
+ if (Globals.DEBUG)
13432
+ {
13433
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13434
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13435
+ }
13436
+
1332713437 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1332813438
1332913439 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -13370,7 +13480,8 @@
1337013480 "\n" +
1337113481 "END\n";
1337213482
13373
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13483
+ if (Globals.DEBUG)
13484
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1337413485 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1337513486
1337613487 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -14569,11 +14680,17 @@
1456914680 void GoDown(int mod)
1457014681 {
1457114682 MODIFIERS |= COMMAND;
14683
+ boolean isVR = (mouseMode&VR)!=0;
1457214684 /**/
1457314685 if((mod&SHIFT) == SHIFT)
14574
- manipCamera.RotatePosition(0, -speed);
14686
+ {
14687
+ if (isVR)
14688
+ manipCamera.RotateInterest(0, -speed);
14689
+ else
14690
+ manipCamera.RotatePosition(0, -speed);
14691
+ }
1457514692 else
14576
- manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14693
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
1457714694 /**/
1457814695 if ((mod & SHIFT) == SHIFT)
1457914696 {
....@@ -14583,6 +14700,8 @@
1458314700 mouseMode |= BACKFORTH;
1458414701 }
1458514702
14703
+ targetLookAt.set(manipCamera.lookAt);
14704
+
1458614705 //prevX = X = anchorX;
1458714706 prevY = Y = anchorY - (int) (renderCamera.Distance());
1458814707 }
....@@ -14591,10 +14710,17 @@
1459114710 {
1459214711 MODIFIERS |= COMMAND;
1459314712 /**/
14713
+ boolean isVR = (mouseMode&VR)!=0;
14714
+
1459414715 if((mod&SHIFT) == SHIFT)
14595
- manipCamera.RotatePosition(0, speed);
14716
+ {
14717
+ if (isVR)
14718
+ manipCamera.RotateInterest(0, speed);
14719
+ else
14720
+ manipCamera.RotatePosition(0, speed);
14721
+ }
1459614722 else
14597
- manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14723
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
1459814724 /**/
1459914725 if ((mod & SHIFT) == SHIFT)
1460014726 {
....@@ -14604,6 +14730,8 @@
1460414730 mouseMode |= BACKFORTH;
1460514731 }
1460614732
14733
+ targetLookAt.set(manipCamera.lookAt);
14734
+
1460714735 //prevX = X = anchorX;
1460814736 prevY = Y = anchorY + (int) (renderCamera.Distance());
1460914737 }
....@@ -14613,9 +14741,14 @@
1461314741 MODIFIERS |= COMMAND;
1461414742 /**/
1461514743 if((mod&SHIFT) == SHIFT)
14616
- manipCamera.Translate(speed*delta, 0, getWidth());
14744
+ manipCamera.Translate(speed*delta, 0, getWidth());
1461714745 else
14618
- manipCamera.RotatePosition(speed, 0);
14746
+ {
14747
+ if ((mouseMode&VR)!=0)
14748
+ manipCamera.RotateInterest(-speed, 0);
14749
+ else
14750
+ manipCamera.RotatePosition(speed, 0);
14751
+ }
1461914752 /**/
1462014753 if ((mod & SHIFT) == SHIFT)
1462114754 {
....@@ -14625,6 +14758,8 @@
1462514758 mouseMode |= ROTATE;
1462614759 } // TRANSLATE;
1462714760
14761
+ targetLookAt.set(manipCamera.lookAt);
14762
+
1462814763 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1462914764 prevY = Y = anchorY;
1463014765 }
....@@ -14634,9 +14769,15 @@
1463414769 MODIFIERS |= COMMAND;
1463514770 /**/
1463614771 if((mod&SHIFT) == SHIFT)
14637
- manipCamera.Translate(-speed*delta, 0, getWidth());
14772
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1463814773 else
14639
- manipCamera.RotatePosition(-speed, 0);
14774
+ {
14775
+ if ((mouseMode&VR)!=0)
14776
+ manipCamera.RotateInterest(speed, 0);
14777
+ else
14778
+ manipCamera.RotatePosition(-speed, 0);
14779
+ }
14780
+
1464014781 /**/
1464114782 if ((mod & SHIFT) == SHIFT)
1464214783 {
....@@ -14646,6 +14787,8 @@
1464614787 mouseMode |= ROTATE;
1464714788 } // TRANSLATE;
1464814789
14790
+ targetLookAt.set(manipCamera.lookAt);
14791
+
1464914792 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1465014793 prevY = Y = anchorY;
1465114794 }
....@@ -15148,8 +15291,8 @@
1514815291 case 'K':
1514915292 KOMPACTTEXTURE ^= true;
1515015293 //textures.clear();
15151
- break;
15152
- case 'P': // Texture Projection macros
15294
+ // break;
15295
+ //case 'P': // Texture Projection macros
1515315296 // SAVETEXTURE ^= true;
1515415297 macromode = true;
1515515298 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -15270,7 +15413,7 @@
1527015413 targetLookAt.set(manipCamera.lookAt);
1527115414 repaint();
1527215415 break;
15273
- case 'p':
15416
+ case 'P': // p':
1527415417 // c'est quoi ca au juste? spherical ^= true;
1527515418 Skinshader ^= true; programInitialized = false;
1527615419 repaint();
....@@ -15315,20 +15458,24 @@
1531515458 OCCLUSION_CULLING ^= true;
1531615459 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1531715460 break;
15318
- case '0': envyoff ^= true; repaint(); break;
15461
+ //case '0': envyoff ^= true; repaint(); break;
1531915462 case '1':
1532015463 case '2':
1532115464 case '3':
1532215465 case '4':
1532315466 case '5':
15324
- newenvy = Character.getNumericValue(key);
15325
- repaint();
15326
- break;
1532715467 case '6':
1532815468 case '7':
1532915469 case '8':
1533015470 case '9':
15331
- BGcolor = (key - '6')/3.f;
15471
+ if (true) // envyoff)
15472
+ {
15473
+ BGcolor = (key - '1')/8.f;
15474
+ }
15475
+ else
15476
+ {
15477
+ //newenvy = Character.getNumericValue(key);
15478
+ }
1533215479 repaint();
1533315480 break;
1533415481 case '!':
....@@ -16026,14 +16173,14 @@
1602616173 {
1602716174 switch (hitSomething)
1602816175 {
16029
- case Object3D.hitCenter: gr.setColor(Color.pink);
16176
+ case Object3D.hitCenter: gr.setColor(Color.white);
1603016177 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1603116178 break;
1603216179 case Object3D.hitRotate: gr.setColor(Color.yellow);
1603316180 gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1603416181 break;
1603516182 case Object3D.hitScale: gr.setColor(Color.cyan);
16036
- gr.drawLine(X, Y, 0, 0);
16183
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1603716184 break;
1603816185 }
1603916186
....@@ -16052,7 +16199,7 @@
1605216199 if (hasMarquee)
1605316200 {
1605416201 gr.setXORMode(Color.white);
16055
- gr.setColor(Color.red);
16202
+ gr.setColor(Color.white);
1605616203 if (!firstime)
1605716204 {
1605816205 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -16519,6 +16666,8 @@
1651916666 private /*static*/ boolean firstime;
1652016667 private /*static*/ cVector newView = new cVector();
1652116668 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16669
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16670
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1652216671 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1652316672 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1652416673 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16531,29 +16680,67 @@
1653116680 {
1653216681 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1653316682
16683
+ int usedsuf = 0;
16684
+
1653416685 for (int i = 0; i < suffixes.length; i++)
1653516686 {
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)
16687
+ String[] suffixe = suffixes;
16688
+ String[] fallback = suffixes2;
16689
+ String[] fallfallback = suffixes3;
16690
+
16691
+ for (int c=usedsuf; --c>=0;)
1654116692 {
16542
- throw new IOException("Unable to load texture " + resourceName);
16693
+// String[] temp = suffixe;
16694
+// suffixe = fallback;
16695
+// fallback = fallfallback;
16696
+// fallfallback = temp;
1654316697 }
16698
+
16699
+ String resourceName = basename + suffixe[i] + "." + suffix;
16700
+ TextureData data;
16701
+
16702
+ try
16703
+ {
16704
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16705
+ mipmapped,
16706
+ FileUtil.getFileSuffix(resourceName));
16707
+ }
16708
+ catch (Exception e)
16709
+ {
16710
+ try
16711
+ {
16712
+ resourceName = basename + fallback[i] + "." + suffix;
16713
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16714
+ mipmapped,
16715
+ FileUtil.getFileSuffix(resourceName));
16716
+ }
16717
+ catch (Exception e2)
16718
+ {
16719
+ resourceName = basename + fallfallback[i] + "." + suffix;
16720
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16721
+ mipmapped,
16722
+ FileUtil.getFileSuffix(resourceName));
16723
+ }
16724
+ }
16725
+
1654416726 //System.out.println("Target = " + targets[i]);
1654516727 cubemap.updateImage(data, targets[i]);
1654616728 }
1654716729
1654816730 return cubemap;
1654916731 }
16732
+
1655016733 int bigsphere = -1;
1655116734
1655216735 float BGcolor = 0.5f;
1655316736
16554
- private void DrawSkyBox(GL gl)
16737
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16738
+
16739
+ private void DrawSkyBox(GL gl, float ratio)
1655516740 {
16556
- if (envyoff || cubemap == null)
16741
+ if (//envyoff ||
16742
+ WIREFRAME ||
16743
+ cubemap == null)
1655716744 {
1655816745 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1655916746 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16568,7 +16755,17 @@
1656816755 // Compensates for ExaminerViewer's modification of modelview matrix
1656916756 gl.glMatrixMode(GL.GL_MODELVIEW);
1657016757 gl.glLoadIdentity();
16758
+ gl.glScalef(1,ratio,1);
1657116759
16760
+// colorV[0] = 2;
16761
+// colorV[1] = 2;
16762
+// colorV[2] = 2;
16763
+// colorV[3] = 1;
16764
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16765
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16766
+//
16767
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16768
+
1657216769 //gl.glActiveTexture(GL.GL_TEXTURE1);
1657316770 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1657416771
....@@ -16600,6 +16797,7 @@
1660016797 {
1660116798 gl.glScalef(1.0f, -1.0f, 1.0f);
1660216799 }
16800
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1660316801 gl.glMultMatrixd(viewrot_1, 0);
1660416802 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1660516803 //viewer.updateInverseRotation(gl);
....@@ -16640,7 +16838,8 @@
1664016838 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1664116839
1664216840 cubemap.disable();
16643
- ////cubemap.unbind();
16841
+ //cubemap.dispose();
16842
+
1664416843 if (CULLFACE)
1664516844 {
1664616845 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16858,7 +17057,7 @@
1685817057 //new Exception().printStackTrace();
1685917058 System.out.println("select buffer init");
1686017059 // Use debug pipeline
16861
- drawable.setGL(new DebugGL(drawable.getGL()));
17060
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1686217061
1686317062 GL gl = drawable.getGL();
1686417063
....@@ -17176,6 +17375,7 @@
1717617375
1717717376 public void init(GLAutoDrawable drawable)
1717817377 {
17378
+ if (Globals.DEBUG)
1717917379 System.out.println("shadow buffer init");
1718017380
1718117381 GL gl = drawable.getGL();
....@@ -17404,10 +17604,14 @@
1740417604 gl.glFlush();
1740517605
1740617606 /**/
17407
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17607
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1740817608
17409
- float[] pixels = occlusionsizebuffer.array();
17609
+ float[] depths = occlusiondepthbuffer.array();
1741017610
17611
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17612
+
17613
+ int[] pixels = selectsizebuffer.array();
17614
+
1741117615 double r = 0, g = 0, b = 0;
1741217616
1741317617 double count = 0;
....@@ -17418,7 +17622,7 @@
1741817622
1741917623 double FACTOR = 1;
1742017624
17421
- for (int i = 0; i < pixels.length; i++)
17625
+ for (int i = 0; i < depths.length; i++)
1742217626 {
1742317627 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1742417628 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17501,7 +17705,7 @@
1750117705
1750217706 double scale = ray.z; // 1; // cos
1750317707
17504
- float depth = pixels[newindex];
17708
+ float depth = depths[newindex];
1750517709
1750617710 /*
1750717711 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17698,11 +17902,14 @@
1769817902 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1769917903 static IntBuffer bigAAbuffer;
1770017904 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17701
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17905
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1770217906 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1770317907 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1770417908 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17705
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17909
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17910
+
17911
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17912
+
1770617913 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1770717914 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1770817915 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();