Normand Briere
2019-08-26 6266c8a4b2485b29a7d5bcb217460d7aad3e1c4a
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 localAOcamera = 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 = localAOcamera;
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
+ localAOcamera.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
+ localAOcamera.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,82 @@
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 zero12t = { 0.0, 1.0, 2, 1.25 };" +
12518
+ "PARAM pow_2 = { 0.5, 0.25, 0.125, 0.0 };" +
12519
+ "PARAM pow2 = { 2, 4, 8, 0.0 };" +
12520
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12521
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12522
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12523
+ "PARAM light2cam0 = program.env[10];" +
12524
+ "PARAM light2cam1 = program.env[11];" +
12525
+ "PARAM light2cam2 = program.env[12];" +
12526
+ "TEMP temp;" +
12527
+ "TEMP light;" +
12528
+ "TEMP ndotl;" +
12529
+ "TEMP normal;" +
12530
+ "TEMP depth;" +
12531
+ "TEMP eye;" +
12532
+ "TEMP pos;" +
12533
+
12534
+ "MAD normal, fragment.color, zero12t.z, -zero12t.y;" +
12535
+ Normalize("normal") +
12536
+ "MOV light, state.light[0].position;" +
12537
+ "DP3 ndotl.x, light, normal;" +
12538
+ "MAX ndotl.x, ndotl.x, zero12t.x;" +
12539
+
12540
+ // shadow
12541
+ "MOV pos, fragment.texcoord[1];" +
12542
+ "MOV temp, pos;" +
12543
+ ShadowTextureFetch("depth", "temp", "1") +
12544
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12545
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12546
+
12547
+ // No shadow when out of frustum
12548
+ //"SGE temp.y, depth.z, zero123.y;" +
12549
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12550
+
12551
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12552
+
12553
+ // Backlit
12554
+ "MOV pos.w, zero12t.y;" + // one
12555
+ "DP4 eye.x, pos, light2cam0;" +
12556
+ "DP4 eye.y, pos, light2cam1;" +
12557
+ "DP4 eye.z, pos, light2cam2;" +
12558
+ Normalize("eye") +
12559
+
12560
+ "DP3 ndotl.y, -eye, normal;" +
12561
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12562
+ "POW ndotl.y, ndotl.y, pow2.x;" + // backlit
12563
+ "SUB ndotl.y, zero12t.y, ndotl.y;" + // 1 - y
12564
+ //"POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12565
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12566
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12567
+ "ADD ndotl.y, ndotl.y, one.x;" +
12568
+ "MUL ndotl.y, ndotl.y, pow_2.x;" +
12569
+
12570
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12571
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12572
+
12573
+ // Pigment
12574
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12575
+ "LRP temp, zero12t.w, temp, one;" + // texture proportion
12576
+ "MUL temp, temp, zero12t.w;" + // Times x
12577
+
12578
+ //"MUL temp, temp, ndotl.y;" +
12579
+ "MAD ndotl.x, pow_2.xxxx, ndotl.yyyy, ndotl.x;" +
12580
+
12581
+ "MUL temp, temp, ndotl.x;" + // lambert
12582
+
12583
+ "MOV temp.w, zero12t.y;" + // reset alpha
12584
+ "MOV result.color, temp;" +
12585
+ "END";
12586
+
12587
+ String programmax =
12588
+ "!!ARBfp1.0\n" +
12589
+
1108612590 //"OPTION ARB_fragment_program_shadow;" +
1108712591 "PARAM light2cam0 = program.env[10];" +
1108812592 "PARAM light2cam1 = program.env[11];" +
....@@ -11108,7 +12612,7 @@
1110812612 "PARAM params4 = program.env[4];" + // anisoV, cameralight, selfshadow, shadow
1110912613 "PARAM params5 = program.env[5];" + // texture, opacity, fakedepth, shadowbias
1111012614 "PARAM params6 = program.env[6];" + // bump, noise, borderfade, fog punchthrough
11111
- "PARAM params7 = program.env[7];" + // noise power, opacity power
12615
+ "PARAM params7 = program.env[7];" + // noise power, opacity power, parallax
1111212616 "PARAM options0 = program.env[63];" + // fog density, intensity, elevation
1111312617 "PARAM options1 = program.env[62];" + // fog rgb color
1111412618 "PARAM options2 = program.env[61];" + // image intensity, subsurface, lightsheen
....@@ -11197,8 +12701,7 @@
1119712701 "TEMP shininess;" +
1119812702 "\n" +
1119912703 "MOV texSamp, one;" +
11200
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11201
-
12704
+
1120212705 "MOV mapgrid.x, one2048th.x;" +
1120312706 "MOV temp, fragment.texcoord[1];" +
1120412707 /*
....@@ -11219,20 +12722,20 @@
1121912722 "MUL temp, floor, mapgrid.x;" +
1122012723 //"TEX depth0, temp, texture[1], 2D;" +
1122112724 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11222
- TextureFetch("depth0", "temp", "1") +
12725
+ ShadowTextureFetch("depth0", "temp", "1") +
1122312726 "") +
1122412727 "ADD temp.x, temp.x, mapgrid.x;" +
1122512728 //"TEX depth1, temp, texture[1], 2D;" +
1122612729 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11227
- TextureFetch("depth1", "temp", "1") +
12730
+ ShadowTextureFetch("depth1", "temp", "1") +
1122812731 "") +
1122912732 "ADD temp.y, temp.y, mapgrid.x;" +
1123012733 //"TEX depth2, temp, texture[1], 2D;" +
11231
- TextureFetch("depth2", "temp", "1") +
12734
+ ShadowTextureFetch("depth2", "temp", "1") +
1123212735 "SUB temp.x, temp.x, mapgrid.x;" +
1123312736 //"TEX depth3, temp, texture[1], 2D;" +
1123412737 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11235
- TextureFetch("depth3", "temp", "1") +
12738
+ ShadowTextureFetch("depth3", "temp", "1") +
1123612739 "") +
1123712740 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1123812741 //"MOV params, material;" +
....@@ -11354,7 +12857,7 @@
1135412857 "POW texSamp.a, texSamp.a, params6.w;" + // fog punch through shortcut
1135512858 // mar 2013 ??? "KIL alpha.a;" +
1135612859 "MOV alpha, texSamp.aaaa;" + // y;" +
11357
- "KIL alpha.a;" +
12860
+ "KIL alpha.a;" + // not sure with parallax mapping
1135812861 /*
1135912862 "MUL temp.xy, temp, two;" +
1136012863 "TXB bump, temp, texture[0], 2D;" +
....@@ -11440,11 +12943,6 @@
1144012943 "SUB bump0, bump0, half;" +
1144112944 "ADD bump, bump, bump0;" +
1144212945
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
-
1144812946 // double-sided
1144912947 /**/
1145012948 (doublesided?"DP3 temp.z, normal, eye;" +
....@@ -11454,26 +12952,73 @@
1145412952 "ADD temp.x, temp.x, one.x;" +
1145512953 "MUL normal, normal, temp.xxxx;":""
1145612954 ) +
11457
- /**/
11458
-//// Normalize("normal") +
11459
-//// "MAX normal.z, eps.x, normal.z;" +
11460
-// Normalize("normal") +
11461
- "MOV normald, normal;" +
11462
- "MOV normals, normal;" +
12955
+ /**/
12956
+
12957
+ "MOV temp, fragment.texcoord[4];" +
1146312958
1146412959 // UV base
1146512960 //"DP3 UP.x,state.matrix.modelview.row[0],Y;" +
1146612961 //"DP3 UP.y,state.matrix.modelview.row[1],Y;" +
1146712962 //"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;" +
12963
+ "DP3 UP.x,state.matrix.texture[7].row[0],temp;" +
12964
+ "DP3 UP.y,state.matrix.texture[7].row[1],temp;" +
12965
+ "DP3 UP.z,state.matrix.texture[7].row[2],temp;" +
12966
+ Normalize("UP") +
12967
+
1147112968 "XPD V, normal, UP;" +
1147212969 Normalize("V") +
1147312970 "XPD U, V, normal;" +
1147412971 Normalize("U") +
1147512972
12973
+ "MOV temp, fragment.texcoord[0];" +
12974
+
12975
+// "MAD normal, -temp.x, U, normal;" +
12976
+// "MAD normal, -temp.y, V, normal;" +
12977
+// Normalize("normal") +
12978
+
12979
+//// "MAX normal.z, eps.x, normal.z;" +
12980
+// Normalize("normal") +
12981
+ "MOV normald, normal;" +
12982
+ "MOV normals, normal;" +
12983
+
1147612984 // parallax mapping
12985
+
12986
+ "DP3 temp2.x, V, eye;" +
12987
+ "DP3 temp2.y, U, eye;" +
12988
+ "DP3 temp2.z, normal, eye;" +
12989
+ "RCP temp2.z, temp2.z;" +
12990
+
12991
+ "DP3 temp2.w, texSamp, texSamp;" + // Height
12992
+ "RSQ temp2.w, temp2.w;" +
12993
+ "RCP temp2.w, temp2.w;" +
12994
+
12995
+ "SUB temp2.w, temp2.w, half;" +
12996
+ // "SGE temp.x, temp2.w, eps.x;" +
12997
+ // "MUL temp2.w, temp2.w, temp.x;" +
12998
+
12999
+ // "MOV texSamp, U;" +
13000
+
13001
+ "MUL temp2.z, temp2.z, temp2.w;" +
13002
+ "MUL temp2.z, temp2.z, params7.z;" + // parallax
13003
+
13004
+ "MUL temp2, temp2, temp2.z;" +
13005
+
13006
+ "SUB temp, temp, temp2;" +
13007
+
13008
+ "TEX temp, temp, texture[0], 2D;" +
13009
+ "POW temp.a, temp.a, params6.w;" + // punch through
13010
+
13011
+ "ADD texSamp, temp, texSamp;" +
13012
+ "MUL texSamp.xyz, half, texSamp;" +
13013
+
13014
+ "MOV alpha, texSamp.aaaa;" +
13015
+
13016
+// parallax mapping
13017
+
13018
+ "MOV temp.x, texSamp.a;" +
13019
+ "LRP texSamp, params5.x, texSamp, one;" + // texture proportion
13020
+ //"LRP texSamp0, params5.x, texSamp0, one;" +
13021
+ "MOV texSamp.a, temp.x;" +
1147713022
1147813023 //"MOV temp, fragment.texcoord[0];" +
1147913024 //
....@@ -11603,10 +13148,10 @@
1160313148 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1160413149 "") +
1160513150
11606
- // display shadow only (bump == 0)
13151
+ // display shadow only (fakedepth == 0)
1160713152 "SUB temp.x, half.x, shadow.x;" +
11608
- "MOV temp.y, -params6.x;" +
11609
- "SLT temp.z, temp.y, zero.x;" +
13153
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13154
+ "SLT temp.z, temp.y, -c256i.x;" +
1161013155 "SUB temp.y, one.x, temp.z;" +
1161113156 "MUL temp.x, temp.x, temp.y;" +
1161213157 "KIL temp.x;" +
....@@ -11735,8 +13280,10 @@
1173513280 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1173613281
1173713282 "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
13283
+ // Tuning for default skin
13284
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13285
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13286
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1174013287 "MUL temp.x, temp.x, temp.y;" +
1174113288
1174213289 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11935,8 +13482,19 @@
1193513482 //once = true;
1193613483 }
1193713484
11938
- System.out.print("Program #" + mode + "; length = " + program.length());
11939
- System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13485
+ String program = programmax;
13486
+
13487
+ if (Globals.MINSHADER)
13488
+ {
13489
+ program = programmin;
13490
+ }
13491
+
13492
+ if (Globals.DEBUG)
13493
+ {
13494
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
13495
+ System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
13496
+ }
13497
+
1194013498 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1194113499
1194213500 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -11983,7 +13541,8 @@
1198313541 "\n" +
1198413542 "END\n";
1198513543
11986
- System.out.println("Program shadow #" + 0 + "; length = " + program.length());
13544
+ if (Globals.DEBUG)
13545
+ System.out.println("Program shadow #" + 0 + "; length = " + program.length());
1198713546 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1198813547
1198913548 //gl.glNewList(displayListID, GL.GL_COMPILE);
....@@ -12028,25 +13587,26 @@
1202813587 return out;
1202913588 }
1203013589
12031
- String TextureFetch(String dest, String src, String unit)
13590
+ // Also does frustum culling
13591
+ String ShadowTextureFetch(String dest, String src, String unit)
1203213592 {
1203313593 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1203413594 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1203513595 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13596
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13597
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1203613598 "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;" +
13599
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13600
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1204113601 //"SWZ buffer, temp, w,w,w,w;";
12042
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13602
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1204313603 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1204413604 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1204513605 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12046
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13606
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1204713607
12048
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12049
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13608
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13609
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1205013610 }
1205113611
1205213612 String Shadow(String depth, String shadow)
....@@ -12068,12 +13628,16 @@
1206813628
1206913629 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1207013630 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13631
+
13632
+ // Compare fragment depth in light space with shadowmap.
1207113633 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1207213634 "SGE temp.y, temp.x, zero.x;" +
12073
- "SUB " + shadow + ".y, one.x, temp.y;" +
13635
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13636
+
13637
+ // Reverse comparison
1207413638 "SUB temp.x, one.x, temp.x;" +
1207513639 "MUL " + shadow + ".x, temp.x, temp.y;" +
12076
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13640
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1207713641 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1207813642
1207913643 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12087,6 +13651,10 @@
1208713651 // No shadow for backface
1208813652 "DP3 temp.x, normal, lightd;" +
1208913653 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13654
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13655
+
13656
+ // No shadow when out of frustum
13657
+ "SGE temp.x, " + depth + ".z, one.z;" +
1209013658 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1209113659 "";
1209213660 }
....@@ -12232,8 +13800,9 @@
1223213800 /*static*/ float[] modelParams4 = new float[]{0, 0, 0, 0}; // anisoV, cameralight, selfshadow, shadow
1223313801 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1223413802 /*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;
13803
+ /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power, parallax
13804
+
13805
+ //Object3D.cVector2[] vector2buffer;
1223713806
1223813807 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1223913808 // OUT : diff, spec
....@@ -12249,9 +13818,10 @@
1224913818 "DP3 " + dest + ".z," + "normals," + "eye;" +
1225013819 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1225113820 //"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;" +
13821
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13822
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13823
+
13824
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1225513825 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1225613826 "RCP " + dest + ".w," + dest + ".w;" +
1225713827 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -12397,7 +13967,7 @@
1239713967 "PARAM p[4] = { state.matrix.projection }; # modelview projection matrix\n" +
1239813968 "PARAM zero = { 0.0, 0.0, 0.0, 1.0 };" +
1239913969 "PARAM half = { 0.5, 0.5, 0.5, 1.0 };" +
12400
- "PARAM one = { 1.0, 1.0, 1.0, 0.0 };" +
13970
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
1240113971 "PARAM two = { 2.0, 2.0, 2.0, 1.0 };" +
1240213972 "PARAM third = { 0.33333333333, 0.33333333333, 0.33333333333, 1.0 };" +
1240313973 //"PARAM v256 = { 256.0, 256.0, 256.0, 1.0 };" +
....@@ -12458,7 +14028,7 @@
1245814028 "DP4 temp.x,state.matrix.texture[0].inverse.row[0],vertex.texcoord;" +
1245914029 "DP4 temp.y,state.matrix.texture[0].inverse.row[1],vertex.texcoord;" +
1246014030 "DP4 temp.z,state.matrix.texture[0].inverse.row[2],vertex.texcoord;" +
12461
- //"MOV result.texcoord, vertex.texcoord;" +
14031
+ //"MOV result.texcoord, vertex.fogcoord;" +
1246214032 "MOV result.texcoord, temp;" +
1246314033 // border fade
1246414034 "MOV result.texcoord[3], vertex.texcoord;" +
....@@ -12505,7 +14075,9 @@
1250514075
1250614076 //"ADD temp.z, temp.z, one;" +
1250714077
12508
- "MOV result.color, temp;"
14078
+ "MOV result.texcoord[4], vertex.attrib[4];" + // U dir
14079
+
14080
+ "MOV result.color, temp;" // Normal
1250914081 : "MOV result.color, vertex.color;") +
1251014082 ((mode & VP_PROJECTION) != 0 ? "MOV result.color, zero;"
1251114083 : "") +
....@@ -12645,7 +14217,7 @@
1264514217 public void mousePressed(MouseEvent e)
1264614218 {
1264714219 //System.out.println("mousePressed: " + e);
12648
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14220
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1264914221 }
1265014222
1265114223 static long prevtime = 0;
....@@ -12672,6 +14244,7 @@
1267214244
1267314245 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1267414246
14247
+ if (BUTTONLESSWHEEL)
1267514248 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1267614249 {
1267714250 return;
....@@ -12680,7 +14253,7 @@
1268014253 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1268114254
1268214255 // TIMER
12683
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14256
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1268414257 {
1268514258 keepboxmode = BOXMODE;
1268614259 keepsupport = SUPPORT;
....@@ -12720,8 +14293,8 @@
1272014293 // mode |= META;
1272114294 //}
1272214295
12723
- SetMouseMode(WHEEL | e.getModifiersEx());
12724
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14296
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14297
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1272514298 anchorX = ax;
1272614299 anchorY = ay;
1272714300 prevX = px;
....@@ -12755,6 +14328,7 @@
1275514328 else
1275614329 if (evt.getSource() == AAtimer)
1275714330 {
14331
+ Globals.TIMERRUNNING = false;
1275814332 if (mouseDown)
1275914333 {
1276014334 //new Exception().printStackTrace();
....@@ -12780,6 +14354,10 @@
1278014354 // LIVE = waslive;
1278114355 // wasliveok = true;
1278214356 // waslive = false;
14357
+
14358
+ // May 2019 Forget it:
14359
+ if (true)
14360
+ return;
1278314361
1278414362 // source == timer
1278514363 if (mouseDown)
....@@ -12810,7 +14388,7 @@
1281014388
1281114389 // fev 2014???
1281214390 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
12813
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14391
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1281414392 pingthread.StepToTarget(true); // true);
1281514393 }
1281614394 // if (!LIVE)
....@@ -12819,12 +14397,13 @@
1281914397
1282014398 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1282114399
12822
- void clickStart(int x, int y, int modifiers)
14400
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1282314401 {
1282414402 if (!wasliveok)
1282514403 return;
1282614404
1282714405 AAtimer.restart(); //
14406
+ Globals.TIMERRUNNING = true;
1282814407
1282914408 // waslive = LIVE;
1283014409 // LIVE = false;
....@@ -12836,7 +14415,7 @@
1283614415 // touched = true; // main DL
1283714416 if (isRenderer)
1283814417 {
12839
- SetMouseMode(modifiers);
14418
+ SetMouseMode(modifiers, modifiersex);
1284014419 }
1284114420
1284214421 selectX = anchorX = x;
....@@ -12849,7 +14428,7 @@
1284914428 clicked = true;
1285014429 hold = false;
1285114430
12852
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14431
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1285314432 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1285414433 {
1285514434 // System.out.println("RESTART II " + modifiers);
....@@ -12874,14 +14453,15 @@
1287414453 drag = false;
1287514454 //System.out.println("Mouse DOWN");
1287614455 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);
14456
+ //ClickInfo info = new ClickInfo();
14457
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14458
+ object.clickInfo.pane = this;
14459
+ object.clickInfo.camera = renderCamera;
14460
+ object.clickInfo.x = x;
14461
+ object.clickInfo.y = y;
14462
+ object.clickInfo.modifiers = modifiersex;
14463
+ editObj = object.doEditClick(//info,
14464
+ 0);
1288514465 if (!editObj)
1288614466 {
1288714467 hasMarquee = true;
....@@ -12897,11 +14477,14 @@
1289714477
1289814478 public void mouseDragged(MouseEvent e)
1289914479 {
14480
+ Globals.MOUSEDRAGGED = true;
14481
+
14482
+ //System.out.println("mouseDragged: " + e);
1290014483 if (isRenderer)
1290114484 movingcamera = true;
14485
+
1290214486 //if (drawing)
1290314487 //return;
12904
- //System.out.println("mouseDragged: " + e);
1290514488 if ((e.getModifiersEx() & CTRL) != 0
1290614489 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1290714490 {
....@@ -12909,7 +14492,7 @@
1290914492 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1291014493 }
1291114494 else
12912
- drag(e.getX(), e.getY(), e.getModifiersEx());
14495
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1291314496
1291414497 //try { Thread.sleep(1); } catch (Exception ex) {}
1291514498 }
....@@ -12921,6 +14504,11 @@
1292114504 cVector tmp = new cVector();
1292214505 cVector tmp2 = new cVector();
1292314506 boolean isMoving;
14507
+
14508
+ public cVector TargetLookAt()
14509
+ {
14510
+ return targetLookAt;
14511
+ }
1292414512
1292514513 class PingThread extends Thread
1292614514 {
....@@ -13077,6 +14665,7 @@
1307714665
1307814666 public void run()
1307914667 {
14668
+ new Exception().printStackTrace();
1308014669 System.exit(0);
1308114670 for (;;)
1308214671 {
....@@ -13140,26 +14729,32 @@
1314014729 {
1314114730 Globals.lighttouched = true;
1314214731 }
13143
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14732
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1314414733 }
1314514734 //else
1314614735 }
1314714736 }
1314814737 }
1314914738 PingThread pingthread = new PingThread();
13150
- int delta = 5;
13151
- int speed = 5;
14739
+ int delta = 2;
14740
+ int speed = 10;
1315214741 boolean autorepeat = false;
1315314742
1315414743 void GoDown(int mod)
1315514744 {
1315614745 MODIFIERS |= COMMAND;
13157
- /*
14746
+ boolean isVR = (mouseMode&VR)!=0;
14747
+ /**/
1315814748 if((mod&SHIFT) == SHIFT)
13159
- manipCamera.RotatePosition(0, -speed);
14749
+ {
14750
+ if (isVR)
14751
+ manipCamera.RotateInterest(0, -speed);
14752
+ else
14753
+ manipCamera.RotatePosition(0, -speed);
14754
+ }
1316014755 else
13161
- manipCamera.BackForth(0, -speed*delta, getWidth());
13162
- */
14756
+ manipCamera.BackForth(0, -speed*delta, isVR?1000:0); // getWidth());
14757
+ /**/
1316314758 if ((mod & SHIFT) == SHIFT)
1316414759 {
1316514760 mouseMode = mouseMode; // VR??
....@@ -13168,6 +14763,8 @@
1316814763 mouseMode |= BACKFORTH;
1316914764 }
1317014765
14766
+ targetLookAt.set(manipCamera.lookAt);
14767
+
1317114768 //prevX = X = anchorX;
1317214769 prevY = Y = anchorY - (int) (renderCamera.Distance());
1317314770 }
....@@ -13175,12 +14772,19 @@
1317514772 void GoUp(int mod)
1317614773 {
1317714774 MODIFIERS |= COMMAND;
13178
- /*
14775
+ /**/
14776
+ boolean isVR = (mouseMode&VR)!=0;
14777
+
1317914778 if((mod&SHIFT) == SHIFT)
13180
- manipCamera.RotatePosition(0, speed);
14779
+ {
14780
+ if (isVR)
14781
+ manipCamera.RotateInterest(0, speed);
14782
+ else
14783
+ manipCamera.RotatePosition(0, speed);
14784
+ }
1318114785 else
13182
- manipCamera.BackForth(0, speed*delta, getWidth());
13183
- */
14786
+ manipCamera.BackForth(0, speed*delta, isVR?1000:0); // getWidth());
14787
+ /**/
1318414788 if ((mod & SHIFT) == SHIFT)
1318514789 {
1318614790 mouseMode = mouseMode;
....@@ -13189,6 +14793,8 @@
1318914793 mouseMode |= BACKFORTH;
1319014794 }
1319114795
14796
+ targetLookAt.set(manipCamera.lookAt);
14797
+
1319214798 //prevX = X = anchorX;
1319314799 prevY = Y = anchorY + (int) (renderCamera.Distance());
1319414800 }
....@@ -13196,12 +14802,17 @@
1319614802 void GoLeft(int mod)
1319714803 {
1319814804 MODIFIERS |= COMMAND;
13199
- /*
14805
+ /**/
1320014806 if((mod&SHIFT) == SHIFT)
13201
- manipCamera.RotatePosition(speed, 0);
14807
+ manipCamera.Translate(speed*delta, 0, getWidth());
1320214808 else
13203
- manipCamera.Translate(speed*delta, 0, getWidth());
13204
- */
14809
+ {
14810
+ if ((mouseMode&VR)!=0)
14811
+ manipCamera.RotateInterest(-speed, 0);
14812
+ else
14813
+ manipCamera.RotatePosition(speed, 0);
14814
+ }
14815
+ /**/
1320514816 if ((mod & SHIFT) == SHIFT)
1320614817 {
1320714818 mouseMode = mouseMode;
....@@ -13210,6 +14821,8 @@
1321014821 mouseMode |= ROTATE;
1321114822 } // TRANSLATE;
1321214823
14824
+ targetLookAt.set(manipCamera.lookAt);
14825
+
1321314826 prevX = X = anchorX - 10; // (int)(10*renderCamera.Distance());
1321414827 prevY = Y = anchorY;
1321514828 }
....@@ -13217,12 +14830,18 @@
1321714830 void GoRight(int mod)
1321814831 {
1321914832 MODIFIERS |= COMMAND;
13220
- /*
14833
+ /**/
1322114834 if((mod&SHIFT) == SHIFT)
13222
- manipCamera.RotatePosition(-speed, 0);
14835
+ manipCamera.Translate(-speed*delta, 0, getWidth());
1322314836 else
13224
- manipCamera.Translate(-speed*delta, 0, getWidth());
13225
- */
14837
+ {
14838
+ if ((mouseMode&VR)!=0)
14839
+ manipCamera.RotateInterest(speed, 0);
14840
+ else
14841
+ manipCamera.RotatePosition(-speed, 0);
14842
+ }
14843
+
14844
+ /**/
1322614845 if ((mod & SHIFT) == SHIFT)
1322714846 {
1322814847 mouseMode = mouseMode;
....@@ -13231,6 +14850,8 @@
1323114850 mouseMode |= ROTATE;
1323214851 } // TRANSLATE;
1323314852
14853
+ targetLookAt.set(manipCamera.lookAt);
14854
+
1323414855 prevX = X = anchorX + 10; // (int)(10*renderCamera.Distance());
1323514856 prevY = Y = anchorY;
1323614857 }
....@@ -13240,7 +14861,7 @@
1324014861 int X, Y;
1324114862 boolean SX, SY;
1324214863
13243
- void drag(int x, int y, int modifiers)
14864
+ void drag(int x, int y, int modifiers, int modifiersex)
1324414865 {
1324514866 if (IsFrozen())
1324614867 {
....@@ -13249,17 +14870,17 @@
1324914870
1325014871 drag = true; // NEW
1325114872
13252
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14873
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1325314874
1325414875 X = x;
1325514876 Y = y;
1325614877 // floating state for animation
13257
- MODIFIERS = modifiers;
13258
- modifiers &= ~1024;
14878
+ MODIFIERS = modifiersex;
14879
+ modifiersex &= ~1024;
1325914880 if (false) // modifiers != 0)
1326014881 {
1326114882 //new Exception().printStackTrace();
13262
- System.out.println("mouseDragged: " + modifiers);
14883
+ System.out.println("mouseDragged: " + modifiersex);
1326314884 System.out.println("SHIFT = " + SHIFT);
1326414885 System.out.println("CONTROL = " + COMMAND);
1326514886 System.out.println("META = " + META);
....@@ -13272,14 +14893,16 @@
1327214893 if (editObj)
1327314894 {
1327414895 drag = true;
13275
- ClickInfo info = new ClickInfo();
13276
- info.bounds.setBounds(0, 0,
14896
+ //ClickInfo info = new ClickInfo();
14897
+ object.clickInfo.bounds.setBounds(0, 0,
1327714898 (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);
14899
+ object.clickInfo.pane = this;
14900
+ object.clickInfo.camera = renderCamera;
14901
+ object.clickInfo.x = x;
14902
+ object.clickInfo.y = y;
14903
+ object //.GetWindow().copy
14904
+ .doEditDrag(//info,
14905
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1328314906 } else
1328414907 {
1328514908 if (x < startX)
....@@ -13428,23 +15051,27 @@
1342815051 }
1342915052 }
1343015053
15054
+// ClickInfo clickInfo = new ClickInfo();
15055
+
1343115056 public void mouseMoved(MouseEvent e)
1343215057 {
1343315058 //System.out.println("mouseMoved: " + e);
13434
-
1343515059 if (isRenderer)
1343615060 return;
1343715061
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;
15062
+ // Mouse cursor feedback
15063
+ object.clickInfo.x = e.getX();
15064
+ object.clickInfo.y = e.getY();
15065
+ object.clickInfo.modifiers = e.getModifiersEx();
15066
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
15067
+ object.clickInfo.pane = this;
15068
+ object.clickInfo.camera = renderCamera;
1344515069 if (!isRenderer)
1344615070 {
13447
- if (object.editWindow.copy.doEditClick(ci, 0))
15071
+ //ObjEditor editWindow = object.editWindow;
15072
+ //Object3D copy = editWindow.copy;
15073
+ if (object.doEditClick(//clickInfo,
15074
+ 0))
1344815075 {
1344915076 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1345015077 } else
....@@ -13456,7 +15083,11 @@
1345615083
1345715084 public void mouseReleased(MouseEvent e)
1345815085 {
15086
+ Globals.MOUSEDRAGGED = false;
15087
+
1345915088 movingcamera = false;
15089
+ X = 0; // getBounds().width/2;
15090
+ Y = 0; // getBounds().height/2;
1346015091 //System.out.println("mouseReleased: " + e);
1346115092 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1346215093 }
....@@ -13479,9 +15110,9 @@
1347915110 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1348015111 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1348115112
13482
- if (control || command || IsFrozen())
15113
+// No delay if (control || command || IsFrozen())
1348315114 timeout = true;
13484
- else
15115
+// ?? May 2019 else
1348515116 // timer.setDelay((modifiers & 128) != 0?0:350);
1348615117 mouseDown = false;
1348715118 if (!control && !command) // june 2013
....@@ -13591,7 +15222,7 @@
1359115222 System.out.println("keyReleased: " + e);
1359215223 }
1359315224
13594
- void SetMouseMode(int modifiers)
15225
+ void SetMouseMode(int modifiers, int modifiersex)
1359515226 {
1359615227 //System.out.println("SetMouseMode = " + modifiers);
1359715228 //modifiers &= ~1024;
....@@ -13603,25 +15234,25 @@
1360315234 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1360415235 // return;
1360515236 //System.out.println("SetMode = " + modifiers);
13606
- if ((modifiers & WHEEL) == WHEEL)
15237
+ if ((modifiersex & WHEEL) == WHEEL)
1360715238 {
1360815239 mouseMode |= ZOOM;
1360915240 }
1361015241
1361115242 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
13612
- if (capsLocked || (modifiers & META) == META)
15243
+ if (capsLocked) // || (modifiers & META) == META)
1361315244 {
1361415245 mouseMode |= VR; // BACKFORTH;
1361515246 }
13616
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15247
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1361715248 {
1361815249 mouseMode |= SELECT;
1361915250 }
13620
- if ((modifiers & COMMAND) == COMMAND)
15251
+ if ((modifiersex & COMMAND) == COMMAND)
1362115252 {
1362215253 mouseMode |= SELECT;
1362315254 }
13624
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15255
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1362515256 {
1362615257 mouseMode &= ~VR;
1362715258 mouseMode |= TRANSLATE;
....@@ -13650,10 +15281,10 @@
1365015281
1365115282 if (isRenderer) //
1365215283 {
13653
- SetMouseMode(modifiers);
15284
+ SetMouseMode(0, modifiers);
1365415285 }
1365515286
13656
- theRenderer.keyPressed(key);
15287
+ Globals.theRenderer.keyPressed(key);
1365715288 }
1365815289
1365915290 int kompactbit = 4; // power bit
....@@ -13665,7 +15296,7 @@
1366515296 float SATPOW = 1; // 2; // 0.5f;
1366615297 float BRIPOW = 1; // 0.5f; // 0.5f;
1366715298
13668
- void keyPressed(int key)
15299
+ public void keyPressed(int key)
1366915300 {
1367015301 if (key >= '0' && key <= '5')
1367115302 clampbit = (key-'0');
....@@ -13712,7 +15343,8 @@
1371215343 // break;
1371315344 case 'T':
1371415345 CACHETEXTURE ^= true;
13715
- textures.clear();
15346
+ texturepigment.clear();
15347
+ texturebump.clear();
1371615348 // repaint();
1371715349 break;
1371815350 case 'Y':
....@@ -13722,8 +15354,8 @@
1372215354 case 'K':
1372315355 KOMPACTTEXTURE ^= true;
1372415356 //textures.clear();
13725
- break;
13726
- case 'P': // Texture Projection macros
15357
+ // break;
15358
+ //case 'P': // Texture Projection macros
1372715359 // SAVETEXTURE ^= true;
1372815360 macromode = true;
1372915361 Udebug = Vdebug = NORMALdebug = false; programInitialized = false;
....@@ -13797,7 +15429,9 @@
1379715429 case 'E' : COMPACT ^= true;
1379815430 repaint();
1379915431 break;
13800
- case 'W' : DEBUGHSB ^= true;
15432
+ case 'W' : // Wide Window (fullscreen)
15433
+ //DEBUGHSB ^= true;
15434
+ ObjEditor.theFrame.ToggleFullScreen();
1380115435 repaint();
1380215436 break;
1380315437 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13822,8 +15456,8 @@
1382215456 RevertCamera();
1382315457 repaint();
1382415458 break;
13825
- case 'L':
1382615459 case 'l':
15460
+ //case 'L':
1382715461 if (lightMode)
1382815462 {
1382915463 lightMode = false;
....@@ -13842,7 +15476,7 @@
1384215476 targetLookAt.set(manipCamera.lookAt);
1384315477 repaint();
1384415478 break;
13845
- case 'p':
15479
+ case 'P': // p':
1384615480 // c'est quoi ca au juste? spherical ^= true;
1384715481 Skinshader ^= true; programInitialized = false;
1384815482 repaint();
....@@ -13880,27 +15514,31 @@
1388015514 repaint();
1388115515 break;
1388215516 case 'O':
13883
- Globals.drawMode = OCCLUSION; // WARNING
15517
+ // Too dangerous. Use menu. Globals.drawMode = OCCLUSION; // WARNING
1388415518 repaint();
1388515519 break;
1388615520 case 'o':
1388715521 OCCLUSION_CULLING ^= true;
1388815522 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1388915523 break;
13890
- case '0': envyoff ^= true; repaint(); break;
15524
+ //case '0': envyoff ^= true; repaint(); break;
1389115525 case '1':
1389215526 case '2':
1389315527 case '3':
1389415528 case '4':
1389515529 case '5':
13896
- newenvy = Character.getNumericValue(key);
13897
- repaint();
13898
- break;
1389915530 case '6':
1390015531 case '7':
1390115532 case '8':
1390215533 case '9':
13903
- BGcolor = (key - '6')/3.f;
15534
+ if (true) // envyoff)
15535
+ {
15536
+ BGcolor = (key - '1')/8.f;
15537
+ }
15538
+ else
15539
+ {
15540
+ //newenvy = Character.getNumericValue(key);
15541
+ }
1390415542 repaint();
1390515543 break;
1390615544 case '!':
....@@ -13966,9 +15604,9 @@
1396615604 case '_':
1396715605 kompactbit = 5;
1396815606 break;
13969
- case '+':
13970
- kompactbit = 6;
13971
- break;
15607
+// case '+':
15608
+// kompactbit = 6;
15609
+// break;
1397215610 case ' ':
1397315611 lightMode ^= true;
1397415612 Globals.lighttouched = true;
....@@ -13980,13 +15618,14 @@
1398015618 case ESC:
1398115619 RENDERPROGRAM += 1;
1398215620 RENDERPROGRAM %= 3;
15621
+
1398315622 repaint();
1398415623 break;
1398515624 case 'Z':
1398615625 //RESIZETEXTURE ^= true;
1398715626 //break;
1398815627 case 'z':
13989
- RENDERSHADOW ^= true;
15628
+ Globals.RENDERSHADOW ^= true;
1399015629 Globals.lighttouched = true;
1399115630 repaint();
1399215631 break;
....@@ -14019,8 +15658,9 @@
1401915658 case DELETE:
1402015659 ClearSelection();
1402115660 break;
14022
- /*
1402315661 case '+':
15662
+
15663
+ /*
1402415664 //fontsize += 1;
1402515665 bbzoom *= 2;
1402615666 repaint();
....@@ -14037,17 +15677,17 @@
1403715677 case '=':
1403815678 IncDepth();
1403915679 //fontsize += 1;
14040
- object.editWindow.refreshContents(true);
15680
+ object.GetWindow().refreshContents(true);
1404115681 maskbit = 6;
1404215682 break;
1404315683 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1404415684 DecDepth();
1404515685 maskbit = 5;
1404615686 //if(fontsize > 1) fontsize -= 1;
14047
- if (object.editWindow == null)
14048
- new Exception().printStackTrace();
14049
- else
14050
- object.editWindow.refreshContents(true);
15687
+// if (object.editWindow == null)
15688
+// new Exception().printStackTrace();
15689
+// else
15690
+ object.GetWindow().refreshContents(true);
1405115691 break;
1405215692 case '{':
1405315693 manipCamera.shaper_fovy /= 1.1;
....@@ -14102,6 +15742,7 @@
1410215742 }
1410315743 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1410415744 }
15745
+
1410515746 static double OCCLUSIONBOOST = 1; // 0.5;
1410615747
1410715748 void keyReleased(int key, int modifiers)
....@@ -14109,11 +15750,11 @@
1410915750 //mode = ROTATE;
1411015751 if ((MODIFIERS & COMMAND) == 0) // VR??
1411115752 {
14112
- SetMouseMode(modifiers);
15753
+ SetMouseMode(0, modifiers);
1411315754 }
1411415755 }
1411515756
14116
- protected void processKeyEvent(KeyEvent e)
15757
+ public void processKeyEvent(KeyEvent e)
1411715758 {
1411815759 switch (e.getID())
1411915760 {
....@@ -14243,8 +15884,9 @@
1424315884
1424415885 protected void processMouseMotionEvent(MouseEvent e)
1424515886 {
14246
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14247
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15887
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15888
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15889
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1424815890 {
1424915891 mouseMoved(e);
1425015892 } else
....@@ -14269,11 +15911,12 @@
1426915911 }
1427015912 */
1427115913
14272
- object.editWindow.EditSelection();
15914
+ object.GetWindow().EditSelection(false);
1427315915 }
1427415916
1427515917 void SelectParent()
1427615918 {
15919
+ new Exception().printStackTrace();
1427715920 System.exit(0);
1427815921 Composite group = (Composite) object;
1427915922 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14285,10 +15928,10 @@
1428515928 {
1428615929 //selectees.remove(i);
1428715930 System.out.println("select parent of " + elem);
14288
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15931
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1428915932 } else
1429015933 {
14291
- group.editWindow.Select(elem.GetTreePath(), first, true);
15934
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1429215935 }
1429315936
1429415937 first = false;
....@@ -14297,6 +15940,7 @@
1429715940
1429815941 void SelectChildren()
1429915942 {
15943
+ new Exception().printStackTrace();
1430015944 System.exit(0);
1430115945 /*
1430215946 Composite group = (Composite) object;
....@@ -14329,12 +15973,12 @@
1432915973 for (int j = 0; j < group.children.size(); j++)
1433015974 {
1433115975 elem = (Object3D) group.children.elementAt(j);
14332
- object.editWindow.Select(elem.GetTreePath(), first, true);
15976
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1433315977 first = false;
1433415978 }
1433515979 } else
1433615980 {
14337
- object.editWindow.Select(elem.GetTreePath(), first, true);
15981
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1433815982 }
1433915983
1434015984 first = false;
....@@ -14345,21 +15989,21 @@
1434515989 {
1434615990 //Composite group = (Composite) object;
1434715991 Object3D group = object;
14348
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15992
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1434915993 }
1435015994
1435115995 void ResetTransform(int mask)
1435215996 {
1435315997 //Composite group = (Composite) object;
1435415998 Object3D group = object;
14355
- group.editWindow.ResetTransform(mask);
15999
+ group.GetWindow().ResetTransform(mask);
1435616000 }
1435716001
1435816002 void FlipTransform()
1435916003 {
1436016004 //Composite group = (Composite) object;
1436116005 Object3D group = object;
14362
- group.editWindow.FlipTransform();
16006
+ group.GetWindow().FlipTransform();
1436316007 // group.editWindow.ReduceMesh(true);
1436416008 }
1436516009
....@@ -14367,7 +16011,7 @@
1436716011 {
1436816012 //Composite group = (Composite) object;
1436916013 Object3D group = object;
14370
- group.editWindow.PrintMemory();
16014
+ group.GetWindow().PrintMemory();
1437116015 // group.editWindow.ReduceMesh(true);
1437216016 }
1437316017
....@@ -14375,7 +16019,7 @@
1437516019 {
1437616020 //Composite group = (Composite) object;
1437716021 Object3D group = object;
14378
- group.editWindow.ResetCentroid();
16022
+ group.GetWindow().ResetCentroid();
1437916023 }
1438016024
1438116025 void IncDepth()
....@@ -14457,11 +16101,11 @@
1445716101
1445816102 int width = getBounds().width;
1445916103 int height = getBounds().height;
14460
- ClickInfo info = new ClickInfo();
14461
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1446216104 //Image img = CreateImage(width, height);
1446316105 //System.out.println("width = " + width + "; height = " + height + "\n");
16106
+
1446416107 Graphics gr = g; // img.getGraphics();
16108
+
1446516109 if (!hasMarquee)
1446616110 {
1446716111 if (Xmin < Xmax) // !locked)
....@@ -14533,44 +16177,92 @@
1453316177 }
1453416178 if (object != null && !hasMarquee)
1453516179 {
16180
+ if (object.clickInfo == null)
16181
+ object.clickInfo = new ClickInfo();
16182
+ ClickInfo info = object.clickInfo;
16183
+ //ClickInfo info = new ClickInfo();
16184
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16185
+
1453616186 if (isRenderer)
1453716187 {
14538
- info.flags++;
16188
+ object.clickInfo.flags++;
1453916189 double frameAspect = (double) width / (double) height;
1454016190 if (frameAspect > renderCamera.aspect)
1454116191 {
1454216192 int desired = (int) ((double) height * renderCamera.aspect);
14543
- info.bounds.width -= width - desired;
14544
- info.bounds.x += (width - desired) / 2;
16193
+ object.clickInfo.bounds.width -= width - desired;
16194
+ object.clickInfo.bounds.x += (width - desired) / 2;
1454516195 } else
1454616196 {
1454716197 int desired = (int) ((double) width / renderCamera.aspect);
14548
- info.bounds.height -= height - desired;
14549
- info.bounds.y += (height - desired) / 2;
16198
+ object.clickInfo.bounds.height -= height - desired;
16199
+ object.clickInfo.bounds.y += (height - desired) / 2;
1455016200 }
1455116201 }
14552
- info.g = gr;
14553
- info.camera = renderCamera;
16202
+
16203
+ object.clickInfo.g = gr;
16204
+ object.clickInfo.camera = renderCamera;
1455416205 /*
1455516206 // Memory intensive (brep.verticescopy)
1455616207 if (!(object instanceof Composite))
1455716208 object.draw(info, 0, false); // SLOW :
1455816209 */
14559
- if (!isRenderer)
16210
+ if (!isRenderer) // && drag)
1456016211 {
14561
- object.drawEditHandles(info, 0);
16212
+ Grafreed.Assert(object != null);
16213
+ Grafreed.Assert(object.selection != null);
16214
+ if (object.selection.Size() > 0)
16215
+ {
16216
+ int hitSomething = object.selection.get(0).hitSomething;
16217
+
16218
+ object.clickInfo.DX = 0;
16219
+ object.clickInfo.DY = 0;
16220
+ object.clickInfo.W = 1;
16221
+ if (hitSomething == Object3D.hitCenter)
16222
+ {
16223
+ info.DX = X;
16224
+ if (X != 0)
16225
+ info.DX -= info.bounds.width/2;
16226
+
16227
+ info.DY = Y;
16228
+ if (Y != 0)
16229
+ info.DY -= info.bounds.height/2;
16230
+ }
16231
+
16232
+ object.drawEditHandles(//info,
16233
+ 0);
16234
+
16235
+ if (drag && (X != 0 || Y != 0))
16236
+ {
16237
+ switch (hitSomething)
16238
+ {
16239
+ case Object3D.hitCenter: gr.setColor(Color.white);
16240
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16241
+ break;
16242
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16243
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16244
+ break;
16245
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16246
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16247
+ break;
16248
+ }
16249
+
16250
+ }
16251
+ }
1456216252 }
1456316253 }
16254
+
1456416255 if (isRenderer)
1456516256 {
1456616257 //gr.setColor(Color.black);
1456716258 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1456816259 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1456916260 }
16261
+
1457016262 if (hasMarquee)
1457116263 {
1457216264 gr.setXORMode(Color.white);
14573
- gr.setColor(Color.red);
16265
+ gr.setColor(Color.white);
1457416266 if (!firstime)
1457516267 {
1457616268 gr.drawRect(prevmarqX, prevmarqY, prevmarqW, prevmarqH);
....@@ -14679,6 +16371,7 @@
1467916371 public boolean mouseDown(Event evt, int x, int y)
1468016372 {
1468116373 System.out.println("mouseDown: " + evt);
16374
+ System.exit(0);
1468216375 /*
1468316376 locked = true;
1468416377 drag = false;
....@@ -14722,7 +16415,7 @@
1472216415 {
1472316416 keyPressed(0, modifiers);
1472416417 }
14725
- clickStart(x, y, modifiers);
16418
+ // clickStart(x, y, modifiers);
1472616419 return true;
1472716420 }
1472816421
....@@ -14840,7 +16533,7 @@
1484016533 {
1484116534 keyReleased(0, 0);
1484216535 }
14843
- drag(x, y, modifiers);
16536
+ drag(x, y, 0, modifiers);
1484416537 return true;
1484516538 }
1484616539
....@@ -14972,7 +16665,7 @@
1497216665 Object3D object;
1497316666 static Object3D trackedobject;
1497416667 Camera renderCamera; // Light or Eye (or Occlusion)
14975
- /*static*/ Camera manipCamera; // Light or Eye
16668
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1497616669 /*static*/ Camera eyeCamera;
1497716670 /*static*/ Camera lightCamera;
1497816671 int cameracount;
....@@ -15036,6 +16729,8 @@
1503616729 private /*static*/ boolean firstime;
1503716730 private /*static*/ cVector newView = new cVector();
1503816731 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16732
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16733
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1503916734 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1504016735 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1504116736 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15048,29 +16743,67 @@
1504816743 {
1504916744 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1505016745
16746
+ int usedsuf = 0;
16747
+
1505116748 for (int i = 0; i < suffixes.length; i++)
1505216749 {
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)
16750
+ String[] suffixe = suffixes;
16751
+ String[] fallback = suffixes2;
16752
+ String[] fallfallback = suffixes3;
16753
+
16754
+ for (int c=usedsuf; --c>=0;)
1505816755 {
15059
- throw new IOException("Unable to load texture " + resourceName);
16756
+// String[] temp = suffixe;
16757
+// suffixe = fallback;
16758
+// fallback = fallfallback;
16759
+// fallfallback = temp;
1506016760 }
16761
+
16762
+ String resourceName = basename + suffixe[i] + "." + suffix;
16763
+ TextureData data;
16764
+
16765
+ try
16766
+ {
16767
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16768
+ mipmapped,
16769
+ FileUtil.getFileSuffix(resourceName));
16770
+ }
16771
+ catch (Exception e)
16772
+ {
16773
+ try
16774
+ {
16775
+ resourceName = basename + fallback[i] + "." + suffix;
16776
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16777
+ mipmapped,
16778
+ FileUtil.getFileSuffix(resourceName));
16779
+ }
16780
+ catch (Exception e2)
16781
+ {
16782
+ resourceName = basename + fallfallback[i] + "." + suffix;
16783
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16784
+ mipmapped,
16785
+ FileUtil.getFileSuffix(resourceName));
16786
+ }
16787
+ }
16788
+
1506116789 //System.out.println("Target = " + targets[i]);
1506216790 cubemap.updateImage(data, targets[i]);
1506316791 }
1506416792
1506516793 return cubemap;
1506616794 }
16795
+
1506716796 int bigsphere = -1;
1506816797
1506916798 float BGcolor = 0.5f;
1507016799
15071
- private void DrawSkyBox(GL gl)
16800
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16801
+
16802
+ private void DrawSkyBox(GL gl, float ratio)
1507216803 {
15073
- if (envyoff || cubemap == null)
16804
+ if (//envyoff ||
16805
+ WIREFRAME ||
16806
+ cubemap == null)
1507416807 {
1507516808 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1507616809 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15085,7 +16818,17 @@
1508516818 // Compensates for ExaminerViewer's modification of modelview matrix
1508616819 gl.glMatrixMode(GL.GL_MODELVIEW);
1508716820 gl.glLoadIdentity();
16821
+ gl.glScalef(1,ratio,1);
1508816822
16823
+// colorV[0] = 2;
16824
+// colorV[1] = 2;
16825
+// colorV[2] = 2;
16826
+// colorV[3] = 1;
16827
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16828
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16829
+//
16830
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16831
+
1508916832 //gl.glActiveTexture(GL.GL_TEXTURE1);
1509016833 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1509116834
....@@ -15117,6 +16860,7 @@
1511716860 {
1511816861 gl.glScalef(1.0f, -1.0f, 1.0f);
1511916862 }
16863
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1512016864 gl.glMultMatrixd(viewrot_1, 0);
1512116865 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1512216866 //viewer.updateInverseRotation(gl);
....@@ -15157,7 +16901,8 @@
1515716901 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1515816902
1515916903 cubemap.disable();
15160
- ////cubemap.unbind();
16904
+ //cubemap.dispose();
16905
+
1516116906 if (CULLFACE)
1516216907 {
1516316908 gl.glEnable(gl.GL_CULL_FACE);
....@@ -15213,7 +16958,7 @@
1521316958 gl.glScalef(1.0f, -1.0f, 1.0f);
1521416959 }
1521516960
15216
- gl.glNormal3f(0.0f, 0.0f, 1.0f);
16961
+ SetGLNormal(gl, 0.0f, 0.0f, 1.0f);
1521716962
1521816963 float step = 2; // 0.1666f; //0.25f;
1521916964 float stepv = 2; // step * 1652 / 998;
....@@ -15257,16 +17002,16 @@
1525717002 cStatic.objectstack[materialdepth++] = checker;
1525817003 //System.out.println("material " + material);
1525917004 //Applet3D.tracein(this, selected);
15260
- vector2buffer = checker.projectedVertices;
17005
+ //vector2buffer = checker.projectedVertices;
1526117006
1526217007 //checker.GetMaterial().Draw(this, false); // true);
15263
- DrawMaterial(checker.GetMaterial(), false); // true);
17008
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1526417009
1526517010 materialdepth -= 1;
1526617011 if (materialdepth > 0)
1526717012 {
15268
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15269
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
17013
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
17014
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1527017015 }
1527117016 //checker.GetMaterial().opacity = 1f;
1527217017 ////checker.GetMaterial().ambient = 1f;
....@@ -15352,6 +17097,14 @@
1535217097 }
1535317098 }
1535417099
17100
+ private Object3D GetFolder()
17101
+ {
17102
+ Object3D folder = object.GetWindow().copy;
17103
+ if (object.GetWindow().copy.selection.Size() > 0)
17104
+ folder = object.GetWindow().copy.selection.elementAt(0);
17105
+ return folder;
17106
+ }
17107
+
1535517108 class SelectBuffer implements GLEventListener
1535617109 {
1535717110
....@@ -15367,7 +17120,7 @@
1536717120 //new Exception().printStackTrace();
1536817121 System.out.println("select buffer init");
1536917122 // Use debug pipeline
15370
- drawable.setGL(new DebugGL(drawable.getGL()));
17123
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1537117124
1537217125 GL gl = drawable.getGL();
1537317126
....@@ -15410,6 +17163,7 @@
1541017163 {
1541117164 if (!selection)
1541217165 {
17166
+ new Exception().printStackTrace();
1541317167 System.exit(0);
1541417168 return;
1541517169 }
....@@ -15430,6 +17184,17 @@
1543017184
1543117185 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1543217186
17187
+ if (PAINTMODE)
17188
+ {
17189
+ if (object.GetWindow().copy.selection.Size() > 0)
17190
+ {
17191
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17192
+
17193
+ // Make what you paint not selectable.
17194
+ paintobj.ResetSelectable();
17195
+ }
17196
+ }
17197
+
1543317198 //int tmp = selection_view;
1543417199 //selection_view = -1;
1543517200 int temp = DrawMode();
....@@ -15441,6 +17206,17 @@
1544117206 // temp = DEFAULT; // patch for selection debug
1544217207 Globals.drawMode = temp; // WARNING
1544317208
17209
+ if (PAINTMODE)
17210
+ {
17211
+ if (object.GetWindow().copy.selection.Size() > 0)
17212
+ {
17213
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17214
+
17215
+ // Revert.
17216
+ paintobj.RestoreSelectable();
17217
+ }
17218
+ }
17219
+
1544417220 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1544517221
1544617222 // trying different ways of getting the depth info over
....@@ -15488,6 +17264,8 @@
1548817264 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1548917265 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1549017266 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17267
+
17268
+ CreateSelectedPoint();
1549117269
1549217270 // Will fit the mesh !!!
1549317271 selectedpoint.toParent[0][0] = 0.0001;
....@@ -15537,34 +17315,36 @@
1553717315 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]));
1553817316 }
1553917317
15540
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17318
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1554117319 }
1554217320 }
1554317321
1554417322 if (!movingcamera && !PAINTMODE)
15545
- object.editWindow.ScreenFitPoint(); // fev 2014
17323
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1554617324
15547
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17325
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1554817326 {
15549
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17327
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1555017328
15551
- Object3D group = new Object3D("inst" + paintcount++);
17329
+ if (object.GetWindow().copy.selection.Size() > 0)
17330
+ {
17331
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1555217332
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();
17333
+ Object3D inst = new Object3D("inst" + paintcount++);
17334
+
17335
+ inst.CreateMaterial(); // use a void leaf to select instances
17336
+
17337
+ inst.add(paintobj); // link
17338
+
17339
+ object.GetWindow().SnapObject(inst);
17340
+
17341
+ Object3D folder = paintFolder; // GetFolder();
17342
+
17343
+ folder.add(inst);
17344
+
17345
+ object.GetWindow().ResetModel();
17346
+ object.GetWindow().refreshContents();
17347
+ }
1556817348 }
1556917349 else
1557017350 paintcount = 0;
....@@ -15603,6 +17383,11 @@
1560317383 //System.out.println("objects[color] = " + objects[color]);
1560417384 //objects[color].Select();
1560517385 indexcount = 0;
17386
+ ObjEditor window = object.GetWindow();
17387
+ if (window != null && deselect)
17388
+ {
17389
+ window.Select(null, deselect, true);
17390
+ }
1560617391 object.Select(color, deselect);
1560717392 }
1560817393
....@@ -15653,6 +17438,7 @@
1565317438
1565417439 public void init(GLAutoDrawable drawable)
1565517440 {
17441
+ if (Globals.DEBUG)
1565617442 System.out.println("shadow buffer init");
1565717443
1565817444 GL gl = drawable.getGL();
....@@ -15702,7 +17488,7 @@
1570217488 gl.glDisable(gl.GL_CULL_FACE);
1570317489 }
1570417490
15705
- if (!RENDERSHADOW)
17491
+ if (!Globals.RENDERSHADOW)
1570617492 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1570717493
1570817494 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -15712,7 +17498,7 @@
1571217498 //gl.glColorMask(false, false, false, false);
1571317499
1571417500 //render_scene_from_light_view(gl, drawable, 0, 0);
15715
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17501
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1571617502 {
1571717503 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1571817504
....@@ -15772,7 +17558,6 @@
1577217558
1577317559 class AntialiasBuffer implements GLEventListener
1577417560 {
15775
-
1577617561 CameraPane parent = null;
1577717562
1577817563 AntialiasBuffer(CameraPane p)
....@@ -15882,10 +17667,14 @@
1588217667 gl.glFlush();
1588317668
1588417669 /**/
15885
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17670
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1588617671
15887
- float[] pixels = occlusionsizebuffer.array();
17672
+ float[] depths = occlusiondepthbuffer.array();
1588817673
17674
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17675
+
17676
+ int[] pixels = selectsizebuffer.array();
17677
+
1588917678 double r = 0, g = 0, b = 0;
1589017679
1589117680 double count = 0;
....@@ -15896,7 +17685,7 @@
1589617685
1589717686 double FACTOR = 1;
1589817687
15899
- for (int i = 0; i < pixels.length; i++)
17688
+ for (int i = 0; i < depths.length; i++)
1590017689 {
1590117690 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1590217691 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15979,7 +17768,7 @@
1597917768
1598017769 double scale = ray.z; // 1; // cos
1598117770
15982
- float depth = pixels[newindex];
17771
+ float depth = depths[newindex];
1598317772
1598417773 /*
1598517774 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16129,23 +17918,15 @@
1612917918 int AAbuffersize = 0;
1613017919
1613117920 //double[] selectedpoint = new double[3];
16132
- static Superellipsoid selectedpoint = new Superellipsoid();
17921
+ static Superellipsoid selectedpoint;
1613317922 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();
17923
+ static Sphere debugpointG;
17924
+ static Sphere debugpointP;
17925
+ static Sphere debugpointC;
17926
+ static Sphere debugpointR;
1613817927
1613917928 static Sphere debugpoints[] = new Sphere[8];
1614017929
16141
- static
16142
- {
16143
- for (int i=0; i<8; i++)
16144
- {
16145
- debugpoints[i] = new Sphere();
16146
- }
16147
- }
16148
-
1614917930 static void InitPoints(float radius)
1615017931 {
1615117932 for (int i=0; i<8; i++)
....@@ -16165,7 +17946,7 @@
1616517946 }
1616617947 }
1616717948
16168
- static void DrawPoints(CameraPane cpane)
17949
+ static void DrawPoints(iCameraPane cpane)
1616917950 {
1617017951 for (int i=0; i<8; i++) // first and last are red
1617117952 {
....@@ -16184,11 +17965,14 @@
1618417965 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1618517966 static IntBuffer bigAAbuffer;
1618617967 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
16187
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17968
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1618817969 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1618917970 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1619017971 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
16191
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17972
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17973
+
17974
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17975
+
1619217976 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1619317977 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1619417978 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -16197,10 +17981,11 @@
1619717981 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1619817982 // Depth buffer format
1619917983 //private int depth_format;
16200
- static public void NextIndex(Object3D o, GL gl)
17984
+
17985
+ public void NextIndex()
1620117986 {
1620217987 indexcount+=16;
16203
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17988
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1620417989 //objects[indexcount] = o;
1620517990 //System.out.println("indexcount = " + indexcount);
1620617991 }