Normand Briere
2019-08-13 0cdf3fb57ddea3226f094ba45c836c7e9b123e3a
CameraPane.java
....@@ -173,7 +173,7 @@
173173 static boolean doublesided = false; // true; // reversed normals are awful for conformance
174174 boolean anisotropy = true;
175175 boolean softshadow = true; // slower but better false;
176
- boolean opacityhalo = false;
176
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
177177
178178 boolean macromode = false;
179179
....@@ -187,6 +187,18 @@
187187 }
188188
189189 private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
190202
191203 void SetAsGLRenderer(boolean b)
192204 {
....@@ -206,7 +218,8 @@
206218
207219 SetCamera(cam);
208220
209
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
210223
211224 object = o;
212225
....@@ -1484,6 +1497,8 @@
14841497 gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
14851498 }
14861499
1500
+ float[] colorV = new float[4];
1501
+
14871502 void SetColor(Object3D obj, Vertex p0)
14881503 {
14891504 CameraPane display = this;
....@@ -1551,8 +1566,6 @@
15511566 {
15521567 return;
15531568 }
1554
-
1555
- float[] colorV = new float[3];
15561569
15571570 if (false) // marked)
15581571 {
....@@ -8345,7 +8358,7 @@
83458358 // else
83468359 // if (!texname.startsWith("/"))
83478360 // texname = "/Users/nbriere/Textures/" + texname;
8348
- if (!FileExists(texname))
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
83498362 {
83508363 texname = fallbackTextureName;
83518364 }
....@@ -8428,6 +8441,15 @@
84288441 new Exception().printStackTrace();
84298442 } else
84308443 {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8449
+ else
8450
+ new Exception().printStackTrace();
8451
+ } else
8452
+ {
84318453 if (textureon)
84328454 {
84338455 String cachename = texname;
....@@ -8487,6 +8509,7 @@
84878509 texturecache = new CacheTexture(texturedata,resolution);
84888510 //texture = GetTexture(tex, bump);
84898511 }
8512
+ }
84908513 }
84918514 //}
84928515 }
....@@ -8755,10 +8778,12 @@
87558778
87568779 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
87578780 MAXSTACK = temp[0];
8758
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8781
+ if (Globals.DEBUG)
8782
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
87598783 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
87608784 MAXSTACK = temp[0];
8761
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8785
+ if (Globals.DEBUG)
8786
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
87628787
87638788 // Use debug pipeline
87648789 //drawable.setGL(new DebugGL(gl)); //
....@@ -8766,7 +8791,8 @@
87668791 gl = drawable.getGL(); //
87678792
87688793 GL gl3 = getGL();
8769
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8794
+ if (Globals.DEBUG)
8795
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
87708796
87718797
87728798 //float pos[] = { 100, 100, 100, 0 };
....@@ -8931,7 +8957,7 @@
89318957
89328958 if (cubemap == null)
89338959 {
8934
- LoadEnvy(5);
8960
+ //LoadEnvy(1);
89358961 }
89368962
89378963 //cubemap.enable();
....@@ -9218,37 +9244,58 @@
92189244 cubemap = null;
92199245 return;
92209246 case 1:
9221
- name = "cubemaps/box_";
9222
- ext = "png";
9247
+ name = "cubemaps/rgb/";
9248
+ ext = "jpg";
92239249 reverseUP = false;
92249250 break;
92259251 case 2:
9226
- name = "cubemaps/uffizi_";
9227
- ext = "png";
9228
- break; // reverseUP = true; break;
9252
+ name = "cubemaps/uffizi/";
9253
+ ext = "jpg";
9254
+ reverseUP = false;
9255
+ break;
92299256 case 3:
9230
- name = "cubemaps/CloudyHills_";
9231
- ext = "tga";
9257
+ name = "cubemaps/CloudyHills/";
9258
+ ext = "jpg";
92329259 reverseUP = false;
92339260 break;
92349261 case 4:
9235
- name = "cubemaps/cornell_";
9262
+ name = "cubemaps/cornell/";
92369263 ext = "png";
92379264 reverseUP = false;
92389265 break;
9266
+ case 5:
9267
+ name = "cubemaps/skycube/";
9268
+ ext = "jpg";
9269
+ reverseUP = false;
9270
+ break;
9271
+ case 6:
9272
+ name = "cubemaps/SaintLazarusChurch3/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 7:
9277
+ name = "cubemaps/Sodermalmsallen/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 8:
9282
+ name = "cubemaps/Sodermalmsallen2/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 9:
9287
+ name = "cubemaps/UnionSquare/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
92399291 default:
9240
- name = "cubemaps/rgb_";
9241
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9292
+ name = "cubemaps/box/";
9293
+ ext = "png"; /*mipmap = true;*/
9294
+ reverseUP = false;
92429295 break;
92439296 }
9244
-
9245
- try
9246
- {
9247
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
9248
- } catch (IOException e)
9249
- {
9250
- throw new RuntimeException(e);
9251
- }
9297
+
9298
+ LoadSkybox(name, ext, mipmap);
92529299 }
92539300
92549301 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -9280,8 +9327,12 @@
92809327 static double[] model = new double[16];
92819328 double[] camera2light = new double[16];
92829329 double[] light2camera = new double[16];
9283
- int newenvy = -1;
9284
- boolean envyoff = true; // false;
9330
+
9331
+ //int newenvy = -1;
9332
+ //boolean envyoff = false;
9333
+
9334
+ String loadedskyboxname;
9335
+
92859336 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
92869337 //float[] light0 = { 0,0,0 };
92879338 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -9699,7 +9750,7 @@
96999750
97009751 if (renderCamera != lightCamera)
97019752 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
9753
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
97039754
97049755 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
97059756
....@@ -9715,7 +9766,7 @@
97159766
97169767 if (renderCamera != lightCamera)
97179768 //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
9769
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
97199770
97209771 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
97219772
....@@ -9761,10 +9812,12 @@
97619812 rati = 1 / rati;
97629813 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
97639814 }
9764
- assert (newenvy == -1);
9815
+
9816
+ //assert (newenvy == -1);
9817
+
97659818 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
97669819 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
9767
- DrawSkyBox(gl);
9820
+ DrawSkyBox(gl, (float)rati);
97689821 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
97699822 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
97709823 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -10801,7 +10854,7 @@
1080110854
1080210855 if (wait)
1080310856 {
10804
- Sleep(500);
10857
+ Sleep(200); // blocks everything
1080510858
1080610859 wait = false;
1080710860 }
....@@ -10916,7 +10969,7 @@
1091610969 // if (parentcam != renderCamera) // not a light
1091710970 if (cam != lightCamera)
1091810971 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
- LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
10972
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
1092010973
1092110974 for (int j = 0; j < 4; j++)
1092210975 {
....@@ -10931,7 +10984,7 @@
1093110984 // if (parentcam != renderCamera) // not a light
1093210985 if (cam != lightCamera)
1093310986 //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
- LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
10987
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
1093510988
1093610989 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1093710990
....@@ -11017,13 +11070,27 @@
1101711070 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
1101811071 }
1101911072
11020
- if (newenvy > -1)
11073
+// if (newenvy > -1)
11074
+// {
11075
+// LoadEnvy(newenvy);
11076
+// }
11077
+//
11078
+// newenvy = -1;
11079
+
11080
+ if (object.skyboxname != null)
1102111081 {
11022
- LoadEnvy(newenvy);
11082
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11083
+ {
11084
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
+ loadedskyboxname = object.skyboxname;
11086
+ }
1102311087 }
11024
-
11025
- newenvy = -1;
11026
-
11088
+ else
11089
+ {
11090
+ cubemap = null;
11091
+ loadedskyboxname = null;
11092
+ }
11093
+
1102711094 ratio = ((double) getWidth()) / getHeight();
1102811095 //System.out.println("ratio = " + ratio);
1102911096
....@@ -11039,7 +11106,7 @@
1103911106
1104011107 if (!IsFrozen() && !ambientOcclusion)
1104111108 {
11042
- DrawSkyBox(gl);
11109
+ DrawSkyBox(gl, (float)ratio);
1104311110 }
1104411111
1104511112 //if (selection_view == -1)
....@@ -11325,7 +11392,7 @@
1132511392
1132611393 // if (cam != lightCamera)
1132711394 //for (int count = parentcam.GetTransformCount(); --count>=0;)
11328
- LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
11395
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1132911396 }
1133011397
1133111398 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -12399,50 +12466,74 @@
1239912466
1240012467 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1240112468
12402
- String program =
12469
+ String programmin =
1240312470 // Min shader
1240412471 "!!ARBfp1.0\n" +
12405
- "PARAM zero123 = { 0.0, 1.0, 2.0, 3.0 };" +
12472
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
1240612473 "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
1240712474 "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1240812475 "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
1240912476 "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12477
+ "PARAM light2cam0 = program.env[10];" +
12478
+ "PARAM light2cam1 = program.env[11];" +
12479
+ "PARAM light2cam2 = program.env[12];" +
1241012480 "TEMP temp;" +
1241112481 "TEMP light;" +
1241212482 "TEMP ndotl;" +
1241312483 "TEMP normal;" +
1241412484 "TEMP depth;" +
12485
+ "TEMP eye;" +
12486
+ "TEMP pos;" +
1241512487
1241612488 "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
-
12489
+ Normalize("normal") +
1241812490 "MOV light, state.light[0].position;" +
1241912491 "DP3 ndotl.x, light, normal;" +
1242012492
1242112493 // shadow
12422
- "MOV temp, fragment.texcoord[1];" +
12423
- TextureFetch("depth", "temp", "1") +
12494
+ "MOV pos, fragment.texcoord[1];" +
12495
+ "MOV temp, pos;" +
12496
+ ShadowTextureFetch("depth", "temp", "1") +
1242412497 //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
- "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
-
12498
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
1242712499
1242812500 // No shadow when out of frustum
1242912501 //"SGE temp.y, depth.z, zero123.y;" +
1243012502 //"LRP temp.x, temp.y, zero123.y, temp.x;" +
1243112503
12432
- "MUL ndotl.x, ndotl.x, temp.x;" +
12433
- "MAX ndotl.x, ndotl.x, pow2.y;" +
12504
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
1243412505
12506
+ // Backlit
12507
+ "MOV pos.w, zero123.y;" +
12508
+ "DP4 eye.x, pos, light2cam0;" +
12509
+ "DP4 eye.y, pos, light2cam1;" +
12510
+ "DP4 eye.z, pos, light2cam2;" +
12511
+ Normalize("eye") +
12512
+
12513
+ "DP3 ndotl.y, -eye, normal;" +
12514
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12515
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12516
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12517
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12518
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12519
+
12520
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12521
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12522
+
12523
+ // Pigment
1243512524 "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12525
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
1243612526 "MUL temp, temp, ndotl.x;" +
1243712527
1243812528 "MUL temp, temp, zero123.z;" +
1243912529
12440
- "MOV temp.w, zero123.y;" + // reset alpha
12530
+ //"MUL temp, temp, ndotl.y;" +
1244112531
12532
+ "MOV temp.w, zero123.y;" + // reset alpha
1244212533 "MOV result.color, temp;" +
1244312534 "END";
1244412535
12445
- String program2 =
12536
+ String programmax =
1244612537 "!!ARBfp1.0\n" +
1244712538
1244812539 //"OPTION ARB_fragment_program_shadow;" +
....@@ -12580,20 +12671,20 @@
1258012671 "MUL temp, floor, mapgrid.x;" +
1258112672 //"TEX depth0, temp, texture[1], 2D;" +
1258212673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12583
- TextureFetch("depth0", "temp", "1") +
12674
+ ShadowTextureFetch("depth0", "temp", "1") +
1258412675 "") +
1258512676 "ADD temp.x, temp.x, mapgrid.x;" +
1258612677 //"TEX depth1, temp, texture[1], 2D;" +
1258712678 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12588
- TextureFetch("depth1", "temp", "1") +
12679
+ ShadowTextureFetch("depth1", "temp", "1") +
1258912680 "") +
1259012681 "ADD temp.y, temp.y, mapgrid.x;" +
1259112682 //"TEX depth2, temp, texture[1], 2D;" +
12592
- TextureFetch("depth2", "temp", "1") +
12683
+ ShadowTextureFetch("depth2", "temp", "1") +
1259312684 "SUB temp.x, temp.x, mapgrid.x;" +
1259412685 //"TEX depth3, temp, texture[1], 2D;" +
1259512686 (((mode & FP_SOFTSHADOW) == 0) ? "" :
12596
- TextureFetch("depth3", "temp", "1") +
12687
+ ShadowTextureFetch("depth3", "temp", "1") +
1259712688 "") +
1259812689 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1259912690 //"MOV params, material;" +
....@@ -12967,7 +13058,7 @@
1296713058 // display shadow only (fakedepth == 0)
1296813059 "SUB temp.x, half.x, shadow.x;" +
1296913060 "MOV temp.y, -params5.z;" + // params6.x;" +
12970
- "SLT temp.z, temp.y, -one2048th.x;" +
13061
+ "SLT temp.z, temp.y, -c256i.x;" +
1297113062 "SUB temp.y, one.x, temp.z;" +
1297213063 "MUL temp.x, temp.x, temp.y;" +
1297313064 "KIL temp.x;" +
....@@ -13298,6 +13389,13 @@
1329813389 //once = true;
1329913390 }
1330013391
13392
+ String program = programmax;
13393
+
13394
+ if (Globals.MINSHADER)
13395
+ {
13396
+ program = programmin;
13397
+ }
13398
+
1330113399 System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1330213400 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1330313401 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
....@@ -13391,25 +13489,26 @@
1339113489 return out;
1339213490 }
1339313491
13394
- String TextureFetch(String dest, String src, String unit)
13492
+ // Also does frustum culling
13493
+ String ShadowTextureFetch(String dest, String src, String unit)
1339513494 {
1339613495 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1339713496 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1339813497 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13498
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13499
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1339913500 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13400
- "SLT " + src + ".z, " + src + ".x, one.x;" +
13401
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13402
- "SLT " + src + ".z, " + src + ".y, one.x;" +
13403
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13501
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13502
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1340413503 //"SWZ buffer, temp, w,w,w,w;";
13405
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13504
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1340613505 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1340713506 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1340813507 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
13409
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13508
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1341013509
13411
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13412
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13510
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13511
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1341313512 }
1341413513
1341513514 String Shadow(String depth, String shadow)
....@@ -14254,14 +14353,15 @@
1425414353 drag = false;
1425514354 //System.out.println("Mouse DOWN");
1425614355 editObj = false;
14257
- ClickInfo info = new ClickInfo();
14258
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14259
- info.pane = this;
14260
- info.camera = renderCamera;
14261
- info.x = x;
14262
- info.y = y;
14263
- info.modifiers = modifiersex;
14264
- editObj = object.doEditClick(info, 0);
14356
+ //ClickInfo info = new ClickInfo();
14357
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14358
+ object.clickInfo.pane = this;
14359
+ object.clickInfo.camera = renderCamera;
14360
+ object.clickInfo.x = x;
14361
+ object.clickInfo.y = y;
14362
+ object.clickInfo.modifiers = modifiersex;
14363
+ editObj = object.doEditClick(//info,
14364
+ 0);
1426514365 if (!editObj)
1426614366 {
1426714367 hasMarquee = true;
....@@ -14545,9 +14645,9 @@
1454514645 MODIFIERS |= COMMAND;
1454614646 /**/
1454714647 if((mod&SHIFT) == SHIFT)
14548
- manipCamera.RotatePosition(0, -speed);
14549
- else
1455014648 manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14649
+ else
14650
+ manipCamera.RotatePosition(0, -speed);
1455114651 /**/
1455214652 if ((mod & SHIFT) == SHIFT)
1455314653 {
....@@ -14566,9 +14666,9 @@
1456614666 MODIFIERS |= COMMAND;
1456714667 /**/
1456814668 if((mod&SHIFT) == SHIFT)
14569
- manipCamera.RotatePosition(0, speed);
14570
- else
1457114669 manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14670
+ else
14671
+ manipCamera.RotatePosition(0, speed);
1457214672 /**/
1457314673 if ((mod & SHIFT) == SHIFT)
1457414674 {
....@@ -14661,15 +14761,16 @@
1466114761 if (editObj)
1466214762 {
1466314763 drag = true;
14664
- ClickInfo info = new ClickInfo();
14665
- info.bounds.setBounds(0, 0,
14764
+ //ClickInfo info = new ClickInfo();
14765
+ object.clickInfo.bounds.setBounds(0, 0,
1466614766 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14667
- info.pane = this;
14668
- info.camera = renderCamera;
14669
- info.x = x;
14670
- info.y = y;
14671
- object.GetWindow().copy
14672
- .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
14767
+ object.clickInfo.pane = this;
14768
+ object.clickInfo.camera = renderCamera;
14769
+ object.clickInfo.x = x;
14770
+ object.clickInfo.y = y;
14771
+ object //.GetWindow().copy
14772
+ .doEditDrag(//info,
14773
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1467314774 } else
1467414775 {
1467514776 if (x < startX)
....@@ -14818,24 +14919,27 @@
1481814919 }
1481914920 }
1482014921
14922
+// ClickInfo clickInfo = new ClickInfo();
14923
+
1482114924 public void mouseMoved(MouseEvent e)
1482214925 {
1482314926 //System.out.println("mouseMoved: " + e);
1482414927 if (isRenderer)
1482514928 return;
1482614929
14827
- ClickInfo ci = new ClickInfo();
14828
- ci.x = e.getX();
14829
- ci.y = e.getY();
14830
- ci.modifiers = e.getModifiersEx();
14831
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14832
- ci.pane = this;
14833
- ci.camera = renderCamera;
14930
+ // Mouse cursor feedback
14931
+ object.clickInfo.x = e.getX();
14932
+ object.clickInfo.y = e.getY();
14933
+ object.clickInfo.modifiers = e.getModifiersEx();
14934
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14935
+ object.clickInfo.pane = this;
14936
+ object.clickInfo.camera = renderCamera;
1483414937 if (!isRenderer)
1483514938 {
1483614939 //ObjEditor editWindow = object.editWindow;
1483714940 //Object3D copy = editWindow.copy;
14838
- if (object.doEditClick(ci, 0))
14941
+ if (object.doEditClick(//clickInfo,
14942
+ 0))
1483914943 {
1484014944 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1484114945 } else
....@@ -15285,20 +15389,24 @@
1528515389 OCCLUSION_CULLING ^= true;
1528615390 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1528715391 break;
15288
- case '0': envyoff ^= true; repaint(); break;
15392
+ //case '0': envyoff ^= true; repaint(); break;
1528915393 case '1':
1529015394 case '2':
1529115395 case '3':
1529215396 case '4':
1529315397 case '5':
15294
- newenvy = Character.getNumericValue(key);
15295
- repaint();
15296
- break;
1529715398 case '6':
1529815399 case '7':
1529915400 case '8':
1530015401 case '9':
15301
- BGcolor = (key - '6')/3.f;
15402
+ if (true) // envyoff)
15403
+ {
15404
+ BGcolor = (key - '1')/8.f;
15405
+ }
15406
+ else
15407
+ {
15408
+ //newenvy = Character.getNumericValue(key);
15409
+ }
1530215410 repaint();
1530315411 break;
1530415412 case '!':
....@@ -15861,8 +15969,6 @@
1586115969
1586215970 int width = getBounds().width;
1586315971 int height = getBounds().height;
15864
- ClickInfo info = new ClickInfo();
15865
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1586615972 //Image img = CreateImage(width, height);
1586715973 //System.out.println("width = " + width + "; height = " + height + "\n");
1586815974
....@@ -15939,31 +16045,37 @@
1593916045 }
1594016046 if (object != null && !hasMarquee)
1594116047 {
16048
+ if (object.clickInfo == null)
16049
+ object.clickInfo = new ClickInfo();
16050
+ ClickInfo info = object.clickInfo;
16051
+ //ClickInfo info = new ClickInfo();
16052
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16053
+
1594216054 if (isRenderer)
1594316055 {
15944
- info.flags++;
16056
+ object.clickInfo.flags++;
1594516057 double frameAspect = (double) width / (double) height;
1594616058 if (frameAspect > renderCamera.aspect)
1594716059 {
1594816060 int desired = (int) ((double) height * renderCamera.aspect);
15949
- info.bounds.width -= width - desired;
15950
- info.bounds.x += (width - desired) / 2;
16061
+ object.clickInfo.bounds.width -= width - desired;
16062
+ object.clickInfo.bounds.x += (width - desired) / 2;
1595116063 } else
1595216064 {
1595316065 int desired = (int) ((double) width / renderCamera.aspect);
15954
- info.bounds.height -= height - desired;
15955
- info.bounds.y += (height - desired) / 2;
16066
+ object.clickInfo.bounds.height -= height - desired;
16067
+ object.clickInfo.bounds.y += (height - desired) / 2;
1595616068 }
1595716069 }
1595816070
15959
- info.g = gr;
15960
- info.camera = renderCamera;
16071
+ object.clickInfo.g = gr;
16072
+ object.clickInfo.camera = renderCamera;
1596116073 /*
1596216074 // Memory intensive (brep.verticescopy)
1596316075 if (!(object instanceof Composite))
1596416076 object.draw(info, 0, false); // SLOW :
1596516077 */
15966
- if (!isRenderer)
16078
+ if (!isRenderer) // && drag)
1596716079 {
1596816080 Grafreed.Assert(object != null);
1596916081 Grafreed.Assert(object.selection != null);
....@@ -15971,9 +16083,9 @@
1597116083 {
1597216084 int hitSomething = object.selection.get(0).hitSomething;
1597316085
15974
- info.DX = 0;
15975
- info.DY = 0;
15976
- info.W = 1;
16086
+ object.clickInfo.DX = 0;
16087
+ object.clickInfo.DY = 0;
16088
+ object.clickInfo.W = 1;
1597716089 if (hitSomething == Object3D.hitCenter)
1597816090 {
1597916091 info.DX = X;
....@@ -15985,7 +16097,8 @@
1598516097 info.DY -= info.bounds.height/2;
1598616098 }
1598716099
15988
- object.drawEditHandles(info, 0);
16100
+ object.drawEditHandles(//info,
16101
+ 0);
1598916102
1599016103 if (drag && (X != 0 || Y != 0))
1599116104 {
....@@ -16484,6 +16597,8 @@
1648416597 private /*static*/ boolean firstime;
1648516598 private /*static*/ cVector newView = new cVector();
1648616599 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16600
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16601
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1648716602 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1648816603 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1648916604 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -16496,29 +16611,67 @@
1649616611 {
1649716612 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1649816613
16614
+ int usedsuf = 0;
16615
+
1649916616 for (int i = 0; i < suffixes.length; i++)
1650016617 {
16501
- String resourceName = basename + suffixes[i] + "." + suffix;
16502
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16503
- mipmapped,
16504
- FileUtil.getFileSuffix(resourceName));
16505
- if (data == null)
16618
+ String[] suffixe = suffixes;
16619
+ String[] fallback = suffixes2;
16620
+ String[] fallfallback = suffixes3;
16621
+
16622
+ for (int c=usedsuf; --c>=0;)
1650616623 {
16507
- throw new IOException("Unable to load texture " + resourceName);
16624
+// String[] temp = suffixe;
16625
+// suffixe = fallback;
16626
+// fallback = fallfallback;
16627
+// fallfallback = temp;
1650816628 }
16629
+
16630
+ String resourceName = basename + suffixe[i] + "." + suffix;
16631
+ TextureData data;
16632
+
16633
+ try
16634
+ {
16635
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16636
+ mipmapped,
16637
+ FileUtil.getFileSuffix(resourceName));
16638
+ }
16639
+ catch (Exception e)
16640
+ {
16641
+ try
16642
+ {
16643
+ resourceName = basename + fallback[i] + "." + suffix;
16644
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16645
+ mipmapped,
16646
+ FileUtil.getFileSuffix(resourceName));
16647
+ }
16648
+ catch (Exception e2)
16649
+ {
16650
+ resourceName = basename + fallfallback[i] + "." + suffix;
16651
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16652
+ mipmapped,
16653
+ FileUtil.getFileSuffix(resourceName));
16654
+ }
16655
+ }
16656
+
1650916657 //System.out.println("Target = " + targets[i]);
1651016658 cubemap.updateImage(data, targets[i]);
1651116659 }
1651216660
1651316661 return cubemap;
1651416662 }
16663
+
1651516664 int bigsphere = -1;
1651616665
1651716666 float BGcolor = 0.5f;
1651816667
16519
- private void DrawSkyBox(GL gl)
16668
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16669
+
16670
+ private void DrawSkyBox(GL gl, float ratio)
1652016671 {
16521
- if (envyoff || cubemap == null)
16672
+ if (//envyoff ||
16673
+ WIREFRAME ||
16674
+ cubemap == null)
1652216675 {
1652316676 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1652416677 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -16533,7 +16686,17 @@
1653316686 // Compensates for ExaminerViewer's modification of modelview matrix
1653416687 gl.glMatrixMode(GL.GL_MODELVIEW);
1653516688 gl.glLoadIdentity();
16689
+ gl.glScalef(1,ratio,1);
1653616690
16691
+// colorV[0] = 2;
16692
+// colorV[1] = 2;
16693
+// colorV[2] = 2;
16694
+// colorV[3] = 1;
16695
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16696
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16697
+//
16698
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16699
+
1653716700 //gl.glActiveTexture(GL.GL_TEXTURE1);
1653816701 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1653916702
....@@ -16565,6 +16728,7 @@
1656516728 {
1656616729 gl.glScalef(1.0f, -1.0f, 1.0f);
1656716730 }
16731
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1656816732 gl.glMultMatrixd(viewrot_1, 0);
1656916733 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1657016734 //viewer.updateInverseRotation(gl);
....@@ -16823,7 +16987,7 @@
1682316987 //new Exception().printStackTrace();
1682416988 System.out.println("select buffer init");
1682516989 // Use debug pipeline
16826
- drawable.setGL(new DebugGL(drawable.getGL()));
16990
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1682716991
1682816992 GL gl = drawable.getGL();
1682916993
....@@ -17369,10 +17533,14 @@
1736917533 gl.glFlush();
1737017534
1737117535 /**/
17372
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17536
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1737317537
17374
- float[] pixels = occlusionsizebuffer.array();
17538
+ float[] depths = occlusiondepthbuffer.array();
1737517539
17540
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17541
+
17542
+ int[] pixels = selectsizebuffer.array();
17543
+
1737617544 double r = 0, g = 0, b = 0;
1737717545
1737817546 double count = 0;
....@@ -17383,7 +17551,7 @@
1738317551
1738417552 double FACTOR = 1;
1738517553
17386
- for (int i = 0; i < pixels.length; i++)
17554
+ for (int i = 0; i < depths.length; i++)
1738717555 {
1738817556 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1738917557 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -17466,7 +17634,7 @@
1746617634
1746717635 double scale = ray.z; // 1; // cos
1746817636
17469
- float depth = pixels[newindex];
17637
+ float depth = depths[newindex];
1747017638
1747117639 /*
1747217640 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -17663,11 +17831,14 @@
1766317831 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1766417832 static IntBuffer bigAAbuffer;
1766517833 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
17666
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17834
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1766717835 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1766817836 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1766917837 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17670
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17838
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17839
+
17840
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17841
+
1767117842 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1767217843 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1767317844 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();