Normand Briere
2019-08-13 c67de8aca04d988179191ccb52461af00125920e
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -76,7 +110,9 @@
76110 //private Mat4f spotlightTransform = new Mat4f();
77111 //private Mat4f spotlightInverseTransform = new Mat4f();
78112 static GLContext glcontext = null;
79
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
80116 boolean reverseUP = false;
81117 static boolean frozen = false;
82118 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -92,6 +128,8 @@
92128
93129 static int tickcount = 0; // slow pose issue
94130
131
+static boolean BUTTONLESSWHEEL = false;
132
+static boolean ZOOMBOXMODE = false;
95133 static boolean BOXMODE = false;
96134 static boolean IMAGEFLIP = false;
97135 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +144,7 @@
106144 static boolean OEIL = true;
107145 static boolean OEILONCE = false; // do oeilon then oeiloff
108146 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
147
+static boolean SWITCH = true; // false;
110148 static boolean HANDLES = false; // selection doesn't work!!
111149 static boolean PAINTMODE = false;
112150
....@@ -137,7 +175,7 @@
137175 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138176 boolean anisotropy = true;
139177 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
178
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141179
142180 boolean macromode = false;
143181
....@@ -149,12 +187,26 @@
149187 defaultcaps.setAccumBlueBits(16);
150188 defaultcaps.setAccumAlphaBits(16);
151189 }
152
- static CameraPane theRenderer;
190
+
191
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
153192
193
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
194
+ {
195
+ try
196
+ {
197
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
198
+ } catch (IOException e)
199
+ {
200
+ System.out.println("NAME = " + name);
201
+ e.printStackTrace(); // throw new RuntimeException(e);
202
+ return null;
203
+ }
204
+ }
205
+
154206 void SetAsGLRenderer(boolean b)
155207 {
156208 isRenderer = b;
157
- theRenderer = this;
209
+ Globals.theRenderer = this;
158210 }
159211
160212 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -169,7 +221,8 @@
169221
170222 SetCamera(cam);
171223
172
- SetLight(new Camera(new cVector(10, 10, -20)));
224
+ // Warning: not used.
225
+ SetLight(new Camera(new cVector(15, 10, -20)));
173226
174227 object = o;
175228
....@@ -191,6 +244,45 @@
191244 }
192245
193246 /// INTERFACE
247
+
248
+ public javax.media.opengl.GL GetGL0()
249
+ {
250
+ return null;
251
+ }
252
+
253
+ public int GenList()
254
+ {
255
+ javax.media.opengl.GL gl = GetGL();
256
+ return gl.glGenLists(1);
257
+ }
258
+
259
+ public void NewList(int id)
260
+ {
261
+ javax.media.opengl.GL gl = GetGL();
262
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
263
+ }
264
+
265
+ public void CallList(int id)
266
+ {
267
+ javax.media.opengl.GL gl = GetGL();
268
+ gl.glCallList(id);
269
+ }
270
+
271
+ public void EndList()
272
+ {
273
+ javax.media.opengl.GL gl = GetGL();
274
+ gl.glEndList();
275
+ }
276
+
277
+ public boolean IsBoxMode()
278
+ {
279
+ return BOXMODE;
280
+ }
281
+
282
+ public boolean IsZoomBoxMode()
283
+ {
284
+ return ZOOMBOXMODE;
285
+ }
194286
195287 public void ClearDepth()
196288 {
....@@ -231,9 +323,14 @@
231323 return this.ambientOcclusion;
232324 }
233325
326
+ public boolean IsDebugSelection()
327
+ {
328
+ return DEBUG_SELECTION;
329
+ }
330
+
234331 public boolean IsFrozen()
235332 {
236
- boolean selectmode = this.DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
333
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
237334
238335 return !selectmode && cameracount == 0; // != 0;
239336 }
....@@ -254,9 +351,19 @@
254351 return lightCamera;
255352 }
256353
354
+ public Camera ManipCamera()
355
+ {
356
+ return manipCamera;
357
+ }
358
+
257359 public Camera RenderCamera()
258360 {
259361 return renderCamera;
362
+ }
363
+
364
+ public Camera[] Cameras()
365
+ {
366
+ return cameras;
260367 }
261368
262369 public void PushMaterial(Object3D obj, boolean selected)
....@@ -272,7 +379,7 @@
272379 cStatic.objectstack[materialdepth++] = obj;
273380 //System.out.println("material " + material);
274381 //Applet3D.tracein(this, selected);
275
- display.vector2buffer = obj.projectedVertices;
382
+ //display.vector2buffer = obj.projectedVertices;
276383 if (obj instanceof Camera)
277384 {
278385 display.options1[0] = material.shift;
....@@ -281,14 +388,28 @@
281388 display.options1[2] = material.shadowbias;
282389 display.options1[3] = material.aniso;
283390 display.options1[4] = material.anisoV;
391
+// System.out.println("display.options1[0] " + display.options1[0]);
392
+// System.out.println("display.options1[1] " + display.options1[1]);
393
+// System.out.println("display.options1[2] " + display.options1[2]);
394
+// System.out.println("display.options1[3] " + display.options1[3]);
395
+// System.out.println("display.options1[4] " + display.options1[4]);
284396 display.options2[0] = material.opacity;
285397 display.options2[1] = material.diffuse;
286398 display.options2[2] = material.factor;
399
+// System.out.println("display.options2[0] " + display.options2[0]);
400
+// System.out.println("display.options2[1] " + display.options2[1]);
401
+// System.out.println("display.options2[2] " + display.options2[2]);
287402
288403 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
404
+// System.out.println("display.options3[0] " + display.options3[0]);
405
+// System.out.println("display.options3[1] " + display.options3[1]);
406
+// System.out.println("display.options3[2] " + display.options3[2]);
289407 display.options4[0] = material.cameralight/0.2f;
290408 display.options4[1] = material.subsurface;
291409 display.options4[2] = material.sheen;
410
+// System.out.println("display.options4[0] " + display.options4[0]);
411
+// System.out.println("display.options4[1] " + display.options4[1]);
412
+// System.out.println("display.options4[2] " + display.options4[2]);
292413
293414 // if (display.CURRENTANTIALIAS > 0)
294415 // display.options3[3] /= 4;
....@@ -304,7 +425,7 @@
304425 /**/
305426 } else
306427 {
307
- DrawMaterial(material, selected);
428
+ DrawMaterial(material, selected, obj.projectedVertices);
308429 }
309430 } else
310431 {
....@@ -328,8 +449,8 @@
328449 cStatic.objectstack[materialdepth++] = obj;
329450 //System.out.println("material " + material);
330451 //Applet3D.tracein("selected ", selected);
331
- display.vector2buffer = obj.projectedVertices;
332
- display.DrawMaterial(material, selected);
452
+ //display.vector2buffer = obj.projectedVertices;
453
+ display.DrawMaterial(material, selected, obj.projectedVertices);
333454 }
334455 }
335456
....@@ -346,8 +467,8 @@
346467 materialdepth -= 1;
347468 if (materialdepth > 0)
348469 {
349
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
350
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
470
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
471
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
351472 }
352473 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
353474 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -367,8 +488,8 @@
367488 materialdepth -= 1;
368489 if (materialdepth > 0)
369490 {
370
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
371
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
491
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
492
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
372493 }
373494 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
374495 //else
....@@ -403,16 +524,18 @@
403524
404525 javax.media.opengl.GL gl = display.GetGL();
405526
406
- boolean selectmode = display.DrawMode() == display.SELECTION || CameraPane.DEBUG_SELECTION;
527
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
407528
408529 //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
409530 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
410531 {
411532 //gl.glBegin(gl.GL_TRIANGLES);
412
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
533
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
534
+ // TEST LIVE NORMALS && !obj.dontselect
535
+ ;
413536 if (!hasnorm)
414537 {
415
- // System.out.println("FUCK!!");
538
+ // System.out.println("Mesh normal");
416539 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
417540 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
418541 LA.vecCross(obj.v0, obj.v1, obj.v2);
....@@ -566,8 +689,819 @@
566689 }
567690 }
568691
692
+ /**
693
+ * <code>draw</code> renders a <code>TriMesh</code> object including
694
+ * it's normals, colors, textures and vertices.
695
+ *
696
+ * @see Renderer#draw(TriMesh)
697
+ * @param tris
698
+ * the mesh to render.
699
+ */
700
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
701
+ {
702
+ CameraPane display = this;
703
+
704
+ float r = display.modelParams0[0];
705
+ float g = display.modelParams0[1];
706
+ float b = display.modelParams0[2];
707
+ float opacity = display.modelParams5[1];
708
+
709
+ //final GL gl = GLU.getCurrentGL();
710
+ GL gl = display.GetGL(); // getGL();
711
+
712
+ FloatBuffer vertBuf = geo.vertBuf;
713
+
714
+ int v = vertBuf.capacity();
715
+
716
+ int count = 0;
717
+
718
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
719
+ gl.glEnable(gl.GL_CULL_FACE);
720
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
721
+ for (int i=0; i<v/3; i++)
722
+ {
723
+ int index3 = i*3;
724
+
725
+ if (geo.sizeBuf.get(index3+1) == 0)
726
+ continue;
727
+
728
+ count++;
729
+
730
+ int index4 = i*4;
731
+
732
+ float tx = vertBuf.get(index3);
733
+ float ty = vertBuf.get(index3+1);
734
+ float tz = vertBuf.get(index3+2);
735
+
736
+ // if (tx == 0 && ty == 0 && tz == 0)
737
+ // continue;
738
+
739
+ gl.glMatrixMode(gl.GL_TEXTURE);
740
+ gl.glPushMatrix();
741
+
742
+ float[] texmat = geo.texmat;
743
+ texmat[12] = texmat[13] = texmat[14] = i;
744
+
745
+ gl.glMultMatrixf(texmat, 0);
746
+
747
+ gl.glMatrixMode(gl.GL_MODELVIEW);
748
+ gl.glPushMatrix();
749
+
750
+ gl.glTranslatef(tx,ty,tz);
751
+
752
+ if (rotate)
753
+ gl.glRotatef(i, 0, 1, 0);
754
+
755
+ float size = geo.sizeBuf.get(index3) / 100;
756
+ gl.glScalef(size,size,size);
757
+
758
+ float cr = geo.colorBuf.get(index4);
759
+ float cg = geo.colorBuf.get(index4+1);
760
+ float cb = geo.colorBuf.get(index4+2);
761
+ float ca = geo.colorBuf.get(index4+3);
762
+
763
+ display.modelParams0[0] = r * cr;
764
+ display.modelParams0[1] = g * cg;
765
+ display.modelParams0[2] = b * cb;
766
+
767
+ display.modelParams5[1] = opacity * ca;
768
+
769
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
770
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
771
+
772
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
773
+ RandomNode.globalseed2 = RandomNode.globalseed;
774
+
775
+// gl.glColor4f(cr,cg,cb,ca);
776
+ // gl.glScalef(1024/16,1024/16,1024/16);
777
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
778
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
779
+ //gl.glTranslatef(-tx,-ty,-tz);
780
+ gl.glPopMatrix();
781
+
782
+ gl.glMatrixMode(gl.GL_TEXTURE);
783
+ gl.glPopMatrix();
784
+ }
785
+ // gl.glScalef(1024,1024,1024);
786
+ if (!cf)
787
+ gl.glDisable(gl.GL_CULL_FACE);
788
+
789
+ display.modelParams0[0] = r;
790
+ display.modelParams0[1] = g;
791
+ display.modelParams0[2] = b;
792
+
793
+ display.modelParams5[1] = opacity;
794
+
795
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
796
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
797
+
798
+ gl.glMatrixMode(gl.GL_MODELVIEW);
799
+
800
+// System.err.println("total = " + v/3 + "; displayed = " + count);
801
+ if (true)
802
+ return;
803
+
804
+//// if (!tris.predraw(this))
805
+//// {
806
+//// return;
807
+//// }
808
+//// if (Debug.stats)
809
+//// {
810
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
811
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
812
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
813
+//// }
814
+////
815
+//// if (tris.getDisplayListID() != -1)
816
+//// {
817
+//// renderDisplayList(tris);
818
+//// return;
819
+//// }
820
+////
821
+//// if (!generatingDisplayList)
822
+//// {
823
+//// applyStates(tris.states, tris);
824
+//// }
825
+//// if (Debug.stats)
826
+//// {
827
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
828
+//// }
829
+//// boolean transformed = doTransforms(tris);
830
+//
831
+// int glMode = GL.GL_TRIANGLES;
832
+// switch (getMode())
833
+// {
834
+// case Triangles:
835
+// glMode = GL.GL_TRIANGLES;
836
+// break;
837
+// case Strip:
838
+// glMode = GL.GL_TRIANGLE_STRIP;
839
+// break;
840
+// case Fan:
841
+// glMode = GL.GL_TRIANGLE_FAN;
842
+// break;
843
+// }
844
+//
845
+// if (!predrawGeometry(gl))
846
+// {
847
+// // make sure only the necessary indices are sent through on old
848
+// // cards.
849
+// IntBuffer indices = this.getIndexBuffer();
850
+// if (indices == null)
851
+// {
852
+// logger.severe("missing indices on geometry object: " + this.toString());
853
+// } else
854
+// {
855
+// indices.rewind();
856
+// indices.limit(this.getMaxIndex());
857
+//
858
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
859
+//
860
+// indices.clear();
861
+// }
862
+// } else
863
+// {
864
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
865
+// GL.GL_UNSIGNED_INT, 0);
866
+// }
867
+//
868
+//// postdrawGeometry(tris);
869
+//// if (transformed)
870
+//// {
871
+//// undoTransforms(tris);
872
+//// }
873
+////
874
+//// if (Debug.stats)
875
+//// {
876
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
877
+//// }
878
+//// tris.postdraw(this);
879
+ }
880
+
881
+ static Camera localcamera = new Camera();
882
+ static cVector from = new cVector();
883
+ static cVector to = new cVector();
884
+
885
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
886
+ {
887
+ CameraPane cp = this;
888
+
889
+ Camera keep = cp.RenderCamera();
890
+ cp.renderCamera = localcamera;
891
+
892
+ if (br.trimmed)
893
+ {
894
+ float[] colors = new float[br.positions.length / 3];
895
+
896
+ int i3 = 0;
897
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
898
+ {
899
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
900
+ continue;
901
+
902
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
903
+ to.set(br.positions[i3] + br.normals[i3],
904
+ br.positions[i3 + 1] + br.normals[i3 + 1],
905
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
906
+ LA.xformPos(from, transform, from);
907
+ LA.xformPos(to, transform, to); // RIGID ONLY
908
+ localcamera.setAim(from, to);
909
+
910
+ CameraPane.occlusionbuffer.display();
911
+
912
+ if (CameraPane.DEBUG_OCCLUSION)
913
+ cp.display(); // debug
914
+
915
+ colors[i] = cp.vertexOcclusion.r;
916
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
917
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
918
+
919
+ if ((i % 100) == 0 && i != 0)
920
+ {
921
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
922
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
923
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
924
+ }
925
+ }
926
+
927
+ br.colors = colors;
928
+ }
929
+ else
930
+ {
931
+ for (int i = 0; i < br.VertexCount(); i++)
932
+ {
933
+ Vertex v = br.GetVertex(i);
934
+
935
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
936
+ continue;
937
+
938
+ from.set(v.x, v.y, v.z);
939
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
940
+ LA.xformPos(from, transform, from);
941
+ LA.xformPos(to, transform, to); // RIGID ONLY
942
+ localcamera.setAim(from, to);
943
+
944
+ CameraPane.occlusionbuffer.display();
945
+
946
+ if (CameraPane.DEBUG_OCCLUSION)
947
+ cp.display(); // debug
948
+
949
+ v.AO = cp.vertexOcclusion.r;
950
+
951
+ if ((i % 100) == 0 && i != 0)
952
+ {
953
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
954
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
955
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
956
+ }
957
+ }
958
+ }
959
+
960
+ //System.out.println("done.");
961
+
962
+ cp.renderCamera = keep;
963
+ }
964
+
965
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
966
+ {
967
+ CameraPane display = this;
968
+ pointFlow.CreateHT();
969
+
970
+ float r = display.modelParams0[0];
971
+ float g = display.modelParams0[1];
972
+ float b = display.modelParams0[2];
973
+ float opacity = display.modelParams5[1];
974
+
975
+ //final GL gl = GLU.getCurrentGL();
976
+ GL gl = display.GetGL(); // getGL();
977
+
978
+ int s = pointFlow.points.size();
979
+
980
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
981
+ gl.glEnable(gl.GL_CULL_FACE);
982
+
983
+ for (int i=s; --i>=0;)
984
+ //for (int i=0; i<s; i++)
985
+ {
986
+ cVector v = pointFlow.points.get(i);
987
+
988
+ double mindist = Double.MAX_VALUE;
989
+
990
+ double size = pointFlow.minimumSize;
991
+
992
+ double distancenext = 0;
993
+
994
+ if (i > 0)
995
+ {
996
+ cVector w = pointFlow.points.get(i-1);
997
+
998
+ double dist = w.distance(v);
999
+
1000
+ distancenext = dist;
1001
+
1002
+ if (mindist > dist)
1003
+ {
1004
+ mindist = dist;
1005
+ size = mindist*pointFlow.resizefactor;
1006
+ }
1007
+ }
1008
+
1009
+ if (i < s-1)
1010
+ {
1011
+ cVector w = pointFlow.points.get(i+1);
1012
+
1013
+ double dist = w.distance(v);
1014
+
1015
+ if (mindist > dist)
1016
+ {
1017
+ mindist = dist;
1018
+ size = mindist*pointFlow.resizefactor;
1019
+ }
1020
+ }
1021
+
1022
+ if (size < pointFlow.minimumSize)
1023
+ size = pointFlow.minimumSize;
1024
+ if (size > pointFlow.maximumSize)
1025
+ size = pointFlow.maximumSize;
1026
+
1027
+ double tx = v.x;
1028
+ double ty = v.y;
1029
+ double tz = v.z;
1030
+
1031
+ // if (tx == 0 && ty == 0 && tz == 0)
1032
+ // continue;
1033
+
1034
+ gl.glMatrixMode(gl.GL_TEXTURE);
1035
+ gl.glPushMatrix();
1036
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1037
+
1038
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1039
+
1040
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1041
+ gl.glPushMatrix();
1042
+
1043
+ gl.glTranslated(tx,ty,tz);
1044
+
1045
+ gl.glScaled(size,size,size);
1046
+
1047
+// float cr = colorBuf.get(index4);
1048
+// float cg = colorBuf.get(index4+1);
1049
+// float cb = colorBuf.get(index4+2);
1050
+// float ca = colorBuf.get(index4+3);
1051
+//
1052
+// display.modelParams0[0] = r * cr;
1053
+// display.modelParams0[1] = g * cg;
1054
+// display.modelParams0[2] = b * cb;
1055
+//
1056
+// display.modelParams5[1] = opacity * ca;
1057
+//
1058
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1059
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1060
+//
1061
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1062
+// RandomNode.globalseed2 = RandomNode.globalseed;
1063
+//
1064
+//// gl.glColor4f(cr,cg,cb,ca);
1065
+// // gl.glScalef(1024/16,1024/16,1024/16);
1066
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1067
+
1068
+ gl.glPopMatrix();
1069
+
1070
+ double step = size/4; //
1071
+
1072
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1073
+ continue;
1074
+
1075
+ int nbsteps = (int)(distancenext/step);
1076
+
1077
+ step = distancenext/nbsteps;
1078
+
1079
+ cVector next = pointFlow.points.get(i-1);
1080
+
1081
+ tmp.set(next);
1082
+ tmp.sub(v);
1083
+ tmp.normalize();
1084
+ tmp.mul(step);
1085
+
1086
+ // calculate next size
1087
+ mindist = Double.MAX_VALUE;
1088
+
1089
+ double nextsize = pointFlow.minimumSize;
1090
+
1091
+ if (i > 1)
1092
+ {
1093
+ cVector w = pointFlow.points.get(i-2);
1094
+
1095
+ double dist = w.distance(next);
1096
+
1097
+ if (mindist > dist)
1098
+ {
1099
+ mindist = dist;
1100
+ nextsize = mindist*pointFlow.resizefactor;
1101
+ }
1102
+ }
1103
+
1104
+ double dist = v.distance(next);
1105
+
1106
+ if (mindist > dist)
1107
+ {
1108
+ mindist = dist;
1109
+ nextsize = mindist*pointFlow.resizefactor;
1110
+ }
1111
+
1112
+ if (nextsize < pointFlow.minimumSize)
1113
+ nextsize = pointFlow.minimumSize;
1114
+ if (nextsize > pointFlow.maximumSize)
1115
+ nextsize = pointFlow.maximumSize;
1116
+ //
1117
+
1118
+ double count = 0;
1119
+
1120
+ while (distancenext > 0.000000001) // step
1121
+ {
1122
+ gl.glPushMatrix();
1123
+
1124
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1125
+
1126
+ double K = count/nbsteps;
1127
+
1128
+ double intersize = K*nextsize + (1-K)*size;
1129
+
1130
+ gl.glScaled(intersize,intersize,intersize);
1131
+
1132
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1133
+
1134
+ count++;
1135
+
1136
+ distancenext -= step;
1137
+
1138
+ gl.glPopMatrix();
1139
+ }
1140
+
1141
+ if (count != nbsteps)
1142
+ assert(count == nbsteps);
1143
+
1144
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1145
+ //gl.glTranslatef(-tx,-ty,-tz);
1146
+
1147
+ gl.glMatrixMode(gl.GL_TEXTURE);
1148
+ gl.glPopMatrix();
1149
+ }
1150
+
1151
+ if (!cf)
1152
+ gl.glDisable(gl.GL_CULL_FACE);
1153
+
1154
+// display.modelParams0[0] = r;
1155
+// display.modelParams0[1] = g;
1156
+// display.modelParams0[2] = b;
1157
+//
1158
+// display.modelParams5[1] = opacity;
1159
+//
1160
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1161
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1162
+
1163
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1164
+ }
1165
+
1166
+ public void DrawBox(cVector min, cVector max)
1167
+ {
1168
+ javax.media.opengl.GL gl = GetGL();
1169
+ gl.glBegin(gl.GL_LINES);
1170
+
1171
+ gl.glVertex3d(min.x, min.y, min.z);
1172
+ gl.glVertex3d(min.x, min.y, max.z);
1173
+ gl.glVertex3d(min.x, min.y, min.z);
1174
+ gl.glVertex3d(min.x, max.y, min.z);
1175
+ gl.glVertex3d(min.x, min.y, min.z);
1176
+ gl.glVertex3d(max.x, min.y, min.z);
1177
+
1178
+ gl.glVertex3d(max.x, max.y, max.z);
1179
+ gl.glVertex3d(min.x, max.y, max.z);
1180
+ gl.glVertex3d(max.x, max.y, max.z);
1181
+ gl.glVertex3d(max.x, min.y, max.z);
1182
+ gl.glVertex3d(max.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, max.y, min.z);
1184
+
1185
+ gl.glEnd();
1186
+ }
1187
+
1188
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1189
+ {
1190
+ int[] strips = bRep.getRawIndices();
1191
+
1192
+ javax.media.opengl.GL gl = GetGL();
1193
+
1194
+ // TRIANGLE STRIP ARRAY
1195
+ if (bRep.trimmed)
1196
+ {
1197
+ float[] v = bRep.getRawVertices();
1198
+ float[] n = bRep.getRawNormals();
1199
+ float[] c = bRep.getRawColors();
1200
+ float[] uv = bRep.getRawUVMap();
1201
+
1202
+ int count2 = 0;
1203
+ int count3 = 0;
1204
+
1205
+ if (n.length > 0)
1206
+ {
1207
+ for (int i = 0; i < strips.length; i++)
1208
+ {
1209
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1210
+
1211
+ /*
1212
+ boolean locked = false;
1213
+ float eps = 0.1f;
1214
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1215
+
1216
+ int dot = 0;
1217
+
1218
+ if ((dot&1) == 0)
1219
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1220
+
1221
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1222
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1223
+ else
1224
+ {
1225
+ locked = true;
1226
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1227
+ }
1228
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1229
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1230
+ if (hasnorm)
1231
+ {
1232
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1233
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1234
+ }
1235
+
1236
+ if ((dot&4) == 0)
1237
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1238
+
1239
+ if (wrap || !locked && (dot&8) != 0)
1240
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1241
+ else
1242
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1243
+
1244
+ f.dot = dot;
1245
+ */
1246
+
1247
+ if (!selectmode)
1248
+ {
1249
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1250
+ {
1251
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1252
+ } else
1253
+ {
1254
+ gl.glNormal3f(0, 0, 1);
1255
+ }
1256
+
1257
+ if (c != null)
1258
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1259
+ {
1260
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1261
+ }
1262
+ }
1263
+
1264
+ if (flipV)
1265
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1266
+ else
1267
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1268
+
1269
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1270
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1271
+
1272
+ count2 += 2;
1273
+ count3 += 3;
1274
+ if (!selectmode)
1275
+ {
1276
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1277
+ {
1278
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1279
+ } else
1280
+ {
1281
+ gl.glNormal3f(0, 0, 1);
1282
+ }
1283
+ if (c != null)
1284
+ {
1285
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1286
+ }
1287
+ }
1288
+
1289
+ if (flipV)
1290
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1291
+ else
1292
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1293
+
1294
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1295
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1296
+
1297
+ count2 += 2;
1298
+ count3 += 3;
1299
+ for (int j = 0; j < strips[i] - 2; j++)
1300
+ {
1301
+ //gl.glTexCoord2d(...);
1302
+ if (!selectmode)
1303
+ {
1304
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1305
+ {
1306
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1307
+ } else
1308
+ {
1309
+ gl.glNormal3f(0, 0, 1);
1310
+ }
1311
+ if (c != null)
1312
+ {
1313
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1314
+ }
1315
+ }
1316
+
1317
+ if (flipV)
1318
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1319
+ else
1320
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1321
+
1322
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1323
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1324
+
1325
+ count2 += 2;
1326
+ count3 += 3;
1327
+ }
1328
+
1329
+ gl.glEnd();
1330
+ }
1331
+ }
1332
+
1333
+ assert count3 == v.length;
1334
+ }
1335
+ else // !trimmed
1336
+ {
1337
+ int count = 0;
1338
+ for (int i = 0; i < strips.length; i++)
1339
+ {
1340
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1341
+
1342
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1343
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1344
+
1345
+ drawVertex(gl, p, flipV, selectmode);
1346
+ drawVertex(gl, q, flipV, selectmode);
1347
+
1348
+ for (int j = 0; j < strips[i] - 2; j++)
1349
+ {
1350
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1351
+
1352
+ // if (j%2 == 0)
1353
+ // drawFace(p, q, r, display, null);
1354
+ // else
1355
+ // drawFace(p, r, q, display, null);
1356
+
1357
+ // p = q;
1358
+ // q = r;
1359
+ drawVertex(gl, r, flipV, selectmode);
1360
+ }
1361
+
1362
+ gl.glEnd();
1363
+ }
1364
+ }
1365
+ }
1366
+
1367
+ static cSpring.Point3D temp = new cSpring.Point3D();
1368
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1369
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1370
+
1371
+ public void DrawDynamicMesh(cMesh mesh)
1372
+ {
1373
+ GL gl = GetGL(); // getGL();
1374
+
1375
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1376
+
1377
+ gl.glDisable(gl.GL_LIGHTING);
1378
+
1379
+ gl.glLineWidth(1);
1380
+ gl.glColor3f(1,1,1);
1381
+ gl.glBegin(gl.GL_LINES);
1382
+ double scale = 0;
1383
+ int count = 0;
1384
+ for (int s=0; s<Phys.allSprings.size(); s++)
1385
+ {
1386
+ cSpring.Spring spring = Phys.allSprings.get(s);
1387
+ if(s == 0)
1388
+ {
1389
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1390
+ }
1391
+ if (mesh.showsprings)
1392
+ {
1393
+ temp.set(spring.a.position);
1394
+ temp.add(spring.b.position);
1395
+ temp.mul(0.5);
1396
+ temp2.set(spring.a.position);
1397
+ temp2.sub(spring.b.position);
1398
+ temp2.mul(spring.restLength/2);
1399
+ temp.sub(temp2);
1400
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1401
+ temp.add(temp2);
1402
+ temp.add(temp2);
1403
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1404
+ }
1405
+
1406
+ if (spring.isHandle)
1407
+ continue;
1408
+
1409
+ //if (scale < spring.restLength)
1410
+ scale += spring.restLength;
1411
+ count++;
1412
+ }
1413
+ gl.glEnd();
1414
+
1415
+ if (count == 0)
1416
+ scale = 0.01;
1417
+ else
1418
+ scale /= count * 3;
1419
+
1420
+ //scale = 0.25;
1421
+
1422
+ if (mesh.ShowInfo())
1423
+ {
1424
+ gl.glLineWidth(4);
1425
+ for (int s=0; s<Phys.allNodes.size(); s++)
1426
+ {
1427
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1428
+ if (node.mass == 0)
1429
+ continue;
1430
+
1431
+ int i = node.springs==null?-1:node.springs.size();
1432
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1433
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1434
+ //temp.normalize();
1435
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1436
+ gl.glBegin(gl.GL_LINES);
1437
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1438
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1439
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1440
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1441
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1442
+ gl.glEnd();
1443
+ }
1444
+
1445
+ gl.glLineWidth(8);
1446
+ for (int s=0; s<Phys.allNodes.size(); s++)
1447
+ {
1448
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1449
+
1450
+ if (node.springs != null)
1451
+ {
1452
+ for (int i=0; i<node.springs.size(); i+=1)
1453
+ {
1454
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1455
+
1456
+ int c = i+1;
1457
+ // c = node.springs.get(i).nbcopies;
1458
+
1459
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1460
+ gl.glBegin(gl.GL_LINES);
1461
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1462
+ 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);
1463
+ gl.glEnd();
1464
+ }
1465
+ }
1466
+ }
1467
+
1468
+ gl.glLineWidth(1);
1469
+ }
1470
+
1471
+ gl.glEnable(gl.GL_LIGHTING);
1472
+ }
1473
+
5691474 /// INTERFACE
5701475
1476
+ public void StartTriangles()
1477
+ {
1478
+ javax.media.opengl.GL gl = GetGL();
1479
+ gl.glBegin(gl.GL_TRIANGLES);
1480
+ }
1481
+
1482
+ public void EndTriangles()
1483
+ {
1484
+ GetGL().glEnd();
1485
+ }
1486
+
1487
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1488
+ {
1489
+ if (!selectmode)
1490
+ {
1491
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1492
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1493
+
1494
+ if (flipV)
1495
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1496
+ else
1497
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1498
+ }
1499
+
1500
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1501
+ }
1502
+
1503
+ float[] colorV = new float[4];
1504
+
5711505 void SetColor(Object3D obj, Vertex p0)
5721506 {
5731507 CameraPane display = this;
....@@ -635,8 +1569,6 @@
6351569 {
6361570 return;
6371571 }
638
-
639
- float[] colorV = new float[3];
6401572
6411573 if (false) // marked)
6421574 {
....@@ -745,7 +1677,7 @@
7451677 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
7461678 }
7471679
748
- void DrawMaterial(cMaterial material, boolean selected)
1680
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
7491681 {
7501682 CameraPane display = this;
7511683 //new Exception().printStackTrace();
....@@ -761,18 +1693,18 @@
7611693 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
7621694 if (!material.multiply)
7631695 {
764
- display.color = color;
1696
+ display.color = material.color;
7651697 display.saturation = material.modulation;
7661698 }
7671699 else
7681700 {
769
- display.color *= color*2;
1701
+ display.color *= material.color*2;
7701702 display.saturation *= material.modulation*2;
7711703 }
7721704
7731705 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
7741706
775
- float[] colorV = GrafreeD.colorV;
1707
+ float[] colorV = Grafreed.colorV;
7761708
7771709 /**/
7781710 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -780,7 +1712,7 @@
7801712 colorV[0] = display.modelParams0[0] * material.diffuse;
7811713 colorV[1] = display.modelParams0[1] * material.diffuse;
7821714 colorV[2] = display.modelParams0[2] * material.diffuse;
783
- colorV[3] = material.opacity;
1715
+ colorV[3] = 1; // material.opacity;
7841716
7851717 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
7861718 //System.out.println("Opacity = " + opacity);
....@@ -888,9 +1820,9 @@
8881820 display.modelParams7[2] = 0;
8891821 display.modelParams7[3] = 0;
8901822
891
- display.modelParams6[0] = 100; // criss de bug de bump
1823
+ //display.modelParams6[0] = 100; // criss de bug de bump
8921824
893
- Object3D.cVector2[] extparams = display.vector2buffer;
1825
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
8941826 if (extparams != null && extparams.length > 0 && extparams[0] != null)
8951827 {
8961828 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1032,7 +1964,7 @@
10321964 void PushMatrix(double[][] matrix)
10331965 {
10341966 // GrafreeD.tracein(matrix);
1035
- PushMatrix(matrix,1);
1967
+ PushMatrix(matrix, 1);
10361968 }
10371969
10381970 void PushMatrix()
....@@ -1129,7 +2061,7 @@
11292061
11302062 static int camerachangeframe;
11312063
1132
- boolean SetCamera(Camera cam)
2064
+ public boolean SetCamera(Camera cam)
11332065 {
11342066 // may 2014 if (cam == cameras[0] || cam == cameras[1])
11352067 // return false;
....@@ -1186,7 +2118,7 @@
11862118 //System.err.println("Oeil on");
11872119 OEIL = true;
11882120 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1189
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2121
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11902122 //pingthread.StepToTarget(true);
11912123 }
11922124
....@@ -1257,33 +2189,6 @@
12572189 mainDL ^= true;
12582190 }
12592191
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
-
12872192 void ToggleFullScreen()
12882193 {
12892194 FULLSCREEN ^= true;
....@@ -1294,72 +2199,94 @@
12942199 Globals.CROWD ^= true;
12952200 }
12962201
1297
- void ToggleInertia()
1298
- {
1299
- INERTIA ^= true;
1300
- }
1301
-
13022202 void ToggleLocal()
13032203 {
13042204 LOCALTRANSFORM ^= true;
13052205 }
13062206
1307
- void ToggleFast()
2207
+ public void ToggleTexture()
2208
+ {
2209
+ textureon ^= true;
2210
+ }
2211
+
2212
+ public void ToggleLive()
2213
+ {
2214
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2215
+
2216
+ System.err.println("LIVE = " + Globals.isLIVE());
2217
+
2218
+ if (!Globals.isLIVE()) // save sound
2219
+ Grafreed.savesound = true; // wav.save();
2220
+ // else
2221
+ repaint(); // start loop // may 2013
2222
+ }
2223
+
2224
+ public void ToggleSupport()
2225
+ {
2226
+ SUPPORT ^= true;
2227
+ }
2228
+
2229
+ public void ToggleAbort()
2230
+ {
2231
+ ABORTMODE ^= true;
2232
+ }
2233
+
2234
+ public void ToggleInertia()
2235
+ {
2236
+ INERTIA ^= true;
2237
+ }
2238
+
2239
+ public void ToggleFast()
13082240 {
13092241 FAST ^= true;
13102242 }
13112243
1312
- void ToggleSlowPose()
2244
+ public void ToggleSlowPose()
13132245 {
13142246 SLOWPOSE ^= true;
13152247 }
13162248
1317
- void ToggleFootContact()
1318
- {
1319
- FOOTCONTACT ^= true;
1320
- }
1321
-
1322
- void ToggleBoxMode()
2249
+ public void ToggleBoxMode()
13232250 {
13242251 BOXMODE ^= true;
13252252 }
13262253
1327
- void ToggleSmoothFocus()
2254
+ public void ToggleZoomBoxMode()
2255
+ {
2256
+ ZOOMBOXMODE ^= true;
2257
+ }
2258
+
2259
+ public void ToggleSmoothFocus()
13282260 {
13292261 SMOOTHFOCUS ^= true;
13302262 }
13312263
1332
- void ToggleImageFlip()
2264
+ public void ToggleImageFlip()
13332265 {
13342266 IMAGEFLIP ^= true;
13352267 }
13362268
1337
- void ToggleSpeakerMocap()
2269
+ public void ToggleSpeakerMocap()
13382270 {
13392271 SPEAKERMOCAP ^= true;
13402272 }
13412273
1342
- void ToggleSpeakerCamera()
2274
+ public void ToggleSpeakerCamera()
13432275 {
13442276 SPEAKERCAMERA ^= true;
13452277 }
13462278
1347
- void ToggleSpeakerFocus()
2279
+ public void ToggleSpeakerFocus()
13482280 {
13492281 SPEAKERFOCUS ^= true;
13502282 }
13512283
1352
- void ToggleDebug()
1353
- {
1354
- DEBUG ^= true;
1355
- }
1356
-
1357
- void ToggleFrustum()
2284
+ public void ToggleFrustum()
13582285 {
13592286 FRUSTUM ^= true;
13602287 }
13612288
1362
- void ToggleTrack()
2289
+ public void ToggleTrack()
13632290 {
13642291 TRACK ^= true;
13652292 if (TRACK)
....@@ -1378,25 +2305,35 @@
13782305 repaint();
13792306 }
13802307
1381
- void ToggleTrackOnce()
2308
+ public void ToggleTrackOnce()
13822309 {
13832310 TRACKONCE ^= true;
13842311 }
13852312
1386
- void ToggleShadowTrack()
2313
+ public void ToggleShadowTrack()
13872314 {
13882315 SHADOWTRACK ^= true;
13892316 repaint();
13902317 }
13912318
1392
- void ToggleOeil()
2319
+ public void ToggleOeil()
13932320 {
13942321 OEIL ^= true;
13952322 }
13962323
1397
- void ToggleOeilOnce()
2324
+ public void ToggleOeilOnce()
13982325 {
13992326 OEILONCE ^= true;
2327
+ }
2328
+
2329
+ void ToggleFootContact()
2330
+ {
2331
+ FOOTCONTACT ^= true;
2332
+ }
2333
+
2334
+ void ToggleDebug()
2335
+ {
2336
+ Globals.DEBUG ^= true;
14002337 }
14012338
14022339 void ToggleLookAt()
....@@ -1404,9 +2341,9 @@
14042341 LOOKAT ^= true;
14052342 }
14062343
1407
- void ToggleRandom()
2344
+ void ToggleSwitch()
14082345 {
1409
- RANDOM ^= true;
2346
+ SWITCH ^= true;
14102347 }
14112348
14122349 void ToggleHandles()
....@@ -1414,10 +2351,17 @@
14142351 HANDLES ^= true;
14152352 }
14162353
2354
+ Object3D paintFolder;
2355
+
14172356 void TogglePaint()
14182357 {
14192358 PAINTMODE ^= true;
14202359 paintcount = 0;
2360
+
2361
+ if (PAINTMODE)
2362
+ {
2363
+ paintFolder = GetFolder();
2364
+ }
14212365 }
14222366
14232367 void SwapCamera(int a, int b)
....@@ -1513,7 +2457,22 @@
15132457 {
15142458 return currentGL;
15152459 }
1516
-
2460
+
2461
+ static private BufferedImage CreateBim(TextureData texturedata)
2462
+ {
2463
+ Grafreed.Assert(texturedata != null);
2464
+
2465
+ int width = texturedata.getWidth();
2466
+ int height = texturedata.getHeight();
2467
+
2468
+ Buffer buffer = texturedata.getBuffer();
2469
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2470
+
2471
+ byte[] bytes = bytebuf.array();
2472
+
2473
+ return CreateBim(bytes, width, height);
2474
+ }
2475
+
15172476 /**/
15182477 class CacheTexture
15192478 {
....@@ -1522,28 +2481,31 @@
15222481
15232482 int resolution;
15242483
1525
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2484
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
15262485 {
1527
- texture = tex;
2486
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2487
+ texturedata = texdata;
15282488 resolution = res;
15292489 }
15302490 }
15312491 /**/
15322492
15332493 // 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>();
2494
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2495
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2496
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2497
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2498
+
15372499 int pigmentdepth = 0;
15382500 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
15392501 int bumpdepth = 0;
15402502 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
15412503 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
15422504 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
1543
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2505
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
15442506 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
15452507
1546
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2508
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
15472509 {
15482510 TextureData texturedata = null;
15492511
....@@ -1562,13 +2524,34 @@
15622524 if (bump)
15632525 texturedata = ConvertBump(texturedata, false);
15642526
1565
- com.sun.opengl.util.texture.Texture texture =
1566
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2527
+// com.sun.opengl.util.texture.Texture texture =
2528
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
15672529
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);
2530
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2531
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
15702532
1571
- return texture;
2533
+ return texturedata;
2534
+ }
2535
+
2536
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2537
+ {
2538
+ TextureData texturedata = null;
2539
+
2540
+ try
2541
+ {
2542
+ texturedata =
2543
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2544
+ bim,
2545
+ true);
2546
+ } catch (Exception e)
2547
+ {
2548
+ throw new javax.media.opengl.GLException(e);
2549
+ }
2550
+
2551
+ if (bump)
2552
+ texturedata = ConvertBump(texturedata, false);
2553
+
2554
+ return texturedata;
15722555 }
15732556
15742557 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -2641,6 +3624,8 @@
26413624
26423625 System.out.println("LOADING TEXTURE : " + name);
26433626
3627
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3628
+
26443629 //
26453630 if (false) // compressbit > 0)
26463631 {
....@@ -3345,6 +4330,7 @@
33454330
33464331 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
33474332 {
4333
+ new Exception().printStackTrace();
33484334 System.exit(0);
33494335 com.sun.opengl.util.texture.Texture texture = null;
33504336
....@@ -7038,7 +8024,7 @@
70388024 String pigment = Object3D.GetPigment(tex);
70398025 String bump = Object3D.GetBump(tex);
70408026
7041
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8027
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
70428028 {
70438029 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
70448030 // System.out.println("; bump = " + bump);
....@@ -7053,11 +8039,69 @@
70538039 pigment = null;
70548040 }
70558041
7056
- ReleaseTexture(bump, true);
7057
- ReleaseTexture(pigment, false);
8042
+ ReleaseTexture(tex, true);
8043
+ ReleaseTexture(tex, false);
70588044 }
70598045
7060
- void ReleaseTexture(String tex, boolean bump)
8046
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8047
+ {
8048
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8049
+ {
8050
+ return;
8051
+ }
8052
+
8053
+ if (tex == null)
8054
+ {
8055
+ ReleaseTexture(null, false);
8056
+ return;
8057
+ }
8058
+
8059
+ String pigment = Object3D.GetPigment(tex);
8060
+
8061
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8062
+ {
8063
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8064
+ // System.out.println("; bump = " + bump);
8065
+ }
8066
+
8067
+ if (pigment.equals(""))
8068
+ {
8069
+ pigment = null;
8070
+ }
8071
+
8072
+ ReleaseTexture(tex, false);
8073
+ }
8074
+
8075
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8076
+ {
8077
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8078
+ {
8079
+ return;
8080
+ }
8081
+
8082
+ if (tex == null)
8083
+ {
8084
+ ReleaseTexture(null, true);
8085
+ return;
8086
+ }
8087
+
8088
+ String bump = Object3D.GetBump(tex);
8089
+
8090
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8091
+ {
8092
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8093
+ // System.out.println("; bump = " + bump);
8094
+ }
8095
+
8096
+ if (bump.equals(""))
8097
+ {
8098
+ bump = null;
8099
+ }
8100
+
8101
+ ReleaseTexture(tex, true);
8102
+ }
8103
+
8104
+ void ReleaseTexture(cTexture tex, boolean bump)
70618105 {
70628106 if (// DrawMode() != 0 || /*tex == null ||*/
70638107 ambientOcclusion ) // || !textureon)
....@@ -7068,7 +8112,7 @@
70688112 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
70698113
70708114 if (tex != null)
7071
- texture = textures.get(tex);
8115
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
70728116
70738117 // //assert( texture != null );
70748118 // if (texture == null)
....@@ -7160,7 +8204,55 @@
71608204 }
71618205 }
71628206
7163
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8207
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8208
+ {
8209
+// if (// DrawMode() != 0 || /*tex == null ||*/
8210
+// ambientOcclusion ) // || !textureon)
8211
+// {
8212
+// return; // false;
8213
+// }
8214
+//
8215
+// if (tex == null)
8216
+// {
8217
+// BindTexture(null,false,resolution);
8218
+// BindTexture(null,true,resolution);
8219
+// return;
8220
+// }
8221
+//
8222
+// String pigment = Object3D.GetPigment(tex);
8223
+// String bump = Object3D.GetBump(tex);
8224
+//
8225
+// usedtextures.add(pigment);
8226
+// usedtextures.add(bump);
8227
+//
8228
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8229
+// {
8230
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8231
+// // System.out.println("; bump = " + bump);
8232
+// }
8233
+//
8234
+// if (bump.equals(""))
8235
+// {
8236
+// bump = null;
8237
+// }
8238
+// if (pigment.equals(""))
8239
+// {
8240
+// pigment = null;
8241
+// }
8242
+//
8243
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8244
+// BindTexture(pigment, false, resolution);
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8246
+// BindTexture(bump, true, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8248
+//
8249
+// return; // true;
8250
+
8251
+ BindPigmentTexture(tex, resolution);
8252
+ BindBumpTexture(tex, resolution);
8253
+ }
8254
+
8255
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
71648256 {
71658257 if (// DrawMode() != 0 || /*tex == null ||*/
71668258 ambientOcclusion ) // || !textureon)
....@@ -7171,17 +8263,47 @@
71718263 if (tex == null)
71728264 {
71738265 BindTexture(null,false,resolution);
7174
- BindTexture(null,true,resolution);
71758266 return;
71768267 }
71778268
71788269 String pigment = Object3D.GetPigment(tex);
8270
+
8271
+ usedtextures.add(tex);
8272
+
8273
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8274
+ {
8275
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8276
+ // System.out.println("; bump = " + bump);
8277
+ }
8278
+
8279
+ if (pigment.equals(""))
8280
+ {
8281
+ pigment = null;
8282
+ }
8283
+
8284
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8285
+ BindTexture(tex, false, resolution);
8286
+ }
8287
+
8288
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8289
+ {
8290
+ if (// DrawMode() != 0 || /*tex == null ||*/
8291
+ ambientOcclusion ) // || !textureon)
8292
+ {
8293
+ return; // false;
8294
+ }
8295
+
8296
+ if (tex == null)
8297
+ {
8298
+ BindTexture(null,true,resolution);
8299
+ return;
8300
+ }
8301
+
71798302 String bump = Object3D.GetBump(tex);
71808303
7181
- usedtextures.put(pigment, pigment);
7182
- usedtextures.put(bump, bump);
8304
+ usedtextures.add(tex);
71838305
7184
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8306
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
71858307 {
71868308 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
71878309 // System.out.println("; bump = " + bump);
....@@ -7191,43 +8313,94 @@
71918313 {
71928314 bump = null;
71938315 }
7194
- if (pigment.equals(""))
7195
- {
7196
- pigment = null;
7197
- }
71988316
7199
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7200
- BindTexture(pigment, false, resolution);
72018317 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7202
- BindTexture(bump, true, resolution);
8318
+ BindTexture(tex, true, resolution);
72038319 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7204
-
7205
- return; // true;
72068320 }
72078321
7208
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8322
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8323
+
8324
+ private boolean FileExists(String tex)
72098325 {
7210
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8326
+ if (missingTextures.contains(tex))
8327
+ {
8328
+ return false;
8329
+ }
8330
+
8331
+ boolean fileExists = new File(tex).exists();
8332
+
8333
+ if (!fileExists)
8334
+ {
8335
+ // If file exists, the "new File()" is not executed sgain
8336
+ missingTextures.add(tex);
8337
+ }
8338
+
8339
+ return fileExists;
8340
+ }
8341
+
8342
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8343
+ {
8344
+ CacheTexture texturecache = null;
72118345
72128346 if (tex != null)
72138347 {
7214
- String texname = tex;
8348
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8349
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
72158350
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;
8351
+ if (texname.equals("") && texdata == null)
8352
+ {
8353
+ return null;
8354
+ }
8355
+
8356
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8357
+
8358
+// String[] split = tex.split("Textures");
8359
+// if (split.length > 1)
8360
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8361
+// else
8362
+// if (!texname.startsWith("/"))
8363
+// texname = "/Users/nbriere/Textures/" + texname;
8364
+ if (!FileExists(texname) && !texname.startsWith("@"))
8365
+ {
8366
+ texname = fallbackTextureName;
8367
+ }
72228368
72238369 if (CACHETEXTURE)
7224
- texture = textures.get(texname); // TEXTURE CACHE
7225
-
7226
- TextureData texturedata = null;
7227
-
7228
- if (texture == null || texture.resolution < resolution)
72298370 {
7230
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8371
+ if (texdata == null)
8372
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8373
+ else
8374
+ texturecache = bimtextures.get(texdata);
8375
+ }
8376
+
8377
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8378
+ {
8379
+ TextureData texturedata = null;
8380
+
8381
+ if (texdata != null && textureon)
8382
+ {
8383
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8384
+
8385
+ try
8386
+ {
8387
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8388
+ }
8389
+ catch (Exception e)
8390
+ {
8391
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8392
+ }
8393
+
8394
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8395
+ bimtextures.put(texdata, texturecache);
8396
+
8397
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8398
+
8399
+ //Object bim2 = CreateBim(texturecache.texturedata);
8400
+ //bim2 = bim;
8401
+ }
8402
+ else
8403
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
72318404 {
72328405 assert(!bump);
72338406 // if (bump)
....@@ -7238,19 +8411,23 @@
72388411 // }
72398412 // else
72408413 // {
7241
- texture = textures.get(tex);
7242
- if (texture == null)
8414
+ // texturecache = textures.get(texname); // suspicious
8415
+ if (texturecache == null)
72438416 {
7244
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8417
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
72458418 }
8419
+ else
8420
+ new Exception().printStackTrace();
72468421 // }
72478422 } else
7248
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8423
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
72498424 {
72508425 assert(bump);
7251
- texture = textures.get(tex);
7252
- if (texture == null)
7253
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8426
+ // texturecache = textures.get(texname); // suspicious
8427
+ if (texturecache == null)
8428
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8429
+ else
8430
+ new Exception().printStackTrace();
72548431 } else
72558432 {
72568433 //if (tex.equals("IMMORTAL"))
....@@ -7258,11 +8435,22 @@
72588435 // texture = GetResourceTexture("default.png");
72598436 //} else
72608437 //{
7261
- if (tex.equals("WHITE_NOISE"))
8438
+ if (texname.endsWith("WHITE_NOISE"))
72628439 {
7263
- texture = textures.get(tex);
7264
- if (texture == null)
7265
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8440
+ // texturecache = textures.get(texname); // suspicious
8441
+ if (texturecache == null)
8442
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8443
+ else
8444
+ new Exception().printStackTrace();
8445
+ } else
8446
+ {
8447
+ if (texname.startsWith("@"))
8448
+ {
8449
+ // texturecache = textures.get(texname); // suspicious
8450
+ if (texturecache == null)
8451
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8452
+ else
8453
+ new Exception().printStackTrace();
72668454 } else
72678455 {
72688456 if (textureon)
....@@ -7287,7 +8475,7 @@
72878475 }
72888476
72898477 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7290
- if (!new File(cachename).exists())
8478
+ if (!FileExists(cachename))
72918479 cachename = texname;
72928480 else
72938481 processbump = false; // don't process bump map again
....@@ -7309,7 +8497,7 @@
73098497 }
73108498
73118499 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7312
- if (!new File(cachename).exists())
8500
+ if (!FileExists(cachename))
73138501 cachename = texname;
73148502 else
73158503 processbump = false; // don't process bump map again
....@@ -7318,20 +8506,23 @@
73188506 texturedata = GetFileTexture(cachename, processbump, resolution);
73198507
73208508
7321
- if (texturedata != null)
7322
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8509
+ if (texturedata == null)
8510
+ throw new Exception();
8511
+
8512
+ texturecache = new CacheTexture(texturedata,resolution);
73238513 //texture = GetTexture(tex, bump);
73248514 }
8515
+ }
73258516 }
73268517 //}
73278518 }
73288519
7329
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8520
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
73308521 {
73318522 //return false;
73328523
73338524 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7334
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8525
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
73358526 {
73368527 // String ext = "_highres";
73378528 // if (REDUCETEXTURE)
....@@ -7348,52 +8539,17 @@
73488539 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
73498540 if (!cachefile.exists())
73508541 {
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))
8542
+ //if (texturedata.getWidth() == texturedata.getHeight())
73608543 {
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);
8544
+ BufferedImage rendImage = CreateBim(texturedata);
8545
+
73918546 ImageWriter writer = null;
73928547 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
73938548 if (iter.hasNext()) {
73948549 writer = (ImageWriter)iter.next();
73958550 }
7396
- float compressionQuality = 0.9f;
8551
+
8552
+ float compressionQuality = 0.85f;
73978553 try
73988554 {
73998555 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7410,18 +8566,20 @@
74108566 }
74118567 }
74128568 }
7413
-
8569
+
8570
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8571
+
74148572 //System.out.println("Texture = " + tex);
7415
- if (textures.containsKey(texname))
8573
+ if (textures.containsKey(tex))
74168574 {
7417
- CacheTexture thetex = textures.get(texname);
8575
+ CacheTexture thetex = textures.get(tex);
74188576 thetex.texture.disable();
74198577 thetex.texture.dispose();
7420
- textures.remove(texname);
8578
+ textures.remove(tex);
74218579 }
74228580
7423
- texture.texturedata = texturedata;
7424
- textures.put(texname, texture);
8581
+ //texture.texturedata = texturedata;
8582
+ textures.put(tex, texturecache);
74258583
74268584 // newtex = true;
74278585 }
....@@ -7437,10 +8595,44 @@
74378595 }
74388596 }
74398597
7440
- return texture;
8598
+ return texturecache;
74418599 }
74428600
7443
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8601
+ static void EmbedTextures(cTexture tex)
8602
+ {
8603
+ if (tex.pigmentdata == null)
8604
+ {
8605
+ //String texname = Object3D.GetPigment(tex);
8606
+
8607
+ CacheTexture texturecache = texturepigment.get(tex);
8608
+
8609
+ if (texturecache != null)
8610
+ {
8611
+ tex.pw = texturecache.texturedata.getWidth();
8612
+ tex.ph = texturecache.texturedata.getHeight();
8613
+ tex.pigmentdata = //CompressJPEG(CreateBim
8614
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8615
+ ;
8616
+ //, tex.pw, tex.ph), 0.5f);
8617
+ }
8618
+ }
8619
+
8620
+ if (tex.bumpdata == null)
8621
+ {
8622
+ //String texname = Object3D.GetBump(tex);
8623
+
8624
+ CacheTexture texturecache = texturebump.get(tex);
8625
+
8626
+ if (texturecache != null)
8627
+ {
8628
+ tex.bw = texturecache.texturedata.getWidth();
8629
+ tex.bh = texturecache.texturedata.getHeight();
8630
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8631
+ }
8632
+ }
8633
+ }
8634
+
8635
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
74448636 {
74458637 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
74468638
....@@ -7458,21 +8650,21 @@
74588650 return texture!=null?texture.texture:null;
74598651 }
74608652
7461
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8653
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
74628654 {
74638655 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
74648656
74658657 return texture!=null?texture.texturedata:null;
74668658 }
74678659
7468
- boolean BindTexture(String tex, boolean bump, int resolution)
8660
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
74698661 {
74708662 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
74718663 {
74728664 return false;
74738665 }
74748666
7475
- boolean newtex = false;
8667
+ //boolean newtex = false;
74768668
74778669 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
74788670
....@@ -7504,9 +8696,75 @@
75048696 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
75058697 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
75068698
7507
- return newtex;
8699
+ return true; // Warning: not used.
75088700 }
75098701
8702
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8703
+ {
8704
+ try
8705
+ {
8706
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8707
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8708
+ ImageWriter writer = writers.next();
8709
+
8710
+ ImageWriteParam param = writer.getDefaultWriteParam();
8711
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8712
+ param.setCompressionQuality(quality);
8713
+
8714
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8715
+ writer.setOutput(ios);
8716
+ writer.write(null, new IIOImage(image, null, null), param);
8717
+
8718
+ byte[] data = baos.toByteArray();
8719
+ writer.dispose();
8720
+ return data;
8721
+ }
8722
+ catch (Exception e)
8723
+ {
8724
+ e.printStackTrace();
8725
+ return null;
8726
+ }
8727
+ }
8728
+
8729
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8730
+ {
8731
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8732
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8733
+ ImageReader reader = writers.next();
8734
+
8735
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8736
+
8737
+ ImageReadParam param = reader.getDefaultReadParam();
8738
+ param.setDestination(bim);
8739
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8740
+
8741
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8742
+ reader.setInput(ios);
8743
+ BufferedImage bim2 = reader.read(0, param);
8744
+ reader.dispose();
8745
+
8746
+// WritableRaster raster = bim2.getRaster();
8747
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8748
+// byte[] bytes = data.getData();
8749
+//
8750
+// int[] pixels = new int[bytes.length/3];
8751
+// for (int i=pixels.length; --i>=0;)
8752
+// {
8753
+// int i3 = i*3;
8754
+// pixels[i] = 0xFF;
8755
+// pixels[i] <<= 8;
8756
+// pixels[i] |= bytes[i3+2] & 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+1] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3] & 0xFF;
8761
+// }
8762
+//
8763
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8764
+
8765
+ return bim;
8766
+ }
8767
+
75108768 ShadowBuffer shadowPBuf;
75118769 AntialiasBuffer antialiasPBuf;
75128770 int MAXSTACK;
....@@ -7523,10 +8781,12 @@
75238781
75248782 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
75258783 MAXSTACK = temp[0];
7526
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8784
+ if (Globals.DEBUG)
8785
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
75278786 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
75288787 MAXSTACK = temp[0];
7529
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8788
+ if (Globals.DEBUG)
8789
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
75308790
75318791 // Use debug pipeline
75328792 //drawable.setGL(new DebugGL(gl)); //
....@@ -7534,7 +8794,8 @@
75348794 gl = drawable.getGL(); //
75358795
75368796 GL gl3 = getGL();
7537
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8797
+ if (Globals.DEBUG)
8798
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
75388799
75398800
75408801 //float pos[] = { 100, 100, 100, 0 };
....@@ -7699,7 +8960,7 @@
76998960
77008961 if (cubemap == null)
77018962 {
7702
- LoadEnvy(5);
8963
+ //LoadEnvy(1);
77038964 }
77048965
77058966 //cubemap.enable();
....@@ -7975,6 +9236,8 @@
79759236
79769237 void LoadEnvy(int which)
79779238 {
9239
+ assert(false);
9240
+
79789241 String name;
79799242 String ext;
79809243
....@@ -7986,37 +9249,58 @@
79869249 cubemap = null;
79879250 return;
79889251 case 1:
7989
- name = "cubemaps/box_";
7990
- ext = "png";
9252
+ name = "cubemaps/rgb/";
9253
+ ext = "jpg";
79919254 reverseUP = false;
79929255 break;
79939256 case 2:
7994
- name = "cubemaps/uffizi_";
7995
- ext = "png";
7996
- break; // reverseUP = true; break;
9257
+ name = "cubemaps/uffizi/";
9258
+ ext = "jpg";
9259
+ reverseUP = false;
9260
+ break;
79979261 case 3:
7998
- name = "cubemaps/CloudyHills_";
7999
- ext = "tga";
9262
+ name = "cubemaps/CloudyHills/";
9263
+ ext = "jpg";
80009264 reverseUP = false;
80019265 break;
80029266 case 4:
8003
- name = "cubemaps/cornell_";
9267
+ name = "cubemaps/cornell/";
80049268 ext = "png";
80059269 reverseUP = false;
80069270 break;
9271
+ case 5:
9272
+ name = "cubemaps/skycube/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
9276
+ case 6:
9277
+ name = "cubemaps/SaintLazarusChurch3/";
9278
+ ext = "jpg";
9279
+ reverseUP = false;
9280
+ break;
9281
+ case 7:
9282
+ name = "cubemaps/Sodermalmsallen/";
9283
+ ext = "jpg";
9284
+ reverseUP = false;
9285
+ break;
9286
+ case 8:
9287
+ name = "cubemaps/Sodermalmsallen2/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 9:
9292
+ name = "cubemaps/UnionSquare/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
80079296 default:
8008
- name = "cubemaps/rgb_";
8009
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9297
+ name = "cubemaps/box/";
9298
+ ext = "png"; /*mipmap = true;*/
9299
+ reverseUP = false;
80109300 break;
80119301 }
8012
-
8013
- try
8014
- {
8015
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8016
- } catch (IOException e)
8017
- {
8018
- throw new RuntimeException(e);
8019
- }
9302
+
9303
+ LoadSkybox(name, ext, mipmap);
80209304 }
80219305
80229306 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8048,8 +9332,12 @@
80489332 static double[] model = new double[16];
80499333 double[] camera2light = new double[16];
80509334 double[] light2camera = new double[16];
8051
- int newenvy = -1;
8052
- boolean envyoff = true; // false;
9335
+
9336
+ //int newenvy = -1;
9337
+ //boolean envyoff = false;
9338
+
9339
+ String loadedskyboxname;
9340
+
80539341 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
80549342 //float[] light0 = { 0,0,0 };
80559343 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -8342,11 +9630,35 @@
83429630 jy8[3] = 0.5f;
83439631 }
83449632
8345
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9633
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
83469634 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
83479635 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
83489636 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
83499637
9638
+ void ResetOptions()
9639
+ {
9640
+ options1[0] = 100;
9641
+ options1[1] = 0.025f;
9642
+ options1[2] = 0.01f;
9643
+ options1[3] = 0;
9644
+ options1[4] = 0;
9645
+
9646
+ options2[0] = 0;
9647
+ options2[1] = 0.75f;
9648
+ options2[2] = 0;
9649
+ options2[3] = 0;
9650
+
9651
+ options3[0] = 1;
9652
+ options3[1] = 1;
9653
+ options3[2] = 1;
9654
+ options3[3] = 0;
9655
+
9656
+ options4[0] = 1;
9657
+ options4[1] = 0;
9658
+ options4[2] = 1;
9659
+ options4[3] = 0;
9660
+ }
9661
+
83509662 static int imagecount = 0; // movie generation
83519663
83529664 static int jitter = 0;
....@@ -8442,8 +9754,8 @@
84429754 assert (parentcam != renderCamera);
84439755
84449756 if (renderCamera != lightCamera)
8445
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8446
- LA.matConcat(matrix, parentcam.toParent, matrix);
9757
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9758
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
84479759
84489760 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
84499761
....@@ -8458,8 +9770,8 @@
84589770 LA.matCopy(renderCamera.fromScreen, matrix);
84599771
84609772 if (renderCamera != lightCamera)
8461
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8462
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9773
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9774
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
84639775
84649776 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
84659777
....@@ -8505,10 +9817,12 @@
85059817 rati = 1 / rati;
85069818 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
85079819 }
8508
- assert (newenvy == -1);
9820
+
9821
+ //assert (newenvy == -1);
9822
+
85099823 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
85109824 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
8511
- DrawSkyBox(gl);
9825
+ DrawSkyBox(gl, (float)rati);
85129826 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
85139827 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
85149828 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -8531,7 +9845,7 @@
85319845 //gl.glFlush();
85329846 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
85339847
8534
- if (ANIMATION && ABORTED)
9848
+ if (Globals.ANIMATION && ABORTED)
85359849 {
85369850 System.err.println(" ABORTED FRAME");
85379851 break;
....@@ -8561,7 +9875,7 @@
85619875 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
85629876
85639877 // save image
8564
- if (ANIMATION && !ABORTED)
9878
+ if (Globals.ANIMATION && !ABORTED)
85659879 {
85669880 VPwidth = viewport[2];
85679881 VPheight = viewport[3];
....@@ -8672,11 +9986,11 @@
86729986
86739987 // imagecount++;
86749988
8675
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9989
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
86769990
86779991 if (!BOXMODE)
86789992 {
8679
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9993
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
86809994 }
86819995
86829996 if (!BOXMODE)
....@@ -8714,7 +10028,7 @@
871410028 ABORTED = false;
871510029 }
871610030 else
8717
- GrafreeD.wav.cursor += 735 * ACSIZE;
10031
+ Grafreed.wav.cursor += 735 * ACSIZE;
871810032
871910033 if (false)
872010034 {
....@@ -9377,11 +10691,11 @@
937710691
937810692 public void display(GLAutoDrawable drawable)
937910693 {
9380
- if (GrafreeD.savesound && GrafreeD.hassound)
10694
+ if (Grafreed.savesound && Grafreed.hassound)
938110695 {
9382
- GrafreeD.wav.save();
9383
- GrafreeD.savesound = false;
9384
- GrafreeD.hassound = false;
10696
+ Grafreed.wav.save();
10697
+ Grafreed.savesound = false;
10698
+ Grafreed.hassound = false;
938510699 }
938610700 // if (DEBUG_SELECTION)
938710701 // {
....@@ -9457,6 +10771,7 @@
945710771 ANTIALIAS = 0;
945810772 //System.out.println("RESTART");
945910773 AAtimer.restart();
10774
+ Globals.TIMERRUNNING = true;
946010775 }
946110776 }
946210777 }
....@@ -9511,7 +10826,7 @@
951110826 Object3D theobject = object;
951210827 Object3D theparent = object.parent;
951310828 object.parent = null;
9514
- object = (Object3D)GrafreeD.clone(object);
10829
+ object = (Object3D)Grafreed.clone(object);
951510830 object.Stripify();
951610831 if (theobject.selection == null || theobject.selection.Size() == 0)
951710832 theobject.PreprocessOcclusion(this);
....@@ -9524,13 +10839,14 @@
952410839 ambientOcclusion = false;
952510840 }
952610841
9527
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10842
+ if (//Globals.lighttouched &&
10843
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
952810844 {
952910845 //if (RENDERSHADOW) // ?
953010846 if (!IsFrozen())
953110847 {
953210848 // dec 2012
9533
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10849
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
953410850 {
953510851 Globals.framecount++;
953610852 shadowbuffer.display();
....@@ -9543,7 +10859,7 @@
954310859
954410860 if (wait)
954510861 {
9546
- Sleep(500);
10862
+ Sleep(200); // blocks everything
954710863
954810864 wait = false;
954910865 }
....@@ -9657,8 +10973,8 @@
965710973
965810974 // if (parentcam != renderCamera) // not a light
965910975 if (cam != lightCamera)
9660
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9661
- LA.matConcat(matrix, parentcam.toParent, matrix);
10976
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10977
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
966210978
966310979 for (int j = 0; j < 4; j++)
966410980 {
....@@ -9672,8 +10988,8 @@
967210988
967310989 // if (parentcam != renderCamera) // not a light
967410990 if (cam != lightCamera)
9675
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9676
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10991
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10992
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
967710993
967810994 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
967910995
....@@ -9759,13 +11075,41 @@
975911075 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
976011076 }
976111077
9762
- if (newenvy > -1)
11078
+// if (newenvy > -1)
11079
+// {
11080
+// LoadEnvy(newenvy);
11081
+// }
11082
+//
11083
+// newenvy = -1;
11084
+
11085
+ if (object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
976311086 {
9764
- LoadEnvy(newenvy);
11087
+ if (cubemaprgb == null)
11088
+ {
11089
+ cubemaprgb = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11090
+ }
11091
+
11092
+ cubemap = cubemaprgb;
976511093 }
9766
-
9767
- newenvy = -1;
9768
-
11094
+ else
11095
+ {
11096
+ if (object.skyboxname != null)
11097
+ {
11098
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11099
+ {
11100
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11101
+ loadedskyboxname = object.skyboxname;
11102
+ }
11103
+ }
11104
+ else
11105
+ {
11106
+ cubemapcustom = null;
11107
+ loadedskyboxname = null;
11108
+ }
11109
+
11110
+ cubemap = cubemapcustom;
11111
+ }
11112
+
976911113 ratio = ((double) getWidth()) / getHeight();
977011114 //System.out.println("ratio = " + ratio);
977111115
....@@ -9781,7 +11125,7 @@
978111125
978211126 if (!IsFrozen() && !ambientOcclusion)
978311127 {
9784
- DrawSkyBox(gl);
11128
+ DrawSkyBox(gl, (float)ratio);
978511129 }
978611130
978711131 //if (selection_view == -1)
....@@ -9932,7 +11276,16 @@
993211276 // Bump noise
993311277 gl.glActiveTexture(GL.GL_TEXTURE6);
993411278 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9935
- BindTexture(NOISE_TEXTURE, false, 2);
11279
+
11280
+ try
11281
+ {
11282
+ BindTexture(NOISE_TEXTURE, false, 2);
11283
+ }
11284
+ catch (Exception e)
11285
+ {
11286
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11287
+ }
11288
+
993611289
993711290 gl.glActiveTexture(GL.GL_TEXTURE0);
993811291 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9955,9 +11308,9 @@
995511308
995611309 gl.glMatrixMode(GL.GL_MODELVIEW);
995711310
9958
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9959
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9960
-//gl.glEnable(gl.GL_MULTISAMPLE);
11311
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11312
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11313
+gl.glEnable(gl.GL_MULTISAMPLE);
996111314 } else
996211315 {
996311316 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9968,7 +11321,7 @@
996811321 //System.out.println("BLENDING ON");
996911322 gl.glEnable(GL.GL_BLEND);
997011323 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9971
-
11324
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
997211325 gl.glMatrixMode(gl.GL_PROJECTION);
997311326 gl.glLoadIdentity();
997411327
....@@ -10057,8 +11410,8 @@
1005711410 System.err.println("parentcam != renderCamera");
1005811411
1005911412 // if (cam != lightCamera)
10060
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10061
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11413
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11414
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1006211415 }
1006311416
1006411417 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10079,8 +11432,8 @@
1007911432 if (true) // TODO
1008011433 {
1008111434 if (cam != lightCamera)
10082
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10083
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11435
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11436
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1008411437 }
1008511438
1008611439 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10146,7 +11499,7 @@
1014611499 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
1014711500 //System.out.println("fragmentMode = " + fragmentMode);
1014811501
10149
- if (DrawMode() == DEFAULT || DrawMode() == SELECTION || DEBUG_SELECTION)
11502
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
1015011503 {
1015111504 /*
1015211505 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -10217,7 +11570,7 @@
1021711570 }
1021811571 }
1021911572
10220
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11573
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1022111574 {
1022211575 //gl.glDepthFunc(GL.GL_LEQUAL);
1022311576 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10225,24 +11578,21 @@
1022511578
1022611579 boolean texon = textureon;
1022711580
10228
- if (RENDERPROGRAM > 0)
10229
- {
10230
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10231
- textureon = false;
10232
- }
11581
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11582
+ textureon = false;
11583
+
1023311584 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1023411585 //System.out.println("ALLO");
1023511586 gl.glColorMask(false, false, false, false);
1023611587 DrawObject(gl);
10237
- if (RENDERPROGRAM > 0)
10238
- {
10239
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10240
- textureon = texon;
10241
- }
11588
+
11589
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11590
+ textureon = texon;
11591
+
1024211592 gl.glColorMask(true, true, true, true);
1024311593
1024411594 gl.glDepthFunc(GL.GL_EQUAL);
10245
- //gl.glDepthMask(false);
11595
+ gl.glDepthMask(false);
1024611596 }
1024711597
1024811598 if (false) // DrawMode() == SHADOW)
....@@ -10396,8 +11746,14 @@
1039611746 {
1039711747 renderpass++;
1039811748 // System.out.println("Draw object... ");
11749
+ STEP = 1;
1039911750 if (FAST) // in case there is no script
10400
- STEP = 16;
11751
+ STEP = 8;
11752
+
11753
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11754
+ {
11755
+ STEP *= 4;
11756
+ }
1040111757
1040211758 //object.FullInvariants();
1040311759
....@@ -10411,23 +11767,44 @@
1041111767 e.printStackTrace();
1041211768 }
1041311769
10414
- if (GrafreeD.RENDERME > 0)
10415
- GrafreeD.RENDERME--; // mechante magouille
11770
+ if (Grafreed.RENDERME > 0)
11771
+ Grafreed.RENDERME--; // mechante magouille
1041611772
1041711773 Globals.ONESTEP = false;
1041811774 }
1041911775
1042011776 static boolean zoomonce = false;
1042111777
11778
+ static void CreateSelectedPoint()
11779
+ {
11780
+ if (selectedpoint == null)
11781
+ {
11782
+ debugpointG = new Sphere();
11783
+ debugpointP = new Sphere();
11784
+ debugpointC = new Sphere();
11785
+ debugpointR = new Sphere();
11786
+
11787
+ selectedpoint = new Superellipsoid();
11788
+
11789
+ for (int i=0; i<8; i++)
11790
+ {
11791
+ debugpoints[i] = new Sphere();
11792
+ }
11793
+ }
11794
+ }
11795
+
1042211796 void DrawObject(GL gl, boolean draw)
1042311797 {
11798
+ // To clear camera values
11799
+ ResetOptions();
11800
+
1042411801 //System.out.println("DRAW OBJECT " + mouseDown);
1042511802 // DrawMode() = SELECTION;
1042611803 //GL gl = getGL();
1042711804 if ((TRACK || SHADOWTRACK) || zoomonce)
1042811805 {
1042911806 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10430
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11807
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1043111808 pingthread.StepToTarget(true); // true);
1043211809 // zoomonce = false;
1043311810 }
....@@ -10447,7 +11824,7 @@
1044711824 callist = gl.glGenLists(1);
1044811825 }
1044911826
10450
- boolean selectmode = DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
11827
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
1045111828
1045211829 boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
1045311830
....@@ -10482,7 +11859,14 @@
1048211859
1048311860 usedtextures.clear();
1048411861
10485
- BindTextures(DEFAULT_TEXTURES, 2);
11862
+ try
11863
+ {
11864
+ BindTextures(DEFAULT_TEXTURES, 2);
11865
+ }
11866
+ catch (Exception e)
11867
+ {
11868
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11869
+ }
1048611870 }
1048711871 //System.out.println("--> " + stackdepth);
1048811872 // GrafreeD.traceon();
....@@ -10492,8 +11876,9 @@
1049211876
1049311877 if (DrawMode() == DEFAULT)
1049411878 {
10495
- if (DEBUG)
11879
+ if (Globals.DEBUG)
1049611880 {
11881
+ CreateSelectedPoint();
1049711882 float radius = 0.05f;
1049811883 if (selectedpoint.radius != radius)
1049911884 {
....@@ -10547,20 +11932,32 @@
1054711932 ReleaseTextures(DEFAULT_TEXTURES);
1054811933
1054911934 if (CLEANCACHE)
10550
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11935
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1055111936 {
10552
- String tex = e.nextElement();
11937
+ cTexture tex = e.nextElement();
1055311938
1055411939 // System.out.println("Texture --------- " + tex);
1055511940
10556
- if (tex.equals("WHITE_NOISE"))
11941
+ if (tex.equals("WHITE_NOISE:"))
1055711942 continue;
1055811943
10559
- if (!usedtextures.containsKey(tex))
11944
+ if (!usedtextures.contains(tex))
1056011945 {
11946
+ CacheTexture gettex = texturepigment.get(tex);
1056111947 // System.out.println("DISPOSE +++++++++++++++ " + tex);
10562
- textures.get(tex).texture.dispose();
10563
- textures.remove(tex);
11948
+ if (gettex != null)
11949
+ {
11950
+ gettex.texture.dispose();
11951
+ texturepigment.remove(tex);
11952
+ }
11953
+
11954
+ gettex = texturebump.get(tex);
11955
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11956
+ if (gettex != null)
11957
+ {
11958
+ gettex.texture.dispose();
11959
+ texturebump.remove(tex);
11960
+ }
1056411961 }
1056511962 }
1056611963 }
....@@ -10573,7 +11970,14 @@
1057311970 if (checker != null && DrawMode() == DEFAULT)
1057411971 {
1057511972 //BindTexture(IMMORTAL_TEXTURE);
10576
- BindTextures(checker.GetTextures(), checker.texres);
11973
+ try
11974
+ {
11975
+ BindTextures(checker.GetTextures(), checker.texres);
11976
+ }
11977
+ catch (Exception e)
11978
+ {
11979
+ System.err.println("FAILED: " + checker.GetTextures());
11980
+ }
1057711981 // NEAREST
1057811982 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1057911983 DrawChecker(gl);
....@@ -10655,7 +12059,7 @@
1065512059 return;
1065612060 }
1065712061
10658
- String string = obj.GetToolTip();
12062
+ String string = obj.toString(); //.GetToolTip();
1065912063
1066012064 GL gl = GetGL();
1066112065
....@@ -10972,8 +12376,8 @@
1097212376 //obj.TransformToWorld(light, light);
1097312377 for (int i = tp.size(); --i >= 0;)
1097412378 {
10975
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10976
- LA.xformPos(light, tp.get(i).toParent, light);
12379
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12380
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1097712381 }
1097812382
1097912383
....@@ -10990,8 +12394,8 @@
1099012394 parentcam = cameras[0];
1099112395 }
1099212396
10993
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10994
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12397
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12398
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1099512399
1099612400 LA.xformPos(light, renderCamera.toScreen, light);
1099712401
....@@ -11081,8 +12485,76 @@
1108112485
1108212486 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1108312487
11084
- String program =
12488
+ String programmin =
12489
+ // Min shader
1108512490 "!!ARBfp1.0\n" +
12491
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12492
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12493
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12494
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12495
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12496
+ "PARAM light2cam0 = program.env[10];" +
12497
+ "PARAM light2cam1 = program.env[11];" +
12498
+ "PARAM light2cam2 = program.env[12];" +
12499
+ "TEMP temp;" +
12500
+ "TEMP light;" +
12501
+ "TEMP ndotl;" +
12502
+ "TEMP normal;" +
12503
+ "TEMP depth;" +
12504
+ "TEMP eye;" +
12505
+ "TEMP pos;" +
12506
+
12507
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12508
+ Normalize("normal") +
12509
+ "MOV light, state.light[0].position;" +
12510
+ "DP3 ndotl.x, light, normal;" +
12511
+
12512
+ // shadow
12513
+ "MOV pos, fragment.texcoord[1];" +
12514
+ "MOV temp, pos;" +
12515
+ ShadowTextureFetch("depth", "temp", "1") +
12516
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12517
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12518
+
12519
+ // No shadow when out of frustum
12520
+ //"SGE temp.y, depth.z, zero123.y;" +
12521
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12522
+
12523
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12524
+
12525
+ // Backlit
12526
+ "MOV pos.w, zero123.y;" +
12527
+ "DP4 eye.x, pos, light2cam0;" +
12528
+ "DP4 eye.y, pos, light2cam1;" +
12529
+ "DP4 eye.z, pos, light2cam2;" +
12530
+ Normalize("eye") +
12531
+
12532
+ "DP3 ndotl.y, -eye, normal;" +
12533
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12534
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12535
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12536
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12538
+
12539
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12540
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12541
+
12542
+ // Pigment
12543
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12544
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12545
+ "MUL temp, temp, ndotl.x;" +
12546
+
12547
+ "MUL temp, temp, zero123.z;" +
12548
+
12549
+ //"MUL temp, temp, ndotl.y;" +
12550
+
12551
+ "MOV temp.w, zero123.y;" + // reset alpha
12552
+ "MOV result.color, temp;" +
12553
+ "END";
12554
+
12555
+ String programmax =
12556
+ "!!ARBfp1.0\n" +
12557
+
1108612558 //"OPTION ARB_fragment_program_shadow;" +
1108712559 "PARAM light2cam0 = program.env[10];" +
1108812560 "PARAM light2cam1 = program.env[11];" +
....@@ -11197,8 +12669,7 @@
1119712669 "TEMP shininess;" +
1119812670 "\n" +
1119912671 "MOV texSamp, one;" +
11200
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11201
-
12672
+
1120212673 "MOV mapgrid.x, one2048th.x;" +
1120312674 "MOV temp, fragment.texcoord[1];" +
1120412675 /*
....@@ -11219,20 +12690,20 @@
1121912690 "MUL temp, floor, mapgrid.x;" +
1122012691 //"TEX depth0, temp, texture[1], 2D;" +
1122112692 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11222
- TextureFetch("depth0", "temp", "1") +
12693
+ ShadowTextureFetch("depth0", "temp", "1") +
1122312694 "") +
1122412695 "ADD temp.x, temp.x, mapgrid.x;" +
1122512696 //"TEX depth1, temp, texture[1], 2D;" +
1122612697 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11227
- TextureFetch("depth1", "temp", "1") +
12698
+ ShadowTextureFetch("depth1", "temp", "1") +
1122812699 "") +
1122912700 "ADD temp.y, temp.y, mapgrid.x;" +
1123012701 //"TEX depth2, temp, texture[1], 2D;" +
11231
- TextureFetch("depth2", "temp", "1") +
12702
+ ShadowTextureFetch("depth2", "temp", "1") +
1123212703 "SUB temp.x, temp.x, mapgrid.x;" +
1123312704 //"TEX depth3, temp, texture[1], 2D;" +
1123412705 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11235
- TextureFetch("depth3", "temp", "1") +
12706
+ ShadowTextureFetch("depth3", "temp", "1") +
1123612707 "") +
1123712708 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1123812709 //"MOV params, material;" +
....@@ -11603,10 +13074,10 @@
1160313074 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1160413075 "") +
1160513076
11606
- // display shadow only (bump == 0)
13077
+ // display shadow only (fakedepth == 0)
1160713078 "SUB temp.x, half.x, shadow.x;" +
11608
- "MOV temp.y, -params6.x;" +
11609
- "SLT temp.z, temp.y, zero.x;" +
13079
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13080
+ "SLT temp.z, temp.y, -c256i.x;" +
1161013081 "SUB temp.y, one.x, temp.z;" +
1161113082 "MUL temp.x, temp.x, temp.y;" +
1161213083 "KIL temp.x;" +
....@@ -11735,8 +13206,10 @@
1173513206 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1173613207
1173713208 "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
13209
+ // Tuning for default skin
13210
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13211
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13212
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1174013213 "MUL temp.x, temp.x, temp.y;" +
1174113214
1174213215 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11935,7 +13408,14 @@
1193513408 //once = true;
1193613409 }
1193713410
11938
- System.out.print("Program #" + mode + "; length = " + program.length());
13411
+ String program = programmax;
13412
+
13413
+ if (Globals.MINSHADER)
13414
+ {
13415
+ program = programmin;
13416
+ }
13417
+
13418
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1193913419 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1194013420 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1194113421
....@@ -12028,25 +13508,26 @@
1202813508 return out;
1202913509 }
1203013510
12031
- String TextureFetch(String dest, String src, String unit)
13511
+ // Also does frustum culling
13512
+ String ShadowTextureFetch(String dest, String src, String unit)
1203213513 {
1203313514 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1203413515 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1203513516 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13517
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13518
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1203613519 "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;" +
13520
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13521
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1204113522 //"SWZ buffer, temp, w,w,w,w;";
12042
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13523
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1204313524 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1204413525 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1204513526 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12046
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13527
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1204713528
12048
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12049
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13529
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13530
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1205013531 }
1205113532
1205213533 String Shadow(String depth, String shadow)
....@@ -12068,12 +13549,16 @@
1206813549
1206913550 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1207013551 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13552
+
13553
+ // Compare fragment depth in light space with shadowmap.
1207113554 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1207213555 "SGE temp.y, temp.x, zero.x;" +
12073
- "SUB " + shadow + ".y, one.x, temp.y;" +
13556
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13557
+
13558
+ // Reverse comparison
1207413559 "SUB temp.x, one.x, temp.x;" +
1207513560 "MUL " + shadow + ".x, temp.x, temp.y;" +
12076
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13561
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1207713562 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1207813563
1207913564 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12087,6 +13572,10 @@
1208713572 // No shadow for backface
1208813573 "DP3 temp.x, normal, lightd;" +
1208913574 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13575
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13576
+
13577
+ // No shadow when out of frustum
13578
+ "SGE temp.x, " + depth + ".z, one.z;" +
1209013579 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1209113580 "";
1209213581 }
....@@ -12233,7 +13722,8 @@
1223313722 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1223413723 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1223513724 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12236
- Object3D.cVector2[] vector2buffer;
13725
+
13726
+ //Object3D.cVector2[] vector2buffer;
1223713727
1223813728 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1223913729 // OUT : diff, spec
....@@ -12249,9 +13739,10 @@
1224913739 "DP3 " + dest + ".z," + "normals," + "eye;" +
1225013740 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1225113741 //"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;" +
13742
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13743
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13744
+
13745
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1225513746 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1225613747 "RCP " + dest + ".w," + dest + ".w;" +
1225713748 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -12645,7 +14136,7 @@
1264514136 public void mousePressed(MouseEvent e)
1264614137 {
1264714138 //System.out.println("mousePressed: " + e);
12648
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14139
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1264914140 }
1265014141
1265114142 static long prevtime = 0;
....@@ -12672,6 +14163,7 @@
1267214163
1267314164 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1267414165
14166
+ if (BUTTONLESSWHEEL)
1267514167 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1267614168 {
1267714169 return;
....@@ -12680,7 +14172,7 @@
1268014172 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1268114173
1268214174 // TIMER
12683
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14175
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1268414176 {
1268514177 keepboxmode = BOXMODE;
1268614178 keepsupport = SUPPORT;
....@@ -12720,8 +14212,8 @@
1272014212 // mode |= META;
1272114213 //}
1272214214
12723
- SetMouseMode(WHEEL | e.getModifiersEx());
12724
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14215
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14216
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1272514217 anchorX = ax;
1272614218 anchorY = ay;
1272714219 prevX = px;
....@@ -12755,6 +14247,7 @@
1275514247 else
1275614248 if (evt.getSource() == AAtimer)
1275714249 {
14250
+ Globals.TIMERRUNNING = false;
1275814251 if (mouseDown)
1275914252 {
1276014253 //new Exception().printStackTrace();
....@@ -12780,6 +14273,10 @@
1278014273 // LIVE = waslive;
1278114274 // wasliveok = true;
1278214275 // waslive = false;
14276
+
14277
+ // May 2019 Forget it:
14278
+ if (true)
14279
+ return;
1278314280
1278414281 // source == timer
1278514282 if (mouseDown)
....@@ -12810,7 +14307,7 @@
1281014307
1281114308 // fev 2014???
1281214309 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
12813
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14310
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1281414311 pingthread.StepToTarget(true); // true);
1281514312 }
1281614313 // if (!LIVE)
....@@ -12819,12 +14316,13 @@
1281914316
1282014317 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1282114318
12822
- void clickStart(int x, int y, int modifiers)
14319
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1282314320 {
1282414321 if (!wasliveok)
1282514322 return;
1282614323
1282714324 AAtimer.restart(); //
14325
+ Globals.TIMERRUNNING = true;
1282814326
1282914327 // waslive = LIVE;
1283014328 // LIVE = false;
....@@ -12836,7 +14334,7 @@
1283614334 // touched = true; // main DL
1283714335 if (isRenderer)
1283814336 {
12839
- SetMouseMode(modifiers);
14337
+ SetMouseMode(modifiers, modifiersex);
1284014338 }
1284114339
1284214340 selectX = anchorX = x;
....@@ -12849,7 +14347,7 @@
1284914347 clicked = true;
1285014348 hold = false;
1285114349
12852
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14350
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1285314351 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1285414352 {
1285514353 // System.out.println("RESTART II " + modifiers);
....@@ -12874,14 +14372,15 @@
1287414372 drag = false;
1287514373 //System.out.println("Mouse DOWN");
1287614374 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);
14375
+ //ClickInfo info = new ClickInfo();
14376
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14377
+ object.clickInfo.pane = this;
14378
+ object.clickInfo.camera = renderCamera;
14379
+ object.clickInfo.x = x;
14380
+ object.clickInfo.y = y;
14381
+ object.clickInfo.modifiers = modifiersex;
14382
+ editObj = object.doEditClick(//info,
14383
+ 0);
1288514384 if (!editObj)
1288614385 {
1288714386 hasMarquee = true;
....@@ -12897,11 +14396,14 @@
1289714396
1289814397 public void mouseDragged(MouseEvent e)
1289914398 {
14399
+ Globals.MOUSEDRAGGED = true;
14400
+
14401
+ //System.out.println("mouseDragged: " + e);
1290014402 if (isRenderer)
1290114403 movingcamera = true;
14404
+
1290214405 //if (drawing)
1290314406 //return;
12904
- //System.out.println("mouseDragged: " + e);
1290514407 if ((e.getModifiersEx() & CTRL) != 0
1290614408 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1290714409 {
....@@ -12909,7 +14411,7 @@
1290914411 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1291014412 }
1291114413 else
12912
- drag(e.getX(), e.getY(), e.getModifiersEx());
14414
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1291314415
1291414416 //try { Thread.sleep(1); } catch (Exception ex) {}
1291514417 }
....@@ -12921,6 +14423,11 @@
1292114423 cVector tmp = new cVector();
1292214424 cVector tmp2 = new cVector();
1292314425 boolean isMoving;
14426
+
14427
+ public cVector TargetLookAt()
14428
+ {
14429
+ return targetLookAt;
14430
+ }
1292414431
1292514432 class PingThread extends Thread
1292614433 {
....@@ -13077,6 +14584,7 @@
1307714584
1307814585 public void run()
1307914586 {
14587
+ new Exception().printStackTrace();
1308014588 System.exit(0);
1308114589 for (;;)
1308214590 {
....@@ -13140,7 +14648,7 @@
1314014648 {
1314114649 Globals.lighttouched = true;
1314214650 }
13143
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14651
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1314414652 }
1314514653 //else
1314614654 }
....@@ -13154,12 +14662,12 @@
1315414662 void GoDown(int mod)
1315514663 {
1315614664 MODIFIERS |= COMMAND;
13157
- /*
14665
+ /**/
1315814666 if((mod&SHIFT) == SHIFT)
13159
- manipCamera.RotatePosition(0, -speed);
14667
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1316014668 else
13161
- manipCamera.BackForth(0, -speed*delta, getWidth());
13162
- */
14669
+ manipCamera.RotatePosition(0, -speed);
14670
+ /**/
1316314671 if ((mod & SHIFT) == SHIFT)
1316414672 {
1316514673 mouseMode = mouseMode; // VR??
....@@ -13175,12 +14683,12 @@
1317514683 void GoUp(int mod)
1317614684 {
1317714685 MODIFIERS |= COMMAND;
13178
- /*
14686
+ /**/
1317914687 if((mod&SHIFT) == SHIFT)
13180
- manipCamera.RotatePosition(0, speed);
14688
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1318114689 else
13182
- manipCamera.BackForth(0, speed*delta, getWidth());
13183
- */
14690
+ manipCamera.RotatePosition(0, speed);
14691
+ /**/
1318414692 if ((mod & SHIFT) == SHIFT)
1318514693 {
1318614694 mouseMode = mouseMode;
....@@ -13196,12 +14704,12 @@
1319614704 void GoLeft(int mod)
1319714705 {
1319814706 MODIFIERS |= COMMAND;
13199
- /*
14707
+ /**/
1320014708 if((mod&SHIFT) == SHIFT)
13201
- manipCamera.RotatePosition(speed, 0);
13202
- else
1320314709 manipCamera.Translate(speed*delta, 0, getWidth());
13204
- */
14710
+ else
14711
+ manipCamera.RotatePosition(speed, 0);
14712
+ /**/
1320514713 if ((mod & SHIFT) == SHIFT)
1320614714 {
1320714715 mouseMode = mouseMode;
....@@ -13217,12 +14725,12 @@
1321714725 void GoRight(int mod)
1321814726 {
1321914727 MODIFIERS |= COMMAND;
13220
- /*
14728
+ /**/
1322114729 if((mod&SHIFT) == SHIFT)
13222
- manipCamera.RotatePosition(-speed, 0);
13223
- else
1322414730 manipCamera.Translate(-speed*delta, 0, getWidth());
13225
- */
14731
+ else
14732
+ manipCamera.RotatePosition(-speed, 0);
14733
+ /**/
1322614734 if ((mod & SHIFT) == SHIFT)
1322714735 {
1322814736 mouseMode = mouseMode;
....@@ -13240,7 +14748,7 @@
1324014748 int X, Y;
1324114749 boolean SX, SY;
1324214750
13243
- void drag(int x, int y, int modifiers)
14751
+ void drag(int x, int y, int modifiers, int modifiersex)
1324414752 {
1324514753 if (IsFrozen())
1324614754 {
....@@ -13249,17 +14757,17 @@
1324914757
1325014758 drag = true; // NEW
1325114759
13252
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14760
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1325314761
1325414762 X = x;
1325514763 Y = y;
1325614764 // floating state for animation
13257
- MODIFIERS = modifiers;
13258
- modifiers &= ~1024;
14765
+ MODIFIERS = modifiersex;
14766
+ modifiersex &= ~1024;
1325914767 if (false) // modifiers != 0)
1326014768 {
1326114769 //new Exception().printStackTrace();
13262
- System.out.println("mouseDragged: " + modifiers);
14770
+ System.out.println("mouseDragged: " + modifiersex);
1326314771 System.out.println("SHIFT = " + SHIFT);
1326414772 System.out.println("CONTROL = " + COMMAND);
1326514773 System.out.println("META = " + META);
....@@ -13272,14 +14780,16 @@
1327214780 if (editObj)
1327314781 {
1327414782 drag = true;
13275
- ClickInfo info = new ClickInfo();
13276
- info.bounds.setBounds(0, 0,
14783
+ //ClickInfo info = new ClickInfo();
14784
+ object.clickInfo.bounds.setBounds(0, 0,
1327714785 (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);
14786
+ object.clickInfo.pane = this;
14787
+ object.clickInfo.camera = renderCamera;
14788
+ object.clickInfo.x = x;
14789
+ object.clickInfo.y = y;
14790
+ object //.GetWindow().copy
14791
+ .doEditDrag(//info,
14792
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1328314793 } else
1328414794 {
1328514795 if (x < startX)
....@@ -13428,23 +14938,27 @@
1342814938 }
1342914939 }
1343014940
14941
+// ClickInfo clickInfo = new ClickInfo();
14942
+
1343114943 public void mouseMoved(MouseEvent e)
1343214944 {
1343314945 //System.out.println("mouseMoved: " + e);
13434
-
1343514946 if (isRenderer)
1343614947 return;
1343714948
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;
14949
+ // Mouse cursor feedback
14950
+ object.clickInfo.x = e.getX();
14951
+ object.clickInfo.y = e.getY();
14952
+ object.clickInfo.modifiers = e.getModifiersEx();
14953
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14954
+ object.clickInfo.pane = this;
14955
+ object.clickInfo.camera = renderCamera;
1344514956 if (!isRenderer)
1344614957 {
13447
- if (object.editWindow.copy.doEditClick(ci, 0))
14958
+ //ObjEditor editWindow = object.editWindow;
14959
+ //Object3D copy = editWindow.copy;
14960
+ if (object.doEditClick(//clickInfo,
14961
+ 0))
1344814962 {
1344914963 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1345014964 } else
....@@ -13456,7 +14970,11 @@
1345614970
1345714971 public void mouseReleased(MouseEvent e)
1345814972 {
14973
+ Globals.MOUSEDRAGGED = false;
14974
+
1345914975 movingcamera = false;
14976
+ X = 0; // getBounds().width/2;
14977
+ Y = 0; // getBounds().height/2;
1346014978 //System.out.println("mouseReleased: " + e);
1346114979 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1346214980 }
....@@ -13479,9 +14997,9 @@
1347914997 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1348014998 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1348114999
13482
- if (control || command || IsFrozen())
15000
+// No delay if (control || command || IsFrozen())
1348315001 timeout = true;
13484
- else
15002
+// ?? May 2019 else
1348515003 // timer.setDelay((modifiers & 128) != 0?0:350);
1348615004 mouseDown = false;
1348715005 if (!control && !command) // june 2013
....@@ -13591,7 +15109,7 @@
1359115109 System.out.println("keyReleased: " + e);
1359215110 }
1359315111
13594
- void SetMouseMode(int modifiers)
15112
+ void SetMouseMode(int modifiers, int modifiersex)
1359515113 {
1359615114 //System.out.println("SetMouseMode = " + modifiers);
1359715115 //modifiers &= ~1024;
....@@ -13603,25 +15121,25 @@
1360315121 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1360415122 // return;
1360515123 //System.out.println("SetMode = " + modifiers);
13606
- if ((modifiers & WHEEL) == WHEEL)
15124
+ if ((modifiersex & WHEEL) == WHEEL)
1360715125 {
1360815126 mouseMode |= ZOOM;
1360915127 }
1361015128
1361115129 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
13612
- if (capsLocked || (modifiers & META) == META)
15130
+ if (capsLocked) // || (modifiers & META) == META)
1361315131 {
1361415132 mouseMode |= VR; // BACKFORTH;
1361515133 }
13616
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15134
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1361715135 {
1361815136 mouseMode |= SELECT;
1361915137 }
13620
- if ((modifiers & COMMAND) == COMMAND)
15138
+ if ((modifiersex & COMMAND) == COMMAND)
1362115139 {
1362215140 mouseMode |= SELECT;
1362315141 }
13624
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15142
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1362515143 {
1362615144 mouseMode &= ~VR;
1362715145 mouseMode |= TRANSLATE;
....@@ -13650,10 +15168,10 @@
1365015168
1365115169 if (isRenderer) //
1365215170 {
13653
- SetMouseMode(modifiers);
15171
+ SetMouseMode(0, modifiers);
1365415172 }
1365515173
13656
- theRenderer.keyPressed(key);
15174
+ Globals.theRenderer.keyPressed(key);
1365715175 }
1365815176
1365915177 int kompactbit = 4; // power bit
....@@ -13665,7 +15183,7 @@
1366515183 float SATPOW = 1; // 2; // 0.5f;
1366615184 float BRIPOW = 1; // 0.5f; // 0.5f;
1366715185
13668
- void keyPressed(int key)
15186
+ public void keyPressed(int key)
1366915187 {
1367015188 if (key >= '0' && key <= '5')
1367115189 clampbit = (key-'0');
....@@ -13712,7 +15230,8 @@
1371215230 // break;
1371315231 case 'T':
1371415232 CACHETEXTURE ^= true;
13715
- textures.clear();
15233
+ texturepigment.clear();
15234
+ texturebump.clear();
1371615235 // repaint();
1371715236 break;
1371815237 case 'Y':
....@@ -13797,7 +15316,9 @@
1379715316 case 'E' : COMPACT ^= true;
1379815317 repaint();
1379915318 break;
13800
- case 'W' : DEBUGHSB ^= true;
15319
+ case 'W' : // Wide Window (fullscreen)
15320
+ //DEBUGHSB ^= true;
15321
+ ObjEditor.theFrame.ToggleFullScreen();
1380115322 repaint();
1380215323 break;
1380315324 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13822,8 +15343,8 @@
1382215343 RevertCamera();
1382315344 repaint();
1382415345 break;
13825
- case 'L':
1382615346 case 'l':
15347
+ //case 'L':
1382715348 if (lightMode)
1382815349 {
1382915350 lightMode = false;
....@@ -13887,20 +15408,24 @@
1388715408 OCCLUSION_CULLING ^= true;
1388815409 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1388915410 break;
13890
- case '0': envyoff ^= true; repaint(); break;
15411
+ //case '0': envyoff ^= true; repaint(); break;
1389115412 case '1':
1389215413 case '2':
1389315414 case '3':
1389415415 case '4':
1389515416 case '5':
13896
- newenvy = Character.getNumericValue(key);
13897
- repaint();
13898
- break;
1389915417 case '6':
1390015418 case '7':
1390115419 case '8':
1390215420 case '9':
13903
- BGcolor = (key - '6')/3.f;
15421
+ if (true) // envyoff)
15422
+ {
15423
+ BGcolor = (key - '1')/8.f;
15424
+ }
15425
+ else
15426
+ {
15427
+ //newenvy = Character.getNumericValue(key);
15428
+ }
1390415429 repaint();
1390515430 break;
1390615431 case '!':
....@@ -13966,9 +15491,9 @@
1396615491 case '_':
1396715492 kompactbit = 5;
1396815493 break;
13969
- case '+':
13970
- kompactbit = 6;
13971
- break;
15494
+// case '+':
15495
+// kompactbit = 6;
15496
+// break;
1397215497 case ' ':
1397315498 lightMode ^= true;
1397415499 Globals.lighttouched = true;
....@@ -13980,13 +15505,14 @@
1398015505 case ESC:
1398115506 RENDERPROGRAM += 1;
1398215507 RENDERPROGRAM %= 3;
15508
+
1398315509 repaint();
1398415510 break;
1398515511 case 'Z':
1398615512 //RESIZETEXTURE ^= true;
1398715513 //break;
1398815514 case 'z':
13989
- RENDERSHADOW ^= true;
15515
+ Globals.RENDERSHADOW ^= true;
1399015516 Globals.lighttouched = true;
1399115517 repaint();
1399215518 break;
....@@ -14019,8 +15545,9 @@
1401915545 case DELETE:
1402015546 ClearSelection();
1402115547 break;
14022
- /*
1402315548 case '+':
15549
+
15550
+ /*
1402415551 //fontsize += 1;
1402515552 bbzoom *= 2;
1402615553 repaint();
....@@ -14037,17 +15564,17 @@
1403715564 case '=':
1403815565 IncDepth();
1403915566 //fontsize += 1;
14040
- object.editWindow.refreshContents(true);
15567
+ object.GetWindow().refreshContents(true);
1404115568 maskbit = 6;
1404215569 break;
1404315570 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1404415571 DecDepth();
1404515572 maskbit = 5;
1404615573 //if(fontsize > 1) fontsize -= 1;
14047
- if (object.editWindow == null)
14048
- new Exception().printStackTrace();
14049
- else
14050
- object.editWindow.refreshContents(true);
15574
+// if (object.editWindow == null)
15575
+// new Exception().printStackTrace();
15576
+// else
15577
+ object.GetWindow().refreshContents(true);
1405115578 break;
1405215579 case '{':
1405315580 manipCamera.shaper_fovy /= 1.1;
....@@ -14102,6 +15629,7 @@
1410215629 }
1410315630 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1410415631 }
15632
+
1410515633 static double OCCLUSIONBOOST = 1; // 0.5;
1410615634
1410715635 void keyReleased(int key, int modifiers)
....@@ -14109,11 +15637,11 @@
1410915637 //mode = ROTATE;
1411015638 if ((MODIFIERS & COMMAND) == 0) // VR??
1411115639 {
14112
- SetMouseMode(modifiers);
15640
+ SetMouseMode(0, modifiers);
1411315641 }
1411415642 }
1411515643
14116
- protected void processKeyEvent(KeyEvent e)
15644
+ public void processKeyEvent(KeyEvent e)
1411715645 {
1411815646 switch (e.getID())
1411915647 {
....@@ -14243,8 +15771,9 @@
1424315771
1424415772 protected void processMouseMotionEvent(MouseEvent e)
1424515773 {
14246
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14247
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15774
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15775
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15776
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1424815777 {
1424915778 mouseMoved(e);
1425015779 } else
....@@ -14269,11 +15798,12 @@
1426915798 }
1427015799 */
1427115800
14272
- object.editWindow.EditSelection();
15801
+ object.GetWindow().EditSelection(false);
1427315802 }
1427415803
1427515804 void SelectParent()
1427615805 {
15806
+ new Exception().printStackTrace();
1427715807 System.exit(0);
1427815808 Composite group = (Composite) object;
1427915809 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14285,10 +15815,10 @@
1428515815 {
1428615816 //selectees.remove(i);
1428715817 System.out.println("select parent of " + elem);
14288
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15818
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1428915819 } else
1429015820 {
14291
- group.editWindow.Select(elem.GetTreePath(), first, true);
15821
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1429215822 }
1429315823
1429415824 first = false;
....@@ -14297,6 +15827,7 @@
1429715827
1429815828 void SelectChildren()
1429915829 {
15830
+ new Exception().printStackTrace();
1430015831 System.exit(0);
1430115832 /*
1430215833 Composite group = (Composite) object;
....@@ -14329,12 +15860,12 @@
1432915860 for (int j = 0; j < group.children.size(); j++)
1433015861 {
1433115862 elem = (Object3D) group.children.elementAt(j);
14332
- object.editWindow.Select(elem.GetTreePath(), first, true);
15863
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1433315864 first = false;
1433415865 }
1433515866 } else
1433615867 {
14337
- object.editWindow.Select(elem.GetTreePath(), first, true);
15868
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1433815869 }
1433915870
1434015871 first = false;
....@@ -14345,21 +15876,21 @@
1434515876 {
1434615877 //Composite group = (Composite) object;
1434715878 Object3D group = object;
14348
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15879
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1434915880 }
1435015881
1435115882 void ResetTransform(int mask)
1435215883 {
1435315884 //Composite group = (Composite) object;
1435415885 Object3D group = object;
14355
- group.editWindow.ResetTransform(mask);
15886
+ group.GetWindow().ResetTransform(mask);
1435615887 }
1435715888
1435815889 void FlipTransform()
1435915890 {
1436015891 //Composite group = (Composite) object;
1436115892 Object3D group = object;
14362
- group.editWindow.FlipTransform();
15893
+ group.GetWindow().FlipTransform();
1436315894 // group.editWindow.ReduceMesh(true);
1436415895 }
1436515896
....@@ -14367,7 +15898,7 @@
1436715898 {
1436815899 //Composite group = (Composite) object;
1436915900 Object3D group = object;
14370
- group.editWindow.PrintMemory();
15901
+ group.GetWindow().PrintMemory();
1437115902 // group.editWindow.ReduceMesh(true);
1437215903 }
1437315904
....@@ -14375,7 +15906,7 @@
1437515906 {
1437615907 //Composite group = (Composite) object;
1437715908 Object3D group = object;
14378
- group.editWindow.ResetCentroid();
15909
+ group.GetWindow().ResetCentroid();
1437915910 }
1438015911
1438115912 void IncDepth()
....@@ -14457,11 +15988,11 @@
1445715988
1445815989 int width = getBounds().width;
1445915990 int height = getBounds().height;
14460
- ClickInfo info = new ClickInfo();
14461
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1446215991 //Image img = CreateImage(width, height);
1446315992 //System.out.println("width = " + width + "; height = " + height + "\n");
15993
+
1446415994 Graphics gr = g; // img.getGraphics();
15995
+
1446515996 if (!hasMarquee)
1446615997 {
1446715998 if (Xmin < Xmax) // !locked)
....@@ -14533,40 +16064,88 @@
1453316064 }
1453416065 if (object != null && !hasMarquee)
1453516066 {
16067
+ if (object.clickInfo == null)
16068
+ object.clickInfo = new ClickInfo();
16069
+ ClickInfo info = object.clickInfo;
16070
+ //ClickInfo info = new ClickInfo();
16071
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16072
+
1453616073 if (isRenderer)
1453716074 {
14538
- info.flags++;
16075
+ object.clickInfo.flags++;
1453916076 double frameAspect = (double) width / (double) height;
1454016077 if (frameAspect > renderCamera.aspect)
1454116078 {
1454216079 int desired = (int) ((double) height * renderCamera.aspect);
14543
- info.bounds.width -= width - desired;
14544
- info.bounds.x += (width - desired) / 2;
16080
+ object.clickInfo.bounds.width -= width - desired;
16081
+ object.clickInfo.bounds.x += (width - desired) / 2;
1454516082 } else
1454616083 {
1454716084 int desired = (int) ((double) width / renderCamera.aspect);
14548
- info.bounds.height -= height - desired;
14549
- info.bounds.y += (height - desired) / 2;
16085
+ object.clickInfo.bounds.height -= height - desired;
16086
+ object.clickInfo.bounds.y += (height - desired) / 2;
1455016087 }
1455116088 }
14552
- info.g = gr;
14553
- info.camera = renderCamera;
16089
+
16090
+ object.clickInfo.g = gr;
16091
+ object.clickInfo.camera = renderCamera;
1455416092 /*
1455516093 // Memory intensive (brep.verticescopy)
1455616094 if (!(object instanceof Composite))
1455716095 object.draw(info, 0, false); // SLOW :
1455816096 */
14559
- if (!isRenderer)
16097
+ if (!isRenderer) // && drag)
1456016098 {
14561
- object.drawEditHandles(info, 0);
16099
+ Grafreed.Assert(object != null);
16100
+ Grafreed.Assert(object.selection != null);
16101
+ if (object.selection.Size() > 0)
16102
+ {
16103
+ int hitSomething = object.selection.get(0).hitSomething;
16104
+
16105
+ object.clickInfo.DX = 0;
16106
+ object.clickInfo.DY = 0;
16107
+ object.clickInfo.W = 1;
16108
+ if (hitSomething == Object3D.hitCenter)
16109
+ {
16110
+ info.DX = X;
16111
+ if (X != 0)
16112
+ info.DX -= info.bounds.width/2;
16113
+
16114
+ info.DY = Y;
16115
+ if (Y != 0)
16116
+ info.DY -= info.bounds.height/2;
16117
+ }
16118
+
16119
+ object.drawEditHandles(//info,
16120
+ 0);
16121
+
16122
+ if (drag && (X != 0 || Y != 0))
16123
+ {
16124
+ switch (hitSomething)
16125
+ {
16126
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16127
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16128
+ break;
16129
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16130
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16131
+ break;
16132
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16133
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16134
+ break;
16135
+ }
16136
+
16137
+ }
16138
+ }
1456216139 }
1456316140 }
16141
+
1456416142 if (isRenderer)
1456516143 {
1456616144 //gr.setColor(Color.black);
1456716145 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1456816146 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1456916147 }
16148
+
1457016149 if (hasMarquee)
1457116150 {
1457216151 gr.setXORMode(Color.white);
....@@ -14679,6 +16258,7 @@
1467916258 public boolean mouseDown(Event evt, int x, int y)
1468016259 {
1468116260 System.out.println("mouseDown: " + evt);
16261
+ System.exit(0);
1468216262 /*
1468316263 locked = true;
1468416264 drag = false;
....@@ -14722,7 +16302,7 @@
1472216302 {
1472316303 keyPressed(0, modifiers);
1472416304 }
14725
- clickStart(x, y, modifiers);
16305
+ // clickStart(x, y, modifiers);
1472616306 return true;
1472716307 }
1472816308
....@@ -14840,7 +16420,7 @@
1484016420 {
1484116421 keyReleased(0, 0);
1484216422 }
14843
- drag(x, y, modifiers);
16423
+ drag(x, y, 0, modifiers);
1484416424 return true;
1484516425 }
1484616426
....@@ -14972,7 +16552,7 @@
1497216552 Object3D object;
1497316553 static Object3D trackedobject;
1497416554 Camera renderCamera; // Light or Eye (or Occlusion)
14975
- /*static*/ Camera manipCamera; // Light or Eye
16555
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1497616556 /*static*/ Camera eyeCamera;
1497716557 /*static*/ Camera lightCamera;
1497816558 int cameracount;
....@@ -15036,6 +16616,8 @@
1503616616 private /*static*/ boolean firstime;
1503716617 private /*static*/ cVector newView = new cVector();
1503816618 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16619
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16620
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1503916621 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1504016622 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1504116623 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15048,29 +16630,67 @@
1504816630 {
1504916631 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1505016632
16633
+ int usedsuf = 0;
16634
+
1505116635 for (int i = 0; i < suffixes.length; i++)
1505216636 {
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)
16637
+ String[] suffixe = suffixes;
16638
+ String[] fallback = suffixes2;
16639
+ String[] fallfallback = suffixes3;
16640
+
16641
+ for (int c=usedsuf; --c>=0;)
1505816642 {
15059
- throw new IOException("Unable to load texture " + resourceName);
16643
+// String[] temp = suffixe;
16644
+// suffixe = fallback;
16645
+// fallback = fallfallback;
16646
+// fallfallback = temp;
1506016647 }
16648
+
16649
+ String resourceName = basename + suffixe[i] + "." + suffix;
16650
+ TextureData data;
16651
+
16652
+ try
16653
+ {
16654
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16655
+ mipmapped,
16656
+ FileUtil.getFileSuffix(resourceName));
16657
+ }
16658
+ catch (Exception e)
16659
+ {
16660
+ try
16661
+ {
16662
+ resourceName = basename + fallback[i] + "." + suffix;
16663
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16664
+ mipmapped,
16665
+ FileUtil.getFileSuffix(resourceName));
16666
+ }
16667
+ catch (Exception e2)
16668
+ {
16669
+ resourceName = basename + fallfallback[i] + "." + suffix;
16670
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16671
+ mipmapped,
16672
+ FileUtil.getFileSuffix(resourceName));
16673
+ }
16674
+ }
16675
+
1506116676 //System.out.println("Target = " + targets[i]);
1506216677 cubemap.updateImage(data, targets[i]);
1506316678 }
1506416679
1506516680 return cubemap;
1506616681 }
16682
+
1506716683 int bigsphere = -1;
1506816684
1506916685 float BGcolor = 0.5f;
1507016686
15071
- private void DrawSkyBox(GL gl)
16687
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16688
+
16689
+ private void DrawSkyBox(GL gl, float ratio)
1507216690 {
15073
- if (envyoff || cubemap == null)
16691
+ if (//envyoff ||
16692
+ WIREFRAME ||
16693
+ cubemap == null)
1507416694 {
1507516695 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1507616696 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15085,7 +16705,17 @@
1508516705 // Compensates for ExaminerViewer's modification of modelview matrix
1508616706 gl.glMatrixMode(GL.GL_MODELVIEW);
1508716707 gl.glLoadIdentity();
16708
+ gl.glScalef(1,ratio,1);
1508816709
16710
+// colorV[0] = 2;
16711
+// colorV[1] = 2;
16712
+// colorV[2] = 2;
16713
+// colorV[3] = 1;
16714
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16715
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16716
+//
16717
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16718
+
1508916719 //gl.glActiveTexture(GL.GL_TEXTURE1);
1509016720 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1509116721
....@@ -15117,6 +16747,7 @@
1511716747 {
1511816748 gl.glScalef(1.0f, -1.0f, 1.0f);
1511916749 }
16750
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1512016751 gl.glMultMatrixd(viewrot_1, 0);
1512116752 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1512216753 //viewer.updateInverseRotation(gl);
....@@ -15257,16 +16888,16 @@
1525716888 cStatic.objectstack[materialdepth++] = checker;
1525816889 //System.out.println("material " + material);
1525916890 //Applet3D.tracein(this, selected);
15260
- vector2buffer = checker.projectedVertices;
16891
+ //vector2buffer = checker.projectedVertices;
1526116892
1526216893 //checker.GetMaterial().Draw(this, false); // true);
15263
- DrawMaterial(checker.GetMaterial(), false); // true);
16894
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1526416895
1526516896 materialdepth -= 1;
1526616897 if (materialdepth > 0)
1526716898 {
15268
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15269
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16899
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16900
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1527016901 }
1527116902 //checker.GetMaterial().opacity = 1f;
1527216903 ////checker.GetMaterial().ambient = 1f;
....@@ -15352,6 +16983,14 @@
1535216983 }
1535316984 }
1535416985
16986
+ private Object3D GetFolder()
16987
+ {
16988
+ Object3D folder = object.GetWindow().copy;
16989
+ if (object.GetWindow().copy.selection.Size() > 0)
16990
+ folder = object.GetWindow().copy.selection.elementAt(0);
16991
+ return folder;
16992
+ }
16993
+
1535516994 class SelectBuffer implements GLEventListener
1535616995 {
1535716996
....@@ -15367,7 +17006,7 @@
1536717006 //new Exception().printStackTrace();
1536817007 System.out.println("select buffer init");
1536917008 // Use debug pipeline
15370
- drawable.setGL(new DebugGL(drawable.getGL()));
17009
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1537117010
1537217011 GL gl = drawable.getGL();
1537317012
....@@ -15410,6 +17049,7 @@
1541017049 {
1541117050 if (!selection)
1541217051 {
17052
+ new Exception().printStackTrace();
1541317053 System.exit(0);
1541417054 return;
1541517055 }
....@@ -15430,6 +17070,17 @@
1543017070
1543117071 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1543217072
17073
+ if (PAINTMODE)
17074
+ {
17075
+ if (object.GetWindow().copy.selection.Size() > 0)
17076
+ {
17077
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17078
+
17079
+ // Make what you paint not selectable.
17080
+ paintobj.ResetSelectable();
17081
+ }
17082
+ }
17083
+
1543317084 //int tmp = selection_view;
1543417085 //selection_view = -1;
1543517086 int temp = DrawMode();
....@@ -15441,6 +17092,17 @@
1544117092 // temp = DEFAULT; // patch for selection debug
1544217093 Globals.drawMode = temp; // WARNING
1544317094
17095
+ if (PAINTMODE)
17096
+ {
17097
+ if (object.GetWindow().copy.selection.Size() > 0)
17098
+ {
17099
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17100
+
17101
+ // Revert.
17102
+ paintobj.RestoreSelectable();
17103
+ }
17104
+ }
17105
+
1544417106 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1544517107
1544617108 // trying different ways of getting the depth info over
....@@ -15488,6 +17150,8 @@
1548817150 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1548917151 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1549017152 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17153
+
17154
+ CreateSelectedPoint();
1549117155
1549217156 // Will fit the mesh !!!
1549317157 selectedpoint.toParent[0][0] = 0.0001;
....@@ -15537,34 +17201,36 @@
1553717201 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]));
1553817202 }
1553917203
15540
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17204
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1554117205 }
1554217206 }
1554317207
1554417208 if (!movingcamera && !PAINTMODE)
15545
- object.editWindow.ScreenFitPoint(); // fev 2014
17209
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1554617210
15547
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17211
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1554817212 {
15549
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17213
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1555017214
15551
- Object3D group = new Object3D("inst" + paintcount++);
17215
+ if (object.GetWindow().copy.selection.Size() > 0)
17216
+ {
17217
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1555217218
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();
17219
+ Object3D inst = new Object3D("inst" + paintcount++);
17220
+
17221
+ inst.CreateMaterial(); // use a void leaf to select instances
17222
+
17223
+ inst.add(paintobj); // link
17224
+
17225
+ object.GetWindow().SnapObject(inst);
17226
+
17227
+ Object3D folder = paintFolder; // GetFolder();
17228
+
17229
+ folder.add(inst);
17230
+
17231
+ object.GetWindow().ResetModel();
17232
+ object.GetWindow().refreshContents();
17233
+ }
1556817234 }
1556917235 else
1557017236 paintcount = 0;
....@@ -15603,6 +17269,11 @@
1560317269 //System.out.println("objects[color] = " + objects[color]);
1560417270 //objects[color].Select();
1560517271 indexcount = 0;
17272
+ ObjEditor window = object.GetWindow();
17273
+ if (window != null && deselect)
17274
+ {
17275
+ window.Select(null, deselect, true);
17276
+ }
1560617277 object.Select(color, deselect);
1560717278 }
1560817279
....@@ -15702,7 +17373,7 @@
1570217373 gl.glDisable(gl.GL_CULL_FACE);
1570317374 }
1570417375
15705
- if (!RENDERSHADOW)
17376
+ if (!Globals.RENDERSHADOW)
1570617377 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1570717378
1570817379 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -15712,7 +17383,7 @@
1571217383 //gl.glColorMask(false, false, false, false);
1571317384
1571417385 //render_scene_from_light_view(gl, drawable, 0, 0);
15715
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17386
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1571617387 {
1571717388 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1571817389
....@@ -15772,7 +17443,6 @@
1577217443
1577317444 class AntialiasBuffer implements GLEventListener
1577417445 {
15775
-
1577617446 CameraPane parent = null;
1577717447
1577817448 AntialiasBuffer(CameraPane p)
....@@ -15882,10 +17552,14 @@
1588217552 gl.glFlush();
1588317553
1588417554 /**/
15885
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17555
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1588617556
15887
- float[] pixels = occlusionsizebuffer.array();
17557
+ float[] depths = occlusiondepthbuffer.array();
1588817558
17559
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17560
+
17561
+ int[] pixels = selectsizebuffer.array();
17562
+
1588917563 double r = 0, g = 0, b = 0;
1589017564
1589117565 double count = 0;
....@@ -15896,7 +17570,7 @@
1589617570
1589717571 double FACTOR = 1;
1589817572
15899
- for (int i = 0; i < pixels.length; i++)
17573
+ for (int i = 0; i < depths.length; i++)
1590017574 {
1590117575 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1590217576 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15979,7 +17653,7 @@
1597917653
1598017654 double scale = ray.z; // 1; // cos
1598117655
15982
- float depth = pixels[newindex];
17656
+ float depth = depths[newindex];
1598317657
1598417658 /*
1598517659 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16129,23 +17803,15 @@
1612917803 int AAbuffersize = 0;
1613017804
1613117805 //double[] selectedpoint = new double[3];
16132
- static Superellipsoid selectedpoint = new Superellipsoid();
17806
+ static Superellipsoid selectedpoint;
1613317807 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();
17808
+ static Sphere debugpointG;
17809
+ static Sphere debugpointP;
17810
+ static Sphere debugpointC;
17811
+ static Sphere debugpointR;
1613817812
1613917813 static Sphere debugpoints[] = new Sphere[8];
1614017814
16141
- static
16142
- {
16143
- for (int i=0; i<8; i++)
16144
- {
16145
- debugpoints[i] = new Sphere();
16146
- }
16147
- }
16148
-
1614917815 static void InitPoints(float radius)
1615017816 {
1615117817 for (int i=0; i<8; i++)
....@@ -16165,7 +17831,7 @@
1616517831 }
1616617832 }
1616717833
16168
- static void DrawPoints(CameraPane cpane)
17834
+ static void DrawPoints(iCameraPane cpane)
1616917835 {
1617017836 for (int i=0; i<8; i++) // first and last are red
1617117837 {
....@@ -16184,11 +17850,14 @@
1618417850 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1618517851 static IntBuffer bigAAbuffer;
1618617852 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
16187
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17853
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1618817854 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1618917855 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1619017856 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
16191
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17857
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17858
+
17859
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17860
+
1619217861 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1619317862 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1619417863 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -16197,10 +17866,11 @@
1619717866 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1619817867 // Depth buffer format
1619917868 //private int depth_format;
16200
- static public void NextIndex(Object3D o, GL gl)
17869
+
17870
+ public void NextIndex()
1620117871 {
1620217872 indexcount+=16;
16203
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17873
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1620417874 //objects[indexcount] = o;
1620517875 //System.out.println("indexcount = " + indexcount);
1620617876 }