Normand Briere
2019-08-22 6a145f6c81dfcbe0653eda27d042efb48daa7512
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -76,7 +110,11 @@
76110 //private Mat4f spotlightTransform = new Mat4f();
77111 //private Mat4f spotlightInverseTransform = new Mat4f();
78112 static GLContext glcontext = null;
79
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
80118 boolean reverseUP = false;
81119 static boolean frozen = false;
82120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -92,6 +130,8 @@
92130
93131 static int tickcount = 0; // slow pose issue
94132
133
+static boolean BUTTONLESSWHEEL = false;
134
+static boolean ZOOMBOXMODE = false;
95135 static boolean BOXMODE = false;
96136 static boolean IMAGEFLIP = false;
97137 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +146,7 @@
106146 static boolean OEIL = true;
107147 static boolean OEILONCE = false; // do oeilon then oeiloff
108148 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
149
+static boolean SWITCH = true; // false;
110150 static boolean HANDLES = false; // selection doesn't work!!
111151 static boolean PAINTMODE = false;
112152
....@@ -128,7 +168,7 @@
128168
129169
130170 // OPTIONS
131
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
132172 boolean cameraLight = false;
133173 boolean UVdebug = false;
134174 boolean Udebug = false;
....@@ -137,7 +177,7 @@
137177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138178 boolean anisotropy = true;
139179 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141181
142182 boolean macromode = false;
143183
....@@ -149,12 +189,26 @@
149189 defaultcaps.setAccumBlueBits(16);
150190 defaultcaps.setAccumAlphaBits(16);
151191 }
152
- static CameraPane theRenderer;
192
+
193
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
153194
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
207
+
154208 void SetAsGLRenderer(boolean b)
155209 {
156210 isRenderer = b;
157
- theRenderer = this;
211
+ Globals.theRenderer = this;
158212 }
159213
160214 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -169,7 +223,8 @@
169223
170224 SetCamera(cam);
171225
172
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
173228
174229 object = o;
175230
....@@ -192,9 +247,43 @@
192247
193248 /// INTERFACE
194249
250
+ public javax.media.opengl.GL GetGL0()
251
+ {
252
+ return null;
253
+ }
254
+
255
+ public int GenList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ return gl.glGenLists(1);
259
+ }
260
+
261
+ public void NewList(int id)
262
+ {
263
+ javax.media.opengl.GL gl = GetGL();
264
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
265
+ }
266
+
267
+ public void CallList(int id)
268
+ {
269
+ javax.media.opengl.GL gl = GetGL();
270
+ gl.glCallList(id);
271
+ }
272
+
273
+ public void EndList()
274
+ {
275
+ javax.media.opengl.GL gl = GetGL();
276
+ gl.glEndList();
277
+ }
278
+
195279 public boolean IsBoxMode()
196280 {
197281 return BOXMODE;
282
+ }
283
+
284
+ public boolean IsZoomBoxMode()
285
+ {
286
+ return ZOOMBOXMODE;
198287 }
199288
200289 public void ClearDepth()
....@@ -236,9 +325,14 @@
236325 return this.ambientOcclusion;
237326 }
238327
328
+ public boolean IsDebugSelection()
329
+ {
330
+ return DEBUG_SELECTION;
331
+ }
332
+
239333 public boolean IsFrozen()
240334 {
241
- boolean selectmode = this.DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
335
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
242336
243337 return !selectmode && cameracount == 0; // != 0;
244338 }
....@@ -259,9 +353,19 @@
259353 return lightCamera;
260354 }
261355
356
+ public Camera ManipCamera()
357
+ {
358
+ return manipCamera;
359
+ }
360
+
262361 public Camera RenderCamera()
263362 {
264363 return renderCamera;
364
+ }
365
+
366
+ public Camera[] Cameras()
367
+ {
368
+ return cameras;
265369 }
266370
267371 public void PushMaterial(Object3D obj, boolean selected)
....@@ -277,7 +381,7 @@
277381 cStatic.objectstack[materialdepth++] = obj;
278382 //System.out.println("material " + material);
279383 //Applet3D.tracein(this, selected);
280
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
281385 if (obj instanceof Camera)
282386 {
283387 display.options1[0] = material.shift;
....@@ -286,14 +390,28 @@
286390 display.options1[2] = material.shadowbias;
287391 display.options1[3] = material.aniso;
288392 display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
289398 display.options2[0] = material.opacity;
290399 display.options2[1] = material.diffuse;
291400 display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
292404
293405 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
294409 display.options4[0] = material.cameralight/0.2f;
295410 display.options4[1] = material.subsurface;
296411 display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
297415
298416 // if (display.CURRENTANTIALIAS > 0)
299417 // display.options3[3] /= 4;
....@@ -309,7 +427,7 @@
309427 /**/
310428 } else
311429 {
312
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
313431 }
314432 } else
315433 {
....@@ -333,8 +451,8 @@
333451 cStatic.objectstack[materialdepth++] = obj;
334452 //System.out.println("material " + material);
335453 //Applet3D.tracein("selected ", selected);
336
- display.vector2buffer = obj.projectedVertices;
337
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
338456 }
339457 }
340458
....@@ -351,8 +469,8 @@
351469 materialdepth -= 1;
352470 if (materialdepth > 0)
353471 {
354
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
355
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
472
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
473
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
356474 }
357475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
358476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -372,8 +490,8 @@
372490 materialdepth -= 1;
373491 if (materialdepth > 0)
374492 {
375
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
376
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
493
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
494
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
377495 }
378496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
379497 //else
....@@ -408,21 +526,24 @@
408526
409527 javax.media.opengl.GL gl = display.GetGL();
410528
411
- boolean selectmode = display.DrawMode() == display.SELECTION || CameraPane.DEBUG_SELECTION;
529
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
412530
413531 //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
414532 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
415533 {
416534 //gl.glBegin(gl.GL_TRIANGLES);
417
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
535
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
536
+ // TEST LIVE NORMALS && !obj.dontselect
537
+ ;
418538 if (!hasnorm)
419539 {
420
- // System.out.println("FUCK!!");
540
+ // System.out.println("Mesh normal");
421541 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
422542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
423543 LA.vecCross(obj.v0, obj.v1, obj.v2);
424544 LA.vecNormalize(obj.v2);
425
- gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
545
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
426547 }
427548
428549 // P
....@@ -444,7 +565,7 @@
444565 y += ny * obj.NORMALPUSH;
445566 z += nz * obj.NORMALPUSH;
446567
447
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
448569 }
449570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
450571 SetColor(obj, pv);
....@@ -476,7 +597,7 @@
476597 y += ny * obj.NORMALPUSH;
477598 z += nz * obj.NORMALPUSH;
478599
479
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
480601 }
481602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
482603 // boolean locked = false;
....@@ -524,7 +645,7 @@
524645 y += ny * obj.NORMALPUSH;
525646 z += nz * obj.NORMALPUSH;
526647
527
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
528649 }
529650
530651 // if ((dot&4) == 0)
....@@ -760,8 +881,630 @@
760881 //// tris.postdraw(this);
761882 }
762883
884
+ static Camera localcamera = new Camera();
885
+ static cVector from = new cVector();
886
+ static cVector to = new cVector();
887
+
888
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
889
+ {
890
+ CameraPane cp = this;
891
+
892
+ Camera keep = cp.RenderCamera();
893
+ cp.renderCamera = localcamera;
894
+
895
+ if (br.trimmed)
896
+ {
897
+ float[] colors = new float[br.positions.length / 3];
898
+
899
+ int i3 = 0;
900
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
901
+ {
902
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
903
+ continue;
904
+
905
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
906
+ to.set(br.positions[i3] + br.normals[i3],
907
+ br.positions[i3 + 1] + br.normals[i3 + 1],
908
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
909
+ LA.xformPos(from, transform, from);
910
+ LA.xformPos(to, transform, to); // RIGID ONLY
911
+ localcamera.setAim(from, to);
912
+
913
+ CameraPane.occlusionbuffer.display();
914
+
915
+ if (CameraPane.DEBUG_OCCLUSION)
916
+ cp.display(); // debug
917
+
918
+ colors[i] = cp.vertexOcclusion.r;
919
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
920
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
921
+
922
+ if ((i % 100) == 0 && i != 0)
923
+ {
924
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
925
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
926
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
927
+ }
928
+ }
929
+
930
+ br.colors = colors;
931
+ }
932
+ else
933
+ {
934
+ for (int i = 0; i < br.VertexCount(); i++)
935
+ {
936
+ Vertex v = br.GetVertex(i);
937
+
938
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
939
+ continue;
940
+
941
+ from.set(v.x, v.y, v.z);
942
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
943
+ LA.xformPos(from, transform, from);
944
+ LA.xformPos(to, transform, to); // RIGID ONLY
945
+ localcamera.setAim(from, to);
946
+
947
+ CameraPane.occlusionbuffer.display();
948
+
949
+ if (CameraPane.DEBUG_OCCLUSION)
950
+ cp.display(); // debug
951
+
952
+ v.AO = cp.vertexOcclusion.r;
953
+
954
+ if ((i % 100) == 0 && i != 0)
955
+ {
956
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
957
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
958
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
959
+ }
960
+ }
961
+ }
962
+
963
+ //System.out.println("done.");
964
+
965
+ cp.renderCamera = keep;
966
+ }
967
+
968
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
969
+ {
970
+ CameraPane display = this;
971
+ pointFlow.CreateHT();
972
+
973
+ float r = display.modelParams0[0];
974
+ float g = display.modelParams0[1];
975
+ float b = display.modelParams0[2];
976
+ float opacity = display.modelParams5[1];
977
+
978
+ //final GL gl = GLU.getCurrentGL();
979
+ GL gl = display.GetGL(); // getGL();
980
+
981
+ int s = pointFlow.points.size();
982
+
983
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
984
+ gl.glEnable(gl.GL_CULL_FACE);
985
+
986
+ for (int i=s; --i>=0;)
987
+ //for (int i=0; i<s; i++)
988
+ {
989
+ cVector v = pointFlow.points.get(i);
990
+
991
+ double mindist = Double.MAX_VALUE;
992
+
993
+ double size = pointFlow.minimumSize;
994
+
995
+ double distancenext = 0;
996
+
997
+ if (i > 0)
998
+ {
999
+ cVector w = pointFlow.points.get(i-1);
1000
+
1001
+ double dist = w.distance(v);
1002
+
1003
+ distancenext = dist;
1004
+
1005
+ if (mindist > dist)
1006
+ {
1007
+ mindist = dist;
1008
+ size = mindist*pointFlow.resizefactor;
1009
+ }
1010
+ }
1011
+
1012
+ if (i < s-1)
1013
+ {
1014
+ cVector w = pointFlow.points.get(i+1);
1015
+
1016
+ double dist = w.distance(v);
1017
+
1018
+ if (mindist > dist)
1019
+ {
1020
+ mindist = dist;
1021
+ size = mindist*pointFlow.resizefactor;
1022
+ }
1023
+ }
1024
+
1025
+ if (size < pointFlow.minimumSize)
1026
+ size = pointFlow.minimumSize;
1027
+ if (size > pointFlow.maximumSize)
1028
+ size = pointFlow.maximumSize;
1029
+
1030
+ double tx = v.x;
1031
+ double ty = v.y;
1032
+ double tz = v.z;
1033
+
1034
+ // if (tx == 0 && ty == 0 && tz == 0)
1035
+ // continue;
1036
+
1037
+ gl.glMatrixMode(gl.GL_TEXTURE);
1038
+ gl.glPushMatrix();
1039
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1040
+
1041
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1042
+
1043
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1044
+ gl.glPushMatrix();
1045
+
1046
+ gl.glTranslated(tx,ty,tz);
1047
+
1048
+ gl.glScaled(size,size,size);
1049
+
1050
+// float cr = colorBuf.get(index4);
1051
+// float cg = colorBuf.get(index4+1);
1052
+// float cb = colorBuf.get(index4+2);
1053
+// float ca = colorBuf.get(index4+3);
1054
+//
1055
+// display.modelParams0[0] = r * cr;
1056
+// display.modelParams0[1] = g * cg;
1057
+// display.modelParams0[2] = b * cb;
1058
+//
1059
+// display.modelParams5[1] = opacity * ca;
1060
+//
1061
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1062
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1063
+//
1064
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1065
+// RandomNode.globalseed2 = RandomNode.globalseed;
1066
+//
1067
+//// gl.glColor4f(cr,cg,cb,ca);
1068
+// // gl.glScalef(1024/16,1024/16,1024/16);
1069
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1070
+
1071
+ gl.glPopMatrix();
1072
+
1073
+ double step = size/4; //
1074
+
1075
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1076
+ continue;
1077
+
1078
+ int nbsteps = (int)(distancenext/step);
1079
+
1080
+ step = distancenext/nbsteps;
1081
+
1082
+ cVector next = pointFlow.points.get(i-1);
1083
+
1084
+ tmp.set(next);
1085
+ tmp.sub(v);
1086
+ tmp.normalize();
1087
+ tmp.mul(step);
1088
+
1089
+ // calculate next size
1090
+ mindist = Double.MAX_VALUE;
1091
+
1092
+ double nextsize = pointFlow.minimumSize;
1093
+
1094
+ if (i > 1)
1095
+ {
1096
+ cVector w = pointFlow.points.get(i-2);
1097
+
1098
+ double dist = w.distance(next);
1099
+
1100
+ if (mindist > dist)
1101
+ {
1102
+ mindist = dist;
1103
+ nextsize = mindist*pointFlow.resizefactor;
1104
+ }
1105
+ }
1106
+
1107
+ double dist = v.distance(next);
1108
+
1109
+ if (mindist > dist)
1110
+ {
1111
+ mindist = dist;
1112
+ nextsize = mindist*pointFlow.resizefactor;
1113
+ }
1114
+
1115
+ if (nextsize < pointFlow.minimumSize)
1116
+ nextsize = pointFlow.minimumSize;
1117
+ if (nextsize > pointFlow.maximumSize)
1118
+ nextsize = pointFlow.maximumSize;
1119
+ //
1120
+
1121
+ double count = 0;
1122
+
1123
+ while (distancenext > 0.000000001) // step
1124
+ {
1125
+ gl.glPushMatrix();
1126
+
1127
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1128
+
1129
+ double K = count/nbsteps;
1130
+
1131
+ double intersize = K*nextsize + (1-K)*size;
1132
+
1133
+ gl.glScaled(intersize,intersize,intersize);
1134
+
1135
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1136
+
1137
+ count++;
1138
+
1139
+ distancenext -= step;
1140
+
1141
+ gl.glPopMatrix();
1142
+ }
1143
+
1144
+ if (count != nbsteps)
1145
+ assert(count == nbsteps);
1146
+
1147
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1148
+ //gl.glTranslatef(-tx,-ty,-tz);
1149
+
1150
+ gl.glMatrixMode(gl.GL_TEXTURE);
1151
+ gl.glPopMatrix();
1152
+ }
1153
+
1154
+ if (!cf)
1155
+ gl.glDisable(gl.GL_CULL_FACE);
1156
+
1157
+// display.modelParams0[0] = r;
1158
+// display.modelParams0[1] = g;
1159
+// display.modelParams0[2] = b;
1160
+//
1161
+// display.modelParams5[1] = opacity;
1162
+//
1163
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1164
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1165
+
1166
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1167
+ }
1168
+
1169
+ public void DrawBox(cVector min, cVector max)
1170
+ {
1171
+ javax.media.opengl.GL gl = GetGL();
1172
+ gl.glBegin(gl.GL_LINES);
1173
+
1174
+ gl.glVertex3d(min.x, min.y, min.z);
1175
+ gl.glVertex3d(min.x, min.y, max.z);
1176
+ gl.glVertex3d(min.x, min.y, min.z);
1177
+ gl.glVertex3d(min.x, max.y, min.z);
1178
+ gl.glVertex3d(min.x, min.y, min.z);
1179
+ gl.glVertex3d(max.x, min.y, min.z);
1180
+
1181
+ gl.glVertex3d(max.x, max.y, max.z);
1182
+ gl.glVertex3d(min.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, max.y, max.z);
1184
+ gl.glVertex3d(max.x, min.y, max.z);
1185
+ gl.glVertex3d(max.x, max.y, max.z);
1186
+ gl.glVertex3d(max.x, max.y, min.z);
1187
+
1188
+ gl.glEnd();
1189
+ }
1190
+
1191
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1192
+ {
1193
+ int[] strips = bRep.getRawIndices();
1194
+
1195
+ javax.media.opengl.GL gl = GetGL();
1196
+
1197
+ // TRIANGLE STRIP ARRAY
1198
+ if (bRep.trimmed)
1199
+ {
1200
+ float[] v = bRep.getRawVertices();
1201
+ float[] n = bRep.getRawNormals();
1202
+ float[] c = bRep.getRawColors();
1203
+ float[] uv = bRep.getRawUVMap();
1204
+
1205
+ int count2 = 0;
1206
+ int count3 = 0;
1207
+
1208
+ if (n.length > 0)
1209
+ {
1210
+ for (int i = 0; i < strips.length; i++)
1211
+ {
1212
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1213
+
1214
+ /*
1215
+ boolean locked = false;
1216
+ float eps = 0.1f;
1217
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1218
+
1219
+ int dot = 0;
1220
+
1221
+ if ((dot&1) == 0)
1222
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1223
+
1224
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1225
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1226
+ else
1227
+ {
1228
+ locked = true;
1229
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1230
+ }
1231
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1232
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1233
+ if (hasnorm)
1234
+ {
1235
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1236
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1237
+ }
1238
+
1239
+ if ((dot&4) == 0)
1240
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1241
+
1242
+ if (wrap || !locked && (dot&8) != 0)
1243
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1244
+ else
1245
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1246
+
1247
+ f.dot = dot;
1248
+ */
1249
+
1250
+ if (!selectmode)
1251
+ {
1252
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1253
+ {
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1255
+ } else
1256
+ {
1257
+ SetGLNormal(gl, 0, 0, 1);
1258
+ }
1259
+
1260
+ if (c != null)
1261
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1262
+ {
1263
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1264
+ }
1265
+ }
1266
+
1267
+ if (flipV)
1268
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1269
+ else
1270
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
1272
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1273
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1274
+
1275
+ count2 += 2;
1276
+ count3 += 3;
1277
+ if (!selectmode)
1278
+ {
1279
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1280
+ {
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1282
+ } else
1283
+ {
1284
+ SetGLNormal(gl, 0, 0, 1);
1285
+ }
1286
+ if (c != null)
1287
+ {
1288
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1289
+ }
1290
+ }
1291
+
1292
+ if (flipV)
1293
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1294
+ else
1295
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
1297
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1298
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1299
+
1300
+ count2 += 2;
1301
+ count3 += 3;
1302
+ for (int j = 0; j < strips[i] - 2; j++)
1303
+ {
1304
+ //gl.glTexCoord2d(...);
1305
+ if (!selectmode)
1306
+ {
1307
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1308
+ {
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1310
+ } else
1311
+ {
1312
+ SetGLNormal(gl, 0, 0, 1);
1313
+ }
1314
+ if (c != null)
1315
+ {
1316
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1317
+ }
1318
+ }
1319
+
1320
+ if (flipV)
1321
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1322
+ else
1323
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
1325
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1326
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
1328
+ count2 += 2;
1329
+ count3 += 3;
1330
+ }
1331
+
1332
+ gl.glEnd();
1333
+ }
1334
+ }
1335
+
1336
+ assert count3 == v.length;
1337
+ }
1338
+ else // !trimmed
1339
+ {
1340
+ int count = 0;
1341
+ for (int i = 0; i < strips.length; i++)
1342
+ {
1343
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1344
+
1345
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1346
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1347
+
1348
+ drawVertex(gl, p, flipV, selectmode);
1349
+ drawVertex(gl, q, flipV, selectmode);
1350
+
1351
+ for (int j = 0; j < strips[i] - 2; j++)
1352
+ {
1353
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1354
+
1355
+ // if (j%2 == 0)
1356
+ // drawFace(p, q, r, display, null);
1357
+ // else
1358
+ // drawFace(p, r, q, display, null);
1359
+
1360
+ // p = q;
1361
+ // q = r;
1362
+ drawVertex(gl, r, flipV, selectmode);
1363
+ }
1364
+
1365
+ gl.glEnd();
1366
+ }
1367
+ }
1368
+ }
1369
+
1370
+ static cSpring.Point3D temp = new cSpring.Point3D();
1371
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1372
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1373
+
1374
+ public void DrawDynamicMesh(cMesh mesh)
1375
+ {
1376
+ GL gl = GetGL(); // getGL();
1377
+
1378
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1379
+
1380
+ gl.glDisable(gl.GL_LIGHTING);
1381
+
1382
+ gl.glLineWidth(1);
1383
+ gl.glColor3f(1,1,1);
1384
+ gl.glBegin(gl.GL_LINES);
1385
+ double scale = 0;
1386
+ int count = 0;
1387
+ for (int s=0; s<Phys.allSprings.size(); s++)
1388
+ {
1389
+ cSpring.Spring spring = Phys.allSprings.get(s);
1390
+ if(s == 0)
1391
+ {
1392
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1393
+ }
1394
+ if (mesh.showsprings)
1395
+ {
1396
+ temp.set(spring.a.position);
1397
+ temp.add(spring.b.position);
1398
+ temp.mul(0.5);
1399
+ temp2.set(spring.a.position);
1400
+ temp2.sub(spring.b.position);
1401
+ temp2.mul(spring.restLength/2);
1402
+ temp.sub(temp2);
1403
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1404
+ temp.add(temp2);
1405
+ temp.add(temp2);
1406
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1407
+ }
1408
+
1409
+ if (spring.isHandle)
1410
+ continue;
1411
+
1412
+ //if (scale < spring.restLength)
1413
+ scale += spring.restLength;
1414
+ count++;
1415
+ }
1416
+ gl.glEnd();
1417
+
1418
+ if (count == 0)
1419
+ scale = 0.01;
1420
+ else
1421
+ scale /= count * 3;
1422
+
1423
+ //scale = 0.25;
1424
+
1425
+ if (mesh.ShowInfo())
1426
+ {
1427
+ gl.glLineWidth(4);
1428
+ for (int s=0; s<Phys.allNodes.size(); s++)
1429
+ {
1430
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1431
+ if (node.mass == 0)
1432
+ continue;
1433
+
1434
+ int i = node.springs==null?-1:node.springs.size();
1435
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1436
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1437
+ //temp.normalize();
1438
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1439
+ gl.glBegin(gl.GL_LINES);
1440
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1441
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1442
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1443
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1444
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1445
+ gl.glEnd();
1446
+ }
1447
+
1448
+ gl.glLineWidth(8);
1449
+ for (int s=0; s<Phys.allNodes.size(); s++)
1450
+ {
1451
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1452
+
1453
+ if (node.springs != null)
1454
+ {
1455
+ for (int i=0; i<node.springs.size(); i+=1)
1456
+ {
1457
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1458
+
1459
+ int c = i+1;
1460
+ // c = node.springs.get(i).nbcopies;
1461
+
1462
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1463
+ gl.glBegin(gl.GL_LINES);
1464
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1465
+ 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);
1466
+ gl.glEnd();
1467
+ }
1468
+ }
1469
+ }
1470
+
1471
+ gl.glLineWidth(1);
1472
+ }
1473
+
1474
+ gl.glEnable(gl.GL_LIGHTING);
1475
+ }
1476
+
7631477 /// INTERFACE
7641478
1479
+ public void StartTriangles()
1480
+ {
1481
+ javax.media.opengl.GL gl = GetGL();
1482
+ gl.glBegin(gl.GL_TRIANGLES);
1483
+ }
1484
+
1485
+ public void EndTriangles()
1486
+ {
1487
+ GetGL().glEnd();
1488
+ }
1489
+
1490
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1491
+ {
1492
+ if (!selectmode)
1493
+ {
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1495
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1496
+
1497
+ if (flipV)
1498
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1499
+ else
1500
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1501
+ }
1502
+
1503
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1504
+ }
1505
+
1506
+ float[] colorV = new float[4];
1507
+
7651508 void SetColor(Object3D obj, Vertex p0)
7661509 {
7671510 CameraPane display = this;
....@@ -829,8 +1572,6 @@
8291572 {
8301573 return;
8311574 }
832
-
833
- float[] colorV = new float[3];
8341575
8351576 if (false) // marked)
8361577 {
....@@ -939,7 +1680,7 @@
9391680 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
9401681 }
9411682
942
- void DrawMaterial(cMaterial material, boolean selected)
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
9431684 {
9441685 CameraPane display = this;
9451686 //new Exception().printStackTrace();
....@@ -955,18 +1696,18 @@
9551696 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
9561697 if (!material.multiply)
9571698 {
958
- display.color = color;
1699
+ display.color = material.color;
9591700 display.saturation = material.modulation;
9601701 }
9611702 else
9621703 {
963
- display.color *= color*2;
1704
+ display.color *= material.color*2;
9641705 display.saturation *= material.modulation*2;
9651706 }
9661707
9671708 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
9681709
969
- float[] colorV = GrafreeD.colorV;
1710
+ float[] colorV = Grafreed.colorV;
9701711
9711712 /**/
9721713 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -974,7 +1715,7 @@
9741715 colorV[0] = display.modelParams0[0] * material.diffuse;
9751716 colorV[1] = display.modelParams0[1] * material.diffuse;
9761717 colorV[2] = display.modelParams0[2] * material.diffuse;
977
- colorV[3] = material.opacity;
1718
+ colorV[3] = 1; // material.opacity;
9781719
9791720 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
9801721 //System.out.println("Opacity = " + opacity);
....@@ -1079,12 +1820,12 @@
10791820
10801821 display.modelParams7[0] = 0;
10811822 display.modelParams7[1] = 1000;
1082
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
10831824 display.modelParams7[3] = 0;
10841825
1085
- display.modelParams6[0] = 100; // criss de bug de bump
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
10861827
1087
- Object3D.cVector2[] extparams = display.vector2buffer;
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
10881829 if (extparams != null && extparams.length > 0 && extparams[0] != null)
10891830 {
10901831 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1226,7 +1967,7 @@
12261967 void PushMatrix(double[][] matrix)
12271968 {
12281969 // GrafreeD.tracein(matrix);
1229
- PushMatrix(matrix,1);
1970
+ PushMatrix(matrix, 1);
12301971 }
12311972
12321973 void PushMatrix()
....@@ -1312,9 +2053,9 @@
13122053 switch(viewcode)
13132054 {
13142055 case 0: return "main";
1315
- case 1: return "one";
1316
- case 2: return "two";
1317
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
13182059 case 4: return "light";
13192060 }
13202061
....@@ -1323,7 +2064,7 @@
13232064
13242065 static int camerachangeframe;
13252066
1326
- boolean SetCamera(Camera cam)
2067
+ public boolean SetCamera(Camera cam)
13272068 {
13282069 // may 2014 if (cam == cameras[0] || cam == cameras[1])
13292070 // return false;
....@@ -1380,7 +2121,7 @@
13802121 //System.err.println("Oeil on");
13812122 OEIL = true;
13822123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1383
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
13842125 //pingthread.StepToTarget(true);
13852126 }
13862127
....@@ -1451,33 +2192,6 @@
14512192 mainDL ^= true;
14522193 }
14532194
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
-
14812195 void ToggleFullScreen()
14822196 {
14832197 FULLSCREEN ^= true;
....@@ -1488,72 +2202,94 @@
14882202 Globals.CROWD ^= true;
14892203 }
14902204
1491
- void ToggleInertia()
1492
- {
1493
- INERTIA ^= true;
1494
- }
1495
-
14962205 void ToggleLocal()
14972206 {
14982207 LOCALTRANSFORM ^= true;
14992208 }
15002209
1501
- void ToggleFast()
2210
+ public void ToggleTexture()
2211
+ {
2212
+ textureon ^= true;
2213
+ }
2214
+
2215
+ public void ToggleLive()
2216
+ {
2217
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2218
+
2219
+ System.err.println("LIVE = " + Globals.isLIVE());
2220
+
2221
+ if (!Globals.isLIVE()) // save sound
2222
+ Grafreed.savesound = true; // wav.save();
2223
+ // else
2224
+ repaint(); // start loop // may 2013
2225
+ }
2226
+
2227
+ public void ToggleSupport()
2228
+ {
2229
+ SUPPORT ^= true;
2230
+ }
2231
+
2232
+ public void ToggleAbort()
2233
+ {
2234
+ ABORTMODE ^= true;
2235
+ }
2236
+
2237
+ public void ToggleInertia()
2238
+ {
2239
+ INERTIA ^= true;
2240
+ }
2241
+
2242
+ public void ToggleFast()
15022243 {
15032244 FAST ^= true;
15042245 }
15052246
1506
- void ToggleSlowPose()
2247
+ public void ToggleSlowPose()
15072248 {
15082249 SLOWPOSE ^= true;
15092250 }
15102251
1511
- void ToggleFootContact()
1512
- {
1513
- FOOTCONTACT ^= true;
1514
- }
1515
-
1516
- void ToggleBoxMode()
2252
+ public void ToggleBoxMode()
15172253 {
15182254 BOXMODE ^= true;
15192255 }
15202256
1521
- void ToggleSmoothFocus()
2257
+ public void ToggleZoomBoxMode()
2258
+ {
2259
+ ZOOMBOXMODE ^= true;
2260
+ }
2261
+
2262
+ public void ToggleSmoothFocus()
15222263 {
15232264 SMOOTHFOCUS ^= true;
15242265 }
15252266
1526
- void ToggleImageFlip()
2267
+ public void ToggleImageFlip()
15272268 {
15282269 IMAGEFLIP ^= true;
15292270 }
15302271
1531
- void ToggleSpeakerMocap()
2272
+ public void ToggleSpeakerMocap()
15322273 {
15332274 SPEAKERMOCAP ^= true;
15342275 }
15352276
1536
- void ToggleSpeakerCamera()
2277
+ public void ToggleSpeakerCamera()
15372278 {
15382279 SPEAKERCAMERA ^= true;
15392280 }
15402281
1541
- void ToggleSpeakerFocus()
2282
+ public void ToggleSpeakerFocus()
15422283 {
15432284 SPEAKERFOCUS ^= true;
15442285 }
15452286
1546
- void ToggleDebug()
1547
- {
1548
- DEBUG ^= true;
1549
- }
1550
-
1551
- void ToggleFrustum()
2287
+ public void ToggleFrustum()
15522288 {
15532289 FRUSTUM ^= true;
15542290 }
15552291
1556
- void ToggleTrack()
2292
+ public void ToggleTrack()
15572293 {
15582294 TRACK ^= true;
15592295 if (TRACK)
....@@ -1572,25 +2308,35 @@
15722308 repaint();
15732309 }
15742310
1575
- void ToggleTrackOnce()
2311
+ public void ToggleTrackOnce()
15762312 {
15772313 TRACKONCE ^= true;
15782314 }
15792315
1580
- void ToggleShadowTrack()
2316
+ public void ToggleShadowTrack()
15812317 {
15822318 SHADOWTRACK ^= true;
15832319 repaint();
15842320 }
15852321
1586
- void ToggleOeil()
2322
+ public void ToggleOeil()
15872323 {
15882324 OEIL ^= true;
15892325 }
15902326
1591
- void ToggleOeilOnce()
2327
+ public void ToggleOeilOnce()
15922328 {
15932329 OEILONCE ^= true;
2330
+ }
2331
+
2332
+ void ToggleFootContact()
2333
+ {
2334
+ FOOTCONTACT ^= true;
2335
+ }
2336
+
2337
+ void ToggleDebug()
2338
+ {
2339
+ Globals.DEBUG ^= true;
15942340 }
15952341
15962342 void ToggleLookAt()
....@@ -1598,9 +2344,9 @@
15982344 LOOKAT ^= true;
15992345 }
16002346
1601
- void ToggleRandom()
2347
+ void ToggleSwitch()
16022348 {
1603
- RANDOM ^= true;
2349
+ SWITCH ^= true;
16042350 }
16052351
16062352 void ToggleHandles()
....@@ -1608,10 +2354,17 @@
16082354 HANDLES ^= true;
16092355 }
16102356
2357
+ Object3D paintFolder;
2358
+
16112359 void TogglePaint()
16122360 {
16132361 PAINTMODE ^= true;
16142362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
16152368 }
16162369
16172370 void SwapCamera(int a, int b)
....@@ -1707,7 +2460,34 @@
17072460 {
17082461 return currentGL;
17092462 }
1710
-
2463
+
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
2465
+ {
2466
+ Grafreed.Assert(texturedata != null);
2467
+
2468
+ int width = texturedata.getWidth();
2469
+ int height = texturedata.getHeight();
2470
+
2471
+ Buffer buffer = texturedata.getBuffer();
2472
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2473
+
2474
+ byte[] bytes = bytebuf.array();
2475
+
2476
+ return CreateBim(bytes, width, height);
2477
+ }
2478
+
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
2482
+
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2489
+ }
2490
+
17112491 /**/
17122492 class CacheTexture
17132493 {
....@@ -1716,28 +2496,31 @@
17162496
17172497 int resolution;
17182498
1719
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
17202500 {
1721
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
17222503 resolution = res;
17232504 }
17242505 }
17252506 /**/
17262507
17272508 // 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>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
17312514 int pigmentdepth = 0;
17322515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
17332516 int bumpdepth = 0;
17342517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
17352518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
17362519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
1737
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
17382521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
17392522
1740
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
17412524 {
17422525 TextureData texturedata = null;
17432526
....@@ -1747,7 +2530,7 @@
17472530 com.sun.opengl.util.texture.TextureIO.newTextureData(
17482531 getClass().getClassLoader().getResourceAsStream(name),
17492532 true,
1750
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
17512534 } catch (java.io.IOException e)
17522535 {
17532536 throw new javax.media.opengl.GLException(e);
....@@ -1756,13 +2539,34 @@
17562539 if (bump)
17572540 texturedata = ConvertBump(texturedata, false);
17582541
1759
- com.sun.opengl.util.texture.Texture texture =
1760
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2542
+// com.sun.opengl.util.texture.Texture texture =
2543
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
17612544
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);
2545
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2546
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
17642547
1765
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
17662570 }
17672571
17682572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -2835,6 +3639,8 @@
28353639
28363640 System.out.println("LOADING TEXTURE : " + name);
28373641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
28383644 //
28393645 if (false) // compressbit > 0)
28403646 {
....@@ -3539,6 +4345,7 @@
35394345
35404346 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
35414347 {
4348
+ new Exception().printStackTrace();
35424349 System.exit(0);
35434350 com.sun.opengl.util.texture.Texture texture = null;
35444351
....@@ -7232,7 +8039,7 @@
72328039 String pigment = Object3D.GetPigment(tex);
72338040 String bump = Object3D.GetBump(tex);
72348041
7235
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
72368043 {
72378044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
72388045 // System.out.println("; bump = " + bump);
....@@ -7247,11 +8054,69 @@
72478054 pigment = null;
72488055 }
72498056
7250
- ReleaseTexture(bump, true);
7251
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
72528059 }
72538060
7254
- void ReleaseTexture(String tex, boolean bump)
8061
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8062
+ {
8063
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8064
+ {
8065
+ return;
8066
+ }
8067
+
8068
+ if (tex == null)
8069
+ {
8070
+ ReleaseTexture(null, false);
8071
+ return;
8072
+ }
8073
+
8074
+ String pigment = Object3D.GetPigment(tex);
8075
+
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8077
+ {
8078
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8079
+ // System.out.println("; bump = " + bump);
8080
+ }
8081
+
8082
+ if (pigment.equals(""))
8083
+ {
8084
+ pigment = null;
8085
+ }
8086
+
8087
+ ReleaseTexture(tex, false);
8088
+ }
8089
+
8090
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8091
+ {
8092
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8093
+ {
8094
+ return;
8095
+ }
8096
+
8097
+ if (tex == null)
8098
+ {
8099
+ ReleaseTexture(null, true);
8100
+ return;
8101
+ }
8102
+
8103
+ String bump = Object3D.GetBump(tex);
8104
+
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8106
+ {
8107
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8108
+ // System.out.println("; bump = " + bump);
8109
+ }
8110
+
8111
+ if (bump.equals(""))
8112
+ {
8113
+ bump = null;
8114
+ }
8115
+
8116
+ ReleaseTexture(tex, true);
8117
+ }
8118
+
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
72558120 {
72568121 if (// DrawMode() != 0 || /*tex == null ||*/
72578122 ambientOcclusion ) // || !textureon)
....@@ -7262,7 +8127,7 @@
72628127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
72638128
72648129 if (tex != null)
7265
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
72668131
72678132 // //assert( texture != null );
72688133 // if (texture == null)
....@@ -7354,7 +8219,55 @@
73548219 }
73558220 }
73568221
7357
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8222
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8223
+ {
8224
+// if (// DrawMode() != 0 || /*tex == null ||*/
8225
+// ambientOcclusion ) // || !textureon)
8226
+// {
8227
+// return; // false;
8228
+// }
8229
+//
8230
+// if (tex == null)
8231
+// {
8232
+// BindTexture(null,false,resolution);
8233
+// BindTexture(null,true,resolution);
8234
+// return;
8235
+// }
8236
+//
8237
+// String pigment = Object3D.GetPigment(tex);
8238
+// String bump = Object3D.GetBump(tex);
8239
+//
8240
+// usedtextures.add(pigment);
8241
+// usedtextures.add(bump);
8242
+//
8243
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8244
+// {
8245
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8246
+// // System.out.println("; bump = " + bump);
8247
+// }
8248
+//
8249
+// if (bump.equals(""))
8250
+// {
8251
+// bump = null;
8252
+// }
8253
+// if (pigment.equals(""))
8254
+// {
8255
+// pigment = null;
8256
+// }
8257
+//
8258
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8259
+// BindTexture(pigment, false, resolution);
8260
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8261
+// BindTexture(bump, true, resolution);
8262
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8263
+//
8264
+// return; // true;
8265
+
8266
+ BindPigmentTexture(tex, resolution);
8267
+ BindBumpTexture(tex, resolution);
8268
+ }
8269
+
8270
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
73588271 {
73598272 if (// DrawMode() != 0 || /*tex == null ||*/
73608273 ambientOcclusion ) // || !textureon)
....@@ -7365,17 +8278,47 @@
73658278 if (tex == null)
73668279 {
73678280 BindTexture(null,false,resolution);
7368
- BindTexture(null,true,resolution);
73698281 return;
73708282 }
73718283
73728284 String pigment = Object3D.GetPigment(tex);
8285
+
8286
+ usedtextures.add(tex);
8287
+
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8289
+ {
8290
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8291
+ // System.out.println("; bump = " + bump);
8292
+ }
8293
+
8294
+ if (pigment.equals(""))
8295
+ {
8296
+ pigment = null;
8297
+ }
8298
+
8299
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8300
+ BindTexture(tex, false, resolution);
8301
+ }
8302
+
8303
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8304
+ {
8305
+ if (// DrawMode() != 0 || /*tex == null ||*/
8306
+ ambientOcclusion ) // || !textureon)
8307
+ {
8308
+ return; // false;
8309
+ }
8310
+
8311
+ if (tex == null)
8312
+ {
8313
+ BindTexture(null,true,resolution);
8314
+ return;
8315
+ }
8316
+
73738317 String bump = Object3D.GetBump(tex);
73748318
7375
- usedtextures.put(pigment, pigment);
7376
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
73778320
7378
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
73798322 {
73808323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
73818324 // System.out.println("; bump = " + bump);
....@@ -7385,43 +8328,94 @@
73858328 {
73868329 bump = null;
73878330 }
7388
- if (pigment.equals(""))
7389
- {
7390
- pigment = null;
7391
- }
73928331
7393
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7394
- BindTexture(pigment, false, resolution);
73958332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7396
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
73978334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7398
-
7399
- return; // true;
74008335 }
74018336
7402
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8337
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8338
+
8339
+ private boolean FileExists(String tex)
74038340 {
7404
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ if (missingTextures.contains(tex))
8342
+ {
8343
+ return false;
8344
+ }
8345
+
8346
+ boolean fileExists = new File(tex).exists();
8347
+
8348
+ if (!fileExists)
8349
+ {
8350
+ // If file exists, the "new File()" is not executed sgain
8351
+ missingTextures.add(tex);
8352
+ }
8353
+
8354
+ return fileExists;
8355
+ }
8356
+
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8358
+ {
8359
+ CacheTexture texturecache = null;
74058360
74068361 if (tex != null)
74078362 {
7408
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
74098365
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;
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
8370
+
8371
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8372
+
8373
+// String[] split = tex.split("Textures");
8374
+// if (split.length > 1)
8375
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8376
+// else
8377
+// if (!texname.startsWith("/"))
8378
+// texname = "/Users/nbriere/Textures/" + texname;
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
8380
+ {
8381
+ texname = fallbackTextureName;
8382
+ }
74168383
74178384 if (CACHETEXTURE)
7418
- texture = textures.get(texname); // TEXTURE CACHE
7419
-
7420
- TextureData texturedata = null;
7421
-
7422
- if (texture == null || texture.resolution < resolution)
74238385 {
7424
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8388
+ else
8389
+ texturecache = bimtextures.get(texdata);
8390
+ }
8391
+
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8393
+ {
8394
+ TextureData texturedata = null;
8395
+
8396
+ if (texdata != null && textureon)
8397
+ {
8398
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8399
+
8400
+ try
8401
+ {
8402
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8403
+ }
8404
+ catch (Exception e)
8405
+ {
8406
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8407
+ }
8408
+
8409
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8410
+ bimtextures.put(texdata, texturecache);
8411
+
8412
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8413
+
8414
+ //Object bim2 = CreateBim(texturecache.texturedata);
8415
+ //bim2 = bim;
8416
+ }
8417
+ else
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
74258419 {
74268420 assert(!bump);
74278421 // if (bump)
....@@ -7432,19 +8426,23 @@
74328426 // }
74338427 // else
74348428 // {
7435
- texture = textures.get(tex);
7436
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
74378431 {
7438
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
74398433 }
8434
+ else
8435
+ new Exception().printStackTrace();
74408436 // }
74418437 } else
7442
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
74438439 {
74448440 assert(bump);
7445
- texture = textures.get(tex);
7446
- if (texture == null)
7447
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8441
+ // texturecache = textures.get(texname); // suspicious
8442
+ if (texturecache == null)
8443
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8444
+ else
8445
+ new Exception().printStackTrace();
74488446 } else
74498447 {
74508448 //if (tex.equals("IMMORTAL"))
....@@ -7452,11 +8450,22 @@
74528450 // texture = GetResourceTexture("default.png");
74538451 //} else
74548452 //{
7455
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
74568454 {
7457
- texture = textures.get(tex);
7458
- if (texture == null)
7459
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8455
+ // texturecache = textures.get(texname); // suspicious
8456
+ if (texturecache == null)
8457
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8458
+ else
8459
+ new Exception().printStackTrace();
8460
+ } else
8461
+ {
8462
+ if (texname.startsWith("@"))
8463
+ {
8464
+ // texturecache = textures.get(texname); // suspicious
8465
+ if (texturecache == null)
8466
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8467
+ else
8468
+ new Exception().printStackTrace();
74608469 } else
74618470 {
74628471 if (textureon)
....@@ -7481,7 +8490,7 @@
74818490 }
74828491
74838492 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7484
- if (!new File(cachename).exists())
8493
+ if (!FileExists(cachename))
74858494 cachename = texname;
74868495 else
74878496 processbump = false; // don't process bump map again
....@@ -7503,7 +8512,7 @@
75038512 }
75048513
75058514 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7506
- if (!new File(cachename).exists())
8515
+ if (!FileExists(cachename))
75078516 cachename = texname;
75088517 else
75098518 processbump = false; // don't process bump map again
....@@ -7512,20 +8521,23 @@
75128521 texturedata = GetFileTexture(cachename, processbump, resolution);
75138522
75148523
7515
- if (texturedata != null)
7516
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8524
+ if (texturedata == null)
8525
+ throw new Exception();
8526
+
8527
+ texturecache = new CacheTexture(texturedata,resolution);
75178528 //texture = GetTexture(tex, bump);
75188529 }
8530
+ }
75198531 }
75208532 //}
75218533 }
75228534
7523
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
75248536 {
75258537 //return false;
75268538
75278539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7528
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
75298541 {
75308542 // String ext = "_highres";
75318543 // if (REDUCETEXTURE)
....@@ -7542,52 +8554,17 @@
75428554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
75438555 if (!cachefile.exists())
75448556 {
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))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
75548558 {
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);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
75858561 ImageWriter writer = null;
75868562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
75878563 if (iter.hasNext()) {
75888564 writer = (ImageWriter)iter.next();
75898565 }
7590
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
75918568 try
75928569 {
75938570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7604,18 +8581,20 @@
76048581 }
76058582 }
76068583 }
7607
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
76088587 //System.out.println("Texture = " + tex);
7609
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
76108589 {
7611
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
76128591 thetex.texture.disable();
76138592 thetex.texture.dispose();
7614
- textures.remove(texname);
8593
+ textures.remove(tex);
76158594 }
76168595
7617
- texture.texturedata = texturedata;
7618
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
76198598
76208599 // newtex = true;
76218600 }
....@@ -7631,10 +8610,44 @@
76318610 }
76328611 }
76338612
7634
- return texture;
8613
+ return texturecache;
76358614 }
76368615
7637
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8616
+ static void EmbedTextures(cTexture tex)
8617
+ {
8618
+ if (tex.pigmentdata == null)
8619
+ {
8620
+ //String texname = Object3D.GetPigment(tex);
8621
+
8622
+ CacheTexture texturecache = texturepigment.get(tex);
8623
+
8624
+ if (texturecache != null)
8625
+ {
8626
+ tex.pw = texturecache.texturedata.getWidth();
8627
+ tex.ph = texturecache.texturedata.getHeight();
8628
+ tex.pigmentdata = //CompressJPEG(CreateBim
8629
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8630
+ ;
8631
+ //, tex.pw, tex.ph), 0.5f);
8632
+ }
8633
+ }
8634
+
8635
+ if (tex.bumpdata == null)
8636
+ {
8637
+ //String texname = Object3D.GetBump(tex);
8638
+
8639
+ CacheTexture texturecache = texturebump.get(tex);
8640
+
8641
+ if (texturecache != null)
8642
+ {
8643
+ tex.bw = texturecache.texturedata.getWidth();
8644
+ tex.bh = texturecache.texturedata.getHeight();
8645
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8646
+ }
8647
+ }
8648
+ }
8649
+
8650
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
76388651 {
76398652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
76408653
....@@ -7652,21 +8665,21 @@
76528665 return texture!=null?texture.texture:null;
76538666 }
76548667
7655
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
76568669 {
76578670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
76588671
76598672 return texture!=null?texture.texturedata:null;
76608673 }
76618674
7662
- boolean BindTexture(String tex, boolean bump, int resolution)
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
76638676 {
76648677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
76658678 {
76668679 return false;
76678680 }
76688681
7669
- boolean newtex = false;
8682
+ //boolean newtex = false;
76708683
76718684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
76728685
....@@ -7698,9 +8711,75 @@
76988711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
76998712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
77008713
7701
- return newtex;
8714
+ return true; // Warning: not used.
77028715 }
77038716
8717
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8718
+ {
8719
+ try
8720
+ {
8721
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8722
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8723
+ ImageWriter writer = writers.next();
8724
+
8725
+ ImageWriteParam param = writer.getDefaultWriteParam();
8726
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8727
+ param.setCompressionQuality(quality);
8728
+
8729
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8730
+ writer.setOutput(ios);
8731
+ writer.write(null, new IIOImage(image, null, null), param);
8732
+
8733
+ byte[] data = baos.toByteArray();
8734
+ writer.dispose();
8735
+ return data;
8736
+ }
8737
+ catch (Exception e)
8738
+ {
8739
+ e.printStackTrace();
8740
+ return null;
8741
+ }
8742
+ }
8743
+
8744
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8745
+ {
8746
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8747
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8748
+ ImageReader reader = writers.next();
8749
+
8750
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8751
+
8752
+ ImageReadParam param = reader.getDefaultReadParam();
8753
+ param.setDestination(bim);
8754
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8755
+
8756
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8757
+ reader.setInput(ios);
8758
+ BufferedImage bim2 = reader.read(0, param);
8759
+ reader.dispose();
8760
+
8761
+// WritableRaster raster = bim2.getRaster();
8762
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8763
+// byte[] bytes = data.getData();
8764
+//
8765
+// int[] pixels = new int[bytes.length/3];
8766
+// for (int i=pixels.length; --i>=0;)
8767
+// {
8768
+// int i3 = i*3;
8769
+// pixels[i] = 0xFF;
8770
+// pixels[i] <<= 8;
8771
+// pixels[i] |= bytes[i3+2] & 0xFF;
8772
+// pixels[i] <<= 8;
8773
+// pixels[i] |= bytes[i3+1] & 0xFF;
8774
+// pixels[i] <<= 8;
8775
+// pixels[i] |= bytes[i3] & 0xFF;
8776
+// }
8777
+//
8778
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8779
+
8780
+ return bim;
8781
+ }
8782
+
77048783 ShadowBuffer shadowPBuf;
77058784 AntialiasBuffer antialiasPBuf;
77068785 int MAXSTACK;
....@@ -7717,10 +8796,12 @@
77178796
77188797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
77198798 MAXSTACK = temp[0];
7720
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
77218801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
77228802 MAXSTACK = temp[0];
7723
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
77248805
77258806 // Use debug pipeline
77268807 //drawable.setGL(new DebugGL(gl)); //
....@@ -7728,7 +8809,8 @@
77288809 gl = drawable.getGL(); //
77298810
77308811 GL gl3 = getGL();
7731
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
77328814
77338815
77348816 //float pos[] = { 100, 100, 100, 0 };
....@@ -7893,7 +8975,7 @@
78938975
78948976 if (cubemap == null)
78958977 {
7896
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
78978979 }
78988980
78998981 //cubemap.enable();
....@@ -8169,6 +9251,8 @@
81699251
81709252 void LoadEnvy(int which)
81719253 {
9254
+ assert(false);
9255
+
81729256 String name;
81739257 String ext;
81749258
....@@ -8180,37 +9264,58 @@
81809264 cubemap = null;
81819265 return;
81829266 case 1:
8183
- name = "cubemaps/box_";
8184
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
81859269 reverseUP = false;
81869270 break;
81879271 case 2:
8188
- name = "cubemaps/uffizi_";
8189
- ext = "png";
8190
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
81919276 case 3:
8192
- name = "cubemaps/CloudyHills_";
8193
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
81949279 reverseUP = false;
81959280 break;
81969281 case 4:
8197
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
81989283 ext = "png";
81999284 reverseUP = false;
82009285 break;
9286
+ case 5:
9287
+ name = "cubemaps/skycube/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 6:
9292
+ name = "cubemaps/SaintLazarusChurch3/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
9296
+ case 7:
9297
+ name = "cubemaps/Sodermalmsallen/";
9298
+ ext = "jpg";
9299
+ reverseUP = false;
9300
+ break;
9301
+ case 8:
9302
+ name = "cubemaps/Sodermalmsallen2/";
9303
+ ext = "jpg";
9304
+ reverseUP = false;
9305
+ break;
9306
+ case 9:
9307
+ name = "cubemaps/UnionSquare/";
9308
+ ext = "jpg";
9309
+ reverseUP = false;
9310
+ break;
82019311 default:
8202
- name = "cubemaps/rgb_";
8203
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
82049315 break;
82059316 }
8206
-
8207
- try
8208
- {
8209
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8210
- } catch (IOException e)
8211
- {
8212
- throw new RuntimeException(e);
8213
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
82149319 }
82159320
82169321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8242,8 +9347,12 @@
82429347 static double[] model = new double[16];
82439348 double[] camera2light = new double[16];
82449349 double[] light2camera = new double[16];
8245
- int newenvy = -1;
8246
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
82479356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
82489357 //float[] light0 = { 0,0,0 };
82499358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -8536,11 +9645,35 @@
85369645 jy8[3] = 0.5f;
85379646 }
85389647
8539
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9648
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
85409649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
85419650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
85429651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
85439652
9653
+ void ResetOptions()
9654
+ {
9655
+ options1[0] = 100;
9656
+ options1[1] = 0.025f;
9657
+ options1[2] = 0.01f;
9658
+ options1[3] = 0;
9659
+ options1[4] = 0;
9660
+
9661
+ options2[0] = 0;
9662
+ options2[1] = 0.75f;
9663
+ options2[2] = 0;
9664
+ options2[3] = 0;
9665
+
9666
+ options3[0] = 1;
9667
+ options3[1] = 1;
9668
+ options3[2] = 1;
9669
+ options3[3] = 0;
9670
+
9671
+ options4[0] = 1;
9672
+ options4[1] = 0;
9673
+ options4[2] = 1;
9674
+ options4[3] = 0;
9675
+ }
9676
+
85449677 static int imagecount = 0; // movie generation
85459678
85469679 static int jitter = 0;
....@@ -8636,8 +9769,8 @@
86369769 assert (parentcam != renderCamera);
86379770
86389771 if (renderCamera != lightCamera)
8639
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8640
- LA.matConcat(matrix, parentcam.toParent, matrix);
9772
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
86419774
86429775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
86439776
....@@ -8652,8 +9785,8 @@
86529785 LA.matCopy(renderCamera.fromScreen, matrix);
86539786
86549787 if (renderCamera != lightCamera)
8655
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8656
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9788
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
86579790
86589791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
86599792
....@@ -8699,10 +9832,12 @@
86999832 rati = 1 / rati;
87009833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
87019834 }
8702
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
87039838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
87049839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
8705
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
87069841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
87079842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
87089843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -8725,7 +9860,7 @@
87259860 //gl.glFlush();
87269861 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
87279862
8728
- if (ANIMATION && ABORTED)
9863
+ if (Globals.ANIMATION && ABORTED)
87299864 {
87309865 System.err.println(" ABORTED FRAME");
87319866 break;
....@@ -8755,7 +9890,7 @@
87559890 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
87569891
87579892 // save image
8758
- if (ANIMATION && !ABORTED)
9893
+ if (Globals.ANIMATION && !ABORTED)
87599894 {
87609895 VPwidth = viewport[2];
87619896 VPheight = viewport[3];
....@@ -8866,11 +10001,11 @@
886610001
886710002 // imagecount++;
886810003
8869
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
10004
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
887010005
887110006 if (!BOXMODE)
887210007 {
8873
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
10008
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
887410009 }
887510010
887610011 if (!BOXMODE)
....@@ -8908,7 +10043,7 @@
890810043 ABORTED = false;
890910044 }
891010045 else
8911
- GrafreeD.wav.cursor += 735 * ACSIZE;
10046
+ Grafreed.wav.cursor += 735 * ACSIZE;
891210047
891310048 if (false)
891410049 {
....@@ -9568,14 +10703,23 @@
956810703 static boolean init = false;
956910704
957010705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
957110709
957210710 public void display(GLAutoDrawable drawable)
957310711 {
9574
- if (GrafreeD.savesound && GrafreeD.hassound)
10712
+ if (patchMaterial.patchMaterial)
957510713 {
9576
- GrafreeD.wav.save();
9577
- GrafreeD.savesound = false;
9578
- GrafreeD.hassound = false;
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
10718
+ if (Grafreed.savesound && Grafreed.hassound)
10719
+ {
10720
+ Grafreed.wav.save();
10721
+ Grafreed.savesound = false;
10722
+ Grafreed.hassound = false;
957910723 }
958010724 // if (DEBUG_SELECTION)
958110725 // {
....@@ -9651,6 +10795,7 @@
965110795 ANTIALIAS = 0;
965210796 //System.out.println("RESTART");
965310797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
965410799 }
965510800 }
965610801 }
....@@ -9705,7 +10850,7 @@
970510850 Object3D theobject = object;
970610851 Object3D theparent = object.parent;
970710852 object.parent = null;
9708
- object = (Object3D)GrafreeD.clone(object);
10853
+ object = (Object3D)Grafreed.clone(object);
970910854 object.Stripify();
971010855 if (theobject.selection == null || theobject.selection.Size() == 0)
971110856 theobject.PreprocessOcclusion(this);
....@@ -9718,13 +10863,14 @@
971810863 ambientOcclusion = false;
971910864 }
972010865
9721
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
972210868 {
972310869 //if (RENDERSHADOW) // ?
972410870 if (!IsFrozen())
972510871 {
972610872 // dec 2012
9727
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10873
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
972810874 {
972910875 Globals.framecount++;
973010876 shadowbuffer.display();
....@@ -9737,7 +10883,7 @@
973710883
973810884 if (wait)
973910885 {
9740
- Sleep(500);
10886
+ Sleep(200); // blocks everything
974110887
974210888 wait = false;
974310889 }
....@@ -9851,8 +10997,8 @@
985110997
985210998 // if (parentcam != renderCamera) // not a light
985310999 if (cam != lightCamera)
9854
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9855
- LA.matConcat(matrix, parentcam.toParent, matrix);
11000
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
985611002
985711003 for (int j = 0; j < 4; j++)
985811004 {
....@@ -9866,8 +11012,8 @@
986611012
986711013 // if (parentcam != renderCamera) // not a light
986811014 if (cam != lightCamera)
9869
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9870
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11015
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
987111017
987211018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
987311019
....@@ -9953,13 +11099,43 @@
995311099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
995411100 }
995511101
9956
- if (newenvy > -1)
11102
+// if (newenvy > -1)
11103
+// {
11104
+// LoadEnvy(newenvy);
11105
+// }
11106
+//
11107
+// newenvy = -1;
11108
+
11109
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
995711110 {
9958
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
995911117 }
9960
-
9961
- newenvy = -1;
9962
-
11118
+ else
11119
+ {
11120
+ if (object.skyboxname != null)
11121
+ {
11122
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11123
+ {
11124
+ if (cubemap != null && cubemap != cubemaprgb)
11125
+ cubemap.dispose();
11126
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11127
+ loadedskyboxname = object.skyboxname;
11128
+ }
11129
+ }
11130
+ else
11131
+ {
11132
+ cubemapcustom = null;
11133
+ loadedskyboxname = null;
11134
+ }
11135
+
11136
+ cubemap = cubemapcustom;
11137
+ }
11138
+
996311139 ratio = ((double) getWidth()) / getHeight();
996411140 //System.out.println("ratio = " + ratio);
996511141
....@@ -9975,7 +11151,7 @@
997511151
997611152 if (!IsFrozen() && !ambientOcclusion)
997711153 {
9978
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
997911155 }
998011156
998111157 //if (selection_view == -1)
....@@ -10126,7 +11302,16 @@
1012611302 // Bump noise
1012711303 gl.glActiveTexture(GL.GL_TEXTURE6);
1012811304 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
10129
- BindTexture(NOISE_TEXTURE, false, 2);
11305
+
11306
+ try
11307
+ {
11308
+ BindTexture(NOISE_TEXTURE, false, 2);
11309
+ }
11310
+ catch (Exception e)
11311
+ {
11312
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11313
+ }
11314
+
1013011315
1013111316 gl.glActiveTexture(GL.GL_TEXTURE0);
1013211317 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -10149,9 +11334,9 @@
1014911334
1015011335 gl.glMatrixMode(GL.GL_MODELVIEW);
1015111336
10152
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
10153
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
10154
-//gl.glEnable(gl.GL_MULTISAMPLE);
11337
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11338
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11339
+gl.glEnable(gl.GL_MULTISAMPLE);
1015511340 } else
1015611341 {
1015711342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -10162,7 +11347,7 @@
1016211347 //System.out.println("BLENDING ON");
1016311348 gl.glEnable(GL.GL_BLEND);
1016411349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
10165
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
1016611351 gl.glMatrixMode(gl.GL_PROJECTION);
1016711352 gl.glLoadIdentity();
1016811353
....@@ -10251,8 +11436,8 @@
1025111436 System.err.println("parentcam != renderCamera");
1025211437
1025311438 // if (cam != lightCamera)
10254
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10255
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11439
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1025611441 }
1025711442
1025811443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10273,8 +11458,8 @@
1027311458 if (true) // TODO
1027411459 {
1027511460 if (cam != lightCamera)
10276
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10277
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11461
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11462
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1027811463 }
1027911464
1028011465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10340,7 +11525,7 @@
1034011525 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
1034111526 //System.out.println("fragmentMode = " + fragmentMode);
1034211527
10343
- if (DrawMode() == DEFAULT || DrawMode() == SELECTION || DEBUG_SELECTION)
11528
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
1034411529 {
1034511530 /*
1034611531 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -10411,7 +11596,7 @@
1041111596 }
1041211597 }
1041311598
10414
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1041511600 {
1041611601 //gl.glDepthFunc(GL.GL_LEQUAL);
1041711602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10419,24 +11604,21 @@
1041911604
1042011605 boolean texon = textureon;
1042111606
10422
- if (RENDERPROGRAM > 0)
10423
- {
10424
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10425
- textureon = false;
10426
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1042711610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1042811611 //System.out.println("ALLO");
1042911612 gl.glColorMask(false, false, false, false);
1043011613 DrawObject(gl);
10431
- if (RENDERPROGRAM > 0)
10432
- {
10433
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10434
- textureon = texon;
10435
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1043611618 gl.glColorMask(true, true, true, true);
1043711619
1043811620 gl.glDepthFunc(GL.GL_EQUAL);
10439
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1044011622 }
1044111623
1044211624 if (false) // DrawMode() == SHADOW)
....@@ -10590,8 +11772,14 @@
1059011772 {
1059111773 renderpass++;
1059211774 // System.out.println("Draw object... ");
11775
+ STEP = 1;
1059311776 if (FAST) // in case there is no script
10594
- STEP = 16;
11777
+ STEP = 8;
11778
+
11779
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11780
+ {
11781
+ STEP *= 4;
11782
+ }
1059511783
1059611784 //object.FullInvariants();
1059711785
....@@ -10605,23 +11793,44 @@
1060511793 e.printStackTrace();
1060611794 }
1060711795
10608
- if (GrafreeD.RENDERME > 0)
10609
- GrafreeD.RENDERME--; // mechante magouille
11796
+ if (Grafreed.RENDERME > 0)
11797
+ Grafreed.RENDERME--; // mechante magouille
1061011798
1061111799 Globals.ONESTEP = false;
1061211800 }
1061311801
1061411802 static boolean zoomonce = false;
1061511803
11804
+ static void CreateSelectedPoint()
11805
+ {
11806
+ if (selectedpoint == null)
11807
+ {
11808
+ debugpointG = new Sphere();
11809
+ debugpointP = new Sphere();
11810
+ debugpointC = new Sphere();
11811
+ debugpointR = new Sphere();
11812
+
11813
+ selectedpoint = new Superellipsoid();
11814
+
11815
+ for (int i=0; i<8; i++)
11816
+ {
11817
+ debugpoints[i] = new Sphere();
11818
+ }
11819
+ }
11820
+ }
11821
+
1061611822 void DrawObject(GL gl, boolean draw)
1061711823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
1061811827 //System.out.println("DRAW OBJECT " + mouseDown);
1061911828 // DrawMode() = SELECTION;
1062011829 //GL gl = getGL();
1062111830 if ((TRACK || SHADOWTRACK) || zoomonce)
1062211831 {
1062311832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10624
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1062511834 pingthread.StepToTarget(true); // true);
1062611835 // zoomonce = false;
1062711836 }
....@@ -10641,7 +11850,7 @@
1064111850 callist = gl.glGenLists(1);
1064211851 }
1064311852
10644
- boolean selectmode = DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
11853
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
1064511854
1064611855 boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
1064711856
....@@ -10676,7 +11885,14 @@
1067611885
1067711886 usedtextures.clear();
1067811887
10679
- BindTextures(DEFAULT_TEXTURES, 2);
11888
+ try
11889
+ {
11890
+ BindTextures(DEFAULT_TEXTURES, 2);
11891
+ }
11892
+ catch (Exception e)
11893
+ {
11894
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11895
+ }
1068011896 }
1068111897 //System.out.println("--> " + stackdepth);
1068211898 // GrafreeD.traceon();
....@@ -10686,8 +11902,9 @@
1068611902
1068711903 if (DrawMode() == DEFAULT)
1068811904 {
10689
- if (DEBUG)
11905
+ if (Globals.DEBUG)
1069011906 {
11907
+ CreateSelectedPoint();
1069111908 float radius = 0.05f;
1069211909 if (selectedpoint.radius != radius)
1069311910 {
....@@ -10741,20 +11958,32 @@
1074111958 ReleaseTextures(DEFAULT_TEXTURES);
1074211959
1074311960 if (CLEANCACHE)
10744
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1074511962 {
10746
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1074711964
1074811965 // System.out.println("Texture --------- " + tex);
1074911966
10750
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1075111968 continue;
1075211969
10753
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1075411971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1075511973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
10756
- textures.get(tex).texture.dispose();
10757
- textures.remove(tex);
11974
+ if (gettex != null)
11975
+ {
11976
+ gettex.texture.dispose();
11977
+ texturepigment.remove(tex);
11978
+ }
11979
+
11980
+ gettex = texturebump.get(tex);
11981
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11982
+ if (gettex != null)
11983
+ {
11984
+ gettex.texture.dispose();
11985
+ texturebump.remove(tex);
11986
+ }
1075811987 }
1075911988 }
1076011989 }
....@@ -10767,7 +11996,14 @@
1076711996 if (checker != null && DrawMode() == DEFAULT)
1076811997 {
1076911998 //BindTexture(IMMORTAL_TEXTURE);
10770
- BindTextures(checker.GetTextures(), checker.texres);
11999
+ try
12000
+ {
12001
+ BindTextures(checker.GetTextures(), checker.texres);
12002
+ }
12003
+ catch (Exception e)
12004
+ {
12005
+ System.err.println("FAILED: " + checker.GetTextures());
12006
+ }
1077112007 // NEAREST
1077212008 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1077312009 DrawChecker(gl);
....@@ -10849,7 +12085,7 @@
1084912085 return;
1085012086 }
1085112087
10852
- String string = obj.GetToolTip();
12088
+ String string = obj.toString(); //.GetToolTip();
1085312089
1085412090 GL gl = GetGL();
1085512091
....@@ -11166,8 +12402,8 @@
1116612402 //obj.TransformToWorld(light, light);
1116712403 for (int i = tp.size(); --i >= 0;)
1116812404 {
11169
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
11170
- LA.xformPos(light, tp.get(i).toParent, light);
12405
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12406
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1117112407 }
1117212408
1117312409
....@@ -11184,8 +12420,8 @@
1118412420 parentcam = cameras[0];
1118512421 }
1118612422
11187
- for (int count = parentcam.GetTransformCount(); --count>=0;)
11188
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12423
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12424
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1118912425
1119012426 LA.xformPos(light, renderCamera.toScreen, light);
1119112427
....@@ -11275,8 +12511,76 @@
1127512511
1127612512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1127712513
11278
- String program =
12514
+ String programmin =
12515
+ // Min shader
1127912516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12520
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12521
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12522
+ "PARAM light2cam0 = program.env[10];" +
12523
+ "PARAM light2cam1 = program.env[11];" +
12524
+ "PARAM light2cam2 = program.env[12];" +
12525
+ "TEMP temp;" +
12526
+ "TEMP light;" +
12527
+ "TEMP ndotl;" +
12528
+ "TEMP normal;" +
12529
+ "TEMP depth;" +
12530
+ "TEMP eye;" +
12531
+ "TEMP pos;" +
12532
+
12533
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12534
+ Normalize("normal") +
12535
+ "MOV light, state.light[0].position;" +
12536
+ "DP3 ndotl.x, light, normal;" +
12537
+
12538
+ // shadow
12539
+ "MOV pos, fragment.texcoord[1];" +
12540
+ "MOV temp, pos;" +
12541
+ ShadowTextureFetch("depth", "temp", "1") +
12542
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12543
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12544
+
12545
+ // No shadow when out of frustum
12546
+ //"SGE temp.y, depth.z, zero123.y;" +
12547
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12548
+
12549
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12550
+
12551
+ // Backlit
12552
+ "MOV pos.w, zero123.y;" +
12553
+ "DP4 eye.x, pos, light2cam0;" +
12554
+ "DP4 eye.y, pos, light2cam1;" +
12555
+ "DP4 eye.z, pos, light2cam2;" +
12556
+ Normalize("eye") +
12557
+
12558
+ "DP3 ndotl.y, -eye, normal;" +
12559
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12560
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12561
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12562
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12563
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12564
+
12565
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12566
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12567
+
12568
+ // Pigment
12569
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12570
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12571
+ "MUL temp, temp, ndotl.x;" +
12572
+
12573
+ "MUL temp, temp, zero123.z;" +
12574
+
12575
+ //"MUL temp, temp, ndotl.y;" +
12576
+
12577
+ "MOV temp.w, zero123.y;" + // reset alpha
12578
+ "MOV result.color, temp;" +
12579
+ "END";
12580
+
12581
+ String programmax =
12582
+ "!!ARBfp1.0\n" +
12583
+
1128012584 //"OPTION ARB_fragment_program_shadow;" +
1128112585 "PARAM light2cam0 = program.env[10];" +
1128212586 "PARAM light2cam1 = program.env[11];" +
....@@ -11302,7 +12606,7 @@
1130212606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1130312607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1130412608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11305
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1130612610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1130712611 "PARAM options1 = program.env[62];" + // fog rgb color
1130812612 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -11391,8 +12695,7 @@
1139112695 "TEMP shininess;" +
1139212696 "\n" +
1139312697 "MOV texSamp, one;" +
11394
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11395
-
12698
+
1139612699 "MOV mapgrid.x, one2048th.x;" +
1139712700 "MOV temp, fragment.texcoord[1];" +
1139812701 /*
....@@ -11413,20 +12716,20 @@
1141312716 "MUL temp, floor, mapgrid.x;" +
1141412717 //"TEX depth0, temp, texture[1], 2D;" +
1141512718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11416
- TextureFetch("depth0", "temp", "1") +
12719
+ ShadowTextureFetch("depth0", "temp", "1") +
1141712720 "") +
1141812721 "ADD temp.x, temp.x, mapgrid.x;" +
1141912722 //"TEX depth1, temp, texture[1], 2D;" +
1142012723 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11421
- TextureFetch("depth1", "temp", "1") +
12724
+ ShadowTextureFetch("depth1", "temp", "1") +
1142212725 "") +
1142312726 "ADD temp.y, temp.y, mapgrid.x;" +
1142412727 //"TEX depth2, temp, texture[1], 2D;" +
11425
- TextureFetch("depth2", "temp", "1") +
12728
+ ShadowTextureFetch("depth2", "temp", "1") +
1142612729 "SUB temp.x, temp.x, mapgrid.x;" +
1142712730 //"TEX depth3, temp, texture[1], 2D;" +
1142812731 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11429
- TextureFetch("depth3", "temp", "1") +
12732
+ ShadowTextureFetch("depth3", "temp", "1") +
1143012733 "") +
1143112734 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1143212735 //"MOV params, material;" +
....@@ -11548,7 +12851,7 @@
1154812851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1154912852 // mar 2013 ??? "KIL alpha.a;" +
1155012853 "MOV alpha, texSamp.aaaa;" + // y;" +
11551
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1155212855 /*
1155312856 "MUL temp.xy, temp, two;" +
1155412857 "TXB bump, temp, texture[0], 2D;" +
....@@ -11634,11 +12937,6 @@
1163412937 "SUB bump0, bump0, half;" +
1163512938 "ADD bump, bump, bump0;" +
1163612939
11637
- "MOV temp.x, texSamp.a;" +
11638
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
11639
- //"LRP texSamp0, params5.x, texSamp0, one;" +
11640
- "MOV texSamp.a, temp.x;" +
11641
-
1164212940 // double-sided
1164312941 /**/
1164412942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -11655,19 +12953,62 @@
1165512953 "MOV normald, normal;" +
1165612954 "MOV normals, normal;" +
1165712955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1165812958 // UV base
1165912959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1166012960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1166112961 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
11662
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
11663
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
11664
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12962
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12963
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12964
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12965
+ Normalize("UP") +
12966
+
1166512967 "XPD V, normal, UP;" +
1166612968 Normalize("V") +
1166712969 "XPD U, V, normal;" +
1166812970 Normalize("U") +
1166912971
1167012972 // parallax mapping
12973
+
12974
+ "DP3 temp2.x, V, eye;" +
12975
+ "DP3 temp2.y, U, eye;" +
12976
+ "DP3 temp2.z, normal, eye;" +
12977
+ "RCP temp2.z, temp2.z;" +
12978
+
12979
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12980
+ "RSQ temp2.w, temp2.w;" +
12981
+ "RCP temp2.w, temp2.w;" +
12982
+
12983
+ "SUB temp2.w, temp2.w, half;" +
12984
+// "SGE temp.x, temp2.w, eps.x;" +
12985
+// "MUL temp2.w, temp2.w, temp.x;" +
12986
+
12987
+ //"MOV texSamp, U;" +
12988
+
12989
+ "MUL temp2.z, temp2.z, temp2.w;" +
12990
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12991
+
12992
+ "MUL temp2, temp2, temp2.z;" +
12993
+
12994
+ "MOV temp, fragment.texcoord[0];" +
12995
+
12996
+ "SUB temp, temp, temp2;" +
12997
+
12998
+ "TEX temp, temp, texture[0], 2D;" +
12999
+ "POW temp.a, temp.a, params6.w;" + // punch through
13000
+
13001
+ "ADD texSamp, temp, texSamp;" +
13002
+ "MUL texSamp.xyz, half, texSamp;" +
13003
+
13004
+ "MOV alpha, texSamp.aaaa;" +
13005
+
13006
+// parallax mapping
13007
+
13008
+ "MOV temp.x, texSamp.a;" +
13009
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13010
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13011
+ "MOV texSamp.a, temp.x;" +
1167113012
1167213013 //"MOV temp, fragment.texcoord[0];" +
1167313014 //
....@@ -11797,10 +13138,10 @@
1179713138 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1179813139 "") +
1179913140
11800
- // display shadow only (bump == 0)
13141
+ // display shadow only (fakedepth == 0)
1180113142 "SUB temp.x, half.x, shadow.x;" +
11802
- "MOV temp.y, -params6.x;" +
11803
- "SLT temp.z, temp.y, zero.x;" +
13143
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1180413145 "SUB temp.y, one.x, temp.z;" +
1180513146 "MUL temp.x, temp.x, temp.y;" +
1180613147 "KIL temp.x;" +
....@@ -11929,8 +13270,10 @@
1192913270 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1193013271
1193113272 "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
13273
+ // Tuning for default skin
13274
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13275
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13276
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1193413277 "MUL temp.x, temp.x, temp.y;" +
1193513278
1193613279 "MUL saturation, saturation, temp.xxxx;" +
....@@ -12129,8 +13472,19 @@
1212913472 //once = true;
1213013473 }
1213113474
12132
- System.out.print("Program #" + mode + "; length = " + program.length());
12133
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13475
+ String program = programmax;
13476
+
13477
+ if (Globals.MINSHADER)
13478
+ {
13479
+ program = programmin;
13480
+ }
13481
+
13482
+ if (Globals.DEBUG)
13483
+ {
13484
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13485
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13486
+ }
13487
+
1213413488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1213513489
1213613490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12177,7 +13531,8 @@
1217713531 "\n" +
1217813532 "END\n";
1217913533
12180
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1218113536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1218213537
1218313538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12222,25 +13577,26 @@
1222213577 return out;
1222313578 }
1222413579
12225
- String TextureFetch(String dest, String src, String unit)
13580
+ // Also does frustum culling
13581
+ String ShadowTextureFetch(String dest, String src, String unit)
1222613582 {
1222713583 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1222813584 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1222913585 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13586
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13587
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1223013588 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12231
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12232
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12233
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12234
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13589
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13590
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1223513591 //"SWZ buffer, temp, w,w,w,w;";
12236
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13592
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1223713593 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1223813594 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1223913595 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12240
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13596
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1224113597
12242
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12243
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13598
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13599
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1224413600 }
1224513601
1224613602 String Shadow(String depth, String shadow)
....@@ -12262,12 +13618,16 @@
1226213618
1226313619 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1226413620 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13621
+
13622
+ // Compare fragment depth in light space with shadowmap.
1226513623 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1226613624 "SGE temp.y, temp.x, zero.x;" +
12267
- "SUB " + shadow + ".y, one.x, temp.y;" +
13625
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13626
+
13627
+ // Reverse comparison
1226813628 "SUB temp.x, one.x, temp.x;" +
1226913629 "MUL " + shadow + ".x, temp.x, temp.y;" +
12270
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13630
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1227113631 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1227213632
1227313633 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12281,6 +13641,10 @@
1228113641 // No shadow for backface
1228213642 "DP3 temp.x, normal, lightd;" +
1228313643 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13644
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13645
+
13646
+ // No shadow when out of frustum
13647
+ "SGE temp.x, " + depth + ".z, one.z;" +
1228413648 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1228513649 "";
1228613650 }
....@@ -12426,8 +13790,9 @@
1242613790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1242713791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1242813792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
12429
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12430
- Object3D.cVector2[] vector2buffer;
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13794
+
13795
+ //Object3D.cVector2[] vector2buffer;
1243113796
1243213797 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1243313798 // OUT : diff, spec
....@@ -12443,9 +13808,10 @@
1244313808 "DP3 " + dest + ".z," + "normals," + "eye;" +
1244413809 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1244513810 //"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;" +
13811
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13812
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13813
+
13814
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1244913815 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1245013816 "RCP " + dest + ".w," + dest + ".w;" +
1245113817 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -12591,7 +13957,7 @@
1259113957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1259213958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1259313959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12594
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1259513961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1259613962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1259713963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -12652,7 +14018,7 @@
1265214018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1265314019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1265414020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
12655
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1265614022 "MOV result.texcoord, temp;" +
1265714023 // border fade
1265814024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -12699,7 +14065,9 @@
1269914065
1270014066 //"ADD temp.z, temp.z, one;" +
1270114067
12702
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1270314071 : "MOV result.color, vertex.color;") +
1270414072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1270514073 : "") +
....@@ -12839,7 +14207,7 @@
1283914207 public void mousePressed(MouseEvent e)
1284014208 {
1284114209 //System.out.println("mousePressed: " + e);
12842
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14210
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1284314211 }
1284414212
1284514213 static long prevtime = 0;
....@@ -12866,6 +14234,7 @@
1286614234
1286714235 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1286814236
14237
+ if (BUTTONLESSWHEEL)
1286914238 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1287014239 {
1287114240 return;
....@@ -12874,7 +14243,7 @@
1287414243 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1287514244
1287614245 // TIMER
12877
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14246
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1287814247 {
1287914248 keepboxmode = BOXMODE;
1288014249 keepsupport = SUPPORT;
....@@ -12914,8 +14283,8 @@
1291414283 // mode |= META;
1291514284 //}
1291614285
12917
- SetMouseMode(WHEEL | e.getModifiersEx());
12918
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14286
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14287
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1291914288 anchorX = ax;
1292014289 anchorY = ay;
1292114290 prevX = px;
....@@ -12949,6 +14318,7 @@
1294914318 else
1295014319 if (evt.getSource() == AAtimer)
1295114320 {
14321
+ Globals.TIMERRUNNING = false;
1295214322 if (mouseDown)
1295314323 {
1295414324 //new Exception().printStackTrace();
....@@ -12974,6 +14344,10 @@
1297414344 // LIVE = waslive;
1297514345 // wasliveok = true;
1297614346 // waslive = false;
14347
+
14348
+ // May 2019 Forget it:
14349
+ if (true)
14350
+ return;
1297714351
1297814352 // source == timer
1297914353 if (mouseDown)
....@@ -13004,7 +14378,7 @@
1300414378
1300514379 // fev 2014???
1300614380 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
13007
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14381
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1300814382 pingthread.StepToTarget(true); // true);
1300914383 }
1301014384 // if (!LIVE)
....@@ -13013,12 +14387,13 @@
1301314387
1301414388 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1301514389
13016
- void clickStart(int x, int y, int modifiers)
14390
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1301714391 {
1301814392 if (!wasliveok)
1301914393 return;
1302014394
1302114395 AAtimer.restart(); //
14396
+ Globals.TIMERRUNNING = true;
1302214397
1302314398 // waslive = LIVE;
1302414399 // LIVE = false;
....@@ -13030,7 +14405,7 @@
1303014405 // touched = true; // main DL
1303114406 if (isRenderer)
1303214407 {
13033
- SetMouseMode(modifiers);
14408
+ SetMouseMode(modifiers, modifiersex);
1303414409 }
1303514410
1303614411 selectX = anchorX = x;
....@@ -13043,7 +14418,7 @@
1304314418 clicked = true;
1304414419 hold = false;
1304514420
13046
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14421
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1304714422 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1304814423 {
1304914424 // System.out.println("RESTART II " + modifiers);
....@@ -13068,14 +14443,15 @@
1306814443 drag = false;
1306914444 //System.out.println("Mouse DOWN");
1307014445 editObj = false;
13071
- ClickInfo info = new ClickInfo();
13072
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13073
- info.pane = this;
13074
- info.camera = renderCamera;
13075
- info.x = x;
13076
- info.y = y;
13077
- info.modifiers = modifiers;
13078
- editObj = object.doEditClick(info, 0);
14446
+ //ClickInfo info = new ClickInfo();
14447
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14448
+ object.clickInfo.pane = this;
14449
+ object.clickInfo.camera = renderCamera;
14450
+ object.clickInfo.x = x;
14451
+ object.clickInfo.y = y;
14452
+ object.clickInfo.modifiers = modifiersex;
14453
+ editObj = object.doEditClick(//info,
14454
+ 0);
1307914455 if (!editObj)
1308014456 {
1308114457 hasMarquee = true;
....@@ -13091,11 +14467,14 @@
1309114467
1309214468 public void mouseDragged(MouseEvent e)
1309314469 {
14470
+ Globals.MOUSEDRAGGED = true;
14471
+
14472
+ //System.out.println("mouseDragged: " + e);
1309414473 if (isRenderer)
1309514474 movingcamera = true;
14475
+
1309614476 //if (drawing)
1309714477 //return;
13098
- //System.out.println("mouseDragged: " + e);
1309914478 if ((e.getModifiersEx() & CTRL) != 0
1310014479 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1310114480 {
....@@ -13103,7 +14482,7 @@
1310314482 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1310414483 }
1310514484 else
13106
- drag(e.getX(), e.getY(), e.getModifiersEx());
14485
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1310714486
1310814487 //try { Thread.sleep(1); } catch (Exception ex) {}
1310914488 }
....@@ -13115,6 +14494,11 @@
1311514494 cVector tmp = new cVector();
1311614495 cVector tmp2 = new cVector();
1311714496 boolean isMoving;
14497
+
14498
+ public cVector TargetLookAt()
14499
+ {
14500
+ return targetLookAt;
14501
+ }
1311814502
1311914503 class PingThread extends Thread
1312014504 {
....@@ -13271,6 +14655,7 @@
1327114655
1327214656 public void run()
1327314657 {
14658
+ new Exception().printStackTrace();
1327414659 System.exit(0);
1327514660 for (;;)
1327614661 {
....@@ -13334,7 +14719,7 @@
1333414719 {
1333514720 Globals.lighttouched = true;
1333614721 }
13337
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14722
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1333814723 }
1333914724 //else
1334014725 }
....@@ -13348,12 +14733,18 @@
1334814733 void GoDown(int mod)
1334914734 {
1335014735 MODIFIERS |= COMMAND;
13351
- /*
14736
+ boolean isVR = (mouseMode&VR)!=0;
14737
+ /**/
1335214738 if((mod&SHIFT) == SHIFT)
13353
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1335414745 else
13355
- manipCamera.BackForth(0, -speed*delta, getWidth());
13356
- */
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14747
+ /**/
1335714748 if ((mod & SHIFT) == SHIFT)
1335814749 {
1335914750 mouseMode = mouseMode; // VR??
....@@ -13362,6 +14753,8 @@
1336214753 mouseMode |= BACKFORTH;
1336314754 }
1336414755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1336514758 //prevX = X = anchorX;
1336614759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1336714760 }
....@@ -13369,12 +14762,19 @@
1336914762 void GoUp(int mod)
1337014763 {
1337114764 MODIFIERS |= COMMAND;
13372
- /*
14765
+ /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1337314768 if((mod&SHIFT) == SHIFT)
13374
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1337514775 else
13376
- manipCamera.BackForth(0, speed*delta, getWidth());
13377
- */
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14777
+ /**/
1337814778 if ((mod & SHIFT) == SHIFT)
1337914779 {
1338014780 mouseMode = mouseMode;
....@@ -13383,6 +14783,8 @@
1338314783 mouseMode |= BACKFORTH;
1338414784 }
1338514785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1338614788 //prevX = X = anchorX;
1338714789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1338814790 }
....@@ -13390,12 +14792,17 @@
1339014792 void GoLeft(int mod)
1339114793 {
1339214794 MODIFIERS |= COMMAND;
13393
- /*
14795
+ /**/
1339414796 if((mod&SHIFT) == SHIFT)
13395
- manipCamera.RotatePosition(speed, 0);
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1339614798 else
13397
- manipCamera.Translate(speed*delta, 0, getWidth());
13398
- */
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
14805
+ /**/
1339914806 if ((mod & SHIFT) == SHIFT)
1340014807 {
1340114808 mouseMode = mouseMode;
....@@ -13404,6 +14811,8 @@
1340414811 mouseMode |= ROTATE;
1340514812 } // TRANSLATE;
1340614813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1340714816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1340814817 prevY = Y = anchorY;
1340914818 }
....@@ -13411,12 +14820,18 @@
1341114820 void GoRight(int mod)
1341214821 {
1341314822 MODIFIERS |= COMMAND;
13414
- /*
14823
+ /**/
1341514824 if((mod&SHIFT) == SHIFT)
13416
- manipCamera.RotatePosition(-speed, 0);
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1341714826 else
13418
- manipCamera.Translate(-speed*delta, 0, getWidth());
13419
- */
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
14834
+ /**/
1342014835 if ((mod & SHIFT) == SHIFT)
1342114836 {
1342214837 mouseMode = mouseMode;
....@@ -13425,6 +14840,8 @@
1342514840 mouseMode |= ROTATE;
1342614841 } // TRANSLATE;
1342714842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1342814845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1342914846 prevY = Y = anchorY;
1343014847 }
....@@ -13434,7 +14851,7 @@
1343414851 int X, Y;
1343514852 boolean SX, SY;
1343614853
13437
- void drag(int x, int y, int modifiers)
14854
+ void drag(int x, int y, int modifiers, int modifiersex)
1343814855 {
1343914856 if (IsFrozen())
1344014857 {
....@@ -13443,17 +14860,17 @@
1344314860
1344414861 drag = true; // NEW
1344514862
13446
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14863
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1344714864
1344814865 X = x;
1344914866 Y = y;
1345014867 // floating state for animation
13451
- MODIFIERS = modifiers;
13452
- modifiers &= ~1024;
14868
+ MODIFIERS = modifiersex;
14869
+ modifiersex &= ~1024;
1345314870 if (false) // modifiers != 0)
1345414871 {
1345514872 //new Exception().printStackTrace();
13456
- System.out.println("mouseDragged: " + modifiers);
14873
+ System.out.println("mouseDragged: " + modifiersex);
1345714874 System.out.println("SHIFT = " + SHIFT);
1345814875 System.out.println("CONTROL = " + COMMAND);
1345914876 System.out.println("META = " + META);
....@@ -13466,14 +14883,16 @@
1346614883 if (editObj)
1346714884 {
1346814885 drag = true;
13469
- ClickInfo info = new ClickInfo();
13470
- info.bounds.setBounds(0, 0,
14886
+ //ClickInfo info = new ClickInfo();
14887
+ object.clickInfo.bounds.setBounds(0, 0,
1347114888 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13472
- info.pane = this;
13473
- info.camera = renderCamera;
13474
- info.x = x;
13475
- info.y = y;
13476
- object.editWindow.copy.doEditDrag(info);
14889
+ object.clickInfo.pane = this;
14890
+ object.clickInfo.camera = renderCamera;
14891
+ object.clickInfo.x = x;
14892
+ object.clickInfo.y = y;
14893
+ object //.GetWindow().copy
14894
+ .doEditDrag(//info,
14895
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1347714896 } else
1347814897 {
1347914898 if (x < startX)
....@@ -13622,23 +15041,27 @@
1362215041 }
1362315042 }
1362415043
15044
+// ClickInfo clickInfo = new ClickInfo();
15045
+
1362515046 public void mouseMoved(MouseEvent e)
1362615047 {
1362715048 //System.out.println("mouseMoved: " + e);
13628
-
1362915049 if (isRenderer)
1363015050 return;
1363115051
13632
- ClickInfo ci = new ClickInfo();
13633
- ci.x = e.getX();
13634
- ci.y = e.getY();
13635
- ci.modifiers = e.getModifiersEx();
13636
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13637
- ci.pane = this;
13638
- ci.camera = renderCamera;
15052
+ // Mouse cursor feedback
15053
+ object.clickInfo.x = e.getX();
15054
+ object.clickInfo.y = e.getY();
15055
+ object.clickInfo.modifiers = e.getModifiersEx();
15056
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15057
+ object.clickInfo.pane = this;
15058
+ object.clickInfo.camera = renderCamera;
1363915059 if (!isRenderer)
1364015060 {
13641
- if (object.editWindow.copy.doEditClick(ci, 0))
15061
+ //ObjEditor editWindow = object.editWindow;
15062
+ //Object3D copy = editWindow.copy;
15063
+ if (object.doEditClick(//clickInfo,
15064
+ 0))
1364215065 {
1364315066 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1364415067 } else
....@@ -13650,7 +15073,11 @@
1365015073
1365115074 public void mouseReleased(MouseEvent e)
1365215075 {
15076
+ Globals.MOUSEDRAGGED = false;
15077
+
1365315078 movingcamera = false;
15079
+ X = 0; // getBounds().width/2;
15080
+ Y = 0; // getBounds().height/2;
1365415081 //System.out.println("mouseReleased: " + e);
1365515082 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1365615083 }
....@@ -13673,9 +15100,9 @@
1367315100 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1367415101 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1367515102
13676
- if (control || command || IsFrozen())
15103
+// No delay if (control || command || IsFrozen())
1367715104 timeout = true;
13678
- else
15105
+// ?? May 2019 else
1367915106 // timer.setDelay((modifiers & 128) != 0?0:350);
1368015107 mouseDown = false;
1368115108 if (!control && !command) // june 2013
....@@ -13785,7 +15212,7 @@
1378515212 System.out.println("keyReleased: " + e);
1378615213 }
1378715214
13788
- void SetMouseMode(int modifiers)
15215
+ void SetMouseMode(int modifiers, int modifiersex)
1378915216 {
1379015217 //System.out.println("SetMouseMode = " + modifiers);
1379115218 //modifiers &= ~1024;
....@@ -13797,25 +15224,25 @@
1379715224 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1379815225 // return;
1379915226 //System.out.println("SetMode = " + modifiers);
13800
- if ((modifiers & WHEEL) == WHEEL)
15227
+ if ((modifiersex & WHEEL) == WHEEL)
1380115228 {
1380215229 mouseMode |= ZOOM;
1380315230 }
1380415231
1380515232 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
13806
- if (capsLocked || (modifiers & META) == META)
15233
+ if (capsLocked) // || (modifiers & META) == META)
1380715234 {
1380815235 mouseMode |= VR; // BACKFORTH;
1380915236 }
13810
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15237
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1381115238 {
1381215239 mouseMode |= SELECT;
1381315240 }
13814
- if ((modifiers & COMMAND) == COMMAND)
15241
+ if ((modifiersex & COMMAND) == COMMAND)
1381515242 {
1381615243 mouseMode |= SELECT;
1381715244 }
13818
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15245
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1381915246 {
1382015247 mouseMode &= ~VR;
1382115248 mouseMode |= TRANSLATE;
....@@ -13844,10 +15271,10 @@
1384415271
1384515272 if (isRenderer) //
1384615273 {
13847
- SetMouseMode(modifiers);
15274
+ SetMouseMode(0, modifiers);
1384815275 }
1384915276
13850
- theRenderer.keyPressed(key);
15277
+ Globals.theRenderer.keyPressed(key);
1385115278 }
1385215279
1385315280 int kompactbit = 4; // power bit
....@@ -13859,7 +15286,7 @@
1385915286 float SATPOW = 1; // 2; // 0.5f;
1386015287 float BRIPOW = 1; // 0.5f; // 0.5f;
1386115288
13862
- void keyPressed(int key)
15289
+ public void keyPressed(int key)
1386315290 {
1386415291 if (key >= '0' && key <= '5')
1386515292 clampbit = (key-'0');
....@@ -13906,7 +15333,8 @@
1390615333 // break;
1390715334 case 'T':
1390815335 CACHETEXTURE ^= true;
13909
- textures.clear();
15336
+ texturepigment.clear();
15337
+ texturebump.clear();
1391015338 // repaint();
1391115339 break;
1391215340 case 'Y':
....@@ -13916,8 +15344,8 @@
1391615344 case 'K':
1391715345 KOMPACTTEXTURE ^= true;
1391815346 //textures.clear();
13919
- break;
13920
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1392115349 // SAVETEXTURE ^= true;
1392215350 macromode = true;
1392315351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -13991,7 +15419,9 @@
1399115419 case 'E' : COMPACT ^= true;
1399215420 repaint();
1399315421 break;
13994
- case 'W' : DEBUGHSB ^= true;
15422
+ case 'W' : // Wide Window (fullscreen)
15423
+ //DEBUGHSB ^= true;
15424
+ ObjEditor.theFrame.ToggleFullScreen();
1399515425 repaint();
1399615426 break;
1399715427 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -14016,8 +15446,8 @@
1401615446 RevertCamera();
1401715447 repaint();
1401815448 break;
14019
- case 'L':
1402015449 case 'l':
15450
+ //case 'L':
1402115451 if (lightMode)
1402215452 {
1402315453 lightMode = false;
....@@ -14036,7 +15466,7 @@
1403615466 targetLookAt.set(manipCamera.lookAt);
1403715467 repaint();
1403815468 break;
14039
- case 'p':
15469
+ case 'P': // p':
1404015470 // c'est quoi ca au juste? spherical ^= true;
1404115471 Skinshader ^= true; programInitialized = false;
1404215472 repaint();
....@@ -14081,20 +15511,24 @@
1408115511 OCCLUSION_CULLING ^= true;
1408215512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1408315513 break;
14084
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1408515515 case '1':
1408615516 case '2':
1408715517 case '3':
1408815518 case '4':
1408915519 case '5':
14090
- newenvy = Character.getNumericValue(key);
14091
- repaint();
14092
- break;
1409315520 case '6':
1409415521 case '7':
1409515522 case '8':
1409615523 case '9':
14097
- BGcolor = (key - '6')/3.f;
15524
+ if (true) // envyoff)
15525
+ {
15526
+ BGcolor = (key - '1')/8.f;
15527
+ }
15528
+ else
15529
+ {
15530
+ //newenvy = Character.getNumericValue(key);
15531
+ }
1409815532 repaint();
1409915533 break;
1410015534 case '!':
....@@ -14160,9 +15594,9 @@
1416015594 case '_':
1416115595 kompactbit = 5;
1416215596 break;
14163
- case '+':
14164
- kompactbit = 6;
14165
- break;
15597
+// case '+':
15598
+// kompactbit = 6;
15599
+// break;
1416615600 case ' ':
1416715601 lightMode ^= true;
1416815602 Globals.lighttouched = true;
....@@ -14174,13 +15608,14 @@
1417415608 case ESC:
1417515609 RENDERPROGRAM += 1;
1417615610 RENDERPROGRAM %= 3;
15611
+
1417715612 repaint();
1417815613 break;
1417915614 case 'Z':
1418015615 //RESIZETEXTURE ^= true;
1418115616 //break;
1418215617 case 'z':
14183
- RENDERSHADOW ^= true;
15618
+ Globals.RENDERSHADOW ^= true;
1418415619 Globals.lighttouched = true;
1418515620 repaint();
1418615621 break;
....@@ -14213,8 +15648,9 @@
1421315648 case DELETE:
1421415649 ClearSelection();
1421515650 break;
14216
- /*
1421715651 case '+':
15652
+
15653
+ /*
1421815654 //fontsize += 1;
1421915655 bbzoom *= 2;
1422015656 repaint();
....@@ -14231,17 +15667,17 @@
1423115667 case '=':
1423215668 IncDepth();
1423315669 //fontsize += 1;
14234
- object.editWindow.refreshContents(true);
15670
+ object.GetWindow().refreshContents(true);
1423515671 maskbit = 6;
1423615672 break;
1423715673 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1423815674 DecDepth();
1423915675 maskbit = 5;
1424015676 //if(fontsize > 1) fontsize -= 1;
14241
- if (object.editWindow == null)
14242
- new Exception().printStackTrace();
14243
- else
14244
- object.editWindow.refreshContents(true);
15677
+// if (object.editWindow == null)
15678
+// new Exception().printStackTrace();
15679
+// else
15680
+ object.GetWindow().refreshContents(true);
1424515681 break;
1424615682 case '{':
1424715683 manipCamera.shaper_fovy /= 1.1;
....@@ -14296,6 +15732,7 @@
1429615732 }
1429715733 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1429815734 }
15735
+
1429915736 static double OCCLUSIONBOOST = 1; // 0.5;
1430015737
1430115738 void keyReleased(int key, int modifiers)
....@@ -14303,11 +15740,11 @@
1430315740 //mode = ROTATE;
1430415741 if ((MODIFIERS & COMMAND) == 0) // VR??
1430515742 {
14306
- SetMouseMode(modifiers);
15743
+ SetMouseMode(0, modifiers);
1430715744 }
1430815745 }
1430915746
14310
- protected void processKeyEvent(KeyEvent e)
15747
+ public void processKeyEvent(KeyEvent e)
1431115748 {
1431215749 switch (e.getID())
1431315750 {
....@@ -14437,8 +15874,9 @@
1443715874
1443815875 protected void processMouseMotionEvent(MouseEvent e)
1443915876 {
14440
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14441
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15877
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15878
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15879
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1444215880 {
1444315881 mouseMoved(e);
1444415882 } else
....@@ -14463,11 +15901,12 @@
1446315901 }
1446415902 */
1446515903
14466
- object.editWindow.EditSelection();
15904
+ object.GetWindow().EditSelection(false);
1446715905 }
1446815906
1446915907 void SelectParent()
1447015908 {
15909
+ new Exception().printStackTrace();
1447115910 System.exit(0);
1447215911 Composite group = (Composite) object;
1447315912 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14479,10 +15918,10 @@
1447915918 {
1448015919 //selectees.remove(i);
1448115920 System.out.println("select parent of " + elem);
14482
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15921
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1448315922 } else
1448415923 {
14485
- group.editWindow.Select(elem.GetTreePath(), first, true);
15924
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1448615925 }
1448715926
1448815927 first = false;
....@@ -14491,6 +15930,7 @@
1449115930
1449215931 void SelectChildren()
1449315932 {
15933
+ new Exception().printStackTrace();
1449415934 System.exit(0);
1449515935 /*
1449615936 Composite group = (Composite) object;
....@@ -14523,12 +15963,12 @@
1452315963 for (int j = 0; j < group.children.size(); j++)
1452415964 {
1452515965 elem = (Object3D) group.children.elementAt(j);
14526
- object.editWindow.Select(elem.GetTreePath(), first, true);
15966
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1452715967 first = false;
1452815968 }
1452915969 } else
1453015970 {
14531
- object.editWindow.Select(elem.GetTreePath(), first, true);
15971
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1453215972 }
1453315973
1453415974 first = false;
....@@ -14539,21 +15979,21 @@
1453915979 {
1454015980 //Composite group = (Composite) object;
1454115981 Object3D group = object;
14542
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15982
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1454315983 }
1454415984
1454515985 void ResetTransform(int mask)
1454615986 {
1454715987 //Composite group = (Composite) object;
1454815988 Object3D group = object;
14549
- group.editWindow.ResetTransform(mask);
15989
+ group.GetWindow().ResetTransform(mask);
1455015990 }
1455115991
1455215992 void FlipTransform()
1455315993 {
1455415994 //Composite group = (Composite) object;
1455515995 Object3D group = object;
14556
- group.editWindow.FlipTransform();
15996
+ group.GetWindow().FlipTransform();
1455715997 // group.editWindow.ReduceMesh(true);
1455815998 }
1455915999
....@@ -14561,7 +16001,7 @@
1456116001 {
1456216002 //Composite group = (Composite) object;
1456316003 Object3D group = object;
14564
- group.editWindow.PrintMemory();
16004
+ group.GetWindow().PrintMemory();
1456516005 // group.editWindow.ReduceMesh(true);
1456616006 }
1456716007
....@@ -14569,7 +16009,7 @@
1456916009 {
1457016010 //Composite group = (Composite) object;
1457116011 Object3D group = object;
14572
- group.editWindow.ResetCentroid();
16012
+ group.GetWindow().ResetCentroid();
1457316013 }
1457416014
1457516015 void IncDepth()
....@@ -14651,11 +16091,11 @@
1465116091
1465216092 int width = getBounds().width;
1465316093 int height = getBounds().height;
14654
- ClickInfo info = new ClickInfo();
14655
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1465616094 //Image img = CreateImage(width, height);
1465716095 //System.out.println("width = " + width + "; height = " + height + "\n");
16096
+
1465816097 Graphics gr = g; // img.getGraphics();
16098
+
1465916099 if (!hasMarquee)
1466016100 {
1466116101 if (Xmin < Xmax) // !locked)
....@@ -14727,44 +16167,92 @@
1472716167 }
1472816168 if (object != null && !hasMarquee)
1472916169 {
16170
+ if (object.clickInfo == null)
16171
+ object.clickInfo = new ClickInfo();
16172
+ ClickInfo info = object.clickInfo;
16173
+ //ClickInfo info = new ClickInfo();
16174
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16175
+
1473016176 if (isRenderer)
1473116177 {
14732
- info.flags++;
16178
+ object.clickInfo.flags++;
1473316179 double frameAspect = (double) width / (double) height;
1473416180 if (frameAspect > renderCamera.aspect)
1473516181 {
1473616182 int desired = (int) ((double) height * renderCamera.aspect);
14737
- info.bounds.width -= width - desired;
14738
- info.bounds.x += (width - desired) / 2;
16183
+ object.clickInfo.bounds.width -= width - desired;
16184
+ object.clickInfo.bounds.x += (width - desired) / 2;
1473916185 } else
1474016186 {
1474116187 int desired = (int) ((double) width / renderCamera.aspect);
14742
- info.bounds.height -= height - desired;
14743
- info.bounds.y += (height - desired) / 2;
16188
+ object.clickInfo.bounds.height -= height - desired;
16189
+ object.clickInfo.bounds.y += (height - desired) / 2;
1474416190 }
1474516191 }
14746
- info.g = gr;
14747
- info.camera = renderCamera;
16192
+
16193
+ object.clickInfo.g = gr;
16194
+ object.clickInfo.camera = renderCamera;
1474816195 /*
1474916196 // Memory intensive (brep.verticescopy)
1475016197 if (!(object instanceof Composite))
1475116198 object.draw(info, 0, false); // SLOW :
1475216199 */
14753
- if (!isRenderer)
16200
+ if (!isRenderer) // && drag)
1475416201 {
14755
- object.drawEditHandles(info, 0);
16202
+ Grafreed.Assert(object != null);
16203
+ Grafreed.Assert(object.selection != null);
16204
+ if (object.selection.Size() > 0)
16205
+ {
16206
+ int hitSomething = object.selection.get(0).hitSomething;
16207
+
16208
+ object.clickInfo.DX = 0;
16209
+ object.clickInfo.DY = 0;
16210
+ object.clickInfo.W = 1;
16211
+ if (hitSomething == Object3D.hitCenter)
16212
+ {
16213
+ info.DX = X;
16214
+ if (X != 0)
16215
+ info.DX -= info.bounds.width/2;
16216
+
16217
+ info.DY = Y;
16218
+ if (Y != 0)
16219
+ info.DY -= info.bounds.height/2;
16220
+ }
16221
+
16222
+ object.drawEditHandles(//info,
16223
+ 0);
16224
+
16225
+ if (drag && (X != 0 || Y != 0))
16226
+ {
16227
+ switch (hitSomething)
16228
+ {
16229
+ case Object3D.hitCenter: gr.setColor(Color.white);
16230
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16231
+ break;
16232
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16233
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16234
+ break;
16235
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ }
16239
+
16240
+ }
16241
+ }
1475616242 }
1475716243 }
16244
+
1475816245 if (isRenderer)
1475916246 {
1476016247 //gr.setColor(Color.black);
1476116248 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1476216249 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1476316250 }
16251
+
1476416252 if (hasMarquee)
1476516253 {
1476616254 gr.setXORMode(Color.white);
14767
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1476816256 if (!firstime)
1476916257 {
1477016258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -14873,6 +16361,7 @@
1487316361 public boolean mouseDown(Event evt, int x, int y)
1487416362 {
1487516363 System.out.println("mouseDown: " + evt);
16364
+ System.exit(0);
1487616365 /*
1487716366 locked = true;
1487816367 drag = false;
....@@ -14916,7 +16405,7 @@
1491616405 {
1491716406 keyPressed(0, modifiers);
1491816407 }
14919
- clickStart(x, y, modifiers);
16408
+ // clickStart(x, y, modifiers);
1492016409 return true;
1492116410 }
1492216411
....@@ -15034,7 +16523,7 @@
1503416523 {
1503516524 keyReleased(0, 0);
1503616525 }
15037
- drag(x, y, modifiers);
16526
+ drag(x, y, 0, modifiers);
1503816527 return true;
1503916528 }
1504016529
....@@ -15166,7 +16655,7 @@
1516616655 Object3D object;
1516716656 static Object3D trackedobject;
1516816657 Camera renderCamera; // Light or Eye (or Occlusion)
15169
- /*static*/ Camera manipCamera; // Light or Eye
16658
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1517016659 /*static*/ Camera eyeCamera;
1517116660 /*static*/ Camera lightCamera;
1517216661 int cameracount;
....@@ -15230,6 +16719,8 @@
1523016719 private /*static*/ boolean firstime;
1523116720 private /*static*/ cVector newView = new cVector();
1523216721 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16722
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16723
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1523316724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1523416725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1523516726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15242,29 +16733,67 @@
1524216733 {
1524316734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1524416735
16736
+ int usedsuf = 0;
16737
+
1524516738 for (int i = 0; i < suffixes.length; i++)
1524616739 {
15247
- String resourceName = basename + suffixes[i] + "." + suffix;
15248
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15249
- mipmapped,
15250
- FileUtil.getFileSuffix(resourceName));
15251
- if (data == null)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1525216745 {
15253
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1525416750 }
16751
+
16752
+ String resourceName = basename + suffixe[i] + "." + suffix;
16753
+ TextureData data;
16754
+
16755
+ try
16756
+ {
16757
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16758
+ mipmapped,
16759
+ FileUtil.getFileSuffix(resourceName));
16760
+ }
16761
+ catch (Exception e)
16762
+ {
16763
+ try
16764
+ {
16765
+ resourceName = basename + fallback[i] + "." + suffix;
16766
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16767
+ mipmapped,
16768
+ FileUtil.getFileSuffix(resourceName));
16769
+ }
16770
+ catch (Exception e2)
16771
+ {
16772
+ resourceName = basename + fallfallback[i] + "." + suffix;
16773
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16774
+ mipmapped,
16775
+ FileUtil.getFileSuffix(resourceName));
16776
+ }
16777
+ }
16778
+
1525516779 //System.out.println("Target = " + targets[i]);
1525616780 cubemap.updateImage(data, targets[i]);
1525716781 }
1525816782
1525916783 return cubemap;
1526016784 }
16785
+
1526116786 int bigsphere = -1;
1526216787
1526316788 float BGcolor = 0.5f;
1526416789
15265
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1526616793 {
15267
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1526816797 {
1526916798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1527016799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15279,7 +16808,17 @@
1527916808 // Compensates for ExaminerViewer's modification of modelview matrix
1528016809 gl.glMatrixMode(GL.GL_MODELVIEW);
1528116810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1528216812
16813
+// colorV[0] = 2;
16814
+// colorV[1] = 2;
16815
+// colorV[2] = 2;
16816
+// colorV[3] = 1;
16817
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16818
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16819
+//
16820
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16821
+
1528316822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1528416823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1528516824
....@@ -15311,6 +16850,7 @@
1531116850 {
1531216851 gl.glScalef(1.0f, -1.0f, 1.0f);
1531316852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1531416854 gl.glMultMatrixd(viewrot_1, 0);
1531516855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1531616856 //viewer.updateInverseRotation(gl);
....@@ -15351,7 +16891,8 @@
1535116891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1535216892
1535316893 cubemap.disable();
15354
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1535516896 if (CULLFACE)
1535616897 {
1535716898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -15407,7 +16948,7 @@
1540716948 gl.glScalef(1.0f, -1.0f, 1.0f);
1540816949 }
1540916950
15410
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1541116952
1541216953 float step = 2; // 0.1666f; //0.25f;
1541316954 float stepv = 2; // step * 1652 / 998;
....@@ -15451,16 +16992,16 @@
1545116992 cStatic.objectstack[materialdepth++] = checker;
1545216993 //System.out.println("material " + material);
1545316994 //Applet3D.tracein(this, selected);
15454
- vector2buffer = checker.projectedVertices;
16995
+ //vector2buffer = checker.projectedVertices;
1545516996
1545616997 //checker.GetMaterial().Draw(this, false); // true);
15457
- DrawMaterial(checker.GetMaterial(), false); // true);
16998
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1545816999
1545917000 materialdepth -= 1;
1546017001 if (materialdepth > 0)
1546117002 {
15462
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15463
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
17003
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17004
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1546417005 }
1546517006 //checker.GetMaterial().opacity = 1f;
1546617007 ////checker.GetMaterial().ambient = 1f;
....@@ -15546,6 +17087,14 @@
1554617087 }
1554717088 }
1554817089
17090
+ private Object3D GetFolder()
17091
+ {
17092
+ Object3D folder = object.GetWindow().copy;
17093
+ if (object.GetWindow().copy.selection.Size() > 0)
17094
+ folder = object.GetWindow().copy.selection.elementAt(0);
17095
+ return folder;
17096
+ }
17097
+
1554917098 class SelectBuffer implements GLEventListener
1555017099 {
1555117100
....@@ -15561,7 +17110,7 @@
1556117110 //new Exception().printStackTrace();
1556217111 System.out.println("select buffer init");
1556317112 // Use debug pipeline
15564
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1556517114
1556617115 GL gl = drawable.getGL();
1556717116
....@@ -15604,6 +17153,7 @@
1560417153 {
1560517154 if (!selection)
1560617155 {
17156
+ new Exception().printStackTrace();
1560717157 System.exit(0);
1560817158 return;
1560917159 }
....@@ -15624,6 +17174,17 @@
1562417174
1562517175 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1562617176
17177
+ if (PAINTMODE)
17178
+ {
17179
+ if (object.GetWindow().copy.selection.Size() > 0)
17180
+ {
17181
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17182
+
17183
+ // Make what you paint not selectable.
17184
+ paintobj.ResetSelectable();
17185
+ }
17186
+ }
17187
+
1562717188 //int tmp = selection_view;
1562817189 //selection_view = -1;
1562917190 int temp = DrawMode();
....@@ -15635,6 +17196,17 @@
1563517196 // temp = DEFAULT; // patch for selection debug
1563617197 Globals.drawMode = temp; // WARNING
1563717198
17199
+ if (PAINTMODE)
17200
+ {
17201
+ if (object.GetWindow().copy.selection.Size() > 0)
17202
+ {
17203
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17204
+
17205
+ // Revert.
17206
+ paintobj.RestoreSelectable();
17207
+ }
17208
+ }
17209
+
1563817210 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1563917211
1564017212 // trying different ways of getting the depth info over
....@@ -15682,6 +17254,8 @@
1568217254 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1568317255 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1568417256 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17257
+
17258
+ CreateSelectedPoint();
1568517259
1568617260 // Will fit the mesh !!!
1568717261 selectedpoint.toParent[0][0] = 0.0001;
....@@ -15731,34 +17305,36 @@
1573117305 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]));
1573217306 }
1573317307
15734
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17308
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1573517309 }
1573617310 }
1573717311
1573817312 if (!movingcamera && !PAINTMODE)
15739
- object.editWindow.ScreenFitPoint(); // fev 2014
17313
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1574017314
15741
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17315
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1574217316 {
15743
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17317
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1574417318
15745
- Object3D group = new Object3D("inst" + paintcount++);
17319
+ if (object.GetWindow().copy.selection.Size() > 0)
17320
+ {
17321
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1574617322
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();
17323
+ Object3D inst = new Object3D("inst" + paintcount++);
17324
+
17325
+ inst.CreateMaterial(); // use a void leaf to select instances
17326
+
17327
+ inst.add(paintobj); // link
17328
+
17329
+ object.GetWindow().SnapObject(inst);
17330
+
17331
+ Object3D folder = paintFolder; // GetFolder();
17332
+
17333
+ folder.add(inst);
17334
+
17335
+ object.GetWindow().ResetModel();
17336
+ object.GetWindow().refreshContents();
17337
+ }
1576217338 }
1576317339 else
1576417340 paintcount = 0;
....@@ -15797,6 +17373,11 @@
1579717373 //System.out.println("objects[color] = " + objects[color]);
1579817374 //objects[color].Select();
1579917375 indexcount = 0;
17376
+ ObjEditor window = object.GetWindow();
17377
+ if (window != null && deselect)
17378
+ {
17379
+ window.Select(null, deselect, true);
17380
+ }
1580017381 object.Select(color, deselect);
1580117382 }
1580217383
....@@ -15847,6 +17428,7 @@
1584717428
1584817429 public void init(GLAutoDrawable drawable)
1584917430 {
17431
+ if (Globals.DEBUG)
1585017432 System.out.println("shadow buffer init");
1585117433
1585217434 GL gl = drawable.getGL();
....@@ -15896,7 +17478,7 @@
1589617478 gl.glDisable(gl.GL_CULL_FACE);
1589717479 }
1589817480
15899
- if (!RENDERSHADOW)
17481
+ if (!Globals.RENDERSHADOW)
1590017482 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1590117483
1590217484 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -15906,7 +17488,7 @@
1590617488 //gl.glColorMask(false, false, false, false);
1590717489
1590817490 //render_scene_from_light_view(gl, drawable, 0, 0);
15909
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17491
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1591017492 {
1591117493 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1591217494
....@@ -15966,7 +17548,6 @@
1596617548
1596717549 class AntialiasBuffer implements GLEventListener
1596817550 {
15969
-
1597017551 CameraPane parent = null;
1597117552
1597217553 AntialiasBuffer(CameraPane p)
....@@ -16076,10 +17657,14 @@
1607617657 gl.glFlush();
1607717658
1607817659 /**/
16079
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17660
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1608017661
16081
- float[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1608217663
17664
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17665
+
17666
+ int[] pixels = selectsizebuffer.array();
17667
+
1608317668 double r = 0, g = 0, b = 0;
1608417669
1608517670 double count = 0;
....@@ -16090,7 +17675,7 @@
1609017675
1609117676 double FACTOR = 1;
1609217677
16093
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1609417679 {
1609517680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1609617681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -16173,7 +17758,7 @@
1617317758
1617417759 double scale = ray.z; // 1; // cos
1617517760
16176
- float depth = pixels[newindex];
17761
+ float depth = depths[newindex];
1617717762
1617817763 /*
1617917764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16323,23 +17908,15 @@
1632317908 int AAbuffersize = 0;
1632417909
1632517910 //double[] selectedpoint = new double[3];
16326
- static Superellipsoid selectedpoint = new Superellipsoid();
17911
+ static Superellipsoid selectedpoint;
1632717912 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();
17913
+ static Sphere debugpointG;
17914
+ static Sphere debugpointP;
17915
+ static Sphere debugpointC;
17916
+ static Sphere debugpointR;
1633217917
1633317918 static Sphere debugpoints[] = new Sphere[8];
1633417919
16335
- static
16336
- {
16337
- for (int i=0; i<8; i++)
16338
- {
16339
- debugpoints[i] = new Sphere();
16340
- }
16341
- }
16342
-
1634317920 static void InitPoints(float radius)
1634417921 {
1634517922 for (int i=0; i<8; i++)
....@@ -16359,7 +17936,7 @@
1635917936 }
1636017937 }
1636117938
16362
- static void DrawPoints(CameraPane cpane)
17939
+ static void DrawPoints(iCameraPane cpane)
1636317940 {
1636417941 for (int i=0; i<8; i++) // first and last are red
1636517942 {
....@@ -16378,11 +17955,14 @@
1637817955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1637917956 static IntBuffer bigAAbuffer;
1638017957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
16381
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1638217959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1638317960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1638417961 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
16385
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17962
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17963
+
17964
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17965
+
1638617966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1638717967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1638817968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -16391,10 +17971,11 @@
1639117971 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1639217972 // Depth buffer format
1639317973 //private int depth_format;
16394
- static public void NextIndex(Object3D o, GL gl)
17974
+
17975
+ public void NextIndex()
1639517976 {
1639617977 indexcount+=16;
16397
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17978
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1639817979 //objects[indexcount] = o;
1639917980 //System.out.println("indexcount = " + indexcount);
1640017981 }