Normand Briere
2019-07-22 c570e1e38f2ff8622a71f81436654bad01cfdd5b
CameraPane.java
....@@ -37,7 +37,6 @@
3737 static boolean[] selectedstack = new boolean[65536];
3838 static int materialdepth = 0;
3939
40
- static boolean DEBUG = false;
4140 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4241
4342 // camera change fix
....@@ -45,6 +44,39 @@
4544 static boolean ABORTED = false;
4645
4746 static int STEP = 1;
47
+
48
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
49
+ {
50
+ int[] pixels = new int[bytes.length/3];
51
+ for (int i=pixels.length; --i>=0;)
52
+ {
53
+ int i3 = i*3;
54
+ pixels[i] = 0xFF;
55
+ pixels[i] <<= 8;
56
+ pixels[i] |= bytes[i3+2] & 0xFF;
57
+ pixels[i] <<= 8;
58
+ pixels[i] |= bytes[i3+1] & 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3] & 0xFF;
61
+ }
62
+ /*
63
+ int r=0,g=0,b=0,a=0;
64
+ for (int i=0; i<width; i++)
65
+ for (int j=0; j<height; j++)
66
+ {
67
+ int index = j*width+i;
68
+ int p = pixels[index];
69
+ a = ((p>>24) & 0xFF);
70
+ r = ((p>>16) & 0xFF);
71
+ g = ((p>>8) & 0xFF);
72
+ b = (p & 0xFF);
73
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
74
+ }
75
+ /**/
76
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
77
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
78
+ return rendImage;
79
+ }
4880
4981 /*static*/ private boolean CULLFACE = false; // true;
5082 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +88,12 @@
5688 static int CURRENTANTIALIAS = 0; // 1;
5789 /*static*/ boolean RENDERSHADOW = true;
5890 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6191
6292 boolean DISPLAYTEXT = false;
6393 //boolean REDUCETEXTURE = true;
6494 boolean CACHETEXTURE = true;
6595 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
96
+ boolean MIPMAP = true; // false; // true;
6797 boolean COMPRESSTEXTURE = false;
6898 boolean KOMPACTTEXTURE = false; // true;
6999 boolean RESIZETEXTURE = false;
....@@ -92,6 +122,8 @@
92122
93123 static int tickcount = 0; // slow pose issue
94124
125
+static boolean BUTTONLESSWHEEL = false;
126
+static boolean ZOOMBOXMODE = false;
95127 static boolean BOXMODE = false;
96128 static boolean IMAGEFLIP = false;
97129 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +138,7 @@
106138 static boolean OEIL = true;
107139 static boolean OEILONCE = false; // do oeilon then oeiloff
108140 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
141
+static boolean SWITCH = true; // false;
110142 static boolean HANDLES = false; // selection doesn't work!!
111143 static boolean PAINTMODE = false;
112144
....@@ -149,12 +181,13 @@
149181 defaultcaps.setAccumBlueBits(16);
150182 defaultcaps.setAccumAlphaBits(16);
151183 }
152
- static CameraPane theRenderer;
153
-
184
+
185
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
186
+
154187 void SetAsGLRenderer(boolean b)
155188 {
156189 isRenderer = b;
157
- theRenderer = this;
190
+ Globals.theRenderer = this;
158191 }
159192
160193 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -192,9 +225,43 @@
192225
193226 /// INTERFACE
194227
228
+ public javax.media.opengl.GL GetGL0()
229
+ {
230
+ return null;
231
+ }
232
+
233
+ public int GenList()
234
+ {
235
+ javax.media.opengl.GL gl = GetGL();
236
+ return gl.glGenLists(1);
237
+ }
238
+
239
+ public void NewList(int id)
240
+ {
241
+ javax.media.opengl.GL gl = GetGL();
242
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
243
+ }
244
+
245
+ public void CallList(int id)
246
+ {
247
+ javax.media.opengl.GL gl = GetGL();
248
+ gl.glCallList(id);
249
+ }
250
+
251
+ public void EndList()
252
+ {
253
+ javax.media.opengl.GL gl = GetGL();
254
+ gl.glEndList();
255
+ }
256
+
195257 public boolean IsBoxMode()
196258 {
197259 return BOXMODE;
260
+ }
261
+
262
+ public boolean IsZoomBoxMode()
263
+ {
264
+ return ZOOMBOXMODE;
198265 }
199266
200267 public void ClearDepth()
....@@ -236,9 +303,14 @@
236303 return this.ambientOcclusion;
237304 }
238305
306
+ public boolean IsDebugSelection()
307
+ {
308
+ return DEBUG_SELECTION;
309
+ }
310
+
239311 public boolean IsFrozen()
240312 {
241
- boolean selectmode = this.DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
313
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
242314
243315 return !selectmode && cameracount == 0; // != 0;
244316 }
....@@ -259,9 +331,19 @@
259331 return lightCamera;
260332 }
261333
334
+ public Camera ManipCamera()
335
+ {
336
+ return manipCamera;
337
+ }
338
+
262339 public Camera RenderCamera()
263340 {
264341 return renderCamera;
342
+ }
343
+
344
+ public Camera[] Cameras()
345
+ {
346
+ return cameras;
265347 }
266348
267349 public void PushMaterial(Object3D obj, boolean selected)
....@@ -277,7 +359,7 @@
277359 cStatic.objectstack[materialdepth++] = obj;
278360 //System.out.println("material " + material);
279361 //Applet3D.tracein(this, selected);
280
- display.vector2buffer = obj.projectedVertices;
362
+ //display.vector2buffer = obj.projectedVertices;
281363 if (obj instanceof Camera)
282364 {
283365 display.options1[0] = material.shift;
....@@ -286,14 +368,28 @@
286368 display.options1[2] = material.shadowbias;
287369 display.options1[3] = material.aniso;
288370 display.options1[4] = material.anisoV;
371
+// System.out.println("display.options1[0] " + display.options1[0]);
372
+// System.out.println("display.options1[1] " + display.options1[1]);
373
+// System.out.println("display.options1[2] " + display.options1[2]);
374
+// System.out.println("display.options1[3] " + display.options1[3]);
375
+// System.out.println("display.options1[4] " + display.options1[4]);
289376 display.options2[0] = material.opacity;
290377 display.options2[1] = material.diffuse;
291378 display.options2[2] = material.factor;
379
+// System.out.println("display.options2[0] " + display.options2[0]);
380
+// System.out.println("display.options2[1] " + display.options2[1]);
381
+// System.out.println("display.options2[2] " + display.options2[2]);
292382
293383 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
384
+// System.out.println("display.options3[0] " + display.options3[0]);
385
+// System.out.println("display.options3[1] " + display.options3[1]);
386
+// System.out.println("display.options3[2] " + display.options3[2]);
294387 display.options4[0] = material.cameralight/0.2f;
295388 display.options4[1] = material.subsurface;
296389 display.options4[2] = material.sheen;
390
+// System.out.println("display.options4[0] " + display.options4[0]);
391
+// System.out.println("display.options4[1] " + display.options4[1]);
392
+// System.out.println("display.options4[2] " + display.options4[2]);
297393
298394 // if (display.CURRENTANTIALIAS > 0)
299395 // display.options3[3] /= 4;
....@@ -309,7 +405,7 @@
309405 /**/
310406 } else
311407 {
312
- DrawMaterial(material, selected);
408
+ DrawMaterial(material, selected, obj.projectedVertices);
313409 }
314410 } else
315411 {
....@@ -333,8 +429,8 @@
333429 cStatic.objectstack[materialdepth++] = obj;
334430 //System.out.println("material " + material);
335431 //Applet3D.tracein("selected ", selected);
336
- display.vector2buffer = obj.projectedVertices;
337
- display.DrawMaterial(material, selected);
432
+ //display.vector2buffer = obj.projectedVertices;
433
+ display.DrawMaterial(material, selected, obj.projectedVertices);
338434 }
339435 }
340436
....@@ -351,8 +447,8 @@
351447 materialdepth -= 1;
352448 if (materialdepth > 0)
353449 {
354
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
355
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
450
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
451
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
356452 }
357453 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
358454 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -372,8 +468,8 @@
372468 materialdepth -= 1;
373469 if (materialdepth > 0)
374470 {
375
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
376
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
471
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
472
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
377473 }
378474 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
379475 //else
....@@ -408,16 +504,18 @@
408504
409505 javax.media.opengl.GL gl = display.GetGL();
410506
411
- boolean selectmode = display.DrawMode() == display.SELECTION || CameraPane.DEBUG_SELECTION;
507
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
412508
413509 //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
414510 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
415511 {
416512 //gl.glBegin(gl.GL_TRIANGLES);
417
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
513
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
514
+ // TEST LIVE NORMALS && !obj.dontselect
515
+ ;
418516 if (!hasnorm)
419517 {
420
- // System.out.println("FUCK!!");
518
+ // System.out.println("Mesh normal");
421519 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
422520 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
423521 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -760,7 +858,627 @@
760858 //// tris.postdraw(this);
761859 }
762860
861
+ static Camera localcamera = new Camera();
862
+ static cVector from = new cVector();
863
+ static cVector to = new cVector();
864
+
865
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
866
+ {
867
+ CameraPane cp = this;
868
+
869
+ Camera keep = cp.RenderCamera();
870
+ cp.renderCamera = localcamera;
871
+
872
+ if (br.trimmed)
873
+ {
874
+ float[] colors = new float[br.positions.length / 3];
875
+
876
+ int i3 = 0;
877
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
878
+ {
879
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
880
+ continue;
881
+
882
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
883
+ to.set(br.positions[i3] + br.normals[i3],
884
+ br.positions[i3 + 1] + br.normals[i3 + 1],
885
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
886
+ LA.xformPos(from, transform, from);
887
+ LA.xformPos(to, transform, to); // RIGID ONLY
888
+ localcamera.setAim(from, to);
889
+
890
+ CameraPane.occlusionbuffer.display();
891
+
892
+ if (CameraPane.DEBUG_OCCLUSION)
893
+ cp.display(); // debug
894
+
895
+ colors[i] = cp.vertexOcclusion.r;
896
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
897
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
898
+
899
+ if ((i % 100) == 0 && i != 0)
900
+ {
901
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
902
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
903
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
904
+ }
905
+ }
906
+
907
+ br.colors = colors;
908
+ }
909
+ else
910
+ {
911
+ for (int i = 0; i < br.VertexCount(); i++)
912
+ {
913
+ Vertex v = br.GetVertex(i);
914
+
915
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
916
+ continue;
917
+
918
+ from.set(v.x, v.y, v.z);
919
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
920
+ LA.xformPos(from, transform, from);
921
+ LA.xformPos(to, transform, to); // RIGID ONLY
922
+ localcamera.setAim(from, to);
923
+
924
+ CameraPane.occlusionbuffer.display();
925
+
926
+ if (CameraPane.DEBUG_OCCLUSION)
927
+ cp.display(); // debug
928
+
929
+ v.AO = cp.vertexOcclusion.r;
930
+
931
+ if ((i % 100) == 0 && i != 0)
932
+ {
933
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
934
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
935
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
936
+ }
937
+ }
938
+ }
939
+
940
+ //System.out.println("done.");
941
+
942
+ cp.renderCamera = keep;
943
+ }
944
+
945
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
946
+ {
947
+ CameraPane display = this;
948
+ pointFlow.CreateHT();
949
+
950
+ float r = display.modelParams0[0];
951
+ float g = display.modelParams0[1];
952
+ float b = display.modelParams0[2];
953
+ float opacity = display.modelParams5[1];
954
+
955
+ //final GL gl = GLU.getCurrentGL();
956
+ GL gl = display.GetGL(); // getGL();
957
+
958
+ int s = pointFlow.points.size();
959
+
960
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
961
+ gl.glEnable(gl.GL_CULL_FACE);
962
+
963
+ for (int i=s; --i>=0;)
964
+ //for (int i=0; i<s; i++)
965
+ {
966
+ cVector v = pointFlow.points.get(i);
967
+
968
+ double mindist = Double.MAX_VALUE;
969
+
970
+ double size = pointFlow.minimumSize;
971
+
972
+ double distancenext = 0;
973
+
974
+ if (i > 0)
975
+ {
976
+ cVector w = pointFlow.points.get(i-1);
977
+
978
+ double dist = w.distance(v);
979
+
980
+ distancenext = dist;
981
+
982
+ if (mindist > dist)
983
+ {
984
+ mindist = dist;
985
+ size = mindist*pointFlow.resizefactor;
986
+ }
987
+ }
988
+
989
+ if (i < s-1)
990
+ {
991
+ cVector w = pointFlow.points.get(i+1);
992
+
993
+ double dist = w.distance(v);
994
+
995
+ if (mindist > dist)
996
+ {
997
+ mindist = dist;
998
+ size = mindist*pointFlow.resizefactor;
999
+ }
1000
+ }
1001
+
1002
+ if (size < pointFlow.minimumSize)
1003
+ size = pointFlow.minimumSize;
1004
+ if (size > pointFlow.maximumSize)
1005
+ size = pointFlow.maximumSize;
1006
+
1007
+ double tx = v.x;
1008
+ double ty = v.y;
1009
+ double tz = v.z;
1010
+
1011
+ // if (tx == 0 && ty == 0 && tz == 0)
1012
+ // continue;
1013
+
1014
+ gl.glMatrixMode(gl.GL_TEXTURE);
1015
+ gl.glPushMatrix();
1016
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1017
+
1018
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1019
+
1020
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1021
+ gl.glPushMatrix();
1022
+
1023
+ gl.glTranslated(tx,ty,tz);
1024
+
1025
+ gl.glScaled(size,size,size);
1026
+
1027
+// float cr = colorBuf.get(index4);
1028
+// float cg = colorBuf.get(index4+1);
1029
+// float cb = colorBuf.get(index4+2);
1030
+// float ca = colorBuf.get(index4+3);
1031
+//
1032
+// display.modelParams0[0] = r * cr;
1033
+// display.modelParams0[1] = g * cg;
1034
+// display.modelParams0[2] = b * cb;
1035
+//
1036
+// display.modelParams5[1] = opacity * ca;
1037
+//
1038
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1039
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1040
+//
1041
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1042
+// RandomNode.globalseed2 = RandomNode.globalseed;
1043
+//
1044
+//// gl.glColor4f(cr,cg,cb,ca);
1045
+// // gl.glScalef(1024/16,1024/16,1024/16);
1046
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1047
+
1048
+ gl.glPopMatrix();
1049
+
1050
+ double step = size/4; //
1051
+
1052
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1053
+ continue;
1054
+
1055
+ int nbsteps = (int)(distancenext/step);
1056
+
1057
+ step = distancenext/nbsteps;
1058
+
1059
+ cVector next = pointFlow.points.get(i-1);
1060
+
1061
+ tmp.set(next);
1062
+ tmp.sub(v);
1063
+ tmp.normalize();
1064
+ tmp.mul(step);
1065
+
1066
+ // calculate next size
1067
+ mindist = Double.MAX_VALUE;
1068
+
1069
+ double nextsize = pointFlow.minimumSize;
1070
+
1071
+ if (i > 1)
1072
+ {
1073
+ cVector w = pointFlow.points.get(i-2);
1074
+
1075
+ double dist = w.distance(next);
1076
+
1077
+ if (mindist > dist)
1078
+ {
1079
+ mindist = dist;
1080
+ nextsize = mindist*pointFlow.resizefactor;
1081
+ }
1082
+ }
1083
+
1084
+ double dist = v.distance(next);
1085
+
1086
+ if (mindist > dist)
1087
+ {
1088
+ mindist = dist;
1089
+ nextsize = mindist*pointFlow.resizefactor;
1090
+ }
1091
+
1092
+ if (nextsize < pointFlow.minimumSize)
1093
+ nextsize = pointFlow.minimumSize;
1094
+ if (nextsize > pointFlow.maximumSize)
1095
+ nextsize = pointFlow.maximumSize;
1096
+ //
1097
+
1098
+ double count = 0;
1099
+
1100
+ while (distancenext > 0.000000001) // step
1101
+ {
1102
+ gl.glPushMatrix();
1103
+
1104
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1105
+
1106
+ double K = count/nbsteps;
1107
+
1108
+ double intersize = K*nextsize + (1-K)*size;
1109
+
1110
+ gl.glScaled(intersize,intersize,intersize);
1111
+
1112
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1113
+
1114
+ count++;
1115
+
1116
+ distancenext -= step;
1117
+
1118
+ gl.glPopMatrix();
1119
+ }
1120
+
1121
+ if (count != nbsteps)
1122
+ assert(count == nbsteps);
1123
+
1124
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1125
+ //gl.glTranslatef(-tx,-ty,-tz);
1126
+
1127
+ gl.glMatrixMode(gl.GL_TEXTURE);
1128
+ gl.glPopMatrix();
1129
+ }
1130
+
1131
+ if (!cf)
1132
+ gl.glDisable(gl.GL_CULL_FACE);
1133
+
1134
+// display.modelParams0[0] = r;
1135
+// display.modelParams0[1] = g;
1136
+// display.modelParams0[2] = b;
1137
+//
1138
+// display.modelParams5[1] = opacity;
1139
+//
1140
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1141
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1142
+
1143
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1144
+ }
1145
+
1146
+ public void DrawBox(cVector min, cVector max)
1147
+ {
1148
+ javax.media.opengl.GL gl = GetGL();
1149
+ gl.glBegin(gl.GL_LINES);
1150
+
1151
+ gl.glVertex3d(min.x, min.y, min.z);
1152
+ gl.glVertex3d(min.x, min.y, max.z);
1153
+ gl.glVertex3d(min.x, min.y, min.z);
1154
+ gl.glVertex3d(min.x, max.y, min.z);
1155
+ gl.glVertex3d(min.x, min.y, min.z);
1156
+ gl.glVertex3d(max.x, min.y, min.z);
1157
+
1158
+ gl.glVertex3d(max.x, max.y, max.z);
1159
+ gl.glVertex3d(min.x, max.y, max.z);
1160
+ gl.glVertex3d(max.x, max.y, max.z);
1161
+ gl.glVertex3d(max.x, min.y, max.z);
1162
+ gl.glVertex3d(max.x, max.y, max.z);
1163
+ gl.glVertex3d(max.x, max.y, min.z);
1164
+
1165
+ gl.glEnd();
1166
+ }
1167
+
1168
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1169
+ {
1170
+ int[] strips = bRep.getRawIndices();
1171
+
1172
+ javax.media.opengl.GL gl = GetGL();
1173
+
1174
+ // TRIANGLE STRIP ARRAY
1175
+ if (bRep.trimmed)
1176
+ {
1177
+ float[] v = bRep.getRawVertices();
1178
+ float[] n = bRep.getRawNormals();
1179
+ float[] c = bRep.getRawColors();
1180
+ float[] uv = bRep.getRawUVMap();
1181
+
1182
+ int count2 = 0;
1183
+ int count3 = 0;
1184
+
1185
+ if (n.length > 0)
1186
+ {
1187
+ for (int i = 0; i < strips.length; i++)
1188
+ {
1189
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1190
+
1191
+ /*
1192
+ boolean locked = false;
1193
+ float eps = 0.1f;
1194
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1195
+
1196
+ int dot = 0;
1197
+
1198
+ if ((dot&1) == 0)
1199
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1200
+
1201
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1202
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1203
+ else
1204
+ {
1205
+ locked = true;
1206
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1207
+ }
1208
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1209
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1210
+ if (hasnorm)
1211
+ {
1212
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1213
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1214
+ }
1215
+
1216
+ if ((dot&4) == 0)
1217
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1218
+
1219
+ if (wrap || !locked && (dot&8) != 0)
1220
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1221
+ else
1222
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1223
+
1224
+ f.dot = dot;
1225
+ */
1226
+
1227
+ if (!selectmode)
1228
+ {
1229
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1230
+ {
1231
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1232
+ } else
1233
+ {
1234
+ gl.glNormal3f(0, 0, 1);
1235
+ }
1236
+
1237
+ if (c != null)
1238
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1239
+ {
1240
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1241
+ }
1242
+ }
1243
+
1244
+ if (flipV)
1245
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1246
+ else
1247
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1248
+
1249
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1250
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1251
+
1252
+ count2 += 2;
1253
+ count3 += 3;
1254
+ if (!selectmode)
1255
+ {
1256
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1257
+ {
1258
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1259
+ } else
1260
+ {
1261
+ gl.glNormal3f(0, 0, 1);
1262
+ }
1263
+ if (c != null)
1264
+ {
1265
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1266
+ }
1267
+ }
1268
+
1269
+ if (flipV)
1270
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1271
+ else
1272
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1273
+
1274
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1275
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1276
+
1277
+ count2 += 2;
1278
+ count3 += 3;
1279
+ for (int j = 0; j < strips[i] - 2; j++)
1280
+ {
1281
+ //gl.glTexCoord2d(...);
1282
+ if (!selectmode)
1283
+ {
1284
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1285
+ {
1286
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1287
+ } else
1288
+ {
1289
+ gl.glNormal3f(0, 0, 1);
1290
+ }
1291
+ if (c != null)
1292
+ {
1293
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1294
+ }
1295
+ }
1296
+
1297
+ if (flipV)
1298
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1299
+ else
1300
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1301
+
1302
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1303
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1304
+
1305
+ count2 += 2;
1306
+ count3 += 3;
1307
+ }
1308
+
1309
+ gl.glEnd();
1310
+ }
1311
+ }
1312
+
1313
+ assert count3 == v.length;
1314
+ }
1315
+ else // !trimmed
1316
+ {
1317
+ int count = 0;
1318
+ for (int i = 0; i < strips.length; i++)
1319
+ {
1320
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1321
+
1322
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1323
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1324
+
1325
+ drawVertex(gl, p, flipV, selectmode);
1326
+ drawVertex(gl, q, flipV, selectmode);
1327
+
1328
+ for (int j = 0; j < strips[i] - 2; j++)
1329
+ {
1330
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1331
+
1332
+ // if (j%2 == 0)
1333
+ // drawFace(p, q, r, display, null);
1334
+ // else
1335
+ // drawFace(p, r, q, display, null);
1336
+
1337
+ // p = q;
1338
+ // q = r;
1339
+ drawVertex(gl, r, flipV, selectmode);
1340
+ }
1341
+
1342
+ gl.glEnd();
1343
+ }
1344
+ }
1345
+ }
1346
+
1347
+ static cSpring.Point3D temp = new cSpring.Point3D();
1348
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1349
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1350
+
1351
+ public void DrawDynamicMesh(cMesh mesh)
1352
+ {
1353
+ GL gl = GetGL(); // getGL();
1354
+
1355
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1356
+
1357
+ gl.glDisable(gl.GL_LIGHTING);
1358
+
1359
+ gl.glLineWidth(1);
1360
+ gl.glColor3f(1,1,1);
1361
+ gl.glBegin(gl.GL_LINES);
1362
+ double scale = 0;
1363
+ int count = 0;
1364
+ for (int s=0; s<Phys.allSprings.size(); s++)
1365
+ {
1366
+ cSpring.Spring spring = Phys.allSprings.get(s);
1367
+ if(s == 0)
1368
+ {
1369
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1370
+ }
1371
+ if (mesh.showsprings)
1372
+ {
1373
+ temp.set(spring.a.position);
1374
+ temp.add(spring.b.position);
1375
+ temp.mul(0.5);
1376
+ temp2.set(spring.a.position);
1377
+ temp2.sub(spring.b.position);
1378
+ temp2.mul(spring.restLength/2);
1379
+ temp.sub(temp2);
1380
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1381
+ temp.add(temp2);
1382
+ temp.add(temp2);
1383
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1384
+ }
1385
+
1386
+ if (spring.isHandle)
1387
+ continue;
1388
+
1389
+ //if (scale < spring.restLength)
1390
+ scale += spring.restLength;
1391
+ count++;
1392
+ }
1393
+ gl.glEnd();
1394
+
1395
+ if (count == 0)
1396
+ scale = 0.01;
1397
+ else
1398
+ scale /= count * 3;
1399
+
1400
+ //scale = 0.25;
1401
+
1402
+ if (mesh.ShowInfo())
1403
+ {
1404
+ gl.glLineWidth(4);
1405
+ for (int s=0; s<Phys.allNodes.size(); s++)
1406
+ {
1407
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1408
+ if (node.mass == 0)
1409
+ continue;
1410
+
1411
+ int i = node.springs==null?-1:node.springs.size();
1412
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1413
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1414
+ //temp.normalize();
1415
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1416
+ gl.glBegin(gl.GL_LINES);
1417
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1418
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1419
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1420
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1421
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1422
+ gl.glEnd();
1423
+ }
1424
+
1425
+ gl.glLineWidth(8);
1426
+ for (int s=0; s<Phys.allNodes.size(); s++)
1427
+ {
1428
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1429
+
1430
+ if (node.springs != null)
1431
+ {
1432
+ for (int i=0; i<node.springs.size(); i+=1)
1433
+ {
1434
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1435
+
1436
+ int c = i+1;
1437
+ // c = node.springs.get(i).nbcopies;
1438
+
1439
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1440
+ gl.glBegin(gl.GL_LINES);
1441
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1442
+ 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);
1443
+ gl.glEnd();
1444
+ }
1445
+ }
1446
+ }
1447
+
1448
+ gl.glLineWidth(1);
1449
+ }
1450
+
1451
+ gl.glEnable(gl.GL_LIGHTING);
1452
+ }
1453
+
7631454 /// INTERFACE
1455
+
1456
+ public void StartTriangles()
1457
+ {
1458
+ javax.media.opengl.GL gl = GetGL();
1459
+ gl.glBegin(gl.GL_TRIANGLES);
1460
+ }
1461
+
1462
+ public void EndTriangles()
1463
+ {
1464
+ GetGL().glEnd();
1465
+ }
1466
+
1467
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1468
+ {
1469
+ if (!selectmode)
1470
+ {
1471
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1472
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1473
+
1474
+ if (flipV)
1475
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1476
+ else
1477
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1478
+ }
1479
+
1480
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1481
+ }
7641482
7651483 void SetColor(Object3D obj, Vertex p0)
7661484 {
....@@ -939,7 +1657,7 @@
9391657 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
9401658 }
9411659
942
- void DrawMaterial(cMaterial material, boolean selected)
1660
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
9431661 {
9441662 CameraPane display = this;
9451663 //new Exception().printStackTrace();
....@@ -955,18 +1673,18 @@
9551673 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
9561674 if (!material.multiply)
9571675 {
958
- display.color = color;
1676
+ display.color = material.color;
9591677 display.saturation = material.modulation;
9601678 }
9611679 else
9621680 {
963
- display.color *= color*2;
1681
+ display.color *= material.color*2;
9641682 display.saturation *= material.modulation*2;
9651683 }
9661684
9671685 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
9681686
969
- float[] colorV = GrafreeD.colorV;
1687
+ float[] colorV = Grafreed.colorV;
9701688
9711689 /**/
9721690 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -974,7 +1692,7 @@
9741692 colorV[0] = display.modelParams0[0] * material.diffuse;
9751693 colorV[1] = display.modelParams0[1] * material.diffuse;
9761694 colorV[2] = display.modelParams0[2] * material.diffuse;
977
- colorV[3] = material.opacity;
1695
+ colorV[3] = 1; // material.opacity;
9781696
9791697 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
9801698 //System.out.println("Opacity = " + opacity);
....@@ -1082,9 +1800,9 @@
10821800 display.modelParams7[2] = 0;
10831801 display.modelParams7[3] = 0;
10841802
1085
- display.modelParams6[0] = 100; // criss de bug de bump
1803
+ //display.modelParams6[0] = 100; // criss de bug de bump
10861804
1087
- Object3D.cVector2[] extparams = display.vector2buffer;
1805
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
10881806 if (extparams != null && extparams.length > 0 && extparams[0] != null)
10891807 {
10901808 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1226,7 +1944,7 @@
12261944 void PushMatrix(double[][] matrix)
12271945 {
12281946 // GrafreeD.tracein(matrix);
1229
- PushMatrix(matrix,1);
1947
+ PushMatrix(matrix, 1);
12301948 }
12311949
12321950 void PushMatrix()
....@@ -1323,7 +2041,7 @@
13232041
13242042 static int camerachangeframe;
13252043
1326
- boolean SetCamera(Camera cam)
2044
+ public boolean SetCamera(Camera cam)
13272045 {
13282046 // may 2014 if (cam == cameras[0] || cam == cameras[1])
13292047 // return false;
....@@ -1380,7 +2098,7 @@
13802098 //System.err.println("Oeil on");
13812099 OEIL = true;
13822100 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1383
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2101
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
13842102 //pingthread.StepToTarget(true);
13852103 }
13862104
....@@ -1451,33 +2169,6 @@
14512169 mainDL ^= true;
14522170 }
14532171
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
-
14812172 void ToggleFullScreen()
14822173 {
14832174 FULLSCREEN ^= true;
....@@ -1488,72 +2179,94 @@
14882179 Globals.CROWD ^= true;
14892180 }
14902181
1491
- void ToggleInertia()
1492
- {
1493
- INERTIA ^= true;
1494
- }
1495
-
14962182 void ToggleLocal()
14972183 {
14982184 LOCALTRANSFORM ^= true;
14992185 }
15002186
1501
- void ToggleFast()
2187
+ public void ToggleTexture()
2188
+ {
2189
+ textureon ^= true;
2190
+ }
2191
+
2192
+ public void ToggleLive()
2193
+ {
2194
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2195
+
2196
+ System.err.println("LIVE = " + Globals.isLIVE());
2197
+
2198
+ if (!Globals.isLIVE()) // save sound
2199
+ Grafreed.savesound = true; // wav.save();
2200
+ // else
2201
+ repaint(); // start loop // may 2013
2202
+ }
2203
+
2204
+ public void ToggleSupport()
2205
+ {
2206
+ SUPPORT ^= true;
2207
+ }
2208
+
2209
+ public void ToggleAbort()
2210
+ {
2211
+ ABORTMODE ^= true;
2212
+ }
2213
+
2214
+ public void ToggleInertia()
2215
+ {
2216
+ INERTIA ^= true;
2217
+ }
2218
+
2219
+ public void ToggleFast()
15022220 {
15032221 FAST ^= true;
15042222 }
15052223
1506
- void ToggleSlowPose()
2224
+ public void ToggleSlowPose()
15072225 {
15082226 SLOWPOSE ^= true;
15092227 }
15102228
1511
- void ToggleFootContact()
1512
- {
1513
- FOOTCONTACT ^= true;
1514
- }
1515
-
1516
- void ToggleBoxMode()
2229
+ public void ToggleBoxMode()
15172230 {
15182231 BOXMODE ^= true;
15192232 }
15202233
1521
- void ToggleSmoothFocus()
2234
+ public void ToggleZoomBoxMode()
2235
+ {
2236
+ ZOOMBOXMODE ^= true;
2237
+ }
2238
+
2239
+ public void ToggleSmoothFocus()
15222240 {
15232241 SMOOTHFOCUS ^= true;
15242242 }
15252243
1526
- void ToggleImageFlip()
2244
+ public void ToggleImageFlip()
15272245 {
15282246 IMAGEFLIP ^= true;
15292247 }
15302248
1531
- void ToggleSpeakerMocap()
2249
+ public void ToggleSpeakerMocap()
15322250 {
15332251 SPEAKERMOCAP ^= true;
15342252 }
15352253
1536
- void ToggleSpeakerCamera()
2254
+ public void ToggleSpeakerCamera()
15372255 {
15382256 SPEAKERCAMERA ^= true;
15392257 }
15402258
1541
- void ToggleSpeakerFocus()
2259
+ public void ToggleSpeakerFocus()
15422260 {
15432261 SPEAKERFOCUS ^= true;
15442262 }
15452263
1546
- void ToggleDebug()
1547
- {
1548
- DEBUG ^= true;
1549
- }
1550
-
1551
- void ToggleFrustum()
2264
+ public void ToggleFrustum()
15522265 {
15532266 FRUSTUM ^= true;
15542267 }
15552268
1556
- void ToggleTrack()
2269
+ public void ToggleTrack()
15572270 {
15582271 TRACK ^= true;
15592272 if (TRACK)
....@@ -1572,25 +2285,35 @@
15722285 repaint();
15732286 }
15742287
1575
- void ToggleTrackOnce()
2288
+ public void ToggleTrackOnce()
15762289 {
15772290 TRACKONCE ^= true;
15782291 }
15792292
1580
- void ToggleShadowTrack()
2293
+ public void ToggleShadowTrack()
15812294 {
15822295 SHADOWTRACK ^= true;
15832296 repaint();
15842297 }
15852298
1586
- void ToggleOeil()
2299
+ public void ToggleOeil()
15872300 {
15882301 OEIL ^= true;
15892302 }
15902303
1591
- void ToggleOeilOnce()
2304
+ public void ToggleOeilOnce()
15922305 {
15932306 OEILONCE ^= true;
2307
+ }
2308
+
2309
+ void ToggleFootContact()
2310
+ {
2311
+ FOOTCONTACT ^= true;
2312
+ }
2313
+
2314
+ void ToggleDebug()
2315
+ {
2316
+ Globals.DEBUG ^= true;
15942317 }
15952318
15962319 void ToggleLookAt()
....@@ -1598,9 +2321,9 @@
15982321 LOOKAT ^= true;
15992322 }
16002323
1601
- void ToggleRandom()
2324
+ void ToggleSwitch()
16022325 {
1603
- RANDOM ^= true;
2326
+ SWITCH ^= true;
16042327 }
16052328
16062329 void ToggleHandles()
....@@ -1608,10 +2331,17 @@
16082331 HANDLES ^= true;
16092332 }
16102333
2334
+ Object3D paintFolder;
2335
+
16112336 void TogglePaint()
16122337 {
16132338 PAINTMODE ^= true;
16142339 paintcount = 0;
2340
+
2341
+ if (PAINTMODE)
2342
+ {
2343
+ paintFolder = GetFolder();
2344
+ }
16152345 }
16162346
16172347 void SwapCamera(int a, int b)
....@@ -1707,7 +2437,22 @@
17072437 {
17082438 return currentGL;
17092439 }
1710
-
2440
+
2441
+ static private BufferedImage CreateBim(TextureData texturedata)
2442
+ {
2443
+ Grafreed.Assert(texturedata != null);
2444
+
2445
+ int width = texturedata.getWidth();
2446
+ int height = texturedata.getHeight();
2447
+
2448
+ Buffer buffer = texturedata.getBuffer();
2449
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2450
+
2451
+ byte[] bytes = bytebuf.array();
2452
+
2453
+ return CreateBim(bytes, width, height);
2454
+ }
2455
+
17112456 /**/
17122457 class CacheTexture
17132458 {
....@@ -1716,28 +2461,31 @@
17162461
17172462 int resolution;
17182463
1719
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2464
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
17202465 {
1721
- texture = tex;
2466
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2467
+ texturedata = texdata;
17222468 resolution = res;
17232469 }
17242470 }
17252471 /**/
17262472
17272473 // 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>();
2474
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2475
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2476
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2477
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2478
+
17312479 int pigmentdepth = 0;
17322480 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
17332481 int bumpdepth = 0;
17342482 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
17352483 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
17362484 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
1737
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2485
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
17382486 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
17392487
1740
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2488
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
17412489 {
17422490 TextureData texturedata = null;
17432491
....@@ -1756,13 +2504,34 @@
17562504 if (bump)
17572505 texturedata = ConvertBump(texturedata, false);
17582506
1759
- com.sun.opengl.util.texture.Texture texture =
1760
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2507
+// com.sun.opengl.util.texture.Texture texture =
2508
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
17612509
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);
2510
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2511
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
17642512
1765
- return texture;
2513
+ return texturedata;
2514
+ }
2515
+
2516
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2517
+ {
2518
+ TextureData texturedata = null;
2519
+
2520
+ try
2521
+ {
2522
+ texturedata =
2523
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2524
+ bim,
2525
+ true);
2526
+ } catch (Exception e)
2527
+ {
2528
+ throw new javax.media.opengl.GLException(e);
2529
+ }
2530
+
2531
+ if (bump)
2532
+ texturedata = ConvertBump(texturedata, false);
2533
+
2534
+ return texturedata;
17662535 }
17672536
17682537 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -2835,6 +3604,8 @@
28353604
28363605 System.out.println("LOADING TEXTURE : " + name);
28373606
3607
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3608
+
28383609 //
28393610 if (false) // compressbit > 0)
28403611 {
....@@ -3539,6 +4310,7 @@
35394310
35404311 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
35414312 {
4313
+ new Exception().printStackTrace();
35424314 System.exit(0);
35434315 com.sun.opengl.util.texture.Texture texture = null;
35444316
....@@ -7232,7 +8004,7 @@
72328004 String pigment = Object3D.GetPigment(tex);
72338005 String bump = Object3D.GetBump(tex);
72348006
7235
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8007
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
72368008 {
72378009 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
72388010 // System.out.println("; bump = " + bump);
....@@ -7247,11 +8019,69 @@
72478019 pigment = null;
72488020 }
72498021
7250
- ReleaseTexture(bump, true);
7251
- ReleaseTexture(pigment, false);
8022
+ ReleaseTexture(tex, true);
8023
+ ReleaseTexture(tex, false);
72528024 }
72538025
7254
- void ReleaseTexture(String tex, boolean bump)
8026
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8027
+ {
8028
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8029
+ {
8030
+ return;
8031
+ }
8032
+
8033
+ if (tex == null)
8034
+ {
8035
+ ReleaseTexture(null, false);
8036
+ return;
8037
+ }
8038
+
8039
+ String pigment = Object3D.GetPigment(tex);
8040
+
8041
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ {
8043
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8044
+ // System.out.println("; bump = " + bump);
8045
+ }
8046
+
8047
+ if (pigment.equals(""))
8048
+ {
8049
+ pigment = null;
8050
+ }
8051
+
8052
+ ReleaseTexture(tex, false);
8053
+ }
8054
+
8055
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8056
+ {
8057
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8058
+ {
8059
+ return;
8060
+ }
8061
+
8062
+ if (tex == null)
8063
+ {
8064
+ ReleaseTexture(null, true);
8065
+ return;
8066
+ }
8067
+
8068
+ String bump = Object3D.GetBump(tex);
8069
+
8070
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8071
+ {
8072
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8073
+ // System.out.println("; bump = " + bump);
8074
+ }
8075
+
8076
+ if (bump.equals(""))
8077
+ {
8078
+ bump = null;
8079
+ }
8080
+
8081
+ ReleaseTexture(tex, true);
8082
+ }
8083
+
8084
+ void ReleaseTexture(cTexture tex, boolean bump)
72558085 {
72568086 if (// DrawMode() != 0 || /*tex == null ||*/
72578087 ambientOcclusion ) // || !textureon)
....@@ -7262,7 +8092,7 @@
72628092 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
72638093
72648094 if (tex != null)
7265
- texture = textures.get(tex);
8095
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
72668096
72678097 // //assert( texture != null );
72688098 // if (texture == null)
....@@ -7354,7 +8184,55 @@
73548184 }
73558185 }
73568186
7357
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8187
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8188
+ {
8189
+// if (// DrawMode() != 0 || /*tex == null ||*/
8190
+// ambientOcclusion ) // || !textureon)
8191
+// {
8192
+// return; // false;
8193
+// }
8194
+//
8195
+// if (tex == null)
8196
+// {
8197
+// BindTexture(null,false,resolution);
8198
+// BindTexture(null,true,resolution);
8199
+// return;
8200
+// }
8201
+//
8202
+// String pigment = Object3D.GetPigment(tex);
8203
+// String bump = Object3D.GetBump(tex);
8204
+//
8205
+// usedtextures.add(pigment);
8206
+// usedtextures.add(bump);
8207
+//
8208
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8209
+// {
8210
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8211
+// // System.out.println("; bump = " + bump);
8212
+// }
8213
+//
8214
+// if (bump.equals(""))
8215
+// {
8216
+// bump = null;
8217
+// }
8218
+// if (pigment.equals(""))
8219
+// {
8220
+// pigment = null;
8221
+// }
8222
+//
8223
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8224
+// BindTexture(pigment, false, resolution);
8225
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8226
+// BindTexture(bump, true, resolution);
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+//
8229
+// return; // true;
8230
+
8231
+ BindPigmentTexture(tex, resolution);
8232
+ BindBumpTexture(tex, resolution);
8233
+ }
8234
+
8235
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
73588236 {
73598237 if (// DrawMode() != 0 || /*tex == null ||*/
73608238 ambientOcclusion ) // || !textureon)
....@@ -7365,17 +8243,47 @@
73658243 if (tex == null)
73668244 {
73678245 BindTexture(null,false,resolution);
7368
- BindTexture(null,true,resolution);
73698246 return;
73708247 }
73718248
73728249 String pigment = Object3D.GetPigment(tex);
8250
+
8251
+ usedtextures.add(tex);
8252
+
8253
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8254
+ {
8255
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8256
+ // System.out.println("; bump = " + bump);
8257
+ }
8258
+
8259
+ if (pigment.equals(""))
8260
+ {
8261
+ pigment = null;
8262
+ }
8263
+
8264
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8265
+ BindTexture(tex, false, resolution);
8266
+ }
8267
+
8268
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8269
+ {
8270
+ if (// DrawMode() != 0 || /*tex == null ||*/
8271
+ ambientOcclusion ) // || !textureon)
8272
+ {
8273
+ return; // false;
8274
+ }
8275
+
8276
+ if (tex == null)
8277
+ {
8278
+ BindTexture(null,true,resolution);
8279
+ return;
8280
+ }
8281
+
73738282 String bump = Object3D.GetBump(tex);
73748283
7375
- usedtextures.put(pigment, pigment);
7376
- usedtextures.put(bump, bump);
8284
+ usedtextures.add(tex);
73778285
7378
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8286
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
73798287 {
73808288 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
73818289 // System.out.println("; bump = " + bump);
....@@ -7385,43 +8293,82 @@
73858293 {
73868294 bump = null;
73878295 }
7388
- if (pigment.equals(""))
7389
- {
7390
- pigment = null;
7391
- }
73928296
7393
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7394
- BindTexture(pigment, false, resolution);
73958297 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7396
- BindTexture(bump, true, resolution);
8298
+ BindTexture(tex, true, resolution);
73978299 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7398
-
7399
- return; // true;
74008300 }
74018301
7402
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8302
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8303
+
8304
+ private boolean FileExists(String tex)
74038305 {
7404
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8306
+ if (missingTextures.contains(tex))
8307
+ {
8308
+ return false;
8309
+ }
8310
+
8311
+ boolean fileExists = new File(tex).exists();
8312
+
8313
+ if (!fileExists)
8314
+ {
8315
+ // If file exists, the "new File()" is not executed sgain
8316
+ missingTextures.add(tex);
8317
+ }
8318
+
8319
+ return fileExists;
8320
+ }
8321
+
8322
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8323
+ {
8324
+ CacheTexture texturecache = null;
74058325
74068326 if (tex != null)
74078327 {
7408
- String texname = tex;
8328
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8329
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
74098330
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;
8331
+ if (texname.equals("") && texdata == null)
8332
+ {
8333
+ return null;
8334
+ }
8335
+
8336
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8337
+
8338
+// String[] split = tex.split("Textures");
8339
+// if (split.length > 1)
8340
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8341
+// else
8342
+// if (!texname.startsWith("/"))
8343
+// texname = "/Users/nbriere/Textures/" + texname;
8344
+ if (!FileExists(texname))
8345
+ {
8346
+ texname = fallbackTextureName;
8347
+ }
74168348
74178349 if (CACHETEXTURE)
7418
- texture = textures.get(texname); // TEXTURE CACHE
7419
-
7420
- TextureData texturedata = null;
7421
-
7422
- if (texture == null || texture.resolution < resolution)
74238350 {
7424
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8351
+ if (texdata == null)
8352
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8353
+ else
8354
+ texturecache = bimtextures.get(texdata);
8355
+ }
8356
+
8357
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8358
+ {
8359
+ TextureData texturedata = null;
8360
+
8361
+ if (texdata != null)
8362
+ {
8363
+ BufferedImage bim = //new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8364
+
8365
+ CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8366
+
8367
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8368
+ bimtextures.put(texdata, texturecache);
8369
+ }
8370
+ else
8371
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
74258372 {
74268373 assert(!bump);
74278374 // if (bump)
....@@ -7432,19 +8379,23 @@
74328379 // }
74338380 // else
74348381 // {
7435
- texture = textures.get(tex);
7436
- if (texture == null)
8382
+ // texturecache = textures.get(texname); // suspicious
8383
+ if (texturecache == null)
74378384 {
7438
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8385
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
74398386 }
8387
+ else
8388
+ new Exception().printStackTrace();
74408389 // }
74418390 } else
7442
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8391
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
74438392 {
74448393 assert(bump);
7445
- texture = textures.get(tex);
7446
- if (texture == null)
7447
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8394
+ // texturecache = textures.get(texname); // suspicious
8395
+ if (texturecache == null)
8396
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8397
+ else
8398
+ new Exception().printStackTrace();
74488399 } else
74498400 {
74508401 //if (tex.equals("IMMORTAL"))
....@@ -7452,11 +8403,13 @@
74528403 // texture = GetResourceTexture("default.png");
74538404 //} else
74548405 //{
7455
- if (tex.equals("WHITE_NOISE"))
8406
+ if (texname.endsWith("WHITE_NOISE"))
74568407 {
7457
- texture = textures.get(tex);
7458
- if (texture == null)
7459
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8408
+ // texturecache = textures.get(texname); // suspicious
8409
+ if (texturecache == null)
8410
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8411
+ else
8412
+ new Exception().printStackTrace();
74608413 } else
74618414 {
74628415 if (textureon)
....@@ -7481,7 +8434,7 @@
74818434 }
74828435
74838436 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7484
- if (!new File(cachename).exists())
8437
+ if (!FileExists(cachename))
74858438 cachename = texname;
74868439 else
74878440 processbump = false; // don't process bump map again
....@@ -7503,7 +8456,7 @@
75038456 }
75048457
75058458 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7506
- if (!new File(cachename).exists())
8459
+ if (!FileExists(cachename))
75078460 cachename = texname;
75088461 else
75098462 processbump = false; // don't process bump map again
....@@ -7512,20 +8465,22 @@
75128465 texturedata = GetFileTexture(cachename, processbump, resolution);
75138466
75148467
7515
- if (texturedata != null)
7516
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8468
+ if (texturedata == null)
8469
+ throw new Exception();
8470
+
8471
+ texturecache = new CacheTexture(texturedata,resolution);
75178472 //texture = GetTexture(tex, bump);
75188473 }
75198474 }
75208475 //}
75218476 }
75228477
7523
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8478
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
75248479 {
75258480 //return false;
75268481
75278482 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7528
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8483
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
75298484 {
75308485 // String ext = "_highres";
75318486 // if (REDUCETEXTURE)
....@@ -7542,52 +8497,17 @@
75428497 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
75438498 if (!cachefile.exists())
75448499 {
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))
8500
+ //if (texturedata.getWidth() == texturedata.getHeight())
75548501 {
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);
8502
+ BufferedImage rendImage = CreateBim(texturedata);
8503
+
75858504 ImageWriter writer = null;
75868505 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
75878506 if (iter.hasNext()) {
75888507 writer = (ImageWriter)iter.next();
75898508 }
7590
- float compressionQuality = 0.9f;
8509
+
8510
+ float compressionQuality = 0.85f;
75918511 try
75928512 {
75938513 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7604,18 +8524,20 @@
76048524 }
76058525 }
76068526 }
7607
-
8527
+
8528
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8529
+
76088530 //System.out.println("Texture = " + tex);
7609
- if (textures.containsKey(texname))
8531
+ if (textures.containsKey(tex))
76108532 {
7611
- CacheTexture thetex = textures.get(texname);
8533
+ CacheTexture thetex = textures.get(tex);
76128534 thetex.texture.disable();
76138535 thetex.texture.dispose();
7614
- textures.remove(texname);
8536
+ textures.remove(tex);
76158537 }
76168538
7617
- texture.texturedata = texturedata;
7618
- textures.put(texname, texture);
8539
+ //texture.texturedata = texturedata;
8540
+ textures.put(tex, texturecache);
76198541
76208542 // newtex = true;
76218543 }
....@@ -7631,10 +8553,41 @@
76318553 }
76328554 }
76338555
7634
- return texture;
8556
+ return texturecache;
76358557 }
76368558
7637
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8559
+ static void EmbedTextures(cTexture tex)
8560
+ {
8561
+ if (tex.pigmentdata == null)
8562
+ {
8563
+ String texname = Object3D.GetPigment(tex);
8564
+
8565
+ CacheTexture texturecache = texturepigment.get(tex);
8566
+
8567
+ if (texturecache != null)
8568
+ {
8569
+ tex.pigmentdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
8570
+ tex.pw = texturecache.texturedata.getWidth();
8571
+ tex.ph = texturecache.texturedata.getHeight();
8572
+ }
8573
+ }
8574
+
8575
+ if (tex.bumpdata == null)
8576
+ {
8577
+ String texname = Object3D.GetBump(tex);
8578
+
8579
+ CacheTexture texturecache = texturebump.get(tex);
8580
+
8581
+ if (texturecache != null)
8582
+ {
8583
+ tex.bumpdata = ((ByteBuffer)texturecache.texturedata.getBuffer()).array();
8584
+ tex.bw = texturecache.texturedata.getWidth();
8585
+ tex.bh = texturecache.texturedata.getHeight();
8586
+ }
8587
+ }
8588
+ }
8589
+
8590
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
76388591 {
76398592 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
76408593
....@@ -7652,21 +8605,21 @@
76528605 return texture!=null?texture.texture:null;
76538606 }
76548607
7655
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8608
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
76568609 {
76578610 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
76588611
76598612 return texture!=null?texture.texturedata:null;
76608613 }
76618614
7662
- boolean BindTexture(String tex, boolean bump, int resolution)
8615
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
76638616 {
76648617 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
76658618 {
76668619 return false;
76678620 }
76688621
7669
- boolean newtex = false;
8622
+ //boolean newtex = false;
76708623
76718624 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
76728625
....@@ -7698,7 +8651,7 @@
76988651 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
76998652 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
77008653
7701
- return newtex;
8654
+ return true; // Warning: not used.
77028655 }
77038656
77048657 ShadowBuffer shadowPBuf;
....@@ -8536,11 +9489,35 @@
85369489 jy8[3] = 0.5f;
85379490 }
85389491
8539
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9492
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
85409493 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
85419494 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
85429495 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
85439496
9497
+ void ResetOptions()
9498
+ {
9499
+ options1[0] = 100;
9500
+ options1[1] = 0.025f;
9501
+ options1[2] = 0.01f;
9502
+ options1[3] = 0;
9503
+ options1[4] = 0;
9504
+
9505
+ options2[0] = 0;
9506
+ options2[1] = 0.75f;
9507
+ options2[2] = 0;
9508
+ options2[3] = 0;
9509
+
9510
+ options3[0] = 1;
9511
+ options3[1] = 1;
9512
+ options3[2] = 1;
9513
+ options3[3] = 0;
9514
+
9515
+ options4[0] = 1;
9516
+ options4[1] = 0;
9517
+ options4[2] = 1;
9518
+ options4[3] = 0;
9519
+ }
9520
+
85449521 static int imagecount = 0; // movie generation
85459522
85469523 static int jitter = 0;
....@@ -8636,8 +9613,8 @@
86369613 assert (parentcam != renderCamera);
86379614
86389615 if (renderCamera != lightCamera)
8639
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8640
- LA.matConcat(matrix, parentcam.toParent, matrix);
9616
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9617
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
86419618
86429619 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
86439620
....@@ -8652,8 +9629,8 @@
86529629 LA.matCopy(renderCamera.fromScreen, matrix);
86539630
86549631 if (renderCamera != lightCamera)
8655
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8656
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9632
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9633
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
86579634
86589635 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
86599636
....@@ -8725,7 +9702,7 @@
87259702 //gl.glFlush();
87269703 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
87279704
8728
- if (ANIMATION && ABORTED)
9705
+ if (Globals.ANIMATION && ABORTED)
87299706 {
87309707 System.err.println(" ABORTED FRAME");
87319708 break;
....@@ -8755,7 +9732,7 @@
87559732 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
87569733
87579734 // save image
8758
- if (ANIMATION && !ABORTED)
9735
+ if (Globals.ANIMATION && !ABORTED)
87599736 {
87609737 VPwidth = viewport[2];
87619738 VPheight = viewport[3];
....@@ -8866,11 +9843,11 @@
88669843
88679844 // imagecount++;
88689845
8869
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9846
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
88709847
88719848 if (!BOXMODE)
88729849 {
8873
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9850
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
88749851 }
88759852
88769853 if (!BOXMODE)
....@@ -8908,7 +9885,7 @@
89089885 ABORTED = false;
89099886 }
89109887 else
8911
- GrafreeD.wav.cursor += 735 * ACSIZE;
9888
+ Grafreed.wav.cursor += 735 * ACSIZE;
89129889
89139890 if (false)
89149891 {
....@@ -9571,11 +10548,11 @@
957110548
957210549 public void display(GLAutoDrawable drawable)
957310550 {
9574
- if (GrafreeD.savesound && GrafreeD.hassound)
10551
+ if (Grafreed.savesound && Grafreed.hassound)
957510552 {
9576
- GrafreeD.wav.save();
9577
- GrafreeD.savesound = false;
9578
- GrafreeD.hassound = false;
10553
+ Grafreed.wav.save();
10554
+ Grafreed.savesound = false;
10555
+ Grafreed.hassound = false;
957910556 }
958010557 // if (DEBUG_SELECTION)
958110558 // {
....@@ -9651,6 +10628,7 @@
965110628 ANTIALIAS = 0;
965210629 //System.out.println("RESTART");
965310630 AAtimer.restart();
10631
+ Globals.TIMERRUNNING = true;
965410632 }
965510633 }
965610634 }
....@@ -9705,7 +10683,7 @@
970510683 Object3D theobject = object;
970610684 Object3D theparent = object.parent;
970710685 object.parent = null;
9708
- object = (Object3D)GrafreeD.clone(object);
10686
+ object = (Object3D)Grafreed.clone(object);
970910687 object.Stripify();
971010688 if (theobject.selection == null || theobject.selection.Size() == 0)
971110689 theobject.PreprocessOcclusion(this);
....@@ -9718,13 +10696,14 @@
971810696 ambientOcclusion = false;
971910697 }
972010698
9721
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10699
+ if (//Globals.lighttouched &&
10700
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
972210701 {
972310702 //if (RENDERSHADOW) // ?
972410703 if (!IsFrozen())
972510704 {
972610705 // dec 2012
9727
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10706
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
972810707 {
972910708 Globals.framecount++;
973010709 shadowbuffer.display();
....@@ -9851,8 +10830,8 @@
985110830
985210831 // if (parentcam != renderCamera) // not a light
985310832 if (cam != lightCamera)
9854
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9855
- LA.matConcat(matrix, parentcam.toParent, matrix);
10833
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10834
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
985610835
985710836 for (int j = 0; j < 4; j++)
985810837 {
....@@ -9866,8 +10845,8 @@
986610845
986710846 // if (parentcam != renderCamera) // not a light
986810847 if (cam != lightCamera)
9869
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9870
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10848
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10849
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
987110850
987210851 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
987310852
....@@ -10126,7 +11105,16 @@
1012611105 // Bump noise
1012711106 gl.glActiveTexture(GL.GL_TEXTURE6);
1012811107 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10129
- BindTexture(NOISE_TEXTURE, false, 2);
11108
+
11109
+ try
11110
+ {
11111
+ BindTexture(NOISE_TEXTURE, false, 2);
11112
+ }
11113
+ catch (Exception e)
11114
+ {
11115
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11116
+ }
11117
+
1013011118
1013111119 gl.glActiveTexture(GL.GL_TEXTURE0);
1013211120 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10149,9 +11137,9 @@
1014911137
1015011138 gl.glMatrixMode(GL.GL_MODELVIEW);
1015111139
10152
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10153
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10154
-//gl.glEnable(gl.GL_MULTISAMPLE);
11140
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11141
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11142
+gl.glEnable(gl.GL_MULTISAMPLE);
1015511143 } else
1015611144 {
1015711145 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10162,7 +11150,7 @@
1016211150 //System.out.println("BLENDING ON");
1016311151 gl.glEnable(GL.GL_BLEND);
1016411152 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10165
-
11153
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1016611154 gl.glMatrixMode(gl.GL_PROJECTION);
1016711155 gl.glLoadIdentity();
1016811156
....@@ -10251,8 +11239,8 @@
1025111239 System.err.println("parentcam != renderCamera");
1025211240
1025311241 // if (cam != lightCamera)
10254
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10255
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11242
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11243
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1025611244 }
1025711245
1025811246 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10273,8 +11261,8 @@
1027311261 if (true) // TODO
1027411262 {
1027511263 if (cam != lightCamera)
10276
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10277
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11264
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11265
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1027811266 }
1027911267
1028011268 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10340,7 +11328,7 @@
1034011328 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
1034111329 //System.out.println("fragmentMode = " + fragmentMode);
1034211330
10343
- if (DrawMode() == DEFAULT || DrawMode() == SELECTION || DEBUG_SELECTION)
11331
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
1034411332 {
1034511333 /*
1034611334 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -10590,8 +11578,14 @@
1059011578 {
1059111579 renderpass++;
1059211580 // System.out.println("Draw object... ");
11581
+ STEP = 1;
1059311582 if (FAST) // in case there is no script
10594
- STEP = 16;
11583
+ STEP = 8;
11584
+
11585
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11586
+ {
11587
+ STEP *= 4;
11588
+ }
1059511589
1059611590 //object.FullInvariants();
1059711591
....@@ -10605,23 +11599,44 @@
1060511599 e.printStackTrace();
1060611600 }
1060711601
10608
- if (GrafreeD.RENDERME > 0)
10609
- GrafreeD.RENDERME--; // mechante magouille
11602
+ if (Grafreed.RENDERME > 0)
11603
+ Grafreed.RENDERME--; // mechante magouille
1061011604
1061111605 Globals.ONESTEP = false;
1061211606 }
1061311607
1061411608 static boolean zoomonce = false;
1061511609
11610
+ static void CreateSelectedPoint()
11611
+ {
11612
+ if (selectedpoint == null)
11613
+ {
11614
+ debugpointG = new Sphere();
11615
+ debugpointP = new Sphere();
11616
+ debugpointC = new Sphere();
11617
+ debugpointR = new Sphere();
11618
+
11619
+ selectedpoint = new Superellipsoid();
11620
+
11621
+ for (int i=0; i<8; i++)
11622
+ {
11623
+ debugpoints[i] = new Sphere();
11624
+ }
11625
+ }
11626
+ }
11627
+
1061611628 void DrawObject(GL gl, boolean draw)
1061711629 {
11630
+ // To clear camera values
11631
+ ResetOptions();
11632
+
1061811633 //System.out.println("DRAW OBJECT " + mouseDown);
1061911634 // DrawMode() = SELECTION;
1062011635 //GL gl = getGL();
1062111636 if ((TRACK || SHADOWTRACK) || zoomonce)
1062211637 {
1062311638 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10624
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11639
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1062511640 pingthread.StepToTarget(true); // true);
1062611641 // zoomonce = false;
1062711642 }
....@@ -10641,7 +11656,7 @@
1064111656 callist = gl.glGenLists(1);
1064211657 }
1064311658
10644
- boolean selectmode = DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
11659
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
1064511660
1064611661 boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
1064711662
....@@ -10676,7 +11691,14 @@
1067611691
1067711692 usedtextures.clear();
1067811693
10679
- BindTextures(DEFAULT_TEXTURES, 2);
11694
+ try
11695
+ {
11696
+ BindTextures(DEFAULT_TEXTURES, 2);
11697
+ }
11698
+ catch (Exception e)
11699
+ {
11700
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11701
+ }
1068011702 }
1068111703 //System.out.println("--> " + stackdepth);
1068211704 // GrafreeD.traceon();
....@@ -10686,8 +11708,9 @@
1068611708
1068711709 if (DrawMode() == DEFAULT)
1068811710 {
10689
- if (DEBUG)
11711
+ if (Globals.DEBUG)
1069011712 {
11713
+ CreateSelectedPoint();
1069111714 float radius = 0.05f;
1069211715 if (selectedpoint.radius != radius)
1069311716 {
....@@ -10741,20 +11764,32 @@
1074111764 ReleaseTextures(DEFAULT_TEXTURES);
1074211765
1074311766 if (CLEANCACHE)
10744
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11767
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1074511768 {
10746
- String tex = e.nextElement();
11769
+ cTexture tex = e.nextElement();
1074711770
1074811771 // System.out.println("Texture --------- " + tex);
1074911772
10750
- if (tex.equals("WHITE_NOISE"))
11773
+ if (tex.equals("WHITE_NOISE:"))
1075111774 continue;
1075211775
10753
- if (!usedtextures.containsKey(tex))
11776
+ if (!usedtextures.contains(tex))
1075411777 {
11778
+ CacheTexture gettex = texturepigment.get(tex);
1075511779 // System.out.println("DISPOSE +++++++++++++++ " + tex);
10756
- textures.get(tex).texture.dispose();
10757
- textures.remove(tex);
11780
+ if (gettex != null)
11781
+ {
11782
+ gettex.texture.dispose();
11783
+ texturepigment.remove(tex);
11784
+ }
11785
+
11786
+ gettex = texturebump.get(tex);
11787
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11788
+ if (gettex != null)
11789
+ {
11790
+ gettex.texture.dispose();
11791
+ texturebump.remove(tex);
11792
+ }
1075811793 }
1075911794 }
1076011795 }
....@@ -10767,7 +11802,14 @@
1076711802 if (checker != null && DrawMode() == DEFAULT)
1076811803 {
1076911804 //BindTexture(IMMORTAL_TEXTURE);
10770
- BindTextures(checker.GetTextures(), checker.texres);
11805
+ try
11806
+ {
11807
+ BindTextures(checker.GetTextures(), checker.texres);
11808
+ }
11809
+ catch (Exception e)
11810
+ {
11811
+ System.err.println("FAILED: " + checker.GetTextures());
11812
+ }
1077111813 // NEAREST
1077211814 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1077311815 DrawChecker(gl);
....@@ -10849,7 +11891,7 @@
1084911891 return;
1085011892 }
1085111893
10852
- String string = obj.GetToolTip();
11894
+ String string = obj.toString(); //.GetToolTip();
1085311895
1085411896 GL gl = GetGL();
1085511897
....@@ -11166,8 +12208,8 @@
1116612208 //obj.TransformToWorld(light, light);
1116712209 for (int i = tp.size(); --i >= 0;)
1116812210 {
11169
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11170
- LA.xformPos(light, tp.get(i).toParent, light);
12211
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12212
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1117112213 }
1117212214
1117312215
....@@ -11184,8 +12226,8 @@
1118412226 parentcam = cameras[0];
1118512227 }
1118612228
11187
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11188
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12229
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12230
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1118912231
1119012232 LA.xformPos(light, renderCamera.toScreen, light);
1119112233
....@@ -11799,8 +12841,8 @@
1179912841
1180012842 // display shadow only (bump == 0)
1180112843 "SUB temp.x, half.x, shadow.x;" +
11802
- "MOV temp.y, -params6.x;" +
11803
- "SLT temp.z, temp.y, zero.x;" +
12844
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12845
+ "SLT temp.z, temp.y, -one2048th.x;" +
1180412846 "SUB temp.y, one.x, temp.z;" +
1180512847 "MUL temp.x, temp.x, temp.y;" +
1180612848 "KIL temp.x;" +
....@@ -11929,8 +12971,10 @@
1192912971 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1193012972
1193112973 "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
12974
+ // Tuning for default skin
12975
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
12976
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
12977
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1193412978 "MUL temp.x, temp.x, temp.y;" +
1193512979
1193612980 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12129,7 +13173,7 @@
1212913173 //once = true;
1213013174 }
1213113175
12132
- System.out.print("Program #" + mode + "; length = " + program.length());
13176
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1213313177 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1213413178 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1213513179
....@@ -12262,12 +13306,16 @@
1226213306
1226313307 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1226413308 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13309
+
13310
+ // Compare fragment depth in light space with shadowmap.
1226513311 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1226613312 "SGE temp.y, temp.x, zero.x;" +
12267
- "SUB " + shadow + ".y, one.x, temp.y;" +
13313
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13314
+
13315
+ // Reverse comparison
1226813316 "SUB temp.x, one.x, temp.x;" +
1226913317 "MUL " + shadow + ".x, temp.x, temp.y;" +
12270
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13318
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1227113319 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1227213320
1227313321 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12281,6 +13329,10 @@
1228113329 // No shadow for backface
1228213330 "DP3 temp.x, normal, lightd;" +
1228313331 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13332
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13333
+
13334
+ // No shadow when out of frustrum
13335
+ "SGE temp.x, " + depth + ".z, one.z;" +
1228413336 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1228513337 "";
1228613338 }
....@@ -12427,7 +13479,8 @@
1242713479 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1242813480 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1242913481 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12430
- Object3D.cVector2[] vector2buffer;
13482
+
13483
+ //Object3D.cVector2[] vector2buffer;
1243113484
1243213485 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1243313486 // OUT : diff, spec
....@@ -12443,9 +13496,10 @@
1244313496 "DP3 " + dest + ".z," + "normals," + "eye;" +
1244413497 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1244513498 //"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;" +
13499
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13500
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13501
+
13502
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1244913503 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1245013504 "RCP " + dest + ".w," + dest + ".w;" +
1245113505 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -12839,7 +13893,7 @@
1283913893 public void mousePressed(MouseEvent e)
1284013894 {
1284113895 //System.out.println("mousePressed: " + e);
12842
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
13896
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1284313897 }
1284413898
1284513899 static long prevtime = 0;
....@@ -12866,6 +13920,7 @@
1286613920
1286713921 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1286813922
13923
+ if (BUTTONLESSWHEEL)
1286913924 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1287013925 {
1287113926 return;
....@@ -12874,7 +13929,7 @@
1287413929 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1287513930
1287613931 // TIMER
12877
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
13932
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1287813933 {
1287913934 keepboxmode = BOXMODE;
1288013935 keepsupport = SUPPORT;
....@@ -12914,8 +13969,8 @@
1291413969 // mode |= META;
1291513970 //}
1291613971
12917
- SetMouseMode(WHEEL | e.getModifiersEx());
12918
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
13972
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
13973
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1291913974 anchorX = ax;
1292013975 anchorY = ay;
1292113976 prevX = px;
....@@ -12949,6 +14004,7 @@
1294914004 else
1295014005 if (evt.getSource() == AAtimer)
1295114006 {
14007
+ Globals.TIMERRUNNING = false;
1295214008 if (mouseDown)
1295314009 {
1295414010 //new Exception().printStackTrace();
....@@ -12974,6 +14030,10 @@
1297414030 // LIVE = waslive;
1297514031 // wasliveok = true;
1297614032 // waslive = false;
14033
+
14034
+ // May 2019 Forget it:
14035
+ if (true)
14036
+ return;
1297714037
1297814038 // source == timer
1297914039 if (mouseDown)
....@@ -13004,7 +14064,7 @@
1300414064
1300514065 // fev 2014???
1300614066 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13007
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14067
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1300814068 pingthread.StepToTarget(true); // true);
1300914069 }
1301014070 // if (!LIVE)
....@@ -13013,12 +14073,13 @@
1301314073
1301414074 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1301514075
13016
- void clickStart(int x, int y, int modifiers)
14076
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1301714077 {
1301814078 if (!wasliveok)
1301914079 return;
1302014080
1302114081 AAtimer.restart(); //
14082
+ Globals.TIMERRUNNING = true;
1302214083
1302314084 // waslive = LIVE;
1302414085 // LIVE = false;
....@@ -13030,7 +14091,7 @@
1303014091 // touched = true; // main DL
1303114092 if (isRenderer)
1303214093 {
13033
- SetMouseMode(modifiers);
14094
+ SetMouseMode(modifiers, modifiersex);
1303414095 }
1303514096
1303614097 selectX = anchorX = x;
....@@ -13043,7 +14104,7 @@
1304314104 clicked = true;
1304414105 hold = false;
1304514106
13046
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14107
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1304714108 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1304814109 {
1304914110 // System.out.println("RESTART II " + modifiers);
....@@ -13074,7 +14135,7 @@
1307414135 info.camera = renderCamera;
1307514136 info.x = x;
1307614137 info.y = y;
13077
- info.modifiers = modifiers;
14138
+ info.modifiers = modifiersex;
1307814139 editObj = object.doEditClick(info, 0);
1307914140 if (!editObj)
1308014141 {
....@@ -13091,11 +14152,14 @@
1309114152
1309214153 public void mouseDragged(MouseEvent e)
1309314154 {
14155
+ Globals.MOUSEDRAGGED = true;
14156
+
14157
+ //System.out.println("mouseDragged: " + e);
1309414158 if (isRenderer)
1309514159 movingcamera = true;
14160
+
1309614161 //if (drawing)
1309714162 //return;
13098
- //System.out.println("mouseDragged: " + e);
1309914163 if ((e.getModifiersEx() & CTRL) != 0
1310014164 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1310114165 {
....@@ -13103,7 +14167,7 @@
1310314167 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1310414168 }
1310514169 else
13106
- drag(e.getX(), e.getY(), e.getModifiersEx());
14170
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1310714171
1310814172 //try { Thread.sleep(1); } catch (Exception ex) {}
1310914173 }
....@@ -13115,6 +14179,11 @@
1311514179 cVector tmp = new cVector();
1311614180 cVector tmp2 = new cVector();
1311714181 boolean isMoving;
14182
+
14183
+ public cVector TargetLookAt()
14184
+ {
14185
+ return targetLookAt;
14186
+ }
1311814187
1311914188 class PingThread extends Thread
1312014189 {
....@@ -13271,6 +14340,7 @@
1327114340
1327214341 public void run()
1327314342 {
14343
+ new Exception().printStackTrace();
1327414344 System.exit(0);
1327514345 for (;;)
1327614346 {
....@@ -13334,7 +14404,7 @@
1333414404 {
1333514405 Globals.lighttouched = true;
1333614406 }
13337
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14407
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1333814408 }
1333914409 //else
1334014410 }
....@@ -13348,12 +14418,12 @@
1334814418 void GoDown(int mod)
1334914419 {
1335014420 MODIFIERS |= COMMAND;
13351
- /*
14421
+ /**/
1335214422 if((mod&SHIFT) == SHIFT)
1335314423 manipCamera.RotatePosition(0, -speed);
1335414424 else
13355
- manipCamera.BackForth(0, -speed*delta, getWidth());
13356
- */
14425
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14426
+ /**/
1335714427 if ((mod & SHIFT) == SHIFT)
1335814428 {
1335914429 mouseMode = mouseMode; // VR??
....@@ -13369,12 +14439,12 @@
1336914439 void GoUp(int mod)
1337014440 {
1337114441 MODIFIERS |= COMMAND;
13372
- /*
14442
+ /**/
1337314443 if((mod&SHIFT) == SHIFT)
1337414444 manipCamera.RotatePosition(0, speed);
1337514445 else
13376
- manipCamera.BackForth(0, speed*delta, getWidth());
13377
- */
14446
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14447
+ /**/
1337814448 if ((mod & SHIFT) == SHIFT)
1337914449 {
1338014450 mouseMode = mouseMode;
....@@ -13390,12 +14460,12 @@
1339014460 void GoLeft(int mod)
1339114461 {
1339214462 MODIFIERS |= COMMAND;
13393
- /*
14463
+ /**/
1339414464 if((mod&SHIFT) == SHIFT)
13395
- manipCamera.RotatePosition(speed, 0);
13396
- else
1339714465 manipCamera.Translate(speed*delta, 0, getWidth());
13398
- */
14466
+ else
14467
+ manipCamera.RotatePosition(speed, 0);
14468
+ /**/
1339914469 if ((mod & SHIFT) == SHIFT)
1340014470 {
1340114471 mouseMode = mouseMode;
....@@ -13411,12 +14481,12 @@
1341114481 void GoRight(int mod)
1341214482 {
1341314483 MODIFIERS |= COMMAND;
13414
- /*
14484
+ /**/
1341514485 if((mod&SHIFT) == SHIFT)
13416
- manipCamera.RotatePosition(-speed, 0);
13417
- else
1341814486 manipCamera.Translate(-speed*delta, 0, getWidth());
13419
- */
14487
+ else
14488
+ manipCamera.RotatePosition(-speed, 0);
14489
+ /**/
1342014490 if ((mod & SHIFT) == SHIFT)
1342114491 {
1342214492 mouseMode = mouseMode;
....@@ -13434,7 +14504,7 @@
1343414504 int X, Y;
1343514505 boolean SX, SY;
1343614506
13437
- void drag(int x, int y, int modifiers)
14507
+ void drag(int x, int y, int modifiers, int modifiersex)
1343814508 {
1343914509 if (IsFrozen())
1344014510 {
....@@ -13443,17 +14513,17 @@
1344314513
1344414514 drag = true; // NEW
1344514515
13446
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14516
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1344714517
1344814518 X = x;
1344914519 Y = y;
1345014520 // floating state for animation
13451
- MODIFIERS = modifiers;
13452
- modifiers &= ~1024;
14521
+ MODIFIERS = modifiersex;
14522
+ modifiersex &= ~1024;
1345314523 if (false) // modifiers != 0)
1345414524 {
1345514525 //new Exception().printStackTrace();
13456
- System.out.println("mouseDragged: " + modifiers);
14526
+ System.out.println("mouseDragged: " + modifiersex);
1345714527 System.out.println("SHIFT = " + SHIFT);
1345814528 System.out.println("CONTROL = " + COMMAND);
1345914529 System.out.println("META = " + META);
....@@ -13473,7 +14543,8 @@
1347314543 info.camera = renderCamera;
1347414544 info.x = x;
1347514545 info.y = y;
13476
- object.editWindow.copy.doEditDrag(info);
14546
+ object.GetWindow().copy
14547
+ .doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1347714548 } else
1347814549 {
1347914550 if (x < startX)
....@@ -13625,7 +14696,6 @@
1362514696 public void mouseMoved(MouseEvent e)
1362614697 {
1362714698 //System.out.println("mouseMoved: " + e);
13628
-
1362914699 if (isRenderer)
1363014700 return;
1363114701
....@@ -13638,7 +14708,9 @@
1363814708 ci.camera = renderCamera;
1363914709 if (!isRenderer)
1364014710 {
13641
- if (object.editWindow.copy.doEditClick(ci, 0))
14711
+ //ObjEditor editWindow = object.editWindow;
14712
+ //Object3D copy = editWindow.copy;
14713
+ if (object.doEditClick(ci, 0))
1364214714 {
1364314715 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1364414716 } else
....@@ -13650,7 +14722,11 @@
1365014722
1365114723 public void mouseReleased(MouseEvent e)
1365214724 {
14725
+ Globals.MOUSEDRAGGED = false;
14726
+
1365314727 movingcamera = false;
14728
+ X = 0; // getBounds().width/2;
14729
+ Y = 0; // getBounds().height/2;
1365414730 //System.out.println("mouseReleased: " + e);
1365514731 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1365614732 }
....@@ -13673,9 +14749,9 @@
1367314749 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1367414750 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1367514751
13676
- if (control || command || IsFrozen())
14752
+// No delay if (control || command || IsFrozen())
1367714753 timeout = true;
13678
- else
14754
+// ?? May 2019 else
1367914755 // timer.setDelay((modifiers & 128) != 0?0:350);
1368014756 mouseDown = false;
1368114757 if (!control && !command) // june 2013
....@@ -13785,7 +14861,7 @@
1378514861 System.out.println("keyReleased: " + e);
1378614862 }
1378714863
13788
- void SetMouseMode(int modifiers)
14864
+ void SetMouseMode(int modifiers, int modifiersex)
1378914865 {
1379014866 //System.out.println("SetMouseMode = " + modifiers);
1379114867 //modifiers &= ~1024;
....@@ -13797,25 +14873,25 @@
1379714873 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1379814874 // return;
1379914875 //System.out.println("SetMode = " + modifiers);
13800
- if ((modifiers & WHEEL) == WHEEL)
14876
+ if ((modifiersex & WHEEL) == WHEEL)
1380114877 {
1380214878 mouseMode |= ZOOM;
1380314879 }
1380414880
1380514881 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
13806
- if (capsLocked || (modifiers & META) == META)
14882
+ if (capsLocked) // || (modifiers & META) == META)
1380714883 {
1380814884 mouseMode |= VR; // BACKFORTH;
1380914885 }
13810
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
14886
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1381114887 {
1381214888 mouseMode |= SELECT;
1381314889 }
13814
- if ((modifiers & COMMAND) == COMMAND)
14890
+ if ((modifiersex & COMMAND) == COMMAND)
1381514891 {
1381614892 mouseMode |= SELECT;
1381714893 }
13818
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
14894
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1381914895 {
1382014896 mouseMode &= ~VR;
1382114897 mouseMode |= TRANSLATE;
....@@ -13844,10 +14920,10 @@
1384414920
1384514921 if (isRenderer) //
1384614922 {
13847
- SetMouseMode(modifiers);
14923
+ SetMouseMode(0, modifiers);
1384814924 }
1384914925
13850
- theRenderer.keyPressed(key);
14926
+ Globals.theRenderer.keyPressed(key);
1385114927 }
1385214928
1385314929 int kompactbit = 4; // power bit
....@@ -13859,7 +14935,7 @@
1385914935 float SATPOW = 1; // 2; // 0.5f;
1386014936 float BRIPOW = 1; // 0.5f; // 0.5f;
1386114937
13862
- void keyPressed(int key)
14938
+ public void keyPressed(int key)
1386314939 {
1386414940 if (key >= '0' && key <= '5')
1386514941 clampbit = (key-'0');
....@@ -13906,7 +14982,8 @@
1390614982 // break;
1390714983 case 'T':
1390814984 CACHETEXTURE ^= true;
13909
- textures.clear();
14985
+ texturepigment.clear();
14986
+ texturebump.clear();
1391014987 // repaint();
1391114988 break;
1391214989 case 'Y':
....@@ -13991,7 +15068,9 @@
1399115068 case 'E' : COMPACT ^= true;
1399215069 repaint();
1399315070 break;
13994
- case 'W' : DEBUGHSB ^= true;
15071
+ case 'W' : // Wide Window (fullscreen)
15072
+ //DEBUGHSB ^= true;
15073
+ ObjEditor.theFrame.ToggleFullScreen();
1399515074 repaint();
1399615075 break;
1399715076 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14016,8 +15095,8 @@
1401615095 RevertCamera();
1401715096 repaint();
1401815097 break;
14019
- case 'L':
1402015098 case 'l':
15099
+ //case 'L':
1402115100 if (lightMode)
1402215101 {
1402315102 lightMode = false;
....@@ -14160,9 +15239,9 @@
1416015239 case '_':
1416115240 kompactbit = 5;
1416215241 break;
14163
- case '+':
14164
- kompactbit = 6;
14165
- break;
15242
+// case '+':
15243
+// kompactbit = 6;
15244
+// break;
1416615245 case ' ':
1416715246 lightMode ^= true;
1416815247 Globals.lighttouched = true;
....@@ -14174,13 +15253,14 @@
1417415253 case ESC:
1417515254 RENDERPROGRAM += 1;
1417615255 RENDERPROGRAM %= 3;
15256
+
1417715257 repaint();
1417815258 break;
1417915259 case 'Z':
1418015260 //RESIZETEXTURE ^= true;
1418115261 //break;
1418215262 case 'z':
14183
- RENDERSHADOW ^= true;
15263
+ Globals.RENDERSHADOW ^= true;
1418415264 Globals.lighttouched = true;
1418515265 repaint();
1418615266 break;
....@@ -14213,8 +15293,9 @@
1421315293 case DELETE:
1421415294 ClearSelection();
1421515295 break;
14216
- /*
1421715296 case '+':
15297
+
15298
+ /*
1421815299 //fontsize += 1;
1421915300 bbzoom *= 2;
1422015301 repaint();
....@@ -14231,17 +15312,17 @@
1423115312 case '=':
1423215313 IncDepth();
1423315314 //fontsize += 1;
14234
- object.editWindow.refreshContents(true);
15315
+ object.GetWindow().refreshContents(true);
1423515316 maskbit = 6;
1423615317 break;
1423715318 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1423815319 DecDepth();
1423915320 maskbit = 5;
1424015321 //if(fontsize > 1) fontsize -= 1;
14241
- if (object.editWindow == null)
14242
- new Exception().printStackTrace();
14243
- else
14244
- object.editWindow.refreshContents(true);
15322
+// if (object.editWindow == null)
15323
+// new Exception().printStackTrace();
15324
+// else
15325
+ object.GetWindow().refreshContents(true);
1424515326 break;
1424615327 case '{':
1424715328 manipCamera.shaper_fovy /= 1.1;
....@@ -14296,6 +15377,7 @@
1429615377 }
1429715378 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1429815379 }
15380
+
1429915381 static double OCCLUSIONBOOST = 1; // 0.5;
1430015382
1430115383 void keyReleased(int key, int modifiers)
....@@ -14303,11 +15385,11 @@
1430315385 //mode = ROTATE;
1430415386 if ((MODIFIERS & COMMAND) == 0) // VR??
1430515387 {
14306
- SetMouseMode(modifiers);
15388
+ SetMouseMode(0, modifiers);
1430715389 }
1430815390 }
1430915391
14310
- protected void processKeyEvent(KeyEvent e)
15392
+ public void processKeyEvent(KeyEvent e)
1431115393 {
1431215394 switch (e.getID())
1431315395 {
....@@ -14437,8 +15519,9 @@
1443715519
1443815520 protected void processMouseMotionEvent(MouseEvent e)
1443915521 {
14440
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14441
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15522
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15523
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15524
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1444215525 {
1444315526 mouseMoved(e);
1444415527 } else
....@@ -14463,11 +15546,12 @@
1446315546 }
1446415547 */
1446515548
14466
- object.editWindow.EditSelection();
15549
+ object.GetWindow().EditSelection(false);
1446715550 }
1446815551
1446915552 void SelectParent()
1447015553 {
15554
+ new Exception().printStackTrace();
1447115555 System.exit(0);
1447215556 Composite group = (Composite) object;
1447315557 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14479,10 +15563,10 @@
1447915563 {
1448015564 //selectees.remove(i);
1448115565 System.out.println("select parent of " + elem);
14482
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15566
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1448315567 } else
1448415568 {
14485
- group.editWindow.Select(elem.GetTreePath(), first, true);
15569
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1448615570 }
1448715571
1448815572 first = false;
....@@ -14491,6 +15575,7 @@
1449115575
1449215576 void SelectChildren()
1449315577 {
15578
+ new Exception().printStackTrace();
1449415579 System.exit(0);
1449515580 /*
1449615581 Composite group = (Composite) object;
....@@ -14523,12 +15608,12 @@
1452315608 for (int j = 0; j < group.children.size(); j++)
1452415609 {
1452515610 elem = (Object3D) group.children.elementAt(j);
14526
- object.editWindow.Select(elem.GetTreePath(), first, true);
15611
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1452715612 first = false;
1452815613 }
1452915614 } else
1453015615 {
14531
- object.editWindow.Select(elem.GetTreePath(), first, true);
15616
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1453215617 }
1453315618
1453415619 first = false;
....@@ -14539,21 +15624,21 @@
1453915624 {
1454015625 //Composite group = (Composite) object;
1454115626 Object3D group = object;
14542
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15627
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1454315628 }
1454415629
1454515630 void ResetTransform(int mask)
1454615631 {
1454715632 //Composite group = (Composite) object;
1454815633 Object3D group = object;
14549
- group.editWindow.ResetTransform(mask);
15634
+ group.GetWindow().ResetTransform(mask);
1455015635 }
1455115636
1455215637 void FlipTransform()
1455315638 {
1455415639 //Composite group = (Composite) object;
1455515640 Object3D group = object;
14556
- group.editWindow.FlipTransform();
15641
+ group.GetWindow().FlipTransform();
1455715642 // group.editWindow.ReduceMesh(true);
1455815643 }
1455915644
....@@ -14561,7 +15646,7 @@
1456115646 {
1456215647 //Composite group = (Composite) object;
1456315648 Object3D group = object;
14564
- group.editWindow.PrintMemory();
15649
+ group.GetWindow().PrintMemory();
1456515650 // group.editWindow.ReduceMesh(true);
1456615651 }
1456715652
....@@ -14569,7 +15654,7 @@
1456915654 {
1457015655 //Composite group = (Composite) object;
1457115656 Object3D group = object;
14572
- group.editWindow.ResetCentroid();
15657
+ group.GetWindow().ResetCentroid();
1457315658 }
1457415659
1457515660 void IncDepth()
....@@ -14655,7 +15740,9 @@
1465515740 info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1465615741 //Image img = CreateImage(width, height);
1465715742 //System.out.println("width = " + width + "; height = " + height + "\n");
15743
+
1465815744 Graphics gr = g; // img.getGraphics();
15745
+
1465915746 if (!hasMarquee)
1466015747 {
1466115748 if (Xmin < Xmax) // !locked)
....@@ -14743,6 +15830,7 @@
1474315830 info.bounds.y += (height - desired) / 2;
1474415831 }
1474515832 }
15833
+
1474615834 info.g = gr;
1474715835 info.camera = renderCamera;
1474815836 /*
....@@ -14752,15 +15840,55 @@
1475215840 */
1475315841 if (!isRenderer)
1475415842 {
14755
- object.drawEditHandles(info, 0);
15843
+ Grafreed.Assert(object != null);
15844
+ Grafreed.Assert(object.selection != null);
15845
+ if (object.selection.Size() > 0)
15846
+ {
15847
+ int hitSomething = object.selection.get(0).hitSomething;
15848
+
15849
+ info.DX = 0;
15850
+ info.DY = 0;
15851
+ info.W = 1;
15852
+ if (hitSomething == Object3D.hitCenter)
15853
+ {
15854
+ info.DX = X;
15855
+ if (X != 0)
15856
+ info.DX -= info.bounds.width/2;
15857
+
15858
+ info.DY = Y;
15859
+ if (Y != 0)
15860
+ info.DY -= info.bounds.height/2;
15861
+ }
15862
+
15863
+ object.drawEditHandles(info, 0);
15864
+
15865
+ if (drag && (X != 0 || Y != 0))
15866
+ {
15867
+ switch (hitSomething)
15868
+ {
15869
+ case Object3D.hitCenter: gr.setColor(Color.pink);
15870
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15871
+ break;
15872
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
15873
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15874
+ break;
15875
+ case Object3D.hitScale: gr.setColor(Color.cyan);
15876
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
15877
+ break;
15878
+ }
15879
+
15880
+ }
15881
+ }
1475615882 }
1475715883 }
15884
+
1475815885 if (isRenderer)
1475915886 {
1476015887 //gr.setColor(Color.black);
1476115888 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1476215889 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1476315890 }
15891
+
1476415892 if (hasMarquee)
1476515893 {
1476615894 gr.setXORMode(Color.white);
....@@ -14873,6 +16001,7 @@
1487316001 public boolean mouseDown(Event evt, int x, int y)
1487416002 {
1487516003 System.out.println("mouseDown: " + evt);
16004
+ System.exit(0);
1487616005 /*
1487716006 locked = true;
1487816007 drag = false;
....@@ -14916,7 +16045,7 @@
1491616045 {
1491716046 keyPressed(0, modifiers);
1491816047 }
14919
- clickStart(x, y, modifiers);
16048
+ // clickStart(x, y, modifiers);
1492016049 return true;
1492116050 }
1492216051
....@@ -15034,7 +16163,7 @@
1503416163 {
1503516164 keyReleased(0, 0);
1503616165 }
15037
- drag(x, y, modifiers);
16166
+ drag(x, y, 0, modifiers);
1503816167 return true;
1503916168 }
1504016169
....@@ -15166,7 +16295,7 @@
1516616295 Object3D object;
1516716296 static Object3D trackedobject;
1516816297 Camera renderCamera; // Light or Eye (or Occlusion)
15169
- /*static*/ Camera manipCamera; // Light or Eye
16298
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1517016299 /*static*/ Camera eyeCamera;
1517116300 /*static*/ Camera lightCamera;
1517216301 int cameracount;
....@@ -15451,16 +16580,16 @@
1545116580 cStatic.objectstack[materialdepth++] = checker;
1545216581 //System.out.println("material " + material);
1545316582 //Applet3D.tracein(this, selected);
15454
- vector2buffer = checker.projectedVertices;
16583
+ //vector2buffer = checker.projectedVertices;
1545516584
1545616585 //checker.GetMaterial().Draw(this, false); // true);
15457
- DrawMaterial(checker.GetMaterial(), false); // true);
16586
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1545816587
1545916588 materialdepth -= 1;
1546016589 if (materialdepth > 0)
1546116590 {
15462
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15463
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16591
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16592
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1546416593 }
1546516594 //checker.GetMaterial().opacity = 1f;
1546616595 ////checker.GetMaterial().ambient = 1f;
....@@ -15546,6 +16675,14 @@
1554616675 }
1554716676 }
1554816677
16678
+ private Object3D GetFolder()
16679
+ {
16680
+ Object3D folder = object.GetWindow().copy;
16681
+ if (object.GetWindow().copy.selection.Size() > 0)
16682
+ folder = object.GetWindow().copy.selection.elementAt(0);
16683
+ return folder;
16684
+ }
16685
+
1554916686 class SelectBuffer implements GLEventListener
1555016687 {
1555116688
....@@ -15604,6 +16741,7 @@
1560416741 {
1560516742 if (!selection)
1560616743 {
16744
+ new Exception().printStackTrace();
1560716745 System.exit(0);
1560816746 return;
1560916747 }
....@@ -15624,6 +16762,17 @@
1562416762
1562516763 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1562616764
16765
+ if (PAINTMODE)
16766
+ {
16767
+ if (object.GetWindow().copy.selection.Size() > 0)
16768
+ {
16769
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16770
+
16771
+ // Make what you paint not selectable.
16772
+ paintobj.ResetSelectable();
16773
+ }
16774
+ }
16775
+
1562716776 //int tmp = selection_view;
1562816777 //selection_view = -1;
1562916778 int temp = DrawMode();
....@@ -15635,6 +16784,17 @@
1563516784 // temp = DEFAULT; // patch for selection debug
1563616785 Globals.drawMode = temp; // WARNING
1563716786
16787
+ if (PAINTMODE)
16788
+ {
16789
+ if (object.GetWindow().copy.selection.Size() > 0)
16790
+ {
16791
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16792
+
16793
+ // Revert.
16794
+ paintobj.RestoreSelectable();
16795
+ }
16796
+ }
16797
+
1563816798 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1563916799
1564016800 // trying different ways of getting the depth info over
....@@ -15682,6 +16842,8 @@
1568216842 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1568316843 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1568416844 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16845
+
16846
+ CreateSelectedPoint();
1568516847
1568616848 // Will fit the mesh !!!
1568716849 selectedpoint.toParent[0][0] = 0.0001;
....@@ -15731,34 +16893,36 @@
1573116893 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]));
1573216894 }
1573316895
15734
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
16896
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1573516897 }
1573616898 }
1573716899
1573816900 if (!movingcamera && !PAINTMODE)
15739
- object.editWindow.ScreenFitPoint(); // fev 2014
16901
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1574016902
15741
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
16903
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1574216904 {
15743
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
16905
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1574416906
15745
- Object3D group = new Object3D("inst" + paintcount++);
16907
+ if (object.GetWindow().copy.selection.Size() > 0)
16908
+ {
16909
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1574616910
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();
16911
+ Object3D inst = new Object3D("inst" + paintcount++);
16912
+
16913
+ inst.CreateMaterial(); // use a void leaf to select instances
16914
+
16915
+ inst.add(paintobj); // link
16916
+
16917
+ object.GetWindow().SnapObject(inst);
16918
+
16919
+ Object3D folder = paintFolder; // GetFolder();
16920
+
16921
+ folder.add(inst);
16922
+
16923
+ object.GetWindow().ResetModel();
16924
+ object.GetWindow().refreshContents();
16925
+ }
1576216926 }
1576316927 else
1576416928 paintcount = 0;
....@@ -15797,6 +16961,11 @@
1579716961 //System.out.println("objects[color] = " + objects[color]);
1579816962 //objects[color].Select();
1579916963 indexcount = 0;
16964
+ ObjEditor window = object.GetWindow();
16965
+ if (window != null && deselect)
16966
+ {
16967
+ window.Select(null, deselect, true);
16968
+ }
1580016969 object.Select(color, deselect);
1580116970 }
1580216971
....@@ -15896,7 +17065,7 @@
1589617065 gl.glDisable(gl.GL_CULL_FACE);
1589717066 }
1589817067
15899
- if (!RENDERSHADOW)
17068
+ if (!Globals.RENDERSHADOW)
1590017069 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1590117070
1590217071 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -15906,7 +17075,7 @@
1590617075 //gl.glColorMask(false, false, false, false);
1590717076
1590817077 //render_scene_from_light_view(gl, drawable, 0, 0);
15909
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17078
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1591017079 {
1591117080 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1591217081
....@@ -15966,7 +17135,6 @@
1596617135
1596717136 class AntialiasBuffer implements GLEventListener
1596817137 {
15969
-
1597017138 CameraPane parent = null;
1597117139
1597217140 AntialiasBuffer(CameraPane p)
....@@ -16323,23 +17491,15 @@
1632317491 int AAbuffersize = 0;
1632417492
1632517493 //double[] selectedpoint = new double[3];
16326
- static Superellipsoid selectedpoint = new Superellipsoid();
17494
+ static Superellipsoid selectedpoint;
1632717495 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();
17496
+ static Sphere debugpointG;
17497
+ static Sphere debugpointP;
17498
+ static Sphere debugpointC;
17499
+ static Sphere debugpointR;
1633217500
1633317501 static Sphere debugpoints[] = new Sphere[8];
1633417502
16335
- static
16336
- {
16337
- for (int i=0; i<8; i++)
16338
- {
16339
- debugpoints[i] = new Sphere();
16340
- }
16341
- }
16342
-
1634317503 static void InitPoints(float radius)
1634417504 {
1634517505 for (int i=0; i<8; i++)
....@@ -16359,7 +17519,7 @@
1635917519 }
1636017520 }
1636117521
16362
- static void DrawPoints(CameraPane cpane)
17522
+ static void DrawPoints(iCameraPane cpane)
1636317523 {
1636417524 for (int i=0; i<8; i++) // first and last are red
1636517525 {
....@@ -16391,10 +17551,11 @@
1639117551 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1639217552 // Depth buffer format
1639317553 //private int depth_format;
16394
- static public void NextIndex(Object3D o, GL gl)
17554
+
17555
+ public void NextIndex()
1639517556 {
1639617557 indexcount+=16;
16397
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17558
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1639817559 //objects[indexcount] = o;
1639917560 //System.out.println("indexcount = " + indexcount);
1640017561 }