Normand Briere
2019-06-17 e36047725ce3217618d4e5807ac7c8769b9e3598
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 {
....@@ -7919,6 +7921,64 @@
79197921 ReleaseTexture(pigment, false);
79207922 }
79217923
7924
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
7925
+ {
7926
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
7927
+ {
7928
+ return;
7929
+ }
7930
+
7931
+ if (tex == null)
7932
+ {
7933
+ ReleaseTexture(null, false);
7934
+ return;
7935
+ }
7936
+
7937
+ String pigment = Object3D.GetPigment(tex);
7938
+
7939
+ if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
7940
+ {
7941
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
7942
+ // System.out.println("; bump = " + bump);
7943
+ }
7944
+
7945
+ if (pigment.equals(""))
7946
+ {
7947
+ pigment = null;
7948
+ }
7949
+
7950
+ ReleaseTexture(pigment, false);
7951
+ }
7952
+
7953
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
7954
+ {
7955
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
7956
+ {
7957
+ return;
7958
+ }
7959
+
7960
+ if (tex == null)
7961
+ {
7962
+ ReleaseTexture(null, true);
7963
+ return;
7964
+ }
7965
+
7966
+ String bump = Object3D.GetBump(tex);
7967
+
7968
+ if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
7969
+ {
7970
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
7971
+ // System.out.println("; bump = " + bump);
7972
+ }
7973
+
7974
+ if (bump.equals(""))
7975
+ {
7976
+ bump = null;
7977
+ }
7978
+
7979
+ ReleaseTexture(bump, true);
7980
+ }
7981
+
79227982 void ReleaseTexture(String tex, boolean bump)
79237983 {
79247984 if (// DrawMode() != 0 || /*tex == null ||*/
....@@ -8067,6 +8127,93 @@
80678127 return; // true;
80688128 }
80698129
8130
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8131
+ {
8132
+ if (// DrawMode() != 0 || /*tex == null ||*/
8133
+ ambientOcclusion ) // || !textureon)
8134
+ {
8135
+ return; // false;
8136
+ }
8137
+
8138
+ if (tex == null)
8139
+ {
8140
+ BindTexture(null,false,resolution);
8141
+ return;
8142
+ }
8143
+
8144
+ String pigment = Object3D.GetPigment(tex);
8145
+
8146
+ usedtextures.put(pigment, pigment);
8147
+
8148
+ if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8149
+ {
8150
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8151
+ // System.out.println("; bump = " + bump);
8152
+ }
8153
+
8154
+ if (pigment.equals(""))
8155
+ {
8156
+ pigment = null;
8157
+ }
8158
+
8159
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8160
+ BindTexture(pigment, false, resolution);
8161
+ }
8162
+
8163
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8164
+ {
8165
+ if (// DrawMode() != 0 || /*tex == null ||*/
8166
+ ambientOcclusion ) // || !textureon)
8167
+ {
8168
+ return; // false;
8169
+ }
8170
+
8171
+ if (tex == null)
8172
+ {
8173
+ BindTexture(null,true,resolution);
8174
+ return;
8175
+ }
8176
+
8177
+ String bump = Object3D.GetBump(tex);
8178
+
8179
+ usedtextures.put(bump, bump);
8180
+
8181
+ if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8182
+ {
8183
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8184
+ // System.out.println("; bump = " + bump);
8185
+ }
8186
+
8187
+ if (bump.equals(""))
8188
+ {
8189
+ bump = null;
8190
+ }
8191
+
8192
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8193
+ BindTexture(bump, true, resolution);
8194
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8195
+ }
8196
+
8197
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8198
+
8199
+ private boolean FileExists(String tex)
8200
+ {
8201
+ if (missingTextures.contains(tex))
8202
+ {
8203
+ return false;
8204
+ }
8205
+
8206
+ boolean fileExists = new File(tex).exists();
8207
+
8208
+ if (!fileExists)
8209
+ {
8210
+ // If file exists, the "new File()" is not executed sgain
8211
+ missingTextures.add(tex);
8212
+ }
8213
+
8214
+ return fileExists;
8215
+ }
8216
+
80708217 CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
80718218 {
80728219 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
....@@ -8075,15 +8222,17 @@
80758222 {
80768223 String texname = tex;
80778224
8225
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8226
+
80788227 // String[] split = tex.split("Textures");
80798228 // if (split.length > 1)
80808229 // texname = "/Users/nbriere/Textures" + split[split.length-1];
80818230 // else
80828231 // if (!texname.startsWith("/"))
80838232 // texname = "/Users/nbriere/Textures/" + texname;
8084
- if (!new File(tex).exists())
8233
+ if (!FileExists(tex))
80858234 {
8086
- texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname;
8235
+ texname = fallbackTextureName;
80878236 }
80888237
80898238 if (CACHETEXTURE)
....@@ -8153,7 +8302,7 @@
81538302 }
81548303
81558304 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8156
- if (!new File(cachename).exists())
8305
+ if (!FileExists(cachename))
81578306 cachename = texname;
81588307 else
81598308 processbump = false; // don't process bump map again
....@@ -8175,7 +8324,7 @@
81758324 }
81768325
81778326 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8178
- if (!new File(cachename).exists())
8327
+ if (!FileExists(cachename))
81798328 cachename = texname;
81808329 else
81818330 processbump = false; // don't process bump map again
....@@ -9310,8 +9459,8 @@
93109459 assert (parentcam != renderCamera);
93119460
93129461 if (renderCamera != lightCamera)
9313
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9314
- LA.matConcat(matrix, parentcam.toParent, matrix);
9462
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9463
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
93159464
93169465 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93179466
....@@ -9326,8 +9475,8 @@
93269475 LA.matCopy(renderCamera.fromScreen, matrix);
93279476
93289477 if (renderCamera != lightCamera)
9329
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9330
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9478
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9479
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
93319480
93329481 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93339482
....@@ -10392,13 +10541,13 @@
1039210541 ambientOcclusion = false;
1039310542 }
1039410543
10395
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10544
+ if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039610545 {
1039710546 //if (RENDERSHADOW) // ?
1039810547 if (!IsFrozen())
1039910548 {
1040010549 // dec 2012
10401
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10550
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1040210551 {
1040310552 Globals.framecount++;
1040410553 shadowbuffer.display();
....@@ -10525,8 +10674,8 @@
1052510674
1052610675 // if (parentcam != renderCamera) // not a light
1052710676 if (cam != lightCamera)
10528
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10529
- LA.matConcat(matrix, parentcam.toParent, matrix);
10677
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10678
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1053010679
1053110680 for (int j = 0; j < 4; j++)
1053210681 {
....@@ -10540,8 +10689,8 @@
1054010689
1054110690 // if (parentcam != renderCamera) // not a light
1054210691 if (cam != lightCamera)
10543
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10544
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10692
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10693
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1054510694
1054610695 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054710696
....@@ -10934,8 +11083,8 @@
1093411083 System.err.println("parentcam != renderCamera");
1093511084
1093611085 // if (cam != lightCamera)
10937
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10938
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11086
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11087
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1093911088 }
1094011089
1094111090 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10956,8 +11105,8 @@
1095611105 if (true) // TODO
1095711106 {
1095811107 if (cam != lightCamera)
10959
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10960
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11108
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11109
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1096111110 }
1096211111
1096311112 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11552,7 +11701,7 @@
1155211701 return;
1155311702 }
1155411703
11555
- String string = obj.GetToolTip();
11704
+ String string = obj.toString(); //.GetToolTip();
1155611705
1155711706 GL gl = GetGL();
1155811707
....@@ -11869,8 +12018,8 @@
1186912018 //obj.TransformToWorld(light, light);
1187012019 for (int i = tp.size(); --i >= 0;)
1187112020 {
11872
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11873
- LA.xformPos(light, tp.get(i).toParent, light);
12021
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12022
+ LA.xformPos(light, tp.get(i).GlobalTransform(), light);
1187412023 }
1187512024
1187612025
....@@ -11887,8 +12036,8 @@
1188712036 parentcam = cameras[0];
1188812037 }
1188912038
11890
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11891
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12039
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12040
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1189212041
1189312042 LA.xformPos(light, renderCamera.toScreen, light);
1189412043
....@@ -13809,9 +13958,12 @@
1380913958
1381013959 public void mouseDragged(MouseEvent e)
1381113960 {
13961
+ Globals.MOUSEDRAGGED = true;
13962
+
1381213963 //System.out.println("mouseDragged: " + e);
1381313964 if (isRenderer)
1381413965 movingcamera = true;
13966
+
1381513967 //if (drawing)
1381613968 //return;
1381713969 if ((e.getModifiersEx() & CTRL) != 0
....@@ -14373,6 +14525,8 @@
1437314525
1437414526 public void mouseReleased(MouseEvent e)
1437514527 {
14528
+ Globals.MOUSEDRAGGED = false;
14529
+
1437614530 movingcamera = false;
1437714531 X = Y = 0;
1437814532 //System.out.println("mouseReleased: " + e);
....@@ -15488,12 +15642,17 @@
1548815642 {
1548915643 switch (object.selection.get(0).hitSomething)
1549015644 {
15491
- case Object3D.hitCenter: gr.setColor(Color.pink); break;
15492
- case Object3D.hitRotate: gr.setColor(Color.green); break;
15493
- case Object3D.hitScale: gr.setColor(Color.cyan); break;
15645
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15646
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15647
+ break;
15648
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15649
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15650
+ break;
15651
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15652
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15653
+ break;
1549415654 }
1549515655
15496
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1549715656 }
1549815657 }
1549915658 }
....@@ -15911,7 +16070,7 @@
1591116070 Object3D object;
1591216071 static Object3D trackedobject;
1591316072 Camera renderCamera; // Light or Eye (or Occlusion)
15914
- /*static*/ Camera manipCamera; // Light or Eye
16073
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1591516074 /*static*/ Camera eyeCamera;
1591616075 /*static*/ Camera lightCamera;
1591716076 int cameracount;