Normand Briere
2019-07-23 cf7cfa1c792eebba606a48aa648893f6e4873263
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -92,6 +126,8 @@
92126
93127 static int tickcount = 0; // slow pose issue
94128
129
+static boolean BUTTONLESSWHEEL = false;
130
+static boolean ZOOMBOXMODE = false;
95131 static boolean BOXMODE = false;
96132 static boolean IMAGEFLIP = false;
97133 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +142,7 @@
106142 static boolean OEIL = true;
107143 static boolean OEILONCE = false; // do oeilon then oeiloff
108144 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
145
+static boolean SWITCH = true; // false;
110146 static boolean HANDLES = false; // selection doesn't work!!
111147 static boolean PAINTMODE = false;
112148
....@@ -149,12 +185,13 @@
149185 defaultcaps.setAccumBlueBits(16);
150186 defaultcaps.setAccumAlphaBits(16);
151187 }
152
- static CameraPane theRenderer;
153
-
188
+
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
154191 void SetAsGLRenderer(boolean b)
155192 {
156193 isRenderer = b;
157
- theRenderer = this;
194
+ Globals.theRenderer = this;
158195 }
159196
160197 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -192,9 +229,43 @@
192229
193230 /// INTERFACE
194231
232
+ public javax.media.opengl.GL GetGL0()
233
+ {
234
+ return null;
235
+ }
236
+
237
+ public int GenList()
238
+ {
239
+ javax.media.opengl.GL gl = GetGL();
240
+ return gl.glGenLists(1);
241
+ }
242
+
243
+ public void NewList(int id)
244
+ {
245
+ javax.media.opengl.GL gl = GetGL();
246
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
247
+ }
248
+
249
+ public void CallList(int id)
250
+ {
251
+ javax.media.opengl.GL gl = GetGL();
252
+ gl.glCallList(id);
253
+ }
254
+
255
+ public void EndList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ gl.glEndList();
259
+ }
260
+
195261 public boolean IsBoxMode()
196262 {
197263 return BOXMODE;
264
+ }
265
+
266
+ public boolean IsZoomBoxMode()
267
+ {
268
+ return ZOOMBOXMODE;
198269 }
199270
200271 public void ClearDepth()
....@@ -236,9 +307,14 @@
236307 return this.ambientOcclusion;
237308 }
238309
310
+ public boolean IsDebugSelection()
311
+ {
312
+ return DEBUG_SELECTION;
313
+ }
314
+
239315 public boolean IsFrozen()
240316 {
241
- boolean selectmode = this.DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
317
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
242318
243319 return !selectmode && cameracount == 0; // != 0;
244320 }
....@@ -259,9 +335,19 @@
259335 return lightCamera;
260336 }
261337
338
+ public Camera ManipCamera()
339
+ {
340
+ return manipCamera;
341
+ }
342
+
262343 public Camera RenderCamera()
263344 {
264345 return renderCamera;
346
+ }
347
+
348
+ public Camera[] Cameras()
349
+ {
350
+ return cameras;
265351 }
266352
267353 public void PushMaterial(Object3D obj, boolean selected)
....@@ -277,7 +363,7 @@
277363 cStatic.objectstack[materialdepth++] = obj;
278364 //System.out.println("material " + material);
279365 //Applet3D.tracein(this, selected);
280
- display.vector2buffer = obj.projectedVertices;
366
+ //display.vector2buffer = obj.projectedVertices;
281367 if (obj instanceof Camera)
282368 {
283369 display.options1[0] = material.shift;
....@@ -286,14 +372,28 @@
286372 display.options1[2] = material.shadowbias;
287373 display.options1[3] = material.aniso;
288374 display.options1[4] = material.anisoV;
375
+// System.out.println("display.options1[0] " + display.options1[0]);
376
+// System.out.println("display.options1[1] " + display.options1[1]);
377
+// System.out.println("display.options1[2] " + display.options1[2]);
378
+// System.out.println("display.options1[3] " + display.options1[3]);
379
+// System.out.println("display.options1[4] " + display.options1[4]);
289380 display.options2[0] = material.opacity;
290381 display.options2[1] = material.diffuse;
291382 display.options2[2] = material.factor;
383
+// System.out.println("display.options2[0] " + display.options2[0]);
384
+// System.out.println("display.options2[1] " + display.options2[1]);
385
+// System.out.println("display.options2[2] " + display.options2[2]);
292386
293387 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
388
+// System.out.println("display.options3[0] " + display.options3[0]);
389
+// System.out.println("display.options3[1] " + display.options3[1]);
390
+// System.out.println("display.options3[2] " + display.options3[2]);
294391 display.options4[0] = material.cameralight/0.2f;
295392 display.options4[1] = material.subsurface;
296393 display.options4[2] = material.sheen;
394
+// System.out.println("display.options4[0] " + display.options4[0]);
395
+// System.out.println("display.options4[1] " + display.options4[1]);
396
+// System.out.println("display.options4[2] " + display.options4[2]);
297397
298398 // if (display.CURRENTANTIALIAS > 0)
299399 // display.options3[3] /= 4;
....@@ -309,7 +409,7 @@
309409 /**/
310410 } else
311411 {
312
- DrawMaterial(material, selected);
412
+ DrawMaterial(material, selected, obj.projectedVertices);
313413 }
314414 } else
315415 {
....@@ -333,8 +433,8 @@
333433 cStatic.objectstack[materialdepth++] = obj;
334434 //System.out.println("material " + material);
335435 //Applet3D.tracein("selected ", selected);
336
- display.vector2buffer = obj.projectedVertices;
337
- display.DrawMaterial(material, selected);
436
+ //display.vector2buffer = obj.projectedVertices;
437
+ display.DrawMaterial(material, selected, obj.projectedVertices);
338438 }
339439 }
340440
....@@ -351,8 +451,8 @@
351451 materialdepth -= 1;
352452 if (materialdepth > 0)
353453 {
354
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
355
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
454
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
455
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
356456 }
357457 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
358458 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -372,8 +472,8 @@
372472 materialdepth -= 1;
373473 if (materialdepth > 0)
374474 {
375
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
376
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
475
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
476
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
377477 }
378478 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
379479 //else
....@@ -408,16 +508,18 @@
408508
409509 javax.media.opengl.GL gl = display.GetGL();
410510
411
- boolean selectmode = display.DrawMode() == display.SELECTION || CameraPane.DEBUG_SELECTION;
511
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
412512
413513 //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
414514 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
415515 {
416516 //gl.glBegin(gl.GL_TRIANGLES);
417
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
517
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
518
+ // TEST LIVE NORMALS && !obj.dontselect
519
+ ;
418520 if (!hasnorm)
419521 {
420
- // System.out.println("FUCK!!");
522
+ // System.out.println("Mesh normal");
421523 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
422524 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
423525 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -760,7 +862,627 @@
760862 //// tris.postdraw(this);
761863 }
762864
865
+ static Camera localcamera = new Camera();
866
+ static cVector from = new cVector();
867
+ static cVector to = new cVector();
868
+
869
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
870
+ {
871
+ CameraPane cp = this;
872
+
873
+ Camera keep = cp.RenderCamera();
874
+ cp.renderCamera = localcamera;
875
+
876
+ if (br.trimmed)
877
+ {
878
+ float[] colors = new float[br.positions.length / 3];
879
+
880
+ int i3 = 0;
881
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
882
+ {
883
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
884
+ continue;
885
+
886
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
887
+ to.set(br.positions[i3] + br.normals[i3],
888
+ br.positions[i3 + 1] + br.normals[i3 + 1],
889
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
890
+ LA.xformPos(from, transform, from);
891
+ LA.xformPos(to, transform, to); // RIGID ONLY
892
+ localcamera.setAim(from, to);
893
+
894
+ CameraPane.occlusionbuffer.display();
895
+
896
+ if (CameraPane.DEBUG_OCCLUSION)
897
+ cp.display(); // debug
898
+
899
+ colors[i] = cp.vertexOcclusion.r;
900
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
901
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
902
+
903
+ if ((i % 100) == 0 && i != 0)
904
+ {
905
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
906
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
907
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
908
+ }
909
+ }
910
+
911
+ br.colors = colors;
912
+ }
913
+ else
914
+ {
915
+ for (int i = 0; i < br.VertexCount(); i++)
916
+ {
917
+ Vertex v = br.GetVertex(i);
918
+
919
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
920
+ continue;
921
+
922
+ from.set(v.x, v.y, v.z);
923
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
924
+ LA.xformPos(from, transform, from);
925
+ LA.xformPos(to, transform, to); // RIGID ONLY
926
+ localcamera.setAim(from, to);
927
+
928
+ CameraPane.occlusionbuffer.display();
929
+
930
+ if (CameraPane.DEBUG_OCCLUSION)
931
+ cp.display(); // debug
932
+
933
+ v.AO = cp.vertexOcclusion.r;
934
+
935
+ if ((i % 100) == 0 && i != 0)
936
+ {
937
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
938
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
939
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
940
+ }
941
+ }
942
+ }
943
+
944
+ //System.out.println("done.");
945
+
946
+ cp.renderCamera = keep;
947
+ }
948
+
949
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
950
+ {
951
+ CameraPane display = this;
952
+ pointFlow.CreateHT();
953
+
954
+ float r = display.modelParams0[0];
955
+ float g = display.modelParams0[1];
956
+ float b = display.modelParams0[2];
957
+ float opacity = display.modelParams5[1];
958
+
959
+ //final GL gl = GLU.getCurrentGL();
960
+ GL gl = display.GetGL(); // getGL();
961
+
962
+ int s = pointFlow.points.size();
963
+
964
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
965
+ gl.glEnable(gl.GL_CULL_FACE);
966
+
967
+ for (int i=s; --i>=0;)
968
+ //for (int i=0; i<s; i++)
969
+ {
970
+ cVector v = pointFlow.points.get(i);
971
+
972
+ double mindist = Double.MAX_VALUE;
973
+
974
+ double size = pointFlow.minimumSize;
975
+
976
+ double distancenext = 0;
977
+
978
+ if (i > 0)
979
+ {
980
+ cVector w = pointFlow.points.get(i-1);
981
+
982
+ double dist = w.distance(v);
983
+
984
+ distancenext = dist;
985
+
986
+ if (mindist > dist)
987
+ {
988
+ mindist = dist;
989
+ size = mindist*pointFlow.resizefactor;
990
+ }
991
+ }
992
+
993
+ if (i < s-1)
994
+ {
995
+ cVector w = pointFlow.points.get(i+1);
996
+
997
+ double dist = w.distance(v);
998
+
999
+ if (mindist > dist)
1000
+ {
1001
+ mindist = dist;
1002
+ size = mindist*pointFlow.resizefactor;
1003
+ }
1004
+ }
1005
+
1006
+ if (size < pointFlow.minimumSize)
1007
+ size = pointFlow.minimumSize;
1008
+ if (size > pointFlow.maximumSize)
1009
+ size = pointFlow.maximumSize;
1010
+
1011
+ double tx = v.x;
1012
+ double ty = v.y;
1013
+ double tz = v.z;
1014
+
1015
+ // if (tx == 0 && ty == 0 && tz == 0)
1016
+ // continue;
1017
+
1018
+ gl.glMatrixMode(gl.GL_TEXTURE);
1019
+ gl.glPushMatrix();
1020
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1021
+
1022
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1023
+
1024
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1025
+ gl.glPushMatrix();
1026
+
1027
+ gl.glTranslated(tx,ty,tz);
1028
+
1029
+ gl.glScaled(size,size,size);
1030
+
1031
+// float cr = colorBuf.get(index4);
1032
+// float cg = colorBuf.get(index4+1);
1033
+// float cb = colorBuf.get(index4+2);
1034
+// float ca = colorBuf.get(index4+3);
1035
+//
1036
+// display.modelParams0[0] = r * cr;
1037
+// display.modelParams0[1] = g * cg;
1038
+// display.modelParams0[2] = b * cb;
1039
+//
1040
+// display.modelParams5[1] = opacity * ca;
1041
+//
1042
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1043
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1044
+//
1045
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1046
+// RandomNode.globalseed2 = RandomNode.globalseed;
1047
+//
1048
+//// gl.glColor4f(cr,cg,cb,ca);
1049
+// // gl.glScalef(1024/16,1024/16,1024/16);
1050
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1051
+
1052
+ gl.glPopMatrix();
1053
+
1054
+ double step = size/4; //
1055
+
1056
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1057
+ continue;
1058
+
1059
+ int nbsteps = (int)(distancenext/step);
1060
+
1061
+ step = distancenext/nbsteps;
1062
+
1063
+ cVector next = pointFlow.points.get(i-1);
1064
+
1065
+ tmp.set(next);
1066
+ tmp.sub(v);
1067
+ tmp.normalize();
1068
+ tmp.mul(step);
1069
+
1070
+ // calculate next size
1071
+ mindist = Double.MAX_VALUE;
1072
+
1073
+ double nextsize = pointFlow.minimumSize;
1074
+
1075
+ if (i > 1)
1076
+ {
1077
+ cVector w = pointFlow.points.get(i-2);
1078
+
1079
+ double dist = w.distance(next);
1080
+
1081
+ if (mindist > dist)
1082
+ {
1083
+ mindist = dist;
1084
+ nextsize = mindist*pointFlow.resizefactor;
1085
+ }
1086
+ }
1087
+
1088
+ double dist = v.distance(next);
1089
+
1090
+ if (mindist > dist)
1091
+ {
1092
+ mindist = dist;
1093
+ nextsize = mindist*pointFlow.resizefactor;
1094
+ }
1095
+
1096
+ if (nextsize < pointFlow.minimumSize)
1097
+ nextsize = pointFlow.minimumSize;
1098
+ if (nextsize > pointFlow.maximumSize)
1099
+ nextsize = pointFlow.maximumSize;
1100
+ //
1101
+
1102
+ double count = 0;
1103
+
1104
+ while (distancenext > 0.000000001) // step
1105
+ {
1106
+ gl.glPushMatrix();
1107
+
1108
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1109
+
1110
+ double K = count/nbsteps;
1111
+
1112
+ double intersize = K*nextsize + (1-K)*size;
1113
+
1114
+ gl.glScaled(intersize,intersize,intersize);
1115
+
1116
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1117
+
1118
+ count++;
1119
+
1120
+ distancenext -= step;
1121
+
1122
+ gl.glPopMatrix();
1123
+ }
1124
+
1125
+ if (count != nbsteps)
1126
+ assert(count == nbsteps);
1127
+
1128
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1129
+ //gl.glTranslatef(-tx,-ty,-tz);
1130
+
1131
+ gl.glMatrixMode(gl.GL_TEXTURE);
1132
+ gl.glPopMatrix();
1133
+ }
1134
+
1135
+ if (!cf)
1136
+ gl.glDisable(gl.GL_CULL_FACE);
1137
+
1138
+// display.modelParams0[0] = r;
1139
+// display.modelParams0[1] = g;
1140
+// display.modelParams0[2] = b;
1141
+//
1142
+// display.modelParams5[1] = opacity;
1143
+//
1144
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1145
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1146
+
1147
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1148
+ }
1149
+
1150
+ public void DrawBox(cVector min, cVector max)
1151
+ {
1152
+ javax.media.opengl.GL gl = GetGL();
1153
+ gl.glBegin(gl.GL_LINES);
1154
+
1155
+ gl.glVertex3d(min.x, min.y, min.z);
1156
+ gl.glVertex3d(min.x, min.y, max.z);
1157
+ gl.glVertex3d(min.x, min.y, min.z);
1158
+ gl.glVertex3d(min.x, max.y, min.z);
1159
+ gl.glVertex3d(min.x, min.y, min.z);
1160
+ gl.glVertex3d(max.x, min.y, min.z);
1161
+
1162
+ gl.glVertex3d(max.x, max.y, max.z);
1163
+ gl.glVertex3d(min.x, max.y, max.z);
1164
+ gl.glVertex3d(max.x, max.y, max.z);
1165
+ gl.glVertex3d(max.x, min.y, max.z);
1166
+ gl.glVertex3d(max.x, max.y, max.z);
1167
+ gl.glVertex3d(max.x, max.y, min.z);
1168
+
1169
+ gl.glEnd();
1170
+ }
1171
+
1172
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1173
+ {
1174
+ int[] strips = bRep.getRawIndices();
1175
+
1176
+ javax.media.opengl.GL gl = GetGL();
1177
+
1178
+ // TRIANGLE STRIP ARRAY
1179
+ if (bRep.trimmed)
1180
+ {
1181
+ float[] v = bRep.getRawVertices();
1182
+ float[] n = bRep.getRawNormals();
1183
+ float[] c = bRep.getRawColors();
1184
+ float[] uv = bRep.getRawUVMap();
1185
+
1186
+ int count2 = 0;
1187
+ int count3 = 0;
1188
+
1189
+ if (n.length > 0)
1190
+ {
1191
+ for (int i = 0; i < strips.length; i++)
1192
+ {
1193
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1194
+
1195
+ /*
1196
+ boolean locked = false;
1197
+ float eps = 0.1f;
1198
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1199
+
1200
+ int dot = 0;
1201
+
1202
+ if ((dot&1) == 0)
1203
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1204
+
1205
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1206
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1207
+ else
1208
+ {
1209
+ locked = true;
1210
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1211
+ }
1212
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1213
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1214
+ if (hasnorm)
1215
+ {
1216
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1217
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1218
+ }
1219
+
1220
+ if ((dot&4) == 0)
1221
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1222
+
1223
+ if (wrap || !locked && (dot&8) != 0)
1224
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1225
+ else
1226
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1227
+
1228
+ f.dot = dot;
1229
+ */
1230
+
1231
+ if (!selectmode)
1232
+ {
1233
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1234
+ {
1235
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1236
+ } else
1237
+ {
1238
+ gl.glNormal3f(0, 0, 1);
1239
+ }
1240
+
1241
+ if (c != null)
1242
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1243
+ {
1244
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1245
+ }
1246
+ }
1247
+
1248
+ if (flipV)
1249
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1250
+ else
1251
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1252
+
1253
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1254
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1255
+
1256
+ count2 += 2;
1257
+ count3 += 3;
1258
+ if (!selectmode)
1259
+ {
1260
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1261
+ {
1262
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1263
+ } else
1264
+ {
1265
+ gl.glNormal3f(0, 0, 1);
1266
+ }
1267
+ if (c != null)
1268
+ {
1269
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1270
+ }
1271
+ }
1272
+
1273
+ if (flipV)
1274
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1275
+ else
1276
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1277
+
1278
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1279
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1280
+
1281
+ count2 += 2;
1282
+ count3 += 3;
1283
+ for (int j = 0; j < strips[i] - 2; j++)
1284
+ {
1285
+ //gl.glTexCoord2d(...);
1286
+ if (!selectmode)
1287
+ {
1288
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1289
+ {
1290
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1291
+ } else
1292
+ {
1293
+ gl.glNormal3f(0, 0, 1);
1294
+ }
1295
+ if (c != null)
1296
+ {
1297
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1298
+ }
1299
+ }
1300
+
1301
+ if (flipV)
1302
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1303
+ else
1304
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1305
+
1306
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1307
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1308
+
1309
+ count2 += 2;
1310
+ count3 += 3;
1311
+ }
1312
+
1313
+ gl.glEnd();
1314
+ }
1315
+ }
1316
+
1317
+ assert count3 == v.length;
1318
+ }
1319
+ else // !trimmed
1320
+ {
1321
+ int count = 0;
1322
+ for (int i = 0; i < strips.length; i++)
1323
+ {
1324
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1325
+
1326
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1327
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1328
+
1329
+ drawVertex(gl, p, flipV, selectmode);
1330
+ drawVertex(gl, q, flipV, selectmode);
1331
+
1332
+ for (int j = 0; j < strips[i] - 2; j++)
1333
+ {
1334
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1335
+
1336
+ // if (j%2 == 0)
1337
+ // drawFace(p, q, r, display, null);
1338
+ // else
1339
+ // drawFace(p, r, q, display, null);
1340
+
1341
+ // p = q;
1342
+ // q = r;
1343
+ drawVertex(gl, r, flipV, selectmode);
1344
+ }
1345
+
1346
+ gl.glEnd();
1347
+ }
1348
+ }
1349
+ }
1350
+
1351
+ static cSpring.Point3D temp = new cSpring.Point3D();
1352
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1353
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1354
+
1355
+ public void DrawDynamicMesh(cMesh mesh)
1356
+ {
1357
+ GL gl = GetGL(); // getGL();
1358
+
1359
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1360
+
1361
+ gl.glDisable(gl.GL_LIGHTING);
1362
+
1363
+ gl.glLineWidth(1);
1364
+ gl.glColor3f(1,1,1);
1365
+ gl.glBegin(gl.GL_LINES);
1366
+ double scale = 0;
1367
+ int count = 0;
1368
+ for (int s=0; s<Phys.allSprings.size(); s++)
1369
+ {
1370
+ cSpring.Spring spring = Phys.allSprings.get(s);
1371
+ if(s == 0)
1372
+ {
1373
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1374
+ }
1375
+ if (mesh.showsprings)
1376
+ {
1377
+ temp.set(spring.a.position);
1378
+ temp.add(spring.b.position);
1379
+ temp.mul(0.5);
1380
+ temp2.set(spring.a.position);
1381
+ temp2.sub(spring.b.position);
1382
+ temp2.mul(spring.restLength/2);
1383
+ temp.sub(temp2);
1384
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1385
+ temp.add(temp2);
1386
+ temp.add(temp2);
1387
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1388
+ }
1389
+
1390
+ if (spring.isHandle)
1391
+ continue;
1392
+
1393
+ //if (scale < spring.restLength)
1394
+ scale += spring.restLength;
1395
+ count++;
1396
+ }
1397
+ gl.glEnd();
1398
+
1399
+ if (count == 0)
1400
+ scale = 0.01;
1401
+ else
1402
+ scale /= count * 3;
1403
+
1404
+ //scale = 0.25;
1405
+
1406
+ if (mesh.ShowInfo())
1407
+ {
1408
+ gl.glLineWidth(4);
1409
+ for (int s=0; s<Phys.allNodes.size(); s++)
1410
+ {
1411
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1412
+ if (node.mass == 0)
1413
+ continue;
1414
+
1415
+ int i = node.springs==null?-1:node.springs.size();
1416
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1417
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1418
+ //temp.normalize();
1419
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1420
+ gl.glBegin(gl.GL_LINES);
1421
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1422
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1423
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1424
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1425
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1426
+ gl.glEnd();
1427
+ }
1428
+
1429
+ gl.glLineWidth(8);
1430
+ for (int s=0; s<Phys.allNodes.size(); s++)
1431
+ {
1432
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1433
+
1434
+ if (node.springs != null)
1435
+ {
1436
+ for (int i=0; i<node.springs.size(); i+=1)
1437
+ {
1438
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1439
+
1440
+ int c = i+1;
1441
+ // c = node.springs.get(i).nbcopies;
1442
+
1443
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1444
+ gl.glBegin(gl.GL_LINES);
1445
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1446
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1447
+ gl.glEnd();
1448
+ }
1449
+ }
1450
+ }
1451
+
1452
+ gl.glLineWidth(1);
1453
+ }
1454
+
1455
+ gl.glEnable(gl.GL_LIGHTING);
1456
+ }
1457
+
7631458 /// INTERFACE
1459
+
1460
+ public void StartTriangles()
1461
+ {
1462
+ javax.media.opengl.GL gl = GetGL();
1463
+ gl.glBegin(gl.GL_TRIANGLES);
1464
+ }
1465
+
1466
+ public void EndTriangles()
1467
+ {
1468
+ GetGL().glEnd();
1469
+ }
1470
+
1471
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1472
+ {
1473
+ if (!selectmode)
1474
+ {
1475
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1476
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1477
+
1478
+ if (flipV)
1479
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1480
+ else
1481
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1482
+ }
1483
+
1484
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1485
+ }
7641486
7651487 void SetColor(Object3D obj, Vertex p0)
7661488 {
....@@ -939,7 +1661,7 @@
9391661 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
9401662 }
9411663
942
- void DrawMaterial(cMaterial material, boolean selected)
1664
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
9431665 {
9441666 CameraPane display = this;
9451667 //new Exception().printStackTrace();
....@@ -955,18 +1677,18 @@
9551677 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
9561678 if (!material.multiply)
9571679 {
958
- display.color = color;
1680
+ display.color = material.color;
9591681 display.saturation = material.modulation;
9601682 }
9611683 else
9621684 {
963
- display.color *= color*2;
1685
+ display.color *= material.color*2;
9641686 display.saturation *= material.modulation*2;
9651687 }
9661688
9671689 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
9681690
969
- float[] colorV = GrafreeD.colorV;
1691
+ float[] colorV = Grafreed.colorV;
9701692
9711693 /**/
9721694 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -974,7 +1696,7 @@
9741696 colorV[0] = display.modelParams0[0] * material.diffuse;
9751697 colorV[1] = display.modelParams0[1] * material.diffuse;
9761698 colorV[2] = display.modelParams0[2] * material.diffuse;
977
- colorV[3] = material.opacity;
1699
+ colorV[3] = 1; // material.opacity;
9781700
9791701 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
9801702 //System.out.println("Opacity = " + opacity);
....@@ -1082,9 +1804,9 @@
10821804 display.modelParams7[2] = 0;
10831805 display.modelParams7[3] = 0;
10841806
1085
- display.modelParams6[0] = 100; // criss de bug de bump
1807
+ //display.modelParams6[0] = 100; // criss de bug de bump
10861808
1087
- Object3D.cVector2[] extparams = display.vector2buffer;
1809
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
10881810 if (extparams != null && extparams.length > 0 && extparams[0] != null)
10891811 {
10901812 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1226,7 +1948,7 @@
12261948 void PushMatrix(double[][] matrix)
12271949 {
12281950 // GrafreeD.tracein(matrix);
1229
- PushMatrix(matrix,1);
1951
+ PushMatrix(matrix, 1);
12301952 }
12311953
12321954 void PushMatrix()
....@@ -1323,7 +2045,7 @@
13232045
13242046 static int camerachangeframe;
13252047
1326
- boolean SetCamera(Camera cam)
2048
+ public boolean SetCamera(Camera cam)
13272049 {
13282050 // may 2014 if (cam == cameras[0] || cam == cameras[1])
13292051 // return false;
....@@ -1380,7 +2102,7 @@
13802102 //System.err.println("Oeil on");
13812103 OEIL = true;
13822104 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1383
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2105
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
13842106 //pingthread.StepToTarget(true);
13852107 }
13862108
....@@ -1451,33 +2173,6 @@
14512173 mainDL ^= true;
14522174 }
14532175
1454
- void ToggleTexture()
1455
- {
1456
- textureon ^= true;
1457
- }
1458
-
1459
- void ToggleLive()
1460
- {
1461
- Globals.setLIVE(Globals.isLIVE() ^ true);
1462
-
1463
- System.err.println("LIVE = " + Globals.isLIVE());
1464
-
1465
- if (!Globals.isLIVE()) // save sound
1466
- GrafreeD.savesound = true; // wav.save();
1467
- // else
1468
- repaint(); // start loop // may 2013
1469
- }
1470
-
1471
- void ToggleSupport()
1472
- {
1473
- SUPPORT ^= true;
1474
- }
1475
-
1476
- void ToggleAbort()
1477
- {
1478
- ABORTMODE ^= true;
1479
- }
1480
-
14812176 void ToggleFullScreen()
14822177 {
14832178 FULLSCREEN ^= true;
....@@ -1488,72 +2183,94 @@
14882183 Globals.CROWD ^= true;
14892184 }
14902185
1491
- void ToggleInertia()
1492
- {
1493
- INERTIA ^= true;
1494
- }
1495
-
14962186 void ToggleLocal()
14972187 {
14982188 LOCALTRANSFORM ^= true;
14992189 }
15002190
1501
- void ToggleFast()
2191
+ public void ToggleTexture()
2192
+ {
2193
+ textureon ^= true;
2194
+ }
2195
+
2196
+ public void ToggleLive()
2197
+ {
2198
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2199
+
2200
+ System.err.println("LIVE = " + Globals.isLIVE());
2201
+
2202
+ if (!Globals.isLIVE()) // save sound
2203
+ Grafreed.savesound = true; // wav.save();
2204
+ // else
2205
+ repaint(); // start loop // may 2013
2206
+ }
2207
+
2208
+ public void ToggleSupport()
2209
+ {
2210
+ SUPPORT ^= true;
2211
+ }
2212
+
2213
+ public void ToggleAbort()
2214
+ {
2215
+ ABORTMODE ^= true;
2216
+ }
2217
+
2218
+ public void ToggleInertia()
2219
+ {
2220
+ INERTIA ^= true;
2221
+ }
2222
+
2223
+ public void ToggleFast()
15022224 {
15032225 FAST ^= true;
15042226 }
15052227
1506
- void ToggleSlowPose()
2228
+ public void ToggleSlowPose()
15072229 {
15082230 SLOWPOSE ^= true;
15092231 }
15102232
1511
- void ToggleFootContact()
1512
- {
1513
- FOOTCONTACT ^= true;
1514
- }
1515
-
1516
- void ToggleBoxMode()
2233
+ public void ToggleBoxMode()
15172234 {
15182235 BOXMODE ^= true;
15192236 }
15202237
1521
- void ToggleSmoothFocus()
2238
+ public void ToggleZoomBoxMode()
2239
+ {
2240
+ ZOOMBOXMODE ^= true;
2241
+ }
2242
+
2243
+ public void ToggleSmoothFocus()
15222244 {
15232245 SMOOTHFOCUS ^= true;
15242246 }
15252247
1526
- void ToggleImageFlip()
2248
+ public void ToggleImageFlip()
15272249 {
15282250 IMAGEFLIP ^= true;
15292251 }
15302252
1531
- void ToggleSpeakerMocap()
2253
+ public void ToggleSpeakerMocap()
15322254 {
15332255 SPEAKERMOCAP ^= true;
15342256 }
15352257
1536
- void ToggleSpeakerCamera()
2258
+ public void ToggleSpeakerCamera()
15372259 {
15382260 SPEAKERCAMERA ^= true;
15392261 }
15402262
1541
- void ToggleSpeakerFocus()
2263
+ public void ToggleSpeakerFocus()
15422264 {
15432265 SPEAKERFOCUS ^= true;
15442266 }
15452267
1546
- void ToggleDebug()
1547
- {
1548
- DEBUG ^= true;
1549
- }
1550
-
1551
- void ToggleFrustum()
2268
+ public void ToggleFrustum()
15522269 {
15532270 FRUSTUM ^= true;
15542271 }
15552272
1556
- void ToggleTrack()
2273
+ public void ToggleTrack()
15572274 {
15582275 TRACK ^= true;
15592276 if (TRACK)
....@@ -1572,25 +2289,35 @@
15722289 repaint();
15732290 }
15742291
1575
- void ToggleTrackOnce()
2292
+ public void ToggleTrackOnce()
15762293 {
15772294 TRACKONCE ^= true;
15782295 }
15792296
1580
- void ToggleShadowTrack()
2297
+ public void ToggleShadowTrack()
15812298 {
15822299 SHADOWTRACK ^= true;
15832300 repaint();
15842301 }
15852302
1586
- void ToggleOeil()
2303
+ public void ToggleOeil()
15872304 {
15882305 OEIL ^= true;
15892306 }
15902307
1591
- void ToggleOeilOnce()
2308
+ public void ToggleOeilOnce()
15922309 {
15932310 OEILONCE ^= true;
2311
+ }
2312
+
2313
+ void ToggleFootContact()
2314
+ {
2315
+ FOOTCONTACT ^= true;
2316
+ }
2317
+
2318
+ void ToggleDebug()
2319
+ {
2320
+ Globals.DEBUG ^= true;
15942321 }
15952322
15962323 void ToggleLookAt()
....@@ -1598,9 +2325,9 @@
15982325 LOOKAT ^= true;
15992326 }
16002327
1601
- void ToggleRandom()
2328
+ void ToggleSwitch()
16022329 {
1603
- RANDOM ^= true;
2330
+ SWITCH ^= true;
16042331 }
16052332
16062333 void ToggleHandles()
....@@ -1608,10 +2335,17 @@
16082335 HANDLES ^= true;
16092336 }
16102337
2338
+ Object3D paintFolder;
2339
+
16112340 void TogglePaint()
16122341 {
16132342 PAINTMODE ^= true;
16142343 paintcount = 0;
2344
+
2345
+ if (PAINTMODE)
2346
+ {
2347
+ paintFolder = GetFolder();
2348
+ }
16152349 }
16162350
16172351 void SwapCamera(int a, int b)
....@@ -1707,7 +2441,22 @@
17072441 {
17082442 return currentGL;
17092443 }
1710
-
2444
+
2445
+ static private BufferedImage CreateBim(TextureData texturedata)
2446
+ {
2447
+ Grafreed.Assert(texturedata != null);
2448
+
2449
+ int width = texturedata.getWidth();
2450
+ int height = texturedata.getHeight();
2451
+
2452
+ Buffer buffer = texturedata.getBuffer();
2453
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2454
+
2455
+ byte[] bytes = bytebuf.array();
2456
+
2457
+ return CreateBim(bytes, width, height);
2458
+ }
2459
+
17112460 /**/
17122461 class CacheTexture
17132462 {
....@@ -1716,28 +2465,31 @@
17162465
17172466 int resolution;
17182467
1719
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2468
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
17202469 {
1721
- texture = tex;
2470
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2471
+ texturedata = texdata;
17222472 resolution = res;
17232473 }
17242474 }
17252475 /**/
17262476
17272477 // TEXTURE static Texture texture;
1728
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
1729
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
1730
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2478
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2481
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2482
+
17312483 int pigmentdepth = 0;
17322484 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
17332485 int bumpdepth = 0;
17342486 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
17352487 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
17362488 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
1737
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2489
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
17382490 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
17392491
1740
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2492
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
17412493 {
17422494 TextureData texturedata = null;
17432495
....@@ -1756,13 +2508,34 @@
17562508 if (bump)
17572509 texturedata = ConvertBump(texturedata, false);
17582510
1759
- com.sun.opengl.util.texture.Texture texture =
1760
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2511
+// com.sun.opengl.util.texture.Texture texture =
2512
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
17612513
1762
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
1763
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2514
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
17642516
1765
- return texture;
2517
+ return texturedata;
2518
+ }
2519
+
2520
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2521
+ {
2522
+ TextureData texturedata = null;
2523
+
2524
+ try
2525
+ {
2526
+ texturedata =
2527
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2528
+ bim,
2529
+ true);
2530
+ } catch (Exception e)
2531
+ {
2532
+ throw new javax.media.opengl.GLException(e);
2533
+ }
2534
+
2535
+ if (bump)
2536
+ texturedata = ConvertBump(texturedata, false);
2537
+
2538
+ return texturedata;
17662539 }
17672540
17682541 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -2835,6 +3608,8 @@
28353608
28363609 System.out.println("LOADING TEXTURE : " + name);
28373610
3611
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3612
+
28383613 //
28393614 if (false) // compressbit > 0)
28403615 {
....@@ -3539,6 +4314,7 @@
35394314
35404315 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
35414316 {
4317
+ new Exception().printStackTrace();
35424318 System.exit(0);
35434319 com.sun.opengl.util.texture.Texture texture = null;
35444320
....@@ -7232,7 +8008,7 @@
72328008 String pigment = Object3D.GetPigment(tex);
72338009 String bump = Object3D.GetBump(tex);
72348010
7235
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8011
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
72368012 {
72378013 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
72388014 // System.out.println("; bump = " + bump);
....@@ -7247,11 +8023,69 @@
72478023 pigment = null;
72488024 }
72498025
7250
- ReleaseTexture(bump, true);
7251
- ReleaseTexture(pigment, false);
8026
+ ReleaseTexture(tex, true);
8027
+ ReleaseTexture(tex, false);
72528028 }
72538029
7254
- void ReleaseTexture(String tex, boolean bump)
8030
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8031
+ {
8032
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8033
+ {
8034
+ return;
8035
+ }
8036
+
8037
+ if (tex == null)
8038
+ {
8039
+ ReleaseTexture(null, false);
8040
+ return;
8041
+ }
8042
+
8043
+ String pigment = Object3D.GetPigment(tex);
8044
+
8045
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8046
+ {
8047
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8048
+ // System.out.println("; bump = " + bump);
8049
+ }
8050
+
8051
+ if (pigment.equals(""))
8052
+ {
8053
+ pigment = null;
8054
+ }
8055
+
8056
+ ReleaseTexture(tex, false);
8057
+ }
8058
+
8059
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8060
+ {
8061
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8062
+ {
8063
+ return;
8064
+ }
8065
+
8066
+ if (tex == null)
8067
+ {
8068
+ ReleaseTexture(null, true);
8069
+ return;
8070
+ }
8071
+
8072
+ String bump = Object3D.GetBump(tex);
8073
+
8074
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8075
+ {
8076
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8077
+ // System.out.println("; bump = " + bump);
8078
+ }
8079
+
8080
+ if (bump.equals(""))
8081
+ {
8082
+ bump = null;
8083
+ }
8084
+
8085
+ ReleaseTexture(tex, true);
8086
+ }
8087
+
8088
+ void ReleaseTexture(cTexture tex, boolean bump)
72558089 {
72568090 if (// DrawMode() != 0 || /*tex == null ||*/
72578091 ambientOcclusion ) // || !textureon)
....@@ -7262,7 +8096,7 @@
72628096 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
72638097
72648098 if (tex != null)
7265
- texture = textures.get(tex);
8099
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
72668100
72678101 // //assert( texture != null );
72688102 // if (texture == null)
....@@ -7354,7 +8188,55 @@
73548188 }
73558189 }
73568190
7357
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8191
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8192
+ {
8193
+// if (// DrawMode() != 0 || /*tex == null ||*/
8194
+// ambientOcclusion ) // || !textureon)
8195
+// {
8196
+// return; // false;
8197
+// }
8198
+//
8199
+// if (tex == null)
8200
+// {
8201
+// BindTexture(null,false,resolution);
8202
+// BindTexture(null,true,resolution);
8203
+// return;
8204
+// }
8205
+//
8206
+// String pigment = Object3D.GetPigment(tex);
8207
+// String bump = Object3D.GetBump(tex);
8208
+//
8209
+// usedtextures.add(pigment);
8210
+// usedtextures.add(bump);
8211
+//
8212
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8213
+// {
8214
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8215
+// // System.out.println("; bump = " + bump);
8216
+// }
8217
+//
8218
+// if (bump.equals(""))
8219
+// {
8220
+// bump = null;
8221
+// }
8222
+// if (pigment.equals(""))
8223
+// {
8224
+// pigment = null;
8225
+// }
8226
+//
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+// BindTexture(pigment, false, resolution);
8229
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8230
+// BindTexture(bump, true, resolution);
8231
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8232
+//
8233
+// return; // true;
8234
+
8235
+ BindPigmentTexture(tex, resolution);
8236
+ BindBumpTexture(tex, resolution);
8237
+ }
8238
+
8239
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
73588240 {
73598241 if (// DrawMode() != 0 || /*tex == null ||*/
73608242 ambientOcclusion ) // || !textureon)
....@@ -7365,17 +8247,47 @@
73658247 if (tex == null)
73668248 {
73678249 BindTexture(null,false,resolution);
7368
- BindTexture(null,true,resolution);
73698250 return;
73708251 }
73718252
73728253 String pigment = Object3D.GetPigment(tex);
8254
+
8255
+ usedtextures.add(tex);
8256
+
8257
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8258
+ {
8259
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8260
+ // System.out.println("; bump = " + bump);
8261
+ }
8262
+
8263
+ if (pigment.equals(""))
8264
+ {
8265
+ pigment = null;
8266
+ }
8267
+
8268
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8269
+ BindTexture(tex, false, resolution);
8270
+ }
8271
+
8272
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8273
+ {
8274
+ if (// DrawMode() != 0 || /*tex == null ||*/
8275
+ ambientOcclusion ) // || !textureon)
8276
+ {
8277
+ return; // false;
8278
+ }
8279
+
8280
+ if (tex == null)
8281
+ {
8282
+ BindTexture(null,true,resolution);
8283
+ return;
8284
+ }
8285
+
73738286 String bump = Object3D.GetBump(tex);
73748287
7375
- usedtextures.put(pigment, pigment);
7376
- usedtextures.put(bump, bump);
8288
+ usedtextures.add(tex);
73778289
7378
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8290
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
73798291 {
73808292 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
73818293 // System.out.println("; bump = " + bump);
....@@ -7385,43 +8297,94 @@
73858297 {
73868298 bump = null;
73878299 }
7388
- if (pigment.equals(""))
7389
- {
7390
- pigment = null;
7391
- }
73928300
7393
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7394
- BindTexture(pigment, false, resolution);
73958301 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7396
- BindTexture(bump, true, resolution);
8302
+ BindTexture(tex, true, resolution);
73978303 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7398
-
7399
- return; // true;
74008304 }
74018305
7402
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8306
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8307
+
8308
+ private boolean FileExists(String tex)
74038309 {
7404
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8310
+ if (missingTextures.contains(tex))
8311
+ {
8312
+ return false;
8313
+ }
8314
+
8315
+ boolean fileExists = new File(tex).exists();
8316
+
8317
+ if (!fileExists)
8318
+ {
8319
+ // If file exists, the "new File()" is not executed sgain
8320
+ missingTextures.add(tex);
8321
+ }
8322
+
8323
+ return fileExists;
8324
+ }
8325
+
8326
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8327
+ {
8328
+ CacheTexture texturecache = null;
74058329
74068330 if (tex != null)
74078331 {
7408
- String texname = tex;
8332
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8333
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
74098334
7410
- String[] split = tex.split("Textures");
7411
- if (split.length > 1)
7412
- texname = "/Users/nbriere/Textures" + split[split.length-1];
7413
- else
7414
- if (!texname.startsWith("/"))
7415
- texname = "/Users/nbriere/Textures/" + texname;
8335
+ if (texname.equals("") && texdata == null)
8336
+ {
8337
+ return null;
8338
+ }
8339
+
8340
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8341
+
8342
+// String[] split = tex.split("Textures");
8343
+// if (split.length > 1)
8344
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8345
+// else
8346
+// if (!texname.startsWith("/"))
8347
+// texname = "/Users/nbriere/Textures/" + texname;
8348
+ if (!FileExists(texname))
8349
+ {
8350
+ texname = fallbackTextureName;
8351
+ }
74168352
74178353 if (CACHETEXTURE)
7418
- texture = textures.get(texname); // TEXTURE CACHE
7419
-
7420
- TextureData texturedata = null;
7421
-
7422
- if (texture == null || texture.resolution < resolution)
74238354 {
7424
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8355
+ if (texdata == null)
8356
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8357
+ else
8358
+ texturecache = bimtextures.get(texdata);
8359
+ }
8360
+
8361
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8362
+ {
8363
+ TextureData texturedata = null;
8364
+
8365
+ if (texdata != null && textureon)
8366
+ {
8367
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8368
+
8369
+ try
8370
+ {
8371
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8372
+ }
8373
+ catch (Exception e)
8374
+ {
8375
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8376
+ }
8377
+
8378
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8379
+ bimtextures.put(texdata, texturecache);
8380
+
8381
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8382
+
8383
+ //Object bim2 = CreateBim(texturecache.texturedata);
8384
+ //bim2 = bim;
8385
+ }
8386
+ else
8387
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
74258388 {
74268389 assert(!bump);
74278390 // if (bump)
....@@ -7432,19 +8395,23 @@
74328395 // }
74338396 // else
74348397 // {
7435
- texture = textures.get(tex);
7436
- if (texture == null)
8398
+ // texturecache = textures.get(texname); // suspicious
8399
+ if (texturecache == null)
74378400 {
7438
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8401
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
74398402 }
8403
+ else
8404
+ new Exception().printStackTrace();
74408405 // }
74418406 } else
7442
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8407
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
74438408 {
74448409 assert(bump);
7445
- texture = textures.get(tex);
7446
- if (texture == null)
7447
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8410
+ // texturecache = textures.get(texname); // suspicious
8411
+ if (texturecache == null)
8412
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8413
+ else
8414
+ new Exception().printStackTrace();
74488415 } else
74498416 {
74508417 //if (tex.equals("IMMORTAL"))
....@@ -7452,11 +8419,13 @@
74528419 // texture = GetResourceTexture("default.png");
74538420 //} else
74548421 //{
7455
- if (tex.equals("WHITE_NOISE"))
8422
+ if (texname.endsWith("WHITE_NOISE"))
74568423 {
7457
- texture = textures.get(tex);
7458
- if (texture == null)
7459
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8424
+ // texturecache = textures.get(texname); // suspicious
8425
+ if (texturecache == null)
8426
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8427
+ else
8428
+ new Exception().printStackTrace();
74608429 } else
74618430 {
74628431 if (textureon)
....@@ -7481,7 +8450,7 @@
74818450 }
74828451
74838452 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7484
- if (!new File(cachename).exists())
8453
+ if (!FileExists(cachename))
74858454 cachename = texname;
74868455 else
74878456 processbump = false; // don't process bump map again
....@@ -7503,7 +8472,7 @@
75038472 }
75048473
75058474 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7506
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
75078476 cachename = texname;
75088477 else
75098478 processbump = false; // don't process bump map again
....@@ -7512,20 +8481,22 @@
75128481 texturedata = GetFileTexture(cachename, processbump, resolution);
75138482
75148483
7515
- if (texturedata != null)
7516
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8484
+ if (texturedata == null)
8485
+ throw new Exception();
8486
+
8487
+ texturecache = new CacheTexture(texturedata,resolution);
75178488 //texture = GetTexture(tex, bump);
75188489 }
75198490 }
75208491 //}
75218492 }
75228493
7523
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8494
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
75248495 {
75258496 //return false;
75268497
75278498 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7528
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8499
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
75298500 {
75308501 // String ext = "_highres";
75318502 // if (REDUCETEXTURE)
....@@ -7542,52 +8513,17 @@
75428513 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
75438514 if (!cachefile.exists())
75448515 {
7545
- // cache to disk
7546
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
7547
- //buffers[0].
7548
-
7549
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
7550
- int[] pixels = new int[bytebuf.capacity()/3];
7551
-
7552
- // squared size heuristic...
7553
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8516
+ //if (texturedata.getWidth() == texturedata.getHeight())
75548517 {
7555
- for (int i=pixels.length; --i>=0;)
7556
- {
7557
- int i3 = i*3;
7558
- pixels[i] = 0xFF;
7559
- pixels[i] <<= 8;
7560
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
7561
- pixels[i] <<= 8;
7562
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
7563
- pixels[i] <<= 8;
7564
- pixels[i] |= bytebuf.get(i3) & 0xFF;
7565
- }
7566
-
7567
- /*
7568
- int r=0,g=0,b=0,a=0;
7569
- for (int i=0; i<width; i++)
7570
- for (int j=0; j<height; j++)
7571
- {
7572
- int index = j*width+i;
7573
- int p = pixels[index];
7574
- a = ((p>>24) & 0xFF);
7575
- r = ((p>>16) & 0xFF);
7576
- g = ((p>>8) & 0xFF);
7577
- b = (p & 0xFF);
7578
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
7579
- }
7580
- /**/
7581
- int width = (int)Math.sqrt(pixels.length); // squared
7582
- int height = width;
7583
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
7584
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8518
+ BufferedImage rendImage = CreateBim(texturedata);
8519
+
75858520 ImageWriter writer = null;
75868521 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
75878522 if (iter.hasNext()) {
75888523 writer = (ImageWriter)iter.next();
75898524 }
7590
- float compressionQuality = 0.9f;
8525
+
8526
+ float compressionQuality = 0.85f;
75918527 try
75928528 {
75938529 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7604,18 +8540,20 @@
76048540 }
76058541 }
76068542 }
7607
-
8543
+
8544
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8545
+
76088546 //System.out.println("Texture = " + tex);
7609
- if (textures.containsKey(texname))
8547
+ if (textures.containsKey(tex))
76108548 {
7611
- CacheTexture thetex = textures.get(texname);
8549
+ CacheTexture thetex = textures.get(tex);
76128550 thetex.texture.disable();
76138551 thetex.texture.dispose();
7614
- textures.remove(texname);
8552
+ textures.remove(tex);
76158553 }
76168554
7617
- texture.texturedata = texturedata;
7618
- textures.put(texname, texture);
8555
+ //texture.texturedata = texturedata;
8556
+ textures.put(tex, texturecache);
76198557
76208558 // newtex = true;
76218559 }
....@@ -7631,10 +8569,44 @@
76318569 }
76328570 }
76338571
7634
- return texture;
8572
+ return texturecache;
76358573 }
76368574
7637
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8575
+ static void EmbedTextures(cTexture tex)
8576
+ {
8577
+ if (tex.pigmentdata == null)
8578
+ {
8579
+ //String texname = Object3D.GetPigment(tex);
8580
+
8581
+ CacheTexture texturecache = texturepigment.get(tex);
8582
+
8583
+ if (texturecache != null)
8584
+ {
8585
+ tex.pw = texturecache.texturedata.getWidth();
8586
+ tex.ph = texturecache.texturedata.getHeight();
8587
+ tex.pigmentdata = //CompressJPEG(CreateBim
8588
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8589
+ ;
8590
+ //, tex.pw, tex.ph), 0.5f);
8591
+ }
8592
+ }
8593
+
8594
+ if (tex.bumpdata == null)
8595
+ {
8596
+ //String texname = Object3D.GetBump(tex);
8597
+
8598
+ CacheTexture texturecache = texturebump.get(tex);
8599
+
8600
+ if (texturecache != null)
8601
+ {
8602
+ tex.bw = texturecache.texturedata.getWidth();
8603
+ tex.bh = texturecache.texturedata.getHeight();
8604
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8605
+ }
8606
+ }
8607
+ }
8608
+
8609
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
76388610 {
76398611 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
76408612
....@@ -7652,21 +8624,21 @@
76528624 return texture!=null?texture.texture:null;
76538625 }
76548626
7655
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8627
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
76568628 {
76578629 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
76588630
76598631 return texture!=null?texture.texturedata:null;
76608632 }
76618633
7662
- boolean BindTexture(String tex, boolean bump, int resolution)
8634
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
76638635 {
76648636 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
76658637 {
76668638 return false;
76678639 }
76688640
7669
- boolean newtex = false;
8641
+ //boolean newtex = false;
76708642
76718643 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
76728644
....@@ -7698,9 +8670,75 @@
76988670 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
76998671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
77008672
7701
- return newtex;
8673
+ return true; // Warning: not used.
77028674 }
77038675
8676
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8677
+ {
8678
+ try
8679
+ {
8680
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8681
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8682
+ ImageWriter writer = writers.next();
8683
+
8684
+ ImageWriteParam param = writer.getDefaultWriteParam();
8685
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8686
+ param.setCompressionQuality(quality);
8687
+
8688
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8689
+ writer.setOutput(ios);
8690
+ writer.write(null, new IIOImage(image, null, null), param);
8691
+
8692
+ byte[] data = baos.toByteArray();
8693
+ writer.dispose();
8694
+ return data;
8695
+ }
8696
+ catch (Exception e)
8697
+ {
8698
+ e.printStackTrace();
8699
+ return null;
8700
+ }
8701
+ }
8702
+
8703
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8704
+ {
8705
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8706
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8707
+ ImageReader reader = writers.next();
8708
+
8709
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8710
+
8711
+ ImageReadParam param = reader.getDefaultReadParam();
8712
+ param.setDestination(bim);
8713
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8714
+
8715
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8716
+ reader.setInput(ios);
8717
+ BufferedImage bim2 = reader.read(0, param);
8718
+ reader.dispose();
8719
+
8720
+// WritableRaster raster = bim2.getRaster();
8721
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8722
+// byte[] bytes = data.getData();
8723
+//
8724
+// int[] pixels = new int[bytes.length/3];
8725
+// for (int i=pixels.length; --i>=0;)
8726
+// {
8727
+// int i3 = i*3;
8728
+// pixels[i] = 0xFF;
8729
+// pixels[i] <<= 8;
8730
+// pixels[i] |= bytes[i3+2] & 0xFF;
8731
+// pixels[i] <<= 8;
8732
+// pixels[i] |= bytes[i3+1] & 0xFF;
8733
+// pixels[i] <<= 8;
8734
+// pixels[i] |= bytes[i3] & 0xFF;
8735
+// }
8736
+//
8737
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8738
+
8739
+ return bim;
8740
+ }
8741
+
77048742 ShadowBuffer shadowPBuf;
77058743 AntialiasBuffer antialiasPBuf;
77068744 int MAXSTACK;
....@@ -8536,11 +9574,35 @@
85369574 jy8[3] = 0.5f;
85379575 }
85389576
8539
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9577
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
85409578 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
85419579 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
85429580 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
85439581
9582
+ void ResetOptions()
9583
+ {
9584
+ options1[0] = 100;
9585
+ options1[1] = 0.025f;
9586
+ options1[2] = 0.01f;
9587
+ options1[3] = 0;
9588
+ options1[4] = 0;
9589
+
9590
+ options2[0] = 0;
9591
+ options2[1] = 0.75f;
9592
+ options2[2] = 0;
9593
+ options2[3] = 0;
9594
+
9595
+ options3[0] = 1;
9596
+ options3[1] = 1;
9597
+ options3[2] = 1;
9598
+ options3[3] = 0;
9599
+
9600
+ options4[0] = 1;
9601
+ options4[1] = 0;
9602
+ options4[2] = 1;
9603
+ options4[3] = 0;
9604
+ }
9605
+
85449606 static int imagecount = 0; // movie generation
85459607
85469608 static int jitter = 0;
....@@ -8636,8 +9698,8 @@
86369698 assert (parentcam != renderCamera);
86379699
86389700 if (renderCamera != lightCamera)
8639
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8640
- LA.matConcat(matrix, parentcam.toParent, matrix);
9701
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
86419703
86429704 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
86439705
....@@ -8652,8 +9714,8 @@
86529714 LA.matCopy(renderCamera.fromScreen, matrix);
86539715
86549716 if (renderCamera != lightCamera)
8655
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8656
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9717
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
86579719
86589720 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
86599721
....@@ -8725,7 +9787,7 @@
87259787 //gl.glFlush();
87269788 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
87279789
8728
- if (ANIMATION && ABORTED)
9790
+ if (Globals.ANIMATION && ABORTED)
87299791 {
87309792 System.err.println(" ABORTED FRAME");
87319793 break;
....@@ -8755,7 +9817,7 @@
87559817 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
87569818
87579819 // save image
8758
- if (ANIMATION && !ABORTED)
9820
+ if (Globals.ANIMATION && !ABORTED)
87599821 {
87609822 VPwidth = viewport[2];
87619823 VPheight = viewport[3];
....@@ -8866,11 +9928,11 @@
88669928
88679929 // imagecount++;
88689930
8869
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9931
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
88709932
88719933 if (!BOXMODE)
88729934 {
8873
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9935
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
88749936 }
88759937
88769938 if (!BOXMODE)
....@@ -8908,7 +9970,7 @@
89089970 ABORTED = false;
89099971 }
89109972 else
8911
- GrafreeD.wav.cursor += 735 * ACSIZE;
9973
+ Grafreed.wav.cursor += 735 * ACSIZE;
89129974
89139975 if (false)
89149976 {
....@@ -9571,11 +10633,11 @@
957110633
957210634 public void display(GLAutoDrawable drawable)
957310635 {
9574
- if (GrafreeD.savesound && GrafreeD.hassound)
10636
+ if (Grafreed.savesound && Grafreed.hassound)
957510637 {
9576
- GrafreeD.wav.save();
9577
- GrafreeD.savesound = false;
9578
- GrafreeD.hassound = false;
10638
+ Grafreed.wav.save();
10639
+ Grafreed.savesound = false;
10640
+ Grafreed.hassound = false;
957910641 }
958010642 // if (DEBUG_SELECTION)
958110643 // {
....@@ -9651,6 +10713,7 @@
965110713 ANTIALIAS = 0;
965210714 //System.out.println("RESTART");
965310715 AAtimer.restart();
10716
+ Globals.TIMERRUNNING = true;
965410717 }
965510718 }
965610719 }
....@@ -9705,7 +10768,7 @@
970510768 Object3D theobject = object;
970610769 Object3D theparent = object.parent;
970710770 object.parent = null;
9708
- object = (Object3D)GrafreeD.clone(object);
10771
+ object = (Object3D)Grafreed.clone(object);
970910772 object.Stripify();
971010773 if (theobject.selection == null || theobject.selection.Size() == 0)
971110774 theobject.PreprocessOcclusion(this);
....@@ -9718,13 +10781,14 @@
971810781 ambientOcclusion = false;
971910782 }
972010783
9721
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10784
+ if (//Globals.lighttouched &&
10785
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
972210786 {
972310787 //if (RENDERSHADOW) // ?
972410788 if (!IsFrozen())
972510789 {
972610790 // dec 2012
9727
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10791
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
972810792 {
972910793 Globals.framecount++;
973010794 shadowbuffer.display();
....@@ -9851,8 +10915,8 @@
985110915
985210916 // if (parentcam != renderCamera) // not a light
985310917 if (cam != lightCamera)
9854
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9855
- LA.matConcat(matrix, parentcam.toParent, matrix);
10918
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
985610920
985710921 for (int j = 0; j < 4; j++)
985810922 {
....@@ -9866,8 +10930,8 @@
986610930
986710931 // if (parentcam != renderCamera) // not a light
986810932 if (cam != lightCamera)
9869
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9870
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10933
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
987110935
987210936 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
987310937
....@@ -10126,7 +11190,16 @@
1012611190 // Bump noise
1012711191 gl.glActiveTexture(GL.GL_TEXTURE6);
1012811192 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10129
- BindTexture(NOISE_TEXTURE, false, 2);
11193
+
11194
+ try
11195
+ {
11196
+ BindTexture(NOISE_TEXTURE, false, 2);
11197
+ }
11198
+ catch (Exception e)
11199
+ {
11200
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11201
+ }
11202
+
1013011203
1013111204 gl.glActiveTexture(GL.GL_TEXTURE0);
1013211205 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10149,9 +11222,9 @@
1014911222
1015011223 gl.glMatrixMode(GL.GL_MODELVIEW);
1015111224
10152
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10153
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10154
-//gl.glEnable(gl.GL_MULTISAMPLE);
11225
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11226
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11227
+gl.glEnable(gl.GL_MULTISAMPLE);
1015511228 } else
1015611229 {
1015711230 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10162,7 +11235,7 @@
1016211235 //System.out.println("BLENDING ON");
1016311236 gl.glEnable(GL.GL_BLEND);
1016411237 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10165
-
11238
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1016611239 gl.glMatrixMode(gl.GL_PROJECTION);
1016711240 gl.glLoadIdentity();
1016811241
....@@ -10251,8 +11324,8 @@
1025111324 System.err.println("parentcam != renderCamera");
1025211325
1025311326 // if (cam != lightCamera)
10254
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10255
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11327
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11328
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1025611329 }
1025711330
1025811331 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10273,8 +11346,8 @@
1027311346 if (true) // TODO
1027411347 {
1027511348 if (cam != lightCamera)
10276
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10277
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11349
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11350
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1027811351 }
1027911352
1028011353 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10340,7 +11413,7 @@
1034011413 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
1034111414 //System.out.println("fragmentMode = " + fragmentMode);
1034211415
10343
- if (DrawMode() == DEFAULT || DrawMode() == SELECTION || DEBUG_SELECTION)
11416
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
1034411417 {
1034511418 /*
1034611419 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -10411,7 +11484,7 @@
1041111484 }
1041211485 }
1041311486
10414
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11487
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1041511488 {
1041611489 //gl.glDepthFunc(GL.GL_LEQUAL);
1041711490 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10419,24 +11492,21 @@
1041911492
1042011493 boolean texon = textureon;
1042111494
10422
- if (RENDERPROGRAM > 0)
10423
- {
10424
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10425
- textureon = false;
10426
- }
11495
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11496
+ textureon = false;
11497
+
1042711498 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1042811499 //System.out.println("ALLO");
1042911500 gl.glColorMask(false, false, false, false);
1043011501 DrawObject(gl);
10431
- if (RENDERPROGRAM > 0)
10432
- {
10433
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10434
- textureon = texon;
10435
- }
11502
+
11503
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11504
+ textureon = texon;
11505
+
1043611506 gl.glColorMask(true, true, true, true);
1043711507
1043811508 gl.glDepthFunc(GL.GL_EQUAL);
10439
- //gl.glDepthMask(false);
11509
+ gl.glDepthMask(false);
1044011510 }
1044111511
1044211512 if (false) // DrawMode() == SHADOW)
....@@ -10590,8 +11660,14 @@
1059011660 {
1059111661 renderpass++;
1059211662 // System.out.println("Draw object... ");
11663
+ STEP = 1;
1059311664 if (FAST) // in case there is no script
10594
- STEP = 16;
11665
+ STEP = 8;
11666
+
11667
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11668
+ {
11669
+ STEP *= 4;
11670
+ }
1059511671
1059611672 //object.FullInvariants();
1059711673
....@@ -10605,23 +11681,44 @@
1060511681 e.printStackTrace();
1060611682 }
1060711683
10608
- if (GrafreeD.RENDERME > 0)
10609
- GrafreeD.RENDERME--; // mechante magouille
11684
+ if (Grafreed.RENDERME > 0)
11685
+ Grafreed.RENDERME--; // mechante magouille
1061011686
1061111687 Globals.ONESTEP = false;
1061211688 }
1061311689
1061411690 static boolean zoomonce = false;
1061511691
11692
+ static void CreateSelectedPoint()
11693
+ {
11694
+ if (selectedpoint == null)
11695
+ {
11696
+ debugpointG = new Sphere();
11697
+ debugpointP = new Sphere();
11698
+ debugpointC = new Sphere();
11699
+ debugpointR = new Sphere();
11700
+
11701
+ selectedpoint = new Superellipsoid();
11702
+
11703
+ for (int i=0; i<8; i++)
11704
+ {
11705
+ debugpoints[i] = new Sphere();
11706
+ }
11707
+ }
11708
+ }
11709
+
1061611710 void DrawObject(GL gl, boolean draw)
1061711711 {
11712
+ // To clear camera values
11713
+ ResetOptions();
11714
+
1061811715 //System.out.println("DRAW OBJECT " + mouseDown);
1061911716 // DrawMode() = SELECTION;
1062011717 //GL gl = getGL();
1062111718 if ((TRACK || SHADOWTRACK) || zoomonce)
1062211719 {
1062311720 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10624
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11721
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1062511722 pingthread.StepToTarget(true); // true);
1062611723 // zoomonce = false;
1062711724 }
....@@ -10641,7 +11738,7 @@
1064111738 callist = gl.glGenLists(1);
1064211739 }
1064311740
10644
- boolean selectmode = DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
11741
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
1064511742
1064611743 boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
1064711744
....@@ -10676,7 +11773,14 @@
1067611773
1067711774 usedtextures.clear();
1067811775
10679
- BindTextures(DEFAULT_TEXTURES, 2);
11776
+ try
11777
+ {
11778
+ BindTextures(DEFAULT_TEXTURES, 2);
11779
+ }
11780
+ catch (Exception e)
11781
+ {
11782
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11783
+ }
1068011784 }
1068111785 //System.out.println("--> " + stackdepth);
1068211786 // GrafreeD.traceon();
....@@ -10686,8 +11790,9 @@
1068611790
1068711791 if (DrawMode() == DEFAULT)
1068811792 {
10689
- if (DEBUG)
11793
+ if (Globals.DEBUG)
1069011794 {
11795
+ CreateSelectedPoint();
1069111796 float radius = 0.05f;
1069211797 if (selectedpoint.radius != radius)
1069311798 {
....@@ -10741,20 +11846,32 @@
1074111846 ReleaseTextures(DEFAULT_TEXTURES);
1074211847
1074311848 if (CLEANCACHE)
10744
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11849
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1074511850 {
10746
- String tex = e.nextElement();
11851
+ cTexture tex = e.nextElement();
1074711852
1074811853 // System.out.println("Texture --------- " + tex);
1074911854
10750
- if (tex.equals("WHITE_NOISE"))
11855
+ if (tex.equals("WHITE_NOISE:"))
1075111856 continue;
1075211857
10753
- if (!usedtextures.containsKey(tex))
11858
+ if (!usedtextures.contains(tex))
1075411859 {
11860
+ CacheTexture gettex = texturepigment.get(tex);
1075511861 // System.out.println("DISPOSE +++++++++++++++ " + tex);
10756
- textures.get(tex).texture.dispose();
10757
- textures.remove(tex);
11862
+ if (gettex != null)
11863
+ {
11864
+ gettex.texture.dispose();
11865
+ texturepigment.remove(tex);
11866
+ }
11867
+
11868
+ gettex = texturebump.get(tex);
11869
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11870
+ if (gettex != null)
11871
+ {
11872
+ gettex.texture.dispose();
11873
+ texturebump.remove(tex);
11874
+ }
1075811875 }
1075911876 }
1076011877 }
....@@ -10767,7 +11884,14 @@
1076711884 if (checker != null && DrawMode() == DEFAULT)
1076811885 {
1076911886 //BindTexture(IMMORTAL_TEXTURE);
10770
- BindTextures(checker.GetTextures(), checker.texres);
11887
+ try
11888
+ {
11889
+ BindTextures(checker.GetTextures(), checker.texres);
11890
+ }
11891
+ catch (Exception e)
11892
+ {
11893
+ System.err.println("FAILED: " + checker.GetTextures());
11894
+ }
1077111895 // NEAREST
1077211896 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1077311897 DrawChecker(gl);
....@@ -10849,7 +11973,7 @@
1084911973 return;
1085011974 }
1085111975
10852
- String string = obj.GetToolTip();
11976
+ String string = obj.toString(); //.GetToolTip();
1085311977
1085411978 GL gl = GetGL();
1085511979
....@@ -11166,8 +12290,8 @@
1116612290 //obj.TransformToWorld(light, light);
1116712291 for (int i = tp.size(); --i >= 0;)
1116812292 {
11169
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11170
- LA.xformPos(light, tp.get(i).toParent, light);
12293
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12294
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1117112295 }
1117212296
1117312297
....@@ -11184,8 +12308,8 @@
1118412308 parentcam = cameras[0];
1118512309 }
1118612310
11187
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11188
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12311
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12312
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1118912313
1119012314 LA.xformPos(light, renderCamera.toScreen, light);
1119112315
....@@ -11799,8 +12923,8 @@
1179912923
1180012924 // display shadow only (bump == 0)
1180112925 "SUB temp.x, half.x, shadow.x;" +
11802
- "MOV temp.y, -params6.x;" +
11803
- "SLT temp.z, temp.y, zero.x;" +
12926
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12927
+ "SLT temp.z, temp.y, -one2048th.x;" +
1180412928 "SUB temp.y, one.x, temp.z;" +
1180512929 "MUL temp.x, temp.x, temp.y;" +
1180612930 "KIL temp.x;" +
....@@ -11929,8 +13053,10 @@
1192913053 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1193013054
1193113055 "SUB temp.x, one.x, ndotl.x;" +
11932
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
11933
- "ADD temp.y, one.y, options2.y;" + // sursurface
13056
+ // Tuning for default skin
13057
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13058
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13059
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1193413060 "MUL temp.x, temp.x, temp.y;" +
1193513061
1193613062 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12129,7 +13255,7 @@
1212913255 //once = true;
1213013256 }
1213113257
12132
- System.out.print("Program #" + mode + "; length = " + program.length());
13258
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1213313259 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1213413260 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1213513261
....@@ -12262,12 +13388,16 @@
1226213388
1226313389 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1226413390 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13391
+
13392
+ // Compare fragment depth in light space with shadowmap.
1226513393 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1226613394 "SGE temp.y, temp.x, zero.x;" +
12267
- "SUB " + shadow + ".y, one.x, temp.y;" +
13395
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13396
+
13397
+ // Reverse comparison
1226813398 "SUB temp.x, one.x, temp.x;" +
1226913399 "MUL " + shadow + ".x, temp.x, temp.y;" +
12270
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13400
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1227113401 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1227213402
1227313403 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12281,6 +13411,10 @@
1228113411 // No shadow for backface
1228213412 "DP3 temp.x, normal, lightd;" +
1228313413 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13414
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13415
+
13416
+ // No shadow when out of frustrum
13417
+ "SGE temp.x, " + depth + ".z, one.z;" +
1228413418 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1228513419 "";
1228613420 }
....@@ -12427,7 +13561,8 @@
1242713561 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1242813562 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1242913563 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12430
- Object3D.cVector2[] vector2buffer;
13564
+
13565
+ //Object3D.cVector2[] vector2buffer;
1243113566
1243213567 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1243313568 // OUT : diff, spec
....@@ -12443,9 +13578,10 @@
1244313578 "DP3 " + dest + ".z," + "normals," + "eye;" +
1244413579 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1244513580 //"MOV " + dest + ".w," + "normal.z;" +
12446
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
12447
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
12448
- //"MOV " + dest + ".z," + "params2.w;" +
13581
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13582
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13583
+
13584
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1244913585 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1245013586 "RCP " + dest + ".w," + dest + ".w;" +
1245113587 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -12839,7 +13975,7 @@
1283913975 public void mousePressed(MouseEvent e)
1284013976 {
1284113977 //System.out.println("mousePressed: " + e);
12842
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
13978
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1284313979 }
1284413980
1284513981 static long prevtime = 0;
....@@ -12866,6 +14002,7 @@
1286614002
1286714003 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1286814004
14005
+ if (BUTTONLESSWHEEL)
1286914006 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1287014007 {
1287114008 return;
....@@ -12874,7 +14011,7 @@
1287414011 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1287514012
1287614013 // TIMER
12877
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14014
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1287814015 {
1287914016 keepboxmode = BOXMODE;
1288014017 keepsupport = SUPPORT;
....@@ -12914,8 +14051,8 @@
1291414051 // mode |= META;
1291514052 //}
1291614053
12917
- SetMouseMode(WHEEL | e.getModifiersEx());
12918
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14054
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14055
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1291914056 anchorX = ax;
1292014057 anchorY = ay;
1292114058 prevX = px;
....@@ -12949,6 +14086,7 @@
1294914086 else
1295014087 if (evt.getSource() == AAtimer)
1295114088 {
14089
+ Globals.TIMERRUNNING = false;
1295214090 if (mouseDown)
1295314091 {
1295414092 //new Exception().printStackTrace();
....@@ -12974,6 +14112,10 @@
1297414112 // LIVE = waslive;
1297514113 // wasliveok = true;
1297614114 // waslive = false;
14115
+
14116
+ // May 2019 Forget it:
14117
+ if (true)
14118
+ return;
1297714119
1297814120 // source == timer
1297914121 if (mouseDown)
....@@ -13004,7 +14146,7 @@
1300414146
1300514147 // fev 2014???
1300614148 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13007
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14149
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1300814150 pingthread.StepToTarget(true); // true);
1300914151 }
1301014152 // if (!LIVE)
....@@ -13013,12 +14155,13 @@
1301314155
1301414156 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1301514157
13016
- void clickStart(int x, int y, int modifiers)
14158
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1301714159 {
1301814160 if (!wasliveok)
1301914161 return;
1302014162
1302114163 AAtimer.restart(); //
14164
+ Globals.TIMERRUNNING = true;
1302214165
1302314166 // waslive = LIVE;
1302414167 // LIVE = false;
....@@ -13030,7 +14173,7 @@
1303014173 // touched = true; // main DL
1303114174 if (isRenderer)
1303214175 {
13033
- SetMouseMode(modifiers);
14176
+ SetMouseMode(modifiers, modifiersex);
1303414177 }
1303514178
1303614179 selectX = anchorX = x;
....@@ -13043,7 +14186,7 @@
1304314186 clicked = true;
1304414187 hold = false;
1304514188
13046
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14189
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1304714190 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1304814191 {
1304914192 // System.out.println("RESTART II " + modifiers);
....@@ -13074,7 +14217,7 @@
1307414217 info.camera = renderCamera;
1307514218 info.x = x;
1307614219 info.y = y;
13077
- info.modifiers = modifiers;
14220
+ info.modifiers = modifiersex;
1307814221 editObj = object.doEditClick(info, 0);
1307914222 if (!editObj)
1308014223 {
....@@ -13091,11 +14234,14 @@
1309114234
1309214235 public void mouseDragged(MouseEvent e)
1309314236 {
14237
+ Globals.MOUSEDRAGGED = true;
14238
+
14239
+ //System.out.println("mouseDragged: " + e);
1309414240 if (isRenderer)
1309514241 movingcamera = true;
14242
+
1309614243 //if (drawing)
1309714244 //return;
13098
- //System.out.println("mouseDragged: " + e);
1309914245 if ((e.getModifiersEx() & CTRL) != 0
1310014246 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1310114247 {
....@@ -13103,7 +14249,7 @@
1310314249 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1310414250 }
1310514251 else
13106
- drag(e.getX(), e.getY(), e.getModifiersEx());
14252
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1310714253
1310814254 //try { Thread.sleep(1); } catch (Exception ex) {}
1310914255 }
....@@ -13115,6 +14261,11 @@
1311514261 cVector tmp = new cVector();
1311614262 cVector tmp2 = new cVector();
1311714263 boolean isMoving;
14264
+
14265
+ public cVector TargetLookAt()
14266
+ {
14267
+ return targetLookAt;
14268
+ }
1311814269
1311914270 class PingThread extends Thread
1312014271 {
....@@ -13271,6 +14422,7 @@
1327114422
1327214423 public void run()
1327314424 {
14425
+ new Exception().printStackTrace();
1327414426 System.exit(0);
1327514427 for (;;)
1327614428 {
....@@ -13334,7 +14486,7 @@
1333414486 {
1333514487 Globals.lighttouched = true;
1333614488 }
13337
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14489
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1333814490 }
1333914491 //else
1334014492 }
....@@ -13348,12 +14500,12 @@
1334814500 void GoDown(int mod)
1334914501 {
1335014502 MODIFIERS |= COMMAND;
13351
- /*
14503
+ /**/
1335214504 if((mod&SHIFT) == SHIFT)
1335314505 manipCamera.RotatePosition(0, -speed);
1335414506 else
13355
- manipCamera.BackForth(0, -speed*delta, getWidth());
13356
- */
14507
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14508
+ /**/
1335714509 if ((mod & SHIFT) == SHIFT)
1335814510 {
1335914511 mouseMode = mouseMode; // VR??
....@@ -13369,12 +14521,12 @@
1336914521 void GoUp(int mod)
1337014522 {
1337114523 MODIFIERS |= COMMAND;
13372
- /*
14524
+ /**/
1337314525 if((mod&SHIFT) == SHIFT)
1337414526 manipCamera.RotatePosition(0, speed);
1337514527 else
13376
- manipCamera.BackForth(0, speed*delta, getWidth());
13377
- */
14528
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14529
+ /**/
1337814530 if ((mod & SHIFT) == SHIFT)
1337914531 {
1338014532 mouseMode = mouseMode;
....@@ -13390,12 +14542,12 @@
1339014542 void GoLeft(int mod)
1339114543 {
1339214544 MODIFIERS |= COMMAND;
13393
- /*
14545
+ /**/
1339414546 if((mod&SHIFT) == SHIFT)
13395
- manipCamera.RotatePosition(speed, 0);
13396
- else
1339714547 manipCamera.Translate(speed*delta, 0, getWidth());
13398
- */
14548
+ else
14549
+ manipCamera.RotatePosition(speed, 0);
14550
+ /**/
1339914551 if ((mod & SHIFT) == SHIFT)
1340014552 {
1340114553 mouseMode = mouseMode;
....@@ -13411,12 +14563,12 @@
1341114563 void GoRight(int mod)
1341214564 {
1341314565 MODIFIERS |= COMMAND;
13414
- /*
14566
+ /**/
1341514567 if((mod&SHIFT) == SHIFT)
13416
- manipCamera.RotatePosition(-speed, 0);
13417
- else
1341814568 manipCamera.Translate(-speed*delta, 0, getWidth());
13419
- */
14569
+ else
14570
+ manipCamera.RotatePosition(-speed, 0);
14571
+ /**/
1342014572 if ((mod & SHIFT) == SHIFT)
1342114573 {
1342214574 mouseMode = mouseMode;
....@@ -13434,7 +14586,7 @@
1343414586 int X, Y;
1343514587 boolean SX, SY;
1343614588
13437
- void drag(int x, int y, int modifiers)
14589
+ void drag(int x, int y, int modifiers, int modifiersex)
1343814590 {
1343914591 if (IsFrozen())
1344014592 {
....@@ -13443,17 +14595,17 @@
1344314595
1344414596 drag = true; // NEW
1344514597
13446
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14598
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1344714599
1344814600 X = x;
1344914601 Y = y;
1345014602 // floating state for animation
13451
- MODIFIERS = modifiers;
13452
- modifiers &= ~1024;
14603
+ MODIFIERS = modifiersex;
14604
+ modifiersex &= ~1024;
1345314605 if (false) // modifiers != 0)
1345414606 {
1345514607 //new Exception().printStackTrace();
13456
- System.out.println("mouseDragged: " + modifiers);
14608
+ System.out.println("mouseDragged: " + modifiersex);
1345714609 System.out.println("SHIFT = " + SHIFT);
1345814610 System.out.println("CONTROL = " + COMMAND);
1345914611 System.out.println("META = " + META);
....@@ -13473,7 +14625,8 @@
1347314625 info.camera = renderCamera;
1347414626 info.x = x;
1347514627 info.y = y;
13476
- object.editWindow.copy.doEditDrag(info);
14628
+ object.GetWindow().copy
14629
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1347714630 } else
1347814631 {
1347914632 if (x < startX)
....@@ -13625,7 +14778,6 @@
1362514778 public void mouseMoved(MouseEvent e)
1362614779 {
1362714780 //System.out.println("mouseMoved: " + e);
13628
-
1362914781 if (isRenderer)
1363014782 return;
1363114783
....@@ -13638,7 +14790,9 @@
1363814790 ci.camera = renderCamera;
1363914791 if (!isRenderer)
1364014792 {
13641
- if (object.editWindow.copy.doEditClick(ci, 0))
14793
+ //ObjEditor editWindow = object.editWindow;
14794
+ //Object3D copy = editWindow.copy;
14795
+ if (object.doEditClick(ci, 0))
1364214796 {
1364314797 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1364414798 } else
....@@ -13650,7 +14804,11 @@
1365014804
1365114805 public void mouseReleased(MouseEvent e)
1365214806 {
14807
+ Globals.MOUSEDRAGGED = false;
14808
+
1365314809 movingcamera = false;
14810
+ X = 0; // getBounds().width/2;
14811
+ Y = 0; // getBounds().height/2;
1365414812 //System.out.println("mouseReleased: " + e);
1365514813 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1365614814 }
....@@ -13673,9 +14831,9 @@
1367314831 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1367414832 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1367514833
13676
- if (control || command || IsFrozen())
14834
+// No delay if (control || command || IsFrozen())
1367714835 timeout = true;
13678
- else
14836
+// ?? May 2019 else
1367914837 // timer.setDelay((modifiers & 128) != 0?0:350);
1368014838 mouseDown = false;
1368114839 if (!control && !command) // june 2013
....@@ -13785,7 +14943,7 @@
1378514943 System.out.println("keyReleased: " + e);
1378614944 }
1378714945
13788
- void SetMouseMode(int modifiers)
14946
+ void SetMouseMode(int modifiers, int modifiersex)
1378914947 {
1379014948 //System.out.println("SetMouseMode = " + modifiers);
1379114949 //modifiers &= ~1024;
....@@ -13797,25 +14955,25 @@
1379714955 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1379814956 // return;
1379914957 //System.out.println("SetMode = " + modifiers);
13800
- if ((modifiers & WHEEL) == WHEEL)
14958
+ if ((modifiersex & WHEEL) == WHEEL)
1380114959 {
1380214960 mouseMode |= ZOOM;
1380314961 }
1380414962
1380514963 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
13806
- if (capsLocked || (modifiers & META) == META)
14964
+ if (capsLocked) // || (modifiers & META) == META)
1380714965 {
1380814966 mouseMode |= VR; // BACKFORTH;
1380914967 }
13810
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
14968
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1381114969 {
1381214970 mouseMode |= SELECT;
1381314971 }
13814
- if ((modifiers & COMMAND) == COMMAND)
14972
+ if ((modifiersex & COMMAND) == COMMAND)
1381514973 {
1381614974 mouseMode |= SELECT;
1381714975 }
13818
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
14976
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1381914977 {
1382014978 mouseMode &= ~VR;
1382114979 mouseMode |= TRANSLATE;
....@@ -13844,10 +15002,10 @@
1384415002
1384515003 if (isRenderer) //
1384615004 {
13847
- SetMouseMode(modifiers);
15005
+ SetMouseMode(0, modifiers);
1384815006 }
1384915007
13850
- theRenderer.keyPressed(key);
15008
+ Globals.theRenderer.keyPressed(key);
1385115009 }
1385215010
1385315011 int kompactbit = 4; // power bit
....@@ -13859,7 +15017,7 @@
1385915017 float SATPOW = 1; // 2; // 0.5f;
1386015018 float BRIPOW = 1; // 0.5f; // 0.5f;
1386115019
13862
- void keyPressed(int key)
15020
+ public void keyPressed(int key)
1386315021 {
1386415022 if (key >= '0' && key <= '5')
1386515023 clampbit = (key-'0');
....@@ -13906,7 +15064,8 @@
1390615064 // break;
1390715065 case 'T':
1390815066 CACHETEXTURE ^= true;
13909
- textures.clear();
15067
+ texturepigment.clear();
15068
+ texturebump.clear();
1391015069 // repaint();
1391115070 break;
1391215071 case 'Y':
....@@ -13991,7 +15150,9 @@
1399115150 case 'E' : COMPACT ^= true;
1399215151 repaint();
1399315152 break;
13994
- case 'W' : DEBUGHSB ^= true;
15153
+ case 'W' : // Wide Window (fullscreen)
15154
+ //DEBUGHSB ^= true;
15155
+ ObjEditor.theFrame.ToggleFullScreen();
1399515156 repaint();
1399615157 break;
1399715158 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14016,8 +15177,8 @@
1401615177 RevertCamera();
1401715178 repaint();
1401815179 break;
14019
- case 'L':
1402015180 case 'l':
15181
+ //case 'L':
1402115182 if (lightMode)
1402215183 {
1402315184 lightMode = false;
....@@ -14160,9 +15321,9 @@
1416015321 case '_':
1416115322 kompactbit = 5;
1416215323 break;
14163
- case '+':
14164
- kompactbit = 6;
14165
- break;
15324
+// case '+':
15325
+// kompactbit = 6;
15326
+// break;
1416615327 case ' ':
1416715328 lightMode ^= true;
1416815329 Globals.lighttouched = true;
....@@ -14174,13 +15335,14 @@
1417415335 case ESC:
1417515336 RENDERPROGRAM += 1;
1417615337 RENDERPROGRAM %= 3;
15338
+
1417715339 repaint();
1417815340 break;
1417915341 case 'Z':
1418015342 //RESIZETEXTURE ^= true;
1418115343 //break;
1418215344 case 'z':
14183
- RENDERSHADOW ^= true;
15345
+ Globals.RENDERSHADOW ^= true;
1418415346 Globals.lighttouched = true;
1418515347 repaint();
1418615348 break;
....@@ -14213,8 +15375,9 @@
1421315375 case DELETE:
1421415376 ClearSelection();
1421515377 break;
14216
- /*
1421715378 case '+':
15379
+
15380
+ /*
1421815381 //fontsize += 1;
1421915382 bbzoom *= 2;
1422015383 repaint();
....@@ -14231,17 +15394,17 @@
1423115394 case '=':
1423215395 IncDepth();
1423315396 //fontsize += 1;
14234
- object.editWindow.refreshContents(true);
15397
+ object.GetWindow().refreshContents(true);
1423515398 maskbit = 6;
1423615399 break;
1423715400 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1423815401 DecDepth();
1423915402 maskbit = 5;
1424015403 //if(fontsize > 1) fontsize -= 1;
14241
- if (object.editWindow == null)
14242
- new Exception().printStackTrace();
14243
- else
14244
- object.editWindow.refreshContents(true);
15404
+// if (object.editWindow == null)
15405
+// new Exception().printStackTrace();
15406
+// else
15407
+ object.GetWindow().refreshContents(true);
1424515408 break;
1424615409 case '{':
1424715410 manipCamera.shaper_fovy /= 1.1;
....@@ -14296,6 +15459,7 @@
1429615459 }
1429715460 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1429815461 }
15462
+
1429915463 static double OCCLUSIONBOOST = 1; // 0.5;
1430015464
1430115465 void keyReleased(int key, int modifiers)
....@@ -14303,11 +15467,11 @@
1430315467 //mode = ROTATE;
1430415468 if ((MODIFIERS & COMMAND) == 0) // VR??
1430515469 {
14306
- SetMouseMode(modifiers);
15470
+ SetMouseMode(0, modifiers);
1430715471 }
1430815472 }
1430915473
14310
- protected void processKeyEvent(KeyEvent e)
15474
+ public void processKeyEvent(KeyEvent e)
1431115475 {
1431215476 switch (e.getID())
1431315477 {
....@@ -14437,8 +15601,9 @@
1443715601
1443815602 protected void processMouseMotionEvent(MouseEvent e)
1443915603 {
14440
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14441
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15604
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15605
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15606
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1444215607 {
1444315608 mouseMoved(e);
1444415609 } else
....@@ -14463,11 +15628,12 @@
1446315628 }
1446415629 */
1446515630
14466
- object.editWindow.EditSelection();
15631
+ object.GetWindow().EditSelection(false);
1446715632 }
1446815633
1446915634 void SelectParent()
1447015635 {
15636
+ new Exception().printStackTrace();
1447115637 System.exit(0);
1447215638 Composite group = (Composite) object;
1447315639 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14479,10 +15645,10 @@
1447915645 {
1448015646 //selectees.remove(i);
1448115647 System.out.println("select parent of " + elem);
14482
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15648
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1448315649 } else
1448415650 {
14485
- group.editWindow.Select(elem.GetTreePath(), first, true);
15651
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1448615652 }
1448715653
1448815654 first = false;
....@@ -14491,6 +15657,7 @@
1449115657
1449215658 void SelectChildren()
1449315659 {
15660
+ new Exception().printStackTrace();
1449415661 System.exit(0);
1449515662 /*
1449615663 Composite group = (Composite) object;
....@@ -14523,12 +15690,12 @@
1452315690 for (int j = 0; j < group.children.size(); j++)
1452415691 {
1452515692 elem = (Object3D) group.children.elementAt(j);
14526
- object.editWindow.Select(elem.GetTreePath(), first, true);
15693
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1452715694 first = false;
1452815695 }
1452915696 } else
1453015697 {
14531
- object.editWindow.Select(elem.GetTreePath(), first, true);
15698
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1453215699 }
1453315700
1453415701 first = false;
....@@ -14539,21 +15706,21 @@
1453915706 {
1454015707 //Composite group = (Composite) object;
1454115708 Object3D group = object;
14542
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15709
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1454315710 }
1454415711
1454515712 void ResetTransform(int mask)
1454615713 {
1454715714 //Composite group = (Composite) object;
1454815715 Object3D group = object;
14549
- group.editWindow.ResetTransform(mask);
15716
+ group.GetWindow().ResetTransform(mask);
1455015717 }
1455115718
1455215719 void FlipTransform()
1455315720 {
1455415721 //Composite group = (Composite) object;
1455515722 Object3D group = object;
14556
- group.editWindow.FlipTransform();
15723
+ group.GetWindow().FlipTransform();
1455715724 // group.editWindow.ReduceMesh(true);
1455815725 }
1455915726
....@@ -14561,7 +15728,7 @@
1456115728 {
1456215729 //Composite group = (Composite) object;
1456315730 Object3D group = object;
14564
- group.editWindow.PrintMemory();
15731
+ group.GetWindow().PrintMemory();
1456515732 // group.editWindow.ReduceMesh(true);
1456615733 }
1456715734
....@@ -14569,7 +15736,7 @@
1456915736 {
1457015737 //Composite group = (Composite) object;
1457115738 Object3D group = object;
14572
- group.editWindow.ResetCentroid();
15739
+ group.GetWindow().ResetCentroid();
1457315740 }
1457415741
1457515742 void IncDepth()
....@@ -14655,7 +15822,9 @@
1465515822 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1465615823 //Image img = CreateImage(width, height);
1465715824 //System.out.println("width = " + width + "; height = " + height + "\n");
15825
+
1465815826 Graphics gr = g; // img.getGraphics();
15827
+
1465915828 if (!hasMarquee)
1466015829 {
1466115830 if (Xmin < Xmax) // !locked)
....@@ -14743,6 +15912,7 @@
1474315912 info.bounds.y += (height - desired) / 2;
1474415913 }
1474515914 }
15915
+
1474615916 info.g = gr;
1474715917 info.camera = renderCamera;
1474815918 /*
....@@ -14752,15 +15922,55 @@
1475215922 */
1475315923 if (!isRenderer)
1475415924 {
14755
- object.drawEditHandles(info, 0);
15925
+ Grafreed.Assert(object != null);
15926
+ Grafreed.Assert(object.selection != null);
15927
+ if (object.selection.Size() > 0)
15928
+ {
15929
+ int hitSomething = object.selection.get(0).hitSomething;
15930
+
15931
+ info.DX = 0;
15932
+ info.DY = 0;
15933
+ info.W = 1;
15934
+ if (hitSomething == Object3D.hitCenter)
15935
+ {
15936
+ info.DX = X;
15937
+ if (X != 0)
15938
+ info.DX -= info.bounds.width/2;
15939
+
15940
+ info.DY = Y;
15941
+ if (Y != 0)
15942
+ info.DY -= info.bounds.height/2;
15943
+ }
15944
+
15945
+ object.drawEditHandles(info, 0);
15946
+
15947
+ if (drag && (X != 0 || Y != 0))
15948
+ {
15949
+ switch (hitSomething)
15950
+ {
15951
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15952
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15953
+ break;
15954
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15955
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15956
+ break;
15957
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15958
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15959
+ break;
15960
+ }
15961
+
15962
+ }
15963
+ }
1475615964 }
1475715965 }
15966
+
1475815967 if (isRenderer)
1475915968 {
1476015969 //gr.setColor(Color.black);
1476115970 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1476215971 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1476315972 }
15973
+
1476415974 if (hasMarquee)
1476515975 {
1476615976 gr.setXORMode(Color.white);
....@@ -14873,6 +16083,7 @@
1487316083 public boolean mouseDown(Event evt, int x, int y)
1487416084 {
1487516085 System.out.println("mouseDown: " + evt);
16086
+ System.exit(0);
1487616087 /*
1487716088 locked = true;
1487816089 drag = false;
....@@ -14916,7 +16127,7 @@
1491616127 {
1491716128 keyPressed(0, modifiers);
1491816129 }
14919
- clickStart(x, y, modifiers);
16130
+ // clickStart(x, y, modifiers);
1492016131 return true;
1492116132 }
1492216133
....@@ -15034,7 +16245,7 @@
1503416245 {
1503516246 keyReleased(0, 0);
1503616247 }
15037
- drag(x, y, modifiers);
16248
+ drag(x, y, 0, modifiers);
1503816249 return true;
1503916250 }
1504016251
....@@ -15166,7 +16377,7 @@
1516616377 Object3D object;
1516716378 static Object3D trackedobject;
1516816379 Camera renderCamera; // Light or Eye (or Occlusion)
15169
- /*static*/ Camera manipCamera; // Light or Eye
16380
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1517016381 /*static*/ Camera eyeCamera;
1517116382 /*static*/ Camera lightCamera;
1517216383 int cameracount;
....@@ -15451,16 +16662,16 @@
1545116662 cStatic.objectstack[materialdepth++] = checker;
1545216663 //System.out.println("material " + material);
1545316664 //Applet3D.tracein(this, selected);
15454
- vector2buffer = checker.projectedVertices;
16665
+ //vector2buffer = checker.projectedVertices;
1545516666
1545616667 //checker.GetMaterial().Draw(this, false); // true);
15457
- DrawMaterial(checker.GetMaterial(), false); // true);
16668
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1545816669
1545916670 materialdepth -= 1;
1546016671 if (materialdepth > 0)
1546116672 {
15462
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15463
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16673
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16674
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1546416675 }
1546516676 //checker.GetMaterial().opacity = 1f;
1546616677 ////checker.GetMaterial().ambient = 1f;
....@@ -15546,6 +16757,14 @@
1554616757 }
1554716758 }
1554816759
16760
+ private Object3D GetFolder()
16761
+ {
16762
+ Object3D folder = object.GetWindow().copy;
16763
+ if (object.GetWindow().copy.selection.Size() > 0)
16764
+ folder = object.GetWindow().copy.selection.elementAt(0);
16765
+ return folder;
16766
+ }
16767
+
1554916768 class SelectBuffer implements GLEventListener
1555016769 {
1555116770
....@@ -15604,6 +16823,7 @@
1560416823 {
1560516824 if (!selection)
1560616825 {
16826
+ new Exception().printStackTrace();
1560716827 System.exit(0);
1560816828 return;
1560916829 }
....@@ -15624,6 +16844,17 @@
1562416844
1562516845 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1562616846
16847
+ if (PAINTMODE)
16848
+ {
16849
+ if (object.GetWindow().copy.selection.Size() > 0)
16850
+ {
16851
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16852
+
16853
+ // Make what you paint not selectable.
16854
+ paintobj.ResetSelectable();
16855
+ }
16856
+ }
16857
+
1562716858 //int tmp = selection_view;
1562816859 //selection_view = -1;
1562916860 int temp = DrawMode();
....@@ -15635,6 +16866,17 @@
1563516866 // temp = DEFAULT; // patch for selection debug
1563616867 Globals.drawMode = temp; // WARNING
1563716868
16869
+ if (PAINTMODE)
16870
+ {
16871
+ if (object.GetWindow().copy.selection.Size() > 0)
16872
+ {
16873
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16874
+
16875
+ // Revert.
16876
+ paintobj.RestoreSelectable();
16877
+ }
16878
+ }
16879
+
1563816880 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1563916881
1564016882 // trying different ways of getting the depth info over
....@@ -15682,6 +16924,8 @@
1568216924 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1568316925 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1568416926 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16927
+
16928
+ CreateSelectedPoint();
1568516929
1568616930 // Will fit the mesh !!!
1568716931 selectedpoint.toParent[0][0] = 0.0001;
....@@ -15731,34 +16975,36 @@
1573116975 System.out.println("; fromto " + sel + " " + Trunk(previousselectedpoint.toParent[3][0]) + " " + Trunk(previousselectedpoint.toParent[3][2]) + " " + Trunk(selectedpoint.toParent[3][0]) + " " + Trunk(selectedpoint.toParent[3][2]));
1573216976 }
1573316977
15734
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
16978
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1573516979 }
1573616980 }
1573716981
1573816982 if (!movingcamera && !PAINTMODE)
15739
- object.editWindow.ScreenFitPoint(); // fev 2014
16983
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1574016984
15741
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
16985
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1574216986 {
15743
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16987
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1574416988
15745
- Object3D group = new Object3D("inst" + paintcount++);
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ {
16991
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1574616992
15747
- group.CreateMaterial(); // use a void leaf to select instances
15748
-
15749
- group.add(paintobj); // link
15750
-
15751
- object.editWindow.SnapObject(group);
15752
-
15753
- Object3D folder = object.editWindow.copy;
15754
-
15755
- if (object.editWindow.copy.selection.Size() > 0)
15756
- folder = object.editWindow.copy.selection.elementAt(0);
15757
-
15758
- folder.add(group);
15759
-
15760
- object.editWindow.ResetModel();
15761
- object.editWindow.refreshContents();
16993
+ Object3D inst = new Object3D("inst" + paintcount++);
16994
+
16995
+ inst.CreateMaterial(); // use a void leaf to select instances
16996
+
16997
+ inst.add(paintobj); // link
16998
+
16999
+ object.GetWindow().SnapObject(inst);
17000
+
17001
+ Object3D folder = paintFolder; // GetFolder();
17002
+
17003
+ folder.add(inst);
17004
+
17005
+ object.GetWindow().ResetModel();
17006
+ object.GetWindow().refreshContents();
17007
+ }
1576217008 }
1576317009 else
1576417010 paintcount = 0;
....@@ -15797,6 +17043,11 @@
1579717043 //System.out.println("objects[color] = " + objects[color]);
1579817044 //objects[color].Select();
1579917045 indexcount = 0;
17046
+ ObjEditor window = object.GetWindow();
17047
+ if (window != null && deselect)
17048
+ {
17049
+ window.Select(null, deselect, true);
17050
+ }
1580017051 object.Select(color, deselect);
1580117052 }
1580217053
....@@ -15896,7 +17147,7 @@
1589617147 gl.glDisable(gl.GL_CULL_FACE);
1589717148 }
1589817149
15899
- if (!RENDERSHADOW)
17150
+ if (!Globals.RENDERSHADOW)
1590017151 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1590117152
1590217153 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -15906,7 +17157,7 @@
1590617157 //gl.glColorMask(false, false, false, false);
1590717158
1590817159 //render_scene_from_light_view(gl, drawable, 0, 0);
15909
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17160
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1591017161 {
1591117162 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1591217163
....@@ -15966,7 +17217,6 @@
1596617217
1596717218 class AntialiasBuffer implements GLEventListener
1596817219 {
15969
-
1597017220 CameraPane parent = null;
1597117221
1597217222 AntialiasBuffer(CameraPane p)
....@@ -16323,23 +17573,15 @@
1632317573 int AAbuffersize = 0;
1632417574
1632517575 //double[] selectedpoint = new double[3];
16326
- static Superellipsoid selectedpoint = new Superellipsoid();
17576
+ static Superellipsoid selectedpoint;
1632717577 static Sphere previousselectedpoint = null;
16328
- static Sphere debugpointG = new Sphere();
16329
- static Sphere debugpointP = new Sphere();
16330
- static Sphere debugpointC = new Sphere();
16331
- static Sphere debugpointR = new Sphere();
17578
+ static Sphere debugpointG;
17579
+ static Sphere debugpointP;
17580
+ static Sphere debugpointC;
17581
+ static Sphere debugpointR;
1633217582
1633317583 static Sphere debugpoints[] = new Sphere[8];
1633417584
16335
- static
16336
- {
16337
- for (int i=0; i<8; i++)
16338
- {
16339
- debugpoints[i] = new Sphere();
16340
- }
16341
- }
16342
-
1634317585 static void InitPoints(float radius)
1634417586 {
1634517587 for (int i=0; i<8; i++)
....@@ -16359,7 +17601,7 @@
1635917601 }
1636017602 }
1636117603
16362
- static void DrawPoints(CameraPane cpane)
17604
+ static void DrawPoints(iCameraPane cpane)
1636317605 {
1636417606 for (int i=0; i<8; i++) // first and last are red
1636517607 {
....@@ -16391,10 +17633,11 @@
1639117633 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1639217634 // Depth buffer format
1639317635 //private int depth_format;
16394
- static public void NextIndex(Object3D o, GL gl)
17636
+
17637
+ public void NextIndex()
1639517638 {
1639617639 indexcount+=16;
16397
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17640
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1639817641 //objects[indexcount] = o;
1639917642 //System.out.println("indexcount = " + indexcount);
1640017643 }