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,51 +12485,74 @@
1239912485
1240012486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240112487
12402
- String program =
12488
+ String programmin =
1240312489 // Min shader
1240412490 "!!ARBfp1.0\n" +
12405
- "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
1240612492 "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
1240712493 "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1240812494 "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
1240912495 "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];" +
1241012499 "TEMP temp;" +
1241112500 "TEMP light;" +
1241212501 "TEMP ndotl;" +
1241312502 "TEMP normal;" +
1241412503 "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
1241512506
1241612507 "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
-
12508
+ Normalize("normal") +
1241812509 "MOV light, state.light[0].position;" +
1241912510 "DP3 ndotl.x, light, normal;" +
1242012511
1242112512 // shadow
12422
- "MOV temp, fragment.texcoord[1];" +
12423
- TextureFetch("depth", "temp", "1") +
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
1242412516 //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
- "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
-
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
1242712518
1242812519 // No shadow when out of frustum
1242912520 //"SGE temp.y, depth.z, zero123.y;" +
1243012521 //"LRP temp.x, temp.y, zero123.y, temp.x;" +
1243112522
12432
- "MUL ndotl.x, ndotl.x, temp.x;" +
12433
- "MAX ndotl.x, ndotl.x, pow2.y;" +
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
1243412524
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
1243512543 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
1243612544 "LRP temp, zero123.w, temp, one;" + // texture proportion
1243712545 "MUL temp, temp, ndotl.x;" +
1243812546
1243912547 "MUL temp, temp, zero123.z;" +
1244012548
12441
- "MOV temp.w, zero123.y;" + // reset alpha
12549
+ //"MUL temp, temp, ndotl.y;" +
1244212550
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
1244312552 "MOV result.color, temp;" +
1244412553 "END";
1244512554
12446
- String program2 =
12555
+ String programmax =
1244712556 "!!ARBfp1.0\n" +
1244812557
1244912558 //"OPTION ARB_fragment_program_shadow;" +
....@@ -12581,20 +12690,20 @@
1258112690 "MUL temp, floor, mapgrid.x;" +
1258212691 //"TEX depth0, temp, texture[1], 2D;" +
1258312692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12584
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1258512694 "") +
1258612695 "ADD temp.x, temp.x, mapgrid.x;" +
1258712696 //"TEX depth1, temp, texture[1], 2D;" +
1258812697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12589
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1259012699 "") +
1259112700 "ADD temp.y, temp.y, mapgrid.x;" +
1259212701 //"TEX depth2, temp, texture[1], 2D;" +
12593
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1259412703 "SUB temp.x, temp.x, mapgrid.x;" +
1259512704 //"TEX depth3, temp, texture[1], 2D;" +
1259612705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12597
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1259812707 "") +
1259912708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1260012709 //"MOV params, material;" +
....@@ -12968,7 +13077,7 @@
1296813077 // display shadow only (fakedepth == 0)
1296913078 "SUB temp.x, half.x, shadow.x;" +
1297013079 "MOV temp.y, -params5.z;" + // params6.x;" +
12971
- "SLT temp.z, temp.y, -one2048th.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1297213081 "SUB temp.y, one.x, temp.z;" +
1297313082 "MUL temp.x, temp.x, temp.y;" +
1297413083 "KIL temp.x;" +
....@@ -13299,6 +13408,13 @@
1329913408 //once = true;
1330013409 }
1330113410
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
1330213418 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1330313419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1330413420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13392,7 +13508,8 @@
1339213508 return out;
1339313509 }
1339413510
13395
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1339613513 {
1339713514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1339813515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
....@@ -14255,14 +14372,15 @@
1425514372 drag = false;
1425614373 //System.out.println("Mouse DOWN");
1425714374 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);
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);
1426614384 if (!editObj)
1426714385 {
1426814386 hasMarquee = true;
....@@ -14546,9 +14664,9 @@
1454614664 MODIFIERS |= COMMAND;
1454714665 /**/
1454814666 if((mod&SHIFT) == SHIFT)
14549
- manipCamera.RotatePosition(0, -speed);
14550
- else
1455114667 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14668
+ else
14669
+ manipCamera.RotatePosition(0, -speed);
1455214670 /**/
1455314671 if ((mod & SHIFT) == SHIFT)
1455414672 {
....@@ -14567,9 +14685,9 @@
1456714685 MODIFIERS |= COMMAND;
1456814686 /**/
1456914687 if((mod&SHIFT) == SHIFT)
14570
- manipCamera.RotatePosition(0, speed);
14571
- else
1457214688 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14689
+ else
14690
+ manipCamera.RotatePosition(0, speed);
1457314691 /**/
1457414692 if ((mod & SHIFT) == SHIFT)
1457514693 {
....@@ -14662,15 +14780,16 @@
1466214780 if (editObj)
1466314781 {
1466414782 drag = true;
14665
- ClickInfo info = new ClickInfo();
14666
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1466714785 (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);
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);
1467414793 } else
1467514794 {
1467614795 if (x < startX)
....@@ -14819,24 +14938,27 @@
1481914938 }
1482014939 }
1482114940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1482214943 public void mouseMoved(MouseEvent e)
1482314944 {
1482414945 //System.out.println("mouseMoved: " + e);
1482514946 if (isRenderer)
1482614947 return;
1482714948
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;
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;
1483514956 if (!isRenderer)
1483614957 {
1483714958 //ObjEditor editWindow = object.editWindow;
1483814959 //Object3D copy = editWindow.copy;
14839
- if (object.doEditClick(ci, 0))
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1484014962 {
1484114963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1484214964 } else
....@@ -15286,20 +15408,24 @@
1528615408 OCCLUSION_CULLING ^= true;
1528715409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1528815410 break;
15289
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1529015412 case '1':
1529115413 case '2':
1529215414 case '3':
1529315415 case '4':
1529415416 case '5':
15295
- newenvy = Character.getNumericValue(key);
15296
- repaint();
15297
- break;
1529815417 case '6':
1529915418 case '7':
1530015419 case '8':
1530115420 case '9':
15302
- 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
+ }
1530315429 repaint();
1530415430 break;
1530515431 case '!':
....@@ -15862,8 +15988,6 @@
1586215988
1586315989 int width = getBounds().width;
1586415990 int height = getBounds().height;
15865
- ClickInfo info = new ClickInfo();
15866
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1586715991 //Image img = CreateImage(width, height);
1586815992 //System.out.println("width = " + width + "; height = " + height + "\n");
1586915993
....@@ -15940,31 +16064,37 @@
1594016064 }
1594116065 if (object != null && !hasMarquee)
1594216066 {
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
+
1594316073 if (isRenderer)
1594416074 {
15945
- info.flags++;
16075
+ object.clickInfo.flags++;
1594616076 double frameAspect = (double) width / (double) height;
1594716077 if (frameAspect > renderCamera.aspect)
1594816078 {
1594916079 int desired = (int) ((double) height * renderCamera.aspect);
15950
- info.bounds.width -= width - desired;
15951
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1595216082 } else
1595316083 {
1595416084 int desired = (int) ((double) width / renderCamera.aspect);
15955
- info.bounds.height -= height - desired;
15956
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1595716087 }
1595816088 }
1595916089
15960
- info.g = gr;
15961
- info.camera = renderCamera;
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1596216092 /*
1596316093 // Memory intensive (brep.verticescopy)
1596416094 if (!(object instanceof Composite))
1596516095 object.draw(info, 0, false); // SLOW :
1596616096 */
15967
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1596816098 {
1596916099 Grafreed.Assert(object != null);
1597016100 Grafreed.Assert(object.selection != null);
....@@ -15972,9 +16102,9 @@
1597216102 {
1597316103 int hitSomething = object.selection.get(0).hitSomething;
1597416104
15975
- info.DX = 0;
15976
- info.DY = 0;
15977
- info.W = 1;
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
1597816108 if (hitSomething == Object3D.hitCenter)
1597916109 {
1598016110 info.DX = X;
....@@ -15986,7 +16116,8 @@
1598616116 info.DY -= info.bounds.height/2;
1598716117 }
1598816118
15989
- object.drawEditHandles(info, 0);
16119
+ object.drawEditHandles(//info,
16120
+ 0);
1599016121
1599116122 if (drag && (X != 0 || Y != 0))
1599216123 {
....@@ -16485,6 +16616,8 @@
1648516616 private /*static*/ boolean firstime;
1648616617 private /*static*/ cVector newView = new cVector();
1648716618 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"};
1648816621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1648916622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1649016623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16497,29 +16630,67 @@
1649716630 {
1649816631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1649916632
16633
+ int usedsuf = 0;
16634
+
1650016635 for (int i = 0; i < suffixes.length; i++)
1650116636 {
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)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1650716642 {
16508
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1650916647 }
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
+
1651016676 //System.out.println("Target = " + targets[i]);
1651116677 cubemap.updateImage(data, targets[i]);
1651216678 }
1651316679
1651416680 return cubemap;
1651516681 }
16682
+
1651616683 int bigsphere = -1;
1651716684
1651816685 float BGcolor = 0.5f;
1651916686
16520
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1652116690 {
16522
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1652316694 {
1652416695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1652516696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16534,7 +16705,17 @@
1653416705 // Compensates for ExaminerViewer's modification of modelview matrix
1653516706 gl.glMatrixMode(GL.GL_MODELVIEW);
1653616707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1653716709
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
+
1653816719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1653916720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1654016721
....@@ -16566,6 +16747,7 @@
1656616747 {
1656716748 gl.glScalef(1.0f, -1.0f, 1.0f);
1656816749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1656916751 gl.glMultMatrixd(viewrot_1, 0);
1657016752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1657116753 //viewer.updateInverseRotation(gl);
....@@ -16824,7 +17006,7 @@
1682417006 //new Exception().printStackTrace();
1682517007 System.out.println("select buffer init");
1682617008 // Use debug pipeline
16827
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1682817010
1682917011 GL gl = drawable.getGL();
1683017012
....@@ -17370,10 +17552,14 @@
1737017552 gl.glFlush();
1737117553
1737217554 /**/
17373
- 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);
1737417556
17375
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1737617558
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
+
1737717563 double r = 0, g = 0, b = 0;
1737817564
1737917565 double count = 0;
....@@ -17384,7 +17570,7 @@
1738417570
1738517571 double FACTOR = 1;
1738617572
17387
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1738817574 {
1738917575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1739017576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17467,7 +17653,7 @@
1746717653
1746817654 double scale = ray.z; // 1; // cos
1746917655
17470
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1747117657
1747217658 /*
1747317659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17664,11 +17850,14 @@
1766417850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1766517851 static IntBuffer bigAAbuffer;
1766617852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17667
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1766817854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1766917855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1767017856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17671
- 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
+
1767217861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1767317862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1767417863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();