Normand Briere
2019-08-21 7ac1b01c591ed65743676b1181d60eb17c5cb69d
CameraPane.java
....@@ -18,7 +18,10 @@
1818 import javax.imageio.ImageIO;
1919 import javax.imageio.ImageWriteParam;
2020 import javax.imageio.ImageWriter;
21
+import javax.imageio.ImageReadParam;
22
+import javax.imageio.ImageReader;
2123 import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
24
+import javax.imageio.stream.ImageInputStream;
2225 import javax.imageio.stream.ImageOutputStream;
2326 import javax.imageio.ImageWriteParam;
2427
....@@ -30,6 +33,7 @@
3033 import java.nio.*;
3134
3235 import gleem.linalg.Mat4f;
36
+import javax.imageio.ImageTypeSpecifier;
3337
3438 class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
3539 {
....@@ -37,7 +41,6 @@
3741 static boolean[] selectedstack = new boolean[65536];
3842 static int materialdepth = 0;
3943
40
- static boolean DEBUG = false;
4144 static boolean FRUSTUM = false; // still bogus true; // frustum culling
4245
4346 // camera change fix
....@@ -45,6 +48,39 @@
4548 static boolean ABORTED = false;
4649
4750 static int STEP = 1;
51
+
52
+ private static BufferedImage CreateBim(byte[] bytes, int width, int height)
53
+ {
54
+ int[] pixels = new int[bytes.length/3];
55
+ for (int i=pixels.length; --i>=0;)
56
+ {
57
+ int i3 = i*3;
58
+ pixels[i] = 0xFF;
59
+ pixels[i] <<= 8;
60
+ pixels[i] |= bytes[i3+2] & 0xFF;
61
+ pixels[i] <<= 8;
62
+ pixels[i] |= bytes[i3+1] & 0xFF;
63
+ pixels[i] <<= 8;
64
+ pixels[i] |= bytes[i3] & 0xFF;
65
+ }
66
+ /*
67
+ int r=0,g=0,b=0,a=0;
68
+ for (int i=0; i<width; i++)
69
+ for (int j=0; j<height; j++)
70
+ {
71
+ int index = j*width+i;
72
+ int p = pixels[index];
73
+ a = ((p>>24) & 0xFF);
74
+ r = ((p>>16) & 0xFF);
75
+ g = ((p>>8) & 0xFF);
76
+ b = (p & 0xFF);
77
+ pixels[index] = (a<<24) | (b<<16) | (g<<8) | r;
78
+ }
79
+ /**/
80
+ BufferedImage rendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); // ImageIO.read(infile);
81
+ rendImage.setRGB(0,0,width,height,pixels,width*(height-1),-width);
82
+ return rendImage;
83
+ }
4884
4985 /*static*/ private boolean CULLFACE = false; // true;
5086 /*static*/ boolean NEAREST = false; // true;
....@@ -56,14 +92,12 @@
5692 static int CURRENTANTIALIAS = 0; // 1;
5793 /*static*/ boolean RENDERSHADOW = true;
5894 /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
59
- static boolean ANIMATION = false;
60
- static String filename;
6195
6296 boolean DISPLAYTEXT = false;
6397 //boolean REDUCETEXTURE = true;
6498 boolean CACHETEXTURE = true;
6599 boolean CLEANCACHE = false; // true;
66
- boolean MIPMAP = false; // true;
100
+ boolean MIPMAP = false; // true; // never works...
67101 boolean COMPRESSTEXTURE = false;
68102 boolean KOMPACTTEXTURE = false; // true;
69103 boolean RESIZETEXTURE = false;
....@@ -76,7 +110,11 @@
76110 //private Mat4f spotlightTransform = new Mat4f();
77111 //private Mat4f spotlightInverseTransform = new Mat4f();
78112 static GLContext glcontext = null;
79
- /*static*/ com.sun.opengl.util.texture.Texture cubemap;
113
+ /*static*/ com.sun.opengl.util.texture.Texture cubemap; // Either custom or rgb
114
+ /*static*/ com.sun.opengl.util.texture.Texture cubemapcustom;
115
+ /*static*/ com.sun.opengl.util.texture.Texture cubemaprgb;
116
+ boolean transformMode;
117
+
80118 boolean reverseUP = false;
81119 static boolean frozen = false;
82120 boolean enablebackspace = false; // patch for back buffer refresh
....@@ -92,6 +130,8 @@
92130
93131 static int tickcount = 0; // slow pose issue
94132
133
+static boolean BUTTONLESSWHEEL = false;
134
+static boolean ZOOMBOXMODE = false;
95135 static boolean BOXMODE = false;
96136 static boolean IMAGEFLIP = false;
97137 static boolean SMOOTHFOCUS = false;
....@@ -106,7 +146,7 @@
106146 static boolean OEIL = true;
107147 static boolean OEILONCE = false; // do oeilon then oeiloff
108148 static boolean LOOKAT = true;
109
-static boolean RANDOM = true; // false;
149
+static boolean SWITCH = true; // false;
110150 static boolean HANDLES = false; // selection doesn't work!!
111151 static boolean PAINTMODE = false;
112152
....@@ -128,7 +168,7 @@
128168
129169
130170 // OPTIONS
131
- boolean Skinshader = true;
171
+ boolean Skinshader = false; // true;
132172 boolean cameraLight = false;
133173 boolean UVdebug = false;
134174 boolean Udebug = false;
....@@ -137,7 +177,7 @@
137177 static boolean doublesided = false; // true; // reversed normals are awful for conformance
138178 boolean anisotropy = true;
139179 boolean softshadow = true; // slower but better false;
140
- boolean opacityhalo = false;
180
+ boolean opacityhalo = false; // reverse the halo effect (e.g. glass)
141181
142182 boolean macromode = false;
143183
....@@ -149,12 +189,26 @@
149189 defaultcaps.setAccumBlueBits(16);
150190 defaultcaps.setAccumAlphaBits(16);
151191 }
152
- static CameraPane theRenderer;
192
+
193
+ private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
153194
195
+ public com.sun.opengl.util.texture.Texture LoadSkybox(String name, String ext, boolean mipmap) throws GLException
196
+ {
197
+ try
198
+ {
199
+ return LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
200
+ } catch (IOException e)
201
+ {
202
+ System.out.println("NAME = " + name);
203
+ e.printStackTrace(); // throw new RuntimeException(e);
204
+ return null;
205
+ }
206
+ }
207
+
154208 void SetAsGLRenderer(boolean b)
155209 {
156210 isRenderer = b;
157
- theRenderer = this;
211
+ Globals.theRenderer = this;
158212 }
159213
160214 CameraPane(Object3D o, Camera cam, boolean withcontext)
....@@ -169,7 +223,8 @@
169223
170224 SetCamera(cam);
171225
172
- SetLight(new Camera(new cVector(10, 10, -20)));
226
+ // Warning: not used.
227
+ SetLight(new Camera(new cVector(15, 10, -20)));
173228
174229 object = o;
175230
....@@ -191,6 +246,45 @@
191246 }
192247
193248 /// INTERFACE
249
+
250
+ public javax.media.opengl.GL GetGL0()
251
+ {
252
+ return null;
253
+ }
254
+
255
+ public int GenList()
256
+ {
257
+ javax.media.opengl.GL gl = GetGL();
258
+ return gl.glGenLists(1);
259
+ }
260
+
261
+ public void NewList(int id)
262
+ {
263
+ javax.media.opengl.GL gl = GetGL();
264
+ gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
265
+ }
266
+
267
+ public void CallList(int id)
268
+ {
269
+ javax.media.opengl.GL gl = GetGL();
270
+ gl.glCallList(id);
271
+ }
272
+
273
+ public void EndList()
274
+ {
275
+ javax.media.opengl.GL gl = GetGL();
276
+ gl.glEndList();
277
+ }
278
+
279
+ public boolean IsBoxMode()
280
+ {
281
+ return BOXMODE;
282
+ }
283
+
284
+ public boolean IsZoomBoxMode()
285
+ {
286
+ return ZOOMBOXMODE;
287
+ }
194288
195289 public void ClearDepth()
196290 {
....@@ -231,9 +325,14 @@
231325 return this.ambientOcclusion;
232326 }
233327
328
+ public boolean IsDebugSelection()
329
+ {
330
+ return DEBUG_SELECTION;
331
+ }
332
+
234333 public boolean IsFrozen()
235334 {
236
- boolean selectmode = this.DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
335
+ boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
237336
238337 return !selectmode && cameracount == 0; // != 0;
239338 }
....@@ -254,9 +353,19 @@
254353 return lightCamera;
255354 }
256355
356
+ public Camera ManipCamera()
357
+ {
358
+ return manipCamera;
359
+ }
360
+
257361 public Camera RenderCamera()
258362 {
259363 return renderCamera;
364
+ }
365
+
366
+ public Camera[] Cameras()
367
+ {
368
+ return cameras;
260369 }
261370
262371 public void PushMaterial(Object3D obj, boolean selected)
....@@ -272,7 +381,7 @@
272381 cStatic.objectstack[materialdepth++] = obj;
273382 //System.out.println("material " + material);
274383 //Applet3D.tracein(this, selected);
275
- display.vector2buffer = obj.projectedVertices;
384
+ //display.vector2buffer = obj.projectedVertices;
276385 if (obj instanceof Camera)
277386 {
278387 display.options1[0] = material.shift;
....@@ -281,14 +390,28 @@
281390 display.options1[2] = material.shadowbias;
282391 display.options1[3] = material.aniso;
283392 display.options1[4] = material.anisoV;
393
+// System.out.println("display.options1[0] " + display.options1[0]);
394
+// System.out.println("display.options1[1] " + display.options1[1]);
395
+// System.out.println("display.options1[2] " + display.options1[2]);
396
+// System.out.println("display.options1[3] " + display.options1[3]);
397
+// System.out.println("display.options1[4] " + display.options1[4]);
284398 display.options2[0] = material.opacity;
285399 display.options2[1] = material.diffuse;
286400 display.options2[2] = material.factor;
401
+// System.out.println("display.options2[0] " + display.options2[0]);
402
+// System.out.println("display.options2[1] " + display.options2[1]);
403
+// System.out.println("display.options2[2] " + display.options2[2]);
287404
288405 cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
406
+// System.out.println("display.options3[0] " + display.options3[0]);
407
+// System.out.println("display.options3[1] " + display.options3[1]);
408
+// System.out.println("display.options3[2] " + display.options3[2]);
289409 display.options4[0] = material.cameralight/0.2f;
290410 display.options4[1] = material.subsurface;
291411 display.options4[2] = material.sheen;
412
+// System.out.println("display.options4[0] " + display.options4[0]);
413
+// System.out.println("display.options4[1] " + display.options4[1]);
414
+// System.out.println("display.options4[2] " + display.options4[2]);
292415
293416 // if (display.CURRENTANTIALIAS > 0)
294417 // display.options3[3] /= 4;
....@@ -304,7 +427,7 @@
304427 /**/
305428 } else
306429 {
307
- DrawMaterial(material, selected);
430
+ DrawMaterial(material, selected, obj.projectedVertices);
308431 }
309432 } else
310433 {
....@@ -328,8 +451,8 @@
328451 cStatic.objectstack[materialdepth++] = obj;
329452 //System.out.println("material " + material);
330453 //Applet3D.tracein("selected ", selected);
331
- display.vector2buffer = obj.projectedVertices;
332
- display.DrawMaterial(material, selected);
454
+ //display.vector2buffer = obj.projectedVertices;
455
+ display.DrawMaterial(material, selected, obj.projectedVertices);
333456 }
334457 }
335458
....@@ -346,8 +469,8 @@
346469 materialdepth -= 1;
347470 if (materialdepth > 0)
348471 {
349
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
350
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
472
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
473
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
351474 }
352475 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
353476 } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
....@@ -367,8 +490,8 @@
367490 materialdepth -= 1;
368491 if (materialdepth > 0)
369492 {
370
- display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
371
- display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
493
+ //display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
494
+ display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
372495 }
373496 //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
374497 //else
....@@ -403,21 +526,24 @@
403526
404527 javax.media.opengl.GL gl = display.GetGL();
405528
406
- boolean selectmode = display.DrawMode() == display.SELECTION || CameraPane.DEBUG_SELECTION;
529
+ boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
407530
408531 //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
409532 if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
410533 {
411534 //gl.glBegin(gl.GL_TRIANGLES);
412
- boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
535
+ boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0)
536
+ // TEST LIVE NORMALS && !obj.dontselect
537
+ ;
413538 if (!hasnorm)
414539 {
415
- // System.out.println("FUCK!!");
540
+ // System.out.println("Mesh normal");
416541 LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
417542 LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
418543 LA.vecCross(obj.v0, obj.v1, obj.v2);
419544 LA.vecNormalize(obj.v2);
420
- gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
545
+
546
+ SetGLNormal(gl, (float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
421547 }
422548
423549 // P
....@@ -439,7 +565,7 @@
439565 y += ny * obj.NORMALPUSH;
440566 z += nz * obj.NORMALPUSH;
441567
442
- gl.glNormal3f(nx, ny, nz);
568
+ SetGLNormal(gl, nx, ny, nz);
443569 }
444570 gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
445571 SetColor(obj, pv);
....@@ -471,7 +597,7 @@
471597 y += ny * obj.NORMALPUSH;
472598 z += nz * obj.NORMALPUSH;
473599
474
- gl.glNormal3f(nx, ny, nz);
600
+ SetGLNormal(gl, nx, ny, nz);
475601 }
476602 //System.out.println("vertexq = " + qv.s + ", " + qv.t);
477603 // boolean locked = false;
....@@ -519,7 +645,7 @@
519645 y += ny * obj.NORMALPUSH;
520646 z += nz * obj.NORMALPUSH;
521647
522
- gl.glNormal3f(nx, ny, nz);
648
+ SetGLNormal(gl, nx, ny, nz);
523649 }
524650
525651 // if ((dot&4) == 0)
....@@ -566,8 +692,819 @@
566692 }
567693 }
568694
695
+ /**
696
+ * <code>draw</code> renders a <code>TriMesh</code> object including
697
+ * it's normals, colors, textures and vertices.
698
+ *
699
+ * @see Renderer#draw(TriMesh)
700
+ * @param tris
701
+ * the mesh to render.
702
+ */
703
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
704
+ {
705
+ CameraPane display = this;
706
+
707
+ float r = display.modelParams0[0];
708
+ float g = display.modelParams0[1];
709
+ float b = display.modelParams0[2];
710
+ float opacity = display.modelParams5[1];
711
+
712
+ //final GL gl = GLU.getCurrentGL();
713
+ GL gl = display.GetGL(); // getGL();
714
+
715
+ FloatBuffer vertBuf = geo.vertBuf;
716
+
717
+ int v = vertBuf.capacity();
718
+
719
+ int count = 0;
720
+
721
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
722
+ gl.glEnable(gl.GL_CULL_FACE);
723
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
724
+ for (int i=0; i<v/3; i++)
725
+ {
726
+ int index3 = i*3;
727
+
728
+ if (geo.sizeBuf.get(index3+1) == 0)
729
+ continue;
730
+
731
+ count++;
732
+
733
+ int index4 = i*4;
734
+
735
+ float tx = vertBuf.get(index3);
736
+ float ty = vertBuf.get(index3+1);
737
+ float tz = vertBuf.get(index3+2);
738
+
739
+ // if (tx == 0 && ty == 0 && tz == 0)
740
+ // continue;
741
+
742
+ gl.glMatrixMode(gl.GL_TEXTURE);
743
+ gl.glPushMatrix();
744
+
745
+ float[] texmat = geo.texmat;
746
+ texmat[12] = texmat[13] = texmat[14] = i;
747
+
748
+ gl.glMultMatrixf(texmat, 0);
749
+
750
+ gl.glMatrixMode(gl.GL_MODELVIEW);
751
+ gl.glPushMatrix();
752
+
753
+ gl.glTranslatef(tx,ty,tz);
754
+
755
+ if (rotate)
756
+ gl.glRotatef(i, 0, 1, 0);
757
+
758
+ float size = geo.sizeBuf.get(index3) / 100;
759
+ gl.glScalef(size,size,size);
760
+
761
+ float cr = geo.colorBuf.get(index4);
762
+ float cg = geo.colorBuf.get(index4+1);
763
+ float cb = geo.colorBuf.get(index4+2);
764
+ float ca = geo.colorBuf.get(index4+3);
765
+
766
+ display.modelParams0[0] = r * cr;
767
+ display.modelParams0[1] = g * cg;
768
+ display.modelParams0[2] = b * cb;
769
+
770
+ display.modelParams5[1] = opacity * ca;
771
+
772
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
773
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
774
+
775
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
776
+ RandomNode.globalseed2 = RandomNode.globalseed;
777
+
778
+// gl.glColor4f(cr,cg,cb,ca);
779
+ // gl.glScalef(1024/16,1024/16,1024/16);
780
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
781
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
782
+ //gl.glTranslatef(-tx,-ty,-tz);
783
+ gl.glPopMatrix();
784
+
785
+ gl.glMatrixMode(gl.GL_TEXTURE);
786
+ gl.glPopMatrix();
787
+ }
788
+ // gl.glScalef(1024,1024,1024);
789
+ if (!cf)
790
+ gl.glDisable(gl.GL_CULL_FACE);
791
+
792
+ display.modelParams0[0] = r;
793
+ display.modelParams0[1] = g;
794
+ display.modelParams0[2] = b;
795
+
796
+ display.modelParams5[1] = opacity;
797
+
798
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
799
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
800
+
801
+ gl.glMatrixMode(gl.GL_MODELVIEW);
802
+
803
+// System.err.println("total = " + v/3 + "; displayed = " + count);
804
+ if (true)
805
+ return;
806
+
807
+//// if (!tris.predraw(this))
808
+//// {
809
+//// return;
810
+//// }
811
+//// if (Debug.stats)
812
+//// {
813
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
814
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
815
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
816
+//// }
817
+////
818
+//// if (tris.getDisplayListID() != -1)
819
+//// {
820
+//// renderDisplayList(tris);
821
+//// return;
822
+//// }
823
+////
824
+//// if (!generatingDisplayList)
825
+//// {
826
+//// applyStates(tris.states, tris);
827
+//// }
828
+//// if (Debug.stats)
829
+//// {
830
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
831
+//// }
832
+//// boolean transformed = doTransforms(tris);
833
+//
834
+// int glMode = GL.GL_TRIANGLES;
835
+// switch (getMode())
836
+// {
837
+// case Triangles:
838
+// glMode = GL.GL_TRIANGLES;
839
+// break;
840
+// case Strip:
841
+// glMode = GL.GL_TRIANGLE_STRIP;
842
+// break;
843
+// case Fan:
844
+// glMode = GL.GL_TRIANGLE_FAN;
845
+// break;
846
+// }
847
+//
848
+// if (!predrawGeometry(gl))
849
+// {
850
+// // make sure only the necessary indices are sent through on old
851
+// // cards.
852
+// IntBuffer indices = this.getIndexBuffer();
853
+// if (indices == null)
854
+// {
855
+// logger.severe("missing indices on geometry object: " + this.toString());
856
+// } else
857
+// {
858
+// indices.rewind();
859
+// indices.limit(this.getMaxIndex());
860
+//
861
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
862
+//
863
+// indices.clear();
864
+// }
865
+// } else
866
+// {
867
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
868
+// GL.GL_UNSIGNED_INT, 0);
869
+// }
870
+//
871
+//// postdrawGeometry(tris);
872
+//// if (transformed)
873
+//// {
874
+//// undoTransforms(tris);
875
+//// }
876
+////
877
+//// if (Debug.stats)
878
+//// {
879
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
880
+//// }
881
+//// tris.postdraw(this);
882
+ }
883
+
884
+ static Camera localcamera = new Camera();
885
+ static cVector from = new cVector();
886
+ static cVector to = new cVector();
887
+
888
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
889
+ {
890
+ CameraPane cp = this;
891
+
892
+ Camera keep = cp.RenderCamera();
893
+ cp.renderCamera = localcamera;
894
+
895
+ if (br.trimmed)
896
+ {
897
+ float[] colors = new float[br.positions.length / 3];
898
+
899
+ int i3 = 0;
900
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
901
+ {
902
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
903
+ continue;
904
+
905
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
906
+ to.set(br.positions[i3] + br.normals[i3],
907
+ br.positions[i3 + 1] + br.normals[i3 + 1],
908
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
909
+ LA.xformPos(from, transform, from);
910
+ LA.xformPos(to, transform, to); // RIGID ONLY
911
+ localcamera.setAim(from, to);
912
+
913
+ CameraPane.occlusionbuffer.display();
914
+
915
+ if (CameraPane.DEBUG_OCCLUSION)
916
+ cp.display(); // debug
917
+
918
+ colors[i] = cp.vertexOcclusion.r;
919
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
920
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
921
+
922
+ if ((i % 100) == 0 && i != 0)
923
+ {
924
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
925
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
926
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
927
+ }
928
+ }
929
+
930
+ br.colors = colors;
931
+ }
932
+ else
933
+ {
934
+ for (int i = 0; i < br.VertexCount(); i++)
935
+ {
936
+ Vertex v = br.GetVertex(i);
937
+
938
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
939
+ continue;
940
+
941
+ from.set(v.x, v.y, v.z);
942
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
943
+ LA.xformPos(from, transform, from);
944
+ LA.xformPos(to, transform, to); // RIGID ONLY
945
+ localcamera.setAim(from, to);
946
+
947
+ CameraPane.occlusionbuffer.display();
948
+
949
+ if (CameraPane.DEBUG_OCCLUSION)
950
+ cp.display(); // debug
951
+
952
+ v.AO = cp.vertexOcclusion.r;
953
+
954
+ if ((i % 100) == 0 && i != 0)
955
+ {
956
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
957
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
958
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
959
+ }
960
+ }
961
+ }
962
+
963
+ //System.out.println("done.");
964
+
965
+ cp.renderCamera = keep;
966
+ }
967
+
968
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
969
+ {
970
+ CameraPane display = this;
971
+ pointFlow.CreateHT();
972
+
973
+ float r = display.modelParams0[0];
974
+ float g = display.modelParams0[1];
975
+ float b = display.modelParams0[2];
976
+ float opacity = display.modelParams5[1];
977
+
978
+ //final GL gl = GLU.getCurrentGL();
979
+ GL gl = display.GetGL(); // getGL();
980
+
981
+ int s = pointFlow.points.size();
982
+
983
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
984
+ gl.glEnable(gl.GL_CULL_FACE);
985
+
986
+ for (int i=s; --i>=0;)
987
+ //for (int i=0; i<s; i++)
988
+ {
989
+ cVector v = pointFlow.points.get(i);
990
+
991
+ double mindist = Double.MAX_VALUE;
992
+
993
+ double size = pointFlow.minimumSize;
994
+
995
+ double distancenext = 0;
996
+
997
+ if (i > 0)
998
+ {
999
+ cVector w = pointFlow.points.get(i-1);
1000
+
1001
+ double dist = w.distance(v);
1002
+
1003
+ distancenext = dist;
1004
+
1005
+ if (mindist > dist)
1006
+ {
1007
+ mindist = dist;
1008
+ size = mindist*pointFlow.resizefactor;
1009
+ }
1010
+ }
1011
+
1012
+ if (i < s-1)
1013
+ {
1014
+ cVector w = pointFlow.points.get(i+1);
1015
+
1016
+ double dist = w.distance(v);
1017
+
1018
+ if (mindist > dist)
1019
+ {
1020
+ mindist = dist;
1021
+ size = mindist*pointFlow.resizefactor;
1022
+ }
1023
+ }
1024
+
1025
+ if (size < pointFlow.minimumSize)
1026
+ size = pointFlow.minimumSize;
1027
+ if (size > pointFlow.maximumSize)
1028
+ size = pointFlow.maximumSize;
1029
+
1030
+ double tx = v.x;
1031
+ double ty = v.y;
1032
+ double tz = v.z;
1033
+
1034
+ // if (tx == 0 && ty == 0 && tz == 0)
1035
+ // continue;
1036
+
1037
+ gl.glMatrixMode(gl.GL_TEXTURE);
1038
+ gl.glPushMatrix();
1039
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1040
+
1041
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1042
+
1043
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1044
+ gl.glPushMatrix();
1045
+
1046
+ gl.glTranslated(tx,ty,tz);
1047
+
1048
+ gl.glScaled(size,size,size);
1049
+
1050
+// float cr = colorBuf.get(index4);
1051
+// float cg = colorBuf.get(index4+1);
1052
+// float cb = colorBuf.get(index4+2);
1053
+// float ca = colorBuf.get(index4+3);
1054
+//
1055
+// display.modelParams0[0] = r * cr;
1056
+// display.modelParams0[1] = g * cg;
1057
+// display.modelParams0[2] = b * cb;
1058
+//
1059
+// display.modelParams5[1] = opacity * ca;
1060
+//
1061
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1062
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1063
+//
1064
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1065
+// RandomNode.globalseed2 = RandomNode.globalseed;
1066
+//
1067
+//// gl.glColor4f(cr,cg,cb,ca);
1068
+// // gl.glScalef(1024/16,1024/16,1024/16);
1069
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1070
+
1071
+ gl.glPopMatrix();
1072
+
1073
+ double step = size/4; //
1074
+
1075
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1076
+ continue;
1077
+
1078
+ int nbsteps = (int)(distancenext/step);
1079
+
1080
+ step = distancenext/nbsteps;
1081
+
1082
+ cVector next = pointFlow.points.get(i-1);
1083
+
1084
+ tmp.set(next);
1085
+ tmp.sub(v);
1086
+ tmp.normalize();
1087
+ tmp.mul(step);
1088
+
1089
+ // calculate next size
1090
+ mindist = Double.MAX_VALUE;
1091
+
1092
+ double nextsize = pointFlow.minimumSize;
1093
+
1094
+ if (i > 1)
1095
+ {
1096
+ cVector w = pointFlow.points.get(i-2);
1097
+
1098
+ double dist = w.distance(next);
1099
+
1100
+ if (mindist > dist)
1101
+ {
1102
+ mindist = dist;
1103
+ nextsize = mindist*pointFlow.resizefactor;
1104
+ }
1105
+ }
1106
+
1107
+ double dist = v.distance(next);
1108
+
1109
+ if (mindist > dist)
1110
+ {
1111
+ mindist = dist;
1112
+ nextsize = mindist*pointFlow.resizefactor;
1113
+ }
1114
+
1115
+ if (nextsize < pointFlow.minimumSize)
1116
+ nextsize = pointFlow.minimumSize;
1117
+ if (nextsize > pointFlow.maximumSize)
1118
+ nextsize = pointFlow.maximumSize;
1119
+ //
1120
+
1121
+ double count = 0;
1122
+
1123
+ while (distancenext > 0.000000001) // step
1124
+ {
1125
+ gl.glPushMatrix();
1126
+
1127
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1128
+
1129
+ double K = count/nbsteps;
1130
+
1131
+ double intersize = K*nextsize + (1-K)*size;
1132
+
1133
+ gl.glScaled(intersize,intersize,intersize);
1134
+
1135
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1136
+
1137
+ count++;
1138
+
1139
+ distancenext -= step;
1140
+
1141
+ gl.glPopMatrix();
1142
+ }
1143
+
1144
+ if (count != nbsteps)
1145
+ assert(count == nbsteps);
1146
+
1147
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1148
+ //gl.glTranslatef(-tx,-ty,-tz);
1149
+
1150
+ gl.glMatrixMode(gl.GL_TEXTURE);
1151
+ gl.glPopMatrix();
1152
+ }
1153
+
1154
+ if (!cf)
1155
+ gl.glDisable(gl.GL_CULL_FACE);
1156
+
1157
+// display.modelParams0[0] = r;
1158
+// display.modelParams0[1] = g;
1159
+// display.modelParams0[2] = b;
1160
+//
1161
+// display.modelParams5[1] = opacity;
1162
+//
1163
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1164
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1165
+
1166
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1167
+ }
1168
+
1169
+ public void DrawBox(cVector min, cVector max)
1170
+ {
1171
+ javax.media.opengl.GL gl = GetGL();
1172
+ gl.glBegin(gl.GL_LINES);
1173
+
1174
+ gl.glVertex3d(min.x, min.y, min.z);
1175
+ gl.glVertex3d(min.x, min.y, max.z);
1176
+ gl.glVertex3d(min.x, min.y, min.z);
1177
+ gl.glVertex3d(min.x, max.y, min.z);
1178
+ gl.glVertex3d(min.x, min.y, min.z);
1179
+ gl.glVertex3d(max.x, min.y, min.z);
1180
+
1181
+ gl.glVertex3d(max.x, max.y, max.z);
1182
+ gl.glVertex3d(min.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, max.y, max.z);
1184
+ gl.glVertex3d(max.x, min.y, max.z);
1185
+ gl.glVertex3d(max.x, max.y, max.z);
1186
+ gl.glVertex3d(max.x, max.y, min.z);
1187
+
1188
+ gl.glEnd();
1189
+ }
1190
+
1191
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1192
+ {
1193
+ int[] strips = bRep.getRawIndices();
1194
+
1195
+ javax.media.opengl.GL gl = GetGL();
1196
+
1197
+ // TRIANGLE STRIP ARRAY
1198
+ if (bRep.trimmed)
1199
+ {
1200
+ float[] v = bRep.getRawVertices();
1201
+ float[] n = bRep.getRawNormals();
1202
+ float[] c = bRep.getRawColors();
1203
+ float[] uv = bRep.getRawUVMap();
1204
+
1205
+ int count2 = 0;
1206
+ int count3 = 0;
1207
+
1208
+ if (n.length > 0)
1209
+ {
1210
+ for (int i = 0; i < strips.length; i++)
1211
+ {
1212
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1213
+
1214
+ /*
1215
+ boolean locked = false;
1216
+ float eps = 0.1f;
1217
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1218
+
1219
+ int dot = 0;
1220
+
1221
+ if ((dot&1) == 0)
1222
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1223
+
1224
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1225
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1226
+ else
1227
+ {
1228
+ locked = true;
1229
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1230
+ }
1231
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1232
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1233
+ if (hasnorm)
1234
+ {
1235
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1236
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1237
+ }
1238
+
1239
+ if ((dot&4) == 0)
1240
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1241
+
1242
+ if (wrap || !locked && (dot&8) != 0)
1243
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1244
+ else
1245
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1246
+
1247
+ f.dot = dot;
1248
+ */
1249
+
1250
+ if (!selectmode)
1251
+ {
1252
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1253
+ {
1254
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1255
+ } else
1256
+ {
1257
+ SetGLNormal(gl, 0, 0, 1);
1258
+ }
1259
+
1260
+ if (c != null)
1261
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1262
+ {
1263
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1264
+ }
1265
+ }
1266
+
1267
+ if (flipV)
1268
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1269
+ else
1270
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1271
+
1272
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1273
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1274
+
1275
+ count2 += 2;
1276
+ count3 += 3;
1277
+ if (!selectmode)
1278
+ {
1279
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1280
+ {
1281
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1282
+ } else
1283
+ {
1284
+ SetGLNormal(gl, 0, 0, 1);
1285
+ }
1286
+ if (c != null)
1287
+ {
1288
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1289
+ }
1290
+ }
1291
+
1292
+ if (flipV)
1293
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1294
+ else
1295
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1296
+
1297
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1298
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1299
+
1300
+ count2 += 2;
1301
+ count3 += 3;
1302
+ for (int j = 0; j < strips[i] - 2; j++)
1303
+ {
1304
+ //gl.glTexCoord2d(...);
1305
+ if (!selectmode)
1306
+ {
1307
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1308
+ {
1309
+ SetGLNormal(gl, n[count3], n[count3 + 1], n[count3 + 2]);
1310
+ } else
1311
+ {
1312
+ SetGLNormal(gl, 0, 0, 1);
1313
+ }
1314
+ if (c != null)
1315
+ {
1316
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1317
+ }
1318
+ }
1319
+
1320
+ if (flipV)
1321
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1322
+ else
1323
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1324
+
1325
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1326
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1327
+
1328
+ count2 += 2;
1329
+ count3 += 3;
1330
+ }
1331
+
1332
+ gl.glEnd();
1333
+ }
1334
+ }
1335
+
1336
+ assert count3 == v.length;
1337
+ }
1338
+ else // !trimmed
1339
+ {
1340
+ int count = 0;
1341
+ for (int i = 0; i < strips.length; i++)
1342
+ {
1343
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1344
+
1345
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1346
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1347
+
1348
+ drawVertex(gl, p, flipV, selectmode);
1349
+ drawVertex(gl, q, flipV, selectmode);
1350
+
1351
+ for (int j = 0; j < strips[i] - 2; j++)
1352
+ {
1353
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1354
+
1355
+ // if (j%2 == 0)
1356
+ // drawFace(p, q, r, display, null);
1357
+ // else
1358
+ // drawFace(p, r, q, display, null);
1359
+
1360
+ // p = q;
1361
+ // q = r;
1362
+ drawVertex(gl, r, flipV, selectmode);
1363
+ }
1364
+
1365
+ gl.glEnd();
1366
+ }
1367
+ }
1368
+ }
1369
+
1370
+ static cSpring.Point3D temp = new cSpring.Point3D();
1371
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1372
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1373
+
1374
+ public void DrawDynamicMesh(cMesh mesh)
1375
+ {
1376
+ GL gl = GetGL(); // getGL();
1377
+
1378
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1379
+
1380
+ gl.glDisable(gl.GL_LIGHTING);
1381
+
1382
+ gl.glLineWidth(1);
1383
+ gl.glColor3f(1,1,1);
1384
+ gl.glBegin(gl.GL_LINES);
1385
+ double scale = 0;
1386
+ int count = 0;
1387
+ for (int s=0; s<Phys.allSprings.size(); s++)
1388
+ {
1389
+ cSpring.Spring spring = Phys.allSprings.get(s);
1390
+ if(s == 0)
1391
+ {
1392
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1393
+ }
1394
+ if (mesh.showsprings)
1395
+ {
1396
+ temp.set(spring.a.position);
1397
+ temp.add(spring.b.position);
1398
+ temp.mul(0.5);
1399
+ temp2.set(spring.a.position);
1400
+ temp2.sub(spring.b.position);
1401
+ temp2.mul(spring.restLength/2);
1402
+ temp.sub(temp2);
1403
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1404
+ temp.add(temp2);
1405
+ temp.add(temp2);
1406
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1407
+ }
1408
+
1409
+ if (spring.isHandle)
1410
+ continue;
1411
+
1412
+ //if (scale < spring.restLength)
1413
+ scale += spring.restLength;
1414
+ count++;
1415
+ }
1416
+ gl.glEnd();
1417
+
1418
+ if (count == 0)
1419
+ scale = 0.01;
1420
+ else
1421
+ scale /= count * 3;
1422
+
1423
+ //scale = 0.25;
1424
+
1425
+ if (mesh.ShowInfo())
1426
+ {
1427
+ gl.glLineWidth(4);
1428
+ for (int s=0; s<Phys.allNodes.size(); s++)
1429
+ {
1430
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1431
+ if (node.mass == 0)
1432
+ continue;
1433
+
1434
+ int i = node.springs==null?-1:node.springs.size();
1435
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1436
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1437
+ //temp.normalize();
1438
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1439
+ gl.glBegin(gl.GL_LINES);
1440
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1441
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1442
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1443
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1444
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1445
+ gl.glEnd();
1446
+ }
1447
+
1448
+ gl.glLineWidth(8);
1449
+ for (int s=0; s<Phys.allNodes.size(); s++)
1450
+ {
1451
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1452
+
1453
+ if (node.springs != null)
1454
+ {
1455
+ for (int i=0; i<node.springs.size(); i+=1)
1456
+ {
1457
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1458
+
1459
+ int c = i+1;
1460
+ // c = node.springs.get(i).nbcopies;
1461
+
1462
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1463
+ gl.glBegin(gl.GL_LINES);
1464
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1465
+ gl.glVertex3d(f.position.x/3+node.position.x*2/3, f.position.y/3+node.position.y*2/3, f.position.z/3+node.position.z*2/3);
1466
+ gl.glEnd();
1467
+ }
1468
+ }
1469
+ }
1470
+
1471
+ gl.glLineWidth(1);
1472
+ }
1473
+
1474
+ gl.glEnable(gl.GL_LIGHTING);
1475
+ }
1476
+
5691477 /// INTERFACE
5701478
1479
+ public void StartTriangles()
1480
+ {
1481
+ javax.media.opengl.GL gl = GetGL();
1482
+ gl.glBegin(gl.GL_TRIANGLES);
1483
+ }
1484
+
1485
+ public void EndTriangles()
1486
+ {
1487
+ GetGL().glEnd();
1488
+ }
1489
+
1490
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1491
+ {
1492
+ if (!selectmode)
1493
+ {
1494
+ SetGLNormal(gl, (float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1495
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1496
+
1497
+ if (flipV)
1498
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1499
+ else
1500
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1501
+ }
1502
+
1503
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1504
+ }
1505
+
1506
+ float[] colorV = new float[4];
1507
+
5711508 void SetColor(Object3D obj, Vertex p0)
5721509 {
5731510 CameraPane display = this;
....@@ -635,8 +1572,6 @@
6351572 {
6361573 return;
6371574 }
638
-
639
- float[] colorV = new float[3];
6401575
6411576 if (false) // marked)
6421577 {
....@@ -745,7 +1680,7 @@
7451680 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
7461681 }
7471682
748
- void DrawMaterial(cMaterial material, boolean selected)
1683
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
7491684 {
7501685 CameraPane display = this;
7511686 //new Exception().printStackTrace();
....@@ -761,18 +1696,18 @@
7611696 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
7621697 if (!material.multiply)
7631698 {
764
- display.color = color;
1699
+ display.color = material.color;
7651700 display.saturation = material.modulation;
7661701 }
7671702 else
7681703 {
769
- display.color *= color*2;
1704
+ display.color *= material.color*2;
7701705 display.saturation *= material.modulation*2;
7711706 }
7721707
7731708 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
7741709
775
- float[] colorV = GrafreeD.colorV;
1710
+ float[] colorV = Grafreed.colorV;
7761711
7771712 /**/
7781713 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -780,7 +1715,7 @@
7801715 colorV[0] = display.modelParams0[0] * material.diffuse;
7811716 colorV[1] = display.modelParams0[1] * material.diffuse;
7821717 colorV[2] = display.modelParams0[2] * material.diffuse;
783
- colorV[3] = material.opacity;
1718
+ colorV[3] = 1; // material.opacity;
7841719
7851720 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
7861721 //System.out.println("Opacity = " + opacity);
....@@ -885,12 +1820,12 @@
8851820
8861821 display.modelParams7[0] = 0;
8871822 display.modelParams7[1] = 1000;
888
- display.modelParams7[2] = 0;
1823
+ display.modelParams7[2] = material.parallax;
8891824 display.modelParams7[3] = 0;
8901825
891
- display.modelParams6[0] = 100; // criss de bug de bump
1826
+ //display.modelParams6[0] = 100; // criss de bug de bump
8921827
893
- Object3D.cVector2[] extparams = display.vector2buffer;
1828
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
8941829 if (extparams != null && extparams.length > 0 && extparams[0] != null)
8951830 {
8961831 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1032,7 +1967,7 @@
10321967 void PushMatrix(double[][] matrix)
10331968 {
10341969 // GrafreeD.tracein(matrix);
1035
- PushMatrix(matrix,1);
1970
+ PushMatrix(matrix, 1);
10361971 }
10371972
10381973 void PushMatrix()
....@@ -1118,9 +2053,9 @@
11182053 switch(viewcode)
11192054 {
11202055 case 0: return "main";
1121
- case 1: return "one";
1122
- case 2: return "two";
1123
- case 3: return "three";
2056
+ case 1: return "Red";
2057
+ case 2: return "Green";
2058
+ case 3: return "Blue";
11242059 case 4: return "light";
11252060 }
11262061
....@@ -1129,7 +2064,7 @@
11292064
11302065 static int camerachangeframe;
11312066
1132
- boolean SetCamera(Camera cam)
2067
+ public boolean SetCamera(Camera cam)
11332068 {
11342069 // may 2014 if (cam == cameras[0] || cam == cameras[1])
11352070 // return false;
....@@ -1186,7 +2121,7 @@
11862121 //System.err.println("Oeil on");
11872122 OEIL = true;
11882123 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1189
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2124
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11902125 //pingthread.StepToTarget(true);
11912126 }
11922127
....@@ -1257,33 +2192,6 @@
12572192 mainDL ^= true;
12582193 }
12592194
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
-
12872195 void ToggleFullScreen()
12882196 {
12892197 FULLSCREEN ^= true;
....@@ -1294,72 +2202,94 @@
12942202 Globals.CROWD ^= true;
12952203 }
12962204
1297
- void ToggleInertia()
1298
- {
1299
- INERTIA ^= true;
1300
- }
1301
-
13022205 void ToggleLocal()
13032206 {
13042207 LOCALTRANSFORM ^= true;
13052208 }
13062209
1307
- void ToggleFast()
2210
+ public void ToggleTexture()
2211
+ {
2212
+ textureon ^= true;
2213
+ }
2214
+
2215
+ public void ToggleLive()
2216
+ {
2217
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2218
+
2219
+ System.err.println("LIVE = " + Globals.isLIVE());
2220
+
2221
+ if (!Globals.isLIVE()) // save sound
2222
+ Grafreed.savesound = true; // wav.save();
2223
+ // else
2224
+ repaint(); // start loop // may 2013
2225
+ }
2226
+
2227
+ public void ToggleSupport()
2228
+ {
2229
+ SUPPORT ^= true;
2230
+ }
2231
+
2232
+ public void ToggleAbort()
2233
+ {
2234
+ ABORTMODE ^= true;
2235
+ }
2236
+
2237
+ public void ToggleInertia()
2238
+ {
2239
+ INERTIA ^= true;
2240
+ }
2241
+
2242
+ public void ToggleFast()
13082243 {
13092244 FAST ^= true;
13102245 }
13112246
1312
- void ToggleSlowPose()
2247
+ public void ToggleSlowPose()
13132248 {
13142249 SLOWPOSE ^= true;
13152250 }
13162251
1317
- void ToggleFootContact()
1318
- {
1319
- FOOTCONTACT ^= true;
1320
- }
1321
-
1322
- void ToggleBoxMode()
2252
+ public void ToggleBoxMode()
13232253 {
13242254 BOXMODE ^= true;
13252255 }
13262256
1327
- void ToggleSmoothFocus()
2257
+ public void ToggleZoomBoxMode()
2258
+ {
2259
+ ZOOMBOXMODE ^= true;
2260
+ }
2261
+
2262
+ public void ToggleSmoothFocus()
13282263 {
13292264 SMOOTHFOCUS ^= true;
13302265 }
13312266
1332
- void ToggleImageFlip()
2267
+ public void ToggleImageFlip()
13332268 {
13342269 IMAGEFLIP ^= true;
13352270 }
13362271
1337
- void ToggleSpeakerMocap()
2272
+ public void ToggleSpeakerMocap()
13382273 {
13392274 SPEAKERMOCAP ^= true;
13402275 }
13412276
1342
- void ToggleSpeakerCamera()
2277
+ public void ToggleSpeakerCamera()
13432278 {
13442279 SPEAKERCAMERA ^= true;
13452280 }
13462281
1347
- void ToggleSpeakerFocus()
2282
+ public void ToggleSpeakerFocus()
13482283 {
13492284 SPEAKERFOCUS ^= true;
13502285 }
13512286
1352
- void ToggleDebug()
1353
- {
1354
- DEBUG ^= true;
1355
- }
1356
-
1357
- void ToggleFrustum()
2287
+ public void ToggleFrustum()
13582288 {
13592289 FRUSTUM ^= true;
13602290 }
13612291
1362
- void ToggleTrack()
2292
+ public void ToggleTrack()
13632293 {
13642294 TRACK ^= true;
13652295 if (TRACK)
....@@ -1378,25 +2308,35 @@
13782308 repaint();
13792309 }
13802310
1381
- void ToggleTrackOnce()
2311
+ public void ToggleTrackOnce()
13822312 {
13832313 TRACKONCE ^= true;
13842314 }
13852315
1386
- void ToggleShadowTrack()
2316
+ public void ToggleShadowTrack()
13872317 {
13882318 SHADOWTRACK ^= true;
13892319 repaint();
13902320 }
13912321
1392
- void ToggleOeil()
2322
+ public void ToggleOeil()
13932323 {
13942324 OEIL ^= true;
13952325 }
13962326
1397
- void ToggleOeilOnce()
2327
+ public void ToggleOeilOnce()
13982328 {
13992329 OEILONCE ^= true;
2330
+ }
2331
+
2332
+ void ToggleFootContact()
2333
+ {
2334
+ FOOTCONTACT ^= true;
2335
+ }
2336
+
2337
+ void ToggleDebug()
2338
+ {
2339
+ Globals.DEBUG ^= true;
14002340 }
14012341
14022342 void ToggleLookAt()
....@@ -1404,9 +2344,9 @@
14042344 LOOKAT ^= true;
14052345 }
14062346
1407
- void ToggleRandom()
2347
+ void ToggleSwitch()
14082348 {
1409
- RANDOM ^= true;
2349
+ SWITCH ^= true;
14102350 }
14112351
14122352 void ToggleHandles()
....@@ -1414,10 +2354,17 @@
14142354 HANDLES ^= true;
14152355 }
14162356
2357
+ Object3D paintFolder;
2358
+
14172359 void TogglePaint()
14182360 {
14192361 PAINTMODE ^= true;
14202362 paintcount = 0;
2363
+
2364
+ if (PAINTMODE)
2365
+ {
2366
+ paintFolder = GetFolder();
2367
+ }
14212368 }
14222369
14232370 void SwapCamera(int a, int b)
....@@ -1513,7 +2460,34 @@
15132460 {
15142461 return currentGL;
15152462 }
1516
-
2463
+
2464
+ static private BufferedImage CreateBim(TextureData texturedata)
2465
+ {
2466
+ Grafreed.Assert(texturedata != null);
2467
+
2468
+ int width = texturedata.getWidth();
2469
+ int height = texturedata.getHeight();
2470
+
2471
+ Buffer buffer = texturedata.getBuffer();
2472
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2473
+
2474
+ byte[] bytes = bytebuf.array();
2475
+
2476
+ return CreateBim(bytes, width, height);
2477
+ }
2478
+
2479
+ private void SetGLNormal(javax.media.opengl.GL gl, float nx, float ny, float nz)
2480
+ {
2481
+ gl.glNormal3f(nx, ny, nz);
2482
+
2483
+ if (ny > 0.9 || ny < -0.9)
2484
+ // Ground or ceiling
2485
+ gl.glVertexAttrib3f(4, 1, 0, 0);
2486
+ else
2487
+ // Walls
2488
+ gl.glVertexAttrib3f(4, 0, 1, 0);
2489
+ }
2490
+
15172491 /**/
15182492 class CacheTexture
15192493 {
....@@ -1522,28 +2496,31 @@
15222496
15232497 int resolution;
15242498
1525
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2499
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
15262500 {
1527
- texture = tex;
2501
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2502
+ texturedata = texdata;
15282503 resolution = res;
15292504 }
15302505 }
15312506 /**/
15322507
15332508 // 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>();
2509
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2510
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2511
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2512
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2513
+
15372514 int pigmentdepth = 0;
15382515 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
15392516 int bumpdepth = 0;
15402517 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
15412518 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
15422519 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
1543
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2520
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
15442521 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
15452522
1546
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2523
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
15472524 {
15482525 TextureData texturedata = null;
15492526
....@@ -1553,7 +2530,7 @@
15532530 com.sun.opengl.util.texture.TextureIO.newTextureData(
15542531 getClass().getClassLoader().getResourceAsStream(name),
15552532 true,
1556
- com.sun.opengl.util.texture.TextureIO.PNG);
2533
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
15572534 } catch (java.io.IOException e)
15582535 {
15592536 throw new javax.media.opengl.GLException(e);
....@@ -1562,13 +2539,34 @@
15622539 if (bump)
15632540 texturedata = ConvertBump(texturedata, false);
15642541
1565
- com.sun.opengl.util.texture.Texture texture =
1566
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2542
+// com.sun.opengl.util.texture.Texture texture =
2543
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
15672544
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);
2545
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2546
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
15702547
1571
- return texture;
2548
+ return texturedata;
2549
+ }
2550
+
2551
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2552
+ {
2553
+ TextureData texturedata = null;
2554
+
2555
+ try
2556
+ {
2557
+ texturedata =
2558
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2559
+ bim,
2560
+ true);
2561
+ } catch (Exception e)
2562
+ {
2563
+ throw new javax.media.opengl.GLException(e);
2564
+ }
2565
+
2566
+ if (bump)
2567
+ texturedata = ConvertBump(texturedata, false);
2568
+
2569
+ return texturedata;
15722570 }
15732571
15742572 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -2641,6 +3639,8 @@
26413639
26423640 System.out.println("LOADING TEXTURE : " + name);
26433641
3642
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3643
+
26443644 //
26453645 if (false) // compressbit > 0)
26463646 {
....@@ -3345,6 +4345,7 @@
33454345
33464346 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
33474347 {
4348
+ new Exception().printStackTrace();
33484349 System.exit(0);
33494350 com.sun.opengl.util.texture.Texture texture = null;
33504351
....@@ -7038,7 +8039,7 @@
70388039 String pigment = Object3D.GetPigment(tex);
70398040 String bump = Object3D.GetBump(tex);
70408041
7041
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8042
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
70428043 {
70438044 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
70448045 // System.out.println("; bump = " + bump);
....@@ -7053,11 +8054,69 @@
70538054 pigment = null;
70548055 }
70558056
7056
- ReleaseTexture(bump, true);
7057
- ReleaseTexture(pigment, false);
8057
+ ReleaseTexture(tex, true);
8058
+ ReleaseTexture(tex, false);
70588059 }
70598060
7060
- void ReleaseTexture(String tex, boolean bump)
8061
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8062
+ {
8063
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8064
+ {
8065
+ return;
8066
+ }
8067
+
8068
+ if (tex == null)
8069
+ {
8070
+ ReleaseTexture(null, false);
8071
+ return;
8072
+ }
8073
+
8074
+ String pigment = Object3D.GetPigment(tex);
8075
+
8076
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8077
+ {
8078
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8079
+ // System.out.println("; bump = " + bump);
8080
+ }
8081
+
8082
+ if (pigment.equals(""))
8083
+ {
8084
+ pigment = null;
8085
+ }
8086
+
8087
+ ReleaseTexture(tex, false);
8088
+ }
8089
+
8090
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8091
+ {
8092
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8093
+ {
8094
+ return;
8095
+ }
8096
+
8097
+ if (tex == null)
8098
+ {
8099
+ ReleaseTexture(null, true);
8100
+ return;
8101
+ }
8102
+
8103
+ String bump = Object3D.GetBump(tex);
8104
+
8105
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8106
+ {
8107
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8108
+ // System.out.println("; bump = " + bump);
8109
+ }
8110
+
8111
+ if (bump.equals(""))
8112
+ {
8113
+ bump = null;
8114
+ }
8115
+
8116
+ ReleaseTexture(tex, true);
8117
+ }
8118
+
8119
+ void ReleaseTexture(cTexture tex, boolean bump)
70618120 {
70628121 if (// DrawMode() != 0 || /*tex == null ||*/
70638122 ambientOcclusion ) // || !textureon)
....@@ -7068,7 +8127,7 @@
70688127 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
70698128
70708129 if (tex != null)
7071
- texture = textures.get(tex);
8130
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
70728131
70738132 // //assert( texture != null );
70748133 // if (texture == null)
....@@ -7160,7 +8219,55 @@
71608219 }
71618220 }
71628221
7163
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8222
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8223
+ {
8224
+// if (// DrawMode() != 0 || /*tex == null ||*/
8225
+// ambientOcclusion ) // || !textureon)
8226
+// {
8227
+// return; // false;
8228
+// }
8229
+//
8230
+// if (tex == null)
8231
+// {
8232
+// BindTexture(null,false,resolution);
8233
+// BindTexture(null,true,resolution);
8234
+// return;
8235
+// }
8236
+//
8237
+// String pigment = Object3D.GetPigment(tex);
8238
+// String bump = Object3D.GetBump(tex);
8239
+//
8240
+// usedtextures.add(pigment);
8241
+// usedtextures.add(bump);
8242
+//
8243
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8244
+// {
8245
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8246
+// // System.out.println("; bump = " + bump);
8247
+// }
8248
+//
8249
+// if (bump.equals(""))
8250
+// {
8251
+// bump = null;
8252
+// }
8253
+// if (pigment.equals(""))
8254
+// {
8255
+// pigment = null;
8256
+// }
8257
+//
8258
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8259
+// BindTexture(pigment, false, resolution);
8260
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8261
+// BindTexture(bump, true, resolution);
8262
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8263
+//
8264
+// return; // true;
8265
+
8266
+ BindPigmentTexture(tex, resolution);
8267
+ BindBumpTexture(tex, resolution);
8268
+ }
8269
+
8270
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
71648271 {
71658272 if (// DrawMode() != 0 || /*tex == null ||*/
71668273 ambientOcclusion ) // || !textureon)
....@@ -7171,17 +8278,47 @@
71718278 if (tex == null)
71728279 {
71738280 BindTexture(null,false,resolution);
7174
- BindTexture(null,true,resolution);
71758281 return;
71768282 }
71778283
71788284 String pigment = Object3D.GetPigment(tex);
8285
+
8286
+ usedtextures.add(tex);
8287
+
8288
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8289
+ {
8290
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8291
+ // System.out.println("; bump = " + bump);
8292
+ }
8293
+
8294
+ if (pigment.equals(""))
8295
+ {
8296
+ pigment = null;
8297
+ }
8298
+
8299
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8300
+ BindTexture(tex, false, resolution);
8301
+ }
8302
+
8303
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8304
+ {
8305
+ if (// DrawMode() != 0 || /*tex == null ||*/
8306
+ ambientOcclusion ) // || !textureon)
8307
+ {
8308
+ return; // false;
8309
+ }
8310
+
8311
+ if (tex == null)
8312
+ {
8313
+ BindTexture(null,true,resolution);
8314
+ return;
8315
+ }
8316
+
71798317 String bump = Object3D.GetBump(tex);
71808318
7181
- usedtextures.put(pigment, pigment);
7182
- usedtextures.put(bump, bump);
8319
+ usedtextures.add(tex);
71838320
7184
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8321
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
71858322 {
71868323 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
71878324 // System.out.println("; bump = " + bump);
....@@ -7191,43 +8328,94 @@
71918328 {
71928329 bump = null;
71938330 }
7194
- if (pigment.equals(""))
7195
- {
7196
- pigment = null;
7197
- }
71988331
7199
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7200
- BindTexture(pigment, false, resolution);
72018332 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7202
- BindTexture(bump, true, resolution);
8333
+ BindTexture(tex, true, resolution);
72038334 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7204
-
7205
- return; // true;
72068335 }
72078336
7208
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8337
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8338
+
8339
+ private boolean FileExists(String tex)
72098340 {
7210
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8341
+ if (missingTextures.contains(tex))
8342
+ {
8343
+ return false;
8344
+ }
8345
+
8346
+ boolean fileExists = new File(tex).exists();
8347
+
8348
+ if (!fileExists)
8349
+ {
8350
+ // If file exists, the "new File()" is not executed sgain
8351
+ missingTextures.add(tex);
8352
+ }
8353
+
8354
+ return fileExists;
8355
+ }
8356
+
8357
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8358
+ {
8359
+ CacheTexture texturecache = null;
72118360
72128361 if (tex != null)
72138362 {
7214
- String texname = tex;
8363
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8364
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
72158365
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;
8366
+ if (texname.equals("") && texdata == null)
8367
+ {
8368
+ return null;
8369
+ }
8370
+
8371
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8372
+
8373
+// String[] split = tex.split("Textures");
8374
+// if (split.length > 1)
8375
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8376
+// else
8377
+// if (!texname.startsWith("/"))
8378
+// texname = "/Users/nbriere/Textures/" + texname;
8379
+ if (!FileExists(texname) && !texname.startsWith("@"))
8380
+ {
8381
+ texname = fallbackTextureName;
8382
+ }
72228383
72238384 if (CACHETEXTURE)
7224
- texture = textures.get(texname); // TEXTURE CACHE
7225
-
7226
- TextureData texturedata = null;
7227
-
7228
- if (texture == null || texture.resolution < resolution)
72298385 {
7230
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8386
+ if (texdata == null)
8387
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8388
+ else
8389
+ texturecache = bimtextures.get(texdata);
8390
+ }
8391
+
8392
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8393
+ {
8394
+ TextureData texturedata = null;
8395
+
8396
+ if (texdata != null && textureon)
8397
+ {
8398
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8399
+
8400
+ try
8401
+ {
8402
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8403
+ }
8404
+ catch (Exception e)
8405
+ {
8406
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8407
+ }
8408
+
8409
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8410
+ bimtextures.put(texdata, texturecache);
8411
+
8412
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8413
+
8414
+ //Object bim2 = CreateBim(texturecache.texturedata);
8415
+ //bim2 = bim;
8416
+ }
8417
+ else
8418
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
72318419 {
72328420 assert(!bump);
72338421 // if (bump)
....@@ -7238,19 +8426,23 @@
72388426 // }
72398427 // else
72408428 // {
7241
- texture = textures.get(tex);
7242
- if (texture == null)
8429
+ // texturecache = textures.get(texname); // suspicious
8430
+ if (texturecache == null)
72438431 {
7244
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8432
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
72458433 }
8434
+ else
8435
+ new Exception().printStackTrace();
72468436 // }
72478437 } else
7248
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8438
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
72498439 {
72508440 assert(bump);
7251
- texture = textures.get(tex);
7252
- if (texture == null)
7253
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8441
+ // texturecache = textures.get(texname); // suspicious
8442
+ if (texturecache == null)
8443
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8444
+ else
8445
+ new Exception().printStackTrace();
72548446 } else
72558447 {
72568448 //if (tex.equals("IMMORTAL"))
....@@ -7258,11 +8450,22 @@
72588450 // texture = GetResourceTexture("default.png");
72598451 //} else
72608452 //{
7261
- if (tex.equals("WHITE_NOISE"))
8453
+ if (texname.endsWith("WHITE_NOISE"))
72628454 {
7263
- texture = textures.get(tex);
7264
- if (texture == null)
7265
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8455
+ // texturecache = textures.get(texname); // suspicious
8456
+ if (texturecache == null)
8457
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8458
+ else
8459
+ new Exception().printStackTrace();
8460
+ } else
8461
+ {
8462
+ if (texname.startsWith("@"))
8463
+ {
8464
+ // texturecache = textures.get(texname); // suspicious
8465
+ if (texturecache == null)
8466
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8467
+ else
8468
+ new Exception().printStackTrace();
72668469 } else
72678470 {
72688471 if (textureon)
....@@ -7287,7 +8490,7 @@
72878490 }
72888491
72898492 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7290
- if (!new File(cachename).exists())
8493
+ if (!FileExists(cachename))
72918494 cachename = texname;
72928495 else
72938496 processbump = false; // don't process bump map again
....@@ -7309,7 +8512,7 @@
73098512 }
73108513
73118514 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7312
- if (!new File(cachename).exists())
8515
+ if (!FileExists(cachename))
73138516 cachename = texname;
73148517 else
73158518 processbump = false; // don't process bump map again
....@@ -7318,20 +8521,23 @@
73188521 texturedata = GetFileTexture(cachename, processbump, resolution);
73198522
73208523
7321
- if (texturedata != null)
7322
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8524
+ if (texturedata == null)
8525
+ throw new Exception();
8526
+
8527
+ texturecache = new CacheTexture(texturedata,resolution);
73238528 //texture = GetTexture(tex, bump);
73248529 }
8530
+ }
73258531 }
73268532 //}
73278533 }
73288534
7329
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8535
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
73308536 {
73318537 //return false;
73328538
73338539 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7334
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8540
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
73358541 {
73368542 // String ext = "_highres";
73378543 // if (REDUCETEXTURE)
....@@ -7348,52 +8554,17 @@
73488554 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
73498555 if (!cachefile.exists())
73508556 {
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))
8557
+ //if (texturedata.getWidth() == texturedata.getHeight())
73608558 {
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);
8559
+ BufferedImage rendImage = CreateBim(texturedata);
8560
+
73918561 ImageWriter writer = null;
73928562 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
73938563 if (iter.hasNext()) {
73948564 writer = (ImageWriter)iter.next();
73958565 }
7396
- float compressionQuality = 0.9f;
8566
+
8567
+ float compressionQuality = 0.85f;
73978568 try
73988569 {
73998570 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7410,18 +8581,20 @@
74108581 }
74118582 }
74128583 }
7413
-
8584
+
8585
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8586
+
74148587 //System.out.println("Texture = " + tex);
7415
- if (textures.containsKey(texname))
8588
+ if (textures.containsKey(tex))
74168589 {
7417
- CacheTexture thetex = textures.get(texname);
8590
+ CacheTexture thetex = textures.get(tex);
74188591 thetex.texture.disable();
74198592 thetex.texture.dispose();
7420
- textures.remove(texname);
8593
+ textures.remove(tex);
74218594 }
74228595
7423
- texture.texturedata = texturedata;
7424
- textures.put(texname, texture);
8596
+ //texture.texturedata = texturedata;
8597
+ textures.put(tex, texturecache);
74258598
74268599 // newtex = true;
74278600 }
....@@ -7437,10 +8610,44 @@
74378610 }
74388611 }
74398612
7440
- return texture;
8613
+ return texturecache;
74418614 }
74428615
7443
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8616
+ static void EmbedTextures(cTexture tex)
8617
+ {
8618
+ if (tex.pigmentdata == null)
8619
+ {
8620
+ //String texname = Object3D.GetPigment(tex);
8621
+
8622
+ CacheTexture texturecache = texturepigment.get(tex);
8623
+
8624
+ if (texturecache != null)
8625
+ {
8626
+ tex.pw = texturecache.texturedata.getWidth();
8627
+ tex.ph = texturecache.texturedata.getHeight();
8628
+ tex.pigmentdata = //CompressJPEG(CreateBim
8629
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8630
+ ;
8631
+ //, tex.pw, tex.ph), 0.5f);
8632
+ }
8633
+ }
8634
+
8635
+ if (tex.bumpdata == null)
8636
+ {
8637
+ //String texname = Object3D.GetBump(tex);
8638
+
8639
+ CacheTexture texturecache = texturebump.get(tex);
8640
+
8641
+ if (texturecache != null)
8642
+ {
8643
+ tex.bw = texturecache.texturedata.getWidth();
8644
+ tex.bh = texturecache.texturedata.getHeight();
8645
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8646
+ }
8647
+ }
8648
+ }
8649
+
8650
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
74448651 {
74458652 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
74468653
....@@ -7458,21 +8665,21 @@
74588665 return texture!=null?texture.texture:null;
74598666 }
74608667
7461
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8668
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
74628669 {
74638670 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
74648671
74658672 return texture!=null?texture.texturedata:null;
74668673 }
74678674
7468
- boolean BindTexture(String tex, boolean bump, int resolution)
8675
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
74698676 {
74708677 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
74718678 {
74728679 return false;
74738680 }
74748681
7475
- boolean newtex = false;
8682
+ //boolean newtex = false;
74768683
74778684 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
74788685
....@@ -7504,9 +8711,75 @@
75048711 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
75058712 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
75068713
7507
- return newtex;
8714
+ return true; // Warning: not used.
75088715 }
75098716
8717
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8718
+ {
8719
+ try
8720
+ {
8721
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8722
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8723
+ ImageWriter writer = writers.next();
8724
+
8725
+ ImageWriteParam param = writer.getDefaultWriteParam();
8726
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8727
+ param.setCompressionQuality(quality);
8728
+
8729
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8730
+ writer.setOutput(ios);
8731
+ writer.write(null, new IIOImage(image, null, null), param);
8732
+
8733
+ byte[] data = baos.toByteArray();
8734
+ writer.dispose();
8735
+ return data;
8736
+ }
8737
+ catch (Exception e)
8738
+ {
8739
+ e.printStackTrace();
8740
+ return null;
8741
+ }
8742
+ }
8743
+
8744
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8745
+ {
8746
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8747
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8748
+ ImageReader reader = writers.next();
8749
+
8750
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8751
+
8752
+ ImageReadParam param = reader.getDefaultReadParam();
8753
+ param.setDestination(bim);
8754
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8755
+
8756
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8757
+ reader.setInput(ios);
8758
+ BufferedImage bim2 = reader.read(0, param);
8759
+ reader.dispose();
8760
+
8761
+// WritableRaster raster = bim2.getRaster();
8762
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8763
+// byte[] bytes = data.getData();
8764
+//
8765
+// int[] pixels = new int[bytes.length/3];
8766
+// for (int i=pixels.length; --i>=0;)
8767
+// {
8768
+// int i3 = i*3;
8769
+// pixels[i] = 0xFF;
8770
+// pixels[i] <<= 8;
8771
+// pixels[i] |= bytes[i3+2] & 0xFF;
8772
+// pixels[i] <<= 8;
8773
+// pixels[i] |= bytes[i3+1] & 0xFF;
8774
+// pixels[i] <<= 8;
8775
+// pixels[i] |= bytes[i3] & 0xFF;
8776
+// }
8777
+//
8778
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8779
+
8780
+ return bim;
8781
+ }
8782
+
75108783 ShadowBuffer shadowPBuf;
75118784 AntialiasBuffer antialiasPBuf;
75128785 int MAXSTACK;
....@@ -7523,10 +8796,12 @@
75238796
75248797 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
75258798 MAXSTACK = temp[0];
7526
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
75278801 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
75288802 MAXSTACK = temp[0];
7529
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8803
+ if (Globals.DEBUG)
8804
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
75308805
75318806 // Use debug pipeline
75328807 //drawable.setGL(new DebugGL(gl)); //
....@@ -7534,7 +8809,8 @@
75348809 gl = drawable.getGL(); //
75358810
75368811 GL gl3 = getGL();
7537
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8812
+ if (Globals.DEBUG)
8813
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
75388814
75398815
75408816 //float pos[] = { 100, 100, 100, 0 };
....@@ -7699,7 +8975,7 @@
76998975
77008976 if (cubemap == null)
77018977 {
7702
- LoadEnvy(5);
8978
+ //LoadEnvy(1);
77038979 }
77048980
77058981 //cubemap.enable();
....@@ -7975,6 +9251,8 @@
79759251
79769252 void LoadEnvy(int which)
79779253 {
9254
+ assert(false);
9255
+
79789256 String name;
79799257 String ext;
79809258
....@@ -7986,37 +9264,58 @@
79869264 cubemap = null;
79879265 return;
79889266 case 1:
7989
- name = "cubemaps/box_";
7990
- ext = "png";
9267
+ name = "cubemaps/rgb/";
9268
+ ext = "jpg";
79919269 reverseUP = false;
79929270 break;
79939271 case 2:
7994
- name = "cubemaps/uffizi_";
7995
- ext = "png";
7996
- break; // reverseUP = true; break;
9272
+ name = "cubemaps/uffizi/";
9273
+ ext = "jpg";
9274
+ reverseUP = false;
9275
+ break;
79979276 case 3:
7998
- name = "cubemaps/CloudyHills_";
7999
- ext = "tga";
9277
+ name = "cubemaps/CloudyHills/";
9278
+ ext = "jpg";
80009279 reverseUP = false;
80019280 break;
80029281 case 4:
8003
- name = "cubemaps/cornell_";
9282
+ name = "cubemaps/cornell/";
80049283 ext = "png";
80059284 reverseUP = false;
80069285 break;
9286
+ case 5:
9287
+ name = "cubemaps/skycube/";
9288
+ ext = "jpg";
9289
+ reverseUP = false;
9290
+ break;
9291
+ case 6:
9292
+ name = "cubemaps/SaintLazarusChurch3/";
9293
+ ext = "jpg";
9294
+ reverseUP = false;
9295
+ break;
9296
+ case 7:
9297
+ name = "cubemaps/Sodermalmsallen/";
9298
+ ext = "jpg";
9299
+ reverseUP = false;
9300
+ break;
9301
+ case 8:
9302
+ name = "cubemaps/Sodermalmsallen2/";
9303
+ ext = "jpg";
9304
+ reverseUP = false;
9305
+ break;
9306
+ case 9:
9307
+ name = "cubemaps/UnionSquare/";
9308
+ ext = "jpg";
9309
+ reverseUP = false;
9310
+ break;
80079311 default:
8008
- name = "cubemaps/rgb_";
8009
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9312
+ name = "cubemaps/box/";
9313
+ ext = "png"; /*mipmap = true;*/
9314
+ reverseUP = false;
80109315 break;
80119316 }
8012
-
8013
- try
8014
- {
8015
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8016
- } catch (IOException e)
8017
- {
8018
- throw new RuntimeException(e);
8019
- }
9317
+
9318
+ LoadSkybox(name, ext, mipmap);
80209319 }
80219320
80229321 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8048,8 +9347,12 @@
80489347 static double[] model = new double[16];
80499348 double[] camera2light = new double[16];
80509349 double[] light2camera = new double[16];
8051
- int newenvy = -1;
8052
- boolean envyoff = true; // false;
9350
+
9351
+ //int newenvy = -1;
9352
+ //boolean envyoff = false;
9353
+
9354
+ String loadedskyboxname;
9355
+
80539356 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
80549357 //float[] light0 = { 0,0,0 };
80559358 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -8342,11 +9645,35 @@
83429645 jy8[3] = 0.5f;
83439646 }
83449647
8345
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9648
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
83469649 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
83479650 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
83489651 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
83499652
9653
+ void ResetOptions()
9654
+ {
9655
+ options1[0] = 100;
9656
+ options1[1] = 0.025f;
9657
+ options1[2] = 0.01f;
9658
+ options1[3] = 0;
9659
+ options1[4] = 0;
9660
+
9661
+ options2[0] = 0;
9662
+ options2[1] = 0.75f;
9663
+ options2[2] = 0;
9664
+ options2[3] = 0;
9665
+
9666
+ options3[0] = 1;
9667
+ options3[1] = 1;
9668
+ options3[2] = 1;
9669
+ options3[3] = 0;
9670
+
9671
+ options4[0] = 1;
9672
+ options4[1] = 0;
9673
+ options4[2] = 1;
9674
+ options4[3] = 0;
9675
+ }
9676
+
83509677 static int imagecount = 0; // movie generation
83519678
83529679 static int jitter = 0;
....@@ -8442,8 +9769,8 @@
84429769 assert (parentcam != renderCamera);
84439770
84449771 if (renderCamera != lightCamera)
8445
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8446
- LA.matConcat(matrix, parentcam.toParent, matrix);
9772
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9773
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
84479774
84489775 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
84499776
....@@ -8458,8 +9785,8 @@
84589785 LA.matCopy(renderCamera.fromScreen, matrix);
84599786
84609787 if (renderCamera != lightCamera)
8461
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8462
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9788
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9789
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
84639790
84649791 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
84659792
....@@ -8505,10 +9832,12 @@
85059832 rati = 1 / rati;
85069833 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
85079834 }
8508
- assert (newenvy == -1);
9835
+
9836
+ //assert (newenvy == -1);
9837
+
85099838 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
85109839 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
8511
- DrawSkyBox(gl);
9840
+ DrawSkyBox(gl, (float)rati);
85129841 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
85139842 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
85149843 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -8531,7 +9860,7 @@
85319860 //gl.glFlush();
85329861 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
85339862
8534
- if (ANIMATION && ABORTED)
9863
+ if (Globals.ANIMATION && ABORTED)
85359864 {
85369865 System.err.println(" ABORTED FRAME");
85379866 break;
....@@ -8561,7 +9890,7 @@
85619890 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
85629891
85639892 // save image
8564
- if (ANIMATION && !ABORTED)
9893
+ if (Globals.ANIMATION && !ABORTED)
85659894 {
85669895 VPwidth = viewport[2];
85679896 VPheight = viewport[3];
....@@ -8672,11 +10001,11 @@
867210001
867310002 // imagecount++;
867410003
8675
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
10004
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
867610005
867710006 if (!BOXMODE)
867810007 {
8679
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
10008
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
868010009 }
868110010
868210011 if (!BOXMODE)
....@@ -8714,7 +10043,7 @@
871410043 ABORTED = false;
871510044 }
871610045 else
8717
- GrafreeD.wav.cursor += 735 * ACSIZE;
10046
+ Grafreed.wav.cursor += 735 * ACSIZE;
871810047
871910048 if (false)
872010049 {
....@@ -9374,14 +10703,23 @@
937410703 static boolean init = false;
937510704
937610705 double[][] matrix = LA.newMatrix();
10706
+
10707
+ // This is to refresh the UI of the material panel.
10708
+ ObjEditor patchMaterial;
937710709
937810710 public void display(GLAutoDrawable drawable)
937910711 {
9380
- if (GrafreeD.savesound && GrafreeD.hassound)
10712
+ if (patchMaterial.patchMaterial)
938110713 {
9382
- GrafreeD.wav.save();
9383
- GrafreeD.savesound = false;
9384
- GrafreeD.hassound = false;
10714
+ patchMaterial.patchMaterial = false;
10715
+ patchMaterial.objectPanel.setSelectedIndex(1);
10716
+ }
10717
+
10718
+ if (Grafreed.savesound && Grafreed.hassound)
10719
+ {
10720
+ Grafreed.wav.save();
10721
+ Grafreed.savesound = false;
10722
+ Grafreed.hassound = false;
938510723 }
938610724 // if (DEBUG_SELECTION)
938710725 // {
....@@ -9457,6 +10795,7 @@
945710795 ANTIALIAS = 0;
945810796 //System.out.println("RESTART");
945910797 AAtimer.restart();
10798
+ Globals.TIMERRUNNING = true;
946010799 }
946110800 }
946210801 }
....@@ -9511,7 +10850,7 @@
951110850 Object3D theobject = object;
951210851 Object3D theparent = object.parent;
951310852 object.parent = null;
9514
- object = (Object3D)GrafreeD.clone(object);
10853
+ object = (Object3D)Grafreed.clone(object);
951510854 object.Stripify();
951610855 if (theobject.selection == null || theobject.selection.Size() == 0)
951710856 theobject.PreprocessOcclusion(this);
....@@ -9524,13 +10863,14 @@
952410863 ambientOcclusion = false;
952510864 }
952610865
9527
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10866
+ if (//Globals.lighttouched &&
10867
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
952810868 {
952910869 //if (RENDERSHADOW) // ?
953010870 if (!IsFrozen())
953110871 {
953210872 // dec 2012
9533
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10873
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
953410874 {
953510875 Globals.framecount++;
953610876 shadowbuffer.display();
....@@ -9543,7 +10883,7 @@
954310883
954410884 if (wait)
954510885 {
9546
- Sleep(500);
10886
+ Sleep(200); // blocks everything
954710887
954810888 wait = false;
954910889 }
....@@ -9657,8 +10997,8 @@
965710997
965810998 // if (parentcam != renderCamera) // not a light
965910999 if (cam != lightCamera)
9660
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9661
- LA.matConcat(matrix, parentcam.toParent, matrix);
11000
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11001
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
966211002
966311003 for (int j = 0; j < 4; j++)
966411004 {
....@@ -9672,8 +11012,8 @@
967211012
967311013 // if (parentcam != renderCamera) // not a light
967411014 if (cam != lightCamera)
9675
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9676
- LA.matConcat(parentcam.fromParent, matrix, matrix);
11015
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11016
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
967711017
967811018 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
967911019
....@@ -9759,13 +11099,43 @@
975911099 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
976011100 }
976111101
9762
- if (newenvy > -1)
11102
+// if (newenvy > -1)
11103
+// {
11104
+// LoadEnvy(newenvy);
11105
+// }
11106
+//
11107
+// newenvy = -1;
11108
+
11109
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
976311110 {
9764
- LoadEnvy(newenvy);
11111
+ if (cubemaprgb == null)
11112
+ {
11113
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb2" + "/", "jpg", false);
11114
+ }
11115
+
11116
+ cubemap = cubemaprgb;
976511117 }
9766
-
9767
- newenvy = -1;
9768
-
11118
+ else
11119
+ {
11120
+ if (object.skyboxname != null)
11121
+ {
11122
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11123
+ {
11124
+ if (cubemap != null && cubemap != cubemaprgb)
11125
+ cubemap.dispose();
11126
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11127
+ loadedskyboxname = object.skyboxname;
11128
+ }
11129
+ }
11130
+ else
11131
+ {
11132
+ cubemapcustom = null;
11133
+ loadedskyboxname = null;
11134
+ }
11135
+
11136
+ cubemap = cubemapcustom;
11137
+ }
11138
+
976911139 ratio = ((double) getWidth()) / getHeight();
977011140 //System.out.println("ratio = " + ratio);
977111141
....@@ -9781,7 +11151,7 @@
978111151
978211152 if (!IsFrozen() && !ambientOcclusion)
978311153 {
9784
- DrawSkyBox(gl);
11154
+ DrawSkyBox(gl, (float)ratio);
978511155 }
978611156
978711157 //if (selection_view == -1)
....@@ -9932,7 +11302,16 @@
993211302 // Bump noise
993311303 gl.glActiveTexture(GL.GL_TEXTURE6);
993411304 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9935
- BindTexture(NOISE_TEXTURE, false, 2);
11305
+
11306
+ try
11307
+ {
11308
+ BindTexture(NOISE_TEXTURE, false, 2);
11309
+ }
11310
+ catch (Exception e)
11311
+ {
11312
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11313
+ }
11314
+
993611315
993711316 gl.glActiveTexture(GL.GL_TEXTURE0);
993811317 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9955,9 +11334,9 @@
995511334
995611335 gl.glMatrixMode(GL.GL_MODELVIEW);
995711336
9958
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9959
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9960
-//gl.glEnable(gl.GL_MULTISAMPLE);
11337
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11338
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11339
+gl.glEnable(gl.GL_MULTISAMPLE);
996111340 } else
996211341 {
996311342 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9968,7 +11347,7 @@
996811347 //System.out.println("BLENDING ON");
996911348 gl.glEnable(GL.GL_BLEND);
997011349 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9971
-
11350
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
997211351 gl.glMatrixMode(gl.GL_PROJECTION);
997311352 gl.glLoadIdentity();
997411353
....@@ -10057,8 +11436,8 @@
1005711436 System.err.println("parentcam != renderCamera");
1005811437
1005911438 // if (cam != lightCamera)
10060
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10061
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11439
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11440
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1006211441 }
1006311442
1006411443 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10079,8 +11458,8 @@
1007911458 if (true) // TODO
1008011459 {
1008111460 if (cam != lightCamera)
10082
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10083
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11461
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11462
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1008411463 }
1008511464
1008611465 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10146,7 +11525,7 @@
1014611525 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
1014711526 //System.out.println("fragmentMode = " + fragmentMode);
1014811527
10149
- if (DrawMode() == DEFAULT || DrawMode() == SELECTION || DEBUG_SELECTION)
11528
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
1015011529 {
1015111530 /*
1015211531 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -10217,7 +11596,7 @@
1021711596 }
1021811597 }
1021911598
10220
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11599
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1022111600 {
1022211601 //gl.glDepthFunc(GL.GL_LEQUAL);
1022311602 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10225,24 +11604,21 @@
1022511604
1022611605 boolean texon = textureon;
1022711606
10228
- if (RENDERPROGRAM > 0)
10229
- {
10230
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10231
- textureon = false;
10232
- }
11607
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11608
+ textureon = false;
11609
+
1023311610 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1023411611 //System.out.println("ALLO");
1023511612 gl.glColorMask(false, false, false, false);
1023611613 DrawObject(gl);
10237
- if (RENDERPROGRAM > 0)
10238
- {
10239
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10240
- textureon = texon;
10241
- }
11614
+
11615
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11616
+ textureon = texon;
11617
+
1024211618 gl.glColorMask(true, true, true, true);
1024311619
1024411620 gl.glDepthFunc(GL.GL_EQUAL);
10245
- //gl.glDepthMask(false);
11621
+ gl.glDepthMask(false);
1024611622 }
1024711623
1024811624 if (false) // DrawMode() == SHADOW)
....@@ -10396,8 +11772,14 @@
1039611772 {
1039711773 renderpass++;
1039811774 // System.out.println("Draw object... ");
11775
+ STEP = 1;
1039911776 if (FAST) // in case there is no script
10400
- STEP = 16;
11777
+ STEP = 8;
11778
+
11779
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11780
+ {
11781
+ STEP *= 4;
11782
+ }
1040111783
1040211784 //object.FullInvariants();
1040311785
....@@ -10411,23 +11793,44 @@
1041111793 e.printStackTrace();
1041211794 }
1041311795
10414
- if (GrafreeD.RENDERME > 0)
10415
- GrafreeD.RENDERME--; // mechante magouille
11796
+ if (Grafreed.RENDERME > 0)
11797
+ Grafreed.RENDERME--; // mechante magouille
1041611798
1041711799 Globals.ONESTEP = false;
1041811800 }
1041911801
1042011802 static boolean zoomonce = false;
1042111803
11804
+ static void CreateSelectedPoint()
11805
+ {
11806
+ if (selectedpoint == null)
11807
+ {
11808
+ debugpointG = new Sphere();
11809
+ debugpointP = new Sphere();
11810
+ debugpointC = new Sphere();
11811
+ debugpointR = new Sphere();
11812
+
11813
+ selectedpoint = new Superellipsoid();
11814
+
11815
+ for (int i=0; i<8; i++)
11816
+ {
11817
+ debugpoints[i] = new Sphere();
11818
+ }
11819
+ }
11820
+ }
11821
+
1042211822 void DrawObject(GL gl, boolean draw)
1042311823 {
11824
+ // To clear camera values
11825
+ ResetOptions();
11826
+
1042411827 //System.out.println("DRAW OBJECT " + mouseDown);
1042511828 // DrawMode() = SELECTION;
1042611829 //GL gl = getGL();
1042711830 if ((TRACK || SHADOWTRACK) || zoomonce)
1042811831 {
1042911832 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10430
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11833
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1043111834 pingthread.StepToTarget(true); // true);
1043211835 // zoomonce = false;
1043311836 }
....@@ -10447,7 +11850,7 @@
1044711850 callist = gl.glGenLists(1);
1044811851 }
1044911852
10450
- boolean selectmode = DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
11853
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
1045111854
1045211855 boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
1045311856
....@@ -10482,7 +11885,14 @@
1048211885
1048311886 usedtextures.clear();
1048411887
10485
- BindTextures(DEFAULT_TEXTURES, 2);
11888
+ try
11889
+ {
11890
+ BindTextures(DEFAULT_TEXTURES, 2);
11891
+ }
11892
+ catch (Exception e)
11893
+ {
11894
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11895
+ }
1048611896 }
1048711897 //System.out.println("--> " + stackdepth);
1048811898 // GrafreeD.traceon();
....@@ -10492,8 +11902,9 @@
1049211902
1049311903 if (DrawMode() == DEFAULT)
1049411904 {
10495
- if (DEBUG)
11905
+ if (Globals.DEBUG)
1049611906 {
11907
+ CreateSelectedPoint();
1049711908 float radius = 0.05f;
1049811909 if (selectedpoint.radius != radius)
1049911910 {
....@@ -10547,20 +11958,32 @@
1054711958 ReleaseTextures(DEFAULT_TEXTURES);
1054811959
1054911960 if (CLEANCACHE)
10550
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11961
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1055111962 {
10552
- String tex = e.nextElement();
11963
+ cTexture tex = e.nextElement();
1055311964
1055411965 // System.out.println("Texture --------- " + tex);
1055511966
10556
- if (tex.equals("WHITE_NOISE"))
11967
+ if (tex.equals("WHITE_NOISE:"))
1055711968 continue;
1055811969
10559
- if (!usedtextures.containsKey(tex))
11970
+ if (!usedtextures.contains(tex))
1056011971 {
11972
+ CacheTexture gettex = texturepigment.get(tex);
1056111973 // System.out.println("DISPOSE +++++++++++++++ " + tex);
10562
- textures.get(tex).texture.dispose();
10563
- textures.remove(tex);
11974
+ if (gettex != null)
11975
+ {
11976
+ gettex.texture.dispose();
11977
+ texturepigment.remove(tex);
11978
+ }
11979
+
11980
+ gettex = texturebump.get(tex);
11981
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11982
+ if (gettex != null)
11983
+ {
11984
+ gettex.texture.dispose();
11985
+ texturebump.remove(tex);
11986
+ }
1056411987 }
1056511988 }
1056611989 }
....@@ -10573,7 +11996,14 @@
1057311996 if (checker != null && DrawMode() == DEFAULT)
1057411997 {
1057511998 //BindTexture(IMMORTAL_TEXTURE);
10576
- BindTextures(checker.GetTextures(), checker.texres);
11999
+ try
12000
+ {
12001
+ BindTextures(checker.GetTextures(), checker.texres);
12002
+ }
12003
+ catch (Exception e)
12004
+ {
12005
+ System.err.println("FAILED: " + checker.GetTextures());
12006
+ }
1057712007 // NEAREST
1057812008 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1057912009 DrawChecker(gl);
....@@ -10655,7 +12085,7 @@
1065512085 return;
1065612086 }
1065712087
10658
- String string = obj.GetToolTip();
12088
+ String string = obj.toString(); //.GetToolTip();
1065912089
1066012090 GL gl = GetGL();
1066112091
....@@ -10972,8 +12402,8 @@
1097212402 //obj.TransformToWorld(light, light);
1097312403 for (int i = tp.size(); --i >= 0;)
1097412404 {
10975
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10976
- LA.xformPos(light, tp.get(i).toParent, light);
12405
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12406
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1097712407 }
1097812408
1097912409
....@@ -10990,8 +12420,8 @@
1099012420 parentcam = cameras[0];
1099112421 }
1099212422
10993
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10994
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12423
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12424
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1099512425
1099612426 LA.xformPos(light, renderCamera.toScreen, light);
1099712427
....@@ -11081,8 +12511,76 @@
1108112511
1108212512 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1108312513
11084
- String program =
12514
+ String programmin =
12515
+ // Min shader
1108512516 "!!ARBfp1.0\n" +
12517
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12520
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12521
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12522
+ "PARAM light2cam0 = program.env[10];" +
12523
+ "PARAM light2cam1 = program.env[11];" +
12524
+ "PARAM light2cam2 = program.env[12];" +
12525
+ "TEMP temp;" +
12526
+ "TEMP light;" +
12527
+ "TEMP ndotl;" +
12528
+ "TEMP normal;" +
12529
+ "TEMP depth;" +
12530
+ "TEMP eye;" +
12531
+ "TEMP pos;" +
12532
+
12533
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12534
+ Normalize("normal") +
12535
+ "MOV light, state.light[0].position;" +
12536
+ "DP3 ndotl.x, light, normal;" +
12537
+
12538
+ // shadow
12539
+ "MOV pos, fragment.texcoord[1];" +
12540
+ "MOV temp, pos;" +
12541
+ ShadowTextureFetch("depth", "temp", "1") +
12542
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12543
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12544
+
12545
+ // No shadow when out of frustum
12546
+ //"SGE temp.y, depth.z, zero123.y;" +
12547
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12548
+
12549
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12550
+
12551
+ // Backlit
12552
+ "MOV pos.w, zero123.y;" +
12553
+ "DP4 eye.x, pos, light2cam0;" +
12554
+ "DP4 eye.y, pos, light2cam1;" +
12555
+ "DP4 eye.z, pos, light2cam2;" +
12556
+ Normalize("eye") +
12557
+
12558
+ "DP3 ndotl.y, -eye, normal;" +
12559
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12560
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12561
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12562
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12563
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12564
+
12565
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12566
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12567
+
12568
+ // Pigment
12569
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12570
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12571
+ "MUL temp, temp, ndotl.x;" +
12572
+
12573
+ "MUL temp, temp, zero123.z;" +
12574
+
12575
+ //"MUL temp, temp, ndotl.y;" +
12576
+
12577
+ "MOV temp.w, zero123.y;" + // reset alpha
12578
+ "MOV result.color, temp;" +
12579
+ "END";
12580
+
12581
+ String programmax =
12582
+ "!!ARBfp1.0\n" +
12583
+
1108612584 //"OPTION ARB_fragment_program_shadow;" +
1108712585 "PARAM light2cam0 = program.env[10];" +
1108812586 "PARAM light2cam1 = program.env[11];" +
....@@ -11108,7 +12606,7 @@
1110812606 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1110912607 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1111012608 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11111
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12609
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1111212610 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1111312611 "PARAM options1 = program.env[62];" + // fog rgb color
1111412612 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -11197,8 +12695,7 @@
1119712695 "TEMP shininess;" +
1119812696 "\n" +
1119912697 "MOV texSamp, one;" +
11200
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11201
-
12698
+
1120212699 "MOV mapgrid.x, one2048th.x;" +
1120312700 "MOV temp, fragment.texcoord[1];" +
1120412701 /*
....@@ -11219,20 +12716,20 @@
1121912716 "MUL temp, floor, mapgrid.x;" +
1122012717 //"TEX depth0, temp, texture[1], 2D;" +
1122112718 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11222
- TextureFetch("depth0", "temp", "1") +
12719
+ ShadowTextureFetch("depth0", "temp", "1") +
1122312720 "") +
1122412721 "ADD temp.x, temp.x, mapgrid.x;" +
1122512722 //"TEX depth1, temp, texture[1], 2D;" +
1122612723 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11227
- TextureFetch("depth1", "temp", "1") +
12724
+ ShadowTextureFetch("depth1", "temp", "1") +
1122812725 "") +
1122912726 "ADD temp.y, temp.y, mapgrid.x;" +
1123012727 //"TEX depth2, temp, texture[1], 2D;" +
11231
- TextureFetch("depth2", "temp", "1") +
12728
+ ShadowTextureFetch("depth2", "temp", "1") +
1123212729 "SUB temp.x, temp.x, mapgrid.x;" +
1123312730 //"TEX depth3, temp, texture[1], 2D;" +
1123412731 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11235
- TextureFetch("depth3", "temp", "1") +
12732
+ ShadowTextureFetch("depth3", "temp", "1") +
1123612733 "") +
1123712734 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1123812735 //"MOV params, material;" +
....@@ -11354,7 +12851,7 @@
1135412851 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1135512852 // mar 2013 ??? "KIL alpha.a;" +
1135612853 "MOV alpha, texSamp.aaaa;" + // y;" +
11357
- "KIL alpha.a;" +
12854
+ "KIL alpha.a;" + // not sure with parallax mapping
1135812855 /*
1135912856 "MUL temp.xy, temp, two;" +
1136012857 "TXB bump, temp, texture[0], 2D;" +
....@@ -11440,11 +12937,6 @@
1144012937 "SUB bump0, bump0, half;" +
1144112938 "ADD bump, bump, bump0;" +
1144212939
11443
- "MOV temp.x, texSamp.a;" +
11444
- "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
11445
- //"LRP texSamp0, params5.x, texSamp0, one;" +
11446
- "MOV texSamp.a, temp.x;" +
11447
-
1144812940 // double-sided
1144912941 /**/
1145012942 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -11461,19 +12953,62 @@
1146112953 "MOV normald, normal;" +
1146212954 "MOV normals, normal;" +
1146312955
12956
+ "MOV temp, fragment.texcoord[4];" +
12957
+
1146412958 // UV base
1146512959 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1146612960 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1146712961 //"DP3 UP.z,state.matrix.modelview.row[2],Y;" +
11468
- "DP3 UP.x,state.matrix.texture[7].row[0],Y;" +
11469
- "DP3 UP.y,state.matrix.texture[7].row[1],Y;" +
11470
- "DP3 UP.z,state.matrix.texture[7].row[2],Y;" +
12962
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12963
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12964
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12965
+ Normalize("UP") +
12966
+
1147112967 "XPD V, normal, UP;" +
1147212968 Normalize("V") +
1147312969 "XPD U, V, normal;" +
1147412970 Normalize("U") +
1147512971
1147612972 // parallax mapping
12973
+
12974
+ "DP3 temp2.x, V, eye;" +
12975
+ "DP3 temp2.y, U, eye;" +
12976
+ "DP3 temp2.z, normal, eye;" +
12977
+ "RCP temp2.z, temp2.z;" +
12978
+
12979
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12980
+ "RSQ temp2.w, temp2.w;" +
12981
+ "RCP temp2.w, temp2.w;" +
12982
+
12983
+ "SUB temp2.w, temp2.w, half;" +
12984
+// "SGE temp.x, temp2.w, eps.x;" +
12985
+// "MUL temp2.w, temp2.w, temp.x;" +
12986
+
12987
+ //"MOV texSamp, U;" +
12988
+
12989
+ "MUL temp2.z, temp2.z, temp2.w;" +
12990
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
12991
+
12992
+ "MUL temp2, temp2, temp2.z;" +
12993
+
12994
+ "MOV temp, fragment.texcoord[0];" +
12995
+
12996
+ "SUB temp, temp, temp2;" +
12997
+
12998
+ "TEX temp, temp, texture[0], 2D;" +
12999
+ "POW temp.a, temp.a, params6.w;" + // punch through
13000
+
13001
+ "ADD texSamp, temp, texSamp;" +
13002
+ "MUL temp.xyz, half, texSamp;" +
13003
+
13004
+ "MOV alpha, texSamp.aaaa;" +
13005
+
13006
+// parallax mapping
13007
+
13008
+ "MOV temp.x, texSamp.a;" +
13009
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13010
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13011
+ "MOV texSamp.a, temp.x;" +
1147713012
1147813013 //"MOV temp, fragment.texcoord[0];" +
1147913014 //
....@@ -11603,10 +13138,10 @@
1160313138 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1160413139 "") +
1160513140
11606
- // display shadow only (bump == 0)
13141
+ // display shadow only (fakedepth == 0)
1160713142 "SUB temp.x, half.x, shadow.x;" +
11608
- "MOV temp.y, -params6.x;" +
11609
- "SLT temp.z, temp.y, zero.x;" +
13143
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13144
+ "SLT temp.z, temp.y, -c256i.x;" +
1161013145 "SUB temp.y, one.x, temp.z;" +
1161113146 "MUL temp.x, temp.x, temp.y;" +
1161213147 "KIL temp.x;" +
....@@ -11735,8 +13270,10 @@
1173513270 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1173613271
1173713272 "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
13273
+ // Tuning for default skin
13274
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13275
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13276
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1174013277 "MUL temp.x, temp.x, temp.y;" +
1174113278
1174213279 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11935,8 +13472,19 @@
1193513472 //once = true;
1193613473 }
1193713474
11938
- System.out.print("Program #" + mode + "; length = " + program.length());
11939
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13475
+ String program = programmax;
13476
+
13477
+ if (Globals.MINSHADER)
13478
+ {
13479
+ program = programmin;
13480
+ }
13481
+
13482
+ if (Globals.DEBUG)
13483
+ {
13484
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13485
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13486
+ }
13487
+
1194013488 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1194113489
1194213490 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -11983,7 +13531,8 @@
1198313531 "\n" +
1198413532 "END\n";
1198513533
11986
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13534
+ if (Globals.DEBUG)
13535
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1198713536 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1198813537
1198913538 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12028,25 +13577,26 @@
1202813577 return out;
1202913578 }
1203013579
12031
- String TextureFetch(String dest, String src, String unit)
13580
+ // Also does frustum culling
13581
+ String ShadowTextureFetch(String dest, String src, String unit)
1203213582 {
1203313583 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1203413584 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1203513585 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13586
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13587
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1203613588 "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;" +
13589
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13590
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1204113591 //"SWZ buffer, temp, w,w,w,w;";
12042
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13592
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1204313593 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1204413594 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1204513595 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12046
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13596
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1204713597
12048
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12049
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13598
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13599
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1205013600 }
1205113601
1205213602 String Shadow(String depth, String shadow)
....@@ -12068,12 +13618,16 @@
1206813618
1206913619 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1207013620 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13621
+
13622
+ // Compare fragment depth in light space with shadowmap.
1207113623 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1207213624 "SGE temp.y, temp.x, zero.x;" +
12073
- "SUB " + shadow + ".y, one.x, temp.y;" +
13625
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13626
+
13627
+ // Reverse comparison
1207413628 "SUB temp.x, one.x, temp.x;" +
1207513629 "MUL " + shadow + ".x, temp.x, temp.y;" +
12076
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13630
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1207713631 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1207813632
1207913633 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12087,6 +13641,10 @@
1208713641 // No shadow for backface
1208813642 "DP3 temp.x, normal, lightd;" +
1208913643 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13644
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13645
+
13646
+ // No shadow when out of frustum
13647
+ "SGE temp.x, " + depth + ".z, one.z;" +
1209013648 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1209113649 "";
1209213650 }
....@@ -12232,8 +13790,9 @@
1223213790 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1223313791 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1223413792 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
12235
- /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12236
- Object3D.cVector2[] vector2buffer;
13793
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13794
+
13795
+ //Object3D.cVector2[] vector2buffer;
1223713796
1223813797 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1223913798 // OUT : diff, spec
....@@ -12249,9 +13808,10 @@
1224913808 "DP3 " + dest + ".z," + "normals," + "eye;" +
1225013809 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1225113810 //"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;" +
13811
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13812
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13813
+
13814
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1225513815 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1225613816 "RCP " + dest + ".w," + dest + ".w;" +
1225713817 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -12397,7 +13957,7 @@
1239713957 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1239813958 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1239913959 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12400
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13960
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1240113961 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1240213962 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1240313963 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -12458,7 +14018,7 @@
1245814018 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1245914019 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1246014020 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
12461
- //"MOV result.texcoord, vertex.texcoord;" +
14021
+ //"MOV result.texcoord, vertex.fogcoord;" +
1246214022 "MOV result.texcoord, temp;" +
1246314023 // border fade
1246414024 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -12505,7 +14065,9 @@
1250514065
1250614066 //"ADD temp.z, temp.z, one;" +
1250714067
12508
- "MOV result.color, temp;"
14068
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14069
+
14070
+ "MOV result.color, temp;" // Normal
1250914071 : "MOV result.color, vertex.color;") +
1251014072 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1251114073 : "") +
....@@ -12645,7 +14207,7 @@
1264514207 public void mousePressed(MouseEvent e)
1264614208 {
1264714209 //System.out.println("mousePressed: " + e);
12648
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14210
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1264914211 }
1265014212
1265114213 static long prevtime = 0;
....@@ -12672,6 +14234,7 @@
1267214234
1267314235 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1267414236
14237
+ if (BUTTONLESSWHEEL)
1267514238 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1267614239 {
1267714240 return;
....@@ -12680,7 +14243,7 @@
1268014243 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1268114244
1268214245 // TIMER
12683
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14246
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1268414247 {
1268514248 keepboxmode = BOXMODE;
1268614249 keepsupport = SUPPORT;
....@@ -12720,8 +14283,8 @@
1272014283 // mode |= META;
1272114284 //}
1272214285
12723
- SetMouseMode(WHEEL | e.getModifiersEx());
12724
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14286
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14287
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1272514288 anchorX = ax;
1272614289 anchorY = ay;
1272714290 prevX = px;
....@@ -12755,6 +14318,7 @@
1275514318 else
1275614319 if (evt.getSource() == AAtimer)
1275714320 {
14321
+ Globals.TIMERRUNNING = false;
1275814322 if (mouseDown)
1275914323 {
1276014324 //new Exception().printStackTrace();
....@@ -12780,6 +14344,10 @@
1278014344 // LIVE = waslive;
1278114345 // wasliveok = true;
1278214346 // waslive = false;
14347
+
14348
+ // May 2019 Forget it:
14349
+ if (true)
14350
+ return;
1278314351
1278414352 // source == timer
1278514353 if (mouseDown)
....@@ -12810,7 +14378,7 @@
1281014378
1281114379 // fev 2014???
1281214380 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
12813
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14381
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1281414382 pingthread.StepToTarget(true); // true);
1281514383 }
1281614384 // if (!LIVE)
....@@ -12819,12 +14387,13 @@
1281914387
1282014388 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1282114389
12822
- void clickStart(int x, int y, int modifiers)
14390
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1282314391 {
1282414392 if (!wasliveok)
1282514393 return;
1282614394
1282714395 AAtimer.restart(); //
14396
+ Globals.TIMERRUNNING = true;
1282814397
1282914398 // waslive = LIVE;
1283014399 // LIVE = false;
....@@ -12836,7 +14405,7 @@
1283614405 // touched = true; // main DL
1283714406 if (isRenderer)
1283814407 {
12839
- SetMouseMode(modifiers);
14408
+ SetMouseMode(modifiers, modifiersex);
1284014409 }
1284114410
1284214411 selectX = anchorX = x;
....@@ -12849,7 +14418,7 @@
1284914418 clicked = true;
1285014419 hold = false;
1285114420
12852
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14421
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1285314422 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1285414423 {
1285514424 // System.out.println("RESTART II " + modifiers);
....@@ -12874,14 +14443,15 @@
1287414443 drag = false;
1287514444 //System.out.println("Mouse DOWN");
1287614445 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);
14446
+ //ClickInfo info = new ClickInfo();
14447
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14448
+ object.clickInfo.pane = this;
14449
+ object.clickInfo.camera = renderCamera;
14450
+ object.clickInfo.x = x;
14451
+ object.clickInfo.y = y;
14452
+ object.clickInfo.modifiers = modifiersex;
14453
+ editObj = object.doEditClick(//info,
14454
+ 0);
1288514455 if (!editObj)
1288614456 {
1288714457 hasMarquee = true;
....@@ -12897,11 +14467,14 @@
1289714467
1289814468 public void mouseDragged(MouseEvent e)
1289914469 {
14470
+ Globals.MOUSEDRAGGED = true;
14471
+
14472
+ //System.out.println("mouseDragged: " + e);
1290014473 if (isRenderer)
1290114474 movingcamera = true;
14475
+
1290214476 //if (drawing)
1290314477 //return;
12904
- //System.out.println("mouseDragged: " + e);
1290514478 if ((e.getModifiersEx() & CTRL) != 0
1290614479 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1290714480 {
....@@ -12909,7 +14482,7 @@
1290914482 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1291014483 }
1291114484 else
12912
- drag(e.getX(), e.getY(), e.getModifiersEx());
14485
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1291314486
1291414487 //try { Thread.sleep(1); } catch (Exception ex) {}
1291514488 }
....@@ -12921,6 +14494,11 @@
1292114494 cVector tmp = new cVector();
1292214495 cVector tmp2 = new cVector();
1292314496 boolean isMoving;
14497
+
14498
+ public cVector TargetLookAt()
14499
+ {
14500
+ return targetLookAt;
14501
+ }
1292414502
1292514503 class PingThread extends Thread
1292614504 {
....@@ -13077,6 +14655,7 @@
1307714655
1307814656 public void run()
1307914657 {
14658
+ new Exception().printStackTrace();
1308014659 System.exit(0);
1308114660 for (;;)
1308214661 {
....@@ -13140,7 +14719,7 @@
1314014719 {
1314114720 Globals.lighttouched = true;
1314214721 }
13143
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14722
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1314414723 }
1314514724 //else
1314614725 }
....@@ -13154,12 +14733,18 @@
1315414733 void GoDown(int mod)
1315514734 {
1315614735 MODIFIERS |= COMMAND;
13157
- /*
14736
+ boolean isVR = (mouseMode&VR)!=0;
14737
+ /**/
1315814738 if((mod&SHIFT) == SHIFT)
13159
- manipCamera.RotatePosition(0, -speed);
14739
+ {
14740
+ if (isVR)
14741
+ manipCamera.RotateInterest(0, -speed);
14742
+ else
14743
+ manipCamera.RotatePosition(0, -speed);
14744
+ }
1316014745 else
13161
- manipCamera.BackForth(0, -speed*delta, getWidth());
13162
- */
14746
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14747
+ /**/
1316314748 if ((mod & SHIFT) == SHIFT)
1316414749 {
1316514750 mouseMode = mouseMode; // VR??
....@@ -13168,6 +14753,8 @@
1316814753 mouseMode |= BACKFORTH;
1316914754 }
1317014755
14756
+ targetLookAt.set(manipCamera.lookAt);
14757
+
1317114758 //prevX = X = anchorX;
1317214759 prevY = Y = anchorY - (int) (renderCamera.Distance());
1317314760 }
....@@ -13175,12 +14762,19 @@
1317514762 void GoUp(int mod)
1317614763 {
1317714764 MODIFIERS |= COMMAND;
13178
- /*
14765
+ /**/
14766
+ boolean isVR = (mouseMode&VR)!=0;
14767
+
1317914768 if((mod&SHIFT) == SHIFT)
13180
- manipCamera.RotatePosition(0, speed);
14769
+ {
14770
+ if (isVR)
14771
+ manipCamera.RotateInterest(0, speed);
14772
+ else
14773
+ manipCamera.RotatePosition(0, speed);
14774
+ }
1318114775 else
13182
- manipCamera.BackForth(0, speed*delta, getWidth());
13183
- */
14776
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14777
+ /**/
1318414778 if ((mod & SHIFT) == SHIFT)
1318514779 {
1318614780 mouseMode = mouseMode;
....@@ -13189,6 +14783,8 @@
1318914783 mouseMode |= BACKFORTH;
1319014784 }
1319114785
14786
+ targetLookAt.set(manipCamera.lookAt);
14787
+
1319214788 //prevX = X = anchorX;
1319314789 prevY = Y = anchorY + (int) (renderCamera.Distance());
1319414790 }
....@@ -13196,12 +14792,17 @@
1319614792 void GoLeft(int mod)
1319714793 {
1319814794 MODIFIERS |= COMMAND;
13199
- /*
14795
+ /**/
1320014796 if((mod&SHIFT) == SHIFT)
13201
- manipCamera.RotatePosition(speed, 0);
14797
+ manipCamera.Translate(speed*delta, 0, getWidth());
1320214798 else
13203
- manipCamera.Translate(speed*delta, 0, getWidth());
13204
- */
14799
+ {
14800
+ if ((mouseMode&VR)!=0)
14801
+ manipCamera.RotateInterest(-speed, 0);
14802
+ else
14803
+ manipCamera.RotatePosition(speed, 0);
14804
+ }
14805
+ /**/
1320514806 if ((mod & SHIFT) == SHIFT)
1320614807 {
1320714808 mouseMode = mouseMode;
....@@ -13210,6 +14811,8 @@
1321014811 mouseMode |= ROTATE;
1321114812 } // TRANSLATE;
1321214813
14814
+ targetLookAt.set(manipCamera.lookAt);
14815
+
1321314816 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1321414817 prevY = Y = anchorY;
1321514818 }
....@@ -13217,12 +14820,18 @@
1321714820 void GoRight(int mod)
1321814821 {
1321914822 MODIFIERS |= COMMAND;
13220
- /*
14823
+ /**/
1322114824 if((mod&SHIFT) == SHIFT)
13222
- manipCamera.RotatePosition(-speed, 0);
14825
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1322314826 else
13224
- manipCamera.Translate(-speed*delta, 0, getWidth());
13225
- */
14827
+ {
14828
+ if ((mouseMode&VR)!=0)
14829
+ manipCamera.RotateInterest(speed, 0);
14830
+ else
14831
+ manipCamera.RotatePosition(-speed, 0);
14832
+ }
14833
+
14834
+ /**/
1322614835 if ((mod & SHIFT) == SHIFT)
1322714836 {
1322814837 mouseMode = mouseMode;
....@@ -13231,6 +14840,8 @@
1323114840 mouseMode |= ROTATE;
1323214841 } // TRANSLATE;
1323314842
14843
+ targetLookAt.set(manipCamera.lookAt);
14844
+
1323414845 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1323514846 prevY = Y = anchorY;
1323614847 }
....@@ -13240,7 +14851,7 @@
1324014851 int X, Y;
1324114852 boolean SX, SY;
1324214853
13243
- void drag(int x, int y, int modifiers)
14854
+ void drag(int x, int y, int modifiers, int modifiersex)
1324414855 {
1324514856 if (IsFrozen())
1324614857 {
....@@ -13249,17 +14860,17 @@
1324914860
1325014861 drag = true; // NEW
1325114862
13252
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14863
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1325314864
1325414865 X = x;
1325514866 Y = y;
1325614867 // floating state for animation
13257
- MODIFIERS = modifiers;
13258
- modifiers &= ~1024;
14868
+ MODIFIERS = modifiersex;
14869
+ modifiersex &= ~1024;
1325914870 if (false) // modifiers != 0)
1326014871 {
1326114872 //new Exception().printStackTrace();
13262
- System.out.println("mouseDragged: " + modifiers);
14873
+ System.out.println("mouseDragged: " + modifiersex);
1326314874 System.out.println("SHIFT = " + SHIFT);
1326414875 System.out.println("CONTROL = " + COMMAND);
1326514876 System.out.println("META = " + META);
....@@ -13272,14 +14883,16 @@
1327214883 if (editObj)
1327314884 {
1327414885 drag = true;
13275
- ClickInfo info = new ClickInfo();
13276
- info.bounds.setBounds(0, 0,
14886
+ //ClickInfo info = new ClickInfo();
14887
+ object.clickInfo.bounds.setBounds(0, 0,
1327714888 (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);
14889
+ object.clickInfo.pane = this;
14890
+ object.clickInfo.camera = renderCamera;
14891
+ object.clickInfo.x = x;
14892
+ object.clickInfo.y = y;
14893
+ object //.GetWindow().copy
14894
+ .doEditDrag(//info,
14895
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1328314896 } else
1328414897 {
1328514898 if (x < startX)
....@@ -13428,23 +15041,27 @@
1342815041 }
1342915042 }
1343015043
15044
+// ClickInfo clickInfo = new ClickInfo();
15045
+
1343115046 public void mouseMoved(MouseEvent e)
1343215047 {
1343315048 //System.out.println("mouseMoved: " + e);
13434
-
1343515049 if (isRenderer)
1343615050 return;
1343715051
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;
15052
+ // Mouse cursor feedback
15053
+ object.clickInfo.x = e.getX();
15054
+ object.clickInfo.y = e.getY();
15055
+ object.clickInfo.modifiers = e.getModifiersEx();
15056
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15057
+ object.clickInfo.pane = this;
15058
+ object.clickInfo.camera = renderCamera;
1344515059 if (!isRenderer)
1344615060 {
13447
- if (object.editWindow.copy.doEditClick(ci, 0))
15061
+ //ObjEditor editWindow = object.editWindow;
15062
+ //Object3D copy = editWindow.copy;
15063
+ if (object.doEditClick(//clickInfo,
15064
+ 0))
1344815065 {
1344915066 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1345015067 } else
....@@ -13456,7 +15073,11 @@
1345615073
1345715074 public void mouseReleased(MouseEvent e)
1345815075 {
15076
+ Globals.MOUSEDRAGGED = false;
15077
+
1345915078 movingcamera = false;
15079
+ X = 0; // getBounds().width/2;
15080
+ Y = 0; // getBounds().height/2;
1346015081 //System.out.println("mouseReleased: " + e);
1346115082 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1346215083 }
....@@ -13479,9 +15100,9 @@
1347915100 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1348015101 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1348115102
13482
- if (control || command || IsFrozen())
15103
+// No delay if (control || command || IsFrozen())
1348315104 timeout = true;
13484
- else
15105
+// ?? May 2019 else
1348515106 // timer.setDelay((modifiers & 128) != 0?0:350);
1348615107 mouseDown = false;
1348715108 if (!control && !command) // june 2013
....@@ -13591,7 +15212,7 @@
1359115212 System.out.println("keyReleased: " + e);
1359215213 }
1359315214
13594
- void SetMouseMode(int modifiers)
15215
+ void SetMouseMode(int modifiers, int modifiersex)
1359515216 {
1359615217 //System.out.println("SetMouseMode = " + modifiers);
1359715218 //modifiers &= ~1024;
....@@ -13603,25 +15224,25 @@
1360315224 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1360415225 // return;
1360515226 //System.out.println("SetMode = " + modifiers);
13606
- if ((modifiers & WHEEL) == WHEEL)
15227
+ if ((modifiersex & WHEEL) == WHEEL)
1360715228 {
1360815229 mouseMode |= ZOOM;
1360915230 }
1361015231
1361115232 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
13612
- if (capsLocked || (modifiers & META) == META)
15233
+ if (capsLocked) // || (modifiers & META) == META)
1361315234 {
1361415235 mouseMode |= VR; // BACKFORTH;
1361515236 }
13616
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15237
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1361715238 {
1361815239 mouseMode |= SELECT;
1361915240 }
13620
- if ((modifiers & COMMAND) == COMMAND)
15241
+ if ((modifiersex & COMMAND) == COMMAND)
1362115242 {
1362215243 mouseMode |= SELECT;
1362315244 }
13624
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15245
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1362515246 {
1362615247 mouseMode &= ~VR;
1362715248 mouseMode |= TRANSLATE;
....@@ -13650,10 +15271,10 @@
1365015271
1365115272 if (isRenderer) //
1365215273 {
13653
- SetMouseMode(modifiers);
15274
+ SetMouseMode(0, modifiers);
1365415275 }
1365515276
13656
- theRenderer.keyPressed(key);
15277
+ Globals.theRenderer.keyPressed(key);
1365715278 }
1365815279
1365915280 int kompactbit = 4; // power bit
....@@ -13665,7 +15286,7 @@
1366515286 float SATPOW = 1; // 2; // 0.5f;
1366615287 float BRIPOW = 1; // 0.5f; // 0.5f;
1366715288
13668
- void keyPressed(int key)
15289
+ public void keyPressed(int key)
1366915290 {
1367015291 if (key >= '0' && key <= '5')
1367115292 clampbit = (key-'0');
....@@ -13712,7 +15333,8 @@
1371215333 // break;
1371315334 case 'T':
1371415335 CACHETEXTURE ^= true;
13715
- textures.clear();
15336
+ texturepigment.clear();
15337
+ texturebump.clear();
1371615338 // repaint();
1371715339 break;
1371815340 case 'Y':
....@@ -13722,8 +15344,8 @@
1372215344 case 'K':
1372315345 KOMPACTTEXTURE ^= true;
1372415346 //textures.clear();
13725
- break;
13726
- case 'P': // Texture Projection macros
15347
+ // break;
15348
+ //case 'P': // Texture Projection macros
1372715349 // SAVETEXTURE ^= true;
1372815350 macromode = true;
1372915351 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -13797,7 +15419,9 @@
1379715419 case 'E' : COMPACT ^= true;
1379815420 repaint();
1379915421 break;
13800
- case 'W' : DEBUGHSB ^= true;
15422
+ case 'W' : // Wide Window (fullscreen)
15423
+ //DEBUGHSB ^= true;
15424
+ ObjEditor.theFrame.ToggleFullScreen();
1380115425 repaint();
1380215426 break;
1380315427 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13822,8 +15446,8 @@
1382215446 RevertCamera();
1382315447 repaint();
1382415448 break;
13825
- case 'L':
1382615449 case 'l':
15450
+ //case 'L':
1382715451 if (lightMode)
1382815452 {
1382915453 lightMode = false;
....@@ -13842,7 +15466,7 @@
1384215466 targetLookAt.set(manipCamera.lookAt);
1384315467 repaint();
1384415468 break;
13845
- case 'p':
15469
+ case 'P': // p':
1384615470 // c'est quoi ca au juste? spherical ^= true;
1384715471 Skinshader ^= true; programInitialized = false;
1384815472 repaint();
....@@ -13887,20 +15511,24 @@
1388715511 OCCLUSION_CULLING ^= true;
1388815512 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1388915513 break;
13890
- case '0': envyoff ^= true; repaint(); break;
15514
+ //case '0': envyoff ^= true; repaint(); break;
1389115515 case '1':
1389215516 case '2':
1389315517 case '3':
1389415518 case '4':
1389515519 case '5':
13896
- newenvy = Character.getNumericValue(key);
13897
- repaint();
13898
- break;
1389915520 case '6':
1390015521 case '7':
1390115522 case '8':
1390215523 case '9':
13903
- BGcolor = (key - '6')/3.f;
15524
+ if (true) // envyoff)
15525
+ {
15526
+ BGcolor = (key - '1')/8.f;
15527
+ }
15528
+ else
15529
+ {
15530
+ //newenvy = Character.getNumericValue(key);
15531
+ }
1390415532 repaint();
1390515533 break;
1390615534 case '!':
....@@ -13966,9 +15594,9 @@
1396615594 case '_':
1396715595 kompactbit = 5;
1396815596 break;
13969
- case '+':
13970
- kompactbit = 6;
13971
- break;
15597
+// case '+':
15598
+// kompactbit = 6;
15599
+// break;
1397215600 case ' ':
1397315601 lightMode ^= true;
1397415602 Globals.lighttouched = true;
....@@ -13980,13 +15608,14 @@
1398015608 case ESC:
1398115609 RENDERPROGRAM += 1;
1398215610 RENDERPROGRAM %= 3;
15611
+
1398315612 repaint();
1398415613 break;
1398515614 case 'Z':
1398615615 //RESIZETEXTURE ^= true;
1398715616 //break;
1398815617 case 'z':
13989
- RENDERSHADOW ^= true;
15618
+ Globals.RENDERSHADOW ^= true;
1399015619 Globals.lighttouched = true;
1399115620 repaint();
1399215621 break;
....@@ -14019,8 +15648,9 @@
1401915648 case DELETE:
1402015649 ClearSelection();
1402115650 break;
14022
- /*
1402315651 case '+':
15652
+
15653
+ /*
1402415654 //fontsize += 1;
1402515655 bbzoom *= 2;
1402615656 repaint();
....@@ -14037,17 +15667,17 @@
1403715667 case '=':
1403815668 IncDepth();
1403915669 //fontsize += 1;
14040
- object.editWindow.refreshContents(true);
15670
+ object.GetWindow().refreshContents(true);
1404115671 maskbit = 6;
1404215672 break;
1404315673 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1404415674 DecDepth();
1404515675 maskbit = 5;
1404615676 //if(fontsize > 1) fontsize -= 1;
14047
- if (object.editWindow == null)
14048
- new Exception().printStackTrace();
14049
- else
14050
- object.editWindow.refreshContents(true);
15677
+// if (object.editWindow == null)
15678
+// new Exception().printStackTrace();
15679
+// else
15680
+ object.GetWindow().refreshContents(true);
1405115681 break;
1405215682 case '{':
1405315683 manipCamera.shaper_fovy /= 1.1;
....@@ -14102,6 +15732,7 @@
1410215732 }
1410315733 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1410415734 }
15735
+
1410515736 static double OCCLUSIONBOOST = 1; // 0.5;
1410615737
1410715738 void keyReleased(int key, int modifiers)
....@@ -14109,11 +15740,11 @@
1410915740 //mode = ROTATE;
1411015741 if ((MODIFIERS & COMMAND) == 0) // VR??
1411115742 {
14112
- SetMouseMode(modifiers);
15743
+ SetMouseMode(0, modifiers);
1411315744 }
1411415745 }
1411515746
14116
- protected void processKeyEvent(KeyEvent e)
15747
+ public void processKeyEvent(KeyEvent e)
1411715748 {
1411815749 switch (e.getID())
1411915750 {
....@@ -14243,8 +15874,9 @@
1424315874
1424415875 protected void processMouseMotionEvent(MouseEvent e)
1424515876 {
14246
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14247
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15877
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15878
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15879
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1424815880 {
1424915881 mouseMoved(e);
1425015882 } else
....@@ -14269,11 +15901,12 @@
1426915901 }
1427015902 */
1427115903
14272
- object.editWindow.EditSelection();
15904
+ object.GetWindow().EditSelection(false);
1427315905 }
1427415906
1427515907 void SelectParent()
1427615908 {
15909
+ new Exception().printStackTrace();
1427715910 System.exit(0);
1427815911 Composite group = (Composite) object;
1427915912 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14285,10 +15918,10 @@
1428515918 {
1428615919 //selectees.remove(i);
1428715920 System.out.println("select parent of " + elem);
14288
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15921
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1428915922 } else
1429015923 {
14291
- group.editWindow.Select(elem.GetTreePath(), first, true);
15924
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1429215925 }
1429315926
1429415927 first = false;
....@@ -14297,6 +15930,7 @@
1429715930
1429815931 void SelectChildren()
1429915932 {
15933
+ new Exception().printStackTrace();
1430015934 System.exit(0);
1430115935 /*
1430215936 Composite group = (Composite) object;
....@@ -14329,12 +15963,12 @@
1432915963 for (int j = 0; j < group.children.size(); j++)
1433015964 {
1433115965 elem = (Object3D) group.children.elementAt(j);
14332
- object.editWindow.Select(elem.GetTreePath(), first, true);
15966
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1433315967 first = false;
1433415968 }
1433515969 } else
1433615970 {
14337
- object.editWindow.Select(elem.GetTreePath(), first, true);
15971
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1433815972 }
1433915973
1434015974 first = false;
....@@ -14345,21 +15979,21 @@
1434515979 {
1434615980 //Composite group = (Composite) object;
1434715981 Object3D group = object;
14348
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15982
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1434915983 }
1435015984
1435115985 void ResetTransform(int mask)
1435215986 {
1435315987 //Composite group = (Composite) object;
1435415988 Object3D group = object;
14355
- group.editWindow.ResetTransform(mask);
15989
+ group.GetWindow().ResetTransform(mask);
1435615990 }
1435715991
1435815992 void FlipTransform()
1435915993 {
1436015994 //Composite group = (Composite) object;
1436115995 Object3D group = object;
14362
- group.editWindow.FlipTransform();
15996
+ group.GetWindow().FlipTransform();
1436315997 // group.editWindow.ReduceMesh(true);
1436415998 }
1436515999
....@@ -14367,7 +16001,7 @@
1436716001 {
1436816002 //Composite group = (Composite) object;
1436916003 Object3D group = object;
14370
- group.editWindow.PrintMemory();
16004
+ group.GetWindow().PrintMemory();
1437116005 // group.editWindow.ReduceMesh(true);
1437216006 }
1437316007
....@@ -14375,7 +16009,7 @@
1437516009 {
1437616010 //Composite group = (Composite) object;
1437716011 Object3D group = object;
14378
- group.editWindow.ResetCentroid();
16012
+ group.GetWindow().ResetCentroid();
1437916013 }
1438016014
1438116015 void IncDepth()
....@@ -14457,11 +16091,11 @@
1445716091
1445816092 int width = getBounds().width;
1445916093 int height = getBounds().height;
14460
- ClickInfo info = new ClickInfo();
14461
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1446216094 //Image img = CreateImage(width, height);
1446316095 //System.out.println("width = " + width + "; height = " + height + "\n");
16096
+
1446416097 Graphics gr = g; // img.getGraphics();
16098
+
1446516099 if (!hasMarquee)
1446616100 {
1446716101 if (Xmin < Xmax) // !locked)
....@@ -14533,44 +16167,92 @@
1453316167 }
1453416168 if (object != null && !hasMarquee)
1453516169 {
16170
+ if (object.clickInfo == null)
16171
+ object.clickInfo = new ClickInfo();
16172
+ ClickInfo info = object.clickInfo;
16173
+ //ClickInfo info = new ClickInfo();
16174
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16175
+
1453616176 if (isRenderer)
1453716177 {
14538
- info.flags++;
16178
+ object.clickInfo.flags++;
1453916179 double frameAspect = (double) width / (double) height;
1454016180 if (frameAspect > renderCamera.aspect)
1454116181 {
1454216182 int desired = (int) ((double) height * renderCamera.aspect);
14543
- info.bounds.width -= width - desired;
14544
- info.bounds.x += (width - desired) / 2;
16183
+ object.clickInfo.bounds.width -= width - desired;
16184
+ object.clickInfo.bounds.x += (width - desired) / 2;
1454516185 } else
1454616186 {
1454716187 int desired = (int) ((double) width / renderCamera.aspect);
14548
- info.bounds.height -= height - desired;
14549
- info.bounds.y += (height - desired) / 2;
16188
+ object.clickInfo.bounds.height -= height - desired;
16189
+ object.clickInfo.bounds.y += (height - desired) / 2;
1455016190 }
1455116191 }
14552
- info.g = gr;
14553
- info.camera = renderCamera;
16192
+
16193
+ object.clickInfo.g = gr;
16194
+ object.clickInfo.camera = renderCamera;
1455416195 /*
1455516196 // Memory intensive (brep.verticescopy)
1455616197 if (!(object instanceof Composite))
1455716198 object.draw(info, 0, false); // SLOW :
1455816199 */
14559
- if (!isRenderer)
16200
+ if (!isRenderer) // && drag)
1456016201 {
14561
- object.drawEditHandles(info, 0);
16202
+ Grafreed.Assert(object != null);
16203
+ Grafreed.Assert(object.selection != null);
16204
+ if (object.selection.Size() > 0)
16205
+ {
16206
+ int hitSomething = object.selection.get(0).hitSomething;
16207
+
16208
+ object.clickInfo.DX = 0;
16209
+ object.clickInfo.DY = 0;
16210
+ object.clickInfo.W = 1;
16211
+ if (hitSomething == Object3D.hitCenter)
16212
+ {
16213
+ info.DX = X;
16214
+ if (X != 0)
16215
+ info.DX -= info.bounds.width/2;
16216
+
16217
+ info.DY = Y;
16218
+ if (Y != 0)
16219
+ info.DY -= info.bounds.height/2;
16220
+ }
16221
+
16222
+ object.drawEditHandles(//info,
16223
+ 0);
16224
+
16225
+ if (drag && (X != 0 || Y != 0))
16226
+ {
16227
+ switch (hitSomething)
16228
+ {
16229
+ case Object3D.hitCenter: gr.setColor(Color.white);
16230
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16231
+ break;
16232
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16233
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16234
+ break;
16235
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16236
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16237
+ break;
16238
+ }
16239
+
16240
+ }
16241
+ }
1456216242 }
1456316243 }
16244
+
1456416245 if (isRenderer)
1456516246 {
1456616247 //gr.setColor(Color.black);
1456716248 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1456816249 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1456916250 }
16251
+
1457016252 if (hasMarquee)
1457116253 {
1457216254 gr.setXORMode(Color.white);
14573
- gr.setColor(Color.red);
16255
+ gr.setColor(Color.white);
1457416256 if (!firstime)
1457516257 {
1457616258 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -14679,6 +16361,7 @@
1467916361 public boolean mouseDown(Event evt, int x, int y)
1468016362 {
1468116363 System.out.println("mouseDown: " + evt);
16364
+ System.exit(0);
1468216365 /*
1468316366 locked = true;
1468416367 drag = false;
....@@ -14722,7 +16405,7 @@
1472216405 {
1472316406 keyPressed(0, modifiers);
1472416407 }
14725
- clickStart(x, y, modifiers);
16408
+ // clickStart(x, y, modifiers);
1472616409 return true;
1472716410 }
1472816411
....@@ -14840,7 +16523,7 @@
1484016523 {
1484116524 keyReleased(0, 0);
1484216525 }
14843
- drag(x, y, modifiers);
16526
+ drag(x, y, 0, modifiers);
1484416527 return true;
1484516528 }
1484616529
....@@ -14972,7 +16655,7 @@
1497216655 Object3D object;
1497316656 static Object3D trackedobject;
1497416657 Camera renderCamera; // Light or Eye (or Occlusion)
14975
- /*static*/ Camera manipCamera; // Light or Eye
16658
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1497616659 /*static*/ Camera eyeCamera;
1497716660 /*static*/ Camera lightCamera;
1497816661 int cameracount;
....@@ -15036,6 +16719,8 @@
1503616719 private /*static*/ boolean firstime;
1503716720 private /*static*/ cVector newView = new cVector();
1503816721 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16722
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16723
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1503916724 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1504016725 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1504116726 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15048,29 +16733,67 @@
1504816733 {
1504916734 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1505016735
16736
+ int usedsuf = 0;
16737
+
1505116738 for (int i = 0; i < suffixes.length; i++)
1505216739 {
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)
16740
+ String[] suffixe = suffixes;
16741
+ String[] fallback = suffixes2;
16742
+ String[] fallfallback = suffixes3;
16743
+
16744
+ for (int c=usedsuf; --c>=0;)
1505816745 {
15059
- throw new IOException("Unable to load texture " + resourceName);
16746
+// String[] temp = suffixe;
16747
+// suffixe = fallback;
16748
+// fallback = fallfallback;
16749
+// fallfallback = temp;
1506016750 }
16751
+
16752
+ String resourceName = basename + suffixe[i] + "." + suffix;
16753
+ TextureData data;
16754
+
16755
+ try
16756
+ {
16757
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16758
+ mipmapped,
16759
+ FileUtil.getFileSuffix(resourceName));
16760
+ }
16761
+ catch (Exception e)
16762
+ {
16763
+ try
16764
+ {
16765
+ resourceName = basename + fallback[i] + "." + suffix;
16766
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16767
+ mipmapped,
16768
+ FileUtil.getFileSuffix(resourceName));
16769
+ }
16770
+ catch (Exception e2)
16771
+ {
16772
+ resourceName = basename + fallfallback[i] + "." + suffix;
16773
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16774
+ mipmapped,
16775
+ FileUtil.getFileSuffix(resourceName));
16776
+ }
16777
+ }
16778
+
1506116779 //System.out.println("Target = " + targets[i]);
1506216780 cubemap.updateImage(data, targets[i]);
1506316781 }
1506416782
1506516783 return cubemap;
1506616784 }
16785
+
1506716786 int bigsphere = -1;
1506816787
1506916788 float BGcolor = 0.5f;
1507016789
15071
- private void DrawSkyBox(GL gl)
16790
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16791
+
16792
+ private void DrawSkyBox(GL gl, float ratio)
1507216793 {
15073
- if (envyoff || cubemap == null)
16794
+ if (//envyoff ||
16795
+ WIREFRAME ||
16796
+ cubemap == null)
1507416797 {
1507516798 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1507616799 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15085,7 +16808,17 @@
1508516808 // Compensates for ExaminerViewer's modification of modelview matrix
1508616809 gl.glMatrixMode(GL.GL_MODELVIEW);
1508716810 gl.glLoadIdentity();
16811
+ gl.glScalef(1,ratio,1);
1508816812
16813
+// colorV[0] = 2;
16814
+// colorV[1] = 2;
16815
+// colorV[2] = 2;
16816
+// colorV[3] = 1;
16817
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16818
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16819
+//
16820
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16821
+
1508916822 //gl.glActiveTexture(GL.GL_TEXTURE1);
1509016823 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1509116824
....@@ -15117,6 +16850,7 @@
1511716850 {
1511816851 gl.glScalef(1.0f, -1.0f, 1.0f);
1511916852 }
16853
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1512016854 gl.glMultMatrixd(viewrot_1, 0);
1512116855 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1512216856 //viewer.updateInverseRotation(gl);
....@@ -15157,7 +16891,8 @@
1515716891 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1515816892
1515916893 cubemap.disable();
15160
- ////cubemap.unbind();
16894
+ //cubemap.dispose();
16895
+
1516116896 if (CULLFACE)
1516216897 {
1516316898 gl.glEnable(gl.GL_CULL_FACE);
....@@ -15213,7 +16948,7 @@
1521316948 gl.glScalef(1.0f, -1.0f, 1.0f);
1521416949 }
1521516950
15216
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16951
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1521716952
1521816953 float step = 2; // 0.1666f; //0.25f;
1521916954 float stepv = 2; // step * 1652 / 998;
....@@ -15257,16 +16992,16 @@
1525716992 cStatic.objectstack[materialdepth++] = checker;
1525816993 //System.out.println("material " + material);
1525916994 //Applet3D.tracein(this, selected);
15260
- vector2buffer = checker.projectedVertices;
16995
+ //vector2buffer = checker.projectedVertices;
1526116996
1526216997 //checker.GetMaterial().Draw(this, false); // true);
15263
- DrawMaterial(checker.GetMaterial(), false); // true);
16998
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1526416999
1526517000 materialdepth -= 1;
1526617001 if (materialdepth > 0)
1526717002 {
15268
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15269
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
17003
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17004
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1527017005 }
1527117006 //checker.GetMaterial().opacity = 1f;
1527217007 ////checker.GetMaterial().ambient = 1f;
....@@ -15352,6 +17087,14 @@
1535217087 }
1535317088 }
1535417089
17090
+ private Object3D GetFolder()
17091
+ {
17092
+ Object3D folder = object.GetWindow().copy;
17093
+ if (object.GetWindow().copy.selection.Size() > 0)
17094
+ folder = object.GetWindow().copy.selection.elementAt(0);
17095
+ return folder;
17096
+ }
17097
+
1535517098 class SelectBuffer implements GLEventListener
1535617099 {
1535717100
....@@ -15367,7 +17110,7 @@
1536717110 //new Exception().printStackTrace();
1536817111 System.out.println("select buffer init");
1536917112 // Use debug pipeline
15370
- drawable.setGL(new DebugGL(drawable.getGL()));
17113
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1537117114
1537217115 GL gl = drawable.getGL();
1537317116
....@@ -15410,6 +17153,7 @@
1541017153 {
1541117154 if (!selection)
1541217155 {
17156
+ new Exception().printStackTrace();
1541317157 System.exit(0);
1541417158 return;
1541517159 }
....@@ -15430,6 +17174,17 @@
1543017174
1543117175 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1543217176
17177
+ if (PAINTMODE)
17178
+ {
17179
+ if (object.GetWindow().copy.selection.Size() > 0)
17180
+ {
17181
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17182
+
17183
+ // Make what you paint not selectable.
17184
+ paintobj.ResetSelectable();
17185
+ }
17186
+ }
17187
+
1543317188 //int tmp = selection_view;
1543417189 //selection_view = -1;
1543517190 int temp = DrawMode();
....@@ -15441,6 +17196,17 @@
1544117196 // temp = DEFAULT; // patch for selection debug
1544217197 Globals.drawMode = temp; // WARNING
1544317198
17199
+ if (PAINTMODE)
17200
+ {
17201
+ if (object.GetWindow().copy.selection.Size() > 0)
17202
+ {
17203
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17204
+
17205
+ // Revert.
17206
+ paintobj.RestoreSelectable();
17207
+ }
17208
+ }
17209
+
1544417210 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1544517211
1544617212 // trying different ways of getting the depth info over
....@@ -15488,6 +17254,8 @@
1548817254 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1548917255 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1549017256 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17257
+
17258
+ CreateSelectedPoint();
1549117259
1549217260 // Will fit the mesh !!!
1549317261 selectedpoint.toParent[0][0] = 0.0001;
....@@ -15537,34 +17305,36 @@
1553717305 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]));
1553817306 }
1553917307
15540
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17308
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1554117309 }
1554217310 }
1554317311
1554417312 if (!movingcamera && !PAINTMODE)
15545
- object.editWindow.ScreenFitPoint(); // fev 2014
17313
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1554617314
15547
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17315
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1554817316 {
15549
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17317
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1555017318
15551
- Object3D group = new Object3D("inst" + paintcount++);
17319
+ if (object.GetWindow().copy.selection.Size() > 0)
17320
+ {
17321
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1555217322
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();
17323
+ Object3D inst = new Object3D("inst" + paintcount++);
17324
+
17325
+ inst.CreateMaterial(); // use a void leaf to select instances
17326
+
17327
+ inst.add(paintobj); // link
17328
+
17329
+ object.GetWindow().SnapObject(inst);
17330
+
17331
+ Object3D folder = paintFolder; // GetFolder();
17332
+
17333
+ folder.add(inst);
17334
+
17335
+ object.GetWindow().ResetModel();
17336
+ object.GetWindow().refreshContents();
17337
+ }
1556817338 }
1556917339 else
1557017340 paintcount = 0;
....@@ -15603,6 +17373,11 @@
1560317373 //System.out.println("objects[color] = " + objects[color]);
1560417374 //objects[color].Select();
1560517375 indexcount = 0;
17376
+ ObjEditor window = object.GetWindow();
17377
+ if (window != null && deselect)
17378
+ {
17379
+ window.Select(null, deselect, true);
17380
+ }
1560617381 object.Select(color, deselect);
1560717382 }
1560817383
....@@ -15653,6 +17428,7 @@
1565317428
1565417429 public void init(GLAutoDrawable drawable)
1565517430 {
17431
+ if (Globals.DEBUG)
1565617432 System.out.println("shadow buffer init");
1565717433
1565817434 GL gl = drawable.getGL();
....@@ -15702,7 +17478,7 @@
1570217478 gl.glDisable(gl.GL_CULL_FACE);
1570317479 }
1570417480
15705
- if (!RENDERSHADOW)
17481
+ if (!Globals.RENDERSHADOW)
1570617482 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1570717483
1570817484 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -15712,7 +17488,7 @@
1571217488 //gl.glColorMask(false, false, false, false);
1571317489
1571417490 //render_scene_from_light_view(gl, drawable, 0, 0);
15715
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17491
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1571617492 {
1571717493 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1571817494
....@@ -15772,7 +17548,6 @@
1577217548
1577317549 class AntialiasBuffer implements GLEventListener
1577417550 {
15775
-
1577617551 CameraPane parent = null;
1577717552
1577817553 AntialiasBuffer(CameraPane p)
....@@ -15882,10 +17657,14 @@
1588217657 gl.glFlush();
1588317658
1588417659 /**/
15885
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17660
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1588617661
15887
- float[] pixels = occlusionsizebuffer.array();
17662
+ float[] depths = occlusiondepthbuffer.array();
1588817663
17664
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17665
+
17666
+ int[] pixels = selectsizebuffer.array();
17667
+
1588917668 double r = 0, g = 0, b = 0;
1589017669
1589117670 double count = 0;
....@@ -15896,7 +17675,7 @@
1589617675
1589717676 double FACTOR = 1;
1589817677
15899
- for (int i = 0; i < pixels.length; i++)
17678
+ for (int i = 0; i < depths.length; i++)
1590017679 {
1590117680 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1590217681 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15979,7 +17758,7 @@
1597917758
1598017759 double scale = ray.z; // 1; // cos
1598117760
15982
- float depth = pixels[newindex];
17761
+ float depth = depths[newindex];
1598317762
1598417763 /*
1598517764 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16129,23 +17908,15 @@
1612917908 int AAbuffersize = 0;
1613017909
1613117910 //double[] selectedpoint = new double[3];
16132
- static Superellipsoid selectedpoint = new Superellipsoid();
17911
+ static Superellipsoid selectedpoint;
1613317912 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();
17913
+ static Sphere debugpointG;
17914
+ static Sphere debugpointP;
17915
+ static Sphere debugpointC;
17916
+ static Sphere debugpointR;
1613817917
1613917918 static Sphere debugpoints[] = new Sphere[8];
1614017919
16141
- static
16142
- {
16143
- for (int i=0; i<8; i++)
16144
- {
16145
- debugpoints[i] = new Sphere();
16146
- }
16147
- }
16148
-
1614917920 static void InitPoints(float radius)
1615017921 {
1615117922 for (int i=0; i<8; i++)
....@@ -16165,7 +17936,7 @@
1616517936 }
1616617937 }
1616717938
16168
- static void DrawPoints(CameraPane cpane)
17939
+ static void DrawPoints(iCameraPane cpane)
1616917940 {
1617017941 for (int i=0; i<8; i++) // first and last are red
1617117942 {
....@@ -16184,11 +17955,14 @@
1618417955 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1618517956 static IntBuffer bigAAbuffer;
1618617957 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
16187
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17958
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1618817959 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1618917960 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1619017961 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
16191
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17962
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17963
+
17964
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17965
+
1619217966 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1619317967 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1619417968 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -16197,10 +17971,11 @@
1619717971 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1619817972 // Depth buffer format
1619917973 //private int depth_format;
16200
- static public void NextIndex(Object3D o, GL gl)
17974
+
17975
+ public void NextIndex()
1620117976 {
1620217977 indexcount+=16;
16203
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17978
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1620417979 //objects[indexcount] = o;
1620517980 //System.out.println("indexcount = " + indexcount);
1620617981 }