Normand Briere
2019-08-14 0c1f740dd6ddd6432dc29266e42ef851e26027bb
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
....@@ -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 {
....@@ -206,7 +223,8 @@
206223
207224 SetCamera(cam);
208225
209
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
210228
211229 object = o;
212230
....@@ -1484,6 +1502,8 @@
14841502 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14851503 }
14861504
1505
+ float[] colorV = new float[4];
1506
+
14871507 void SetColor(Object3D obj, Vertex p0)
14881508 {
14891509 CameraPane display = this;
....@@ -1551,8 +1571,6 @@
15511571 {
15521572 return;
15531573 }
1554
-
1555
- float[] colorV = new float[3];
15561574
15571575 if (false) // marked)
15581576 {
....@@ -2499,7 +2517,7 @@
24992517 com.sun.opengl.util.texture.TextureIO.newTextureData(
25002518 getClass().getClassLoader().getResourceAsStream(name),
25012519 true,
2502
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
25032521 } catch (java.io.IOException e)
25042522 {
25052523 throw new javax.media.opengl.GLException(e);
....@@ -8345,7 +8363,7 @@
83458363 // else
83468364 // if (!texname.startsWith("/"))
83478365 // texname = "/Users/nbriere/Textures/" + texname;
8348
- if (!FileExists(texname))
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
83498367 {
83508368 texname = fallbackTextureName;
83518369 }
....@@ -8428,6 +8446,15 @@
84288446 new Exception().printStackTrace();
84298447 } else
84308448 {
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
+ {
84318458 if (textureon)
84328459 {
84338460 String cachename = texname;
....@@ -8487,6 +8514,7 @@
84878514 texturecache = new CacheTexture(texturedata,resolution);
84888515 //texture = GetTexture(tex, bump);
84898516 }
8517
+ }
84908518 }
84918519 //}
84928520 }
....@@ -8755,10 +8783,12 @@
87558783
87568784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87578785 MAXSTACK = temp[0];
8758
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87598788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87608789 MAXSTACK = temp[0];
8761
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87628792
87638793 // Use debug pipeline
87648794 //drawable.setGL(new DebugGL(gl)); //
....@@ -8766,7 +8796,8 @@
87668796 gl = drawable.getGL(); //
87678797
87688798 GL gl3 = getGL();
8769
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87708801
87718802
87728803 //float pos[] = { 100, 100, 100, 0 };
....@@ -8931,7 +8962,7 @@
89318962
89328963 if (cubemap == null)
89338964 {
8934
- LoadEnvy(5);
8965
+ //LoadEnvy(1);
89358966 }
89368967
89378968 //cubemap.enable();
....@@ -9207,6 +9238,8 @@
92079238
92089239 void LoadEnvy(int which)
92099240 {
9241
+ assert(false);
9242
+
92109243 String name;
92119244 String ext;
92129245
....@@ -9218,37 +9251,58 @@
92189251 cubemap = null;
92199252 return;
92209253 case 1:
9221
- name = "cubemaps/box_";
9222
- ext = "png";
9254
+ name = "cubemaps/rgb/";
9255
+ ext = "jpg";
92239256 reverseUP = false;
92249257 break;
92259258 case 2:
9226
- name = "cubemaps/uffizi_";
9227
- ext = "png";
9228
- break; // reverseUP = true; break;
9259
+ name = "cubemaps/uffizi/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
92299263 case 3:
9230
- name = "cubemaps/CloudyHills_";
9231
- ext = "tga";
9264
+ name = "cubemaps/CloudyHills/";
9265
+ ext = "jpg";
92329266 reverseUP = false;
92339267 break;
92349268 case 4:
9235
- name = "cubemaps/cornell_";
9269
+ name = "cubemaps/cornell/";
92369270 ext = "png";
92379271 reverseUP = false;
92389272 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;
92399298 default:
9240
- name = "cubemaps/rgb_";
9241
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9299
+ name = "cubemaps/box/";
9300
+ ext = "png"; /*mipmap = true;*/
9301
+ reverseUP = false;
92429302 break;
92439303 }
9244
-
9245
- try
9246
- {
9247
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9248
- } catch (IOException e)
9249
- {
9250
- throw new RuntimeException(e);
9251
- }
9304
+
9305
+ LoadSkybox(name, ext, mipmap);
92529306 }
92539307
92549308 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9280,8 +9334,12 @@
92809334 static double[] model = new double[16];
92819335 double[] camera2light = new double[16];
92829336 double[] light2camera = new double[16];
9283
- int newenvy = -1;
9284
- boolean envyoff = true; // false;
9337
+
9338
+ //int newenvy = -1;
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
9342
+
92859343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92869344 //float[] light0 = { 0,0,0 };
92879345 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9699,7 +9757,7 @@
96999757
97009758 if (renderCamera != lightCamera)
97019759 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9760
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
97039761
97049762 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
97059763
....@@ -9715,7 +9773,7 @@
97159773
97169774 if (renderCamera != lightCamera)
97179775 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9776
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
97199777
97209778 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
97219779
....@@ -9761,10 +9819,12 @@
97619819 rati = 1 / rati;
97629820 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
97639821 }
9764
- assert (newenvy == -1);
9822
+
9823
+ //assert (newenvy == -1);
9824
+
97659825 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
97669826 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9767
- DrawSkyBox(gl);
9827
+ DrawSkyBox(gl, (float)rati);
97689828 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
97699829 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
97709830 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10801,7 +10861,7 @@
1080110861
1080210862 if (wait)
1080310863 {
10804
- Sleep(500);
10864
+ Sleep(200); // blocks everything
1080510865
1080610866 wait = false;
1080710867 }
....@@ -10916,7 +10976,7 @@
1091610976 // if (parentcam != renderCamera) // not a light
1091710977 if (cam != lightCamera)
1091810978 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10979
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1092010980
1092110981 for (int j = 0; j < 4; j++)
1092210982 {
....@@ -10931,7 +10991,7 @@
1093110991 // if (parentcam != renderCamera) // not a light
1093210992 if (cam != lightCamera)
1093310993 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10994
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1093510995
1093610996 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1093710997
....@@ -11017,13 +11077,43 @@
1101711077 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1101811078 }
1101911079
11020
- if (newenvy > -1)
11080
+// if (newenvy > -1)
11081
+// {
11082
+// LoadEnvy(newenvy);
11083
+// }
11084
+//
11085
+// newenvy = -1;
11086
+
11087
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1102111088 {
11022
- LoadEnvy(newenvy);
11089
+ if (cubemaprgb == null)
11090
+ {
11091
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb" + "/", "jpg", false);
11092
+ }
11093
+
11094
+ cubemap = cubemaprgb;
1102311095 }
11024
-
11025
- newenvy = -1;
11026
-
11096
+ else
11097
+ {
11098
+ if (object.skyboxname != null)
11099
+ {
11100
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11101
+ {
11102
+ if (cubemap != null && cubemap != cubemaprgb)
11103
+ cubemap.dispose();
11104
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11105
+ loadedskyboxname = object.skyboxname;
11106
+ }
11107
+ }
11108
+ else
11109
+ {
11110
+ cubemapcustom = null;
11111
+ loadedskyboxname = null;
11112
+ }
11113
+
11114
+ cubemap = cubemapcustom;
11115
+ }
11116
+
1102711117 ratio = ((double) getWidth()) / getHeight();
1102811118 //System.out.println("ratio = " + ratio);
1102911119
....@@ -11039,7 +11129,7 @@
1103911129
1104011130 if (!IsFrozen() && !ambientOcclusion)
1104111131 {
11042
- DrawSkyBox(gl);
11132
+ DrawSkyBox(gl, (float)ratio);
1104311133 }
1104411134
1104511135 //if (selection_view == -1)
....@@ -11325,7 +11415,7 @@
1132511415
1132611416 // if (cam != lightCamera)
1132711417 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11328
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11418
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1132911419 }
1133011420
1133111421 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -12399,51 +12489,74 @@
1239912489
1240012490 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240112491
12402
- String program =
12492
+ String programmin =
1240312493 // Min shader
1240412494 "!!ARBfp1.0\n" +
12405
- "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12495
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
1240612496 "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
1240712497 "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1240812498 "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
1240912499 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12500
+ "PARAM light2cam0 = program.env[10];" +
12501
+ "PARAM light2cam1 = program.env[11];" +
12502
+ "PARAM light2cam2 = program.env[12];" +
1241012503 "TEMP temp;" +
1241112504 "TEMP light;" +
1241212505 "TEMP ndotl;" +
1241312506 "TEMP normal;" +
1241412507 "TEMP depth;" +
12508
+ "TEMP eye;" +
12509
+ "TEMP pos;" +
1241512510
1241612511 "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
-
12512
+ Normalize("normal") +
1241812513 "MOV light, state.light[0].position;" +
1241912514 "DP3 ndotl.x, light, normal;" +
1242012515
1242112516 // shadow
12422
- "MOV temp, fragment.texcoord[1];" +
12423
- TextureFetch("depth", "temp", "1") +
12517
+ "MOV pos, fragment.texcoord[1];" +
12518
+ "MOV temp, pos;" +
12519
+ ShadowTextureFetch("depth", "temp", "1") +
1242412520 //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
- "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
-
12521
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
1242712522
1242812523 // No shadow when out of frustum
1242912524 //"SGE temp.y, depth.z, zero123.y;" +
1243012525 //"LRP temp.x, temp.y, zero123.y, temp.x;" +
1243112526
12432
- "MUL ndotl.x, ndotl.x, temp.x;" +
12433
- "MAX ndotl.x, ndotl.x, pow2.y;" +
12527
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
1243412528
12529
+ // Backlit
12530
+ "MOV pos.w, zero123.y;" +
12531
+ "DP4 eye.x, pos, light2cam0;" +
12532
+ "DP4 eye.y, pos, light2cam1;" +
12533
+ "DP4 eye.z, pos, light2cam2;" +
12534
+ Normalize("eye") +
12535
+
12536
+ "DP3 ndotl.y, -eye, normal;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12538
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12539
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12540
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12541
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12542
+
12543
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12544
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12545
+
12546
+ // Pigment
1243512547 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
1243612548 "LRP temp, zero123.w, temp, one;" + // texture proportion
1243712549 "MUL temp, temp, ndotl.x;" +
1243812550
1243912551 "MUL temp, temp, zero123.z;" +
1244012552
12441
- "MOV temp.w, zero123.y;" + // reset alpha
12553
+ //"MUL temp, temp, ndotl.y;" +
1244212554
12555
+ "MOV temp.w, zero123.y;" + // reset alpha
1244312556 "MOV result.color, temp;" +
1244412557 "END";
1244512558
12446
- String program2 =
12559
+ String programmax =
1244712560 "!!ARBfp1.0\n" +
1244812561
1244912562 //"OPTION ARB_fragment_program_shadow;" +
....@@ -12581,20 +12694,20 @@
1258112694 "MUL temp, floor, mapgrid.x;" +
1258212695 //"TEX depth0, temp, texture[1], 2D;" +
1258312696 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12584
- TextureFetch("depth0", "temp", "1") +
12697
+ ShadowTextureFetch("depth0", "temp", "1") +
1258512698 "") +
1258612699 "ADD temp.x, temp.x, mapgrid.x;" +
1258712700 //"TEX depth1, temp, texture[1], 2D;" +
1258812701 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12589
- TextureFetch("depth1", "temp", "1") +
12702
+ ShadowTextureFetch("depth1", "temp", "1") +
1259012703 "") +
1259112704 "ADD temp.y, temp.y, mapgrid.x;" +
1259212705 //"TEX depth2, temp, texture[1], 2D;" +
12593
- TextureFetch("depth2", "temp", "1") +
12706
+ ShadowTextureFetch("depth2", "temp", "1") +
1259412707 "SUB temp.x, temp.x, mapgrid.x;" +
1259512708 //"TEX depth3, temp, texture[1], 2D;" +
1259612709 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12597
- TextureFetch("depth3", "temp", "1") +
12710
+ ShadowTextureFetch("depth3", "temp", "1") +
1259812711 "") +
1259912712 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1260012713 //"MOV params, material;" +
....@@ -12968,7 +13081,7 @@
1296813081 // display shadow only (fakedepth == 0)
1296913082 "SUB temp.x, half.x, shadow.x;" +
1297013083 "MOV temp.y, -params5.z;" + // params6.x;" +
12971
- "SLT temp.z, temp.y, -one2048th.x;" +
13084
+ "SLT temp.z, temp.y, -c256i.x;" +
1297213085 "SUB temp.y, one.x, temp.z;" +
1297313086 "MUL temp.x, temp.x, temp.y;" +
1297413087 "KIL temp.x;" +
....@@ -13299,6 +13412,13 @@
1329913412 //once = true;
1330013413 }
1330113414
13415
+ String program = programmax;
13416
+
13417
+ if (Globals.MINSHADER)
13418
+ {
13419
+ program = programmin;
13420
+ }
13421
+
1330213422 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1330313423 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1330413424 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13392,7 +13512,8 @@
1339213512 return out;
1339313513 }
1339413514
13395
- String TextureFetch(String dest, String src, String unit)
13515
+ // Also does frustum culling
13516
+ String ShadowTextureFetch(String dest, String src, String unit)
1339613517 {
1339713518 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1339813519 "SGE " + src + ".w, " + src + ".x, eps.x;" +
....@@ -14255,14 +14376,15 @@
1425514376 drag = false;
1425614377 //System.out.println("Mouse DOWN");
1425714378 editObj = false;
14258
- ClickInfo info = new ClickInfo();
14259
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14260
- info.pane = this;
14261
- info.camera = renderCamera;
14262
- info.x = x;
14263
- info.y = y;
14264
- info.modifiers = modifiersex;
14265
- editObj = object.doEditClick(info, 0);
14379
+ //ClickInfo info = new ClickInfo();
14380
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14381
+ object.clickInfo.pane = this;
14382
+ object.clickInfo.camera = renderCamera;
14383
+ object.clickInfo.x = x;
14384
+ object.clickInfo.y = y;
14385
+ object.clickInfo.modifiers = modifiersex;
14386
+ editObj = object.doEditClick(//info,
14387
+ 0);
1426614388 if (!editObj)
1426714389 {
1426814390 hasMarquee = true;
....@@ -14546,9 +14668,9 @@
1454614668 MODIFIERS |= COMMAND;
1454714669 /**/
1454814670 if((mod&SHIFT) == SHIFT)
14549
- manipCamera.RotatePosition(0, -speed);
14550
- else
1455114671 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14672
+ else
14673
+ manipCamera.RotatePosition(0, -speed);
1455214674 /**/
1455314675 if ((mod & SHIFT) == SHIFT)
1455414676 {
....@@ -14567,9 +14689,9 @@
1456714689 MODIFIERS |= COMMAND;
1456814690 /**/
1456914691 if((mod&SHIFT) == SHIFT)
14570
- manipCamera.RotatePosition(0, speed);
14571
- else
1457214692 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14693
+ else
14694
+ manipCamera.RotatePosition(0, speed);
1457314695 /**/
1457414696 if ((mod & SHIFT) == SHIFT)
1457514697 {
....@@ -14662,15 +14784,16 @@
1466214784 if (editObj)
1466314785 {
1466414786 drag = true;
14665
- ClickInfo info = new ClickInfo();
14666
- info.bounds.setBounds(0, 0,
14787
+ //ClickInfo info = new ClickInfo();
14788
+ object.clickInfo.bounds.setBounds(0, 0,
1466714789 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14668
- info.pane = this;
14669
- info.camera = renderCamera;
14670
- info.x = x;
14671
- info.y = y;
14672
- object.GetWindow().copy
14673
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14790
+ object.clickInfo.pane = this;
14791
+ object.clickInfo.camera = renderCamera;
14792
+ object.clickInfo.x = x;
14793
+ object.clickInfo.y = y;
14794
+ object //.GetWindow().copy
14795
+ .doEditDrag(//info,
14796
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1467414797 } else
1467514798 {
1467614799 if (x < startX)
....@@ -14819,24 +14942,27 @@
1481914942 }
1482014943 }
1482114944
14945
+// ClickInfo clickInfo = new ClickInfo();
14946
+
1482214947 public void mouseMoved(MouseEvent e)
1482314948 {
1482414949 //System.out.println("mouseMoved: " + e);
1482514950 if (isRenderer)
1482614951 return;
1482714952
14828
- ClickInfo ci = new ClickInfo();
14829
- ci.x = e.getX();
14830
- ci.y = e.getY();
14831
- ci.modifiers = e.getModifiersEx();
14832
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14833
- ci.pane = this;
14834
- ci.camera = renderCamera;
14953
+ // Mouse cursor feedback
14954
+ object.clickInfo.x = e.getX();
14955
+ object.clickInfo.y = e.getY();
14956
+ object.clickInfo.modifiers = e.getModifiersEx();
14957
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14958
+ object.clickInfo.pane = this;
14959
+ object.clickInfo.camera = renderCamera;
1483514960 if (!isRenderer)
1483614961 {
1483714962 //ObjEditor editWindow = object.editWindow;
1483814963 //Object3D copy = editWindow.copy;
14839
- if (object.doEditClick(ci, 0))
14964
+ if (object.doEditClick(//clickInfo,
14965
+ 0))
1484014966 {
1484114967 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1484214968 } else
....@@ -15286,20 +15412,24 @@
1528615412 OCCLUSION_CULLING ^= true;
1528715413 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1528815414 break;
15289
- case '0': envyoff ^= true; repaint(); break;
15415
+ //case '0': envyoff ^= true; repaint(); break;
1529015416 case '1':
1529115417 case '2':
1529215418 case '3':
1529315419 case '4':
1529415420 case '5':
15295
- newenvy = Character.getNumericValue(key);
15296
- repaint();
15297
- break;
1529815421 case '6':
1529915422 case '7':
1530015423 case '8':
1530115424 case '9':
15302
- BGcolor = (key - '6')/3.f;
15425
+ if (true) // envyoff)
15426
+ {
15427
+ BGcolor = (key - '1')/8.f;
15428
+ }
15429
+ else
15430
+ {
15431
+ //newenvy = Character.getNumericValue(key);
15432
+ }
1530315433 repaint();
1530415434 break;
1530515435 case '!':
....@@ -15862,8 +15992,6 @@
1586215992
1586315993 int width = getBounds().width;
1586415994 int height = getBounds().height;
15865
- ClickInfo info = new ClickInfo();
15866
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1586715995 //Image img = CreateImage(width, height);
1586815996 //System.out.println("width = " + width + "; height = " + height + "\n");
1586915997
....@@ -15940,31 +16068,37 @@
1594016068 }
1594116069 if (object != null && !hasMarquee)
1594216070 {
16071
+ if (object.clickInfo == null)
16072
+ object.clickInfo = new ClickInfo();
16073
+ ClickInfo info = object.clickInfo;
16074
+ //ClickInfo info = new ClickInfo();
16075
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16076
+
1594316077 if (isRenderer)
1594416078 {
15945
- info.flags++;
16079
+ object.clickInfo.flags++;
1594616080 double frameAspect = (double) width / (double) height;
1594716081 if (frameAspect > renderCamera.aspect)
1594816082 {
1594916083 int desired = (int) ((double) height * renderCamera.aspect);
15950
- info.bounds.width -= width - desired;
15951
- info.bounds.x += (width - desired) / 2;
16084
+ object.clickInfo.bounds.width -= width - desired;
16085
+ object.clickInfo.bounds.x += (width - desired) / 2;
1595216086 } else
1595316087 {
1595416088 int desired = (int) ((double) width / renderCamera.aspect);
15955
- info.bounds.height -= height - desired;
15956
- info.bounds.y += (height - desired) / 2;
16089
+ object.clickInfo.bounds.height -= height - desired;
16090
+ object.clickInfo.bounds.y += (height - desired) / 2;
1595716091 }
1595816092 }
1595916093
15960
- info.g = gr;
15961
- info.camera = renderCamera;
16094
+ object.clickInfo.g = gr;
16095
+ object.clickInfo.camera = renderCamera;
1596216096 /*
1596316097 // Memory intensive (brep.verticescopy)
1596416098 if (!(object instanceof Composite))
1596516099 object.draw(info, 0, false); // SLOW :
1596616100 */
15967
- if (!isRenderer)
16101
+ if (!isRenderer) // && drag)
1596816102 {
1596916103 Grafreed.Assert(object != null);
1597016104 Grafreed.Assert(object.selection != null);
....@@ -15972,9 +16106,9 @@
1597216106 {
1597316107 int hitSomething = object.selection.get(0).hitSomething;
1597416108
15975
- info.DX = 0;
15976
- info.DY = 0;
15977
- info.W = 1;
16109
+ object.clickInfo.DX = 0;
16110
+ object.clickInfo.DY = 0;
16111
+ object.clickInfo.W = 1;
1597816112 if (hitSomething == Object3D.hitCenter)
1597916113 {
1598016114 info.DX = X;
....@@ -15986,7 +16120,8 @@
1598616120 info.DY -= info.bounds.height/2;
1598716121 }
1598816122
15989
- object.drawEditHandles(info, 0);
16123
+ object.drawEditHandles(//info,
16124
+ 0);
1599016125
1599116126 if (drag && (X != 0 || Y != 0))
1599216127 {
....@@ -16485,6 +16620,8 @@
1648516620 private /*static*/ boolean firstime;
1648616621 private /*static*/ cVector newView = new cVector();
1648716622 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16623
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16624
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1648816625 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1648916626 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1649016627 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16497,29 +16634,67 @@
1649716634 {
1649816635 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1649916636
16637
+ int usedsuf = 0;
16638
+
1650016639 for (int i = 0; i < suffixes.length; i++)
1650116640 {
16502
- String resourceName = basename + suffixes[i] + "." + suffix;
16503
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16504
- mipmapped,
16505
- FileUtil.getFileSuffix(resourceName));
16506
- if (data == null)
16641
+ String[] suffixe = suffixes;
16642
+ String[] fallback = suffixes2;
16643
+ String[] fallfallback = suffixes3;
16644
+
16645
+ for (int c=usedsuf; --c>=0;)
1650716646 {
16508
- throw new IOException("Unable to load texture " + resourceName);
16647
+// String[] temp = suffixe;
16648
+// suffixe = fallback;
16649
+// fallback = fallfallback;
16650
+// fallfallback = temp;
1650916651 }
16652
+
16653
+ String resourceName = basename + suffixe[i] + "." + suffix;
16654
+ TextureData data;
16655
+
16656
+ try
16657
+ {
16658
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16659
+ mipmapped,
16660
+ FileUtil.getFileSuffix(resourceName));
16661
+ }
16662
+ catch (Exception e)
16663
+ {
16664
+ try
16665
+ {
16666
+ resourceName = basename + fallback[i] + "." + suffix;
16667
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16668
+ mipmapped,
16669
+ FileUtil.getFileSuffix(resourceName));
16670
+ }
16671
+ catch (Exception e2)
16672
+ {
16673
+ resourceName = basename + fallfallback[i] + "." + suffix;
16674
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16675
+ mipmapped,
16676
+ FileUtil.getFileSuffix(resourceName));
16677
+ }
16678
+ }
16679
+
1651016680 //System.out.println("Target = " + targets[i]);
1651116681 cubemap.updateImage(data, targets[i]);
1651216682 }
1651316683
1651416684 return cubemap;
1651516685 }
16686
+
1651616687 int bigsphere = -1;
1651716688
1651816689 float BGcolor = 0.5f;
1651916690
16520
- private void DrawSkyBox(GL gl)
16691
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16692
+
16693
+ private void DrawSkyBox(GL gl, float ratio)
1652116694 {
16522
- if (envyoff || cubemap == null)
16695
+ if (//envyoff ||
16696
+ WIREFRAME ||
16697
+ cubemap == null)
1652316698 {
1652416699 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1652516700 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16534,7 +16709,17 @@
1653416709 // Compensates for ExaminerViewer's modification of modelview matrix
1653516710 gl.glMatrixMode(GL.GL_MODELVIEW);
1653616711 gl.glLoadIdentity();
16712
+ gl.glScalef(1,ratio,1);
1653716713
16714
+// colorV[0] = 2;
16715
+// colorV[1] = 2;
16716
+// colorV[2] = 2;
16717
+// colorV[3] = 1;
16718
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16719
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16720
+//
16721
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16722
+
1653816723 //gl.glActiveTexture(GL.GL_TEXTURE1);
1653916724 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1654016725
....@@ -16566,6 +16751,7 @@
1656616751 {
1656716752 gl.glScalef(1.0f, -1.0f, 1.0f);
1656816753 }
16754
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1656916755 gl.glMultMatrixd(viewrot_1, 0);
1657016756 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1657116757 //viewer.updateInverseRotation(gl);
....@@ -16606,7 +16792,8 @@
1660616792 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1660716793
1660816794 cubemap.disable();
16609
- ////cubemap.unbind();
16795
+ //cubemap.dispose();
16796
+
1661016797 if (CULLFACE)
1661116798 {
1661216799 gl.glEnable(gl.GL_CULL_FACE);
....@@ -16824,7 +17011,7 @@
1682417011 //new Exception().printStackTrace();
1682517012 System.out.println("select buffer init");
1682617013 // Use debug pipeline
16827
- drawable.setGL(new DebugGL(drawable.getGL()));
17014
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1682817015
1682917016 GL gl = drawable.getGL();
1683017017
....@@ -17370,10 +17557,14 @@
1737017557 gl.glFlush();
1737117558
1737217559 /**/
17373
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17560
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1737417561
17375
- float[] pixels = occlusionsizebuffer.array();
17562
+ float[] depths = occlusiondepthbuffer.array();
1737617563
17564
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17565
+
17566
+ int[] pixels = selectsizebuffer.array();
17567
+
1737717568 double r = 0, g = 0, b = 0;
1737817569
1737917570 double count = 0;
....@@ -17384,7 +17575,7 @@
1738417575
1738517576 double FACTOR = 1;
1738617577
17387
- for (int i = 0; i < pixels.length; i++)
17578
+ for (int i = 0; i < depths.length; i++)
1738817579 {
1738917580 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1739017581 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17467,7 +17658,7 @@
1746717658
1746817659 double scale = ray.z; // 1; // cos
1746917660
17470
- float depth = pixels[newindex];
17661
+ float depth = depths[newindex];
1747117662
1747217663 /*
1747317664 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17664,11 +17855,14 @@
1766417855 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1766517856 static IntBuffer bigAAbuffer;
1766617857 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17667
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17858
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1766817859 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1766917860 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1767017861 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17671
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17862
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17863
+
17864
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17865
+
1767217866 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1767317867 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1767417868 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();