Normand Briere
2019-08-12 8f1afe25ea8fc8801aab66331c32a50859a758c2
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,25 @@
149185 defaultcaps.setAccumBlueBits(16);
150186 defaultcaps.setAccumAlphaBits(16);
151187 }
152
- static CameraPane theRenderer;
188
+
189
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
153190
191
+ public void LoadSkybox(String name, String ext, boolean mipmap) throws GLException
192
+ {
193
+ try
194
+ {
195
+ cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
196
+ } catch (IOException e)
197
+ {
198
+ System.out.println("NAME = " + name);
199
+ e.printStackTrace(); // throw new RuntimeException(e);
200
+ }
201
+ }
202
+
154203 void SetAsGLRenderer(boolean b)
155204 {
156205 isRenderer = b;
157
- theRenderer = this;
206
+ Globals.theRenderer = this;
158207 }
159208
160209 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -169,7 +218,8 @@
169218
170219 SetCamera(cam);
171220
172
- SetLight(new Camera(new cVector(10, 10, -20)));
221
+ // Warning: not used.
222
+ SetLight(new Camera(new cVector(15, 10, -20)));
173223
174224 object = o;
175225
....@@ -191,6 +241,45 @@
191241 }
192242
193243 /// INTERFACE
244
+
245
+ public javax.media.opengl.GL GetGL0()
246
+ {
247
+ return null;
248
+ }
249
+
250
+ public int GenList()
251
+ {
252
+ javax.media.opengl.GL gl = GetGL();
253
+ return gl.glGenLists(1);
254
+ }
255
+
256
+ public void NewList(int id)
257
+ {
258
+ javax.media.opengl.GL gl = GetGL();
259
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
260
+ }
261
+
262
+ public void CallList(int id)
263
+ {
264
+ javax.media.opengl.GL gl = GetGL();
265
+ gl.glCallList(id);
266
+ }
267
+
268
+ public void EndList()
269
+ {
270
+ javax.media.opengl.GL gl = GetGL();
271
+ gl.glEndList();
272
+ }
273
+
274
+ public boolean IsBoxMode()
275
+ {
276
+ return BOXMODE;
277
+ }
278
+
279
+ public boolean IsZoomBoxMode()
280
+ {
281
+ return ZOOMBOXMODE;
282
+ }
194283
195284 public void ClearDepth()
196285 {
....@@ -231,9 +320,14 @@
231320 return this.ambientOcclusion;
232321 }
233322
323
+ public boolean IsDebugSelection()
324
+ {
325
+ return DEBUG_SELECTION;
326
+ }
327
+
234328 public boolean IsFrozen()
235329 {
236
- boolean selectmode = this.DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
330
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
237331
238332 return !selectmode && cameracount == 0; // != 0;
239333 }
....@@ -254,9 +348,19 @@
254348 return lightCamera;
255349 }
256350
351
+ public Camera ManipCamera()
352
+ {
353
+ return manipCamera;
354
+ }
355
+
257356 public Camera RenderCamera()
258357 {
259358 return renderCamera;
359
+ }
360
+
361
+ public Camera[] Cameras()
362
+ {
363
+ return cameras;
260364 }
261365
262366 public void PushMaterial(Object3D obj, boolean selected)
....@@ -272,7 +376,7 @@
272376 cStatic.objectstack[materialdepth++] = obj;
273377 //System.out.println("material " + material);
274378 //Applet3D.tracein(this, selected);
275
- display.vector2buffer = obj.projectedVertices;
379
+ //display.vector2buffer = obj.projectedVertices;
276380 if (obj instanceof Camera)
277381 {
278382 display.options1[0] = material.shift;
....@@ -281,14 +385,28 @@
281385 display.options1[2] = material.shadowbias;
282386 display.options1[3] = material.aniso;
283387 display.options1[4] = material.anisoV;
388
+// System.out.println("display.options1[0] " + display.options1[0]);
389
+// System.out.println("display.options1[1] " + display.options1[1]);
390
+// System.out.println("display.options1[2] " + display.options1[2]);
391
+// System.out.println("display.options1[3] " + display.options1[3]);
392
+// System.out.println("display.options1[4] " + display.options1[4]);
284393 display.options2[0] = material.opacity;
285394 display.options2[1] = material.diffuse;
286395 display.options2[2] = material.factor;
396
+// System.out.println("display.options2[0] " + display.options2[0]);
397
+// System.out.println("display.options2[1] " + display.options2[1]);
398
+// System.out.println("display.options2[2] " + display.options2[2]);
287399
288400 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
401
+// System.out.println("display.options3[0] " + display.options3[0]);
402
+// System.out.println("display.options3[1] " + display.options3[1]);
403
+// System.out.println("display.options3[2] " + display.options3[2]);
289404 display.options4[0] = material.cameralight/0.2f;
290405 display.options4[1] = material.subsurface;
291406 display.options4[2] = material.sheen;
407
+// System.out.println("display.options4[0] " + display.options4[0]);
408
+// System.out.println("display.options4[1] " + display.options4[1]);
409
+// System.out.println("display.options4[2] " + display.options4[2]);
292410
293411 // if (display.CURRENTANTIALIAS > 0)
294412 // display.options3[3] /= 4;
....@@ -304,7 +422,7 @@
304422 /**/
305423 } else
306424 {
307
- DrawMaterial(material, selected);
425
+ DrawMaterial(material, selected, obj.projectedVertices);
308426 }
309427 } else
310428 {
....@@ -328,8 +446,8 @@
328446 cStatic.objectstack[materialdepth++] = obj;
329447 //System.out.println("material " + material);
330448 //Applet3D.tracein("selected ", selected);
331
- display.vector2buffer = obj.projectedVertices;
332
- display.DrawMaterial(material, selected);
449
+ //display.vector2buffer = obj.projectedVertices;
450
+ display.DrawMaterial(material, selected, obj.projectedVertices);
333451 }
334452 }
335453
....@@ -346,8 +464,8 @@
346464 materialdepth -= 1;
347465 if (materialdepth > 0)
348466 {
349
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
350
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
467
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
468
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
351469 }
352470 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
353471 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -367,8 +485,8 @@
367485 materialdepth -= 1;
368486 if (materialdepth > 0)
369487 {
370
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
371
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
488
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
489
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
372490 }
373491 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
374492 //else
....@@ -403,16 +521,18 @@
403521
404522 javax.media.opengl.GL gl = display.GetGL();
405523
406
- boolean selectmode = display.DrawMode() == display.SELECTION || CameraPane.DEBUG_SELECTION;
524
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
407525
408526 //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
409527 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
410528 {
411529 //gl.glBegin(gl.GL_TRIANGLES);
412
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
530
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
531
+ // TEST LIVE NORMALS && !obj.dontselect
532
+ ;
413533 if (!hasnorm)
414534 {
415
- // System.out.println("FUCK!!");
535
+ // System.out.println("Mesh normal");
416536 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
417537 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
418538 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -566,8 +686,819 @@
566686 }
567687 }
568688
689
+ /**
690
+ * <code>draw</code> renders a <code>TriMesh</code> object including
691
+ * it's normals, colors, textures and vertices.
692
+ *
693
+ * @see Renderer#draw(TriMesh)
694
+ * @param tris
695
+ * the mesh to render.
696
+ */
697
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
698
+ {
699
+ CameraPane display = this;
700
+
701
+ float r = display.modelParams0[0];
702
+ float g = display.modelParams0[1];
703
+ float b = display.modelParams0[2];
704
+ float opacity = display.modelParams5[1];
705
+
706
+ //final GL gl = GLU.getCurrentGL();
707
+ GL gl = display.GetGL(); // getGL();
708
+
709
+ FloatBuffer vertBuf = geo.vertBuf;
710
+
711
+ int v = vertBuf.capacity();
712
+
713
+ int count = 0;
714
+
715
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
716
+ gl.glEnable(gl.GL_CULL_FACE);
717
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
718
+ for (int i=0; i<v/3; i++)
719
+ {
720
+ int index3 = i*3;
721
+
722
+ if (geo.sizeBuf.get(index3+1) == 0)
723
+ continue;
724
+
725
+ count++;
726
+
727
+ int index4 = i*4;
728
+
729
+ float tx = vertBuf.get(index3);
730
+ float ty = vertBuf.get(index3+1);
731
+ float tz = vertBuf.get(index3+2);
732
+
733
+ // if (tx == 0 && ty == 0 && tz == 0)
734
+ // continue;
735
+
736
+ gl.glMatrixMode(gl.GL_TEXTURE);
737
+ gl.glPushMatrix();
738
+
739
+ float[] texmat = geo.texmat;
740
+ texmat[12] = texmat[13] = texmat[14] = i;
741
+
742
+ gl.glMultMatrixf(texmat, 0);
743
+
744
+ gl.glMatrixMode(gl.GL_MODELVIEW);
745
+ gl.glPushMatrix();
746
+
747
+ gl.glTranslatef(tx,ty,tz);
748
+
749
+ if (rotate)
750
+ gl.glRotatef(i, 0, 1, 0);
751
+
752
+ float size = geo.sizeBuf.get(index3) / 100;
753
+ gl.glScalef(size,size,size);
754
+
755
+ float cr = geo.colorBuf.get(index4);
756
+ float cg = geo.colorBuf.get(index4+1);
757
+ float cb = geo.colorBuf.get(index4+2);
758
+ float ca = geo.colorBuf.get(index4+3);
759
+
760
+ display.modelParams0[0] = r * cr;
761
+ display.modelParams0[1] = g * cg;
762
+ display.modelParams0[2] = b * cb;
763
+
764
+ display.modelParams5[1] = opacity * ca;
765
+
766
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
767
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
768
+
769
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
770
+ RandomNode.globalseed2 = RandomNode.globalseed;
771
+
772
+// gl.glColor4f(cr,cg,cb,ca);
773
+ // gl.glScalef(1024/16,1024/16,1024/16);
774
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
775
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
776
+ //gl.glTranslatef(-tx,-ty,-tz);
777
+ gl.glPopMatrix();
778
+
779
+ gl.glMatrixMode(gl.GL_TEXTURE);
780
+ gl.glPopMatrix();
781
+ }
782
+ // gl.glScalef(1024,1024,1024);
783
+ if (!cf)
784
+ gl.glDisable(gl.GL_CULL_FACE);
785
+
786
+ display.modelParams0[0] = r;
787
+ display.modelParams0[1] = g;
788
+ display.modelParams0[2] = b;
789
+
790
+ display.modelParams5[1] = opacity;
791
+
792
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
793
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
794
+
795
+ gl.glMatrixMode(gl.GL_MODELVIEW);
796
+
797
+// System.err.println("total = " + v/3 + "; displayed = " + count);
798
+ if (true)
799
+ return;
800
+
801
+//// if (!tris.predraw(this))
802
+//// {
803
+//// return;
804
+//// }
805
+//// if (Debug.stats)
806
+//// {
807
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
808
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
809
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
810
+//// }
811
+////
812
+//// if (tris.getDisplayListID() != -1)
813
+//// {
814
+//// renderDisplayList(tris);
815
+//// return;
816
+//// }
817
+////
818
+//// if (!generatingDisplayList)
819
+//// {
820
+//// applyStates(tris.states, tris);
821
+//// }
822
+//// if (Debug.stats)
823
+//// {
824
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
825
+//// }
826
+//// boolean transformed = doTransforms(tris);
827
+//
828
+// int glMode = GL.GL_TRIANGLES;
829
+// switch (getMode())
830
+// {
831
+// case Triangles:
832
+// glMode = GL.GL_TRIANGLES;
833
+// break;
834
+// case Strip:
835
+// glMode = GL.GL_TRIANGLE_STRIP;
836
+// break;
837
+// case Fan:
838
+// glMode = GL.GL_TRIANGLE_FAN;
839
+// break;
840
+// }
841
+//
842
+// if (!predrawGeometry(gl))
843
+// {
844
+// // make sure only the necessary indices are sent through on old
845
+// // cards.
846
+// IntBuffer indices = this.getIndexBuffer();
847
+// if (indices == null)
848
+// {
849
+// logger.severe("missing indices on geometry object: " + this.toString());
850
+// } else
851
+// {
852
+// indices.rewind();
853
+// indices.limit(this.getMaxIndex());
854
+//
855
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
856
+//
857
+// indices.clear();
858
+// }
859
+// } else
860
+// {
861
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
862
+// GL.GL_UNSIGNED_INT, 0);
863
+// }
864
+//
865
+//// postdrawGeometry(tris);
866
+//// if (transformed)
867
+//// {
868
+//// undoTransforms(tris);
869
+//// }
870
+////
871
+//// if (Debug.stats)
872
+//// {
873
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
874
+//// }
875
+//// tris.postdraw(this);
876
+ }
877
+
878
+ static Camera localcamera = new Camera();
879
+ static cVector from = new cVector();
880
+ static cVector to = new cVector();
881
+
882
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
883
+ {
884
+ CameraPane cp = this;
885
+
886
+ Camera keep = cp.RenderCamera();
887
+ cp.renderCamera = localcamera;
888
+
889
+ if (br.trimmed)
890
+ {
891
+ float[] colors = new float[br.positions.length / 3];
892
+
893
+ int i3 = 0;
894
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
895
+ {
896
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
897
+ continue;
898
+
899
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
900
+ to.set(br.positions[i3] + br.normals[i3],
901
+ br.positions[i3 + 1] + br.normals[i3 + 1],
902
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
903
+ LA.xformPos(from, transform, from);
904
+ LA.xformPos(to, transform, to); // RIGID ONLY
905
+ localcamera.setAim(from, to);
906
+
907
+ CameraPane.occlusionbuffer.display();
908
+
909
+ if (CameraPane.DEBUG_OCCLUSION)
910
+ cp.display(); // debug
911
+
912
+ colors[i] = cp.vertexOcclusion.r;
913
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
914
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
915
+
916
+ if ((i % 100) == 0 && i != 0)
917
+ {
918
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
919
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
920
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
921
+ }
922
+ }
923
+
924
+ br.colors = colors;
925
+ }
926
+ else
927
+ {
928
+ for (int i = 0; i < br.VertexCount(); i++)
929
+ {
930
+ Vertex v = br.GetVertex(i);
931
+
932
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
933
+ continue;
934
+
935
+ from.set(v.x, v.y, v.z);
936
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
937
+ LA.xformPos(from, transform, from);
938
+ LA.xformPos(to, transform, to); // RIGID ONLY
939
+ localcamera.setAim(from, to);
940
+
941
+ CameraPane.occlusionbuffer.display();
942
+
943
+ if (CameraPane.DEBUG_OCCLUSION)
944
+ cp.display(); // debug
945
+
946
+ v.AO = cp.vertexOcclusion.r;
947
+
948
+ if ((i % 100) == 0 && i != 0)
949
+ {
950
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
951
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
952
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
953
+ }
954
+ }
955
+ }
956
+
957
+ //System.out.println("done.");
958
+
959
+ cp.renderCamera = keep;
960
+ }
961
+
962
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
963
+ {
964
+ CameraPane display = this;
965
+ pointFlow.CreateHT();
966
+
967
+ float r = display.modelParams0[0];
968
+ float g = display.modelParams0[1];
969
+ float b = display.modelParams0[2];
970
+ float opacity = display.modelParams5[1];
971
+
972
+ //final GL gl = GLU.getCurrentGL();
973
+ GL gl = display.GetGL(); // getGL();
974
+
975
+ int s = pointFlow.points.size();
976
+
977
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
978
+ gl.glEnable(gl.GL_CULL_FACE);
979
+
980
+ for (int i=s; --i>=0;)
981
+ //for (int i=0; i<s; i++)
982
+ {
983
+ cVector v = pointFlow.points.get(i);
984
+
985
+ double mindist = Double.MAX_VALUE;
986
+
987
+ double size = pointFlow.minimumSize;
988
+
989
+ double distancenext = 0;
990
+
991
+ if (i > 0)
992
+ {
993
+ cVector w = pointFlow.points.get(i-1);
994
+
995
+ double dist = w.distance(v);
996
+
997
+ distancenext = dist;
998
+
999
+ if (mindist > dist)
1000
+ {
1001
+ mindist = dist;
1002
+ size = mindist*pointFlow.resizefactor;
1003
+ }
1004
+ }
1005
+
1006
+ if (i < s-1)
1007
+ {
1008
+ cVector w = pointFlow.points.get(i+1);
1009
+
1010
+ double dist = w.distance(v);
1011
+
1012
+ if (mindist > dist)
1013
+ {
1014
+ mindist = dist;
1015
+ size = mindist*pointFlow.resizefactor;
1016
+ }
1017
+ }
1018
+
1019
+ if (size < pointFlow.minimumSize)
1020
+ size = pointFlow.minimumSize;
1021
+ if (size > pointFlow.maximumSize)
1022
+ size = pointFlow.maximumSize;
1023
+
1024
+ double tx = v.x;
1025
+ double ty = v.y;
1026
+ double tz = v.z;
1027
+
1028
+ // if (tx == 0 && ty == 0 && tz == 0)
1029
+ // continue;
1030
+
1031
+ gl.glMatrixMode(gl.GL_TEXTURE);
1032
+ gl.glPushMatrix();
1033
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1034
+
1035
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1036
+
1037
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1038
+ gl.glPushMatrix();
1039
+
1040
+ gl.glTranslated(tx,ty,tz);
1041
+
1042
+ gl.glScaled(size,size,size);
1043
+
1044
+// float cr = colorBuf.get(index4);
1045
+// float cg = colorBuf.get(index4+1);
1046
+// float cb = colorBuf.get(index4+2);
1047
+// float ca = colorBuf.get(index4+3);
1048
+//
1049
+// display.modelParams0[0] = r * cr;
1050
+// display.modelParams0[1] = g * cg;
1051
+// display.modelParams0[2] = b * cb;
1052
+//
1053
+// display.modelParams5[1] = opacity * ca;
1054
+//
1055
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1056
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1057
+//
1058
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1059
+// RandomNode.globalseed2 = RandomNode.globalseed;
1060
+//
1061
+//// gl.glColor4f(cr,cg,cb,ca);
1062
+// // gl.glScalef(1024/16,1024/16,1024/16);
1063
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1064
+
1065
+ gl.glPopMatrix();
1066
+
1067
+ double step = size/4; //
1068
+
1069
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1070
+ continue;
1071
+
1072
+ int nbsteps = (int)(distancenext/step);
1073
+
1074
+ step = distancenext/nbsteps;
1075
+
1076
+ cVector next = pointFlow.points.get(i-1);
1077
+
1078
+ tmp.set(next);
1079
+ tmp.sub(v);
1080
+ tmp.normalize();
1081
+ tmp.mul(step);
1082
+
1083
+ // calculate next size
1084
+ mindist = Double.MAX_VALUE;
1085
+
1086
+ double nextsize = pointFlow.minimumSize;
1087
+
1088
+ if (i > 1)
1089
+ {
1090
+ cVector w = pointFlow.points.get(i-2);
1091
+
1092
+ double dist = w.distance(next);
1093
+
1094
+ if (mindist > dist)
1095
+ {
1096
+ mindist = dist;
1097
+ nextsize = mindist*pointFlow.resizefactor;
1098
+ }
1099
+ }
1100
+
1101
+ double dist = v.distance(next);
1102
+
1103
+ if (mindist > dist)
1104
+ {
1105
+ mindist = dist;
1106
+ nextsize = mindist*pointFlow.resizefactor;
1107
+ }
1108
+
1109
+ if (nextsize < pointFlow.minimumSize)
1110
+ nextsize = pointFlow.minimumSize;
1111
+ if (nextsize > pointFlow.maximumSize)
1112
+ nextsize = pointFlow.maximumSize;
1113
+ //
1114
+
1115
+ double count = 0;
1116
+
1117
+ while (distancenext > 0.000000001) // step
1118
+ {
1119
+ gl.glPushMatrix();
1120
+
1121
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1122
+
1123
+ double K = count/nbsteps;
1124
+
1125
+ double intersize = K*nextsize + (1-K)*size;
1126
+
1127
+ gl.glScaled(intersize,intersize,intersize);
1128
+
1129
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1130
+
1131
+ count++;
1132
+
1133
+ distancenext -= step;
1134
+
1135
+ gl.glPopMatrix();
1136
+ }
1137
+
1138
+ if (count != nbsteps)
1139
+ assert(count == nbsteps);
1140
+
1141
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1142
+ //gl.glTranslatef(-tx,-ty,-tz);
1143
+
1144
+ gl.glMatrixMode(gl.GL_TEXTURE);
1145
+ gl.glPopMatrix();
1146
+ }
1147
+
1148
+ if (!cf)
1149
+ gl.glDisable(gl.GL_CULL_FACE);
1150
+
1151
+// display.modelParams0[0] = r;
1152
+// display.modelParams0[1] = g;
1153
+// display.modelParams0[2] = b;
1154
+//
1155
+// display.modelParams5[1] = opacity;
1156
+//
1157
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1158
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1159
+
1160
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1161
+ }
1162
+
1163
+ public void DrawBox(cVector min, cVector max)
1164
+ {
1165
+ javax.media.opengl.GL gl = GetGL();
1166
+ gl.glBegin(gl.GL_LINES);
1167
+
1168
+ gl.glVertex3d(min.x, min.y, min.z);
1169
+ gl.glVertex3d(min.x, min.y, max.z);
1170
+ gl.glVertex3d(min.x, min.y, min.z);
1171
+ gl.glVertex3d(min.x, max.y, min.z);
1172
+ gl.glVertex3d(min.x, min.y, min.z);
1173
+ gl.glVertex3d(max.x, min.y, min.z);
1174
+
1175
+ gl.glVertex3d(max.x, max.y, max.z);
1176
+ gl.glVertex3d(min.x, max.y, max.z);
1177
+ gl.glVertex3d(max.x, max.y, max.z);
1178
+ gl.glVertex3d(max.x, min.y, max.z);
1179
+ gl.glVertex3d(max.x, max.y, max.z);
1180
+ gl.glVertex3d(max.x, max.y, min.z);
1181
+
1182
+ gl.glEnd();
1183
+ }
1184
+
1185
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1186
+ {
1187
+ int[] strips = bRep.getRawIndices();
1188
+
1189
+ javax.media.opengl.GL gl = GetGL();
1190
+
1191
+ // TRIANGLE STRIP ARRAY
1192
+ if (bRep.trimmed)
1193
+ {
1194
+ float[] v = bRep.getRawVertices();
1195
+ float[] n = bRep.getRawNormals();
1196
+ float[] c = bRep.getRawColors();
1197
+ float[] uv = bRep.getRawUVMap();
1198
+
1199
+ int count2 = 0;
1200
+ int count3 = 0;
1201
+
1202
+ if (n.length > 0)
1203
+ {
1204
+ for (int i = 0; i < strips.length; i++)
1205
+ {
1206
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1207
+
1208
+ /*
1209
+ boolean locked = false;
1210
+ float eps = 0.1f;
1211
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1212
+
1213
+ int dot = 0;
1214
+
1215
+ if ((dot&1) == 0)
1216
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1217
+
1218
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1219
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1220
+ else
1221
+ {
1222
+ locked = true;
1223
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1224
+ }
1225
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1226
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1227
+ if (hasnorm)
1228
+ {
1229
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1230
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1231
+ }
1232
+
1233
+ if ((dot&4) == 0)
1234
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1235
+
1236
+ if (wrap || !locked && (dot&8) != 0)
1237
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1238
+ else
1239
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1240
+
1241
+ f.dot = dot;
1242
+ */
1243
+
1244
+ if (!selectmode)
1245
+ {
1246
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1247
+ {
1248
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1249
+ } else
1250
+ {
1251
+ gl.glNormal3f(0, 0, 1);
1252
+ }
1253
+
1254
+ if (c != null)
1255
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1256
+ {
1257
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1258
+ }
1259
+ }
1260
+
1261
+ if (flipV)
1262
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1263
+ else
1264
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1265
+
1266
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1267
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1268
+
1269
+ count2 += 2;
1270
+ count3 += 3;
1271
+ if (!selectmode)
1272
+ {
1273
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1274
+ {
1275
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1276
+ } else
1277
+ {
1278
+ gl.glNormal3f(0, 0, 1);
1279
+ }
1280
+ if (c != null)
1281
+ {
1282
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1283
+ }
1284
+ }
1285
+
1286
+ if (flipV)
1287
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1288
+ else
1289
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1290
+
1291
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1292
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1293
+
1294
+ count2 += 2;
1295
+ count3 += 3;
1296
+ for (int j = 0; j < strips[i] - 2; j++)
1297
+ {
1298
+ //gl.glTexCoord2d(...);
1299
+ if (!selectmode)
1300
+ {
1301
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1302
+ {
1303
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1304
+ } else
1305
+ {
1306
+ gl.glNormal3f(0, 0, 1);
1307
+ }
1308
+ if (c != null)
1309
+ {
1310
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1311
+ }
1312
+ }
1313
+
1314
+ if (flipV)
1315
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1316
+ else
1317
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1318
+
1319
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1320
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1321
+
1322
+ count2 += 2;
1323
+ count3 += 3;
1324
+ }
1325
+
1326
+ gl.glEnd();
1327
+ }
1328
+ }
1329
+
1330
+ assert count3 == v.length;
1331
+ }
1332
+ else // !trimmed
1333
+ {
1334
+ int count = 0;
1335
+ for (int i = 0; i < strips.length; i++)
1336
+ {
1337
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1338
+
1339
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1340
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1341
+
1342
+ drawVertex(gl, p, flipV, selectmode);
1343
+ drawVertex(gl, q, flipV, selectmode);
1344
+
1345
+ for (int j = 0; j < strips[i] - 2; j++)
1346
+ {
1347
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1348
+
1349
+ // if (j%2 == 0)
1350
+ // drawFace(p, q, r, display, null);
1351
+ // else
1352
+ // drawFace(p, r, q, display, null);
1353
+
1354
+ // p = q;
1355
+ // q = r;
1356
+ drawVertex(gl, r, flipV, selectmode);
1357
+ }
1358
+
1359
+ gl.glEnd();
1360
+ }
1361
+ }
1362
+ }
1363
+
1364
+ static cSpring.Point3D temp = new cSpring.Point3D();
1365
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1366
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1367
+
1368
+ public void DrawDynamicMesh(cMesh mesh)
1369
+ {
1370
+ GL gl = GetGL(); // getGL();
1371
+
1372
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1373
+
1374
+ gl.glDisable(gl.GL_LIGHTING);
1375
+
1376
+ gl.glLineWidth(1);
1377
+ gl.glColor3f(1,1,1);
1378
+ gl.glBegin(gl.GL_LINES);
1379
+ double scale = 0;
1380
+ int count = 0;
1381
+ for (int s=0; s<Phys.allSprings.size(); s++)
1382
+ {
1383
+ cSpring.Spring spring = Phys.allSprings.get(s);
1384
+ if(s == 0)
1385
+ {
1386
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1387
+ }
1388
+ if (mesh.showsprings)
1389
+ {
1390
+ temp.set(spring.a.position);
1391
+ temp.add(spring.b.position);
1392
+ temp.mul(0.5);
1393
+ temp2.set(spring.a.position);
1394
+ temp2.sub(spring.b.position);
1395
+ temp2.mul(spring.restLength/2);
1396
+ temp.sub(temp2);
1397
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1398
+ temp.add(temp2);
1399
+ temp.add(temp2);
1400
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1401
+ }
1402
+
1403
+ if (spring.isHandle)
1404
+ continue;
1405
+
1406
+ //if (scale < spring.restLength)
1407
+ scale += spring.restLength;
1408
+ count++;
1409
+ }
1410
+ gl.glEnd();
1411
+
1412
+ if (count == 0)
1413
+ scale = 0.01;
1414
+ else
1415
+ scale /= count * 3;
1416
+
1417
+ //scale = 0.25;
1418
+
1419
+ if (mesh.ShowInfo())
1420
+ {
1421
+ gl.glLineWidth(4);
1422
+ for (int s=0; s<Phys.allNodes.size(); s++)
1423
+ {
1424
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1425
+ if (node.mass == 0)
1426
+ continue;
1427
+
1428
+ int i = node.springs==null?-1:node.springs.size();
1429
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1430
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1431
+ //temp.normalize();
1432
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1433
+ gl.glBegin(gl.GL_LINES);
1434
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1435
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1436
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1437
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1438
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1439
+ gl.glEnd();
1440
+ }
1441
+
1442
+ gl.glLineWidth(8);
1443
+ for (int s=0; s<Phys.allNodes.size(); s++)
1444
+ {
1445
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1446
+
1447
+ if (node.springs != null)
1448
+ {
1449
+ for (int i=0; i<node.springs.size(); i+=1)
1450
+ {
1451
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1452
+
1453
+ int c = i+1;
1454
+ // c = node.springs.get(i).nbcopies;
1455
+
1456
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1457
+ gl.glBegin(gl.GL_LINES);
1458
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1459
+ 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);
1460
+ gl.glEnd();
1461
+ }
1462
+ }
1463
+ }
1464
+
1465
+ gl.glLineWidth(1);
1466
+ }
1467
+
1468
+ gl.glEnable(gl.GL_LIGHTING);
1469
+ }
1470
+
5691471 /// INTERFACE
5701472
1473
+ public void StartTriangles()
1474
+ {
1475
+ javax.media.opengl.GL gl = GetGL();
1476
+ gl.glBegin(gl.GL_TRIANGLES);
1477
+ }
1478
+
1479
+ public void EndTriangles()
1480
+ {
1481
+ GetGL().glEnd();
1482
+ }
1483
+
1484
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1485
+ {
1486
+ if (!selectmode)
1487
+ {
1488
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1489
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1490
+
1491
+ if (flipV)
1492
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1493
+ else
1494
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1495
+ }
1496
+
1497
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1498
+ }
1499
+
1500
+ float[] colorV = new float[4];
1501
+
5711502 void SetColor(Object3D obj, Vertex p0)
5721503 {
5731504 CameraPane display = this;
....@@ -635,8 +1566,6 @@
6351566 {
6361567 return;
6371568 }
638
-
639
- float[] colorV = new float[3];
6401569
6411570 if (false) // marked)
6421571 {
....@@ -745,7 +1674,7 @@
7451674 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
7461675 }
7471676
748
- void DrawMaterial(cMaterial material, boolean selected)
1677
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
7491678 {
7501679 CameraPane display = this;
7511680 //new Exception().printStackTrace();
....@@ -761,18 +1690,18 @@
7611690 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
7621691 if (!material.multiply)
7631692 {
764
- display.color = color;
1693
+ display.color = material.color;
7651694 display.saturation = material.modulation;
7661695 }
7671696 else
7681697 {
769
- display.color *= color*2;
1698
+ display.color *= material.color*2;
7701699 display.saturation *= material.modulation*2;
7711700 }
7721701
7731702 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
7741703
775
- float[] colorV = GrafreeD.colorV;
1704
+ float[] colorV = Grafreed.colorV;
7761705
7771706 /**/
7781707 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -780,7 +1709,7 @@
7801709 colorV[0] = display.modelParams0[0] * material.diffuse;
7811710 colorV[1] = display.modelParams0[1] * material.diffuse;
7821711 colorV[2] = display.modelParams0[2] * material.diffuse;
783
- colorV[3] = material.opacity;
1712
+ colorV[3] = 1; // material.opacity;
7841713
7851714 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
7861715 //System.out.println("Opacity = " + opacity);
....@@ -888,9 +1817,9 @@
8881817 display.modelParams7[2] = 0;
8891818 display.modelParams7[3] = 0;
8901819
891
- display.modelParams6[0] = 100; // criss de bug de bump
1820
+ //display.modelParams6[0] = 100; // criss de bug de bump
8921821
893
- Object3D.cVector2[] extparams = display.vector2buffer;
1822
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
8941823 if (extparams != null && extparams.length > 0 && extparams[0] != null)
8951824 {
8961825 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1032,7 +1961,7 @@
10321961 void PushMatrix(double[][] matrix)
10331962 {
10341963 // GrafreeD.tracein(matrix);
1035
- PushMatrix(matrix,1);
1964
+ PushMatrix(matrix, 1);
10361965 }
10371966
10381967 void PushMatrix()
....@@ -1129,7 +2058,7 @@
11292058
11302059 static int camerachangeframe;
11312060
1132
- boolean SetCamera(Camera cam)
2061
+ public boolean SetCamera(Camera cam)
11332062 {
11342063 // may 2014 if (cam == cameras[0] || cam == cameras[1])
11352064 // return false;
....@@ -1186,7 +2115,7 @@
11862115 //System.err.println("Oeil on");
11872116 OEIL = true;
11882117 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1189
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2118
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11902119 //pingthread.StepToTarget(true);
11912120 }
11922121
....@@ -1257,33 +2186,6 @@
12572186 mainDL ^= true;
12582187 }
12592188
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
-
12872189 void ToggleFullScreen()
12882190 {
12892191 FULLSCREEN ^= true;
....@@ -1294,72 +2196,94 @@
12942196 Globals.CROWD ^= true;
12952197 }
12962198
1297
- void ToggleInertia()
1298
- {
1299
- INERTIA ^= true;
1300
- }
1301
-
13022199 void ToggleLocal()
13032200 {
13042201 LOCALTRANSFORM ^= true;
13052202 }
13062203
1307
- void ToggleFast()
2204
+ public void ToggleTexture()
2205
+ {
2206
+ textureon ^= true;
2207
+ }
2208
+
2209
+ public void ToggleLive()
2210
+ {
2211
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2212
+
2213
+ System.err.println("LIVE = " + Globals.isLIVE());
2214
+
2215
+ if (!Globals.isLIVE()) // save sound
2216
+ Grafreed.savesound = true; // wav.save();
2217
+ // else
2218
+ repaint(); // start loop // may 2013
2219
+ }
2220
+
2221
+ public void ToggleSupport()
2222
+ {
2223
+ SUPPORT ^= true;
2224
+ }
2225
+
2226
+ public void ToggleAbort()
2227
+ {
2228
+ ABORTMODE ^= true;
2229
+ }
2230
+
2231
+ public void ToggleInertia()
2232
+ {
2233
+ INERTIA ^= true;
2234
+ }
2235
+
2236
+ public void ToggleFast()
13082237 {
13092238 FAST ^= true;
13102239 }
13112240
1312
- void ToggleSlowPose()
2241
+ public void ToggleSlowPose()
13132242 {
13142243 SLOWPOSE ^= true;
13152244 }
13162245
1317
- void ToggleFootContact()
1318
- {
1319
- FOOTCONTACT ^= true;
1320
- }
1321
-
1322
- void ToggleBoxMode()
2246
+ public void ToggleBoxMode()
13232247 {
13242248 BOXMODE ^= true;
13252249 }
13262250
1327
- void ToggleSmoothFocus()
2251
+ public void ToggleZoomBoxMode()
2252
+ {
2253
+ ZOOMBOXMODE ^= true;
2254
+ }
2255
+
2256
+ public void ToggleSmoothFocus()
13282257 {
13292258 SMOOTHFOCUS ^= true;
13302259 }
13312260
1332
- void ToggleImageFlip()
2261
+ public void ToggleImageFlip()
13332262 {
13342263 IMAGEFLIP ^= true;
13352264 }
13362265
1337
- void ToggleSpeakerMocap()
2266
+ public void ToggleSpeakerMocap()
13382267 {
13392268 SPEAKERMOCAP ^= true;
13402269 }
13412270
1342
- void ToggleSpeakerCamera()
2271
+ public void ToggleSpeakerCamera()
13432272 {
13442273 SPEAKERCAMERA ^= true;
13452274 }
13462275
1347
- void ToggleSpeakerFocus()
2276
+ public void ToggleSpeakerFocus()
13482277 {
13492278 SPEAKERFOCUS ^= true;
13502279 }
13512280
1352
- void ToggleDebug()
1353
- {
1354
- DEBUG ^= true;
1355
- }
1356
-
1357
- void ToggleFrustum()
2281
+ public void ToggleFrustum()
13582282 {
13592283 FRUSTUM ^= true;
13602284 }
13612285
1362
- void ToggleTrack()
2286
+ public void ToggleTrack()
13632287 {
13642288 TRACK ^= true;
13652289 if (TRACK)
....@@ -1378,25 +2302,35 @@
13782302 repaint();
13792303 }
13802304
1381
- void ToggleTrackOnce()
2305
+ public void ToggleTrackOnce()
13822306 {
13832307 TRACKONCE ^= true;
13842308 }
13852309
1386
- void ToggleShadowTrack()
2310
+ public void ToggleShadowTrack()
13872311 {
13882312 SHADOWTRACK ^= true;
13892313 repaint();
13902314 }
13912315
1392
- void ToggleOeil()
2316
+ public void ToggleOeil()
13932317 {
13942318 OEIL ^= true;
13952319 }
13962320
1397
- void ToggleOeilOnce()
2321
+ public void ToggleOeilOnce()
13982322 {
13992323 OEILONCE ^= true;
2324
+ }
2325
+
2326
+ void ToggleFootContact()
2327
+ {
2328
+ FOOTCONTACT ^= true;
2329
+ }
2330
+
2331
+ void ToggleDebug()
2332
+ {
2333
+ Globals.DEBUG ^= true;
14002334 }
14012335
14022336 void ToggleLookAt()
....@@ -1404,9 +2338,9 @@
14042338 LOOKAT ^= true;
14052339 }
14062340
1407
- void ToggleRandom()
2341
+ void ToggleSwitch()
14082342 {
1409
- RANDOM ^= true;
2343
+ SWITCH ^= true;
14102344 }
14112345
14122346 void ToggleHandles()
....@@ -1414,10 +2348,17 @@
14142348 HANDLES ^= true;
14152349 }
14162350
2351
+ Object3D paintFolder;
2352
+
14172353 void TogglePaint()
14182354 {
14192355 PAINTMODE ^= true;
14202356 paintcount = 0;
2357
+
2358
+ if (PAINTMODE)
2359
+ {
2360
+ paintFolder = GetFolder();
2361
+ }
14212362 }
14222363
14232364 void SwapCamera(int a, int b)
....@@ -1513,7 +2454,22 @@
15132454 {
15142455 return currentGL;
15152456 }
1516
-
2457
+
2458
+ static private BufferedImage CreateBim(TextureData texturedata)
2459
+ {
2460
+ Grafreed.Assert(texturedata != null);
2461
+
2462
+ int width = texturedata.getWidth();
2463
+ int height = texturedata.getHeight();
2464
+
2465
+ Buffer buffer = texturedata.getBuffer();
2466
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2467
+
2468
+ byte[] bytes = bytebuf.array();
2469
+
2470
+ return CreateBim(bytes, width, height);
2471
+ }
2472
+
15172473 /**/
15182474 class CacheTexture
15192475 {
....@@ -1522,28 +2478,31 @@
15222478
15232479 int resolution;
15242480
1525
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2481
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
15262482 {
1527
- texture = tex;
2483
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2484
+ texturedata = texdata;
15282485 resolution = res;
15292486 }
15302487 }
15312488 /**/
15322489
15332490 // 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>();
2491
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2492
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2493
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2494
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2495
+
15372496 int pigmentdepth = 0;
15382497 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
15392498 int bumpdepth = 0;
15402499 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
15412500 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
15422501 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
1543
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2502
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
15442503 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
15452504
1546
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2505
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
15472506 {
15482507 TextureData texturedata = null;
15492508
....@@ -1562,13 +2521,34 @@
15622521 if (bump)
15632522 texturedata = ConvertBump(texturedata, false);
15642523
1565
- com.sun.opengl.util.texture.Texture texture =
1566
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2524
+// com.sun.opengl.util.texture.Texture texture =
2525
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
15672526
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);
2527
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2528
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
15702529
1571
- return texture;
2530
+ return texturedata;
2531
+ }
2532
+
2533
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2534
+ {
2535
+ TextureData texturedata = null;
2536
+
2537
+ try
2538
+ {
2539
+ texturedata =
2540
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2541
+ bim,
2542
+ true);
2543
+ } catch (Exception e)
2544
+ {
2545
+ throw new javax.media.opengl.GLException(e);
2546
+ }
2547
+
2548
+ if (bump)
2549
+ texturedata = ConvertBump(texturedata, false);
2550
+
2551
+ return texturedata;
15722552 }
15732553
15742554 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -2641,6 +3621,8 @@
26413621
26423622 System.out.println("LOADING TEXTURE : " + name);
26433623
3624
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3625
+
26443626 //
26453627 if (false) // compressbit > 0)
26463628 {
....@@ -3345,6 +4327,7 @@
33454327
33464328 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
33474329 {
4330
+ new Exception().printStackTrace();
33484331 System.exit(0);
33494332 com.sun.opengl.util.texture.Texture texture = null;
33504333
....@@ -7038,7 +8021,7 @@
70388021 String pigment = Object3D.GetPigment(tex);
70398022 String bump = Object3D.GetBump(tex);
70408023
7041
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8024
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
70428025 {
70438026 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
70448027 // System.out.println("; bump = " + bump);
....@@ -7053,11 +8036,69 @@
70538036 pigment = null;
70548037 }
70558038
7056
- ReleaseTexture(bump, true);
7057
- ReleaseTexture(pigment, false);
8039
+ ReleaseTexture(tex, true);
8040
+ ReleaseTexture(tex, false);
70588041 }
70598042
7060
- void ReleaseTexture(String tex, boolean bump)
8043
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8044
+ {
8045
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8046
+ {
8047
+ return;
8048
+ }
8049
+
8050
+ if (tex == null)
8051
+ {
8052
+ ReleaseTexture(null, false);
8053
+ return;
8054
+ }
8055
+
8056
+ String pigment = Object3D.GetPigment(tex);
8057
+
8058
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8059
+ {
8060
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8061
+ // System.out.println("; bump = " + bump);
8062
+ }
8063
+
8064
+ if (pigment.equals(""))
8065
+ {
8066
+ pigment = null;
8067
+ }
8068
+
8069
+ ReleaseTexture(tex, false);
8070
+ }
8071
+
8072
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8073
+ {
8074
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8075
+ {
8076
+ return;
8077
+ }
8078
+
8079
+ if (tex == null)
8080
+ {
8081
+ ReleaseTexture(null, true);
8082
+ return;
8083
+ }
8084
+
8085
+ String bump = Object3D.GetBump(tex);
8086
+
8087
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8088
+ {
8089
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8090
+ // System.out.println("; bump = " + bump);
8091
+ }
8092
+
8093
+ if (bump.equals(""))
8094
+ {
8095
+ bump = null;
8096
+ }
8097
+
8098
+ ReleaseTexture(tex, true);
8099
+ }
8100
+
8101
+ void ReleaseTexture(cTexture tex, boolean bump)
70618102 {
70628103 if (// DrawMode() != 0 || /*tex == null ||*/
70638104 ambientOcclusion ) // || !textureon)
....@@ -7068,7 +8109,7 @@
70688109 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
70698110
70708111 if (tex != null)
7071
- texture = textures.get(tex);
8112
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
70728113
70738114 // //assert( texture != null );
70748115 // if (texture == null)
....@@ -7160,7 +8201,55 @@
71608201 }
71618202 }
71628203
7163
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8204
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8205
+ {
8206
+// if (// DrawMode() != 0 || /*tex == null ||*/
8207
+// ambientOcclusion ) // || !textureon)
8208
+// {
8209
+// return; // false;
8210
+// }
8211
+//
8212
+// if (tex == null)
8213
+// {
8214
+// BindTexture(null,false,resolution);
8215
+// BindTexture(null,true,resolution);
8216
+// return;
8217
+// }
8218
+//
8219
+// String pigment = Object3D.GetPigment(tex);
8220
+// String bump = Object3D.GetBump(tex);
8221
+//
8222
+// usedtextures.add(pigment);
8223
+// usedtextures.add(bump);
8224
+//
8225
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8226
+// {
8227
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8228
+// // System.out.println("; bump = " + bump);
8229
+// }
8230
+//
8231
+// if (bump.equals(""))
8232
+// {
8233
+// bump = null;
8234
+// }
8235
+// if (pigment.equals(""))
8236
+// {
8237
+// pigment = null;
8238
+// }
8239
+//
8240
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8241
+// BindTexture(pigment, false, resolution);
8242
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8243
+// BindTexture(bump, true, resolution);
8244
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8245
+//
8246
+// return; // true;
8247
+
8248
+ BindPigmentTexture(tex, resolution);
8249
+ BindBumpTexture(tex, resolution);
8250
+ }
8251
+
8252
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
71648253 {
71658254 if (// DrawMode() != 0 || /*tex == null ||*/
71668255 ambientOcclusion ) // || !textureon)
....@@ -7171,17 +8260,47 @@
71718260 if (tex == null)
71728261 {
71738262 BindTexture(null,false,resolution);
7174
- BindTexture(null,true,resolution);
71758263 return;
71768264 }
71778265
71788266 String pigment = Object3D.GetPigment(tex);
8267
+
8268
+ usedtextures.add(tex);
8269
+
8270
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8271
+ {
8272
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8273
+ // System.out.println("; bump = " + bump);
8274
+ }
8275
+
8276
+ if (pigment.equals(""))
8277
+ {
8278
+ pigment = null;
8279
+ }
8280
+
8281
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8282
+ BindTexture(tex, false, resolution);
8283
+ }
8284
+
8285
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8286
+ {
8287
+ if (// DrawMode() != 0 || /*tex == null ||*/
8288
+ ambientOcclusion ) // || !textureon)
8289
+ {
8290
+ return; // false;
8291
+ }
8292
+
8293
+ if (tex == null)
8294
+ {
8295
+ BindTexture(null,true,resolution);
8296
+ return;
8297
+ }
8298
+
71798299 String bump = Object3D.GetBump(tex);
71808300
7181
- usedtextures.put(pigment, pigment);
7182
- usedtextures.put(bump, bump);
8301
+ usedtextures.add(tex);
71838302
7184
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8303
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
71858304 {
71868305 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
71878306 // System.out.println("; bump = " + bump);
....@@ -7191,43 +8310,94 @@
71918310 {
71928311 bump = null;
71938312 }
7194
- if (pigment.equals(""))
7195
- {
7196
- pigment = null;
7197
- }
71988313
7199
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7200
- BindTexture(pigment, false, resolution);
72018314 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7202
- BindTexture(bump, true, resolution);
8315
+ BindTexture(tex, true, resolution);
72038316 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7204
-
7205
- return; // true;
72068317 }
72078318
7208
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8319
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8320
+
8321
+ private boolean FileExists(String tex)
72098322 {
7210
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8323
+ if (missingTextures.contains(tex))
8324
+ {
8325
+ return false;
8326
+ }
8327
+
8328
+ boolean fileExists = new File(tex).exists();
8329
+
8330
+ if (!fileExists)
8331
+ {
8332
+ // If file exists, the "new File()" is not executed sgain
8333
+ missingTextures.add(tex);
8334
+ }
8335
+
8336
+ return fileExists;
8337
+ }
8338
+
8339
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8340
+ {
8341
+ CacheTexture texturecache = null;
72118342
72128343 if (tex != null)
72138344 {
7214
- String texname = tex;
8345
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8346
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
72158347
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;
8348
+ if (texname.equals("") && texdata == null)
8349
+ {
8350
+ return null;
8351
+ }
8352
+
8353
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8354
+
8355
+// String[] split = tex.split("Textures");
8356
+// if (split.length > 1)
8357
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8358
+// else
8359
+// if (!texname.startsWith("/"))
8360
+// texname = "/Users/nbriere/Textures/" + texname;
8361
+ if (!FileExists(texname) && !texname.startsWith("@"))
8362
+ {
8363
+ texname = fallbackTextureName;
8364
+ }
72228365
72238366 if (CACHETEXTURE)
7224
- texture = textures.get(texname); // TEXTURE CACHE
7225
-
7226
- TextureData texturedata = null;
7227
-
7228
- if (texture == null || texture.resolution < resolution)
72298367 {
7230
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8368
+ if (texdata == null)
8369
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8370
+ else
8371
+ texturecache = bimtextures.get(texdata);
8372
+ }
8373
+
8374
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8375
+ {
8376
+ TextureData texturedata = null;
8377
+
8378
+ if (texdata != null && textureon)
8379
+ {
8380
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8381
+
8382
+ try
8383
+ {
8384
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8385
+ }
8386
+ catch (Exception e)
8387
+ {
8388
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8389
+ }
8390
+
8391
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8392
+ bimtextures.put(texdata, texturecache);
8393
+
8394
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8395
+
8396
+ //Object bim2 = CreateBim(texturecache.texturedata);
8397
+ //bim2 = bim;
8398
+ }
8399
+ else
8400
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
72318401 {
72328402 assert(!bump);
72338403 // if (bump)
....@@ -7238,19 +8408,23 @@
72388408 // }
72398409 // else
72408410 // {
7241
- texture = textures.get(tex);
7242
- if (texture == null)
8411
+ // texturecache = textures.get(texname); // suspicious
8412
+ if (texturecache == null)
72438413 {
7244
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8414
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
72458415 }
8416
+ else
8417
+ new Exception().printStackTrace();
72468418 // }
72478419 } else
7248
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8420
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
72498421 {
72508422 assert(bump);
7251
- texture = textures.get(tex);
7252
- if (texture == null)
7253
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8423
+ // texturecache = textures.get(texname); // suspicious
8424
+ if (texturecache == null)
8425
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ else
8427
+ new Exception().printStackTrace();
72548428 } else
72558429 {
72568430 //if (tex.equals("IMMORTAL"))
....@@ -7258,11 +8432,22 @@
72588432 // texture = GetResourceTexture("default.png");
72598433 //} else
72608434 //{
7261
- if (tex.equals("WHITE_NOISE"))
8435
+ if (texname.endsWith("WHITE_NOISE"))
72628436 {
7263
- texture = textures.get(tex);
7264
- if (texture == null)
7265
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8437
+ // texturecache = textures.get(texname); // suspicious
8438
+ if (texturecache == null)
8439
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ else
8441
+ new Exception().printStackTrace();
8442
+ } else
8443
+ {
8444
+ if (texname.startsWith("@"))
8445
+ {
8446
+ // texturecache = textures.get(texname); // suspicious
8447
+ if (texturecache == null)
8448
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8449
+ else
8450
+ new Exception().printStackTrace();
72668451 } else
72678452 {
72688453 if (textureon)
....@@ -7287,7 +8472,7 @@
72878472 }
72888473
72898474 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7290
- if (!new File(cachename).exists())
8475
+ if (!FileExists(cachename))
72918476 cachename = texname;
72928477 else
72938478 processbump = false; // don't process bump map again
....@@ -7309,7 +8494,7 @@
73098494 }
73108495
73118496 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7312
- if (!new File(cachename).exists())
8497
+ if (!FileExists(cachename))
73138498 cachename = texname;
73148499 else
73158500 processbump = false; // don't process bump map again
....@@ -7318,20 +8503,23 @@
73188503 texturedata = GetFileTexture(cachename, processbump, resolution);
73198504
73208505
7321
- if (texturedata != null)
7322
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8506
+ if (texturedata == null)
8507
+ throw new Exception();
8508
+
8509
+ texturecache = new CacheTexture(texturedata,resolution);
73238510 //texture = GetTexture(tex, bump);
73248511 }
8512
+ }
73258513 }
73268514 //}
73278515 }
73288516
7329
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8517
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
73308518 {
73318519 //return false;
73328520
73338521 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7334
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8522
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
73358523 {
73368524 // String ext = "_highres";
73378525 // if (REDUCETEXTURE)
....@@ -7348,52 +8536,17 @@
73488536 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
73498537 if (!cachefile.exists())
73508538 {
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))
8539
+ //if (texturedata.getWidth() == texturedata.getHeight())
73608540 {
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);
8541
+ BufferedImage rendImage = CreateBim(texturedata);
8542
+
73918543 ImageWriter writer = null;
73928544 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
73938545 if (iter.hasNext()) {
73948546 writer = (ImageWriter)iter.next();
73958547 }
7396
- float compressionQuality = 0.9f;
8548
+
8549
+ float compressionQuality = 0.85f;
73978550 try
73988551 {
73998552 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7410,18 +8563,20 @@
74108563 }
74118564 }
74128565 }
7413
-
8566
+
8567
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8568
+
74148569 //System.out.println("Texture = " + tex);
7415
- if (textures.containsKey(texname))
8570
+ if (textures.containsKey(tex))
74168571 {
7417
- CacheTexture thetex = textures.get(texname);
8572
+ CacheTexture thetex = textures.get(tex);
74188573 thetex.texture.disable();
74198574 thetex.texture.dispose();
7420
- textures.remove(texname);
8575
+ textures.remove(tex);
74218576 }
74228577
7423
- texture.texturedata = texturedata;
7424
- textures.put(texname, texture);
8578
+ //texture.texturedata = texturedata;
8579
+ textures.put(tex, texturecache);
74258580
74268581 // newtex = true;
74278582 }
....@@ -7437,10 +8592,44 @@
74378592 }
74388593 }
74398594
7440
- return texture;
8595
+ return texturecache;
74418596 }
74428597
7443
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8598
+ static void EmbedTextures(cTexture tex)
8599
+ {
8600
+ if (tex.pigmentdata == null)
8601
+ {
8602
+ //String texname = Object3D.GetPigment(tex);
8603
+
8604
+ CacheTexture texturecache = texturepigment.get(tex);
8605
+
8606
+ if (texturecache != null)
8607
+ {
8608
+ tex.pw = texturecache.texturedata.getWidth();
8609
+ tex.ph = texturecache.texturedata.getHeight();
8610
+ tex.pigmentdata = //CompressJPEG(CreateBim
8611
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8612
+ ;
8613
+ //, tex.pw, tex.ph), 0.5f);
8614
+ }
8615
+ }
8616
+
8617
+ if (tex.bumpdata == null)
8618
+ {
8619
+ //String texname = Object3D.GetBump(tex);
8620
+
8621
+ CacheTexture texturecache = texturebump.get(tex);
8622
+
8623
+ if (texturecache != null)
8624
+ {
8625
+ tex.bw = texturecache.texturedata.getWidth();
8626
+ tex.bh = texturecache.texturedata.getHeight();
8627
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8628
+ }
8629
+ }
8630
+ }
8631
+
8632
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
74448633 {
74458634 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
74468635
....@@ -7458,21 +8647,21 @@
74588647 return texture!=null?texture.texture:null;
74598648 }
74608649
7461
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8650
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
74628651 {
74638652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
74648653
74658654 return texture!=null?texture.texturedata:null;
74668655 }
74678656
7468
- boolean BindTexture(String tex, boolean bump, int resolution)
8657
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
74698658 {
74708659 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
74718660 {
74728661 return false;
74738662 }
74748663
7475
- boolean newtex = false;
8664
+ //boolean newtex = false;
74768665
74778666 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
74788667
....@@ -7504,9 +8693,75 @@
75048693 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
75058694 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
75068695
7507
- return newtex;
8696
+ return true; // Warning: not used.
75088697 }
75098698
8699
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8700
+ {
8701
+ try
8702
+ {
8703
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8704
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8705
+ ImageWriter writer = writers.next();
8706
+
8707
+ ImageWriteParam param = writer.getDefaultWriteParam();
8708
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8709
+ param.setCompressionQuality(quality);
8710
+
8711
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8712
+ writer.setOutput(ios);
8713
+ writer.write(null, new IIOImage(image, null, null), param);
8714
+
8715
+ byte[] data = baos.toByteArray();
8716
+ writer.dispose();
8717
+ return data;
8718
+ }
8719
+ catch (Exception e)
8720
+ {
8721
+ e.printStackTrace();
8722
+ return null;
8723
+ }
8724
+ }
8725
+
8726
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8727
+ {
8728
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8729
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8730
+ ImageReader reader = writers.next();
8731
+
8732
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8733
+
8734
+ ImageReadParam param = reader.getDefaultReadParam();
8735
+ param.setDestination(bim);
8736
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8737
+
8738
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8739
+ reader.setInput(ios);
8740
+ BufferedImage bim2 = reader.read(0, param);
8741
+ reader.dispose();
8742
+
8743
+// WritableRaster raster = bim2.getRaster();
8744
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8745
+// byte[] bytes = data.getData();
8746
+//
8747
+// int[] pixels = new int[bytes.length/3];
8748
+// for (int i=pixels.length; --i>=0;)
8749
+// {
8750
+// int i3 = i*3;
8751
+// pixels[i] = 0xFF;
8752
+// pixels[i] <<= 8;
8753
+// pixels[i] |= bytes[i3+2] & 0xFF;
8754
+// pixels[i] <<= 8;
8755
+// pixels[i] |= bytes[i3+1] & 0xFF;
8756
+// pixels[i] <<= 8;
8757
+// pixels[i] |= bytes[i3] & 0xFF;
8758
+// }
8759
+//
8760
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8761
+
8762
+ return bim;
8763
+ }
8764
+
75108765 ShadowBuffer shadowPBuf;
75118766 AntialiasBuffer antialiasPBuf;
75128767 int MAXSTACK;
....@@ -7523,10 +8778,12 @@
75238778
75248779 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
75258780 MAXSTACK = temp[0];
7526
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8781
+ if (Globals.DEBUG)
8782
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
75278783 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
75288784 MAXSTACK = temp[0];
7529
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8785
+ if (Globals.DEBUG)
8786
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
75308787
75318788 // Use debug pipeline
75328789 //drawable.setGL(new DebugGL(gl)); //
....@@ -7534,7 +8791,8 @@
75348791 gl = drawable.getGL(); //
75358792
75368793 GL gl3 = getGL();
7537
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8794
+ if (Globals.DEBUG)
8795
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
75388796
75398797
75408798 //float pos[] = { 100, 100, 100, 0 };
....@@ -7699,7 +8957,7 @@
76998957
77008958 if (cubemap == null)
77018959 {
7702
- LoadEnvy(5);
8960
+ //LoadEnvy(1);
77038961 }
77048962
77058963 //cubemap.enable();
....@@ -7986,37 +9244,58 @@
79869244 cubemap = null;
79879245 return;
79889246 case 1:
7989
- name = "cubemaps/box_";
7990
- ext = "png";
9247
+ name = "cubemaps/rgb/";
9248
+ ext = "jpg";
79919249 reverseUP = false;
79929250 break;
79939251 case 2:
7994
- name = "cubemaps/uffizi_";
7995
- ext = "png";
7996
- break; // reverseUP = true; break;
9252
+ name = "cubemaps/uffizi/";
9253
+ ext = "jpg";
9254
+ reverseUP = false;
9255
+ break;
79979256 case 3:
7998
- name = "cubemaps/CloudyHills_";
7999
- ext = "tga";
9257
+ name = "cubemaps/CloudyHills/";
9258
+ ext = "jpg";
80009259 reverseUP = false;
80019260 break;
80029261 case 4:
8003
- name = "cubemaps/cornell_";
9262
+ name = "cubemaps/cornell/";
80049263 ext = "png";
80059264 reverseUP = false;
80069265 break;
9266
+ case 5:
9267
+ name = "cubemaps/skycube/";
9268
+ ext = "jpg";
9269
+ reverseUP = false;
9270
+ break;
9271
+ case 6:
9272
+ name = "cubemaps/SaintLazarusChurch3/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 7:
9277
+ name = "cubemaps/Sodermalmsallen/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 8:
9282
+ name = "cubemaps/Sodermalmsallen2/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 9:
9287
+ name = "cubemaps/UnionSquare/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
80079291 default:
8008
- name = "cubemaps/rgb_";
8009
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9292
+ name = "cubemaps/box/";
9293
+ ext = "png"; /*mipmap = true;*/
9294
+ reverseUP = false;
80109295 break;
80119296 }
8012
-
8013
- try
8014
- {
8015
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8016
- } catch (IOException e)
8017
- {
8018
- throw new RuntimeException(e);
8019
- }
9297
+
9298
+ LoadSkybox(name, ext, mipmap);
80209299 }
80219300
80229301 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8048,8 +9327,12 @@
80489327 static double[] model = new double[16];
80499328 double[] camera2light = new double[16];
80509329 double[] light2camera = new double[16];
8051
- int newenvy = -1;
8052
- boolean envyoff = true; // false;
9330
+
9331
+ //int newenvy = -1;
9332
+ //boolean envyoff = false;
9333
+
9334
+ String loadedskyboxname;
9335
+
80539336 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
80549337 //float[] light0 = { 0,0,0 };
80559338 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -8342,11 +9625,35 @@
83429625 jy8[3] = 0.5f;
83439626 }
83449627
8345
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9628
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
83469629 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
83479630 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
83489631 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
83499632
9633
+ void ResetOptions()
9634
+ {
9635
+ options1[0] = 100;
9636
+ options1[1] = 0.025f;
9637
+ options1[2] = 0.01f;
9638
+ options1[3] = 0;
9639
+ options1[4] = 0;
9640
+
9641
+ options2[0] = 0;
9642
+ options2[1] = 0.75f;
9643
+ options2[2] = 0;
9644
+ options2[3] = 0;
9645
+
9646
+ options3[0] = 1;
9647
+ options3[1] = 1;
9648
+ options3[2] = 1;
9649
+ options3[3] = 0;
9650
+
9651
+ options4[0] = 1;
9652
+ options4[1] = 0;
9653
+ options4[2] = 1;
9654
+ options4[3] = 0;
9655
+ }
9656
+
83509657 static int imagecount = 0; // movie generation
83519658
83529659 static int jitter = 0;
....@@ -8442,8 +9749,8 @@
84429749 assert (parentcam != renderCamera);
84439750
84449751 if (renderCamera != lightCamera)
8445
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8446
- LA.matConcat(matrix, parentcam.toParent, matrix);
9752
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9753
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
84479754
84489755 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
84499756
....@@ -8458,8 +9765,8 @@
84589765 LA.matCopy(renderCamera.fromScreen, matrix);
84599766
84609767 if (renderCamera != lightCamera)
8461
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8462
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9768
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9769
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
84639770
84649771 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
84659772
....@@ -8505,10 +9812,12 @@
85059812 rati = 1 / rati;
85069813 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
85079814 }
8508
- assert (newenvy == -1);
9815
+
9816
+ //assert (newenvy == -1);
9817
+
85099818 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
85109819 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
8511
- DrawSkyBox(gl);
9820
+ DrawSkyBox(gl, (float)rati);
85129821 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
85139822 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
85149823 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -8531,7 +9840,7 @@
85319840 //gl.glFlush();
85329841 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
85339842
8534
- if (ANIMATION && ABORTED)
9843
+ if (Globals.ANIMATION && ABORTED)
85359844 {
85369845 System.err.println(" ABORTED FRAME");
85379846 break;
....@@ -8561,7 +9870,7 @@
85619870 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
85629871
85639872 // save image
8564
- if (ANIMATION && !ABORTED)
9873
+ if (Globals.ANIMATION && !ABORTED)
85659874 {
85669875 VPwidth = viewport[2];
85679876 VPheight = viewport[3];
....@@ -8672,11 +9981,11 @@
86729981
86739982 // imagecount++;
86749983
8675
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9984
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
86769985
86779986 if (!BOXMODE)
86789987 {
8679
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9988
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
86809989 }
86819990
86829991 if (!BOXMODE)
....@@ -8714,7 +10023,7 @@
871410023 ABORTED = false;
871510024 }
871610025 else
8717
- GrafreeD.wav.cursor += 735 * ACSIZE;
10026
+ Grafreed.wav.cursor += 735 * ACSIZE;
871810027
871910028 if (false)
872010029 {
....@@ -9377,11 +10686,11 @@
937710686
937810687 public void display(GLAutoDrawable drawable)
937910688 {
9380
- if (GrafreeD.savesound && GrafreeD.hassound)
10689
+ if (Grafreed.savesound && Grafreed.hassound)
938110690 {
9382
- GrafreeD.wav.save();
9383
- GrafreeD.savesound = false;
9384
- GrafreeD.hassound = false;
10691
+ Grafreed.wav.save();
10692
+ Grafreed.savesound = false;
10693
+ Grafreed.hassound = false;
938510694 }
938610695 // if (DEBUG_SELECTION)
938710696 // {
....@@ -9457,6 +10766,7 @@
945710766 ANTIALIAS = 0;
945810767 //System.out.println("RESTART");
945910768 AAtimer.restart();
10769
+ Globals.TIMERRUNNING = true;
946010770 }
946110771 }
946210772 }
....@@ -9511,7 +10821,7 @@
951110821 Object3D theobject = object;
951210822 Object3D theparent = object.parent;
951310823 object.parent = null;
9514
- object = (Object3D)GrafreeD.clone(object);
10824
+ object = (Object3D)Grafreed.clone(object);
951510825 object.Stripify();
951610826 if (theobject.selection == null || theobject.selection.Size() == 0)
951710827 theobject.PreprocessOcclusion(this);
....@@ -9524,13 +10834,14 @@
952410834 ambientOcclusion = false;
952510835 }
952610836
9527
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10837
+ if (//Globals.lighttouched &&
10838
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
952810839 {
952910840 //if (RENDERSHADOW) // ?
953010841 if (!IsFrozen())
953110842 {
953210843 // dec 2012
9533
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10844
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
953410845 {
953510846 Globals.framecount++;
953610847 shadowbuffer.display();
....@@ -9543,7 +10854,7 @@
954310854
954410855 if (wait)
954510856 {
9546
- Sleep(500);
10857
+ Sleep(200); // blocks everything
954710858
954810859 wait = false;
954910860 }
....@@ -9657,8 +10968,8 @@
965710968
965810969 // if (parentcam != renderCamera) // not a light
965910970 if (cam != lightCamera)
9660
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9661
- LA.matConcat(matrix, parentcam.toParent, matrix);
10971
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10972
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
966210973
966310974 for (int j = 0; j < 4; j++)
966410975 {
....@@ -9672,8 +10983,8 @@
967210983
967310984 // if (parentcam != renderCamera) // not a light
967410985 if (cam != lightCamera)
9675
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9676
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10986
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10987
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
967710988
967810989 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
967910990
....@@ -9759,13 +11070,27 @@
975911070 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
976011071 }
976111072
9762
- if (newenvy > -1)
11073
+// if (newenvy > -1)
11074
+// {
11075
+// LoadEnvy(newenvy);
11076
+// }
11077
+//
11078
+// newenvy = -1;
11079
+
11080
+ if (object.skyboxname != null)
976311081 {
9764
- LoadEnvy(newenvy);
11082
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11083
+ {
11084
+ LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11085
+ loadedskyboxname = object.skyboxname;
11086
+ }
976511087 }
9766
-
9767
- newenvy = -1;
9768
-
11088
+ else
11089
+ {
11090
+ cubemap = null;
11091
+ loadedskyboxname = null;
11092
+ }
11093
+
976911094 ratio = ((double) getWidth()) / getHeight();
977011095 //System.out.println("ratio = " + ratio);
977111096
....@@ -9781,7 +11106,7 @@
978111106
978211107 if (!IsFrozen() && !ambientOcclusion)
978311108 {
9784
- DrawSkyBox(gl);
11109
+ DrawSkyBox(gl, (float)ratio);
978511110 }
978611111
978711112 //if (selection_view == -1)
....@@ -9932,7 +11257,16 @@
993211257 // Bump noise
993311258 gl.glActiveTexture(GL.GL_TEXTURE6);
993411259 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9935
- BindTexture(NOISE_TEXTURE, false, 2);
11260
+
11261
+ try
11262
+ {
11263
+ BindTexture(NOISE_TEXTURE, false, 2);
11264
+ }
11265
+ catch (Exception e)
11266
+ {
11267
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11268
+ }
11269
+
993611270
993711271 gl.glActiveTexture(GL.GL_TEXTURE0);
993811272 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9955,9 +11289,9 @@
995511289
995611290 gl.glMatrixMode(GL.GL_MODELVIEW);
995711291
9958
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9959
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9960
-//gl.glEnable(gl.GL_MULTISAMPLE);
11292
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11293
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11294
+gl.glEnable(gl.GL_MULTISAMPLE);
996111295 } else
996211296 {
996311297 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9968,7 +11302,7 @@
996811302 //System.out.println("BLENDING ON");
996911303 gl.glEnable(GL.GL_BLEND);
997011304 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9971
-
11305
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
997211306 gl.glMatrixMode(gl.GL_PROJECTION);
997311307 gl.glLoadIdentity();
997411308
....@@ -10057,8 +11391,8 @@
1005711391 System.err.println("parentcam != renderCamera");
1005811392
1005911393 // if (cam != lightCamera)
10060
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10061
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11394
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11395
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1006211396 }
1006311397
1006411398 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10079,8 +11413,8 @@
1007911413 if (true) // TODO
1008011414 {
1008111415 if (cam != lightCamera)
10082
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10083
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11416
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11417
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1008411418 }
1008511419
1008611420 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10146,7 +11480,7 @@
1014611480 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
1014711481 //System.out.println("fragmentMode = " + fragmentMode);
1014811482
10149
- if (DrawMode() == DEFAULT || DrawMode() == SELECTION || DEBUG_SELECTION)
11483
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
1015011484 {
1015111485 /*
1015211486 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -10217,7 +11551,7 @@
1021711551 }
1021811552 }
1021911553
10220
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11554
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1022111555 {
1022211556 //gl.glDepthFunc(GL.GL_LEQUAL);
1022311557 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10225,24 +11559,21 @@
1022511559
1022611560 boolean texon = textureon;
1022711561
10228
- if (RENDERPROGRAM > 0)
10229
- {
10230
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10231
- textureon = false;
10232
- }
11562
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11563
+ textureon = false;
11564
+
1023311565 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1023411566 //System.out.println("ALLO");
1023511567 gl.glColorMask(false, false, false, false);
1023611568 DrawObject(gl);
10237
- if (RENDERPROGRAM > 0)
10238
- {
10239
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10240
- textureon = texon;
10241
- }
11569
+
11570
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11571
+ textureon = texon;
11572
+
1024211573 gl.glColorMask(true, true, true, true);
1024311574
1024411575 gl.glDepthFunc(GL.GL_EQUAL);
10245
- //gl.glDepthMask(false);
11576
+ gl.glDepthMask(false);
1024611577 }
1024711578
1024811579 if (false) // DrawMode() == SHADOW)
....@@ -10396,8 +11727,14 @@
1039611727 {
1039711728 renderpass++;
1039811729 // System.out.println("Draw object... ");
11730
+ STEP = 1;
1039911731 if (FAST) // in case there is no script
10400
- STEP = 16;
11732
+ STEP = 8;
11733
+
11734
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11735
+ {
11736
+ STEP *= 4;
11737
+ }
1040111738
1040211739 //object.FullInvariants();
1040311740
....@@ -10411,23 +11748,44 @@
1041111748 e.printStackTrace();
1041211749 }
1041311750
10414
- if (GrafreeD.RENDERME > 0)
10415
- GrafreeD.RENDERME--; // mechante magouille
11751
+ if (Grafreed.RENDERME > 0)
11752
+ Grafreed.RENDERME--; // mechante magouille
1041611753
1041711754 Globals.ONESTEP = false;
1041811755 }
1041911756
1042011757 static boolean zoomonce = false;
1042111758
11759
+ static void CreateSelectedPoint()
11760
+ {
11761
+ if (selectedpoint == null)
11762
+ {
11763
+ debugpointG = new Sphere();
11764
+ debugpointP = new Sphere();
11765
+ debugpointC = new Sphere();
11766
+ debugpointR = new Sphere();
11767
+
11768
+ selectedpoint = new Superellipsoid();
11769
+
11770
+ for (int i=0; i<8; i++)
11771
+ {
11772
+ debugpoints[i] = new Sphere();
11773
+ }
11774
+ }
11775
+ }
11776
+
1042211777 void DrawObject(GL gl, boolean draw)
1042311778 {
11779
+ // To clear camera values
11780
+ ResetOptions();
11781
+
1042411782 //System.out.println("DRAW OBJECT " + mouseDown);
1042511783 // DrawMode() = SELECTION;
1042611784 //GL gl = getGL();
1042711785 if ((TRACK || SHADOWTRACK) || zoomonce)
1042811786 {
1042911787 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10430
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11788
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1043111789 pingthread.StepToTarget(true); // true);
1043211790 // zoomonce = false;
1043311791 }
....@@ -10447,7 +11805,7 @@
1044711805 callist = gl.glGenLists(1);
1044811806 }
1044911807
10450
- boolean selectmode = DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
11808
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
1045111809
1045211810 boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
1045311811
....@@ -10482,7 +11840,14 @@
1048211840
1048311841 usedtextures.clear();
1048411842
10485
- BindTextures(DEFAULT_TEXTURES, 2);
11843
+ try
11844
+ {
11845
+ BindTextures(DEFAULT_TEXTURES, 2);
11846
+ }
11847
+ catch (Exception e)
11848
+ {
11849
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11850
+ }
1048611851 }
1048711852 //System.out.println("--> " + stackdepth);
1048811853 // GrafreeD.traceon();
....@@ -10492,8 +11857,9 @@
1049211857
1049311858 if (DrawMode() == DEFAULT)
1049411859 {
10495
- if (DEBUG)
11860
+ if (Globals.DEBUG)
1049611861 {
11862
+ CreateSelectedPoint();
1049711863 float radius = 0.05f;
1049811864 if (selectedpoint.radius != radius)
1049911865 {
....@@ -10547,20 +11913,32 @@
1054711913 ReleaseTextures(DEFAULT_TEXTURES);
1054811914
1054911915 if (CLEANCACHE)
10550
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11916
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1055111917 {
10552
- String tex = e.nextElement();
11918
+ cTexture tex = e.nextElement();
1055311919
1055411920 // System.out.println("Texture --------- " + tex);
1055511921
10556
- if (tex.equals("WHITE_NOISE"))
11922
+ if (tex.equals("WHITE_NOISE:"))
1055711923 continue;
1055811924
10559
- if (!usedtextures.containsKey(tex))
11925
+ if (!usedtextures.contains(tex))
1056011926 {
11927
+ CacheTexture gettex = texturepigment.get(tex);
1056111928 // System.out.println("DISPOSE +++++++++++++++ " + tex);
10562
- textures.get(tex).texture.dispose();
10563
- textures.remove(tex);
11929
+ if (gettex != null)
11930
+ {
11931
+ gettex.texture.dispose();
11932
+ texturepigment.remove(tex);
11933
+ }
11934
+
11935
+ gettex = texturebump.get(tex);
11936
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11937
+ if (gettex != null)
11938
+ {
11939
+ gettex.texture.dispose();
11940
+ texturebump.remove(tex);
11941
+ }
1056411942 }
1056511943 }
1056611944 }
....@@ -10573,7 +11951,14 @@
1057311951 if (checker != null && DrawMode() == DEFAULT)
1057411952 {
1057511953 //BindTexture(IMMORTAL_TEXTURE);
10576
- BindTextures(checker.GetTextures(), checker.texres);
11954
+ try
11955
+ {
11956
+ BindTextures(checker.GetTextures(), checker.texres);
11957
+ }
11958
+ catch (Exception e)
11959
+ {
11960
+ System.err.println("FAILED: " + checker.GetTextures());
11961
+ }
1057711962 // NEAREST
1057811963 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1057911964 DrawChecker(gl);
....@@ -10655,7 +12040,7 @@
1065512040 return;
1065612041 }
1065712042
10658
- String string = obj.GetToolTip();
12043
+ String string = obj.toString(); //.GetToolTip();
1065912044
1066012045 GL gl = GetGL();
1066112046
....@@ -10972,8 +12357,8 @@
1097212357 //obj.TransformToWorld(light, light);
1097312358 for (int i = tp.size(); --i >= 0;)
1097412359 {
10975
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10976
- LA.xformPos(light, tp.get(i).toParent, light);
12360
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12361
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1097712362 }
1097812363
1097912364
....@@ -10990,8 +12375,8 @@
1099012375 parentcam = cameras[0];
1099112376 }
1099212377
10993
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10994
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12378
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12379
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1099512380
1099612381 LA.xformPos(light, renderCamera.toScreen, light);
1099712382
....@@ -11081,8 +12466,76 @@
1108112466
1108212467 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1108312468
11084
- String program =
12469
+ String programmin =
12470
+ // Min shader
1108512471 "!!ARBfp1.0\n" +
12472
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12473
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12474
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12475
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12476
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12477
+ "PARAM light2cam0 = program.env[10];" +
12478
+ "PARAM light2cam1 = program.env[11];" +
12479
+ "PARAM light2cam2 = program.env[12];" +
12480
+ "TEMP temp;" +
12481
+ "TEMP light;" +
12482
+ "TEMP ndotl;" +
12483
+ "TEMP normal;" +
12484
+ "TEMP depth;" +
12485
+ "TEMP eye;" +
12486
+ "TEMP pos;" +
12487
+
12488
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12489
+ Normalize("normal") +
12490
+ "MOV light, state.light[0].position;" +
12491
+ "DP3 ndotl.x, light, normal;" +
12492
+
12493
+ // shadow
12494
+ "MOV pos, fragment.texcoord[1];" +
12495
+ "MOV temp, pos;" +
12496
+ ShadowTextureFetch("depth", "temp", "1") +
12497
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12498
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12499
+
12500
+ // No shadow when out of frustum
12501
+ //"SGE temp.y, depth.z, zero123.y;" +
12502
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12503
+
12504
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12505
+
12506
+ // Backlit
12507
+ "MOV pos.w, zero123.y;" +
12508
+ "DP4 eye.x, pos, light2cam0;" +
12509
+ "DP4 eye.y, pos, light2cam1;" +
12510
+ "DP4 eye.z, pos, light2cam2;" +
12511
+ Normalize("eye") +
12512
+
12513
+ "DP3 ndotl.y, -eye, normal;" +
12514
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12515
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12516
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12517
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12518
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12519
+
12520
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12521
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12522
+
12523
+ // Pigment
12524
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12525
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12526
+ "MUL temp, temp, ndotl.x;" +
12527
+
12528
+ "MUL temp, temp, zero123.z;" +
12529
+
12530
+ //"MUL temp, temp, ndotl.y;" +
12531
+
12532
+ "MOV temp.w, zero123.y;" + // reset alpha
12533
+ "MOV result.color, temp;" +
12534
+ "END";
12535
+
12536
+ String programmax =
12537
+ "!!ARBfp1.0\n" +
12538
+
1108612539 //"OPTION ARB_fragment_program_shadow;" +
1108712540 "PARAM light2cam0 = program.env[10];" +
1108812541 "PARAM light2cam1 = program.env[11];" +
....@@ -11197,8 +12650,7 @@
1119712650 "TEMP shininess;" +
1119812651 "\n" +
1119912652 "MOV texSamp, one;" +
11200
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11201
-
12653
+
1120212654 "MOV mapgrid.x, one2048th.x;" +
1120312655 "MOV temp, fragment.texcoord[1];" +
1120412656 /*
....@@ -11219,20 +12671,20 @@
1121912671 "MUL temp, floor, mapgrid.x;" +
1122012672 //"TEX depth0, temp, texture[1], 2D;" +
1122112673 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11222
- TextureFetch("depth0", "temp", "1") +
12674
+ ShadowTextureFetch("depth0", "temp", "1") +
1122312675 "") +
1122412676 "ADD temp.x, temp.x, mapgrid.x;" +
1122512677 //"TEX depth1, temp, texture[1], 2D;" +
1122612678 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11227
- TextureFetch("depth1", "temp", "1") +
12679
+ ShadowTextureFetch("depth1", "temp", "1") +
1122812680 "") +
1122912681 "ADD temp.y, temp.y, mapgrid.x;" +
1123012682 //"TEX depth2, temp, texture[1], 2D;" +
11231
- TextureFetch("depth2", "temp", "1") +
12683
+ ShadowTextureFetch("depth2", "temp", "1") +
1123212684 "SUB temp.x, temp.x, mapgrid.x;" +
1123312685 //"TEX depth3, temp, texture[1], 2D;" +
1123412686 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11235
- TextureFetch("depth3", "temp", "1") +
12687
+ ShadowTextureFetch("depth3", "temp", "1") +
1123612688 "") +
1123712689 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1123812690 //"MOV params, material;" +
....@@ -11603,10 +13055,10 @@
1160313055 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1160413056 "") +
1160513057
11606
- // display shadow only (bump == 0)
13058
+ // display shadow only (fakedepth == 0)
1160713059 "SUB temp.x, half.x, shadow.x;" +
11608
- "MOV temp.y, -params6.x;" +
11609
- "SLT temp.z, temp.y, zero.x;" +
13060
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13061
+ "SLT temp.z, temp.y, -c256i.x;" +
1161013062 "SUB temp.y, one.x, temp.z;" +
1161113063 "MUL temp.x, temp.x, temp.y;" +
1161213064 "KIL temp.x;" +
....@@ -11735,8 +13187,10 @@
1173513187 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1173613188
1173713189 "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
13190
+ // Tuning for default skin
13191
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13192
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13193
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1174013194 "MUL temp.x, temp.x, temp.y;" +
1174113195
1174213196 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11935,7 +13389,14 @@
1193513389 //once = true;
1193613390 }
1193713391
11938
- System.out.print("Program #" + mode + "; length = " + program.length());
13392
+ String program = programmax;
13393
+
13394
+ if (Globals.MINSHADER)
13395
+ {
13396
+ program = programmin;
13397
+ }
13398
+
13399
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1193913400 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1194013401 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1194113402
....@@ -12028,25 +13489,26 @@
1202813489 return out;
1202913490 }
1203013491
12031
- String TextureFetch(String dest, String src, String unit)
13492
+ // Also does frustum culling
13493
+ String ShadowTextureFetch(String dest, String src, String unit)
1203213494 {
1203313495 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1203413496 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1203513497 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13498
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13499
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1203613500 "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;" +
13501
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13502
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1204113503 //"SWZ buffer, temp, w,w,w,w;";
12042
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13504
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1204313505 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1204413506 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1204513507 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12046
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13508
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1204713509
12048
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12049
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13510
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13511
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1205013512 }
1205113513
1205213514 String Shadow(String depth, String shadow)
....@@ -12068,12 +13530,16 @@
1206813530
1206913531 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1207013532 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13533
+
13534
+ // Compare fragment depth in light space with shadowmap.
1207113535 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1207213536 "SGE temp.y, temp.x, zero.x;" +
12073
- "SUB " + shadow + ".y, one.x, temp.y;" +
13537
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13538
+
13539
+ // Reverse comparison
1207413540 "SUB temp.x, one.x, temp.x;" +
1207513541 "MUL " + shadow + ".x, temp.x, temp.y;" +
12076
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13542
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1207713543 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1207813544
1207913545 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12087,6 +13553,10 @@
1208713553 // No shadow for backface
1208813554 "DP3 temp.x, normal, lightd;" +
1208913555 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13556
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13557
+
13558
+ // No shadow when out of frustum
13559
+ "SGE temp.x, " + depth + ".z, one.z;" +
1209013560 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1209113561 "";
1209213562 }
....@@ -12233,7 +13703,8 @@
1223313703 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1223413704 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1223513705 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12236
- Object3D.cVector2[] vector2buffer;
13706
+
13707
+ //Object3D.cVector2[] vector2buffer;
1223713708
1223813709 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1223913710 // OUT : diff, spec
....@@ -12249,9 +13720,10 @@
1224913720 "DP3 " + dest + ".z," + "normals," + "eye;" +
1225013721 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1225113722 //"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;" +
13723
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13724
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13725
+
13726
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1225513727 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1225613728 "RCP " + dest + ".w," + dest + ".w;" +
1225713729 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -12645,7 +14117,7 @@
1264514117 public void mousePressed(MouseEvent e)
1264614118 {
1264714119 //System.out.println("mousePressed: " + e);
12648
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14120
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1264914121 }
1265014122
1265114123 static long prevtime = 0;
....@@ -12672,6 +14144,7 @@
1267214144
1267314145 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1267414146
14147
+ if (BUTTONLESSWHEEL)
1267514148 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1267614149 {
1267714150 return;
....@@ -12680,7 +14153,7 @@
1268014153 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1268114154
1268214155 // TIMER
12683
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14156
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1268414157 {
1268514158 keepboxmode = BOXMODE;
1268614159 keepsupport = SUPPORT;
....@@ -12720,8 +14193,8 @@
1272014193 // mode |= META;
1272114194 //}
1272214195
12723
- SetMouseMode(WHEEL | e.getModifiersEx());
12724
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14196
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14197
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1272514198 anchorX = ax;
1272614199 anchorY = ay;
1272714200 prevX = px;
....@@ -12755,6 +14228,7 @@
1275514228 else
1275614229 if (evt.getSource() == AAtimer)
1275714230 {
14231
+ Globals.TIMERRUNNING = false;
1275814232 if (mouseDown)
1275914233 {
1276014234 //new Exception().printStackTrace();
....@@ -12780,6 +14254,10 @@
1278014254 // LIVE = waslive;
1278114255 // wasliveok = true;
1278214256 // waslive = false;
14257
+
14258
+ // May 2019 Forget it:
14259
+ if (true)
14260
+ return;
1278314261
1278414262 // source == timer
1278514263 if (mouseDown)
....@@ -12810,7 +14288,7 @@
1281014288
1281114289 // fev 2014???
1281214290 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
12813
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14291
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1281414292 pingthread.StepToTarget(true); // true);
1281514293 }
1281614294 // if (!LIVE)
....@@ -12819,12 +14297,13 @@
1281914297
1282014298 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1282114299
12822
- void clickStart(int x, int y, int modifiers)
14300
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1282314301 {
1282414302 if (!wasliveok)
1282514303 return;
1282614304
1282714305 AAtimer.restart(); //
14306
+ Globals.TIMERRUNNING = true;
1282814307
1282914308 // waslive = LIVE;
1283014309 // LIVE = false;
....@@ -12836,7 +14315,7 @@
1283614315 // touched = true; // main DL
1283714316 if (isRenderer)
1283814317 {
12839
- SetMouseMode(modifiers);
14318
+ SetMouseMode(modifiers, modifiersex);
1284014319 }
1284114320
1284214321 selectX = anchorX = x;
....@@ -12849,7 +14328,7 @@
1284914328 clicked = true;
1285014329 hold = false;
1285114330
12852
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14331
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1285314332 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1285414333 {
1285514334 // System.out.println("RESTART II " + modifiers);
....@@ -12874,14 +14353,15 @@
1287414353 drag = false;
1287514354 //System.out.println("Mouse DOWN");
1287614355 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);
14356
+ //ClickInfo info = new ClickInfo();
14357
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14358
+ object.clickInfo.pane = this;
14359
+ object.clickInfo.camera = renderCamera;
14360
+ object.clickInfo.x = x;
14361
+ object.clickInfo.y = y;
14362
+ object.clickInfo.modifiers = modifiersex;
14363
+ editObj = object.doEditClick(//info,
14364
+ 0);
1288514365 if (!editObj)
1288614366 {
1288714367 hasMarquee = true;
....@@ -12897,11 +14377,14 @@
1289714377
1289814378 public void mouseDragged(MouseEvent e)
1289914379 {
14380
+ Globals.MOUSEDRAGGED = true;
14381
+
14382
+ //System.out.println("mouseDragged: " + e);
1290014383 if (isRenderer)
1290114384 movingcamera = true;
14385
+
1290214386 //if (drawing)
1290314387 //return;
12904
- //System.out.println("mouseDragged: " + e);
1290514388 if ((e.getModifiersEx() & CTRL) != 0
1290614389 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1290714390 {
....@@ -12909,7 +14392,7 @@
1290914392 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1291014393 }
1291114394 else
12912
- drag(e.getX(), e.getY(), e.getModifiersEx());
14395
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1291314396
1291414397 //try { Thread.sleep(1); } catch (Exception ex) {}
1291514398 }
....@@ -12921,6 +14404,11 @@
1292114404 cVector tmp = new cVector();
1292214405 cVector tmp2 = new cVector();
1292314406 boolean isMoving;
14407
+
14408
+ public cVector TargetLookAt()
14409
+ {
14410
+ return targetLookAt;
14411
+ }
1292414412
1292514413 class PingThread extends Thread
1292614414 {
....@@ -13077,6 +14565,7 @@
1307714565
1307814566 public void run()
1307914567 {
14568
+ new Exception().printStackTrace();
1308014569 System.exit(0);
1308114570 for (;;)
1308214571 {
....@@ -13140,7 +14629,7 @@
1314014629 {
1314114630 Globals.lighttouched = true;
1314214631 }
13143
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14632
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1314414633 }
1314514634 //else
1314614635 }
....@@ -13154,12 +14643,12 @@
1315414643 void GoDown(int mod)
1315514644 {
1315614645 MODIFIERS |= COMMAND;
13157
- /*
14646
+ /**/
1315814647 if((mod&SHIFT) == SHIFT)
13159
- manipCamera.RotatePosition(0, -speed);
14648
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1316014649 else
13161
- manipCamera.BackForth(0, -speed*delta, getWidth());
13162
- */
14650
+ manipCamera.RotatePosition(0, -speed);
14651
+ /**/
1316314652 if ((mod & SHIFT) == SHIFT)
1316414653 {
1316514654 mouseMode = mouseMode; // VR??
....@@ -13175,12 +14664,12 @@
1317514664 void GoUp(int mod)
1317614665 {
1317714666 MODIFIERS |= COMMAND;
13178
- /*
14667
+ /**/
1317914668 if((mod&SHIFT) == SHIFT)
13180
- manipCamera.RotatePosition(0, speed);
14669
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1318114670 else
13182
- manipCamera.BackForth(0, speed*delta, getWidth());
13183
- */
14671
+ manipCamera.RotatePosition(0, speed);
14672
+ /**/
1318414673 if ((mod & SHIFT) == SHIFT)
1318514674 {
1318614675 mouseMode = mouseMode;
....@@ -13196,12 +14685,12 @@
1319614685 void GoLeft(int mod)
1319714686 {
1319814687 MODIFIERS |= COMMAND;
13199
- /*
14688
+ /**/
1320014689 if((mod&SHIFT) == SHIFT)
13201
- manipCamera.RotatePosition(speed, 0);
13202
- else
1320314690 manipCamera.Translate(speed*delta, 0, getWidth());
13204
- */
14691
+ else
14692
+ manipCamera.RotatePosition(speed, 0);
14693
+ /**/
1320514694 if ((mod & SHIFT) == SHIFT)
1320614695 {
1320714696 mouseMode = mouseMode;
....@@ -13217,12 +14706,12 @@
1321714706 void GoRight(int mod)
1321814707 {
1321914708 MODIFIERS |= COMMAND;
13220
- /*
14709
+ /**/
1322114710 if((mod&SHIFT) == SHIFT)
13222
- manipCamera.RotatePosition(-speed, 0);
13223
- else
1322414711 manipCamera.Translate(-speed*delta, 0, getWidth());
13225
- */
14712
+ else
14713
+ manipCamera.RotatePosition(-speed, 0);
14714
+ /**/
1322614715 if ((mod & SHIFT) == SHIFT)
1322714716 {
1322814717 mouseMode = mouseMode;
....@@ -13240,7 +14729,7 @@
1324014729 int X, Y;
1324114730 boolean SX, SY;
1324214731
13243
- void drag(int x, int y, int modifiers)
14732
+ void drag(int x, int y, int modifiers, int modifiersex)
1324414733 {
1324514734 if (IsFrozen())
1324614735 {
....@@ -13249,17 +14738,17 @@
1324914738
1325014739 drag = true; // NEW
1325114740
13252
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14741
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1325314742
1325414743 X = x;
1325514744 Y = y;
1325614745 // floating state for animation
13257
- MODIFIERS = modifiers;
13258
- modifiers &= ~1024;
14746
+ MODIFIERS = modifiersex;
14747
+ modifiersex &= ~1024;
1325914748 if (false) // modifiers != 0)
1326014749 {
1326114750 //new Exception().printStackTrace();
13262
- System.out.println("mouseDragged: " + modifiers);
14751
+ System.out.println("mouseDragged: " + modifiersex);
1326314752 System.out.println("SHIFT = " + SHIFT);
1326414753 System.out.println("CONTROL = " + COMMAND);
1326514754 System.out.println("META = " + META);
....@@ -13272,14 +14761,16 @@
1327214761 if (editObj)
1327314762 {
1327414763 drag = true;
13275
- ClickInfo info = new ClickInfo();
13276
- info.bounds.setBounds(0, 0,
14764
+ //ClickInfo info = new ClickInfo();
14765
+ object.clickInfo.bounds.setBounds(0, 0,
1327714766 (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);
14767
+ object.clickInfo.pane = this;
14768
+ object.clickInfo.camera = renderCamera;
14769
+ object.clickInfo.x = x;
14770
+ object.clickInfo.y = y;
14771
+ object //.GetWindow().copy
14772
+ .doEditDrag(//info,
14773
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1328314774 } else
1328414775 {
1328514776 if (x < startX)
....@@ -13428,23 +14919,27 @@
1342814919 }
1342914920 }
1343014921
14922
+// ClickInfo clickInfo = new ClickInfo();
14923
+
1343114924 public void mouseMoved(MouseEvent e)
1343214925 {
1343314926 //System.out.println("mouseMoved: " + e);
13434
-
1343514927 if (isRenderer)
1343614928 return;
1343714929
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;
14930
+ // Mouse cursor feedback
14931
+ object.clickInfo.x = e.getX();
14932
+ object.clickInfo.y = e.getY();
14933
+ object.clickInfo.modifiers = e.getModifiersEx();
14934
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14935
+ object.clickInfo.pane = this;
14936
+ object.clickInfo.camera = renderCamera;
1344514937 if (!isRenderer)
1344614938 {
13447
- if (object.editWindow.copy.doEditClick(ci, 0))
14939
+ //ObjEditor editWindow = object.editWindow;
14940
+ //Object3D copy = editWindow.copy;
14941
+ if (object.doEditClick(//clickInfo,
14942
+ 0))
1344814943 {
1344914944 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1345014945 } else
....@@ -13456,7 +14951,11 @@
1345614951
1345714952 public void mouseReleased(MouseEvent e)
1345814953 {
14954
+ Globals.MOUSEDRAGGED = false;
14955
+
1345914956 movingcamera = false;
14957
+ X = 0; // getBounds().width/2;
14958
+ Y = 0; // getBounds().height/2;
1346014959 //System.out.println("mouseReleased: " + e);
1346114960 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1346214961 }
....@@ -13479,9 +14978,9 @@
1347914978 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1348014979 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1348114980
13482
- if (control || command || IsFrozen())
14981
+// No delay if (control || command || IsFrozen())
1348314982 timeout = true;
13484
- else
14983
+// ?? May 2019 else
1348514984 // timer.setDelay((modifiers & 128) != 0?0:350);
1348614985 mouseDown = false;
1348714986 if (!control && !command) // june 2013
....@@ -13591,7 +15090,7 @@
1359115090 System.out.println("keyReleased: " + e);
1359215091 }
1359315092
13594
- void SetMouseMode(int modifiers)
15093
+ void SetMouseMode(int modifiers, int modifiersex)
1359515094 {
1359615095 //System.out.println("SetMouseMode = " + modifiers);
1359715096 //modifiers &= ~1024;
....@@ -13603,25 +15102,25 @@
1360315102 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1360415103 // return;
1360515104 //System.out.println("SetMode = " + modifiers);
13606
- if ((modifiers & WHEEL) == WHEEL)
15105
+ if ((modifiersex & WHEEL) == WHEEL)
1360715106 {
1360815107 mouseMode |= ZOOM;
1360915108 }
1361015109
1361115110 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
13612
- if (capsLocked || (modifiers & META) == META)
15111
+ if (capsLocked) // || (modifiers & META) == META)
1361315112 {
1361415113 mouseMode |= VR; // BACKFORTH;
1361515114 }
13616
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15115
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1361715116 {
1361815117 mouseMode |= SELECT;
1361915118 }
13620
- if ((modifiers & COMMAND) == COMMAND)
15119
+ if ((modifiersex & COMMAND) == COMMAND)
1362115120 {
1362215121 mouseMode |= SELECT;
1362315122 }
13624
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15123
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1362515124 {
1362615125 mouseMode &= ~VR;
1362715126 mouseMode |= TRANSLATE;
....@@ -13650,10 +15149,10 @@
1365015149
1365115150 if (isRenderer) //
1365215151 {
13653
- SetMouseMode(modifiers);
15152
+ SetMouseMode(0, modifiers);
1365415153 }
1365515154
13656
- theRenderer.keyPressed(key);
15155
+ Globals.theRenderer.keyPressed(key);
1365715156 }
1365815157
1365915158 int kompactbit = 4; // power bit
....@@ -13665,7 +15164,7 @@
1366515164 float SATPOW = 1; // 2; // 0.5f;
1366615165 float BRIPOW = 1; // 0.5f; // 0.5f;
1366715166
13668
- void keyPressed(int key)
15167
+ public void keyPressed(int key)
1366915168 {
1367015169 if (key >= '0' && key <= '5')
1367115170 clampbit = (key-'0');
....@@ -13712,7 +15211,8 @@
1371215211 // break;
1371315212 case 'T':
1371415213 CACHETEXTURE ^= true;
13715
- textures.clear();
15214
+ texturepigment.clear();
15215
+ texturebump.clear();
1371615216 // repaint();
1371715217 break;
1371815218 case 'Y':
....@@ -13797,7 +15297,9 @@
1379715297 case 'E' : COMPACT ^= true;
1379815298 repaint();
1379915299 break;
13800
- case 'W' : DEBUGHSB ^= true;
15300
+ case 'W' : // Wide Window (fullscreen)
15301
+ //DEBUGHSB ^= true;
15302
+ ObjEditor.theFrame.ToggleFullScreen();
1380115303 repaint();
1380215304 break;
1380315305 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13822,8 +15324,8 @@
1382215324 RevertCamera();
1382315325 repaint();
1382415326 break;
13825
- case 'L':
1382615327 case 'l':
15328
+ //case 'L':
1382715329 if (lightMode)
1382815330 {
1382915331 lightMode = false;
....@@ -13887,20 +15389,24 @@
1388715389 OCCLUSION_CULLING ^= true;
1388815390 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1388915391 break;
13890
- case '0': envyoff ^= true; repaint(); break;
15392
+ //case '0': envyoff ^= true; repaint(); break;
1389115393 case '1':
1389215394 case '2':
1389315395 case '3':
1389415396 case '4':
1389515397 case '5':
13896
- newenvy = Character.getNumericValue(key);
13897
- repaint();
13898
- break;
1389915398 case '6':
1390015399 case '7':
1390115400 case '8':
1390215401 case '9':
13903
- BGcolor = (key - '6')/3.f;
15402
+ if (true) // envyoff)
15403
+ {
15404
+ BGcolor = (key - '1')/8.f;
15405
+ }
15406
+ else
15407
+ {
15408
+ //newenvy = Character.getNumericValue(key);
15409
+ }
1390415410 repaint();
1390515411 break;
1390615412 case '!':
....@@ -13966,9 +15472,9 @@
1396615472 case '_':
1396715473 kompactbit = 5;
1396815474 break;
13969
- case '+':
13970
- kompactbit = 6;
13971
- break;
15475
+// case '+':
15476
+// kompactbit = 6;
15477
+// break;
1397215478 case ' ':
1397315479 lightMode ^= true;
1397415480 Globals.lighttouched = true;
....@@ -13980,13 +15486,14 @@
1398015486 case ESC:
1398115487 RENDERPROGRAM += 1;
1398215488 RENDERPROGRAM %= 3;
15489
+
1398315490 repaint();
1398415491 break;
1398515492 case 'Z':
1398615493 //RESIZETEXTURE ^= true;
1398715494 //break;
1398815495 case 'z':
13989
- RENDERSHADOW ^= true;
15496
+ Globals.RENDERSHADOW ^= true;
1399015497 Globals.lighttouched = true;
1399115498 repaint();
1399215499 break;
....@@ -14019,8 +15526,9 @@
1401915526 case DELETE:
1402015527 ClearSelection();
1402115528 break;
14022
- /*
1402315529 case '+':
15530
+
15531
+ /*
1402415532 //fontsize += 1;
1402515533 bbzoom *= 2;
1402615534 repaint();
....@@ -14037,17 +15545,17 @@
1403715545 case '=':
1403815546 IncDepth();
1403915547 //fontsize += 1;
14040
- object.editWindow.refreshContents(true);
15548
+ object.GetWindow().refreshContents(true);
1404115549 maskbit = 6;
1404215550 break;
1404315551 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1404415552 DecDepth();
1404515553 maskbit = 5;
1404615554 //if(fontsize > 1) fontsize -= 1;
14047
- if (object.editWindow == null)
14048
- new Exception().printStackTrace();
14049
- else
14050
- object.editWindow.refreshContents(true);
15555
+// if (object.editWindow == null)
15556
+// new Exception().printStackTrace();
15557
+// else
15558
+ object.GetWindow().refreshContents(true);
1405115559 break;
1405215560 case '{':
1405315561 manipCamera.shaper_fovy /= 1.1;
....@@ -14102,6 +15610,7 @@
1410215610 }
1410315611 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1410415612 }
15613
+
1410515614 static double OCCLUSIONBOOST = 1; // 0.5;
1410615615
1410715616 void keyReleased(int key, int modifiers)
....@@ -14109,11 +15618,11 @@
1410915618 //mode = ROTATE;
1411015619 if ((MODIFIERS & COMMAND) == 0) // VR??
1411115620 {
14112
- SetMouseMode(modifiers);
15621
+ SetMouseMode(0, modifiers);
1411315622 }
1411415623 }
1411515624
14116
- protected void processKeyEvent(KeyEvent e)
15625
+ public void processKeyEvent(KeyEvent e)
1411715626 {
1411815627 switch (e.getID())
1411915628 {
....@@ -14243,8 +15752,9 @@
1424315752
1424415753 protected void processMouseMotionEvent(MouseEvent e)
1424515754 {
14246
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14247
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15755
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15756
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15757
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1424815758 {
1424915759 mouseMoved(e);
1425015760 } else
....@@ -14269,11 +15779,12 @@
1426915779 }
1427015780 */
1427115781
14272
- object.editWindow.EditSelection();
15782
+ object.GetWindow().EditSelection(false);
1427315783 }
1427415784
1427515785 void SelectParent()
1427615786 {
15787
+ new Exception().printStackTrace();
1427715788 System.exit(0);
1427815789 Composite group = (Composite) object;
1427915790 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14285,10 +15796,10 @@
1428515796 {
1428615797 //selectees.remove(i);
1428715798 System.out.println("select parent of " + elem);
14288
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15799
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1428915800 } else
1429015801 {
14291
- group.editWindow.Select(elem.GetTreePath(), first, true);
15802
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1429215803 }
1429315804
1429415805 first = false;
....@@ -14297,6 +15808,7 @@
1429715808
1429815809 void SelectChildren()
1429915810 {
15811
+ new Exception().printStackTrace();
1430015812 System.exit(0);
1430115813 /*
1430215814 Composite group = (Composite) object;
....@@ -14329,12 +15841,12 @@
1432915841 for (int j = 0; j < group.children.size(); j++)
1433015842 {
1433115843 elem = (Object3D) group.children.elementAt(j);
14332
- object.editWindow.Select(elem.GetTreePath(), first, true);
15844
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1433315845 first = false;
1433415846 }
1433515847 } else
1433615848 {
14337
- object.editWindow.Select(elem.GetTreePath(), first, true);
15849
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1433815850 }
1433915851
1434015852 first = false;
....@@ -14345,21 +15857,21 @@
1434515857 {
1434615858 //Composite group = (Composite) object;
1434715859 Object3D group = object;
14348
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15860
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1434915861 }
1435015862
1435115863 void ResetTransform(int mask)
1435215864 {
1435315865 //Composite group = (Composite) object;
1435415866 Object3D group = object;
14355
- group.editWindow.ResetTransform(mask);
15867
+ group.GetWindow().ResetTransform(mask);
1435615868 }
1435715869
1435815870 void FlipTransform()
1435915871 {
1436015872 //Composite group = (Composite) object;
1436115873 Object3D group = object;
14362
- group.editWindow.FlipTransform();
15874
+ group.GetWindow().FlipTransform();
1436315875 // group.editWindow.ReduceMesh(true);
1436415876 }
1436515877
....@@ -14367,7 +15879,7 @@
1436715879 {
1436815880 //Composite group = (Composite) object;
1436915881 Object3D group = object;
14370
- group.editWindow.PrintMemory();
15882
+ group.GetWindow().PrintMemory();
1437115883 // group.editWindow.ReduceMesh(true);
1437215884 }
1437315885
....@@ -14375,7 +15887,7 @@
1437515887 {
1437615888 //Composite group = (Composite) object;
1437715889 Object3D group = object;
14378
- group.editWindow.ResetCentroid();
15890
+ group.GetWindow().ResetCentroid();
1437915891 }
1438015892
1438115893 void IncDepth()
....@@ -14457,11 +15969,11 @@
1445715969
1445815970 int width = getBounds().width;
1445915971 int height = getBounds().height;
14460
- ClickInfo info = new ClickInfo();
14461
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1446215972 //Image img = CreateImage(width, height);
1446315973 //System.out.println("width = " + width + "; height = " + height + "\n");
15974
+
1446415975 Graphics gr = g; // img.getGraphics();
15976
+
1446515977 if (!hasMarquee)
1446615978 {
1446715979 if (Xmin < Xmax) // !locked)
....@@ -14533,40 +16045,88 @@
1453316045 }
1453416046 if (object != null && !hasMarquee)
1453516047 {
16048
+ if (object.clickInfo == null)
16049
+ object.clickInfo = new ClickInfo();
16050
+ ClickInfo info = object.clickInfo;
16051
+ //ClickInfo info = new ClickInfo();
16052
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16053
+
1453616054 if (isRenderer)
1453716055 {
14538
- info.flags++;
16056
+ object.clickInfo.flags++;
1453916057 double frameAspect = (double) width / (double) height;
1454016058 if (frameAspect > renderCamera.aspect)
1454116059 {
1454216060 int desired = (int) ((double) height * renderCamera.aspect);
14543
- info.bounds.width -= width - desired;
14544
- info.bounds.x += (width - desired) / 2;
16061
+ object.clickInfo.bounds.width -= width - desired;
16062
+ object.clickInfo.bounds.x += (width - desired) / 2;
1454516063 } else
1454616064 {
1454716065 int desired = (int) ((double) width / renderCamera.aspect);
14548
- info.bounds.height -= height - desired;
14549
- info.bounds.y += (height - desired) / 2;
16066
+ object.clickInfo.bounds.height -= height - desired;
16067
+ object.clickInfo.bounds.y += (height - desired) / 2;
1455016068 }
1455116069 }
14552
- info.g = gr;
14553
- info.camera = renderCamera;
16070
+
16071
+ object.clickInfo.g = gr;
16072
+ object.clickInfo.camera = renderCamera;
1455416073 /*
1455516074 // Memory intensive (brep.verticescopy)
1455616075 if (!(object instanceof Composite))
1455716076 object.draw(info, 0, false); // SLOW :
1455816077 */
14559
- if (!isRenderer)
16078
+ if (!isRenderer) // && drag)
1456016079 {
14561
- object.drawEditHandles(info, 0);
16080
+ Grafreed.Assert(object != null);
16081
+ Grafreed.Assert(object.selection != null);
16082
+ if (object.selection.Size() > 0)
16083
+ {
16084
+ int hitSomething = object.selection.get(0).hitSomething;
16085
+
16086
+ object.clickInfo.DX = 0;
16087
+ object.clickInfo.DY = 0;
16088
+ object.clickInfo.W = 1;
16089
+ if (hitSomething == Object3D.hitCenter)
16090
+ {
16091
+ info.DX = X;
16092
+ if (X != 0)
16093
+ info.DX -= info.bounds.width/2;
16094
+
16095
+ info.DY = Y;
16096
+ if (Y != 0)
16097
+ info.DY -= info.bounds.height/2;
16098
+ }
16099
+
16100
+ object.drawEditHandles(//info,
16101
+ 0);
16102
+
16103
+ if (drag && (X != 0 || Y != 0))
16104
+ {
16105
+ switch (hitSomething)
16106
+ {
16107
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16108
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16109
+ break;
16110
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16111
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16112
+ break;
16113
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16114
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16115
+ break;
16116
+ }
16117
+
16118
+ }
16119
+ }
1456216120 }
1456316121 }
16122
+
1456416123 if (isRenderer)
1456516124 {
1456616125 //gr.setColor(Color.black);
1456716126 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1456816127 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1456916128 }
16129
+
1457016130 if (hasMarquee)
1457116131 {
1457216132 gr.setXORMode(Color.white);
....@@ -14679,6 +16239,7 @@
1467916239 public boolean mouseDown(Event evt, int x, int y)
1468016240 {
1468116241 System.out.println("mouseDown: " + evt);
16242
+ System.exit(0);
1468216243 /*
1468316244 locked = true;
1468416245 drag = false;
....@@ -14722,7 +16283,7 @@
1472216283 {
1472316284 keyPressed(0, modifiers);
1472416285 }
14725
- clickStart(x, y, modifiers);
16286
+ // clickStart(x, y, modifiers);
1472616287 return true;
1472716288 }
1472816289
....@@ -14840,7 +16401,7 @@
1484016401 {
1484116402 keyReleased(0, 0);
1484216403 }
14843
- drag(x, y, modifiers);
16404
+ drag(x, y, 0, modifiers);
1484416405 return true;
1484516406 }
1484616407
....@@ -14972,7 +16533,7 @@
1497216533 Object3D object;
1497316534 static Object3D trackedobject;
1497416535 Camera renderCamera; // Light or Eye (or Occlusion)
14975
- /*static*/ Camera manipCamera; // Light or Eye
16536
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1497616537 /*static*/ Camera eyeCamera;
1497716538 /*static*/ Camera lightCamera;
1497816539 int cameracount;
....@@ -15036,6 +16597,8 @@
1503616597 private /*static*/ boolean firstime;
1503716598 private /*static*/ cVector newView = new cVector();
1503816599 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16600
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16601
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1503916602 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1504016603 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1504116604 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15048,29 +16611,67 @@
1504816611 {
1504916612 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1505016613
16614
+ int usedsuf = 0;
16615
+
1505116616 for (int i = 0; i < suffixes.length; i++)
1505216617 {
15053
- String resourceName = basename + suffixes[i] + "." + suffix;
15054
- TextureData data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
15055
- mipmapped,
15056
- FileUtil.getFileSuffix(resourceName));
15057
- if (data == null)
16618
+ String[] suffixe = suffixes;
16619
+ String[] fallback = suffixes2;
16620
+ String[] fallfallback = suffixes3;
16621
+
16622
+ for (int c=usedsuf; --c>=0;)
1505816623 {
15059
- throw new IOException("Unable to load texture " + resourceName);
16624
+// String[] temp = suffixe;
16625
+// suffixe = fallback;
16626
+// fallback = fallfallback;
16627
+// fallfallback = temp;
1506016628 }
16629
+
16630
+ String resourceName = basename + suffixe[i] + "." + suffix;
16631
+ TextureData data;
16632
+
16633
+ try
16634
+ {
16635
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16636
+ mipmapped,
16637
+ FileUtil.getFileSuffix(resourceName));
16638
+ }
16639
+ catch (Exception e)
16640
+ {
16641
+ try
16642
+ {
16643
+ resourceName = basename + fallback[i] + "." + suffix;
16644
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16645
+ mipmapped,
16646
+ FileUtil.getFileSuffix(resourceName));
16647
+ }
16648
+ catch (Exception e2)
16649
+ {
16650
+ resourceName = basename + fallfallback[i] + "." + suffix;
16651
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16652
+ mipmapped,
16653
+ FileUtil.getFileSuffix(resourceName));
16654
+ }
16655
+ }
16656
+
1506116657 //System.out.println("Target = " + targets[i]);
1506216658 cubemap.updateImage(data, targets[i]);
1506316659 }
1506416660
1506516661 return cubemap;
1506616662 }
16663
+
1506716664 int bigsphere = -1;
1506816665
1506916666 float BGcolor = 0.5f;
1507016667
15071
- private void DrawSkyBox(GL gl)
16668
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16669
+
16670
+ private void DrawSkyBox(GL gl, float ratio)
1507216671 {
15073
- if (envyoff || cubemap == null)
16672
+ if (//envyoff ||
16673
+ WIREFRAME ||
16674
+ cubemap == null)
1507416675 {
1507516676 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1507616677 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15085,7 +16686,17 @@
1508516686 // Compensates for ExaminerViewer's modification of modelview matrix
1508616687 gl.glMatrixMode(GL.GL_MODELVIEW);
1508716688 gl.glLoadIdentity();
16689
+ gl.glScalef(1,ratio,1);
1508816690
16691
+// colorV[0] = 2;
16692
+// colorV[1] = 2;
16693
+// colorV[2] = 2;
16694
+// colorV[3] = 1;
16695
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16696
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16697
+//
16698
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16699
+
1508916700 //gl.glActiveTexture(GL.GL_TEXTURE1);
1509016701 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1509116702
....@@ -15117,6 +16728,7 @@
1511716728 {
1511816729 gl.glScalef(1.0f, -1.0f, 1.0f);
1511916730 }
16731
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1512016732 gl.glMultMatrixd(viewrot_1, 0);
1512116733 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1512216734 //viewer.updateInverseRotation(gl);
....@@ -15257,16 +16869,16 @@
1525716869 cStatic.objectstack[materialdepth++] = checker;
1525816870 //System.out.println("material " + material);
1525916871 //Applet3D.tracein(this, selected);
15260
- vector2buffer = checker.projectedVertices;
16872
+ //vector2buffer = checker.projectedVertices;
1526116873
1526216874 //checker.GetMaterial().Draw(this, false); // true);
15263
- DrawMaterial(checker.GetMaterial(), false); // true);
16875
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1526416876
1526516877 materialdepth -= 1;
1526616878 if (materialdepth > 0)
1526716879 {
15268
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15269
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16880
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16881
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1527016882 }
1527116883 //checker.GetMaterial().opacity = 1f;
1527216884 ////checker.GetMaterial().ambient = 1f;
....@@ -15352,6 +16964,14 @@
1535216964 }
1535316965 }
1535416966
16967
+ private Object3D GetFolder()
16968
+ {
16969
+ Object3D folder = object.GetWindow().copy;
16970
+ if (object.GetWindow().copy.selection.Size() > 0)
16971
+ folder = object.GetWindow().copy.selection.elementAt(0);
16972
+ return folder;
16973
+ }
16974
+
1535516975 class SelectBuffer implements GLEventListener
1535616976 {
1535716977
....@@ -15367,7 +16987,7 @@
1536716987 //new Exception().printStackTrace();
1536816988 System.out.println("select buffer init");
1536916989 // Use debug pipeline
15370
- drawable.setGL(new DebugGL(drawable.getGL()));
16990
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1537116991
1537216992 GL gl = drawable.getGL();
1537316993
....@@ -15410,6 +17030,7 @@
1541017030 {
1541117031 if (!selection)
1541217032 {
17033
+ new Exception().printStackTrace();
1541317034 System.exit(0);
1541417035 return;
1541517036 }
....@@ -15430,6 +17051,17 @@
1543017051
1543117052 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1543217053
17054
+ if (PAINTMODE)
17055
+ {
17056
+ if (object.GetWindow().copy.selection.Size() > 0)
17057
+ {
17058
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17059
+
17060
+ // Make what you paint not selectable.
17061
+ paintobj.ResetSelectable();
17062
+ }
17063
+ }
17064
+
1543317065 //int tmp = selection_view;
1543417066 //selection_view = -1;
1543517067 int temp = DrawMode();
....@@ -15441,6 +17073,17 @@
1544117073 // temp = DEFAULT; // patch for selection debug
1544217074 Globals.drawMode = temp; // WARNING
1544317075
17076
+ if (PAINTMODE)
17077
+ {
17078
+ if (object.GetWindow().copy.selection.Size() > 0)
17079
+ {
17080
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17081
+
17082
+ // Revert.
17083
+ paintobj.RestoreSelectable();
17084
+ }
17085
+ }
17086
+
1544417087 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1544517088
1544617089 // trying different ways of getting the depth info over
....@@ -15488,6 +17131,8 @@
1548817131 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1548917132 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1549017133 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17134
+
17135
+ CreateSelectedPoint();
1549117136
1549217137 // Will fit the mesh !!!
1549317138 selectedpoint.toParent[0][0] = 0.0001;
....@@ -15537,34 +17182,36 @@
1553717182 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]));
1553817183 }
1553917184
15540
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17185
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1554117186 }
1554217187 }
1554317188
1554417189 if (!movingcamera && !PAINTMODE)
15545
- object.editWindow.ScreenFitPoint(); // fev 2014
17190
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1554617191
15547
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17192
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1554817193 {
15549
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17194
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1555017195
15551
- Object3D group = new Object3D("inst" + paintcount++);
17196
+ if (object.GetWindow().copy.selection.Size() > 0)
17197
+ {
17198
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1555217199
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();
17200
+ Object3D inst = new Object3D("inst" + paintcount++);
17201
+
17202
+ inst.CreateMaterial(); // use a void leaf to select instances
17203
+
17204
+ inst.add(paintobj); // link
17205
+
17206
+ object.GetWindow().SnapObject(inst);
17207
+
17208
+ Object3D folder = paintFolder; // GetFolder();
17209
+
17210
+ folder.add(inst);
17211
+
17212
+ object.GetWindow().ResetModel();
17213
+ object.GetWindow().refreshContents();
17214
+ }
1556817215 }
1556917216 else
1557017217 paintcount = 0;
....@@ -15603,6 +17250,11 @@
1560317250 //System.out.println("objects[color] = " + objects[color]);
1560417251 //objects[color].Select();
1560517252 indexcount = 0;
17253
+ ObjEditor window = object.GetWindow();
17254
+ if (window != null && deselect)
17255
+ {
17256
+ window.Select(null, deselect, true);
17257
+ }
1560617258 object.Select(color, deselect);
1560717259 }
1560817260
....@@ -15702,7 +17354,7 @@
1570217354 gl.glDisable(gl.GL_CULL_FACE);
1570317355 }
1570417356
15705
- if (!RENDERSHADOW)
17357
+ if (!Globals.RENDERSHADOW)
1570617358 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1570717359
1570817360 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -15712,7 +17364,7 @@
1571217364 //gl.glColorMask(false, false, false, false);
1571317365
1571417366 //render_scene_from_light_view(gl, drawable, 0, 0);
15715
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17367
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1571617368 {
1571717369 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1571817370
....@@ -15772,7 +17424,6 @@
1577217424
1577317425 class AntialiasBuffer implements GLEventListener
1577417426 {
15775
-
1577617427 CameraPane parent = null;
1577717428
1577817429 AntialiasBuffer(CameraPane p)
....@@ -16129,23 +17780,15 @@
1612917780 int AAbuffersize = 0;
1613017781
1613117782 //double[] selectedpoint = new double[3];
16132
- static Superellipsoid selectedpoint = new Superellipsoid();
17783
+ static Superellipsoid selectedpoint;
1613317784 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();
17785
+ static Sphere debugpointG;
17786
+ static Sphere debugpointP;
17787
+ static Sphere debugpointC;
17788
+ static Sphere debugpointR;
1613817789
1613917790 static Sphere debugpoints[] = new Sphere[8];
1614017791
16141
- static
16142
- {
16143
- for (int i=0; i<8; i++)
16144
- {
16145
- debugpoints[i] = new Sphere();
16146
- }
16147
- }
16148
-
1614917792 static void InitPoints(float radius)
1615017793 {
1615117794 for (int i=0; i<8; i++)
....@@ -16165,7 +17808,7 @@
1616517808 }
1616617809 }
1616717810
16168
- static void DrawPoints(CameraPane cpane)
17811
+ static void DrawPoints(iCameraPane cpane)
1616917812 {
1617017813 for (int i=0; i<8; i++) // first and last are red
1617117814 {
....@@ -16197,10 +17840,11 @@
1619717840 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1619817841 // Depth buffer format
1619917842 //private int depth_format;
16200
- static public void NextIndex(Object3D o, GL gl)
17843
+
17844
+ public void NextIndex()
1620117845 {
1620217846 indexcount+=16;
16203
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17847
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1620417848 //objects[indexcount] = o;
1620517849 //System.out.println("indexcount = " + indexcount);
1620617850 }