Normand Briere
2019-06-21 15123b19e7bc8da2869429b07f0fbaa0598e945e
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,10 +464,12 @@
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)
468
+ // TEST LIVE NORMALS && !obj.dontselect
469
+ ;
466470 if (!hasnorm)
467471 {
468
- // System.out.println("FUCK!!");
472
+ // System.out.println("Mesh normal");
469473 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
470474 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
471475 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1190,10 +1194,12 @@
11901194 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11911195 }
11921196 }
1197
+
11931198 if (flipV)
11941199 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11951200 else
11961201 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1202
+
11971203 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11981204 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11991205
....@@ -1213,10 +1219,12 @@
12131219 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12141220 }
12151221 }
1222
+
12161223 if (flipV)
12171224 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12181225 else
12191226 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1227
+
12201228 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12211229 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12221230
....@@ -1244,8 +1252,10 @@
12441252 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12451253 else
12461254 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1255
+
12471256 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12481257 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1258
+
12491259 count2 += 2;
12501260 count3 += 3;
12511261 }
....@@ -1888,7 +1898,7 @@
18881898 void PushMatrix(double[][] matrix)
18891899 {
18901900 // GrafreeD.tracein(matrix);
1891
- PushMatrix(matrix,1);
1901
+ PushMatrix(matrix, 1);
18921902 }
18931903
18941904 void PushMatrix()
....@@ -2265,7 +2275,7 @@
22652275 LOOKAT ^= true;
22662276 }
22672277
2268
- void ToggleRandom()
2278
+ void ToggleSwitch()
22692279 {
22702280 SWITCH ^= true;
22712281 }
....@@ -2374,7 +2384,7 @@
23742384 {
23752385 return currentGL;
23762386 }
2377
-
2387
+
23782388 /**/
23792389 class CacheTexture
23802390 {
....@@ -7919,6 +7929,64 @@
79197929 ReleaseTexture(pigment, false);
79207930 }
79217931
7932
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
7933
+ {
7934
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
7935
+ {
7936
+ return;
7937
+ }
7938
+
7939
+ if (tex == null)
7940
+ {
7941
+ ReleaseTexture(null, false);
7942
+ return;
7943
+ }
7944
+
7945
+ String pigment = Object3D.GetPigment(tex);
7946
+
7947
+ if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
7948
+ {
7949
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
7950
+ // System.out.println("; bump = " + bump);
7951
+ }
7952
+
7953
+ if (pigment.equals(""))
7954
+ {
7955
+ pigment = null;
7956
+ }
7957
+
7958
+ ReleaseTexture(pigment, false);
7959
+ }
7960
+
7961
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
7962
+ {
7963
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
7964
+ {
7965
+ return;
7966
+ }
7967
+
7968
+ if (tex == null)
7969
+ {
7970
+ ReleaseTexture(null, true);
7971
+ return;
7972
+ }
7973
+
7974
+ String bump = Object3D.GetBump(tex);
7975
+
7976
+ if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
7977
+ {
7978
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
7979
+ // System.out.println("; bump = " + bump);
7980
+ }
7981
+
7982
+ if (bump.equals(""))
7983
+ {
7984
+ bump = null;
7985
+ }
7986
+
7987
+ ReleaseTexture(bump, true);
7988
+ }
7989
+
79227990 void ReleaseTexture(String tex, boolean bump)
79237991 {
79247992 if (// DrawMode() != 0 || /*tex == null ||*/
....@@ -8067,6 +8135,93 @@
80678135 return; // true;
80688136 }
80698137
8138
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8139
+ {
8140
+ if (// DrawMode() != 0 || /*tex == null ||*/
8141
+ ambientOcclusion ) // || !textureon)
8142
+ {
8143
+ return; // false;
8144
+ }
8145
+
8146
+ if (tex == null)
8147
+ {
8148
+ BindTexture(null,false,resolution);
8149
+ return;
8150
+ }
8151
+
8152
+ String pigment = Object3D.GetPigment(tex);
8153
+
8154
+ usedtextures.put(pigment, pigment);
8155
+
8156
+ if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8157
+ {
8158
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8159
+ // System.out.println("; bump = " + bump);
8160
+ }
8161
+
8162
+ if (pigment.equals(""))
8163
+ {
8164
+ pigment = null;
8165
+ }
8166
+
8167
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8168
+ BindTexture(pigment, false, resolution);
8169
+ }
8170
+
8171
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8172
+ {
8173
+ if (// DrawMode() != 0 || /*tex == null ||*/
8174
+ ambientOcclusion ) // || !textureon)
8175
+ {
8176
+ return; // false;
8177
+ }
8178
+
8179
+ if (tex == null)
8180
+ {
8181
+ BindTexture(null,true,resolution);
8182
+ return;
8183
+ }
8184
+
8185
+ String bump = Object3D.GetBump(tex);
8186
+
8187
+ usedtextures.put(bump, bump);
8188
+
8189
+ if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8190
+ {
8191
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8192
+ // System.out.println("; bump = " + bump);
8193
+ }
8194
+
8195
+ if (bump.equals(""))
8196
+ {
8197
+ bump = null;
8198
+ }
8199
+
8200
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8201
+ BindTexture(bump, true, resolution);
8202
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8203
+ }
8204
+
8205
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8206
+
8207
+ private boolean FileExists(String tex)
8208
+ {
8209
+ if (missingTextures.contains(tex))
8210
+ {
8211
+ return false;
8212
+ }
8213
+
8214
+ boolean fileExists = new File(tex).exists();
8215
+
8216
+ if (!fileExists)
8217
+ {
8218
+ // If file exists, the "new File()" is not executed sgain
8219
+ missingTextures.add(tex);
8220
+ }
8221
+
8222
+ return fileExists;
8223
+ }
8224
+
80708225 CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
80718226 {
80728227 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
....@@ -8075,15 +8230,17 @@
80758230 {
80768231 String texname = tex;
80778232
8233
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8234
+
80788235 // String[] split = tex.split("Textures");
80798236 // if (split.length > 1)
80808237 // texname = "/Users/nbriere/Textures" + split[split.length-1];
80818238 // else
80828239 // if (!texname.startsWith("/"))
80838240 // texname = "/Users/nbriere/Textures/" + texname;
8084
- if (!new File(tex).exists())
8241
+ if (!FileExists(tex))
80858242 {
8086
- texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname;
8243
+ texname = fallbackTextureName;
80878244 }
80888245
80898246 if (CACHETEXTURE)
....@@ -8153,7 +8310,7 @@
81538310 }
81548311
81558312 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8156
- if (!new File(cachename).exists())
8313
+ if (!FileExists(cachename))
81578314 cachename = texname;
81588315 else
81598316 processbump = false; // don't process bump map again
....@@ -8175,7 +8332,7 @@
81758332 }
81768333
81778334 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8178
- if (!new File(cachename).exists())
8335
+ if (!FileExists(cachename))
81798336 cachename = texname;
81808337 else
81818338 processbump = false; // don't process bump map again
....@@ -9310,8 +9467,8 @@
93109467 assert (parentcam != renderCamera);
93119468
93129469 if (renderCamera != lightCamera)
9313
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9314
- LA.matConcat(matrix, parentcam.toParent, matrix);
9470
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9471
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
93159472
93169473 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93179474
....@@ -9326,8 +9483,8 @@
93269483 LA.matCopy(renderCamera.fromScreen, matrix);
93279484
93289485 if (renderCamera != lightCamera)
9329
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9330
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9486
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9487
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
93319488
93329489 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93339490
....@@ -10392,13 +10549,13 @@
1039210549 ambientOcclusion = false;
1039310550 }
1039410551
10395
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10552
+ if (Globals.lighttouched && DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
1039610553 {
1039710554 //if (RENDERSHADOW) // ?
1039810555 if (!IsFrozen())
1039910556 {
1040010557 // dec 2012
10401
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10558
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
1040210559 {
1040310560 Globals.framecount++;
1040410561 shadowbuffer.display();
....@@ -10525,8 +10682,8 @@
1052510682
1052610683 // if (parentcam != renderCamera) // not a light
1052710684 if (cam != lightCamera)
10528
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10529
- LA.matConcat(matrix, parentcam.toParent, matrix);
10685
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10686
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1053010687
1053110688 for (int j = 0; j < 4; j++)
1053210689 {
....@@ -10540,8 +10697,8 @@
1054010697
1054110698 // if (parentcam != renderCamera) // not a light
1054210699 if (cam != lightCamera)
10543
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10544
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10700
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10701
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1054510702
1054610703 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054710704
....@@ -10934,8 +11091,8 @@
1093411091 System.err.println("parentcam != renderCamera");
1093511092
1093611093 // if (cam != lightCamera)
10937
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10938
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11094
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11095
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1093911096 }
1094011097
1094111098 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10956,8 +11113,8 @@
1095611113 if (true) // TODO
1095711114 {
1095811115 if (cam != lightCamera)
10959
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10960
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11116
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11117
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1096111118 }
1096211119
1096311120 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11552,7 +11709,7 @@
1155211709 return;
1155311710 }
1155411711
11555
- String string = obj.GetToolTip();
11712
+ String string = obj.toString(); //.GetToolTip();
1155611713
1155711714 GL gl = GetGL();
1155811715
....@@ -11869,8 +12026,8 @@
1186912026 //obj.TransformToWorld(light, light);
1187012027 for (int i = tp.size(); --i >= 0;)
1187112028 {
11872
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11873
- LA.xformPos(light, tp.get(i).toParent, light);
12029
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12030
+ LA.xformPos(light, tp.get(i).GlobalTransform(), light);
1187412031 }
1187512032
1187612033
....@@ -11887,8 +12044,8 @@
1188712044 parentcam = cameras[0];
1188812045 }
1188912046
11890
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11891
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12047
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12048
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1189212049
1189312050 LA.xformPos(light, renderCamera.toScreen, light);
1189412051
....@@ -13809,9 +13966,12 @@
1380913966
1381013967 public void mouseDragged(MouseEvent e)
1381113968 {
13969
+ Globals.MOUSEDRAGGED = true;
13970
+
1381213971 //System.out.println("mouseDragged: " + e);
1381313972 if (isRenderer)
1381413973 movingcamera = true;
13974
+
1381513975 //if (drawing)
1381613976 //return;
1381713977 if ((e.getModifiersEx() & CTRL) != 0
....@@ -14373,7 +14533,10 @@
1437314533
1437414534 public void mouseReleased(MouseEvent e)
1437514535 {
14536
+ Globals.MOUSEDRAGGED = false;
14537
+
1437614538 movingcamera = false;
14539
+ X = Y = 0;
1437714540 //System.out.println("mouseReleased: " + e);
1437814541 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1437914542 }
....@@ -15382,7 +15545,9 @@
1538215545 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1538315546 //Image img = CreateImage(width, height);
1538415547 //System.out.println("width = " + width + "; height = " + height + "\n");
15548
+
1538515549 Graphics gr = g; // img.getGraphics();
15550
+
1538615551 if (!hasMarquee)
1538715552 {
1538815553 if (Xmin < Xmax) // !locked)
....@@ -15480,14 +15645,33 @@
1548015645 if (!isRenderer)
1548115646 {
1548215647 object.drawEditHandles(info, 0);
15648
+
15649
+ if (drag && (X != 0 || Y != 0) && object.selection.Size() > 0)
15650
+ {
15651
+ switch (object.selection.get(0).hitSomething)
15652
+ {
15653
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15654
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15655
+ break;
15656
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15657
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15658
+ break;
15659
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15660
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15661
+ break;
15662
+ }
15663
+
15664
+ }
1548315665 }
1548415666 }
15667
+
1548515668 if (isRenderer)
1548615669 {
1548715670 //gr.setColor(Color.black);
1548815671 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1548915672 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1549015673 }
15674
+
1549115675 if (hasMarquee)
1549215676 {
1549315677 gr.setXORMode(Color.white);
....@@ -15894,7 +16078,7 @@
1589416078 Object3D object;
1589516079 static Object3D trackedobject;
1589616080 Camera renderCamera; // Light or Eye (or Occlusion)
15897
- /*static*/ Camera manipCamera; // Light or Eye
16081
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1589816082 /*static*/ Camera eyeCamera;
1589916083 /*static*/ Camera lightCamera;
1590016084 int cameracount;