Normand Briere
2019-07-24 ebd16116fc612bf14e2469ba27dd7ee54918eabb
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -92,6 +126,8 @@
92126
93127 static int tickcount = 0; // slow pose issue
94128
129
+static boolean BUTTONLESSWHEEL = false;
130
+static boolean ZOOMBOXMODE = false;
95131 static boolean BOXMODE = false;
96132 static boolean IMAGEFLIP = false;
97133 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +142,7 @@
106142 static boolean OEIL = true;
107143 static boolean OEILONCE = false; // do oeilon then oeiloff
108144 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
145
+static boolean SWITCH = true; // false;
110146 static boolean HANDLES = false; // selection doesn't work!!
111147 static boolean PAINTMODE = false;
112148
....@@ -149,12 +185,13 @@
149185 defaultcaps.setAccumBlueBits(16);
150186 defaultcaps.setAccumAlphaBits(16);
151187 }
152
- static CameraPane theRenderer;
153
-
188
+
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
190
+
154191 void SetAsGLRenderer(boolean b)
155192 {
156193 isRenderer = b;
157
- theRenderer = this;
194
+ Globals.theRenderer = this;
158195 }
159196
160197 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -191,6 +228,45 @@
191228 }
192229
193230 /// INTERFACE
231
+
232
+ public javax.media.opengl.GL GetGL0()
233
+ {
234
+ return null;
235
+ }
236
+
237
+ public int GenList()
238
+ {
239
+ javax.media.opengl.GL gl = GetGL();
240
+ return gl.glGenLists(1);
241
+ }
242
+
243
+ public void NewList(int id)
244
+ {
245
+ javax.media.opengl.GL gl = GetGL();
246
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
247
+ }
248
+
249
+ public void CallList(int id)
250
+ {
251
+ javax.media.opengl.GL gl = GetGL();
252
+ gl.glCallList(id);
253
+ }
254
+
255
+ public void EndList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ gl.glEndList();
259
+ }
260
+
261
+ public boolean IsBoxMode()
262
+ {
263
+ return BOXMODE;
264
+ }
265
+
266
+ public boolean IsZoomBoxMode()
267
+ {
268
+ return ZOOMBOXMODE;
269
+ }
194270
195271 public void ClearDepth()
196272 {
....@@ -231,9 +307,14 @@
231307 return this.ambientOcclusion;
232308 }
233309
310
+ public boolean IsDebugSelection()
311
+ {
312
+ return DEBUG_SELECTION;
313
+ }
314
+
234315 public boolean IsFrozen()
235316 {
236
- boolean selectmode = this.DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
317
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
237318
238319 return !selectmode && cameracount == 0; // != 0;
239320 }
....@@ -254,9 +335,19 @@
254335 return lightCamera;
255336 }
256337
338
+ public Camera ManipCamera()
339
+ {
340
+ return manipCamera;
341
+ }
342
+
257343 public Camera RenderCamera()
258344 {
259345 return renderCamera;
346
+ }
347
+
348
+ public Camera[] Cameras()
349
+ {
350
+ return cameras;
260351 }
261352
262353 public void PushMaterial(Object3D obj, boolean selected)
....@@ -272,7 +363,7 @@
272363 cStatic.objectstack[materialdepth++] = obj;
273364 //System.out.println("material " + material);
274365 //Applet3D.tracein(this, selected);
275
- display.vector2buffer = obj.projectedVertices;
366
+ //display.vector2buffer = obj.projectedVertices;
276367 if (obj instanceof Camera)
277368 {
278369 display.options1[0] = material.shift;
....@@ -281,14 +372,28 @@
281372 display.options1[2] = material.shadowbias;
282373 display.options1[3] = material.aniso;
283374 display.options1[4] = material.anisoV;
375
+// System.out.println("display.options1[0] " + display.options1[0]);
376
+// System.out.println("display.options1[1] " + display.options1[1]);
377
+// System.out.println("display.options1[2] " + display.options1[2]);
378
+// System.out.println("display.options1[3] " + display.options1[3]);
379
+// System.out.println("display.options1[4] " + display.options1[4]);
284380 display.options2[0] = material.opacity;
285381 display.options2[1] = material.diffuse;
286382 display.options2[2] = material.factor;
383
+// System.out.println("display.options2[0] " + display.options2[0]);
384
+// System.out.println("display.options2[1] " + display.options2[1]);
385
+// System.out.println("display.options2[2] " + display.options2[2]);
287386
288387 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
388
+// System.out.println("display.options3[0] " + display.options3[0]);
389
+// System.out.println("display.options3[1] " + display.options3[1]);
390
+// System.out.println("display.options3[2] " + display.options3[2]);
289391 display.options4[0] = material.cameralight/0.2f;
290392 display.options4[1] = material.subsurface;
291393 display.options4[2] = material.sheen;
394
+// System.out.println("display.options4[0] " + display.options4[0]);
395
+// System.out.println("display.options4[1] " + display.options4[1]);
396
+// System.out.println("display.options4[2] " + display.options4[2]);
292397
293398 // if (display.CURRENTANTIALIAS > 0)
294399 // display.options3[3] /= 4;
....@@ -304,7 +409,7 @@
304409 /**/
305410 } else
306411 {
307
- DrawMaterial(material, selected);
412
+ DrawMaterial(material, selected, obj.projectedVertices);
308413 }
309414 } else
310415 {
....@@ -328,8 +433,8 @@
328433 cStatic.objectstack[materialdepth++] = obj;
329434 //System.out.println("material " + material);
330435 //Applet3D.tracein("selected ", selected);
331
- display.vector2buffer = obj.projectedVertices;
332
- display.DrawMaterial(material, selected);
436
+ //display.vector2buffer = obj.projectedVertices;
437
+ display.DrawMaterial(material, selected, obj.projectedVertices);
333438 }
334439 }
335440
....@@ -346,8 +451,8 @@
346451 materialdepth -= 1;
347452 if (materialdepth > 0)
348453 {
349
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
350
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
454
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
455
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
351456 }
352457 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
353458 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -367,8 +472,8 @@
367472 materialdepth -= 1;
368473 if (materialdepth > 0)
369474 {
370
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
371
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
475
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
476
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
372477 }
373478 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
374479 //else
....@@ -403,16 +508,18 @@
403508
404509 javax.media.opengl.GL gl = display.GetGL();
405510
406
- boolean selectmode = display.DrawMode() == display.SELECTION || CameraPane.DEBUG_SELECTION;
511
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
407512
408513 //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
409514 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
410515 {
411516 //gl.glBegin(gl.GL_TRIANGLES);
412
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
517
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
518
+ // TEST LIVE NORMALS && !obj.dontselect
519
+ ;
413520 if (!hasnorm)
414521 {
415
- // System.out.println("FUCK!!");
522
+ // System.out.println("Mesh normal");
416523 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
417524 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
418525 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -566,7 +673,816 @@
566673 }
567674 }
568675
676
+ /**
677
+ * <code>draw</code> renders a <code>TriMesh</code> object including
678
+ * it's normals, colors, textures and vertices.
679
+ *
680
+ * @see Renderer#draw(TriMesh)
681
+ * @param tris
682
+ * the mesh to render.
683
+ */
684
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
685
+ {
686
+ CameraPane display = this;
687
+
688
+ float r = display.modelParams0[0];
689
+ float g = display.modelParams0[1];
690
+ float b = display.modelParams0[2];
691
+ float opacity = display.modelParams5[1];
692
+
693
+ //final GL gl = GLU.getCurrentGL();
694
+ GL gl = display.GetGL(); // getGL();
695
+
696
+ FloatBuffer vertBuf = geo.vertBuf;
697
+
698
+ int v = vertBuf.capacity();
699
+
700
+ int count = 0;
701
+
702
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
703
+ gl.glEnable(gl.GL_CULL_FACE);
704
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
705
+ for (int i=0; i<v/3; i++)
706
+ {
707
+ int index3 = i*3;
708
+
709
+ if (geo.sizeBuf.get(index3+1) == 0)
710
+ continue;
711
+
712
+ count++;
713
+
714
+ int index4 = i*4;
715
+
716
+ float tx = vertBuf.get(index3);
717
+ float ty = vertBuf.get(index3+1);
718
+ float tz = vertBuf.get(index3+2);
719
+
720
+ // if (tx == 0 && ty == 0 && tz == 0)
721
+ // continue;
722
+
723
+ gl.glMatrixMode(gl.GL_TEXTURE);
724
+ gl.glPushMatrix();
725
+
726
+ float[] texmat = geo.texmat;
727
+ texmat[12] = texmat[13] = texmat[14] = i;
728
+
729
+ gl.glMultMatrixf(texmat, 0);
730
+
731
+ gl.glMatrixMode(gl.GL_MODELVIEW);
732
+ gl.glPushMatrix();
733
+
734
+ gl.glTranslatef(tx,ty,tz);
735
+
736
+ if (rotate)
737
+ gl.glRotatef(i, 0, 1, 0);
738
+
739
+ float size = geo.sizeBuf.get(index3) / 100;
740
+ gl.glScalef(size,size,size);
741
+
742
+ float cr = geo.colorBuf.get(index4);
743
+ float cg = geo.colorBuf.get(index4+1);
744
+ float cb = geo.colorBuf.get(index4+2);
745
+ float ca = geo.colorBuf.get(index4+3);
746
+
747
+ display.modelParams0[0] = r * cr;
748
+ display.modelParams0[1] = g * cg;
749
+ display.modelParams0[2] = b * cb;
750
+
751
+ display.modelParams5[1] = opacity * ca;
752
+
753
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
754
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
755
+
756
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
757
+ RandomNode.globalseed2 = RandomNode.globalseed;
758
+
759
+// gl.glColor4f(cr,cg,cb,ca);
760
+ // gl.glScalef(1024/16,1024/16,1024/16);
761
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
762
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
763
+ //gl.glTranslatef(-tx,-ty,-tz);
764
+ gl.glPopMatrix();
765
+
766
+ gl.glMatrixMode(gl.GL_TEXTURE);
767
+ gl.glPopMatrix();
768
+ }
769
+ // gl.glScalef(1024,1024,1024);
770
+ if (!cf)
771
+ gl.glDisable(gl.GL_CULL_FACE);
772
+
773
+ display.modelParams0[0] = r;
774
+ display.modelParams0[1] = g;
775
+ display.modelParams0[2] = b;
776
+
777
+ display.modelParams5[1] = opacity;
778
+
779
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
780
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
781
+
782
+ gl.glMatrixMode(gl.GL_MODELVIEW);
783
+
784
+// System.err.println("total = " + v/3 + "; displayed = " + count);
785
+ if (true)
786
+ return;
787
+
788
+//// if (!tris.predraw(this))
789
+//// {
790
+//// return;
791
+//// }
792
+//// if (Debug.stats)
793
+//// {
794
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
795
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
796
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
797
+//// }
798
+////
799
+//// if (tris.getDisplayListID() != -1)
800
+//// {
801
+//// renderDisplayList(tris);
802
+//// return;
803
+//// }
804
+////
805
+//// if (!generatingDisplayList)
806
+//// {
807
+//// applyStates(tris.states, tris);
808
+//// }
809
+//// if (Debug.stats)
810
+//// {
811
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
812
+//// }
813
+//// boolean transformed = doTransforms(tris);
814
+//
815
+// int glMode = GL.GL_TRIANGLES;
816
+// switch (getMode())
817
+// {
818
+// case Triangles:
819
+// glMode = GL.GL_TRIANGLES;
820
+// break;
821
+// case Strip:
822
+// glMode = GL.GL_TRIANGLE_STRIP;
823
+// break;
824
+// case Fan:
825
+// glMode = GL.GL_TRIANGLE_FAN;
826
+// break;
827
+// }
828
+//
829
+// if (!predrawGeometry(gl))
830
+// {
831
+// // make sure only the necessary indices are sent through on old
832
+// // cards.
833
+// IntBuffer indices = this.getIndexBuffer();
834
+// if (indices == null)
835
+// {
836
+// logger.severe("missing indices on geometry object: " + this.toString());
837
+// } else
838
+// {
839
+// indices.rewind();
840
+// indices.limit(this.getMaxIndex());
841
+//
842
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
843
+//
844
+// indices.clear();
845
+// }
846
+// } else
847
+// {
848
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
849
+// GL.GL_UNSIGNED_INT, 0);
850
+// }
851
+//
852
+//// postdrawGeometry(tris);
853
+//// if (transformed)
854
+//// {
855
+//// undoTransforms(tris);
856
+//// }
857
+////
858
+//// if (Debug.stats)
859
+//// {
860
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
861
+//// }
862
+//// tris.postdraw(this);
863
+ }
864
+
865
+ static Camera localcamera = new Camera();
866
+ static cVector from = new cVector();
867
+ static cVector to = new cVector();
868
+
869
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
870
+ {
871
+ CameraPane cp = this;
872
+
873
+ Camera keep = cp.RenderCamera();
874
+ cp.renderCamera = localcamera;
875
+
876
+ if (br.trimmed)
877
+ {
878
+ float[] colors = new float[br.positions.length / 3];
879
+
880
+ int i3 = 0;
881
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
882
+ {
883
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
884
+ continue;
885
+
886
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
887
+ to.set(br.positions[i3] + br.normals[i3],
888
+ br.positions[i3 + 1] + br.normals[i3 + 1],
889
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
890
+ LA.xformPos(from, transform, from);
891
+ LA.xformPos(to, transform, to); // RIGID ONLY
892
+ localcamera.setAim(from, to);
893
+
894
+ CameraPane.occlusionbuffer.display();
895
+
896
+ if (CameraPane.DEBUG_OCCLUSION)
897
+ cp.display(); // debug
898
+
899
+ colors[i] = cp.vertexOcclusion.r;
900
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
901
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
902
+
903
+ if ((i % 100) == 0 && i != 0)
904
+ {
905
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
906
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
907
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
908
+ }
909
+ }
910
+
911
+ br.colors = colors;
912
+ }
913
+ else
914
+ {
915
+ for (int i = 0; i < br.VertexCount(); i++)
916
+ {
917
+ Vertex v = br.GetVertex(i);
918
+
919
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
920
+ continue;
921
+
922
+ from.set(v.x, v.y, v.z);
923
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
924
+ LA.xformPos(from, transform, from);
925
+ LA.xformPos(to, transform, to); // RIGID ONLY
926
+ localcamera.setAim(from, to);
927
+
928
+ CameraPane.occlusionbuffer.display();
929
+
930
+ if (CameraPane.DEBUG_OCCLUSION)
931
+ cp.display(); // debug
932
+
933
+ v.AO = cp.vertexOcclusion.r;
934
+
935
+ if ((i % 100) == 0 && i != 0)
936
+ {
937
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
938
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
939
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
940
+ }
941
+ }
942
+ }
943
+
944
+ //System.out.println("done.");
945
+
946
+ cp.renderCamera = keep;
947
+ }
948
+
949
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
950
+ {
951
+ CameraPane display = this;
952
+ pointFlow.CreateHT();
953
+
954
+ float r = display.modelParams0[0];
955
+ float g = display.modelParams0[1];
956
+ float b = display.modelParams0[2];
957
+ float opacity = display.modelParams5[1];
958
+
959
+ //final GL gl = GLU.getCurrentGL();
960
+ GL gl = display.GetGL(); // getGL();
961
+
962
+ int s = pointFlow.points.size();
963
+
964
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
965
+ gl.glEnable(gl.GL_CULL_FACE);
966
+
967
+ for (int i=s; --i>=0;)
968
+ //for (int i=0; i<s; i++)
969
+ {
970
+ cVector v = pointFlow.points.get(i);
971
+
972
+ double mindist = Double.MAX_VALUE;
973
+
974
+ double size = pointFlow.minimumSize;
975
+
976
+ double distancenext = 0;
977
+
978
+ if (i > 0)
979
+ {
980
+ cVector w = pointFlow.points.get(i-1);
981
+
982
+ double dist = w.distance(v);
983
+
984
+ distancenext = dist;
985
+
986
+ if (mindist > dist)
987
+ {
988
+ mindist = dist;
989
+ size = mindist*pointFlow.resizefactor;
990
+ }
991
+ }
992
+
993
+ if (i < s-1)
994
+ {
995
+ cVector w = pointFlow.points.get(i+1);
996
+
997
+ double dist = w.distance(v);
998
+
999
+ if (mindist > dist)
1000
+ {
1001
+ mindist = dist;
1002
+ size = mindist*pointFlow.resizefactor;
1003
+ }
1004
+ }
1005
+
1006
+ if (size < pointFlow.minimumSize)
1007
+ size = pointFlow.minimumSize;
1008
+ if (size > pointFlow.maximumSize)
1009
+ size = pointFlow.maximumSize;
1010
+
1011
+ double tx = v.x;
1012
+ double ty = v.y;
1013
+ double tz = v.z;
1014
+
1015
+ // if (tx == 0 && ty == 0 && tz == 0)
1016
+ // continue;
1017
+
1018
+ gl.glMatrixMode(gl.GL_TEXTURE);
1019
+ gl.glPushMatrix();
1020
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1021
+
1022
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1023
+
1024
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1025
+ gl.glPushMatrix();
1026
+
1027
+ gl.glTranslated(tx,ty,tz);
1028
+
1029
+ gl.glScaled(size,size,size);
1030
+
1031
+// float cr = colorBuf.get(index4);
1032
+// float cg = colorBuf.get(index4+1);
1033
+// float cb = colorBuf.get(index4+2);
1034
+// float ca = colorBuf.get(index4+3);
1035
+//
1036
+// display.modelParams0[0] = r * cr;
1037
+// display.modelParams0[1] = g * cg;
1038
+// display.modelParams0[2] = b * cb;
1039
+//
1040
+// display.modelParams5[1] = opacity * ca;
1041
+//
1042
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1043
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1044
+//
1045
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1046
+// RandomNode.globalseed2 = RandomNode.globalseed;
1047
+//
1048
+//// gl.glColor4f(cr,cg,cb,ca);
1049
+// // gl.glScalef(1024/16,1024/16,1024/16);
1050
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1051
+
1052
+ gl.glPopMatrix();
1053
+
1054
+ double step = size/4; //
1055
+
1056
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1057
+ continue;
1058
+
1059
+ int nbsteps = (int)(distancenext/step);
1060
+
1061
+ step = distancenext/nbsteps;
1062
+
1063
+ cVector next = pointFlow.points.get(i-1);
1064
+
1065
+ tmp.set(next);
1066
+ tmp.sub(v);
1067
+ tmp.normalize();
1068
+ tmp.mul(step);
1069
+
1070
+ // calculate next size
1071
+ mindist = Double.MAX_VALUE;
1072
+
1073
+ double nextsize = pointFlow.minimumSize;
1074
+
1075
+ if (i > 1)
1076
+ {
1077
+ cVector w = pointFlow.points.get(i-2);
1078
+
1079
+ double dist = w.distance(next);
1080
+
1081
+ if (mindist > dist)
1082
+ {
1083
+ mindist = dist;
1084
+ nextsize = mindist*pointFlow.resizefactor;
1085
+ }
1086
+ }
1087
+
1088
+ double dist = v.distance(next);
1089
+
1090
+ if (mindist > dist)
1091
+ {
1092
+ mindist = dist;
1093
+ nextsize = mindist*pointFlow.resizefactor;
1094
+ }
1095
+
1096
+ if (nextsize < pointFlow.minimumSize)
1097
+ nextsize = pointFlow.minimumSize;
1098
+ if (nextsize > pointFlow.maximumSize)
1099
+ nextsize = pointFlow.maximumSize;
1100
+ //
1101
+
1102
+ double count = 0;
1103
+
1104
+ while (distancenext > 0.000000001) // step
1105
+ {
1106
+ gl.glPushMatrix();
1107
+
1108
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1109
+
1110
+ double K = count/nbsteps;
1111
+
1112
+ double intersize = K*nextsize + (1-K)*size;
1113
+
1114
+ gl.glScaled(intersize,intersize,intersize);
1115
+
1116
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1117
+
1118
+ count++;
1119
+
1120
+ distancenext -= step;
1121
+
1122
+ gl.glPopMatrix();
1123
+ }
1124
+
1125
+ if (count != nbsteps)
1126
+ assert(count == nbsteps);
1127
+
1128
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1129
+ //gl.glTranslatef(-tx,-ty,-tz);
1130
+
1131
+ gl.glMatrixMode(gl.GL_TEXTURE);
1132
+ gl.glPopMatrix();
1133
+ }
1134
+
1135
+ if (!cf)
1136
+ gl.glDisable(gl.GL_CULL_FACE);
1137
+
1138
+// display.modelParams0[0] = r;
1139
+// display.modelParams0[1] = g;
1140
+// display.modelParams0[2] = b;
1141
+//
1142
+// display.modelParams5[1] = opacity;
1143
+//
1144
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1145
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1146
+
1147
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1148
+ }
1149
+
1150
+ public void DrawBox(cVector min, cVector max)
1151
+ {
1152
+ javax.media.opengl.GL gl = GetGL();
1153
+ gl.glBegin(gl.GL_LINES);
1154
+
1155
+ gl.glVertex3d(min.x, min.y, min.z);
1156
+ gl.glVertex3d(min.x, min.y, max.z);
1157
+ gl.glVertex3d(min.x, min.y, min.z);
1158
+ gl.glVertex3d(min.x, max.y, min.z);
1159
+ gl.glVertex3d(min.x, min.y, min.z);
1160
+ gl.glVertex3d(max.x, min.y, min.z);
1161
+
1162
+ gl.glVertex3d(max.x, max.y, max.z);
1163
+ gl.glVertex3d(min.x, max.y, max.z);
1164
+ gl.glVertex3d(max.x, max.y, max.z);
1165
+ gl.glVertex3d(max.x, min.y, max.z);
1166
+ gl.glVertex3d(max.x, max.y, max.z);
1167
+ gl.glVertex3d(max.x, max.y, min.z);
1168
+
1169
+ gl.glEnd();
1170
+ }
1171
+
1172
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1173
+ {
1174
+ int[] strips = bRep.getRawIndices();
1175
+
1176
+ javax.media.opengl.GL gl = GetGL();
1177
+
1178
+ // TRIANGLE STRIP ARRAY
1179
+ if (bRep.trimmed)
1180
+ {
1181
+ float[] v = bRep.getRawVertices();
1182
+ float[] n = bRep.getRawNormals();
1183
+ float[] c = bRep.getRawColors();
1184
+ float[] uv = bRep.getRawUVMap();
1185
+
1186
+ int count2 = 0;
1187
+ int count3 = 0;
1188
+
1189
+ if (n.length > 0)
1190
+ {
1191
+ for (int i = 0; i < strips.length; i++)
1192
+ {
1193
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1194
+
1195
+ /*
1196
+ boolean locked = false;
1197
+ float eps = 0.1f;
1198
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1199
+
1200
+ int dot = 0;
1201
+
1202
+ if ((dot&1) == 0)
1203
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1204
+
1205
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1206
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1207
+ else
1208
+ {
1209
+ locked = true;
1210
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1211
+ }
1212
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1213
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1214
+ if (hasnorm)
1215
+ {
1216
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1217
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1218
+ }
1219
+
1220
+ if ((dot&4) == 0)
1221
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1222
+
1223
+ if (wrap || !locked && (dot&8) != 0)
1224
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1225
+ else
1226
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1227
+
1228
+ f.dot = dot;
1229
+ */
1230
+
1231
+ if (!selectmode)
1232
+ {
1233
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1234
+ {
1235
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1236
+ } else
1237
+ {
1238
+ gl.glNormal3f(0, 0, 1);
1239
+ }
1240
+
1241
+ if (c != null)
1242
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1243
+ {
1244
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1245
+ }
1246
+ }
1247
+
1248
+ if (flipV)
1249
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1250
+ else
1251
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1252
+
1253
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1254
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1255
+
1256
+ count2 += 2;
1257
+ count3 += 3;
1258
+ if (!selectmode)
1259
+ {
1260
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1261
+ {
1262
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1263
+ } else
1264
+ {
1265
+ gl.glNormal3f(0, 0, 1);
1266
+ }
1267
+ if (c != null)
1268
+ {
1269
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1270
+ }
1271
+ }
1272
+
1273
+ if (flipV)
1274
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1275
+ else
1276
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1277
+
1278
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1279
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1280
+
1281
+ count2 += 2;
1282
+ count3 += 3;
1283
+ for (int j = 0; j < strips[i] - 2; j++)
1284
+ {
1285
+ //gl.glTexCoord2d(...);
1286
+ if (!selectmode)
1287
+ {
1288
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1289
+ {
1290
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1291
+ } else
1292
+ {
1293
+ gl.glNormal3f(0, 0, 1);
1294
+ }
1295
+ if (c != null)
1296
+ {
1297
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1298
+ }
1299
+ }
1300
+
1301
+ if (flipV)
1302
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1303
+ else
1304
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1305
+
1306
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1307
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1308
+
1309
+ count2 += 2;
1310
+ count3 += 3;
1311
+ }
1312
+
1313
+ gl.glEnd();
1314
+ }
1315
+ }
1316
+
1317
+ assert count3 == v.length;
1318
+ }
1319
+ else // !trimmed
1320
+ {
1321
+ int count = 0;
1322
+ for (int i = 0; i < strips.length; i++)
1323
+ {
1324
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1325
+
1326
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1327
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1328
+
1329
+ drawVertex(gl, p, flipV, selectmode);
1330
+ drawVertex(gl, q, flipV, selectmode);
1331
+
1332
+ for (int j = 0; j < strips[i] - 2; j++)
1333
+ {
1334
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1335
+
1336
+ // if (j%2 == 0)
1337
+ // drawFace(p, q, r, display, null);
1338
+ // else
1339
+ // drawFace(p, r, q, display, null);
1340
+
1341
+ // p = q;
1342
+ // q = r;
1343
+ drawVertex(gl, r, flipV, selectmode);
1344
+ }
1345
+
1346
+ gl.glEnd();
1347
+ }
1348
+ }
1349
+ }
1350
+
1351
+ static cSpring.Point3D temp = new cSpring.Point3D();
1352
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1353
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1354
+
1355
+ public void DrawDynamicMesh(cMesh mesh)
1356
+ {
1357
+ GL gl = GetGL(); // getGL();
1358
+
1359
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1360
+
1361
+ gl.glDisable(gl.GL_LIGHTING);
1362
+
1363
+ gl.glLineWidth(1);
1364
+ gl.glColor3f(1,1,1);
1365
+ gl.glBegin(gl.GL_LINES);
1366
+ double scale = 0;
1367
+ int count = 0;
1368
+ for (int s=0; s<Phys.allSprings.size(); s++)
1369
+ {
1370
+ cSpring.Spring spring = Phys.allSprings.get(s);
1371
+ if(s == 0)
1372
+ {
1373
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1374
+ }
1375
+ if (mesh.showsprings)
1376
+ {
1377
+ temp.set(spring.a.position);
1378
+ temp.add(spring.b.position);
1379
+ temp.mul(0.5);
1380
+ temp2.set(spring.a.position);
1381
+ temp2.sub(spring.b.position);
1382
+ temp2.mul(spring.restLength/2);
1383
+ temp.sub(temp2);
1384
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1385
+ temp.add(temp2);
1386
+ temp.add(temp2);
1387
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1388
+ }
1389
+
1390
+ if (spring.isHandle)
1391
+ continue;
1392
+
1393
+ //if (scale < spring.restLength)
1394
+ scale += spring.restLength;
1395
+ count++;
1396
+ }
1397
+ gl.glEnd();
1398
+
1399
+ if (count == 0)
1400
+ scale = 0.01;
1401
+ else
1402
+ scale /= count * 3;
1403
+
1404
+ //scale = 0.25;
1405
+
1406
+ if (mesh.ShowInfo())
1407
+ {
1408
+ gl.glLineWidth(4);
1409
+ for (int s=0; s<Phys.allNodes.size(); s++)
1410
+ {
1411
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1412
+ if (node.mass == 0)
1413
+ continue;
1414
+
1415
+ int i = node.springs==null?-1:node.springs.size();
1416
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1417
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1418
+ //temp.normalize();
1419
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1420
+ gl.glBegin(gl.GL_LINES);
1421
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1422
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1423
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1424
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1425
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1426
+ gl.glEnd();
1427
+ }
1428
+
1429
+ gl.glLineWidth(8);
1430
+ for (int s=0; s<Phys.allNodes.size(); s++)
1431
+ {
1432
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1433
+
1434
+ if (node.springs != null)
1435
+ {
1436
+ for (int i=0; i<node.springs.size(); i+=1)
1437
+ {
1438
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1439
+
1440
+ int c = i+1;
1441
+ // c = node.springs.get(i).nbcopies;
1442
+
1443
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1444
+ gl.glBegin(gl.GL_LINES);
1445
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1446
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1447
+ gl.glEnd();
1448
+ }
1449
+ }
1450
+ }
1451
+
1452
+ gl.glLineWidth(1);
1453
+ }
1454
+
1455
+ gl.glEnable(gl.GL_LIGHTING);
1456
+ }
1457
+
5691458 /// INTERFACE
1459
+
1460
+ public void StartTriangles()
1461
+ {
1462
+ javax.media.opengl.GL gl = GetGL();
1463
+ gl.glBegin(gl.GL_TRIANGLES);
1464
+ }
1465
+
1466
+ public void EndTriangles()
1467
+ {
1468
+ GetGL().glEnd();
1469
+ }
1470
+
1471
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1472
+ {
1473
+ if (!selectmode)
1474
+ {
1475
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1476
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1477
+
1478
+ if (flipV)
1479
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1480
+ else
1481
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1482
+ }
1483
+
1484
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1485
+ }
5701486
5711487 void SetColor(Object3D obj, Vertex p0)
5721488 {
....@@ -745,7 +1661,7 @@
7451661 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
7461662 }
7471663
748
- void DrawMaterial(cMaterial material, boolean selected)
1664
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
7491665 {
7501666 CameraPane display = this;
7511667 //new Exception().printStackTrace();
....@@ -761,18 +1677,18 @@
7611677 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
7621678 if (!material.multiply)
7631679 {
764
- display.color = color;
1680
+ display.color = material.color;
7651681 display.saturation = material.modulation;
7661682 }
7671683 else
7681684 {
769
- display.color *= color*2;
1685
+ display.color *= material.color*2;
7701686 display.saturation *= material.modulation*2;
7711687 }
7721688
7731689 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
7741690
775
- float[] colorV = GrafreeD.colorV;
1691
+ float[] colorV = Grafreed.colorV;
7761692
7771693 /**/
7781694 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -780,7 +1696,7 @@
7801696 colorV[0] = display.modelParams0[0] * material.diffuse;
7811697 colorV[1] = display.modelParams0[1] * material.diffuse;
7821698 colorV[2] = display.modelParams0[2] * material.diffuse;
783
- colorV[3] = material.opacity;
1699
+ colorV[3] = 1; // material.opacity;
7841700
7851701 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
7861702 //System.out.println("Opacity = " + opacity);
....@@ -888,9 +1804,9 @@
8881804 display.modelParams7[2] = 0;
8891805 display.modelParams7[3] = 0;
8901806
891
- display.modelParams6[0] = 100; // criss de bug de bump
1807
+ //display.modelParams6[0] = 100; // criss de bug de bump
8921808
893
- Object3D.cVector2[] extparams = display.vector2buffer;
1809
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
8941810 if (extparams != null && extparams.length > 0 && extparams[0] != null)
8951811 {
8961812 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1032,7 +1948,7 @@
10321948 void PushMatrix(double[][] matrix)
10331949 {
10341950 // GrafreeD.tracein(matrix);
1035
- PushMatrix(matrix,1);
1951
+ PushMatrix(matrix, 1);
10361952 }
10371953
10381954 void PushMatrix()
....@@ -1129,7 +2045,7 @@
11292045
11302046 static int camerachangeframe;
11312047
1132
- boolean SetCamera(Camera cam)
2048
+ public boolean SetCamera(Camera cam)
11332049 {
11342050 // may 2014 if (cam == cameras[0] || cam == cameras[1])
11352051 // return false;
....@@ -1186,7 +2102,7 @@
11862102 //System.err.println("Oeil on");
11872103 OEIL = true;
11882104 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1189
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2105
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11902106 //pingthread.StepToTarget(true);
11912107 }
11922108
....@@ -1257,33 +2173,6 @@
12572173 mainDL ^= true;
12582174 }
12592175
1260
- void ToggleTexture()
1261
- {
1262
- textureon ^= true;
1263
- }
1264
-
1265
- void ToggleLive()
1266
- {
1267
- Globals.setLIVE(Globals.isLIVE() ^ true);
1268
-
1269
- System.err.println("LIVE = " + Globals.isLIVE());
1270
-
1271
- if (!Globals.isLIVE()) // save sound
1272
- GrafreeD.savesound = true; // wav.save();
1273
- // else
1274
- repaint(); // start loop // may 2013
1275
- }
1276
-
1277
- void ToggleSupport()
1278
- {
1279
- SUPPORT ^= true;
1280
- }
1281
-
1282
- void ToggleAbort()
1283
- {
1284
- ABORTMODE ^= true;
1285
- }
1286
-
12872176 void ToggleFullScreen()
12882177 {
12892178 FULLSCREEN ^= true;
....@@ -1294,72 +2183,94 @@
12942183 Globals.CROWD ^= true;
12952184 }
12962185
1297
- void ToggleInertia()
1298
- {
1299
- INERTIA ^= true;
1300
- }
1301
-
13022186 void ToggleLocal()
13032187 {
13042188 LOCALTRANSFORM ^= true;
13052189 }
13062190
1307
- void ToggleFast()
2191
+ public void ToggleTexture()
2192
+ {
2193
+ textureon ^= true;
2194
+ }
2195
+
2196
+ public void ToggleLive()
2197
+ {
2198
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2199
+
2200
+ System.err.println("LIVE = " + Globals.isLIVE());
2201
+
2202
+ if (!Globals.isLIVE()) // save sound
2203
+ Grafreed.savesound = true; // wav.save();
2204
+ // else
2205
+ repaint(); // start loop // may 2013
2206
+ }
2207
+
2208
+ public void ToggleSupport()
2209
+ {
2210
+ SUPPORT ^= true;
2211
+ }
2212
+
2213
+ public void ToggleAbort()
2214
+ {
2215
+ ABORTMODE ^= true;
2216
+ }
2217
+
2218
+ public void ToggleInertia()
2219
+ {
2220
+ INERTIA ^= true;
2221
+ }
2222
+
2223
+ public void ToggleFast()
13082224 {
13092225 FAST ^= true;
13102226 }
13112227
1312
- void ToggleSlowPose()
2228
+ public void ToggleSlowPose()
13132229 {
13142230 SLOWPOSE ^= true;
13152231 }
13162232
1317
- void ToggleFootContact()
1318
- {
1319
- FOOTCONTACT ^= true;
1320
- }
1321
-
1322
- void ToggleBoxMode()
2233
+ public void ToggleBoxMode()
13232234 {
13242235 BOXMODE ^= true;
13252236 }
13262237
1327
- void ToggleSmoothFocus()
2238
+ public void ToggleZoomBoxMode()
2239
+ {
2240
+ ZOOMBOXMODE ^= true;
2241
+ }
2242
+
2243
+ public void ToggleSmoothFocus()
13282244 {
13292245 SMOOTHFOCUS ^= true;
13302246 }
13312247
1332
- void ToggleImageFlip()
2248
+ public void ToggleImageFlip()
13332249 {
13342250 IMAGEFLIP ^= true;
13352251 }
13362252
1337
- void ToggleSpeakerMocap()
2253
+ public void ToggleSpeakerMocap()
13382254 {
13392255 SPEAKERMOCAP ^= true;
13402256 }
13412257
1342
- void ToggleSpeakerCamera()
2258
+ public void ToggleSpeakerCamera()
13432259 {
13442260 SPEAKERCAMERA ^= true;
13452261 }
13462262
1347
- void ToggleSpeakerFocus()
2263
+ public void ToggleSpeakerFocus()
13482264 {
13492265 SPEAKERFOCUS ^= true;
13502266 }
13512267
1352
- void ToggleDebug()
1353
- {
1354
- DEBUG ^= true;
1355
- }
1356
-
1357
- void ToggleFrustum()
2268
+ public void ToggleFrustum()
13582269 {
13592270 FRUSTUM ^= true;
13602271 }
13612272
1362
- void ToggleTrack()
2273
+ public void ToggleTrack()
13632274 {
13642275 TRACK ^= true;
13652276 if (TRACK)
....@@ -1378,25 +2289,35 @@
13782289 repaint();
13792290 }
13802291
1381
- void ToggleTrackOnce()
2292
+ public void ToggleTrackOnce()
13822293 {
13832294 TRACKONCE ^= true;
13842295 }
13852296
1386
- void ToggleShadowTrack()
2297
+ public void ToggleShadowTrack()
13872298 {
13882299 SHADOWTRACK ^= true;
13892300 repaint();
13902301 }
13912302
1392
- void ToggleOeil()
2303
+ public void ToggleOeil()
13932304 {
13942305 OEIL ^= true;
13952306 }
13962307
1397
- void ToggleOeilOnce()
2308
+ public void ToggleOeilOnce()
13982309 {
13992310 OEILONCE ^= true;
2311
+ }
2312
+
2313
+ void ToggleFootContact()
2314
+ {
2315
+ FOOTCONTACT ^= true;
2316
+ }
2317
+
2318
+ void ToggleDebug()
2319
+ {
2320
+ Globals.DEBUG ^= true;
14002321 }
14012322
14022323 void ToggleLookAt()
....@@ -1404,9 +2325,9 @@
14042325 LOOKAT ^= true;
14052326 }
14062327
1407
- void ToggleRandom()
2328
+ void ToggleSwitch()
14082329 {
1409
- RANDOM ^= true;
2330
+ SWITCH ^= true;
14102331 }
14112332
14122333 void ToggleHandles()
....@@ -1414,10 +2335,17 @@
14142335 HANDLES ^= true;
14152336 }
14162337
2338
+ Object3D paintFolder;
2339
+
14172340 void TogglePaint()
14182341 {
14192342 PAINTMODE ^= true;
14202343 paintcount = 0;
2344
+
2345
+ if (PAINTMODE)
2346
+ {
2347
+ paintFolder = GetFolder();
2348
+ }
14212349 }
14222350
14232351 void SwapCamera(int a, int b)
....@@ -1513,7 +2441,22 @@
15132441 {
15142442 return currentGL;
15152443 }
1516
-
2444
+
2445
+ static private BufferedImage CreateBim(TextureData texturedata)
2446
+ {
2447
+ Grafreed.Assert(texturedata != null);
2448
+
2449
+ int width = texturedata.getWidth();
2450
+ int height = texturedata.getHeight();
2451
+
2452
+ Buffer buffer = texturedata.getBuffer();
2453
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2454
+
2455
+ byte[] bytes = bytebuf.array();
2456
+
2457
+ return CreateBim(bytes, width, height);
2458
+ }
2459
+
15172460 /**/
15182461 class CacheTexture
15192462 {
....@@ -1522,28 +2465,31 @@
15222465
15232466 int resolution;
15242467
1525
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2468
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
15262469 {
1527
- texture = tex;
2470
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2471
+ texturedata = texdata;
15282472 resolution = res;
15292473 }
15302474 }
15312475 /**/
15322476
15332477 // TEXTURE static Texture texture;
1534
- static public java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/> textures
1535
- = new java.util.Hashtable<String, CacheTexture/*com.sun.opengl.util.texture.Texture*/>();
1536
- static public java.util.Hashtable<String, String> usedtextures = new java.util.Hashtable<String, String>();
2478
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2479
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2480
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2481
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2482
+
15372483 int pigmentdepth = 0;
15382484 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
15392485 int bumpdepth = 0;
15402486 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
15412487 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
15422488 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
1543
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2489
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
15442490 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
15452491
1546
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2492
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
15472493 {
15482494 TextureData texturedata = null;
15492495
....@@ -1562,13 +2508,34 @@
15622508 if (bump)
15632509 texturedata = ConvertBump(texturedata, false);
15642510
1565
- com.sun.opengl.util.texture.Texture texture =
1566
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2511
+// com.sun.opengl.util.texture.Texture texture =
2512
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
15672513
1568
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
1569
- texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
2514
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2515
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
15702516
1571
- return texture;
2517
+ return texturedata;
2518
+ }
2519
+
2520
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2521
+ {
2522
+ TextureData texturedata = null;
2523
+
2524
+ try
2525
+ {
2526
+ texturedata =
2527
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2528
+ bim,
2529
+ true);
2530
+ } catch (Exception e)
2531
+ {
2532
+ throw new javax.media.opengl.GLException(e);
2533
+ }
2534
+
2535
+ if (bump)
2536
+ texturedata = ConvertBump(texturedata, false);
2537
+
2538
+ return texturedata;
15722539 }
15732540
15742541 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -2641,6 +3608,8 @@
26413608
26423609 System.out.println("LOADING TEXTURE : " + name);
26433610
3611
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3612
+
26443613 //
26453614 if (false) // compressbit > 0)
26463615 {
....@@ -3345,6 +4314,7 @@
33454314
33464315 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
33474316 {
4317
+ new Exception().printStackTrace();
33484318 System.exit(0);
33494319 com.sun.opengl.util.texture.Texture texture = null;
33504320
....@@ -7038,7 +8008,7 @@
70388008 String pigment = Object3D.GetPigment(tex);
70398009 String bump = Object3D.GetBump(tex);
70408010
7041
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8011
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
70428012 {
70438013 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
70448014 // System.out.println("; bump = " + bump);
....@@ -7053,11 +8023,69 @@
70538023 pigment = null;
70548024 }
70558025
7056
- ReleaseTexture(bump, true);
7057
- ReleaseTexture(pigment, false);
8026
+ ReleaseTexture(tex, true);
8027
+ ReleaseTexture(tex, false);
70588028 }
70598029
7060
- void ReleaseTexture(String tex, boolean bump)
8030
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8031
+ {
8032
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8033
+ {
8034
+ return;
8035
+ }
8036
+
8037
+ if (tex == null)
8038
+ {
8039
+ ReleaseTexture(null, false);
8040
+ return;
8041
+ }
8042
+
8043
+ String pigment = Object3D.GetPigment(tex);
8044
+
8045
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8046
+ {
8047
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8048
+ // System.out.println("; bump = " + bump);
8049
+ }
8050
+
8051
+ if (pigment.equals(""))
8052
+ {
8053
+ pigment = null;
8054
+ }
8055
+
8056
+ ReleaseTexture(tex, false);
8057
+ }
8058
+
8059
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8060
+ {
8061
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8062
+ {
8063
+ return;
8064
+ }
8065
+
8066
+ if (tex == null)
8067
+ {
8068
+ ReleaseTexture(null, true);
8069
+ return;
8070
+ }
8071
+
8072
+ String bump = Object3D.GetBump(tex);
8073
+
8074
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8075
+ {
8076
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8077
+ // System.out.println("; bump = " + bump);
8078
+ }
8079
+
8080
+ if (bump.equals(""))
8081
+ {
8082
+ bump = null;
8083
+ }
8084
+
8085
+ ReleaseTexture(tex, true);
8086
+ }
8087
+
8088
+ void ReleaseTexture(cTexture tex, boolean bump)
70618089 {
70628090 if (// DrawMode() != 0 || /*tex == null ||*/
70638091 ambientOcclusion ) // || !textureon)
....@@ -7068,7 +8096,7 @@
70688096 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
70698097
70708098 if (tex != null)
7071
- texture = textures.get(tex);
8099
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
70728100
70738101 // //assert( texture != null );
70748102 // if (texture == null)
....@@ -7160,7 +8188,55 @@
71608188 }
71618189 }
71628190
7163
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8191
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8192
+ {
8193
+// if (// DrawMode() != 0 || /*tex == null ||*/
8194
+// ambientOcclusion ) // || !textureon)
8195
+// {
8196
+// return; // false;
8197
+// }
8198
+//
8199
+// if (tex == null)
8200
+// {
8201
+// BindTexture(null,false,resolution);
8202
+// BindTexture(null,true,resolution);
8203
+// return;
8204
+// }
8205
+//
8206
+// String pigment = Object3D.GetPigment(tex);
8207
+// String bump = Object3D.GetBump(tex);
8208
+//
8209
+// usedtextures.add(pigment);
8210
+// usedtextures.add(bump);
8211
+//
8212
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8213
+// {
8214
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8215
+// // System.out.println("; bump = " + bump);
8216
+// }
8217
+//
8218
+// if (bump.equals(""))
8219
+// {
8220
+// bump = null;
8221
+// }
8222
+// if (pigment.equals(""))
8223
+// {
8224
+// pigment = null;
8225
+// }
8226
+//
8227
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8228
+// BindTexture(pigment, false, resolution);
8229
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8230
+// BindTexture(bump, true, resolution);
8231
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8232
+//
8233
+// return; // true;
8234
+
8235
+ BindPigmentTexture(tex, resolution);
8236
+ BindBumpTexture(tex, resolution);
8237
+ }
8238
+
8239
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
71648240 {
71658241 if (// DrawMode() != 0 || /*tex == null ||*/
71668242 ambientOcclusion ) // || !textureon)
....@@ -7171,17 +8247,47 @@
71718247 if (tex == null)
71728248 {
71738249 BindTexture(null,false,resolution);
7174
- BindTexture(null,true,resolution);
71758250 return;
71768251 }
71778252
71788253 String pigment = Object3D.GetPigment(tex);
8254
+
8255
+ usedtextures.add(tex);
8256
+
8257
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8258
+ {
8259
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8260
+ // System.out.println("; bump = " + bump);
8261
+ }
8262
+
8263
+ if (pigment.equals(""))
8264
+ {
8265
+ pigment = null;
8266
+ }
8267
+
8268
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8269
+ BindTexture(tex, false, resolution);
8270
+ }
8271
+
8272
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8273
+ {
8274
+ if (// DrawMode() != 0 || /*tex == null ||*/
8275
+ ambientOcclusion ) // || !textureon)
8276
+ {
8277
+ return; // false;
8278
+ }
8279
+
8280
+ if (tex == null)
8281
+ {
8282
+ BindTexture(null,true,resolution);
8283
+ return;
8284
+ }
8285
+
71798286 String bump = Object3D.GetBump(tex);
71808287
7181
- usedtextures.put(pigment, pigment);
7182
- usedtextures.put(bump, bump);
8288
+ usedtextures.add(tex);
71838289
7184
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8290
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
71858291 {
71868292 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
71878293 // System.out.println("; bump = " + bump);
....@@ -7191,43 +8297,94 @@
71918297 {
71928298 bump = null;
71938299 }
7194
- if (pigment.equals(""))
7195
- {
7196
- pigment = null;
7197
- }
71988300
7199
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7200
- BindTexture(pigment, false, resolution);
72018301 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7202
- BindTexture(bump, true, resolution);
8302
+ BindTexture(tex, true, resolution);
72038303 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7204
-
7205
- return; // true;
72068304 }
72078305
7208
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8306
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8307
+
8308
+ private boolean FileExists(String tex)
72098309 {
7210
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8310
+ if (missingTextures.contains(tex))
8311
+ {
8312
+ return false;
8313
+ }
8314
+
8315
+ boolean fileExists = new File(tex).exists();
8316
+
8317
+ if (!fileExists)
8318
+ {
8319
+ // If file exists, the "new File()" is not executed sgain
8320
+ missingTextures.add(tex);
8321
+ }
8322
+
8323
+ return fileExists;
8324
+ }
8325
+
8326
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8327
+ {
8328
+ CacheTexture texturecache = null;
72118329
72128330 if (tex != null)
72138331 {
7214
- String texname = tex;
8332
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8333
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
72158334
7216
- String[] split = tex.split("Textures");
7217
- if (split.length > 1)
7218
- texname = "/Users/nbriere/Textures" + split[split.length-1];
7219
- else
7220
- if (!texname.startsWith("/"))
7221
- texname = "/Users/nbriere/Textures/" + texname;
8335
+ if (texname.equals("") && texdata == null)
8336
+ {
8337
+ return null;
8338
+ }
8339
+
8340
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8341
+
8342
+// String[] split = tex.split("Textures");
8343
+// if (split.length > 1)
8344
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8345
+// else
8346
+// if (!texname.startsWith("/"))
8347
+// texname = "/Users/nbriere/Textures/" + texname;
8348
+ if (!FileExists(texname))
8349
+ {
8350
+ texname = fallbackTextureName;
8351
+ }
72228352
72238353 if (CACHETEXTURE)
7224
- texture = textures.get(texname); // TEXTURE CACHE
7225
-
7226
- TextureData texturedata = null;
7227
-
7228
- if (texture == null || texture.resolution < resolution)
72298354 {
7230
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8355
+ if (texdata == null)
8356
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8357
+ else
8358
+ texturecache = bimtextures.get(texdata);
8359
+ }
8360
+
8361
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8362
+ {
8363
+ TextureData texturedata = null;
8364
+
8365
+ if (texdata != null && textureon)
8366
+ {
8367
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8368
+
8369
+ try
8370
+ {
8371
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8372
+ }
8373
+ catch (Exception e)
8374
+ {
8375
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8376
+ }
8377
+
8378
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8379
+ bimtextures.put(texdata, texturecache);
8380
+
8381
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8382
+
8383
+ //Object bim2 = CreateBim(texturecache.texturedata);
8384
+ //bim2 = bim;
8385
+ }
8386
+ else
8387
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
72318388 {
72328389 assert(!bump);
72338390 // if (bump)
....@@ -7238,19 +8395,23 @@
72388395 // }
72398396 // else
72408397 // {
7241
- texture = textures.get(tex);
7242
- if (texture == null)
8398
+ // texturecache = textures.get(texname); // suspicious
8399
+ if (texturecache == null)
72438400 {
7244
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8401
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
72458402 }
8403
+ else
8404
+ new Exception().printStackTrace();
72468405 // }
72478406 } else
7248
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8407
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
72498408 {
72508409 assert(bump);
7251
- texture = textures.get(tex);
7252
- if (texture == null)
7253
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8410
+ // texturecache = textures.get(texname); // suspicious
8411
+ if (texturecache == null)
8412
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8413
+ else
8414
+ new Exception().printStackTrace();
72548415 } else
72558416 {
72568417 //if (tex.equals("IMMORTAL"))
....@@ -7258,11 +8419,13 @@
72588419 // texture = GetResourceTexture("default.png");
72598420 //} else
72608421 //{
7261
- if (tex.equals("WHITE_NOISE"))
8422
+ if (texname.endsWith("WHITE_NOISE"))
72628423 {
7263
- texture = textures.get(tex);
7264
- if (texture == null)
7265
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8424
+ // texturecache = textures.get(texname); // suspicious
8425
+ if (texturecache == null)
8426
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8427
+ else
8428
+ new Exception().printStackTrace();
72668429 } else
72678430 {
72688431 if (textureon)
....@@ -7287,7 +8450,7 @@
72878450 }
72888451
72898452 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7290
- if (!new File(cachename).exists())
8453
+ if (!FileExists(cachename))
72918454 cachename = texname;
72928455 else
72938456 processbump = false; // don't process bump map again
....@@ -7309,7 +8472,7 @@
73098472 }
73108473
73118474 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7312
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
73138476 cachename = texname;
73148477 else
73158478 processbump = false; // don't process bump map again
....@@ -7318,20 +8481,22 @@
73188481 texturedata = GetFileTexture(cachename, processbump, resolution);
73198482
73208483
7321
- if (texturedata != null)
7322
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8484
+ if (texturedata == null)
8485
+ throw new Exception();
8486
+
8487
+ texturecache = new CacheTexture(texturedata,resolution);
73238488 //texture = GetTexture(tex, bump);
73248489 }
73258490 }
73268491 //}
73278492 }
73288493
7329
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8494
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
73308495 {
73318496 //return false;
73328497
73338498 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7334
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8499
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
73358500 {
73368501 // String ext = "_highres";
73378502 // if (REDUCETEXTURE)
....@@ -7348,52 +8513,17 @@
73488513 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
73498514 if (!cachefile.exists())
73508515 {
7351
- // cache to disk
7352
- Buffer buffer = texturedata.getBuffer(); // getMipmapData();
7353
- //buffers[0].
7354
-
7355
- ByteBuffer bytebuf = (ByteBuffer)buffer; // ).asIntBuffer();
7356
- int[] pixels = new int[bytebuf.capacity()/3];
7357
-
7358
- // squared size heuristic...
7359
- if ((int)Math.sqrt(pixels.length) == Math.sqrt(pixels.length))
8516
+ //if (texturedata.getWidth() == texturedata.getHeight())
73608517 {
7361
- for (int i=pixels.length; --i>=0;)
7362
- {
7363
- int i3 = i*3;
7364
- pixels[i] = 0xFF;
7365
- pixels[i] <<= 8;
7366
- pixels[i] |= bytebuf.get(i3+2) & 0xFF;
7367
- pixels[i] <<= 8;
7368
- pixels[i] |= bytebuf.get(i3+1) & 0xFF;
7369
- pixels[i] <<= 8;
7370
- pixels[i] |= bytebuf.get(i3) & 0xFF;
7371
- }
7372
-
7373
- /*
7374
- int r=0,g=0,b=0,a=0;
7375
- for (int i=0; i<width; i++)
7376
- for (int j=0; j<height; j++)
7377
- {
7378
- int index = j*width+i;
7379
- int p = pixels[index];
7380
- a = ((p>>24) & 0xFF);
7381
- r = ((p>>16) & 0xFF);
7382
- g = ((p>>8) & 0xFF);
7383
- b = (p & 0xFF);
7384
- pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
7385
- }
7386
- /**/
7387
- int width = (int)Math.sqrt(pixels.length); // squared
7388
- int height = width;
7389
- BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
7390
- rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
8518
+ BufferedImage rendImage = CreateBim(texturedata);
8519
+
73918520 ImageWriter writer = null;
73928521 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
73938522 if (iter.hasNext()) {
73948523 writer = (ImageWriter)iter.next();
73958524 }
7396
- float compressionQuality = 0.9f;
8525
+
8526
+ float compressionQuality = 0.85f;
73978527 try
73988528 {
73998529 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7410,18 +8540,20 @@
74108540 }
74118541 }
74128542 }
7413
-
8543
+
8544
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8545
+
74148546 //System.out.println("Texture = " + tex);
7415
- if (textures.containsKey(texname))
8547
+ if (textures.containsKey(tex))
74168548 {
7417
- CacheTexture thetex = textures.get(texname);
8549
+ CacheTexture thetex = textures.get(tex);
74188550 thetex.texture.disable();
74198551 thetex.texture.dispose();
7420
- textures.remove(texname);
8552
+ textures.remove(tex);
74218553 }
74228554
7423
- texture.texturedata = texturedata;
7424
- textures.put(texname, texture);
8555
+ //texture.texturedata = texturedata;
8556
+ textures.put(tex, texturecache);
74258557
74268558 // newtex = true;
74278559 }
....@@ -7437,10 +8569,44 @@
74378569 }
74388570 }
74398571
7440
- return texture;
8572
+ return texturecache;
74418573 }
74428574
7443
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8575
+ static void EmbedTextures(cTexture tex)
8576
+ {
8577
+ if (tex.pigmentdata == null)
8578
+ {
8579
+ //String texname = Object3D.GetPigment(tex);
8580
+
8581
+ CacheTexture texturecache = texturepigment.get(tex);
8582
+
8583
+ if (texturecache != null)
8584
+ {
8585
+ tex.pw = texturecache.texturedata.getWidth();
8586
+ tex.ph = texturecache.texturedata.getHeight();
8587
+ tex.pigmentdata = //CompressJPEG(CreateBim
8588
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8589
+ ;
8590
+ //, tex.pw, tex.ph), 0.5f);
8591
+ }
8592
+ }
8593
+
8594
+ if (tex.bumpdata == null)
8595
+ {
8596
+ //String texname = Object3D.GetBump(tex);
8597
+
8598
+ CacheTexture texturecache = texturebump.get(tex);
8599
+
8600
+ if (texturecache != null)
8601
+ {
8602
+ tex.bw = texturecache.texturedata.getWidth();
8603
+ tex.bh = texturecache.texturedata.getHeight();
8604
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8605
+ }
8606
+ }
8607
+ }
8608
+
8609
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
74448610 {
74458611 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
74468612
....@@ -7458,21 +8624,21 @@
74588624 return texture!=null?texture.texture:null;
74598625 }
74608626
7461
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8627
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
74628628 {
74638629 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
74648630
74658631 return texture!=null?texture.texturedata:null;
74668632 }
74678633
7468
- boolean BindTexture(String tex, boolean bump, int resolution)
8634
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
74698635 {
74708636 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
74718637 {
74728638 return false;
74738639 }
74748640
7475
- boolean newtex = false;
8641
+ //boolean newtex = false;
74768642
74778643 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
74788644
....@@ -7504,9 +8670,75 @@
75048670 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
75058671 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
75068672
7507
- return newtex;
8673
+ return true; // Warning: not used.
75088674 }
75098675
8676
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8677
+ {
8678
+ try
8679
+ {
8680
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8681
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8682
+ ImageWriter writer = writers.next();
8683
+
8684
+ ImageWriteParam param = writer.getDefaultWriteParam();
8685
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8686
+ param.setCompressionQuality(quality);
8687
+
8688
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8689
+ writer.setOutput(ios);
8690
+ writer.write(null, new IIOImage(image, null, null), param);
8691
+
8692
+ byte[] data = baos.toByteArray();
8693
+ writer.dispose();
8694
+ return data;
8695
+ }
8696
+ catch (Exception e)
8697
+ {
8698
+ e.printStackTrace();
8699
+ return null;
8700
+ }
8701
+ }
8702
+
8703
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8704
+ {
8705
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8706
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8707
+ ImageReader reader = writers.next();
8708
+
8709
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8710
+
8711
+ ImageReadParam param = reader.getDefaultReadParam();
8712
+ param.setDestination(bim);
8713
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8714
+
8715
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8716
+ reader.setInput(ios);
8717
+ BufferedImage bim2 = reader.read(0, param);
8718
+ reader.dispose();
8719
+
8720
+// WritableRaster raster = bim2.getRaster();
8721
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8722
+// byte[] bytes = data.getData();
8723
+//
8724
+// int[] pixels = new int[bytes.length/3];
8725
+// for (int i=pixels.length; --i>=0;)
8726
+// {
8727
+// int i3 = i*3;
8728
+// pixels[i] = 0xFF;
8729
+// pixels[i] <<= 8;
8730
+// pixels[i] |= bytes[i3+2] & 0xFF;
8731
+// pixels[i] <<= 8;
8732
+// pixels[i] |= bytes[i3+1] & 0xFF;
8733
+// pixels[i] <<= 8;
8734
+// pixels[i] |= bytes[i3] & 0xFF;
8735
+// }
8736
+//
8737
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8738
+
8739
+ return bim;
8740
+ }
8741
+
75108742 ShadowBuffer shadowPBuf;
75118743 AntialiasBuffer antialiasPBuf;
75128744 int MAXSTACK;
....@@ -8342,11 +9574,35 @@
83429574 jy8[3] = 0.5f;
83439575 }
83449576
8345
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9577
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
83469578 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
83479579 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
83489580 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
83499581
9582
+ void ResetOptions()
9583
+ {
9584
+ options1[0] = 100;
9585
+ options1[1] = 0.025f;
9586
+ options1[2] = 0.01f;
9587
+ options1[3] = 0;
9588
+ options1[4] = 0;
9589
+
9590
+ options2[0] = 0;
9591
+ options2[1] = 0.75f;
9592
+ options2[2] = 0;
9593
+ options2[3] = 0;
9594
+
9595
+ options3[0] = 1;
9596
+ options3[1] = 1;
9597
+ options3[2] = 1;
9598
+ options3[3] = 0;
9599
+
9600
+ options4[0] = 1;
9601
+ options4[1] = 0;
9602
+ options4[2] = 1;
9603
+ options4[3] = 0;
9604
+ }
9605
+
83509606 static int imagecount = 0; // movie generation
83519607
83529608 static int jitter = 0;
....@@ -8442,8 +9698,8 @@
84429698 assert (parentcam != renderCamera);
84439699
84449700 if (renderCamera != lightCamera)
8445
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8446
- LA.matConcat(matrix, parentcam.toParent, matrix);
9701
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9702
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
84479703
84489704 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
84499705
....@@ -8458,8 +9714,8 @@
84589714 LA.matCopy(renderCamera.fromScreen, matrix);
84599715
84609716 if (renderCamera != lightCamera)
8461
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8462
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9717
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9718
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
84639719
84649720 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
84659721
....@@ -8531,7 +9787,7 @@
85319787 //gl.glFlush();
85329788 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
85339789
8534
- if (ANIMATION && ABORTED)
9790
+ if (Globals.ANIMATION && ABORTED)
85359791 {
85369792 System.err.println(" ABORTED FRAME");
85379793 break;
....@@ -8561,7 +9817,7 @@
85619817 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
85629818
85639819 // save image
8564
- if (ANIMATION && !ABORTED)
9820
+ if (Globals.ANIMATION && !ABORTED)
85659821 {
85669822 VPwidth = viewport[2];
85679823 VPheight = viewport[3];
....@@ -8672,11 +9928,11 @@
86729928
86739929 // imagecount++;
86749930
8675
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9931
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
86769932
86779933 if (!BOXMODE)
86789934 {
8679
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9935
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
86809936 }
86819937
86829938 if (!BOXMODE)
....@@ -8714,7 +9970,7 @@
87149970 ABORTED = false;
87159971 }
87169972 else
8717
- GrafreeD.wav.cursor += 735 * ACSIZE;
9973
+ Grafreed.wav.cursor += 735 * ACSIZE;
87189974
87199975 if (false)
87209976 {
....@@ -9377,11 +10633,11 @@
937710633
937810634 public void display(GLAutoDrawable drawable)
937910635 {
9380
- if (GrafreeD.savesound && GrafreeD.hassound)
10636
+ if (Grafreed.savesound && Grafreed.hassound)
938110637 {
9382
- GrafreeD.wav.save();
9383
- GrafreeD.savesound = false;
9384
- GrafreeD.hassound = false;
10638
+ Grafreed.wav.save();
10639
+ Grafreed.savesound = false;
10640
+ Grafreed.hassound = false;
938510641 }
938610642 // if (DEBUG_SELECTION)
938710643 // {
....@@ -9457,6 +10713,7 @@
945710713 ANTIALIAS = 0;
945810714 //System.out.println("RESTART");
945910715 AAtimer.restart();
10716
+ Globals.TIMERRUNNING = true;
946010717 }
946110718 }
946210719 }
....@@ -9511,7 +10768,7 @@
951110768 Object3D theobject = object;
951210769 Object3D theparent = object.parent;
951310770 object.parent = null;
9514
- object = (Object3D)GrafreeD.clone(object);
10771
+ object = (Object3D)Grafreed.clone(object);
951510772 object.Stripify();
951610773 if (theobject.selection == null || theobject.selection.Size() == 0)
951710774 theobject.PreprocessOcclusion(this);
....@@ -9524,13 +10781,14 @@
952410781 ambientOcclusion = false;
952510782 }
952610783
9527
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10784
+ if (//Globals.lighttouched &&
10785
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
952810786 {
952910787 //if (RENDERSHADOW) // ?
953010788 if (!IsFrozen())
953110789 {
953210790 // dec 2012
9533
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10791
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
953410792 {
953510793 Globals.framecount++;
953610794 shadowbuffer.display();
....@@ -9657,8 +10915,8 @@
965710915
965810916 // if (parentcam != renderCamera) // not a light
965910917 if (cam != lightCamera)
9660
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9661
- LA.matConcat(matrix, parentcam.toParent, matrix);
10918
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10919
+ LA.matConcat(matrix, parentcam.GlobalTransform(), matrix);
966210920
966310921 for (int j = 0; j < 4; j++)
966410922 {
....@@ -9672,8 +10930,8 @@
967210930
967310931 // if (parentcam != renderCamera) // not a light
967410932 if (cam != lightCamera)
9675
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9676
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10933
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10934
+ LA.matConcat(parentcam.GlobalTransformInv(), matrix, matrix);
967710935
967810936 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
967910937
....@@ -9932,7 +11190,16 @@
993211190 // Bump noise
993311191 gl.glActiveTexture(GL.GL_TEXTURE6);
993411192 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9935
- BindTexture(NOISE_TEXTURE, false, 2);
11193
+
11194
+ try
11195
+ {
11196
+ BindTexture(NOISE_TEXTURE, false, 2);
11197
+ }
11198
+ catch (Exception e)
11199
+ {
11200
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11201
+ }
11202
+
993611203
993711204 gl.glActiveTexture(GL.GL_TEXTURE0);
993811205 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9955,9 +11222,9 @@
995511222
995611223 gl.glMatrixMode(GL.GL_MODELVIEW);
995711224
9958
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9959
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9960
-//gl.glEnable(gl.GL_MULTISAMPLE);
11225
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11226
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11227
+gl.glEnable(gl.GL_MULTISAMPLE);
996111228 } else
996211229 {
996311230 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9968,7 +11235,7 @@
996811235 //System.out.println("BLENDING ON");
996911236 gl.glEnable(GL.GL_BLEND);
997011237 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9971
-
11238
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
997211239 gl.glMatrixMode(gl.GL_PROJECTION);
997311240 gl.glLoadIdentity();
997411241
....@@ -10057,8 +11324,8 @@
1005711324 System.err.println("parentcam != renderCamera");
1005811325
1005911326 // if (cam != lightCamera)
10060
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10061
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11327
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11328
+ LA.xformDir(lightposition, parentcam.GlobalTransform(), lightposition); // may 2013
1006211329 }
1006311330
1006411331 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10079,8 +11346,8 @@
1007911346 if (true) // TODO
1008011347 {
1008111348 if (cam != lightCamera)
10082
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10083
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11349
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11350
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1008411351 }
1008511352
1008611353 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10146,7 +11413,7 @@
1014611413 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
1014711414 //System.out.println("fragmentMode = " + fragmentMode);
1014811415
10149
- if (DrawMode() == DEFAULT || DrawMode() == SELECTION || DEBUG_SELECTION)
11416
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
1015011417 {
1015111418 /*
1015211419 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -10217,7 +11484,7 @@
1021711484 }
1021811485 }
1021911486
10220
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11487
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1022111488 {
1022211489 //gl.glDepthFunc(GL.GL_LEQUAL);
1022311490 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10225,24 +11492,21 @@
1022511492
1022611493 boolean texon = textureon;
1022711494
10228
- if (RENDERPROGRAM > 0)
10229
- {
10230
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10231
- textureon = false;
10232
- }
11495
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11496
+ textureon = false;
11497
+
1023311498 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1023411499 //System.out.println("ALLO");
1023511500 gl.glColorMask(false, false, false, false);
1023611501 DrawObject(gl);
10237
- if (RENDERPROGRAM > 0)
10238
- {
10239
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10240
- textureon = texon;
10241
- }
11502
+
11503
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11504
+ textureon = texon;
11505
+
1024211506 gl.glColorMask(true, true, true, true);
1024311507
1024411508 gl.glDepthFunc(GL.GL_EQUAL);
10245
- //gl.glDepthMask(false);
11509
+ gl.glDepthMask(false);
1024611510 }
1024711511
1024811512 if (false) // DrawMode() == SHADOW)
....@@ -10396,8 +11660,14 @@
1039611660 {
1039711661 renderpass++;
1039811662 // System.out.println("Draw object... ");
11663
+ STEP = 1;
1039911664 if (FAST) // in case there is no script
10400
- STEP = 16;
11665
+ STEP = 8;
11666
+
11667
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11668
+ {
11669
+ STEP *= 4;
11670
+ }
1040111671
1040211672 //object.FullInvariants();
1040311673
....@@ -10411,23 +11681,44 @@
1041111681 e.printStackTrace();
1041211682 }
1041311683
10414
- if (GrafreeD.RENDERME > 0)
10415
- GrafreeD.RENDERME--; // mechante magouille
11684
+ if (Grafreed.RENDERME > 0)
11685
+ Grafreed.RENDERME--; // mechante magouille
1041611686
1041711687 Globals.ONESTEP = false;
1041811688 }
1041911689
1042011690 static boolean zoomonce = false;
1042111691
11692
+ static void CreateSelectedPoint()
11693
+ {
11694
+ if (selectedpoint == null)
11695
+ {
11696
+ debugpointG = new Sphere();
11697
+ debugpointP = new Sphere();
11698
+ debugpointC = new Sphere();
11699
+ debugpointR = new Sphere();
11700
+
11701
+ selectedpoint = new Superellipsoid();
11702
+
11703
+ for (int i=0; i<8; i++)
11704
+ {
11705
+ debugpoints[i] = new Sphere();
11706
+ }
11707
+ }
11708
+ }
11709
+
1042211710 void DrawObject(GL gl, boolean draw)
1042311711 {
11712
+ // To clear camera values
11713
+ ResetOptions();
11714
+
1042411715 //System.out.println("DRAW OBJECT " + mouseDown);
1042511716 // DrawMode() = SELECTION;
1042611717 //GL gl = getGL();
1042711718 if ((TRACK || SHADOWTRACK) || zoomonce)
1042811719 {
1042911720 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10430
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11721
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1043111722 pingthread.StepToTarget(true); // true);
1043211723 // zoomonce = false;
1043311724 }
....@@ -10447,7 +11738,7 @@
1044711738 callist = gl.glGenLists(1);
1044811739 }
1044911740
10450
- boolean selectmode = DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
11741
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
1045111742
1045211743 boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
1045311744
....@@ -10482,7 +11773,14 @@
1048211773
1048311774 usedtextures.clear();
1048411775
10485
- BindTextures(DEFAULT_TEXTURES, 2);
11776
+ try
11777
+ {
11778
+ BindTextures(DEFAULT_TEXTURES, 2);
11779
+ }
11780
+ catch (Exception e)
11781
+ {
11782
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11783
+ }
1048611784 }
1048711785 //System.out.println("--> " + stackdepth);
1048811786 // GrafreeD.traceon();
....@@ -10492,8 +11790,9 @@
1049211790
1049311791 if (DrawMode() == DEFAULT)
1049411792 {
10495
- if (DEBUG)
11793
+ if (Globals.DEBUG)
1049611794 {
11795
+ CreateSelectedPoint();
1049711796 float radius = 0.05f;
1049811797 if (selectedpoint.radius != radius)
1049911798 {
....@@ -10547,20 +11846,32 @@
1054711846 ReleaseTextures(DEFAULT_TEXTURES);
1054811847
1054911848 if (CLEANCACHE)
10550
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11849
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1055111850 {
10552
- String tex = e.nextElement();
11851
+ cTexture tex = e.nextElement();
1055311852
1055411853 // System.out.println("Texture --------- " + tex);
1055511854
10556
- if (tex.equals("WHITE_NOISE"))
11855
+ if (tex.equals("WHITE_NOISE:"))
1055711856 continue;
1055811857
10559
- if (!usedtextures.containsKey(tex))
11858
+ if (!usedtextures.contains(tex))
1056011859 {
11860
+ CacheTexture gettex = texturepigment.get(tex);
1056111861 // System.out.println("DISPOSE +++++++++++++++ " + tex);
10562
- textures.get(tex).texture.dispose();
10563
- textures.remove(tex);
11862
+ if (gettex != null)
11863
+ {
11864
+ gettex.texture.dispose();
11865
+ texturepigment.remove(tex);
11866
+ }
11867
+
11868
+ gettex = texturebump.get(tex);
11869
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11870
+ if (gettex != null)
11871
+ {
11872
+ gettex.texture.dispose();
11873
+ texturebump.remove(tex);
11874
+ }
1056411875 }
1056511876 }
1056611877 }
....@@ -10573,7 +11884,14 @@
1057311884 if (checker != null && DrawMode() == DEFAULT)
1057411885 {
1057511886 //BindTexture(IMMORTAL_TEXTURE);
10576
- BindTextures(checker.GetTextures(), checker.texres);
11887
+ try
11888
+ {
11889
+ BindTextures(checker.GetTextures(), checker.texres);
11890
+ }
11891
+ catch (Exception e)
11892
+ {
11893
+ System.err.println("FAILED: " + checker.GetTextures());
11894
+ }
1057711895 // NEAREST
1057811896 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1057911897 DrawChecker(gl);
....@@ -10655,7 +11973,7 @@
1065511973 return;
1065611974 }
1065711975
10658
- String string = obj.GetToolTip();
11976
+ String string = obj.toString(); //.GetToolTip();
1065911977
1066011978 GL gl = GetGL();
1066111979
....@@ -10972,8 +12290,8 @@
1097212290 //obj.TransformToWorld(light, light);
1097312291 for (int i = tp.size(); --i >= 0;)
1097412292 {
10975
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10976
- LA.xformPos(light, tp.get(i).toParent, light);
12293
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12294
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1097712295 }
1097812296
1097912297
....@@ -10990,8 +12308,8 @@
1099012308 parentcam = cameras[0];
1099112309 }
1099212310
10993
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10994
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12311
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12312
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1099512313
1099612314 LA.xformPos(light, renderCamera.toScreen, light);
1099712315
....@@ -11082,7 +12400,52 @@
1108212400 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1108312401
1108412402 String program =
12403
+ // Min shader
1108512404 "!!ARBfp1.0\n" +
12405
+ "PARAM zero123 = { 0.0, 1.0, 2.0, 1.25 };" +
12406
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12407
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12408
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12409
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12410
+ "TEMP temp;" +
12411
+ "TEMP light;" +
12412
+ "TEMP ndotl;" +
12413
+ "TEMP normal;" +
12414
+ "TEMP depth;" +
12415
+
12416
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12417
+
12418
+ "MOV light, state.light[0].position;" +
12419
+ "DP3 ndotl.x, light, normal;" +
12420
+
12421
+ // shadow
12422
+ "MOV temp, fragment.texcoord[1];" +
12423
+ TextureFetch("depth", "temp", "1") +
12424
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12425
+ "SLT temp.x, fragment.texcoord[1].z, depth.z;" +
12426
+
12427
+
12428
+ // No shadow when out of frustum
12429
+ //"SGE temp.y, depth.z, zero123.y;" +
12430
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12431
+
12432
+ "MUL ndotl.x, ndotl.x, temp.x;" +
12433
+ "MAX ndotl.x, ndotl.x, pow2.y;" +
12434
+
12435
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12436
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12437
+ "MUL temp, temp, ndotl.x;" +
12438
+
12439
+ "MUL temp, temp, zero123.z;" +
12440
+
12441
+ "MOV temp.w, zero123.y;" + // reset alpha
12442
+
12443
+ "MOV result.color, temp;" +
12444
+ "END";
12445
+
12446
+ String program2 =
12447
+ "!!ARBfp1.0\n" +
12448
+
1108612449 //"OPTION ARB_fragment_program_shadow;" +
1108712450 "PARAM light2cam0 = program.env[10];" +
1108812451 "PARAM light2cam1 = program.env[11];" +
....@@ -11197,8 +12560,7 @@
1119712560 "TEMP shininess;" +
1119812561 "\n" +
1119912562 "MOV texSamp, one;" +
11200
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11201
-
12563
+
1120212564 "MOV mapgrid.x, one2048th.x;" +
1120312565 "MOV temp, fragment.texcoord[1];" +
1120412566 /*
....@@ -11603,10 +12965,10 @@
1160312965 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1160412966 "") +
1160512967
11606
- // display shadow only (bump == 0)
12968
+ // display shadow only (fakedepth == 0)
1160712969 "SUB temp.x, half.x, shadow.x;" +
11608
- "MOV temp.y, -params6.x;" +
11609
- "SLT temp.z, temp.y, zero.x;" +
12970
+ "MOV temp.y, -params5.z;" + // params6.x;" +
12971
+ "SLT temp.z, temp.y, -one2048th.x;" +
1161012972 "SUB temp.y, one.x, temp.z;" +
1161112973 "MUL temp.x, temp.x, temp.y;" +
1161212974 "KIL temp.x;" +
....@@ -11735,8 +13097,10 @@
1173513097 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1173613098
1173713099 "SUB temp.x, one.x, ndotl.x;" +
11738
- "ADD temp.x, temp.x, options2.z;" + // lightsheen
11739
- "ADD temp.y, one.y, options2.y;" + // sursurface
13100
+ // Tuning for default skin
13101
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13102
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13103
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1174013104 "MUL temp.x, temp.x, temp.y;" +
1174113105
1174213106 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11935,7 +13299,7 @@
1193513299 //once = true;
1193613300 }
1193713301
11938
- System.out.print("Program #" + mode + "; length = " + program.length());
13302
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1193913303 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1194013304 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1194113305
....@@ -12033,20 +13397,20 @@
1203313397 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1203413398 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1203513399 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13400
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13401
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1203613402 "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12037
- "SLT " + src + ".z, " + src + ".x, one.x;" +
12038
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
12039
- "SLT " + src + ".z, " + src + ".y, one.x;" +
12040
- "MUL " + src + ".w, " + src + ".z, " + src + ".w;" +
13403
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13404
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1204113405 //"SWZ buffer, temp, w,w,w,w;";
12042
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13406
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1204313407 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1204413408 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1204513409 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12046
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13410
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1204713411
12048
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12049
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13412
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13413
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1205013414 }
1205113415
1205213416 String Shadow(String depth, String shadow)
....@@ -12068,12 +13432,16 @@
1206813432
1206913433 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1207013434 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13435
+
13436
+ // Compare fragment depth in light space with shadowmap.
1207113437 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1207213438 "SGE temp.y, temp.x, zero.x;" +
12073
- "SUB " + shadow + ".y, one.x, temp.y;" +
13439
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13440
+
13441
+ // Reverse comparison
1207413442 "SUB temp.x, one.x, temp.x;" +
1207513443 "MUL " + shadow + ".x, temp.x, temp.y;" +
12076
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13444
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1207713445 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1207813446
1207913447 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12087,6 +13455,10 @@
1208713455 // No shadow for backface
1208813456 "DP3 temp.x, normal, lightd;" +
1208913457 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13458
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13459
+
13460
+ // No shadow when out of frustum
13461
+ "SGE temp.x, " + depth + ".z, one.z;" +
1209013462 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1209113463 "";
1209213464 }
....@@ -12233,7 +13605,8 @@
1223313605 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1223413606 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1223513607 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12236
- Object3D.cVector2[] vector2buffer;
13608
+
13609
+ //Object3D.cVector2[] vector2buffer;
1223713610
1223813611 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1223913612 // OUT : diff, spec
....@@ -12249,9 +13622,10 @@
1224913622 "DP3 " + dest + ".z," + "normals," + "eye;" +
1225013623 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1225113624 //"MOV " + dest + ".w," + "normal.z;" +
12252
- "MUL " + dest + ".z," + "params2.w," + dest + ".x;" +
12253
- "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
12254
- //"MOV " + dest + ".z," + "params2.w;" +
13625
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13626
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13627
+
13628
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1225513629 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1225613630 "RCP " + dest + ".w," + dest + ".w;" +
1225713631 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -12645,7 +14019,7 @@
1264514019 public void mousePressed(MouseEvent e)
1264614020 {
1264714021 //System.out.println("mousePressed: " + e);
12648
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14022
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1264914023 }
1265014024
1265114025 static long prevtime = 0;
....@@ -12672,6 +14046,7 @@
1267214046
1267314047 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1267414048
14049
+ if (BUTTONLESSWHEEL)
1267514050 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1267614051 {
1267714052 return;
....@@ -12680,7 +14055,7 @@
1268014055 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1268114056
1268214057 // TIMER
12683
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14058
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1268414059 {
1268514060 keepboxmode = BOXMODE;
1268614061 keepsupport = SUPPORT;
....@@ -12720,8 +14095,8 @@
1272014095 // mode |= META;
1272114096 //}
1272214097
12723
- SetMouseMode(WHEEL | e.getModifiersEx());
12724
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14098
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14099
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1272514100 anchorX = ax;
1272614101 anchorY = ay;
1272714102 prevX = px;
....@@ -12755,6 +14130,7 @@
1275514130 else
1275614131 if (evt.getSource() == AAtimer)
1275714132 {
14133
+ Globals.TIMERRUNNING = false;
1275814134 if (mouseDown)
1275914135 {
1276014136 //new Exception().printStackTrace();
....@@ -12780,6 +14156,10 @@
1278014156 // LIVE = waslive;
1278114157 // wasliveok = true;
1278214158 // waslive = false;
14159
+
14160
+ // May 2019 Forget it:
14161
+ if (true)
14162
+ return;
1278314163
1278414164 // source == timer
1278514165 if (mouseDown)
....@@ -12810,7 +14190,7 @@
1281014190
1281114191 // fev 2014???
1281214192 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
12813
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14193
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1281414194 pingthread.StepToTarget(true); // true);
1281514195 }
1281614196 // if (!LIVE)
....@@ -12819,12 +14199,13 @@
1281914199
1282014200 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1282114201
12822
- void clickStart(int x, int y, int modifiers)
14202
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1282314203 {
1282414204 if (!wasliveok)
1282514205 return;
1282614206
1282714207 AAtimer.restart(); //
14208
+ Globals.TIMERRUNNING = true;
1282814209
1282914210 // waslive = LIVE;
1283014211 // LIVE = false;
....@@ -12836,7 +14217,7 @@
1283614217 // touched = true; // main DL
1283714218 if (isRenderer)
1283814219 {
12839
- SetMouseMode(modifiers);
14220
+ SetMouseMode(modifiers, modifiersex);
1284014221 }
1284114222
1284214223 selectX = anchorX = x;
....@@ -12849,7 +14230,7 @@
1284914230 clicked = true;
1285014231 hold = false;
1285114232
12852
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14233
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1285314234 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1285414235 {
1285514236 // System.out.println("RESTART II " + modifiers);
....@@ -12874,14 +14255,15 @@
1287414255 drag = false;
1287514256 //System.out.println("Mouse DOWN");
1287614257 editObj = false;
12877
- ClickInfo info = new ClickInfo();
12878
- info.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
12879
- info.pane = this;
12880
- info.camera = renderCamera;
12881
- info.x = x;
12882
- info.y = y;
12883
- info.modifiers = modifiers;
12884
- editObj = object.doEditClick(info, 0);
14258
+ //ClickInfo info = new ClickInfo();
14259
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14260
+ object.clickInfo.pane = this;
14261
+ object.clickInfo.camera = renderCamera;
14262
+ object.clickInfo.x = x;
14263
+ object.clickInfo.y = y;
14264
+ object.clickInfo.modifiers = modifiersex;
14265
+ editObj = object.doEditClick(//info,
14266
+ 0);
1288514267 if (!editObj)
1288614268 {
1288714269 hasMarquee = true;
....@@ -12897,11 +14279,14 @@
1289714279
1289814280 public void mouseDragged(MouseEvent e)
1289914281 {
14282
+ Globals.MOUSEDRAGGED = true;
14283
+
14284
+ //System.out.println("mouseDragged: " + e);
1290014285 if (isRenderer)
1290114286 movingcamera = true;
14287
+
1290214288 //if (drawing)
1290314289 //return;
12904
- //System.out.println("mouseDragged: " + e);
1290514290 if ((e.getModifiersEx() & CTRL) != 0
1290614291 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1290714292 {
....@@ -12909,7 +14294,7 @@
1290914294 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1291014295 }
1291114296 else
12912
- drag(e.getX(), e.getY(), e.getModifiersEx());
14297
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1291314298
1291414299 //try { Thread.sleep(1); } catch (Exception ex) {}
1291514300 }
....@@ -12921,6 +14306,11 @@
1292114306 cVector tmp = new cVector();
1292214307 cVector tmp2 = new cVector();
1292314308 boolean isMoving;
14309
+
14310
+ public cVector TargetLookAt()
14311
+ {
14312
+ return targetLookAt;
14313
+ }
1292414314
1292514315 class PingThread extends Thread
1292614316 {
....@@ -13077,6 +14467,7 @@
1307714467
1307814468 public void run()
1307914469 {
14470
+ new Exception().printStackTrace();
1308014471 System.exit(0);
1308114472 for (;;)
1308214473 {
....@@ -13140,7 +14531,7 @@
1314014531 {
1314114532 Globals.lighttouched = true;
1314214533 }
13143
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14534
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1314414535 }
1314514536 //else
1314614537 }
....@@ -13154,12 +14545,12 @@
1315414545 void GoDown(int mod)
1315514546 {
1315614547 MODIFIERS |= COMMAND;
13157
- /*
14548
+ /**/
1315814549 if((mod&SHIFT) == SHIFT)
1315914550 manipCamera.RotatePosition(0, -speed);
1316014551 else
13161
- manipCamera.BackForth(0, -speed*delta, getWidth());
13162
- */
14552
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
14553
+ /**/
1316314554 if ((mod & SHIFT) == SHIFT)
1316414555 {
1316514556 mouseMode = mouseMode; // VR??
....@@ -13175,12 +14566,12 @@
1317514566 void GoUp(int mod)
1317614567 {
1317714568 MODIFIERS |= COMMAND;
13178
- /*
14569
+ /**/
1317914570 if((mod&SHIFT) == SHIFT)
1318014571 manipCamera.RotatePosition(0, speed);
1318114572 else
13182
- manipCamera.BackForth(0, speed*delta, getWidth());
13183
- */
14573
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
14574
+ /**/
1318414575 if ((mod & SHIFT) == SHIFT)
1318514576 {
1318614577 mouseMode = mouseMode;
....@@ -13196,12 +14587,12 @@
1319614587 void GoLeft(int mod)
1319714588 {
1319814589 MODIFIERS |= COMMAND;
13199
- /*
14590
+ /**/
1320014591 if((mod&SHIFT) == SHIFT)
13201
- manipCamera.RotatePosition(speed, 0);
13202
- else
1320314592 manipCamera.Translate(speed*delta, 0, getWidth());
13204
- */
14593
+ else
14594
+ manipCamera.RotatePosition(speed, 0);
14595
+ /**/
1320514596 if ((mod & SHIFT) == SHIFT)
1320614597 {
1320714598 mouseMode = mouseMode;
....@@ -13217,12 +14608,12 @@
1321714608 void GoRight(int mod)
1321814609 {
1321914610 MODIFIERS |= COMMAND;
13220
- /*
14611
+ /**/
1322114612 if((mod&SHIFT) == SHIFT)
13222
- manipCamera.RotatePosition(-speed, 0);
13223
- else
1322414613 manipCamera.Translate(-speed*delta, 0, getWidth());
13225
- */
14614
+ else
14615
+ manipCamera.RotatePosition(-speed, 0);
14616
+ /**/
1322614617 if ((mod & SHIFT) == SHIFT)
1322714618 {
1322814619 mouseMode = mouseMode;
....@@ -13240,7 +14631,7 @@
1324014631 int X, Y;
1324114632 boolean SX, SY;
1324214633
13243
- void drag(int x, int y, int modifiers)
14634
+ void drag(int x, int y, int modifiers, int modifiersex)
1324414635 {
1324514636 if (IsFrozen())
1324614637 {
....@@ -13249,17 +14640,17 @@
1324914640
1325014641 drag = true; // NEW
1325114642
13252
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14643
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1325314644
1325414645 X = x;
1325514646 Y = y;
1325614647 // floating state for animation
13257
- MODIFIERS = modifiers;
13258
- modifiers &= ~1024;
14648
+ MODIFIERS = modifiersex;
14649
+ modifiersex &= ~1024;
1325914650 if (false) // modifiers != 0)
1326014651 {
1326114652 //new Exception().printStackTrace();
13262
- System.out.println("mouseDragged: " + modifiers);
14653
+ System.out.println("mouseDragged: " + modifiersex);
1326314654 System.out.println("SHIFT = " + SHIFT);
1326414655 System.out.println("CONTROL = " + COMMAND);
1326514656 System.out.println("META = " + META);
....@@ -13272,14 +14663,16 @@
1327214663 if (editObj)
1327314664 {
1327414665 drag = true;
13275
- ClickInfo info = new ClickInfo();
13276
- info.bounds.setBounds(0, 0,
14666
+ //ClickInfo info = new ClickInfo();
14667
+ object.clickInfo.bounds.setBounds(0, 0,
1327714668 (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13278
- info.pane = this;
13279
- info.camera = renderCamera;
13280
- info.x = x;
13281
- info.y = y;
13282
- object.editWindow.copy.doEditDrag(info);
14669
+ object.clickInfo.pane = this;
14670
+ object.clickInfo.camera = renderCamera;
14671
+ object.clickInfo.x = x;
14672
+ object.clickInfo.y = y;
14673
+ object //.GetWindow().copy
14674
+ .doEditDrag(//info,
14675
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1328314676 } else
1328414677 {
1328514678 if (x < startX)
....@@ -13428,23 +14821,27 @@
1342814821 }
1342914822 }
1343014823
14824
+// ClickInfo clickInfo = new ClickInfo();
14825
+
1343114826 public void mouseMoved(MouseEvent e)
1343214827 {
1343314828 //System.out.println("mouseMoved: " + e);
13434
-
1343514829 if (isRenderer)
1343614830 return;
1343714831
13438
- ClickInfo ci = new ClickInfo();
13439
- ci.x = e.getX();
13440
- ci.y = e.getY();
13441
- ci.modifiers = e.getModifiersEx();
13442
- ci.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
13443
- ci.pane = this;
13444
- ci.camera = renderCamera;
14832
+ // Mouse cursor feedback
14833
+ object.clickInfo.x = e.getX();
14834
+ object.clickInfo.y = e.getY();
14835
+ object.clickInfo.modifiers = e.getModifiersEx();
14836
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14837
+ object.clickInfo.pane = this;
14838
+ object.clickInfo.camera = renderCamera;
1344514839 if (!isRenderer)
1344614840 {
13447
- if (object.editWindow.copy.doEditClick(ci, 0))
14841
+ //ObjEditor editWindow = object.editWindow;
14842
+ //Object3D copy = editWindow.copy;
14843
+ if (object.doEditClick(//clickInfo,
14844
+ 0))
1344814845 {
1344914846 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1345014847 } else
....@@ -13456,7 +14853,11 @@
1345614853
1345714854 public void mouseReleased(MouseEvent e)
1345814855 {
14856
+ Globals.MOUSEDRAGGED = false;
14857
+
1345914858 movingcamera = false;
14859
+ X = 0; // getBounds().width/2;
14860
+ Y = 0; // getBounds().height/2;
1346014861 //System.out.println("mouseReleased: " + e);
1346114862 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1346214863 }
....@@ -13479,9 +14880,9 @@
1347914880 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1348014881 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1348114882
13482
- if (control || command || IsFrozen())
14883
+// No delay if (control || command || IsFrozen())
1348314884 timeout = true;
13484
- else
14885
+// ?? May 2019 else
1348514886 // timer.setDelay((modifiers & 128) != 0?0:350);
1348614887 mouseDown = false;
1348714888 if (!control && !command) // june 2013
....@@ -13591,7 +14992,7 @@
1359114992 System.out.println("keyReleased: " + e);
1359214993 }
1359314994
13594
- void SetMouseMode(int modifiers)
14995
+ void SetMouseMode(int modifiers, int modifiersex)
1359514996 {
1359614997 //System.out.println("SetMouseMode = " + modifiers);
1359714998 //modifiers &= ~1024;
....@@ -13603,25 +15004,25 @@
1360315004 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1360415005 // return;
1360515006 //System.out.println("SetMode = " + modifiers);
13606
- if ((modifiers & WHEEL) == WHEEL)
15007
+ if ((modifiersex & WHEEL) == WHEEL)
1360715008 {
1360815009 mouseMode |= ZOOM;
1360915010 }
1361015011
1361115012 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
13612
- if (capsLocked || (modifiers & META) == META)
15013
+ if (capsLocked) // || (modifiers & META) == META)
1361315014 {
1361415015 mouseMode |= VR; // BACKFORTH;
1361515016 }
13616
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15017
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1361715018 {
1361815019 mouseMode |= SELECT;
1361915020 }
13620
- if ((modifiers & COMMAND) == COMMAND)
15021
+ if ((modifiersex & COMMAND) == COMMAND)
1362115022 {
1362215023 mouseMode |= SELECT;
1362315024 }
13624
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15025
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1362515026 {
1362615027 mouseMode &= ~VR;
1362715028 mouseMode |= TRANSLATE;
....@@ -13650,10 +15051,10 @@
1365015051
1365115052 if (isRenderer) //
1365215053 {
13653
- SetMouseMode(modifiers);
15054
+ SetMouseMode(0, modifiers);
1365415055 }
1365515056
13656
- theRenderer.keyPressed(key);
15057
+ Globals.theRenderer.keyPressed(key);
1365715058 }
1365815059
1365915060 int kompactbit = 4; // power bit
....@@ -13665,7 +15066,7 @@
1366515066 float SATPOW = 1; // 2; // 0.5f;
1366615067 float BRIPOW = 1; // 0.5f; // 0.5f;
1366715068
13668
- void keyPressed(int key)
15069
+ public void keyPressed(int key)
1366915070 {
1367015071 if (key >= '0' && key <= '5')
1367115072 clampbit = (key-'0');
....@@ -13712,7 +15113,8 @@
1371215113 // break;
1371315114 case 'T':
1371415115 CACHETEXTURE ^= true;
13715
- textures.clear();
15116
+ texturepigment.clear();
15117
+ texturebump.clear();
1371615118 // repaint();
1371715119 break;
1371815120 case 'Y':
....@@ -13797,7 +15199,9 @@
1379715199 case 'E' : COMPACT ^= true;
1379815200 repaint();
1379915201 break;
13800
- case 'W' : DEBUGHSB ^= true;
15202
+ case 'W' : // Wide Window (fullscreen)
15203
+ //DEBUGHSB ^= true;
15204
+ ObjEditor.theFrame.ToggleFullScreen();
1380115205 repaint();
1380215206 break;
1380315207 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13822,8 +15226,8 @@
1382215226 RevertCamera();
1382315227 repaint();
1382415228 break;
13825
- case 'L':
1382615229 case 'l':
15230
+ //case 'L':
1382715231 if (lightMode)
1382815232 {
1382915233 lightMode = false;
....@@ -13966,9 +15370,9 @@
1396615370 case '_':
1396715371 kompactbit = 5;
1396815372 break;
13969
- case '+':
13970
- kompactbit = 6;
13971
- break;
15373
+// case '+':
15374
+// kompactbit = 6;
15375
+// break;
1397215376 case ' ':
1397315377 lightMode ^= true;
1397415378 Globals.lighttouched = true;
....@@ -13980,13 +15384,14 @@
1398015384 case ESC:
1398115385 RENDERPROGRAM += 1;
1398215386 RENDERPROGRAM %= 3;
15387
+
1398315388 repaint();
1398415389 break;
1398515390 case 'Z':
1398615391 //RESIZETEXTURE ^= true;
1398715392 //break;
1398815393 case 'z':
13989
- RENDERSHADOW ^= true;
15394
+ Globals.RENDERSHADOW ^= true;
1399015395 Globals.lighttouched = true;
1399115396 repaint();
1399215397 break;
....@@ -14019,8 +15424,9 @@
1401915424 case DELETE:
1402015425 ClearSelection();
1402115426 break;
14022
- /*
1402315427 case '+':
15428
+
15429
+ /*
1402415430 //fontsize += 1;
1402515431 bbzoom *= 2;
1402615432 repaint();
....@@ -14037,17 +15443,17 @@
1403715443 case '=':
1403815444 IncDepth();
1403915445 //fontsize += 1;
14040
- object.editWindow.refreshContents(true);
15446
+ object.GetWindow().refreshContents(true);
1404115447 maskbit = 6;
1404215448 break;
1404315449 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1404415450 DecDepth();
1404515451 maskbit = 5;
1404615452 //if(fontsize > 1) fontsize -= 1;
14047
- if (object.editWindow == null)
14048
- new Exception().printStackTrace();
14049
- else
14050
- object.editWindow.refreshContents(true);
15453
+// if (object.editWindow == null)
15454
+// new Exception().printStackTrace();
15455
+// else
15456
+ object.GetWindow().refreshContents(true);
1405115457 break;
1405215458 case '{':
1405315459 manipCamera.shaper_fovy /= 1.1;
....@@ -14102,6 +15508,7 @@
1410215508 }
1410315509 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1410415510 }
15511
+
1410515512 static double OCCLUSIONBOOST = 1; // 0.5;
1410615513
1410715514 void keyReleased(int key, int modifiers)
....@@ -14109,11 +15516,11 @@
1410915516 //mode = ROTATE;
1411015517 if ((MODIFIERS & COMMAND) == 0) // VR??
1411115518 {
14112
- SetMouseMode(modifiers);
15519
+ SetMouseMode(0, modifiers);
1411315520 }
1411415521 }
1411515522
14116
- protected void processKeyEvent(KeyEvent e)
15523
+ public void processKeyEvent(KeyEvent e)
1411715524 {
1411815525 switch (e.getID())
1411915526 {
....@@ -14243,8 +15650,9 @@
1424315650
1424415651 protected void processMouseMotionEvent(MouseEvent e)
1424515652 {
14246
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14247
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15653
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15654
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15655
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1424815656 {
1424915657 mouseMoved(e);
1425015658 } else
....@@ -14269,11 +15677,12 @@
1426915677 }
1427015678 */
1427115679
14272
- object.editWindow.EditSelection();
15680
+ object.GetWindow().EditSelection(false);
1427315681 }
1427415682
1427515683 void SelectParent()
1427615684 {
15685
+ new Exception().printStackTrace();
1427715686 System.exit(0);
1427815687 Composite group = (Composite) object;
1427915688 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14285,10 +15694,10 @@
1428515694 {
1428615695 //selectees.remove(i);
1428715696 System.out.println("select parent of " + elem);
14288
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15697
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1428915698 } else
1429015699 {
14291
- group.editWindow.Select(elem.GetTreePath(), first, true);
15700
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1429215701 }
1429315702
1429415703 first = false;
....@@ -14297,6 +15706,7 @@
1429715706
1429815707 void SelectChildren()
1429915708 {
15709
+ new Exception().printStackTrace();
1430015710 System.exit(0);
1430115711 /*
1430215712 Composite group = (Composite) object;
....@@ -14329,12 +15739,12 @@
1432915739 for (int j = 0; j < group.children.size(); j++)
1433015740 {
1433115741 elem = (Object3D) group.children.elementAt(j);
14332
- object.editWindow.Select(elem.GetTreePath(), first, true);
15742
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1433315743 first = false;
1433415744 }
1433515745 } else
1433615746 {
14337
- object.editWindow.Select(elem.GetTreePath(), first, true);
15747
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1433815748 }
1433915749
1434015750 first = false;
....@@ -14345,21 +15755,21 @@
1434515755 {
1434615756 //Composite group = (Composite) object;
1434715757 Object3D group = object;
14348
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15758
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1434915759 }
1435015760
1435115761 void ResetTransform(int mask)
1435215762 {
1435315763 //Composite group = (Composite) object;
1435415764 Object3D group = object;
14355
- group.editWindow.ResetTransform(mask);
15765
+ group.GetWindow().ResetTransform(mask);
1435615766 }
1435715767
1435815768 void FlipTransform()
1435915769 {
1436015770 //Composite group = (Composite) object;
1436115771 Object3D group = object;
14362
- group.editWindow.FlipTransform();
15772
+ group.GetWindow().FlipTransform();
1436315773 // group.editWindow.ReduceMesh(true);
1436415774 }
1436515775
....@@ -14367,7 +15777,7 @@
1436715777 {
1436815778 //Composite group = (Composite) object;
1436915779 Object3D group = object;
14370
- group.editWindow.PrintMemory();
15780
+ group.GetWindow().PrintMemory();
1437115781 // group.editWindow.ReduceMesh(true);
1437215782 }
1437315783
....@@ -14375,7 +15785,7 @@
1437515785 {
1437615786 //Composite group = (Composite) object;
1437715787 Object3D group = object;
14378
- group.editWindow.ResetCentroid();
15788
+ group.GetWindow().ResetCentroid();
1437915789 }
1438015790
1438115791 void IncDepth()
....@@ -14457,11 +15867,11 @@
1445715867
1445815868 int width = getBounds().width;
1445915869 int height = getBounds().height;
14460
- ClickInfo info = new ClickInfo();
14461
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1446215870 //Image img = CreateImage(width, height);
1446315871 //System.out.println("width = " + width + "; height = " + height + "\n");
15872
+
1446415873 Graphics gr = g; // img.getGraphics();
15874
+
1446515875 if (!hasMarquee)
1446615876 {
1446715877 if (Xmin < Xmax) // !locked)
....@@ -14533,40 +15943,88 @@
1453315943 }
1453415944 if (object != null && !hasMarquee)
1453515945 {
15946
+ if (object.clickInfo == null)
15947
+ object.clickInfo = new ClickInfo();
15948
+ ClickInfo info = object.clickInfo;
15949
+ //ClickInfo info = new ClickInfo();
15950
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
15951
+
1453615952 if (isRenderer)
1453715953 {
14538
- info.flags++;
15954
+ object.clickInfo.flags++;
1453915955 double frameAspect = (double) width / (double) height;
1454015956 if (frameAspect > renderCamera.aspect)
1454115957 {
1454215958 int desired = (int) ((double) height * renderCamera.aspect);
14543
- info.bounds.width -= width - desired;
14544
- info.bounds.x += (width - desired) / 2;
15959
+ object.clickInfo.bounds.width -= width - desired;
15960
+ object.clickInfo.bounds.x += (width - desired) / 2;
1454515961 } else
1454615962 {
1454715963 int desired = (int) ((double) width / renderCamera.aspect);
14548
- info.bounds.height -= height - desired;
14549
- info.bounds.y += (height - desired) / 2;
15964
+ object.clickInfo.bounds.height -= height - desired;
15965
+ object.clickInfo.bounds.y += (height - desired) / 2;
1455015966 }
1455115967 }
14552
- info.g = gr;
14553
- info.camera = renderCamera;
15968
+
15969
+ object.clickInfo.g = gr;
15970
+ object.clickInfo.camera = renderCamera;
1455415971 /*
1455515972 // Memory intensive (brep.verticescopy)
1455615973 if (!(object instanceof Composite))
1455715974 object.draw(info, 0, false); // SLOW :
1455815975 */
14559
- if (!isRenderer)
15976
+ if (!isRenderer) // && drag)
1456015977 {
14561
- object.drawEditHandles(info, 0);
15978
+ Grafreed.Assert(object != null);
15979
+ Grafreed.Assert(object.selection != null);
15980
+ if (object.selection.Size() > 0)
15981
+ {
15982
+ int hitSomething = object.selection.get(0).hitSomething;
15983
+
15984
+ object.clickInfo.DX = 0;
15985
+ object.clickInfo.DY = 0;
15986
+ object.clickInfo.W = 1;
15987
+ if (hitSomething == Object3D.hitCenter)
15988
+ {
15989
+ info.DX = X;
15990
+ if (X != 0)
15991
+ info.DX -= info.bounds.width/2;
15992
+
15993
+ info.DY = Y;
15994
+ if (Y != 0)
15995
+ info.DY -= info.bounds.height/2;
15996
+ }
15997
+
15998
+ object.drawEditHandles(//info,
15999
+ 0);
16000
+
16001
+ if (drag && (X != 0 || Y != 0))
16002
+ {
16003
+ switch (hitSomething)
16004
+ {
16005
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16006
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16007
+ break;
16008
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16009
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16010
+ break;
16011
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16012
+ gr.drawLine(X, Y, 0, 0);
16013
+ break;
16014
+ }
16015
+
16016
+ }
16017
+ }
1456216018 }
1456316019 }
16020
+
1456416021 if (isRenderer)
1456516022 {
1456616023 //gr.setColor(Color.black);
1456716024 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1456816025 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1456916026 }
16027
+
1457016028 if (hasMarquee)
1457116029 {
1457216030 gr.setXORMode(Color.white);
....@@ -14679,6 +16137,7 @@
1467916137 public boolean mouseDown(Event evt, int x, int y)
1468016138 {
1468116139 System.out.println("mouseDown: " + evt);
16140
+ System.exit(0);
1468216141 /*
1468316142 locked = true;
1468416143 drag = false;
....@@ -14722,7 +16181,7 @@
1472216181 {
1472316182 keyPressed(0, modifiers);
1472416183 }
14725
- clickStart(x, y, modifiers);
16184
+ // clickStart(x, y, modifiers);
1472616185 return true;
1472716186 }
1472816187
....@@ -14840,7 +16299,7 @@
1484016299 {
1484116300 keyReleased(0, 0);
1484216301 }
14843
- drag(x, y, modifiers);
16302
+ drag(x, y, 0, modifiers);
1484416303 return true;
1484516304 }
1484616305
....@@ -14972,7 +16431,7 @@
1497216431 Object3D object;
1497316432 static Object3D trackedobject;
1497416433 Camera renderCamera; // Light or Eye (or Occlusion)
14975
- /*static*/ Camera manipCamera; // Light or Eye
16434
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1497616435 /*static*/ Camera eyeCamera;
1497716436 /*static*/ Camera lightCamera;
1497816437 int cameracount;
....@@ -15257,16 +16716,16 @@
1525716716 cStatic.objectstack[materialdepth++] = checker;
1525816717 //System.out.println("material " + material);
1525916718 //Applet3D.tracein(this, selected);
15260
- vector2buffer = checker.projectedVertices;
16719
+ //vector2buffer = checker.projectedVertices;
1526116720
1526216721 //checker.GetMaterial().Draw(this, false); // true);
15263
- DrawMaterial(checker.GetMaterial(), false); // true);
16722
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1526416723
1526516724 materialdepth -= 1;
1526616725 if (materialdepth > 0)
1526716726 {
15268
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15269
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16727
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16728
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1527016729 }
1527116730 //checker.GetMaterial().opacity = 1f;
1527216731 ////checker.GetMaterial().ambient = 1f;
....@@ -15352,6 +16811,14 @@
1535216811 }
1535316812 }
1535416813
16814
+ private Object3D GetFolder()
16815
+ {
16816
+ Object3D folder = object.GetWindow().copy;
16817
+ if (object.GetWindow().copy.selection.Size() > 0)
16818
+ folder = object.GetWindow().copy.selection.elementAt(0);
16819
+ return folder;
16820
+ }
16821
+
1535516822 class SelectBuffer implements GLEventListener
1535616823 {
1535716824
....@@ -15410,6 +16877,7 @@
1541016877 {
1541116878 if (!selection)
1541216879 {
16880
+ new Exception().printStackTrace();
1541316881 System.exit(0);
1541416882 return;
1541516883 }
....@@ -15430,6 +16898,17 @@
1543016898
1543116899 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1543216900
16901
+ if (PAINTMODE)
16902
+ {
16903
+ if (object.GetWindow().copy.selection.Size() > 0)
16904
+ {
16905
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16906
+
16907
+ // Make what you paint not selectable.
16908
+ paintobj.ResetSelectable();
16909
+ }
16910
+ }
16911
+
1543316912 //int tmp = selection_view;
1543416913 //selection_view = -1;
1543516914 int temp = DrawMode();
....@@ -15441,6 +16920,17 @@
1544116920 // temp = DEFAULT; // patch for selection debug
1544216921 Globals.drawMode = temp; // WARNING
1544316922
16923
+ if (PAINTMODE)
16924
+ {
16925
+ if (object.GetWindow().copy.selection.Size() > 0)
16926
+ {
16927
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
16928
+
16929
+ // Revert.
16930
+ paintobj.RestoreSelectable();
16931
+ }
16932
+ }
16933
+
1544416934 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1544516935
1544616936 // trying different ways of getting the depth info over
....@@ -15488,6 +16978,8 @@
1548816978 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1548916979 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1549016980 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
16981
+
16982
+ CreateSelectedPoint();
1549116983
1549216984 // Will fit the mesh !!!
1549316985 selectedpoint.toParent[0][0] = 0.0001;
....@@ -15537,34 +17029,36 @@
1553717029 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]));
1553817030 }
1553917031
15540
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17032
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1554117033 }
1554217034 }
1554317035
1554417036 if (!movingcamera && !PAINTMODE)
15545
- object.editWindow.ScreenFitPoint(); // fev 2014
17037
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1554617038
15547
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17039
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1554817040 {
15549
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17041
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1555017042
15551
- Object3D group = new Object3D("inst" + paintcount++);
17043
+ if (object.GetWindow().copy.selection.Size() > 0)
17044
+ {
17045
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1555217046
15553
- group.CreateMaterial(); // use a void leaf to select instances
15554
-
15555
- group.add(paintobj); // link
15556
-
15557
- object.editWindow.SnapObject(group);
15558
-
15559
- Object3D folder = object.editWindow.copy;
15560
-
15561
- if (object.editWindow.copy.selection.Size() > 0)
15562
- folder = object.editWindow.copy.selection.elementAt(0);
15563
-
15564
- folder.add(group);
15565
-
15566
- object.editWindow.ResetModel();
15567
- object.editWindow.refreshContents();
17047
+ Object3D inst = new Object3D("inst" + paintcount++);
17048
+
17049
+ inst.CreateMaterial(); // use a void leaf to select instances
17050
+
17051
+ inst.add(paintobj); // link
17052
+
17053
+ object.GetWindow().SnapObject(inst);
17054
+
17055
+ Object3D folder = paintFolder; // GetFolder();
17056
+
17057
+ folder.add(inst);
17058
+
17059
+ object.GetWindow().ResetModel();
17060
+ object.GetWindow().refreshContents();
17061
+ }
1556817062 }
1556917063 else
1557017064 paintcount = 0;
....@@ -15603,6 +17097,11 @@
1560317097 //System.out.println("objects[color] = " + objects[color]);
1560417098 //objects[color].Select();
1560517099 indexcount = 0;
17100
+ ObjEditor window = object.GetWindow();
17101
+ if (window != null && deselect)
17102
+ {
17103
+ window.Select(null, deselect, true);
17104
+ }
1560617105 object.Select(color, deselect);
1560717106 }
1560817107
....@@ -15702,7 +17201,7 @@
1570217201 gl.glDisable(gl.GL_CULL_FACE);
1570317202 }
1570417203
15705
- if (!RENDERSHADOW)
17204
+ if (!Globals.RENDERSHADOW)
1570617205 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1570717206
1570817207 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -15712,7 +17211,7 @@
1571217211 //gl.glColorMask(false, false, false, false);
1571317212
1571417213 //render_scene_from_light_view(gl, drawable, 0, 0);
15715
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17214
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1571617215 {
1571717216 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1571817217
....@@ -15772,7 +17271,6 @@
1577217271
1577317272 class AntialiasBuffer implements GLEventListener
1577417273 {
15775
-
1577617274 CameraPane parent = null;
1577717275
1577817276 AntialiasBuffer(CameraPane p)
....@@ -16129,23 +17627,15 @@
1612917627 int AAbuffersize = 0;
1613017628
1613117629 //double[] selectedpoint = new double[3];
16132
- static Superellipsoid selectedpoint = new Superellipsoid();
17630
+ static Superellipsoid selectedpoint;
1613317631 static Sphere previousselectedpoint = null;
16134
- static Sphere debugpointG = new Sphere();
16135
- static Sphere debugpointP = new Sphere();
16136
- static Sphere debugpointC = new Sphere();
16137
- static Sphere debugpointR = new Sphere();
17632
+ static Sphere debugpointG;
17633
+ static Sphere debugpointP;
17634
+ static Sphere debugpointC;
17635
+ static Sphere debugpointR;
1613817636
1613917637 static Sphere debugpoints[] = new Sphere[8];
1614017638
16141
- static
16142
- {
16143
- for (int i=0; i<8; i++)
16144
- {
16145
- debugpoints[i] = new Sphere();
16146
- }
16147
- }
16148
-
1614917639 static void InitPoints(float radius)
1615017640 {
1615117641 for (int i=0; i<8; i++)
....@@ -16165,7 +17655,7 @@
1616517655 }
1616617656 }
1616717657
16168
- static void DrawPoints(CameraPane cpane)
17658
+ static void DrawPoints(iCameraPane cpane)
1616917659 {
1617017660 for (int i=0; i<8; i++) // first and last are red
1617117661 {
....@@ -16197,10 +17687,11 @@
1619717687 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1619817688 // Depth buffer format
1619917689 //private int depth_format;
16200
- static public void NextIndex(Object3D o, GL gl)
17690
+
17691
+ public void NextIndex()
1620117692 {
1620217693 indexcount+=16;
16203
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17694
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1620417695 //objects[indexcount] = o;
1620517696 //System.out.println("indexcount = " + indexcount);
1620617697 }