Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
CameraPane.java
....@@ -110,7 +110,9 @@
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;
114116 boolean reverseUP = false;
115117 static boolean frozen = false;
116118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -173,7 +175,7 @@
173175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
174176 boolean anisotropy = true;
175177 boolean softshadow = true; // slower but better false;
176
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
177179
178180 boolean macromode = false;
179181
....@@ -187,6 +189,19 @@
187189 }
188190
189191 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
192
+
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
204
+ }
190205
191206 void SetAsGLRenderer(boolean b)
192207 {
....@@ -206,7 +221,8 @@
206221
207222 SetCamera(cam);
208223
209
- SetLight(new Camera(new cVector(10, 10, -20)));
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
210226
211227 object = o;
212228
....@@ -1484,6 +1500,8 @@
14841500 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14851501 }
14861502
1503
+ float[] colorV = new float[4];
1504
+
14871505 void SetColor(Object3D obj, Vertex p0)
14881506 {
14891507 CameraPane display = this;
....@@ -1551,8 +1569,6 @@
15511569 {
15521570 return;
15531571 }
1554
-
1555
- float[] colorV = new float[3];
15561572
15571573 if (false) // marked)
15581574 {
....@@ -8345,7 +8361,7 @@
83458361 // else
83468362 // if (!texname.startsWith("/"))
83478363 // texname = "/Users/nbriere/Textures/" + texname;
8348
- if (!FileExists(texname))
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
83498365 {
83508366 texname = fallbackTextureName;
83518367 }
....@@ -8428,6 +8444,15 @@
84288444 new Exception().printStackTrace();
84298445 } else
84308446 {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
8454
+ } else
8455
+ {
84318456 if (textureon)
84328457 {
84338458 String cachename = texname;
....@@ -8487,6 +8512,7 @@
84878512 texturecache = new CacheTexture(texturedata,resolution);
84888513 //texture = GetTexture(tex, bump);
84898514 }
8515
+ }
84908516 }
84918517 //}
84928518 }
....@@ -8755,10 +8781,12 @@
87558781
87568782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87578783 MAXSTACK = temp[0];
8758
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87598786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87608787 MAXSTACK = temp[0];
8761
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87628790
87638791 // Use debug pipeline
87648792 //drawable.setGL(new DebugGL(gl)); //
....@@ -8766,7 +8794,8 @@
87668794 gl = drawable.getGL(); //
87678795
87688796 GL gl3 = getGL();
8769
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87708799
87718800
87728801 //float pos[] = { 100, 100, 100, 0 };
....@@ -8931,7 +8960,7 @@
89318960
89328961 if (cubemap == null)
89338962 {
8934
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
89358964 }
89368965
89378966 //cubemap.enable();
....@@ -9207,6 +9236,8 @@
92079236
92089237 void LoadEnvy(int which)
92099238 {
9239
+ assert(false);
9240
+
92109241 String name;
92119242 String ext;
92129243
....@@ -9218,37 +9249,58 @@
92189249 cubemap = null;
92199250 return;
92209251 case 1:
9221
- name = "cubemaps/box_";
9222
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
92239254 reverseUP = false;
92249255 break;
92259256 case 2:
9226
- name = "cubemaps/uffizi_";
9227
- ext = "png";
9228
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
92299261 case 3:
9230
- name = "cubemaps/CloudyHills_";
9231
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
92329264 reverseUP = false;
92339265 break;
92349266 case 4:
9235
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
92369268 ext = "png";
92379269 reverseUP = false;
92389270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
92399296 default:
9240
- name = "cubemaps/rgb_";
9241
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
92429300 break;
92439301 }
9244
-
9245
- try
9246
- {
9247
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9248
- } catch (IOException e)
9249
- {
9250
- throw new RuntimeException(e);
9251
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
92529304 }
92539305
92549306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9280,8 +9332,12 @@
92809332 static double[] model = new double[16];
92819333 double[] camera2light = new double[16];
92829334 double[] light2camera = new double[16];
9283
- int newenvy = -1;
9284
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
92859341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92869342 //float[] light0 = { 0,0,0 };
92879343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9699,7 +9755,7 @@
96999755
97009756 if (renderCamera != lightCamera)
97019757 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
97039759
97049760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
97059761
....@@ -9715,7 +9771,7 @@
97159771
97169772 if (renderCamera != lightCamera)
97179773 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
97199775
97209776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
97219777
....@@ -9761,10 +9817,12 @@
97619817 rati = 1 / rati;
97629818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
97639819 }
9764
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
97659823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
97669824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9767
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
97689826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
97699827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
97709828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10801,7 +10859,7 @@
1080110859
1080210860 if (wait)
1080310861 {
10804
- Sleep(500);
10862
+ Sleep(200); // blocks everything
1080510863
1080610864 wait = false;
1080710865 }
....@@ -10916,7 +10974,7 @@
1091610974 // if (parentcam != renderCamera) // not a light
1091710975 if (cam != lightCamera)
1091810976 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1092010978
1092110979 for (int j = 0; j < 4; j++)
1092210980 {
....@@ -10931,7 +10989,7 @@
1093110989 // if (parentcam != renderCamera) // not a light
1093210990 if (cam != lightCamera)
1093310991 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1093510993
1093610994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1093710995
....@@ -11017,13 +11075,41 @@
1101711075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1101811076 }
1101911077
11020
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
1102111086 {
11022
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
1102311093 }
11024
-
11025
- newenvy = -1;
11026
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
1102711113 ratio = ((double) getWidth()) / getHeight();
1102811114 //System.out.println("ratio = " + ratio);
1102911115
....@@ -11039,7 +11125,7 @@
1103911125
1104011126 if (!IsFrozen() && !ambientOcclusion)
1104111127 {
11042
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
1104311129 }
1104411130
1104511131 //if (selection_view == -1)
....@@ -11325,7 +11411,7 @@
1132511411
1132611412 // if (cam != lightCamera)
1132711413 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11328
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1132911415 }
1133011416
1133111417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -12399,8 +12485,76 @@
1239912485
1240012486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240112487
12402
- String program =
12488
+ String programmin =
12489
+ // Min shader
1240312490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1240412558 //"OPTION ARB_fragment_program_shadow;" +
1240512559 "PARAM light2cam0 = program.env[10];" +
1240612560 "PARAM light2cam1 = program.env[11];" +
....@@ -12515,8 +12669,7 @@
1251512669 "TEMP shininess;" +
1251612670 "\n" +
1251712671 "MOV texSamp, one;" +
12518
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
12519
-
12672
+
1252012673 "MOV mapgrid.x, one2048th.x;" +
1252112674 "MOV temp, fragment.texcoord[1];" +
1252212675 /*
....@@ -12537,20 +12690,20 @@
1253712690 "MUL temp, floor, mapgrid.x;" +
1253812691 //"TEX depth0, temp, texture[1], 2D;" +
1253912692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12540
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1254112694 "") +
1254212695 "ADD temp.x, temp.x, mapgrid.x;" +
1254312696 //"TEX depth1, temp, texture[1], 2D;" +
1254412697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12545
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1254612699 "") +
1254712700 "ADD temp.y, temp.y, mapgrid.x;" +
1254812701 //"TEX depth2, temp, texture[1], 2D;" +
12549
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1255012703 "SUB temp.x, temp.x, mapgrid.x;" +
1255112704 //"TEX depth3, temp, texture[1], 2D;" +
1255212705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12553
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1255412707 "") +
1255512708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1255612709 //"MOV params, material;" +
....@@ -12921,10 +13074,10 @@
1292113074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1292213075 "") +
1292313076
12924
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1292513078 "SUB temp.x, half.x, shadow.x;" +
1292613079 "MOV temp.y, -params5.z;" + // params6.x;" +
12927
- "SLT temp.z, temp.y, -one2048th.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1292813081 "SUB temp.y, one.x, temp.z;" +
1292913082 "MUL temp.x, temp.x, temp.y;" +
1293013083 "KIL temp.x;" +
....@@ -13255,6 +13408,13 @@
1325513408 //once = true;
1325613409 }
1325713410
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
1325813418 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1325913419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1326013420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13348,25 +13508,26 @@
1334813508 return out;
1334913509 }
1335013510
13351
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1335213513 {
1335313514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1335413515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1335513516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1335613519 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13357
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13358
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13359
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13360
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1336113522 //"SWZ buffer, temp, w,w,w,w;";
13362
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1336313524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1336413525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1336513526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13366
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1336713528
13368
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13369
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1337013531 }
1337113532
1337213533 String Shadow(String depth, String shadow)
....@@ -13413,7 +13574,7 @@
1341313574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
1341413575 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1341513576
13416
- // No shadow when out of frustrum
13577
+ // No shadow when out of frustum
1341713578 "SGE temp.x, " + depth + ".z, one.z;" +
1341813579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1341913580 "";
....@@ -14211,14 +14372,15 @@
1421114372 drag = false;
1421214373 //System.out.println("Mouse DOWN");
1421314374 editObj = false;
14214
- ClickInfo info = new ClickInfo();
14215
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14216
- info.pane = this;
14217
- info.camera = renderCamera;
14218
- info.x = x;
14219
- info.y = y;
14220
- info.modifiers = modifiersex;
14221
- editObj = object.doEditClick(info, 0);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1422214384 if (!editObj)
1422314385 {
1422414386 hasMarquee = true;
....@@ -14502,9 +14664,9 @@
1450214664 MODIFIERS |= COMMAND;
1450314665 /**/
1450414666 if((mod&SHIFT) == SHIFT)
14505
- manipCamera.RotatePosition(0, -speed);
14506
- else
1450714667 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14668
+ else
14669
+ manipCamera.RotatePosition(0, -speed);
1450814670 /**/
1450914671 if ((mod & SHIFT) == SHIFT)
1451014672 {
....@@ -14523,9 +14685,9 @@
1452314685 MODIFIERS |= COMMAND;
1452414686 /**/
1452514687 if((mod&SHIFT) == SHIFT)
14526
- manipCamera.RotatePosition(0, speed);
14527
- else
1452814688 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14689
+ else
14690
+ manipCamera.RotatePosition(0, speed);
1452914691 /**/
1453014692 if ((mod & SHIFT) == SHIFT)
1453114693 {
....@@ -14618,15 +14780,16 @@
1461814780 if (editObj)
1461914781 {
1462014782 drag = true;
14621
- ClickInfo info = new ClickInfo();
14622
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1462314785 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14624
- info.pane = this;
14625
- info.camera = renderCamera;
14626
- info.x = x;
14627
- info.y = y;
14628
- object.GetWindow().copy
14629
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1463014793 } else
1463114794 {
1463214795 if (x < startX)
....@@ -14775,24 +14938,27 @@
1477514938 }
1477614939 }
1477714940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1477814943 public void mouseMoved(MouseEvent e)
1477914944 {
1478014945 //System.out.println("mouseMoved: " + e);
1478114946 if (isRenderer)
1478214947 return;
1478314948
14784
- ClickInfo ci = new ClickInfo();
14785
- ci.x = e.getX();
14786
- ci.y = e.getY();
14787
- ci.modifiers = e.getModifiersEx();
14788
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14789
- ci.pane = this;
14790
- ci.camera = renderCamera;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1479114956 if (!isRenderer)
1479214957 {
1479314958 //ObjEditor editWindow = object.editWindow;
1479414959 //Object3D copy = editWindow.copy;
14795
- if (object.doEditClick(ci, 0))
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1479614962 {
1479714963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1479814964 } else
....@@ -15242,20 +15408,24 @@
1524215408 OCCLUSION_CULLING ^= true;
1524315409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1524415410 break;
15245
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1524615412 case '1':
1524715413 case '2':
1524815414 case '3':
1524915415 case '4':
1525015416 case '5':
15251
- newenvy = Character.getNumericValue(key);
15252
- repaint();
15253
- break;
1525415417 case '6':
1525515418 case '7':
1525615419 case '8':
1525715420 case '9':
15258
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1525915429 repaint();
1526015430 break;
1526115431 case '!':
....@@ -15818,8 +15988,6 @@
1581815988
1581915989 int width = getBounds().width;
1582015990 int height = getBounds().height;
15821
- ClickInfo info = new ClickInfo();
15822
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1582315991 //Image img = CreateImage(width, height);
1582415992 //System.out.println("width = " + width + "; height = " + height + "\n");
1582515993
....@@ -15896,31 +16064,37 @@
1589616064 }
1589716065 if (object != null && !hasMarquee)
1589816066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1589916073 if (isRenderer)
1590016074 {
15901
- info.flags++;
16075
+ object.clickInfo.flags++;
1590216076 double frameAspect = (double) width / (double) height;
1590316077 if (frameAspect > renderCamera.aspect)
1590416078 {
1590516079 int desired = (int) ((double) height * renderCamera.aspect);
15906
- info.bounds.width -= width - desired;
15907
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1590816082 } else
1590916083 {
1591016084 int desired = (int) ((double) width / renderCamera.aspect);
15911
- info.bounds.height -= height - desired;
15912
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1591316087 }
1591416088 }
1591516089
15916
- info.g = gr;
15917
- info.camera = renderCamera;
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1591816092 /*
1591916093 // Memory intensive (brep.verticescopy)
1592016094 if (!(object instanceof Composite))
1592116095 object.draw(info, 0, false); // SLOW :
1592216096 */
15923
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1592416098 {
1592516099 Grafreed.Assert(object != null);
1592616100 Grafreed.Assert(object.selection != null);
....@@ -15928,9 +16102,9 @@
1592816102 {
1592916103 int hitSomething = object.selection.get(0).hitSomething;
1593016104
15931
- info.DX = 0;
15932
- info.DY = 0;
15933
- info.W = 1;
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
1593416108 if (hitSomething == Object3D.hitCenter)
1593516109 {
1593616110 info.DX = X;
....@@ -15942,7 +16116,8 @@
1594216116 info.DY -= info.bounds.height/2;
1594316117 }
1594416118
15945
- object.drawEditHandles(info, 0);
16119
+ object.drawEditHandles(//info,
16120
+ 0);
1594616121
1594716122 if (drag && (X != 0 || Y != 0))
1594816123 {
....@@ -16441,6 +16616,8 @@
1644116616 private /*static*/ boolean firstime;
1644216617 private /*static*/ cVector newView = new cVector();
1644316618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1644416621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1644516622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1644616623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16453,29 +16630,67 @@
1645316630 {
1645416631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1645516632
16633
+ int usedsuf = 0;
16634
+
1645616635 for (int i = 0; i < suffixes.length; i++)
1645716636 {
16458
- String resourceName = basename + suffixes[i] + "." + suffix;
16459
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16460
- mipmapped,
16461
- FileUtil.getFileSuffix(resourceName));
16462
- if (data == null)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1646316642 {
16464
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1646516647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1646616676 //System.out.println("Target = " + targets[i]);
1646716677 cubemap.updateImage(data, targets[i]);
1646816678 }
1646916679
1647016680 return cubemap;
1647116681 }
16682
+
1647216683 int bigsphere = -1;
1647316684
1647416685 float BGcolor = 0.5f;
1647516686
16476
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1647716690 {
16478
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1647916694 {
1648016695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1648116696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16490,7 +16705,17 @@
1649016705 // Compensates for ExaminerViewer's modification of modelview matrix
1649116706 gl.glMatrixMode(GL.GL_MODELVIEW);
1649216707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1649316709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1649416719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1649516720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1649616721
....@@ -16522,6 +16747,7 @@
1652216747 {
1652316748 gl.glScalef(1.0f, -1.0f, 1.0f);
1652416749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1652516751 gl.glMultMatrixd(viewrot_1, 0);
1652616752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1652716753 //viewer.updateInverseRotation(gl);
....@@ -16780,7 +17006,7 @@
1678017006 //new Exception().printStackTrace();
1678117007 System.out.println("select buffer init");
1678217008 // Use debug pipeline
16783
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1678417010
1678517011 GL gl = drawable.getGL();
1678617012
....@@ -17326,10 +17552,14 @@
1732617552 gl.glFlush();
1732717553
1732817554 /**/
17329
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1733017556
17331
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1733217558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1733317563 double r = 0, g = 0, b = 0;
1733417564
1733517565 double count = 0;
....@@ -17340,7 +17570,7 @@
1734017570
1734117571 double FACTOR = 1;
1734217572
17343
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1734417574 {
1734517575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1734617576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17423,7 +17653,7 @@
1742317653
1742417654 double scale = ray.z; // 1; // cos
1742517655
17426
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1742717657
1742817658 /*
1742917659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17620,11 +17850,14 @@
1762017850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1762117851 static IntBuffer bigAAbuffer;
1762217852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17623
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1762417854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1762517855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1762617856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17627
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1762817861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1762917862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1763017863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();