Normand Briere
2019-06-23 8088590686a45e71278f9a52bb9cc37943dc0c37
CameraPane.java
....@@ -37,7 +37,6 @@
3737 static boolean[] selectedstack = new boolean[65536];
3838 static int materialdepth = 0;
3939
40
- static boolean DEBUG = false;
4140 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4241
4342 // camera change fix
....@@ -149,6 +148,8 @@
149148 defaultcaps.setAccumBlueBits(16);
150149 defaultcaps.setAccumAlphaBits(16);
151150 }
151
+
152
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
152153
153154 void SetAsGLRenderer(boolean b)
154155 {
....@@ -462,10 +463,12 @@
462463 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
463464 {
464465 //gl.glBegin(gl.GL_TRIANGLES);
465
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
466
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
467
+ // TEST LIVE NORMALS && !obj.dontselect
468
+ ;
466469 if (!hasnorm)
467470 {
468
- // System.out.println("FUCK!!");
471
+ // System.out.println("Mesh normal");
469472 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
470473 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
471474 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -1190,10 +1193,12 @@
11901193 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
11911194 }
11921195 }
1196
+
11931197 if (flipV)
11941198 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
11951199 else
11961200 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1201
+
11971202 //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
11981203 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
11991204
....@@ -1213,10 +1218,12 @@
12131218 gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
12141219 }
12151220 }
1221
+
12161222 if (flipV)
12171223 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12181224 else
12191225 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1226
+
12201227 //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
12211228 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
12221229
....@@ -1244,8 +1251,10 @@
12441251 gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
12451252 else
12461253 gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1254
+
12471255 //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
12481256 gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1257
+
12491258 count2 += 2;
12501259 count3 += 3;
12511260 }
....@@ -1888,7 +1897,7 @@
18881897 void PushMatrix(double[][] matrix)
18891898 {
18901899 // GrafreeD.tracein(matrix);
1891
- PushMatrix(matrix,1);
1900
+ PushMatrix(matrix, 1);
18921901 }
18931902
18941903 void PushMatrix()
....@@ -2257,7 +2266,7 @@
22572266
22582267 void ToggleDebug()
22592268 {
2260
- DEBUG ^= true;
2269
+ Globals.DEBUG ^= true;
22612270 }
22622271
22632272 void ToggleLookAt()
....@@ -2265,7 +2274,7 @@
22652274 LOOKAT ^= true;
22662275 }
22672276
2268
- void ToggleRandom()
2277
+ void ToggleSwitch()
22692278 {
22702279 SWITCH ^= true;
22712280 }
....@@ -2374,7 +2383,7 @@
23742383 {
23752384 return currentGL;
23762385 }
2377
-
2386
+
23782387 /**/
23792388 class CacheTexture
23802389 {
....@@ -7919,6 +7928,64 @@
79197928 ReleaseTexture(pigment, false);
79207929 }
79217930
7931
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
7932
+ {
7933
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
7934
+ {
7935
+ return;
7936
+ }
7937
+
7938
+ if (tex == null)
7939
+ {
7940
+ ReleaseTexture(null, false);
7941
+ return;
7942
+ }
7943
+
7944
+ String pigment = Object3D.GetPigment(tex);
7945
+
7946
+ if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
7947
+ {
7948
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
7949
+ // System.out.println("; bump = " + bump);
7950
+ }
7951
+
7952
+ if (pigment.equals(""))
7953
+ {
7954
+ pigment = null;
7955
+ }
7956
+
7957
+ ReleaseTexture(pigment, false);
7958
+ }
7959
+
7960
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
7961
+ {
7962
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
7963
+ {
7964
+ return;
7965
+ }
7966
+
7967
+ if (tex == null)
7968
+ {
7969
+ ReleaseTexture(null, true);
7970
+ return;
7971
+ }
7972
+
7973
+ String bump = Object3D.GetBump(tex);
7974
+
7975
+ if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
7976
+ {
7977
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
7978
+ // System.out.println("; bump = " + bump);
7979
+ }
7980
+
7981
+ if (bump.equals(""))
7982
+ {
7983
+ bump = null;
7984
+ }
7985
+
7986
+ ReleaseTexture(bump, true);
7987
+ }
7988
+
79227989 void ReleaseTexture(String tex, boolean bump)
79237990 {
79247991 if (// DrawMode() != 0 || /*tex == null ||*/
....@@ -8067,6 +8134,93 @@
80678134 return; // true;
80688135 }
80698136
8137
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8138
+ {
8139
+ if (// DrawMode() != 0 || /*tex == null ||*/
8140
+ ambientOcclusion ) // || !textureon)
8141
+ {
8142
+ return; // false;
8143
+ }
8144
+
8145
+ if (tex == null)
8146
+ {
8147
+ BindTexture(null,false,resolution);
8148
+ return;
8149
+ }
8150
+
8151
+ String pigment = Object3D.GetPigment(tex);
8152
+
8153
+ usedtextures.put(pigment, pigment);
8154
+
8155
+ if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8156
+ {
8157
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8158
+ // System.out.println("; bump = " + bump);
8159
+ }
8160
+
8161
+ if (pigment.equals(""))
8162
+ {
8163
+ pigment = null;
8164
+ }
8165
+
8166
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8167
+ BindTexture(pigment, false, resolution);
8168
+ }
8169
+
8170
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8171
+ {
8172
+ if (// DrawMode() != 0 || /*tex == null ||*/
8173
+ ambientOcclusion ) // || !textureon)
8174
+ {
8175
+ return; // false;
8176
+ }
8177
+
8178
+ if (tex == null)
8179
+ {
8180
+ BindTexture(null,true,resolution);
8181
+ return;
8182
+ }
8183
+
8184
+ String bump = Object3D.GetBump(tex);
8185
+
8186
+ usedtextures.put(bump, bump);
8187
+
8188
+ if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8189
+ {
8190
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8191
+ // System.out.println("; bump = " + bump);
8192
+ }
8193
+
8194
+ if (bump.equals(""))
8195
+ {
8196
+ bump = null;
8197
+ }
8198
+
8199
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8200
+ BindTexture(bump, true, resolution);
8201
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8202
+ }
8203
+
8204
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8205
+
8206
+ private boolean FileExists(String tex)
8207
+ {
8208
+ if (missingTextures.contains(tex))
8209
+ {
8210
+ return false;
8211
+ }
8212
+
8213
+ boolean fileExists = new File(tex).exists();
8214
+
8215
+ if (!fileExists)
8216
+ {
8217
+ // If file exists, the "new File()" is not executed sgain
8218
+ missingTextures.add(tex);
8219
+ }
8220
+
8221
+ return fileExists;
8222
+ }
8223
+
80708224 CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
80718225 {
80728226 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
....@@ -8075,15 +8229,17 @@
80758229 {
80768230 String texname = tex;
80778231
8232
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8233
+
80788234 // String[] split = tex.split("Textures");
80798235 // if (split.length > 1)
80808236 // texname = "/Users/nbriere/Textures" + split[split.length-1];
80818237 // else
80828238 // if (!texname.startsWith("/"))
80838239 // texname = "/Users/nbriere/Textures/" + texname;
8084
- if (!new File(tex).exists())
8240
+ if (!FileExists(tex))
80858241 {
8086
- texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname;
8242
+ texname = fallbackTextureName;
80878243 }
80888244
80898245 if (CACHETEXTURE)
....@@ -8153,7 +8309,7 @@
81538309 }
81548310
81558311 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
8156
- if (!new File(cachename).exists())
8312
+ if (!FileExists(cachename))
81578313 cachename = texname;
81588314 else
81598315 processbump = false; // don't process bump map again
....@@ -8175,7 +8331,7 @@
81758331 }
81768332
81778333 cachename = texname.substring(0, texname.length()-4)+ext+".png";
8178
- if (!new File(cachename).exists())
8334
+ if (!FileExists(cachename))
81798335 cachename = texname;
81808336 else
81818337 processbump = false; // don't process bump map again
....@@ -9310,8 +9466,8 @@
93109466 assert (parentcam != renderCamera);
93119467
93129468 if (renderCamera != lightCamera)
9313
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9314
- LA.matConcat(matrix, parentcam.toParent, matrix);
9469
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9470
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
93159471
93169472 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
93179473
....@@ -9326,8 +9482,8 @@
93269482 LA.matCopy(renderCamera.fromScreen, matrix);
93279483
93289484 if (renderCamera != lightCamera)
9329
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9330
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9485
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9486
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
93319487
93329488 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
93339489
....@@ -10525,8 +10681,8 @@
1052510681
1052610682 // if (parentcam != renderCamera) // not a light
1052710683 if (cam != lightCamera)
10528
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10529
- LA.matConcat(matrix, parentcam.toParent, matrix);
10684
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10685
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
1053010686
1053110687 for (int j = 0; j < 4; j++)
1053210688 {
....@@ -10540,8 +10696,8 @@
1054010696
1054110697 // if (parentcam != renderCamera) // not a light
1054210698 if (cam != lightCamera)
10543
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10544
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10699
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10700
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
1054510701
1054610702 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
1054710703
....@@ -10934,8 +11090,8 @@
1093411090 System.err.println("parentcam != renderCamera");
1093511091
1093611092 // if (cam != lightCamera)
10937
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10938
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11093
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11094
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1093911095 }
1094011096
1094111097 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10956,8 +11112,8 @@
1095611112 if (true) // TODO
1095711113 {
1095811114 if (cam != lightCamera)
10959
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10960
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11115
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11116
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1096111117 }
1096211118
1096311119 LA.xformPos(light0, cam.toScreen, light0);
....@@ -11302,6 +11458,24 @@
1130211458
1130311459 static boolean zoomonce = false;
1130411460
11461
+ void CreateSelectedPoint()
11462
+ {
11463
+ if (selectedpoint == null)
11464
+ {
11465
+ debugpointG = new Sphere();
11466
+ debugpointP = new Sphere();
11467
+ debugpointC = new Sphere();
11468
+ debugpointR = new Sphere();
11469
+
11470
+ selectedpoint = new Superellipsoid();
11471
+
11472
+ for (int i=0; i<8; i++)
11473
+ {
11474
+ debugpoints[i] = new Sphere();
11475
+ }
11476
+ }
11477
+ }
11478
+
1130511479 void DrawObject(GL gl, boolean draw)
1130611480 {
1130711481 //System.out.println("DRAW OBJECT " + mouseDown);
....@@ -11382,8 +11556,9 @@
1138211556
1138311557 if (DrawMode() == DEFAULT)
1138411558 {
11385
- if (DEBUG)
11559
+ if (Globals.DEBUG)
1138611560 {
11561
+ CreateSelectedPoint();
1138711562 float radius = 0.05f;
1138811563 if (selectedpoint.radius != radius)
1138911564 {
....@@ -11869,8 +12044,8 @@
1186912044 //obj.TransformToWorld(light, light);
1187012045 for (int i = tp.size(); --i >= 0;)
1187112046 {
11872
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11873
- LA.xformPos(light, tp.get(i).toParent, light);
12047
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12048
+ LA.xformPos(light, tp.get(i).GlobalTransform(), light);
1187412049 }
1187512050
1187612051
....@@ -11887,8 +12062,8 @@
1188712062 parentcam = cameras[0];
1188812063 }
1188912064
11890
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11891
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12065
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12066
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1189212067
1189312068 LA.xformPos(light, renderCamera.toScreen, light);
1189412069
....@@ -13809,9 +13984,12 @@
1380913984
1381013985 public void mouseDragged(MouseEvent e)
1381113986 {
13987
+ Globals.MOUSEDRAGGED = true;
13988
+
1381213989 //System.out.println("mouseDragged: " + e);
1381313990 if (isRenderer)
1381413991 movingcamera = true;
13992
+
1381513993 //if (drawing)
1381613994 //return;
1381713995 if ((e.getModifiersEx() & CTRL) != 0
....@@ -14373,6 +14551,8 @@
1437314551
1437414552 public void mouseReleased(MouseEvent e)
1437514553 {
14554
+ Globals.MOUSEDRAGGED = false;
14555
+
1437614556 movingcamera = false;
1437714557 X = Y = 0;
1437814558 //System.out.println("mouseReleased: " + e);
....@@ -14740,8 +14920,14 @@
1474014920 RevertCamera();
1474114921 repaint();
1474214922 break;
14743
- case 'L':
1474414923 case 'l':
14924
+ lightMode ^= true;
14925
+ Globals.lighttouched = true;
14926
+ manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14927
+ targetLookAt.set(manipCamera.lookAt);
14928
+ repaint();
14929
+ break;
14930
+ case 'L':
1474514931 if (lightMode)
1474614932 {
1474714933 lightMode = false;
....@@ -14888,16 +15074,14 @@
1488815074 kompactbit = 6;
1488915075 break;
1489015076 case ' ':
14891
- lightMode ^= true;
14892
- Globals.lighttouched = true;
14893
- manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
14894
- targetLookAt.set(manipCamera.lookAt);
15077
+ ObjEditor.theFrame.ToggleFullScreen();
1489515078 repaint();
1489615079 break;
1489715080 //case '`' :
1489815081 case ESC:
1489915082 RENDERPROGRAM += 1;
1490015083 RENDERPROGRAM %= 3;
15084
+
1490115085 repaint();
1490215086 break;
1490315087 case 'Z':
....@@ -15488,12 +15672,17 @@
1548815672 {
1548915673 switch (object.selection.get(0).hitSomething)
1549015674 {
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;
15675
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15676
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15677
+ break;
15678
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15679
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15680
+ break;
15681
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15682
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15683
+ break;
1549415684 }
1549515685
15496
- gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
1549715686 }
1549815687 }
1549915688 }
....@@ -15911,7 +16100,7 @@
1591116100 Object3D object;
1591216101 static Object3D trackedobject;
1591316102 Camera renderCamera; // Light or Eye (or Occlusion)
15914
- /*static*/ Camera manipCamera; // Light or Eye
16103
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1591516104 /*static*/ Camera eyeCamera;
1591616105 /*static*/ Camera lightCamera;
1591716106 int cameracount;
....@@ -17068,23 +17257,15 @@
1706817257 int AAbuffersize = 0;
1706917258
1707017259 //double[] selectedpoint = new double[3];
17071
- static Superellipsoid selectedpoint = new Superellipsoid();
17260
+ static Superellipsoid selectedpoint;
1707217261 static Sphere previousselectedpoint = null;
17073
- static Sphere debugpointG = new Sphere();
17074
- static Sphere debugpointP = new Sphere();
17075
- static Sphere debugpointC = new Sphere();
17076
- static Sphere debugpointR = new Sphere();
17262
+ static Sphere debugpointG;
17263
+ static Sphere debugpointP;
17264
+ static Sphere debugpointC;
17265
+ static Sphere debugpointR;
1707717266
1707817267 static Sphere debugpoints[] = new Sphere[8];
1707917268
17080
- static
17081
- {
17082
- for (int i=0; i<8; i++)
17083
- {
17084
- debugpoints[i] = new Sphere();
17085
- }
17086
- }
17087
-
1708817269 static void InitPoints(float radius)
1708917270 {
1709017271 for (int i=0; i<8; i++)