Normand Briere
2019-06-17 26b49d8e26625491f4a407a05e9bc9d72037f938
CameraPane.java
....@@ -150,6 +150,8 @@
150150 defaultcaps.setAccumAlphaBits(16);
151151 }
152152
153
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
154
+
153155 void SetAsGLRenderer(boolean b)
154156 {
155157 isRenderer = b;
....@@ -462,7 +464,7 @@
462464 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
463465 {
464466 //gl.glBegin(gl.GL_TRIANGLES);
465
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
467
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
466468 if (!hasnorm)
467469 {
468470 // System.out.println("FUCK!!");
....@@ -1888,7 +1890,7 @@
18881890 void PushMatrix(double[][] matrix)
18891891 {
18901892 // GrafreeD.tracein(matrix);
1891
- PushMatrix(matrix,1);
1893
+ PushMatrix(matrix, 1);
18921894 }
18931895
18941896 void PushMatrix()
....@@ -2265,7 +2267,7 @@
22652267 LOOKAT ^= true;
22662268 }
22672269
2268
- void ToggleRandom()
2270
+ void ToggleSwitch()
22692271 {
22702272 SWITCH ^= true;
22712273 }
....@@ -2374,7 +2376,7 @@
23742376 {
23752377 return currentGL;
23762378 }
2377
-
2379
+
23782380 /**/
23792381 class CacheTexture
23802382 {
....@@ -8022,7 +8024,7 @@
80228024 }
80238025 }
80248026
8025
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8027
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
80268028 {
80278029 if (// DrawMode() != 0 || /*tex == null ||*/
80288030 ambientOcclusion ) // || !textureon)
....@@ -8067,7 +8069,27 @@
80678069 return; // true;
80688070 }
80698071
8070
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8072
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8073
+
8074
+ private boolean FileExists(String tex)
8075
+ {
8076
+ if (missingTextures.contains(tex))
8077
+ {
8078
+ return false;
8079
+ }
8080
+
8081
+ boolean fileExists = new File(tex).exists();
8082
+
8083
+ if (!fileExists)
8084
+ {
8085
+ // If file exists, the "new File()" is not executed sgain
8086
+ missingTextures.add(tex);
8087
+ }
8088
+
8089
+ return fileExists;
8090
+ }
8091
+
8092
+ CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
80718093 {
80728094 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
80738095
....@@ -8075,15 +8097,17 @@
80758097 {
80768098 String texname = tex;
80778099
8100
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8101
+
80788102 // String[] split = tex.split("Textures");
80798103 // if (split.length > 1)
80808104 // texname = "/Users/nbriere/Textures" + split[split.length-1];
80818105 // else
80828106 // if (!texname.startsWith("/"))
80838107 // texname = "/Users/nbriere/Textures/" + texname;
8084
- if (!new File(tex).exists())
8108
+ if (!FileExists(tex))
80858109 {
8086
- texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname;
8110
+ texname = fallbackTextureName;
80878111 }
80888112
80898113 if (CACHETEXTURE)
....@@ -8153,7 +8177,7 @@
81538177 }
81548178
81558179 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8156
- if (!new File(cachename).exists())
8180
+ if (!FileExists(cachename))
81578181 cachename = texname;
81588182 else
81598183 processbump = false; // don't process bump map again
....@@ -8175,7 +8199,7 @@
81758199 }
81768200
81778201 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8178
- if (!new File(cachename).exists())
8202
+ if (!FileExists(cachename))
81798203 cachename = texname;
81808204 else
81818205 processbump = false; // don't process bump map again
....@@ -8184,7 +8208,9 @@
81848208 texturedata = GetFileTexture(cachename, processbump, resolution);
81858209
81868210
8187
- if (texturedata != null)
8211
+ if (texturedata == null)
8212
+ throw new Exception();
8213
+
81888214 texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
81898215 //texture = GetTexture(tex, bump);
81908216 }
....@@ -8306,7 +8332,7 @@
83068332 return texture;
83078333 }
83088334
8309
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8335
+ com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
83108336 {
83118337 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83128338
....@@ -8324,14 +8350,14 @@
83248350 return texture!=null?texture.texture:null;
83258351 }
83268352
8327
- public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8353
+ public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
83288354 {
83298355 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
83308356
83318357 return texture!=null?texture.texturedata:null;
83328358 }
83338359
8334
- boolean BindTexture(String tex, boolean bump, int resolution)
8360
+ boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
83358361 {
83368362 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
83378363 {
....@@ -9308,8 +9334,8 @@
93089334 assert (parentcam != renderCamera);
93099335
93109336 if (renderCamera != lightCamera)
9311
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9312
- LA.matConcat(matrix, parentcam.toParent, matrix);
9337
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9338
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
93139339
93149340 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93159341
....@@ -9324,8 +9350,8 @@
93249350 LA.matCopy(renderCamera.fromScreen, matrix);
93259351
93269352 if (renderCamera != lightCamera)
9327
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9328
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9353
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9354
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
93299355
93309356 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93319357
....@@ -10390,13 +10416,13 @@
1039010416 ambientOcclusion = false;
1039110417 }
1039210418
10393
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10419
+ if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039410420 {
1039510421 //if (RENDERSHADOW) // ?
1039610422 if (!IsFrozen())
1039710423 {
1039810424 // dec 2012
10399
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10425
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1040010426 {
1040110427 Globals.framecount++;
1040210428 shadowbuffer.display();
....@@ -10523,8 +10549,8 @@
1052310549
1052410550 // if (parentcam != renderCamera) // not a light
1052510551 if (cam != lightCamera)
10526
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10527
- LA.matConcat(matrix, parentcam.toParent, matrix);
10552
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10553
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1052810554
1052910555 for (int j = 0; j < 4; j++)
1053010556 {
....@@ -10538,8 +10564,8 @@
1053810564
1053910565 // if (parentcam != renderCamera) // not a light
1054010566 if (cam != lightCamera)
10541
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10542
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10567
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10568
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1054310569
1054410570 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054510571
....@@ -10798,7 +10824,16 @@
1079810824 // Bump noise
1079910825 gl.glActiveTexture(GL.GL_TEXTURE6);
1080010826 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10801
- BindTexture(NOISE_TEXTURE, false, 2);
10827
+
10828
+ try
10829
+ {
10830
+ BindTexture(NOISE_TEXTURE, false, 2);
10831
+ }
10832
+ catch (Exception e)
10833
+ {
10834
+ System.err.println("FAILED: " + NOISE_TEXTURE);
10835
+ }
10836
+
1080210837
1080310838 gl.glActiveTexture(GL.GL_TEXTURE0);
1080410839 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10923,8 +10958,8 @@
1092310958 System.err.println("parentcam != renderCamera");
1092410959
1092510960 // if (cam != lightCamera)
10926
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10927
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
10961
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10962
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1092810963 }
1092910964
1093010965 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10945,8 +10980,8 @@
1094510980 if (true) // TODO
1094610981 {
1094710982 if (cam != lightCamera)
10948
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10949
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
10983
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10984
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1095010985 }
1095110986
1095210987 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11354,7 +11389,14 @@
1135411389
1135511390 usedtextures.clear();
1135611391
11357
- BindTextures(DEFAULT_TEXTURES, 2);
11392
+ try
11393
+ {
11394
+ BindTextures(DEFAULT_TEXTURES, 2);
11395
+ }
11396
+ catch (Exception e)
11397
+ {
11398
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11399
+ }
1135811400 }
1135911401 //System.out.println("--> " + stackdepth);
1136011402 // GrafreeD.traceon();
....@@ -11445,7 +11487,14 @@
1144511487 if (checker != null && DrawMode() == DEFAULT)
1144611488 {
1144711489 //BindTexture(IMMORTAL_TEXTURE);
11448
- BindTextures(checker.GetTextures(), checker.texres);
11490
+ try
11491
+ {
11492
+ BindTextures(checker.GetTextures(), checker.texres);
11493
+ }
11494
+ catch (Exception e)
11495
+ {
11496
+ System.err.println("FAILED: " + checker.GetTextures());
11497
+ }
1144911498 // NEAREST
1145011499 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1145111500 DrawChecker(gl);
....@@ -11527,7 +11576,7 @@
1152711576 return;
1152811577 }
1152911578
11530
- String string = obj.GetToolTip();
11579
+ String string = obj.toString(); //.GetToolTip();
1153111580
1153211581 GL gl = GetGL();
1153311582
....@@ -11844,8 +11893,8 @@
1184411893 //obj.TransformToWorld(light, light);
1184511894 for (int i = tp.size(); --i >= 0;)
1184611895 {
11847
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11848
- LA.xformPos(light, tp.get(i).toParent, light);
11896
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11897
+ LA.xformPos(light, tp.get(i).GlobalTransform(), light);
1184911898 }
1185011899
1185111900
....@@ -11862,8 +11911,8 @@
1186211911 parentcam = cameras[0];
1186311912 }
1186411913
11865
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11866
- LA.xformPos(light, parentcam.toParent, light); // may 2013
11914
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11915
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1186711916
1186811917 LA.xformPos(light, renderCamera.toScreen, light);
1186911918
....@@ -12477,8 +12526,8 @@
1247712526
1247812527 // display shadow only (bump == 0)
1247912528 "SUB temp.x, half.x, shadow.x;" +
12480
- "MOV temp.y, -params6.x;" +
12481
- "SLT temp.z, temp.y, zero.x;" +
12529
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12530
+ "SLT temp.z, temp.y, -one2048th.x;" +
1248212531 "SUB temp.y, one.x, temp.z;" +
1248312532 "MUL temp.x, temp.x, temp.y;" +
1248412533 "KIL temp.x;" +
....@@ -12809,7 +12858,7 @@
1280912858 //once = true;
1281012859 }
1281112860
12812
- System.out.print("Program #" + mode + "; length = " + program.length());
12861
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1281312862 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1281412863 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1281512864
....@@ -12942,12 +12991,16 @@
1294212991
1294312992 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1294412993 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
12994
+
12995
+ // Compare fragment depth in light space with shadowmap.
1294512996 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1294612997 "SGE temp.y, temp.x, zero.x;" +
12947
- "SUB " + shadow + ".y, one.x, temp.y;" +
12998
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
12999
+
13000
+ // Reverse comparison
1294813001 "SUB temp.x, one.x, temp.x;" +
1294913002 "MUL " + shadow + ".x, temp.x, temp.y;" +
12950
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13003
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1295113004 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1295213005
1295313006 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12961,6 +13014,10 @@
1296113014 // No shadow for backface
1296213015 "DP3 temp.x, normal, lightd;" +
1296313016 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13017
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13018
+
13019
+ // No shadow when out of frustrum
13020
+ "SGE temp.x, " + depth + ".z, one.z;" +
1296413021 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1296513022 "";
1296613023 }
....@@ -13776,9 +13833,12 @@
1377613833
1377713834 public void mouseDragged(MouseEvent e)
1377813835 {
13836
+ Globals.MOUSEDRAGGED = true;
13837
+
1377913838 //System.out.println("mouseDragged: " + e);
1378013839 if (isRenderer)
1378113840 movingcamera = true;
13841
+
1378213842 //if (drawing)
1378313843 //return;
1378413844 if ((e.getModifiersEx() & CTRL) != 0
....@@ -14340,7 +14400,10 @@
1434014400
1434114401 public void mouseReleased(MouseEvent e)
1434214402 {
14403
+ Globals.MOUSEDRAGGED = false;
14404
+
1434314405 movingcamera = false;
14406
+ X = Y = 0;
1434414407 //System.out.println("mouseReleased: " + e);
1434514408 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1434614409 }
....@@ -14870,7 +14933,7 @@
1487014933 //RESIZETEXTURE ^= true;
1487114934 //break;
1487214935 case 'z':
14873
- RENDERSHADOW ^= true;
14936
+ Globals.RENDERSHADOW ^= true;
1487414937 Globals.lighttouched = true;
1487514938 repaint();
1487614939 break;
....@@ -15349,7 +15412,9 @@
1534915412 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1535015413 //Image img = CreateImage(width, height);
1535115414 //System.out.println("width = " + width + "; height = " + height + "\n");
15415
+
1535215416 Graphics gr = g; // img.getGraphics();
15417
+
1535315418 if (!hasMarquee)
1535415419 {
1535515420 if (Xmin < Xmax) // !locked)
....@@ -15447,14 +15512,33 @@
1544715512 if (!isRenderer)
1544815513 {
1544915514 object.drawEditHandles(info, 0);
15515
+
15516
+ if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
15517
+ {
15518
+ switch (object.selection.get(0).hitSomething)
15519
+ {
15520
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15521
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15522
+ break;
15523
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15524
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15525
+ break;
15526
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15527
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15528
+ break;
15529
+ }
15530
+
15531
+ }
1545015532 }
1545115533 }
15534
+
1545215535 if (isRenderer)
1545315536 {
1545415537 //gr.setColor(Color.black);
1545515538 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1545615539 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1545715540 }
15541
+
1545815542 if (hasMarquee)
1545915543 {
1546015544 gr.setXORMode(Color.white);
....@@ -15861,7 +15945,7 @@
1586115945 Object3D object;
1586215946 static Object3D trackedobject;
1586315947 Camera renderCamera; // Light or Eye (or Occlusion)
15864
- /*static*/ Camera manipCamera; // Light or Eye
15948
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1586515949 /*static*/ Camera eyeCamera;
1586615950 /*static*/ Camera lightCamera;
1586715951 int cameracount;
....@@ -16592,7 +16676,7 @@
1659216676 gl.glDisable(gl.GL_CULL_FACE);
1659316677 }
1659416678
16595
- if (!RENDERSHADOW)
16679
+ if (!Globals.RENDERSHADOW)
1659616680 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1659716681
1659816682 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -16602,7 +16686,7 @@
1660216686 //gl.glColorMask(false, false, false, false);
1660316687
1660416688 //render_scene_from_light_view(gl, drawable, 0, 0);
16605
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
16689
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1660616690 {
1660716691 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1660816692