Normand Briere
2019-08-15 24a2a946b35279605e645349bd6b82e9e60aac88
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
....@@ -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,16 +526,18 @@
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);
....@@ -566,8 +691,819 @@
566691 }
567692 }
568693
694
+ /**
695
+ * <code>draw</code> renders a <code>TriMesh</code> object including
696
+ * it's normals, colors, textures and vertices.
697
+ *
698
+ * @see Renderer#draw(TriMesh)
699
+ * @param tris
700
+ * the mesh to render.
701
+ */
702
+ public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
703
+ {
704
+ CameraPane display = this;
705
+
706
+ float r = display.modelParams0[0];
707
+ float g = display.modelParams0[1];
708
+ float b = display.modelParams0[2];
709
+ float opacity = display.modelParams5[1];
710
+
711
+ //final GL gl = GLU.getCurrentGL();
712
+ GL gl = display.GetGL(); // getGL();
713
+
714
+ FloatBuffer vertBuf = geo.vertBuf;
715
+
716
+ int v = vertBuf.capacity();
717
+
718
+ int count = 0;
719
+
720
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
721
+ gl.glEnable(gl.GL_CULL_FACE);
722
+ // gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
723
+ for (int i=0; i<v/3; i++)
724
+ {
725
+ int index3 = i*3;
726
+
727
+ if (geo.sizeBuf.get(index3+1) == 0)
728
+ continue;
729
+
730
+ count++;
731
+
732
+ int index4 = i*4;
733
+
734
+ float tx = vertBuf.get(index3);
735
+ float ty = vertBuf.get(index3+1);
736
+ float tz = vertBuf.get(index3+2);
737
+
738
+ // if (tx == 0 && ty == 0 && tz == 0)
739
+ // continue;
740
+
741
+ gl.glMatrixMode(gl.GL_TEXTURE);
742
+ gl.glPushMatrix();
743
+
744
+ float[] texmat = geo.texmat;
745
+ texmat[12] = texmat[13] = texmat[14] = i;
746
+
747
+ gl.glMultMatrixf(texmat, 0);
748
+
749
+ gl.glMatrixMode(gl.GL_MODELVIEW);
750
+ gl.glPushMatrix();
751
+
752
+ gl.glTranslatef(tx,ty,tz);
753
+
754
+ if (rotate)
755
+ gl.glRotatef(i, 0, 1, 0);
756
+
757
+ float size = geo.sizeBuf.get(index3) / 100;
758
+ gl.glScalef(size,size,size);
759
+
760
+ float cr = geo.colorBuf.get(index4);
761
+ float cg = geo.colorBuf.get(index4+1);
762
+ float cb = geo.colorBuf.get(index4+2);
763
+ float ca = geo.colorBuf.get(index4+3);
764
+
765
+ display.modelParams0[0] = r * cr;
766
+ display.modelParams0[1] = g * cg;
767
+ display.modelParams0[2] = b * cb;
768
+
769
+ display.modelParams5[1] = opacity * ca;
770
+
771
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
772
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
773
+
774
+ RandomNode.globalseed = (int)geo.sizeBuf.get(index3+2); // i;
775
+ RandomNode.globalseed2 = RandomNode.globalseed;
776
+
777
+// gl.glColor4f(cr,cg,cb,ca);
778
+ // gl.glScalef(1024/16,1024/16,1024/16);
779
+ shape.Draw/*Node*/(display,null,selected,false); // blocked
780
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
781
+ //gl.glTranslatef(-tx,-ty,-tz);
782
+ gl.glPopMatrix();
783
+
784
+ gl.glMatrixMode(gl.GL_TEXTURE);
785
+ gl.glPopMatrix();
786
+ }
787
+ // gl.glScalef(1024,1024,1024);
788
+ if (!cf)
789
+ gl.glDisable(gl.GL_CULL_FACE);
790
+
791
+ display.modelParams0[0] = r;
792
+ display.modelParams0[1] = g;
793
+ display.modelParams0[2] = b;
794
+
795
+ display.modelParams5[1] = opacity;
796
+
797
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
798
+ gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
799
+
800
+ gl.glMatrixMode(gl.GL_MODELVIEW);
801
+
802
+// System.err.println("total = " + v/3 + "; displayed = " + count);
803
+ if (true)
804
+ return;
805
+
806
+//// if (!tris.predraw(this))
807
+//// {
808
+//// return;
809
+//// }
810
+//// if (Debug.stats)
811
+//// {
812
+//// StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
813
+//// StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
814
+//// StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
815
+//// }
816
+////
817
+//// if (tris.getDisplayListID() != -1)
818
+//// {
819
+//// renderDisplayList(tris);
820
+//// return;
821
+//// }
822
+////
823
+//// if (!generatingDisplayList)
824
+//// {
825
+//// applyStates(tris.states, tris);
826
+//// }
827
+//// if (Debug.stats)
828
+//// {
829
+//// StatCollector.startStat(StatType.STAT_RENDER_TIMER);
830
+//// }
831
+//// boolean transformed = doTransforms(tris);
832
+//
833
+// int glMode = GL.GL_TRIANGLES;
834
+// switch (getMode())
835
+// {
836
+// case Triangles:
837
+// glMode = GL.GL_TRIANGLES;
838
+// break;
839
+// case Strip:
840
+// glMode = GL.GL_TRIANGLE_STRIP;
841
+// break;
842
+// case Fan:
843
+// glMode = GL.GL_TRIANGLE_FAN;
844
+// break;
845
+// }
846
+//
847
+// if (!predrawGeometry(gl))
848
+// {
849
+// // make sure only the necessary indices are sent through on old
850
+// // cards.
851
+// IntBuffer indices = this.getIndexBuffer();
852
+// if (indices == null)
853
+// {
854
+// logger.severe("missing indices on geometry object: " + this.toString());
855
+// } else
856
+// {
857
+// indices.rewind();
858
+// indices.limit(this.getMaxIndex());
859
+//
860
+// gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
861
+//
862
+// indices.clear();
863
+// }
864
+// } else
865
+// {
866
+// gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
867
+// GL.GL_UNSIGNED_INT, 0);
868
+// }
869
+//
870
+//// postdrawGeometry(tris);
871
+//// if (transformed)
872
+//// {
873
+//// undoTransforms(tris);
874
+//// }
875
+////
876
+//// if (Debug.stats)
877
+//// {
878
+//// StatCollector.endStat(StatType.STAT_RENDER_TIMER);
879
+//// }
880
+//// tris.postdraw(this);
881
+ }
882
+
883
+ static Camera localcamera = new Camera();
884
+ static cVector from = new cVector();
885
+ static cVector to = new cVector();
886
+
887
+ public void PrepOcclusion(BoundaryRep br, double[][] transform)
888
+ {
889
+ CameraPane cp = this;
890
+
891
+ Camera keep = cp.RenderCamera();
892
+ cp.renderCamera = localcamera;
893
+
894
+ if (br.trimmed)
895
+ {
896
+ float[] colors = new float[br.positions.length / 3];
897
+
898
+ int i3 = 0;
899
+ for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
900
+ {
901
+ if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
902
+ continue;
903
+
904
+ from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
905
+ to.set(br.positions[i3] + br.normals[i3],
906
+ br.positions[i3 + 1] + br.normals[i3 + 1],
907
+ br.positions[i3 + 2] + br.normals[i3 + 2]);
908
+ LA.xformPos(from, transform, from);
909
+ LA.xformPos(to, transform, to); // RIGID ONLY
910
+ localcamera.setAim(from, to);
911
+
912
+ CameraPane.occlusionbuffer.display();
913
+
914
+ if (CameraPane.DEBUG_OCCLUSION)
915
+ cp.display(); // debug
916
+
917
+ colors[i] = cp.vertexOcclusion.r;
918
+ //colors[i3 + 1] = cp.vertexOcclusion.g;
919
+ //colors[i3 + 2] = cp.vertexOcclusion.b;
920
+
921
+ if ((i % 100) == 0 && i != 0)
922
+ {
923
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
924
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
925
+ System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
926
+ }
927
+ }
928
+
929
+ br.colors = colors;
930
+ }
931
+ else
932
+ {
933
+ for (int i = 0; i < br.VertexCount(); i++)
934
+ {
935
+ Vertex v = br.GetVertex(i);
936
+
937
+ if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
938
+ continue;
939
+
940
+ from.set(v.x, v.y, v.z);
941
+ to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
942
+ LA.xformPos(from, transform, from);
943
+ LA.xformPos(to, transform, to); // RIGID ONLY
944
+ localcamera.setAim(from, to);
945
+
946
+ CameraPane.occlusionbuffer.display();
947
+
948
+ if (CameraPane.DEBUG_OCCLUSION)
949
+ cp.display(); // debug
950
+
951
+ v.AO = cp.vertexOcclusion.r;
952
+
953
+ if ((i % 100) == 0 && i != 0)
954
+ {
955
+ Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
956
+ //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
957
+ System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
958
+ }
959
+ }
960
+ }
961
+
962
+ //System.out.println("done.");
963
+
964
+ cp.renderCamera = keep;
965
+ }
966
+
967
+ void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
968
+ {
969
+ CameraPane display = this;
970
+ pointFlow.CreateHT();
971
+
972
+ float r = display.modelParams0[0];
973
+ float g = display.modelParams0[1];
974
+ float b = display.modelParams0[2];
975
+ float opacity = display.modelParams5[1];
976
+
977
+ //final GL gl = GLU.getCurrentGL();
978
+ GL gl = display.GetGL(); // getGL();
979
+
980
+ int s = pointFlow.points.size();
981
+
982
+ boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
983
+ gl.glEnable(gl.GL_CULL_FACE);
984
+
985
+ for (int i=s; --i>=0;)
986
+ //for (int i=0; i<s; i++)
987
+ {
988
+ cVector v = pointFlow.points.get(i);
989
+
990
+ double mindist = Double.MAX_VALUE;
991
+
992
+ double size = pointFlow.minimumSize;
993
+
994
+ double distancenext = 0;
995
+
996
+ if (i > 0)
997
+ {
998
+ cVector w = pointFlow.points.get(i-1);
999
+
1000
+ double dist = w.distance(v);
1001
+
1002
+ distancenext = dist;
1003
+
1004
+ if (mindist > dist)
1005
+ {
1006
+ mindist = dist;
1007
+ size = mindist*pointFlow.resizefactor;
1008
+ }
1009
+ }
1010
+
1011
+ if (i < s-1)
1012
+ {
1013
+ cVector w = pointFlow.points.get(i+1);
1014
+
1015
+ double dist = w.distance(v);
1016
+
1017
+ if (mindist > dist)
1018
+ {
1019
+ mindist = dist;
1020
+ size = mindist*pointFlow.resizefactor;
1021
+ }
1022
+ }
1023
+
1024
+ if (size < pointFlow.minimumSize)
1025
+ size = pointFlow.minimumSize;
1026
+ if (size > pointFlow.maximumSize)
1027
+ size = pointFlow.maximumSize;
1028
+
1029
+ double tx = v.x;
1030
+ double ty = v.y;
1031
+ double tz = v.z;
1032
+
1033
+ // if (tx == 0 && ty == 0 && tz == 0)
1034
+ // continue;
1035
+
1036
+ gl.glMatrixMode(gl.GL_TEXTURE);
1037
+ gl.glPushMatrix();
1038
+ pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
1039
+
1040
+ gl.glMultMatrixf(pointFlow.texmat, 0);
1041
+
1042
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1043
+ gl.glPushMatrix();
1044
+
1045
+ gl.glTranslated(tx,ty,tz);
1046
+
1047
+ gl.glScaled(size,size,size);
1048
+
1049
+// float cr = colorBuf.get(index4);
1050
+// float cg = colorBuf.get(index4+1);
1051
+// float cb = colorBuf.get(index4+2);
1052
+// float ca = colorBuf.get(index4+3);
1053
+//
1054
+// display.modelParams0[0] = r * cr;
1055
+// display.modelParams0[1] = g * cg;
1056
+// display.modelParams0[2] = b * cb;
1057
+//
1058
+// display.modelParams5[1] = opacity * ca;
1059
+//
1060
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1061
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1062
+//
1063
+// RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
1064
+// RandomNode.globalseed2 = RandomNode.globalseed;
1065
+//
1066
+//// gl.glColor4f(cr,cg,cb,ca);
1067
+// // gl.glScalef(1024/16,1024/16,1024/16);
1068
+ pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
1069
+
1070
+ gl.glPopMatrix();
1071
+
1072
+ double step = size/4; //
1073
+
1074
+ if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
1075
+ continue;
1076
+
1077
+ int nbsteps = (int)(distancenext/step);
1078
+
1079
+ step = distancenext/nbsteps;
1080
+
1081
+ cVector next = pointFlow.points.get(i-1);
1082
+
1083
+ tmp.set(next);
1084
+ tmp.sub(v);
1085
+ tmp.normalize();
1086
+ tmp.mul(step);
1087
+
1088
+ // calculate next size
1089
+ mindist = Double.MAX_VALUE;
1090
+
1091
+ double nextsize = pointFlow.minimumSize;
1092
+
1093
+ if (i > 1)
1094
+ {
1095
+ cVector w = pointFlow.points.get(i-2);
1096
+
1097
+ double dist = w.distance(next);
1098
+
1099
+ if (mindist > dist)
1100
+ {
1101
+ mindist = dist;
1102
+ nextsize = mindist*pointFlow.resizefactor;
1103
+ }
1104
+ }
1105
+
1106
+ double dist = v.distance(next);
1107
+
1108
+ if (mindist > dist)
1109
+ {
1110
+ mindist = dist;
1111
+ nextsize = mindist*pointFlow.resizefactor;
1112
+ }
1113
+
1114
+ if (nextsize < pointFlow.minimumSize)
1115
+ nextsize = pointFlow.minimumSize;
1116
+ if (nextsize > pointFlow.maximumSize)
1117
+ nextsize = pointFlow.maximumSize;
1118
+ //
1119
+
1120
+ double count = 0;
1121
+
1122
+ while (distancenext > 0.000000001) // step
1123
+ {
1124
+ gl.glPushMatrix();
1125
+
1126
+ gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
1127
+
1128
+ double K = count/nbsteps;
1129
+
1130
+ double intersize = K*nextsize + (1-K)*size;
1131
+
1132
+ gl.glScaled(intersize,intersize,intersize);
1133
+
1134
+ pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
1135
+
1136
+ count++;
1137
+
1138
+ distancenext -= step;
1139
+
1140
+ gl.glPopMatrix();
1141
+ }
1142
+
1143
+ if (count != nbsteps)
1144
+ assert(count == nbsteps);
1145
+
1146
+ // gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
1147
+ //gl.glTranslatef(-tx,-ty,-tz);
1148
+
1149
+ gl.glMatrixMode(gl.GL_TEXTURE);
1150
+ gl.glPopMatrix();
1151
+ }
1152
+
1153
+ if (!cf)
1154
+ gl.glDisable(gl.GL_CULL_FACE);
1155
+
1156
+// display.modelParams0[0] = r;
1157
+// display.modelParams0[1] = g;
1158
+// display.modelParams0[2] = b;
1159
+//
1160
+// display.modelParams5[1] = opacity;
1161
+//
1162
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
1163
+// gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
1164
+
1165
+ gl.glMatrixMode(gl.GL_MODELVIEW);
1166
+ }
1167
+
1168
+ public void DrawBox(cVector min, cVector max)
1169
+ {
1170
+ javax.media.opengl.GL gl = GetGL();
1171
+ gl.glBegin(gl.GL_LINES);
1172
+
1173
+ gl.glVertex3d(min.x, min.y, min.z);
1174
+ gl.glVertex3d(min.x, min.y, max.z);
1175
+ gl.glVertex3d(min.x, min.y, min.z);
1176
+ gl.glVertex3d(min.x, max.y, min.z);
1177
+ gl.glVertex3d(min.x, min.y, min.z);
1178
+ gl.glVertex3d(max.x, min.y, min.z);
1179
+
1180
+ gl.glVertex3d(max.x, max.y, max.z);
1181
+ gl.glVertex3d(min.x, max.y, max.z);
1182
+ gl.glVertex3d(max.x, max.y, max.z);
1183
+ gl.glVertex3d(max.x, min.y, max.z);
1184
+ gl.glVertex3d(max.x, max.y, max.z);
1185
+ gl.glVertex3d(max.x, max.y, min.z);
1186
+
1187
+ gl.glEnd();
1188
+ }
1189
+
1190
+ public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
1191
+ {
1192
+ int[] strips = bRep.getRawIndices();
1193
+
1194
+ javax.media.opengl.GL gl = GetGL();
1195
+
1196
+ // TRIANGLE STRIP ARRAY
1197
+ if (bRep.trimmed)
1198
+ {
1199
+ float[] v = bRep.getRawVertices();
1200
+ float[] n = bRep.getRawNormals();
1201
+ float[] c = bRep.getRawColors();
1202
+ float[] uv = bRep.getRawUVMap();
1203
+
1204
+ int count2 = 0;
1205
+ int count3 = 0;
1206
+
1207
+ if (n.length > 0)
1208
+ {
1209
+ for (int i = 0; i < strips.length; i++)
1210
+ {
1211
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1212
+
1213
+ /*
1214
+ boolean locked = false;
1215
+ float eps = 0.1f;
1216
+ boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
1217
+
1218
+ int dot = 0;
1219
+
1220
+ if ((dot&1) == 0)
1221
+ dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
1222
+
1223
+ if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
1224
+ gl.glTexCoord2f((float) qv.s, (float) qv.t);
1225
+ else
1226
+ {
1227
+ locked = true;
1228
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1229
+ }
1230
+ //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
1231
+ gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
1232
+ if (hasnorm)
1233
+ {
1234
+ //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
1235
+ gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
1236
+ }
1237
+
1238
+ if ((dot&4) == 0)
1239
+ dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
1240
+
1241
+ if (wrap || !locked && (dot&8) != 0)
1242
+ gl.glTexCoord2f((float) rv.s, (float) rv.t);
1243
+ else
1244
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1245
+
1246
+ f.dot = dot;
1247
+ */
1248
+
1249
+ if (!selectmode)
1250
+ {
1251
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1252
+ {
1253
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1254
+ } else
1255
+ {
1256
+ gl.glNormal3f(0, 0, 1);
1257
+ }
1258
+
1259
+ if (c != null)
1260
+ //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
1261
+ {
1262
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1263
+ }
1264
+ }
1265
+
1266
+ if (flipV)
1267
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1268
+ else
1269
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1270
+
1271
+ //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1272
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1273
+
1274
+ count2 += 2;
1275
+ count3 += 3;
1276
+ if (!selectmode)
1277
+ {
1278
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1279
+ {
1280
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1281
+ } else
1282
+ {
1283
+ gl.glNormal3f(0, 0, 1);
1284
+ }
1285
+ if (c != null)
1286
+ {
1287
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1288
+ }
1289
+ }
1290
+
1291
+ if (flipV)
1292
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1293
+ else
1294
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1295
+
1296
+ //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
1297
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1298
+
1299
+ count2 += 2;
1300
+ count3 += 3;
1301
+ for (int j = 0; j < strips[i] - 2; j++)
1302
+ {
1303
+ //gl.glTexCoord2d(...);
1304
+ if (!selectmode)
1305
+ {
1306
+ if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
1307
+ {
1308
+ gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
1309
+ } else
1310
+ {
1311
+ gl.glNormal3f(0, 0, 1);
1312
+ }
1313
+ if (c != null)
1314
+ {
1315
+ gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
1316
+ }
1317
+ }
1318
+
1319
+ if (flipV)
1320
+ gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
1321
+ else
1322
+ gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
1323
+
1324
+ //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
1325
+ gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
1326
+
1327
+ count2 += 2;
1328
+ count3 += 3;
1329
+ }
1330
+
1331
+ gl.glEnd();
1332
+ }
1333
+ }
1334
+
1335
+ assert count3 == v.length;
1336
+ }
1337
+ else // !trimmed
1338
+ {
1339
+ int count = 0;
1340
+ for (int i = 0; i < strips.length; i++)
1341
+ {
1342
+ gl.glBegin(gl.GL_TRIANGLE_STRIP);
1343
+
1344
+ Vertex p = bRep.GetVertex(bRep.indices[count++]);
1345
+ Vertex q = bRep.GetVertex(bRep.indices[count++]);
1346
+
1347
+ drawVertex(gl, p, flipV, selectmode);
1348
+ drawVertex(gl, q, flipV, selectmode);
1349
+
1350
+ for (int j = 0; j < strips[i] - 2; j++)
1351
+ {
1352
+ Vertex r = bRep.GetVertex(bRep.indices[count++]);
1353
+
1354
+ // if (j%2 == 0)
1355
+ // drawFace(p, q, r, display, null);
1356
+ // else
1357
+ // drawFace(p, r, q, display, null);
1358
+
1359
+ // p = q;
1360
+ // q = r;
1361
+ drawVertex(gl, r, flipV, selectmode);
1362
+ }
1363
+
1364
+ gl.glEnd();
1365
+ }
1366
+ }
1367
+ }
1368
+
1369
+ static cSpring.Point3D temp = new cSpring.Point3D();
1370
+ static cSpring.Point3D temp2 = new cSpring.Point3D();
1371
+ static cSpring.Point3D temp3 = new cSpring.Point3D();
1372
+
1373
+ public void DrawDynamicMesh(cMesh mesh)
1374
+ {
1375
+ GL gl = GetGL(); // getGL();
1376
+
1377
+ cSpring.PhysicsController3D Phys = mesh.Phys;
1378
+
1379
+ gl.glDisable(gl.GL_LIGHTING);
1380
+
1381
+ gl.glLineWidth(1);
1382
+ gl.glColor3f(1,1,1);
1383
+ gl.glBegin(gl.GL_LINES);
1384
+ double scale = 0;
1385
+ int count = 0;
1386
+ for (int s=0; s<Phys.allSprings.size(); s++)
1387
+ {
1388
+ cSpring.Spring spring = Phys.allSprings.get(s);
1389
+ if(s == 0)
1390
+ {
1391
+ //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
1392
+ }
1393
+ if (mesh.showsprings)
1394
+ {
1395
+ temp.set(spring.a.position);
1396
+ temp.add(spring.b.position);
1397
+ temp.mul(0.5);
1398
+ temp2.set(spring.a.position);
1399
+ temp2.sub(spring.b.position);
1400
+ temp2.mul(spring.restLength/2);
1401
+ temp.sub(temp2);
1402
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1403
+ temp.add(temp2);
1404
+ temp.add(temp2);
1405
+ gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
1406
+ }
1407
+
1408
+ if (spring.isHandle)
1409
+ continue;
1410
+
1411
+ //if (scale < spring.restLength)
1412
+ scale += spring.restLength;
1413
+ count++;
1414
+ }
1415
+ gl.glEnd();
1416
+
1417
+ if (count == 0)
1418
+ scale = 0.01;
1419
+ else
1420
+ scale /= count * 3;
1421
+
1422
+ //scale = 0.25;
1423
+
1424
+ if (mesh.ShowInfo())
1425
+ {
1426
+ gl.glLineWidth(4);
1427
+ for (int s=0; s<Phys.allNodes.size(); s++)
1428
+ {
1429
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1430
+ if (node.mass == 0)
1431
+ continue;
1432
+
1433
+ int i = node.springs==null?-1:node.springs.size();
1434
+ gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
1435
+ //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
1436
+ //temp.normalize();
1437
+ //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
1438
+ gl.glBegin(gl.GL_LINES);
1439
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1440
+ //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
1441
+ gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
1442
+ node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
1443
+ node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
1444
+ gl.glEnd();
1445
+ }
1446
+
1447
+ gl.glLineWidth(8);
1448
+ for (int s=0; s<Phys.allNodes.size(); s++)
1449
+ {
1450
+ cSpring.DynamicNode node = Phys.allNodes.get(s);
1451
+
1452
+ if (node.springs != null)
1453
+ {
1454
+ for (int i=0; i<node.springs.size(); i+=1)
1455
+ {
1456
+ cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
1457
+
1458
+ int c = i+1;
1459
+ // c = node.springs.get(i).nbcopies;
1460
+
1461
+ gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
1462
+ gl.glBegin(gl.GL_LINES);
1463
+ gl.glVertex3d(node.position.x, node.position.y, node.position.z);
1464
+ 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);
1465
+ gl.glEnd();
1466
+ }
1467
+ }
1468
+ }
1469
+
1470
+ gl.glLineWidth(1);
1471
+ }
1472
+
1473
+ gl.glEnable(gl.GL_LIGHTING);
1474
+ }
1475
+
5691476 /// INTERFACE
5701477
1478
+ public void StartTriangles()
1479
+ {
1480
+ javax.media.opengl.GL gl = GetGL();
1481
+ gl.glBegin(gl.GL_TRIANGLES);
1482
+ }
1483
+
1484
+ public void EndTriangles()
1485
+ {
1486
+ GetGL().glEnd();
1487
+ }
1488
+
1489
+ void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
1490
+ {
1491
+ if (!selectmode)
1492
+ {
1493
+ gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
1494
+ gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
1495
+
1496
+ if (flipV)
1497
+ gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
1498
+ else
1499
+ gl.glTexCoord2f((float) pv.s, (float) pv.t);
1500
+ }
1501
+
1502
+ gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
1503
+ }
1504
+
1505
+ float[] colorV = new float[4];
1506
+
5711507 void SetColor(Object3D obj, Vertex p0)
5721508 {
5731509 CameraPane display = this;
....@@ -635,8 +1571,6 @@
6351571 {
6361572 return;
6371573 }
638
-
639
- float[] colorV = new float[3];
6401574
6411575 if (false) // marked)
6421576 {
....@@ -745,7 +1679,7 @@
7451679 // gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
7461680 }
7471681
748
- void DrawMaterial(cMaterial material, boolean selected)
1682
+ void DrawMaterial(cMaterial material, boolean selected, Object3D.cVector2[] others)
7491683 {
7501684 CameraPane display = this;
7511685 //new Exception().printStackTrace();
....@@ -761,18 +1695,18 @@
7611695 //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
7621696 if (!material.multiply)
7631697 {
764
- display.color = color;
1698
+ display.color = material.color;
7651699 display.saturation = material.modulation;
7661700 }
7671701 else
7681702 {
769
- display.color *= color*2;
1703
+ display.color *= material.color*2;
7701704 display.saturation *= material.modulation*2;
7711705 }
7721706
7731707 cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
7741708
775
- float[] colorV = GrafreeD.colorV;
1709
+ float[] colorV = Grafreed.colorV;
7761710
7771711 /**/
7781712 if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
....@@ -780,7 +1714,7 @@
7801714 colorV[0] = display.modelParams0[0] * material.diffuse;
7811715 colorV[1] = display.modelParams0[1] * material.diffuse;
7821716 colorV[2] = display.modelParams0[2] * material.diffuse;
783
- colorV[3] = material.opacity;
1717
+ colorV[3] = 1; // material.opacity;
7841718
7851719 gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
7861720 //System.out.println("Opacity = " + opacity);
....@@ -888,9 +1822,9 @@
8881822 display.modelParams7[2] = 0;
8891823 display.modelParams7[3] = 0;
8901824
891
- display.modelParams6[0] = 100; // criss de bug de bump
1825
+ //display.modelParams6[0] = 100; // criss de bug de bump
8921826
893
- Object3D.cVector2[] extparams = display.vector2buffer;
1827
+ Object3D.cVector2[] extparams = others; // display.vector2buffer;
8941828 if (extparams != null && extparams.length > 0 && extparams[0] != null)
8951829 {
8961830 display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
....@@ -1032,7 +1966,7 @@
10321966 void PushMatrix(double[][] matrix)
10331967 {
10341968 // GrafreeD.tracein(matrix);
1035
- PushMatrix(matrix,1);
1969
+ PushMatrix(matrix, 1);
10361970 }
10371971
10381972 void PushMatrix()
....@@ -1129,7 +2063,7 @@
11292063
11302064 static int camerachangeframe;
11312065
1132
- boolean SetCamera(Camera cam)
2066
+ public boolean SetCamera(Camera cam)
11332067 {
11342068 // may 2014 if (cam == cameras[0] || cam == cameras[1])
11352069 // return false;
....@@ -1186,7 +2120,7 @@
11862120 //System.err.println("Oeil on");
11872121 OEIL = true;
11882122 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
1189
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
2123
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11902124 //pingthread.StepToTarget(true);
11912125 }
11922126
....@@ -1257,33 +2191,6 @@
12572191 mainDL ^= true;
12582192 }
12592193
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
-
12872194 void ToggleFullScreen()
12882195 {
12892196 FULLSCREEN ^= true;
....@@ -1294,72 +2201,94 @@
12942201 Globals.CROWD ^= true;
12952202 }
12962203
1297
- void ToggleInertia()
1298
- {
1299
- INERTIA ^= true;
1300
- }
1301
-
13022204 void ToggleLocal()
13032205 {
13042206 LOCALTRANSFORM ^= true;
13052207 }
13062208
1307
- void ToggleFast()
2209
+ public void ToggleTexture()
2210
+ {
2211
+ textureon ^= true;
2212
+ }
2213
+
2214
+ public void ToggleLive()
2215
+ {
2216
+ Globals.setLIVE(Globals.isLIVE() ^ true);
2217
+
2218
+ System.err.println("LIVE = " + Globals.isLIVE());
2219
+
2220
+ if (!Globals.isLIVE()) // save sound
2221
+ Grafreed.savesound = true; // wav.save();
2222
+ // else
2223
+ repaint(); // start loop // may 2013
2224
+ }
2225
+
2226
+ public void ToggleSupport()
2227
+ {
2228
+ SUPPORT ^= true;
2229
+ }
2230
+
2231
+ public void ToggleAbort()
2232
+ {
2233
+ ABORTMODE ^= true;
2234
+ }
2235
+
2236
+ public void ToggleInertia()
2237
+ {
2238
+ INERTIA ^= true;
2239
+ }
2240
+
2241
+ public void ToggleFast()
13082242 {
13092243 FAST ^= true;
13102244 }
13112245
1312
- void ToggleSlowPose()
2246
+ public void ToggleSlowPose()
13132247 {
13142248 SLOWPOSE ^= true;
13152249 }
13162250
1317
- void ToggleFootContact()
1318
- {
1319
- FOOTCONTACT ^= true;
1320
- }
1321
-
1322
- void ToggleBoxMode()
2251
+ public void ToggleBoxMode()
13232252 {
13242253 BOXMODE ^= true;
13252254 }
13262255
1327
- void ToggleSmoothFocus()
2256
+ public void ToggleZoomBoxMode()
2257
+ {
2258
+ ZOOMBOXMODE ^= true;
2259
+ }
2260
+
2261
+ public void ToggleSmoothFocus()
13282262 {
13292263 SMOOTHFOCUS ^= true;
13302264 }
13312265
1332
- void ToggleImageFlip()
2266
+ public void ToggleImageFlip()
13332267 {
13342268 IMAGEFLIP ^= true;
13352269 }
13362270
1337
- void ToggleSpeakerMocap()
2271
+ public void ToggleSpeakerMocap()
13382272 {
13392273 SPEAKERMOCAP ^= true;
13402274 }
13412275
1342
- void ToggleSpeakerCamera()
2276
+ public void ToggleSpeakerCamera()
13432277 {
13442278 SPEAKERCAMERA ^= true;
13452279 }
13462280
1347
- void ToggleSpeakerFocus()
2281
+ public void ToggleSpeakerFocus()
13482282 {
13492283 SPEAKERFOCUS ^= true;
13502284 }
13512285
1352
- void ToggleDebug()
1353
- {
1354
- DEBUG ^= true;
1355
- }
1356
-
1357
- void ToggleFrustum()
2286
+ public void ToggleFrustum()
13582287 {
13592288 FRUSTUM ^= true;
13602289 }
13612290
1362
- void ToggleTrack()
2291
+ public void ToggleTrack()
13632292 {
13642293 TRACK ^= true;
13652294 if (TRACK)
....@@ -1378,25 +2307,35 @@
13782307 repaint();
13792308 }
13802309
1381
- void ToggleTrackOnce()
2310
+ public void ToggleTrackOnce()
13822311 {
13832312 TRACKONCE ^= true;
13842313 }
13852314
1386
- void ToggleShadowTrack()
2315
+ public void ToggleShadowTrack()
13872316 {
13882317 SHADOWTRACK ^= true;
13892318 repaint();
13902319 }
13912320
1392
- void ToggleOeil()
2321
+ public void ToggleOeil()
13932322 {
13942323 OEIL ^= true;
13952324 }
13962325
1397
- void ToggleOeilOnce()
2326
+ public void ToggleOeilOnce()
13982327 {
13992328 OEILONCE ^= true;
2329
+ }
2330
+
2331
+ void ToggleFootContact()
2332
+ {
2333
+ FOOTCONTACT ^= true;
2334
+ }
2335
+
2336
+ void ToggleDebug()
2337
+ {
2338
+ Globals.DEBUG ^= true;
14002339 }
14012340
14022341 void ToggleLookAt()
....@@ -1404,9 +2343,9 @@
14042343 LOOKAT ^= true;
14052344 }
14062345
1407
- void ToggleRandom()
2346
+ void ToggleSwitch()
14082347 {
1409
- RANDOM ^= true;
2348
+ SWITCH ^= true;
14102349 }
14112350
14122351 void ToggleHandles()
....@@ -1414,10 +2353,17 @@
14142353 HANDLES ^= true;
14152354 }
14162355
2356
+ Object3D paintFolder;
2357
+
14172358 void TogglePaint()
14182359 {
14192360 PAINTMODE ^= true;
14202361 paintcount = 0;
2362
+
2363
+ if (PAINTMODE)
2364
+ {
2365
+ paintFolder = GetFolder();
2366
+ }
14212367 }
14222368
14232369 void SwapCamera(int a, int b)
....@@ -1513,7 +2459,22 @@
15132459 {
15142460 return currentGL;
15152461 }
1516
-
2462
+
2463
+ static private BufferedImage CreateBim(TextureData texturedata)
2464
+ {
2465
+ Grafreed.Assert(texturedata != null);
2466
+
2467
+ int width = texturedata.getWidth();
2468
+ int height = texturedata.getHeight();
2469
+
2470
+ Buffer buffer = texturedata.getBuffer();
2471
+ ByteBuffer bytebuf = (ByteBuffer)buffer;
2472
+
2473
+ byte[] bytes = bytebuf.array();
2474
+
2475
+ return CreateBim(bytes, width, height);
2476
+ }
2477
+
15172478 /**/
15182479 class CacheTexture
15192480 {
....@@ -1522,28 +2483,31 @@
15222483
15232484 int resolution;
15242485
1525
- CacheTexture(com.sun.opengl.util.texture.Texture tex, int res)
2486
+ CacheTexture(com.sun.opengl.util.texture.TextureData texdata, int res)
15262487 {
1527
- texture = tex;
2488
+ texture = com.sun.opengl.util.texture.TextureIO.newTexture(texdata);
2489
+ texturedata = texdata;
15282490 resolution = res;
15292491 }
15302492 }
15312493 /**/
15322494
15332495 // 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>();
2496
+ static public Hashtable<cTexture, CacheTexture> texturepigment = new Hashtable<cTexture, CacheTexture>();
2497
+ static public Hashtable<cTexture, CacheTexture> texturebump = new Hashtable<cTexture, CacheTexture>();
2498
+ static public Hashtable<byte[], CacheTexture> bimtextures = new Hashtable<byte[], CacheTexture>();
2499
+ static public java.util.HashSet<cTexture> usedtextures = new java.util.HashSet<cTexture>();
2500
+
15372501 int pigmentdepth = 0;
15382502 public com.sun.opengl.util.texture.Texture[] pigmentstack = new com.sun.opengl.util.texture.Texture[65536];
15392503 int bumpdepth = 0;
15402504 public com.sun.opengl.util.texture.Texture[] bumpstack = new com.sun.opengl.util.texture.Texture[65536];
15412505 //public static String DEFAULT_TEXTURE = "DEFAULT_TEXTURE";
15422506 public static cTexture DEFAULT_TEXTURES = new cTexture("DEFAULT_TEXTURE" + ":" + "DEFAULT_TEXTURE_BUMP");
1543
- public static String NOISE_TEXTURE = "WHITE_NOISE";
2507
+ public static cTexture NOISE_TEXTURE = new cTexture("WHITE_NOISE:");
15442508 // public static cTexture IMMORTAL_TEXTURE = new cTexture("IMMORTAL");
15452509
1546
- com.sun.opengl.util.texture.Texture GetResourceTexture(String name, boolean bump)
2510
+ com.sun.opengl.util.texture.TextureData GetResourceTexture(String name, boolean bump)
15472511 {
15482512 TextureData texturedata = null;
15492513
....@@ -1553,7 +2517,7 @@
15532517 com.sun.opengl.util.texture.TextureIO.newTextureData(
15542518 getClass().getClassLoader().getResourceAsStream(name),
15552519 true,
1556
- com.sun.opengl.util.texture.TextureIO.PNG);
2520
+ GetFormat(name)); // com.sun.opengl.util.texture.TextureIO.PNG);
15572521 } catch (java.io.IOException e)
15582522 {
15592523 throw new javax.media.opengl.GLException(e);
....@@ -1562,13 +2526,34 @@
15622526 if (bump)
15632527 texturedata = ConvertBump(texturedata, false);
15642528
1565
- com.sun.opengl.util.texture.Texture texture =
1566
- com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
2529
+// com.sun.opengl.util.texture.Texture texture =
2530
+// com.sun.opengl.util.texture.TextureIO.newTexture(texturedata);
15672531
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);
2532
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_S, javax.media.opengl.GL.GL_REPEAT);
2533
+ //texture.setTexParameteri(javax.media.opengl.GL.GL_TEXTURE_WRAP_T, javax.media.opengl.GL.GL_REPEAT);
15702534
1571
- return texture;
2535
+ return texturedata;
2536
+ }
2537
+
2538
+ com.sun.opengl.util.texture.TextureData GetBimTexture(BufferedImage bim, boolean bump)
2539
+ {
2540
+ TextureData texturedata = null;
2541
+
2542
+ try
2543
+ {
2544
+ texturedata =
2545
+ com.sun.opengl.util.texture.TextureIO.newTextureData(
2546
+ bim,
2547
+ true);
2548
+ } catch (Exception e)
2549
+ {
2550
+ throw new javax.media.opengl.GLException(e);
2551
+ }
2552
+
2553
+ if (bump)
2554
+ texturedata = ConvertBump(texturedata, false);
2555
+
2556
+ return texturedata;
15722557 }
15732558
15742559 boolean HUESMOOTH = true; // wrap around bug... true;
....@@ -2641,6 +3626,8 @@
26413626
26423627 System.out.println("LOADING TEXTURE : " + name);
26433628
3629
+ Object x = texturedata.getMipmapData(); // .getBuffer();
3630
+
26443631 //
26453632 if (false) // compressbit > 0)
26463633 {
....@@ -3345,6 +4332,7 @@
33454332
33464333 com.sun.opengl.util.texture.Texture CompressTexture2(String name)
33474334 {
4335
+ new Exception().printStackTrace();
33484336 System.exit(0);
33494337 com.sun.opengl.util.texture.Texture texture = null;
33504338
....@@ -7038,7 +8026,7 @@
70388026 String pigment = Object3D.GetPigment(tex);
70398027 String bump = Object3D.GetBump(tex);
70408028
7041
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8029
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
70428030 {
70438031 // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
70448032 // System.out.println("; bump = " + bump);
....@@ -7053,11 +8041,69 @@
70538041 pigment = null;
70548042 }
70558043
7056
- ReleaseTexture(bump, true);
7057
- ReleaseTexture(pigment, false);
8044
+ ReleaseTexture(tex, true);
8045
+ ReleaseTexture(tex, false);
70588046 }
70598047
7060
- void ReleaseTexture(String tex, boolean bump)
8048
+ public void ReleasePigmentTexture(cTexture tex) // INTERFACE
8049
+ {
8050
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8051
+ {
8052
+ return;
8053
+ }
8054
+
8055
+ if (tex == null)
8056
+ {
8057
+ ReleaseTexture(null, false);
8058
+ return;
8059
+ }
8060
+
8061
+ String pigment = Object3D.GetPigment(tex);
8062
+
8063
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8064
+ {
8065
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8066
+ // System.out.println("; bump = " + bump);
8067
+ }
8068
+
8069
+ if (pigment.equals(""))
8070
+ {
8071
+ pigment = null;
8072
+ }
8073
+
8074
+ ReleaseTexture(tex, false);
8075
+ }
8076
+
8077
+ public void ReleaseBumpTexture(cTexture tex) // INTERFACE
8078
+ {
8079
+ if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
8080
+ {
8081
+ return;
8082
+ }
8083
+
8084
+ if (tex == null)
8085
+ {
8086
+ ReleaseTexture(null, true);
8087
+ return;
8088
+ }
8089
+
8090
+ String bump = Object3D.GetBump(tex);
8091
+
8092
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8093
+ {
8094
+ // System.out.print("RELEASE +++++++++++++++ pigment = " + pigment);
8095
+ // System.out.println("; bump = " + bump);
8096
+ }
8097
+
8098
+ if (bump.equals(""))
8099
+ {
8100
+ bump = null;
8101
+ }
8102
+
8103
+ ReleaseTexture(tex, true);
8104
+ }
8105
+
8106
+ void ReleaseTexture(cTexture tex, boolean bump)
70618107 {
70628108 if (// DrawMode() != 0 || /*tex == null ||*/
70638109 ambientOcclusion ) // || !textureon)
....@@ -7068,7 +8114,7 @@
70688114 CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
70698115
70708116 if (tex != null)
7071
- texture = textures.get(tex);
8117
+ texture = bump ? texturebump.get(tex) : texturepigment.get(tex);
70728118
70738119 // //assert( texture != null );
70748120 // if (texture == null)
....@@ -7160,7 +8206,55 @@
71608206 }
71618207 }
71628208
7163
- /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
8209
+ /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
8210
+ {
8211
+// if (// DrawMode() != 0 || /*tex == null ||*/
8212
+// ambientOcclusion ) // || !textureon)
8213
+// {
8214
+// return; // false;
8215
+// }
8216
+//
8217
+// if (tex == null)
8218
+// {
8219
+// BindTexture(null,false,resolution);
8220
+// BindTexture(null,true,resolution);
8221
+// return;
8222
+// }
8223
+//
8224
+// String pigment = Object3D.GetPigment(tex);
8225
+// String bump = Object3D.GetBump(tex);
8226
+//
8227
+// usedtextures.add(pigment);
8228
+// usedtextures.add(bump);
8229
+//
8230
+// //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8231
+// {
8232
+// // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8233
+// // System.out.println("; bump = " + bump);
8234
+// }
8235
+//
8236
+// if (bump.equals(""))
8237
+// {
8238
+// bump = null;
8239
+// }
8240
+// if (pigment.equals(""))
8241
+// {
8242
+// pigment = null;
8243
+// }
8244
+//
8245
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8246
+// BindTexture(pigment, false, resolution);
8247
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
8248
+// BindTexture(bump, true, resolution);
8249
+// GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8250
+//
8251
+// return; // true;
8252
+
8253
+ BindPigmentTexture(tex, resolution);
8254
+ BindBumpTexture(tex, resolution);
8255
+ }
8256
+
8257
+ /*boolean*/ public void BindPigmentTexture(cTexture tex, int resolution) throws Exception // INTERFACE
71648258 {
71658259 if (// DrawMode() != 0 || /*tex == null ||*/
71668260 ambientOcclusion ) // || !textureon)
....@@ -7171,17 +8265,47 @@
71718265 if (tex == null)
71728266 {
71738267 BindTexture(null,false,resolution);
7174
- BindTexture(null,true,resolution);
71758268 return;
71768269 }
71778270
71788271 String pigment = Object3D.GetPigment(tex);
8272
+
8273
+ usedtextures.add(tex);
8274
+
8275
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8276
+ {
8277
+ // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
8278
+ // System.out.println("; bump = " + bump);
8279
+ }
8280
+
8281
+ if (pigment.equals(""))
8282
+ {
8283
+ pigment = null;
8284
+ }
8285
+
8286
+ GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
8287
+ BindTexture(tex, false, resolution);
8288
+ }
8289
+
8290
+ /*boolean*/ public void BindBumpTexture(cTexture tex, int resolution) throws Exception // INTERFACE
8291
+ {
8292
+ if (// DrawMode() != 0 || /*tex == null ||*/
8293
+ ambientOcclusion ) // || !textureon)
8294
+ {
8295
+ return; // false;
8296
+ }
8297
+
8298
+ if (tex == null)
8299
+ {
8300
+ BindTexture(null,true,resolution);
8301
+ return;
8302
+ }
8303
+
71798304 String bump = Object3D.GetBump(tex);
71808305
7181
- usedtextures.put(pigment, pigment);
7182
- usedtextures.put(bump, bump);
8306
+ usedtextures.add(tex);
71838307
7184
- if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
8308
+ //if (!tex.equals(":") && !tex.equals(DEFAULT_TEXTURES))
71858309 {
71868310 // System.out.print("BIND +++++++++++++++ pigment = " + pigment);
71878311 // System.out.println("; bump = " + bump);
....@@ -7191,43 +8315,94 @@
71918315 {
71928316 bump = null;
71938317 }
7194
- if (pigment.equals(""))
7195
- {
7196
- pigment = null;
7197
- }
71988318
7199
- GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7200
- BindTexture(pigment, false, resolution);
72018319 GetGL().glActiveTexture(GetGL().GL_TEXTURE2);
7202
- BindTexture(bump, true, resolution);
8320
+ BindTexture(tex, true, resolution);
72038321 GetGL().glActiveTexture(GetGL().GL_TEXTURE0);
7204
-
7205
- return; // true;
72068322 }
72078323
7208
- CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
8324
+ java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
8325
+
8326
+ private boolean FileExists(String tex)
72098327 {
7210
- CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
8328
+ if (missingTextures.contains(tex))
8329
+ {
8330
+ return false;
8331
+ }
8332
+
8333
+ boolean fileExists = new File(tex).exists();
8334
+
8335
+ if (!fileExists)
8336
+ {
8337
+ // If file exists, the "new File()" is not executed sgain
8338
+ missingTextures.add(tex);
8339
+ }
8340
+
8341
+ return fileExists;
8342
+ }
8343
+
8344
+ CacheTexture GetCacheTexture(cTexture tex, boolean bump, int resolution) throws Exception
8345
+ {
8346
+ CacheTexture texturecache = null;
72118347
72128348 if (tex != null)
72138349 {
7214
- String texname = tex;
8350
+ String texname = bump ? Object3D.GetBump(tex) : Object3D.GetPigment(tex);
8351
+ byte[] texdata = bump ? tex.bumpdata : tex.pigmentdata;
72158352
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;
8353
+ if (texname.equals("") && texdata == null)
8354
+ {
8355
+ return null;
8356
+ }
8357
+
8358
+ String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
8359
+
8360
+// String[] split = tex.split("Textures");
8361
+// if (split.length > 1)
8362
+// texname = "/Users/nbriere/Textures" + split[split.length-1];
8363
+// else
8364
+// if (!texname.startsWith("/"))
8365
+// texname = "/Users/nbriere/Textures/" + texname;
8366
+ if (!FileExists(texname) && !texname.startsWith("@"))
8367
+ {
8368
+ texname = fallbackTextureName;
8369
+ }
72228370
72238371 if (CACHETEXTURE)
7224
- texture = textures.get(texname); // TEXTURE CACHE
7225
-
7226
- TextureData texturedata = null;
7227
-
7228
- if (texture == null || texture.resolution < resolution)
72298372 {
7230
- if (tex.equals("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
8373
+ if (texdata == null)
8374
+ texturecache = bump ? texturebump.get(tex) : texturepigment.get(tex);
8375
+ else
8376
+ texturecache = bimtextures.get(texdata);
8377
+ }
8378
+
8379
+ if (texturecache == null || texturecache.resolution != -1 && texturecache.resolution < resolution)
8380
+ {
8381
+ TextureData texturedata = null;
8382
+
8383
+ if (texdata != null && textureon)
8384
+ {
8385
+ BufferedImage bim; // = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8386
+
8387
+ try
8388
+ {
8389
+ bim = DecompressJPEG(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8390
+ }
8391
+ catch (Exception e)
8392
+ {
8393
+ bim = CreateBim(texdata, bump?tex.bw:tex.pw, bump?tex.bh:tex.ph);
8394
+ }
8395
+
8396
+ texturecache = new CacheTexture(GetBimTexture(bim, bump), -1);
8397
+ bimtextures.put(texdata, texturecache);
8398
+
8399
+ //BufferedImage bim3 = new BufferedImage(bump?tex.bw:tex.pw, bump?tex.bh:tex.ph, BufferedImage.TYPE_INT_RGB);
8400
+
8401
+ //Object bim2 = CreateBim(texturecache.texturedata);
8402
+ //bim2 = bim;
8403
+ }
8404
+ else
8405
+ if (texname.endsWith("DEFAULT_TEXTURE")) // ||*/ tex.equals(""))
72318406 {
72328407 assert(!bump);
72338408 // if (bump)
....@@ -7238,19 +8413,23 @@
72388413 // }
72398414 // else
72408415 // {
7241
- texture = textures.get(tex);
7242
- if (texture == null)
8416
+ // texturecache = textures.get(texname); // suspicious
8417
+ if (texturecache == null)
72438418 {
7244
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8419
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
72458420 }
8421
+ else
8422
+ new Exception().printStackTrace();
72468423 // }
72478424 } else
7248
- if (tex.equals("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
8425
+ if (texname.endsWith("DEFAULT_TEXTURE_BUMP")) // ||*/ tex.equals(""))
72498426 {
72508427 assert(bump);
7251
- texture = textures.get(tex);
7252
- if (texture == null)
7253
- texture = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8428
+ // texturecache = textures.get(texname); // suspicious
8429
+ if (texturecache == null)
8430
+ texturecache = new CacheTexture(GetResourceTexture("default.png", bump),resolution);
8431
+ else
8432
+ new Exception().printStackTrace();
72548433 } else
72558434 {
72568435 //if (tex.equals("IMMORTAL"))
....@@ -7258,11 +8437,22 @@
72588437 // texture = GetResourceTexture("default.png");
72598438 //} else
72608439 //{
7261
- if (tex.equals("WHITE_NOISE"))
8440
+ if (texname.endsWith("WHITE_NOISE"))
72628441 {
7263
- texture = textures.get(tex);
7264
- if (texture == null)
7265
- texture = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8442
+ // texturecache = textures.get(texname); // suspicious
8443
+ if (texturecache == null)
8444
+ texturecache = new CacheTexture(GetResourceTexture("whitenoise.png", bump),resolution);
8445
+ else
8446
+ new Exception().printStackTrace();
8447
+ } else
8448
+ {
8449
+ if (texname.startsWith("@"))
8450
+ {
8451
+ // texturecache = textures.get(texname); // suspicious
8452
+ if (texturecache == null)
8453
+ texturecache = new CacheTexture(GetResourceTexture(texname.substring(1), bump),resolution);
8454
+ else
8455
+ new Exception().printStackTrace();
72668456 } else
72678457 {
72688458 if (textureon)
....@@ -7287,7 +8477,7 @@
72878477 }
72888478
72898479 cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
7290
- if (!new File(cachename).exists())
8480
+ if (!FileExists(cachename))
72918481 cachename = texname;
72928482 else
72938483 processbump = false; // don't process bump map again
....@@ -7309,7 +8499,7 @@
73098499 }
73108500
73118501 cachename = texname.substring(0, texname.length()-4)+ext+".png";
7312
- if (!new File(cachename).exists())
8502
+ if (!FileExists(cachename))
73138503 cachename = texname;
73148504 else
73158505 processbump = false; // don't process bump map again
....@@ -7318,20 +8508,23 @@
73188508 texturedata = GetFileTexture(cachename, processbump, resolution);
73198509
73208510
7321
- if (texturedata != null)
7322
- texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
8511
+ if (texturedata == null)
8512
+ throw new Exception();
8513
+
8514
+ texturecache = new CacheTexture(texturedata,resolution);
73238515 //texture = GetTexture(tex, bump);
73248516 }
8517
+ }
73258518 }
73268519 //}
73278520 }
73288521
7329
- if (/*CACHETEXTURE &&*/ texture != null && textureon)
8522
+ if (texdata == null && /*CACHETEXTURE &&*/ texturecache != null && textureon)
73308523 {
73318524 //return false;
73328525
73338526 // System.out.println("CACHE +++++++++++++++ TEXTURE : " + texname + " (" + texture.getEstimatedMemorySize() + ")");
7334
- if (texturedata != null && (texname.endsWith(".jpg") || texname.endsWith(".JPG")))
8527
+ if (texturedata != null && texname.toLowerCase().endsWith(".jpg"))
73358528 {
73368529 // String ext = "_highres";
73378530 // if (REDUCETEXTURE)
....@@ -7348,52 +8541,17 @@
73488541 File cachefile = new File(texname.substring(0, texname.length()-4)+ext+".jpg");
73498542 if (!cachefile.exists())
73508543 {
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))
8544
+ //if (texturedata.getWidth() == texturedata.getHeight())
73608545 {
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);
8546
+ BufferedImage rendImage = CreateBim(texturedata);
8547
+
73918548 ImageWriter writer = null;
73928549 Iterator iter = ImageIO.getImageWritersByFormatName("jpg");
73938550 if (iter.hasNext()) {
73948551 writer = (ImageWriter)iter.next();
73958552 }
7396
- float compressionQuality = 0.9f;
8553
+
8554
+ float compressionQuality = 0.85f;
73978555 try
73988556 {
73998557 ImageOutputStream ios = ImageIO.createImageOutputStream(cachefile);
....@@ -7410,18 +8568,20 @@
74108568 }
74118569 }
74128570 }
7413
-
8571
+
8572
+ Hashtable<cTexture, CacheTexture> textures = bump ? texturebump : texturepigment;
8573
+
74148574 //System.out.println("Texture = " + tex);
7415
- if (textures.containsKey(texname))
8575
+ if (textures.containsKey(tex))
74168576 {
7417
- CacheTexture thetex = textures.get(texname);
8577
+ CacheTexture thetex = textures.get(tex);
74188578 thetex.texture.disable();
74198579 thetex.texture.dispose();
7420
- textures.remove(texname);
8580
+ textures.remove(tex);
74218581 }
74228582
7423
- texture.texturedata = texturedata;
7424
- textures.put(texname, texture);
8583
+ //texture.texturedata = texturedata;
8584
+ textures.put(tex, texturecache);
74258585
74268586 // newtex = true;
74278587 }
....@@ -7437,10 +8597,44 @@
74378597 }
74388598 }
74398599
7440
- return texture;
8600
+ return texturecache;
74418601 }
74428602
7443
- com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
8603
+ static void EmbedTextures(cTexture tex)
8604
+ {
8605
+ if (tex.pigmentdata == null)
8606
+ {
8607
+ //String texname = Object3D.GetPigment(tex);
8608
+
8609
+ CacheTexture texturecache = texturepigment.get(tex);
8610
+
8611
+ if (texturecache != null)
8612
+ {
8613
+ tex.pw = texturecache.texturedata.getWidth();
8614
+ tex.ph = texturecache.texturedata.getHeight();
8615
+ tex.pigmentdata = //CompressJPEG(CreateBim
8616
+ ((ByteBuffer)texturecache.texturedata.getBuffer()).array()
8617
+ ;
8618
+ //, tex.pw, tex.ph), 0.5f);
8619
+ }
8620
+ }
8621
+
8622
+ if (tex.bumpdata == null)
8623
+ {
8624
+ //String texname = Object3D.GetBump(tex);
8625
+
8626
+ CacheTexture texturecache = texturebump.get(tex);
8627
+
8628
+ if (texturecache != null)
8629
+ {
8630
+ tex.bw = texturecache.texturedata.getWidth();
8631
+ tex.bh = texturecache.texturedata.getHeight();
8632
+ tex.bumpdata = CompressJPEG(CreateBim(((ByteBuffer)texturecache.texturedata.getBuffer()).array(), tex.bw, tex.bh), 0.5f);
8633
+ }
8634
+ }
8635
+ }
8636
+
8637
+ com.sun.opengl.util.texture.Texture GetTexture(cTexture tex, boolean bump, int resolution) throws Exception
74448638 {
74458639 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
74468640
....@@ -7458,21 +8652,21 @@
74588652 return texture!=null?texture.texture:null;
74598653 }
74608654
7461
- com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
8655
+ public com.sun.opengl.util.texture.TextureData GetTextureData(cTexture tex, boolean bump, int resolution) throws Exception
74628656 {
74638657 CacheTexture texture = GetCacheTexture(tex, bump, resolution);
74648658
74658659 return texture!=null?texture.texturedata:null;
74668660 }
74678661
7468
- boolean BindTexture(String tex, boolean bump, int resolution)
8662
+ boolean BindTexture(cTexture tex, boolean bump, int resolution) throws Exception
74698663 {
74708664 if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
74718665 {
74728666 return false;
74738667 }
74748668
7475
- boolean newtex = false;
8669
+ //boolean newtex = false;
74768670
74778671 com.sun.opengl.util.texture.Texture texture = GetTexture(tex, bump, resolution);
74788672
....@@ -7504,9 +8698,75 @@
75048698 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_S, GetGL().GL_REPEAT);
75058699 texture.setTexParameteri(GetGL().GL_TEXTURE_WRAP_T, GetGL().GL_REPEAT);
75068700
7507
- return newtex;
8701
+ return true; // Warning: not used.
75088702 }
75098703
8704
+ public static byte[] CompressJPEG(BufferedImage image, float quality)
8705
+ {
8706
+ try
8707
+ {
8708
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
8709
+ Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
8710
+ ImageWriter writer = writers.next();
8711
+
8712
+ ImageWriteParam param = writer.getDefaultWriteParam();
8713
+ param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
8714
+ param.setCompressionQuality(quality);
8715
+
8716
+ ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
8717
+ writer.setOutput(ios);
8718
+ writer.write(null, new IIOImage(image, null, null), param);
8719
+
8720
+ byte[] data = baos.toByteArray();
8721
+ writer.dispose();
8722
+ return data;
8723
+ }
8724
+ catch (Exception e)
8725
+ {
8726
+ e.printStackTrace();
8727
+ return null;
8728
+ }
8729
+ }
8730
+
8731
+ public static BufferedImage DecompressJPEG(byte[] image, int w, int h) throws IOException
8732
+ {
8733
+ ByteArrayInputStream baos = new ByteArrayInputStream(image);
8734
+ Iterator<ImageReader> writers = ImageIO.getImageReadersByFormatName("jpg");
8735
+ ImageReader reader = writers.next();
8736
+
8737
+ BufferedImage bim = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
8738
+
8739
+ ImageReadParam param = reader.getDefaultReadParam();
8740
+ param.setDestination(bim);
8741
+ //param.setDestinationType(ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB));
8742
+
8743
+ ImageInputStream ios = ImageIO.createImageInputStream(baos);
8744
+ reader.setInput(ios);
8745
+ BufferedImage bim2 = reader.read(0, param);
8746
+ reader.dispose();
8747
+
8748
+// WritableRaster raster = bim2.getRaster();
8749
+// DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
8750
+// byte[] bytes = data.getData();
8751
+//
8752
+// int[] pixels = new int[bytes.length/3];
8753
+// for (int i=pixels.length; --i>=0;)
8754
+// {
8755
+// int i3 = i*3;
8756
+// pixels[i] = 0xFF;
8757
+// pixels[i] <<= 8;
8758
+// pixels[i] |= bytes[i3+2] & 0xFF;
8759
+// pixels[i] <<= 8;
8760
+// pixels[i] |= bytes[i3+1] & 0xFF;
8761
+// pixels[i] <<= 8;
8762
+// pixels[i] |= bytes[i3] & 0xFF;
8763
+// }
8764
+//
8765
+// bim.setRGB(0,0,w,h, pixels, w*(h-1),-w);
8766
+
8767
+ return bim;
8768
+ }
8769
+
75108770 ShadowBuffer shadowPBuf;
75118771 AntialiasBuffer antialiasPBuf;
75128772 int MAXSTACK;
....@@ -7523,10 +8783,12 @@
75238783
75248784 gl.glGetIntegerv(GL.GL_MAX_TEXTURE_STACK_DEPTH, temp, 0);
75258785 MAXSTACK = temp[0];
7526
- System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
8786
+ if (Globals.DEBUG)
8787
+ System.out.println("GL_MAX_TEXTURE_STACK_DEPTH = " + MAXSTACK);
75278788 gl.glGetIntegerv(GL.GL_MAX_MODELVIEW_STACK_DEPTH, temp, 0);
75288789 MAXSTACK = temp[0];
7529
- System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
8790
+ if (Globals.DEBUG)
8791
+ System.out.println("GL_MAX_MODELVIEW_STACK_DEPTH = " + MAXSTACK);
75308792
75318793 // Use debug pipeline
75328794 //drawable.setGL(new DebugGL(gl)); //
....@@ -7534,7 +8796,8 @@
75348796 gl = drawable.getGL(); //
75358797
75368798 GL gl3 = getGL();
7537
- System.out.println("INIT GL IS: " + gl.getClass().getName());
8799
+ if (Globals.DEBUG)
8800
+ System.out.println("INIT GL IS: " + gl.getClass().getName());
75388801
75398802
75408803 //float pos[] = { 100, 100, 100, 0 };
....@@ -7699,7 +8962,7 @@
76998962
77008963 if (cubemap == null)
77018964 {
7702
- LoadEnvy(5);
8965
+ //LoadEnvy(1);
77038966 }
77048967
77058968 //cubemap.enable();
....@@ -7975,6 +9238,8 @@
79759238
79769239 void LoadEnvy(int which)
79779240 {
9241
+ assert(false);
9242
+
79789243 String name;
79799244 String ext;
79809245
....@@ -7986,37 +9251,58 @@
79869251 cubemap = null;
79879252 return;
79889253 case 1:
7989
- name = "cubemaps/box_";
7990
- ext = "png";
9254
+ name = "cubemaps/rgb/";
9255
+ ext = "jpg";
79919256 reverseUP = false;
79929257 break;
79939258 case 2:
7994
- name = "cubemaps/uffizi_";
7995
- ext = "png";
7996
- break; // reverseUP = true; break;
9259
+ name = "cubemaps/uffizi/";
9260
+ ext = "jpg";
9261
+ reverseUP = false;
9262
+ break;
79979263 case 3:
7998
- name = "cubemaps/CloudyHills_";
7999
- ext = "tga";
9264
+ name = "cubemaps/CloudyHills/";
9265
+ ext = "jpg";
80009266 reverseUP = false;
80019267 break;
80029268 case 4:
8003
- name = "cubemaps/cornell_";
9269
+ name = "cubemaps/cornell/";
80049270 ext = "png";
80059271 reverseUP = false;
80069272 break;
9273
+ case 5:
9274
+ name = "cubemaps/skycube/";
9275
+ ext = "jpg";
9276
+ reverseUP = false;
9277
+ break;
9278
+ case 6:
9279
+ name = "cubemaps/SaintLazarusChurch3/";
9280
+ ext = "jpg";
9281
+ reverseUP = false;
9282
+ break;
9283
+ case 7:
9284
+ name = "cubemaps/Sodermalmsallen/";
9285
+ ext = "jpg";
9286
+ reverseUP = false;
9287
+ break;
9288
+ case 8:
9289
+ name = "cubemaps/Sodermalmsallen2/";
9290
+ ext = "jpg";
9291
+ reverseUP = false;
9292
+ break;
9293
+ case 9:
9294
+ name = "cubemaps/UnionSquare/";
9295
+ ext = "jpg";
9296
+ reverseUP = false;
9297
+ break;
80079298 default:
8008
- name = "cubemaps/rgb_";
8009
- ext = "png"; /*mipmap = true;*/ reverseUP = false;
9299
+ name = "cubemaps/box/";
9300
+ ext = "png"; /*mipmap = true;*/
9301
+ reverseUP = false;
80109302 break;
80119303 }
8012
-
8013
- try
8014
- {
8015
- cubemap = LoadCubemap(getClass().getClassLoader(), name, ext, mipmap);
8016
- } catch (IOException e)
8017
- {
8018
- throw new RuntimeException(e);
8019
- }
9304
+
9305
+ LoadSkybox(name, ext, mipmap);
80209306 }
80219307
80229308 public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
....@@ -8048,8 +9334,12 @@
80489334 static double[] model = new double[16];
80499335 double[] camera2light = new double[16];
80509336 double[] light2camera = new double[16];
8051
- int newenvy = -1;
8052
- boolean envyoff = true; // false;
9337
+
9338
+ //int newenvy = -1;
9339
+ //boolean envyoff = false;
9340
+
9341
+ String loadedskyboxname;
9342
+
80539343 cVector light0 = new cVector(0, 0, 0); // 1,3,2);
80549344 //float[] light0 = { 0,0,0 };
80559345 cVector dirlight = new cVector(0, 0, 1); // 1,3,2);
....@@ -8342,11 +9632,35 @@
83429632 jy8[3] = 0.5f;
83439633 }
83449634
8345
- float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
9635
+ float[] options1 = new float[]{100, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
83469636 float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
83479637 float[] options3 = new float[]{1, 1, 1, 0}; // fog color
83489638 float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
83499639
9640
+ void ResetOptions()
9641
+ {
9642
+ options1[0] = 100;
9643
+ options1[1] = 0.025f;
9644
+ options1[2] = 0.01f;
9645
+ options1[3] = 0;
9646
+ options1[4] = 0;
9647
+
9648
+ options2[0] = 0;
9649
+ options2[1] = 0.75f;
9650
+ options2[2] = 0;
9651
+ options2[3] = 0;
9652
+
9653
+ options3[0] = 1;
9654
+ options3[1] = 1;
9655
+ options3[2] = 1;
9656
+ options3[3] = 0;
9657
+
9658
+ options4[0] = 1;
9659
+ options4[1] = 0;
9660
+ options4[2] = 1;
9661
+ options4[3] = 0;
9662
+ }
9663
+
83509664 static int imagecount = 0; // movie generation
83519665
83529666 static int jitter = 0;
....@@ -8442,8 +9756,8 @@
84429756 assert (parentcam != renderCamera);
84439757
84449758 if (renderCamera != lightCamera)
8445
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8446
- LA.matConcat(matrix, parentcam.toParent, matrix);
9759
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9760
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
84479761
84489762 // LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
84499763
....@@ -8458,8 +9772,8 @@
84589772 LA.matCopy(renderCamera.fromScreen, matrix);
84599773
84609774 if (renderCamera != lightCamera)
8461
- for (int count = parentcam.GetTransformCount(); --count>=0;)
8462
- LA.matConcat(parentcam.fromParent, matrix, matrix);
9775
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
9776
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
84639777
84649778 // LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
84659779
....@@ -8505,10 +9819,12 @@
85059819 rati = 1 / rati;
85069820 gl.glOrtho(-skyscale / rati, skyscale / rati, -skyscale, skyscale, 0.001, 1000);
85079821 }
8508
- assert (newenvy == -1);
9822
+
9823
+ //assert (newenvy == -1);
9824
+
85099825 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
85109826 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
8511
- DrawSkyBox(gl);
9827
+ DrawSkyBox(gl, (float)rati);
85129828 gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
85139829 gl.glEnable(GL.GL_VERTEX_PROGRAM_ARB);
85149830 accPerspective(gl, renderCamera.shaper_fovy / ratio,
....@@ -8531,7 +9847,7 @@
85319847 //gl.glFlush();
85329848 gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
85339849
8534
- if (ANIMATION && ABORTED)
9850
+ if (Globals.ANIMATION && ABORTED)
85359851 {
85369852 System.err.println(" ABORTED FRAME");
85379853 break;
....@@ -8561,7 +9877,7 @@
85619877 setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
85629878
85639879 // save image
8564
- if (ANIMATION && !ABORTED)
9880
+ if (Globals.ANIMATION && !ABORTED)
85659881 {
85669882 VPwidth = viewport[2];
85679883 VPheight = viewport[3];
....@@ -8672,11 +9988,11 @@
86729988
86739989 // imagecount++;
86749990
8675
- String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
9991
+ String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
86769992
86779993 if (!BOXMODE)
86789994 {
8679
- System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
9995
+ System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
86809996 }
86819997
86829998 if (!BOXMODE)
....@@ -8714,7 +10030,7 @@
871410030 ABORTED = false;
871510031 }
871610032 else
8717
- GrafreeD.wav.cursor += 735 * ACSIZE;
10033
+ Grafreed.wav.cursor += 735 * ACSIZE;
871810034
871910035 if (false)
872010036 {
....@@ -9377,11 +10693,11 @@
937710693
937810694 public void display(GLAutoDrawable drawable)
937910695 {
9380
- if (GrafreeD.savesound && GrafreeD.hassound)
10696
+ if (Grafreed.savesound && Grafreed.hassound)
938110697 {
9382
- GrafreeD.wav.save();
9383
- GrafreeD.savesound = false;
9384
- GrafreeD.hassound = false;
10698
+ Grafreed.wav.save();
10699
+ Grafreed.savesound = false;
10700
+ Grafreed.hassound = false;
938510701 }
938610702 // if (DEBUG_SELECTION)
938710703 // {
....@@ -9457,6 +10773,7 @@
945710773 ANTIALIAS = 0;
945810774 //System.out.println("RESTART");
945910775 AAtimer.restart();
10776
+ Globals.TIMERRUNNING = true;
946010777 }
946110778 }
946210779 }
....@@ -9511,7 +10828,7 @@
951110828 Object3D theobject = object;
951210829 Object3D theparent = object.parent;
951310830 object.parent = null;
9514
- object = (Object3D)GrafreeD.clone(object);
10831
+ object = (Object3D)Grafreed.clone(object);
951510832 object.Stripify();
951610833 if (theobject.selection == null || theobject.selection.Size() == 0)
951710834 theobject.PreprocessOcclusion(this);
....@@ -9524,13 +10841,14 @@
952410841 ambientOcclusion = false;
952510842 }
952610843
9527
- if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
10844
+ if (//Globals.lighttouched &&
10845
+ DrawMode() == DEFAULT) // && !lightMode) // && !FROZEN)
952810846 {
952910847 //if (RENDERSHADOW) // ?
953010848 if (!IsFrozen())
953110849 {
953210850 // dec 2012
9533
- if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
10851
+ if (!ambientOcclusion && !(!flash && DrawMode() == DEFAULT && ANTIALIAS > 0))
953410852 {
953510853 Globals.framecount++;
953610854 shadowbuffer.display();
....@@ -9543,7 +10861,7 @@
954310861
954410862 if (wait)
954510863 {
9546
- Sleep(500);
10864
+ Sleep(200); // blocks everything
954710865
954810866 wait = false;
954910867 }
....@@ -9657,8 +10975,8 @@
965710975
965810976 // if (parentcam != renderCamera) // not a light
965910977 if (cam != lightCamera)
9660
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9661
- LA.matConcat(matrix, parentcam.toParent, matrix);
10978
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10979
+ LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
966210980
966310981 for (int j = 0; j < 4; j++)
966410982 {
....@@ -9672,8 +10990,8 @@
967210990
967310991 // if (parentcam != renderCamera) // not a light
967410992 if (cam != lightCamera)
9675
- for (int count = parentcam.GetTransformCount(); --count>=0;)
9676
- LA.matConcat(parentcam.fromParent, matrix, matrix);
10993
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
10994
+ LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
967710995
967810996 //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
967910997
....@@ -9759,13 +11077,43 @@
975911077 gl.glOrtho(-skyscale / ratio, skyscale / ratio, -skyscale, skyscale, 0.001, 1000);
976011078 }
976111079
9762
- if (newenvy > -1)
11080
+// if (newenvy > -1)
11081
+// {
11082
+// LoadEnvy(newenvy);
11083
+// }
11084
+//
11085
+// newenvy = -1;
11086
+
11087
+ if (transformMode) // object.skyboxname != null && object.skyboxname.equals("cubemaps/default-skyboxes/rgb"))
976311088 {
9764
- LoadEnvy(newenvy);
11089
+ if (cubemaprgb == null)
11090
+ {
11091
+ cubemaprgb = LoadSkybox("cubemaps/default-skyboxes/rgb" + "/", "jpg", false);
11092
+ }
11093
+
11094
+ cubemap = cubemaprgb;
976511095 }
9766
-
9767
- newenvy = -1;
9768
-
11096
+ else
11097
+ {
11098
+ if (object.skyboxname != null)
11099
+ {
11100
+ if (!object.skyboxname.equals(this.loadedskyboxname))
11101
+ {
11102
+ if (cubemap != null && cubemap != cubemaprgb)
11103
+ cubemap.dispose();
11104
+ cubemapcustom = LoadSkybox(object.skyboxname + "/", object.skyboxext, false);
11105
+ loadedskyboxname = object.skyboxname;
11106
+ }
11107
+ }
11108
+ else
11109
+ {
11110
+ cubemapcustom = null;
11111
+ loadedskyboxname = null;
11112
+ }
11113
+
11114
+ cubemap = cubemapcustom;
11115
+ }
11116
+
976911117 ratio = ((double) getWidth()) / getHeight();
977011118 //System.out.println("ratio = " + ratio);
977111119
....@@ -9781,7 +11129,7 @@
978111129
978211130 if (!IsFrozen() && !ambientOcclusion)
978311131 {
9784
- DrawSkyBox(gl);
11132
+ DrawSkyBox(gl, (float)ratio);
978511133 }
978611134
978711135 //if (selection_view == -1)
....@@ -9932,7 +11280,16 @@
993211280 // Bump noise
993311281 gl.glActiveTexture(GL.GL_TEXTURE6);
993411282 //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
9935
- BindTexture(NOISE_TEXTURE, false, 2);
11283
+
11284
+ try
11285
+ {
11286
+ BindTexture(NOISE_TEXTURE, false, 2);
11287
+ }
11288
+ catch (Exception e)
11289
+ {
11290
+ System.err.println("FAILED: " + NOISE_TEXTURE);
11291
+ }
11292
+
993611293
993711294 gl.glActiveTexture(GL.GL_TEXTURE0);
993811295 gl.glEnable(GL.GL_TEXTURE_2D);
....@@ -9955,9 +11312,9 @@
995511312
995611313 gl.glMatrixMode(GL.GL_MODELVIEW);
995711314
9958
-//gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
9959
-//gl.glEnable(gl.GL_POLYGON_SMOOTH);
9960
-//gl.glEnable(gl.GL_MULTISAMPLE);
11315
+gl.glEnable(gl.GL_POLYGON_SMOOTH);
11316
+gl.glHint(gl.GL_POLYGON_SMOOTH_HINT, gl.GL_NICEST);
11317
+gl.glEnable(gl.GL_MULTISAMPLE);
996111318 } else
996211319 {
996311320 //gl.glDisable(GL.GL_TEXTURE_2D);
....@@ -9968,7 +11325,7 @@
996811325 //System.out.println("BLENDING ON");
996911326 gl.glEnable(GL.GL_BLEND);
997011327 gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
9971
-
11328
+// gl.glBlendFunc(GL.GL_SRC_ALPHA_SATURATE, GL.GL_ONE);
997211329 gl.glMatrixMode(gl.GL_PROJECTION);
997311330 gl.glLoadIdentity();
997411331
....@@ -10057,8 +11414,8 @@
1005711414 System.err.println("parentcam != renderCamera");
1005811415
1005911416 // if (cam != lightCamera)
10060
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10061
- LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
11417
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11418
+ LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
1006211419 }
1006311420
1006411421 LA.xformDir(lightposition, cam.toScreen, lightposition);
....@@ -10079,8 +11436,8 @@
1007911436 if (true) // TODO
1008011437 {
1008111438 if (cam != lightCamera)
10082
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10083
- LA.xformDir(light0, parentcam.toParent, light0); // may 2013
11439
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
11440
+ LA.xformDir(light0, parentcam.GlobalTransform(), light0); // may 2013
1008411441 }
1008511442
1008611443 LA.xformPos(light0, cam.toScreen, light0);
....@@ -10146,7 +11503,7 @@
1014611503 fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
1014711504 //System.out.println("fragmentMode = " + fragmentMode);
1014811505
10149
- if (DrawMode() == DEFAULT || DrawMode() == SELECTION || DEBUG_SELECTION)
11506
+ if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
1015011507 {
1015111508 /*
1015211509 if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
....@@ -10217,7 +11574,7 @@
1021711574 }
1021811575 }
1021911576
10220
- if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
11577
+ if (false) //RENDERPROGRAM > 0 && DrawMode() == DEFAULT) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
1022111578 {
1022211579 //gl.glDepthFunc(GL.GL_LEQUAL);
1022311580 //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
....@@ -10225,24 +11582,21 @@
1022511582
1022611583 boolean texon = textureon;
1022711584
10228
- if (RENDERPROGRAM > 0)
10229
- {
10230
- gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
10231
- textureon = false;
10232
- }
11585
+ gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
11586
+ textureon = false;
11587
+
1023311588 //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
1023411589 //System.out.println("ALLO");
1023511590 gl.glColorMask(false, false, false, false);
1023611591 DrawObject(gl);
10237
- if (RENDERPROGRAM > 0)
10238
- {
10239
- gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
10240
- textureon = texon;
10241
- }
11592
+
11593
+ gl.glEnable(GL.GL_FRAGMENT_PROGRAM_ARB);
11594
+ textureon = texon;
11595
+
1024211596 gl.glColorMask(true, true, true, true);
1024311597
1024411598 gl.glDepthFunc(GL.GL_EQUAL);
10245
- //gl.glDepthMask(false);
11599
+ gl.glDepthMask(false);
1024611600 }
1024711601
1024811602 if (false) // DrawMode() == SHADOW)
....@@ -10396,8 +11750,14 @@
1039611750 {
1039711751 renderpass++;
1039811752 // System.out.println("Draw object... ");
11753
+ STEP = 1;
1039911754 if (FAST) // in case there is no script
10400
- STEP = 16;
11755
+ STEP = 8;
11756
+
11757
+ if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
11758
+ {
11759
+ STEP *= 4;
11760
+ }
1040111761
1040211762 //object.FullInvariants();
1040311763
....@@ -10411,23 +11771,44 @@
1041111771 e.printStackTrace();
1041211772 }
1041311773
10414
- if (GrafreeD.RENDERME > 0)
10415
- GrafreeD.RENDERME--; // mechante magouille
11774
+ if (Grafreed.RENDERME > 0)
11775
+ Grafreed.RENDERME--; // mechante magouille
1041611776
1041711777 Globals.ONESTEP = false;
1041811778 }
1041911779
1042011780 static boolean zoomonce = false;
1042111781
11782
+ static void CreateSelectedPoint()
11783
+ {
11784
+ if (selectedpoint == null)
11785
+ {
11786
+ debugpointG = new Sphere();
11787
+ debugpointP = new Sphere();
11788
+ debugpointC = new Sphere();
11789
+ debugpointR = new Sphere();
11790
+
11791
+ selectedpoint = new Superellipsoid();
11792
+
11793
+ for (int i=0; i<8; i++)
11794
+ {
11795
+ debugpoints[i] = new Sphere();
11796
+ }
11797
+ }
11798
+ }
11799
+
1042211800 void DrawObject(GL gl, boolean draw)
1042311801 {
11802
+ // To clear camera values
11803
+ ResetOptions();
11804
+
1042411805 //System.out.println("DRAW OBJECT " + mouseDown);
1042511806 // DrawMode() = SELECTION;
1042611807 //GL gl = getGL();
1042711808 if ((TRACK || SHADOWTRACK) || zoomonce)
1042811809 {
1042911810 if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
10430
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
11811
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1043111812 pingthread.StepToTarget(true); // true);
1043211813 // zoomonce = false;
1043311814 }
....@@ -10447,7 +11828,7 @@
1044711828 callist = gl.glGenLists(1);
1044811829 }
1044911830
10450
- boolean selectmode = DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
11831
+ boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
1045111832
1045211833 boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
1045311834
....@@ -10482,7 +11863,14 @@
1048211863
1048311864 usedtextures.clear();
1048411865
10485
- BindTextures(DEFAULT_TEXTURES, 2);
11866
+ try
11867
+ {
11868
+ BindTextures(DEFAULT_TEXTURES, 2);
11869
+ }
11870
+ catch (Exception e)
11871
+ {
11872
+ System.err.println("FAILED: " + DEFAULT_TEXTURES);
11873
+ }
1048611874 }
1048711875 //System.out.println("--> " + stackdepth);
1048811876 // GrafreeD.traceon();
....@@ -10492,8 +11880,9 @@
1049211880
1049311881 if (DrawMode() == DEFAULT)
1049411882 {
10495
- if (DEBUG)
11883
+ if (Globals.DEBUG)
1049611884 {
11885
+ CreateSelectedPoint();
1049711886 float radius = 0.05f;
1049811887 if (selectedpoint.radius != radius)
1049911888 {
....@@ -10547,20 +11936,32 @@
1054711936 ReleaseTextures(DEFAULT_TEXTURES);
1054811937
1054911938 if (CLEANCACHE)
10550
- for (java.util.Enumeration<String> e = textures.keys() ; e.hasMoreElements();)
11939
+ for (java.util.Enumeration<cTexture> e = texturepigment.keys() ; e.hasMoreElements();)
1055111940 {
10552
- String tex = e.nextElement();
11941
+ cTexture tex = e.nextElement();
1055311942
1055411943 // System.out.println("Texture --------- " + tex);
1055511944
10556
- if (tex.equals("WHITE_NOISE"))
11945
+ if (tex.equals("WHITE_NOISE:"))
1055711946 continue;
1055811947
10559
- if (!usedtextures.containsKey(tex))
11948
+ if (!usedtextures.contains(tex))
1056011949 {
11950
+ CacheTexture gettex = texturepigment.get(tex);
1056111951 // System.out.println("DISPOSE +++++++++++++++ " + tex);
10562
- textures.get(tex).texture.dispose();
10563
- textures.remove(tex);
11952
+ if (gettex != null)
11953
+ {
11954
+ gettex.texture.dispose();
11955
+ texturepigment.remove(tex);
11956
+ }
11957
+
11958
+ gettex = texturebump.get(tex);
11959
+ // System.out.println("DISPOSE +++++++++++++++ " + tex);
11960
+ if (gettex != null)
11961
+ {
11962
+ gettex.texture.dispose();
11963
+ texturebump.remove(tex);
11964
+ }
1056411965 }
1056511966 }
1056611967 }
....@@ -10573,7 +11974,14 @@
1057311974 if (checker != null && DrawMode() == DEFAULT)
1057411975 {
1057511976 //BindTexture(IMMORTAL_TEXTURE);
10576
- BindTextures(checker.GetTextures(), checker.texres);
11977
+ try
11978
+ {
11979
+ BindTextures(checker.GetTextures(), checker.texres);
11980
+ }
11981
+ catch (Exception e)
11982
+ {
11983
+ System.err.println("FAILED: " + checker.GetTextures());
11984
+ }
1057711985 // NEAREST
1057811986 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
1057911987 DrawChecker(gl);
....@@ -10655,7 +12063,7 @@
1065512063 return;
1065612064 }
1065712065
10658
- String string = obj.GetToolTip();
12066
+ String string = obj.toString(); //.GetToolTip();
1065912067
1066012068 GL gl = GetGL();
1066112069
....@@ -10972,8 +12380,8 @@
1097212380 //obj.TransformToWorld(light, light);
1097312381 for (int i = tp.size(); --i >= 0;)
1097412382 {
10975
- for (int count = tp.get(i).GetTransformCount(); --count>=0;)
10976
- LA.xformPos(light, tp.get(i).toParent, light);
12383
+ //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
12384
+ LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
1097712385 }
1097812386
1097912387
....@@ -10990,8 +12398,8 @@
1099012398 parentcam = cameras[0];
1099112399 }
1099212400
10993
- for (int count = parentcam.GetTransformCount(); --count>=0;)
10994
- LA.xformPos(light, parentcam.toParent, light); // may 2013
12401
+ //for (int count = parentcam.GetTransformCount(); --count>=0;)
12402
+ LA.xformPos(light, parentcam.GlobalTransform(), light); // may 2013
1099512403
1099612404 LA.xformPos(light, renderCamera.toScreen, light);
1099712405
....@@ -11081,8 +12489,76 @@
1108112489
1108212490 //gl.glProgramEnvParameter4fvARB(GL.GL_FRAGMENT_PROGRAM_ARB, 127, lightParams, 0);
1108312491
11084
- String program =
12492
+ String programmin =
12493
+ // Min shader
1108512494 "!!ARBfp1.0\n" +
12495
+ "PARAM zero123 = { 0.0, 1.0, 2, 1.25 };" +
12496
+ "PARAM pow2 = { 0.5, 0.25, 0.125, 0.0 };" +
12497
+ "PARAM one = { 1.0, 1.0, 1.0, 1.0 };" +
12498
+ "PARAM eps = { 0.001, 0.001, 0.001, 1.0 };" +
12499
+ "PARAM infinity = { 100000000, 100000000, 100000000, 1.0 };" +
12500
+ "PARAM light2cam0 = program.env[10];" +
12501
+ "PARAM light2cam1 = program.env[11];" +
12502
+ "PARAM light2cam2 = program.env[12];" +
12503
+ "TEMP temp;" +
12504
+ "TEMP light;" +
12505
+ "TEMP ndotl;" +
12506
+ "TEMP normal;" +
12507
+ "TEMP depth;" +
12508
+ "TEMP eye;" +
12509
+ "TEMP pos;" +
12510
+
12511
+ "MAD normal, fragment.color, zero123.z, -zero123.y;" +
12512
+ Normalize("normal") +
12513
+ "MOV light, state.light[0].position;" +
12514
+ "DP3 ndotl.x, light, normal;" +
12515
+
12516
+ // shadow
12517
+ "MOV pos, fragment.texcoord[1];" +
12518
+ "MOV temp, pos;" +
12519
+ ShadowTextureFetch("depth", "temp", "1") +
12520
+ //"TEX depth, fragment.texcoord[1], texture[1], 2D;" +
12521
+ "SLT ndotl.z, fragment.texcoord[1].z, depth.z;" +
12522
+
12523
+ // No shadow when out of frustum
12524
+ //"SGE temp.y, depth.z, zero123.y;" +
12525
+ //"LRP temp.x, temp.y, zero123.y, temp.x;" +
12526
+
12527
+ "MUL ndotl.x, ndotl.x, ndotl.z;" + // Shadow
12528
+
12529
+ // Backlit
12530
+ "MOV pos.w, zero123.y;" +
12531
+ "DP4 eye.x, pos, light2cam0;" +
12532
+ "DP4 eye.y, pos, light2cam1;" +
12533
+ "DP4 eye.z, pos, light2cam2;" +
12534
+ Normalize("eye") +
12535
+
12536
+ "DP3 ndotl.y, -eye, normal;" +
12537
+ //"MUL ndotl.y, ndotl.y, pow2.x;" +
12538
+ "POW ndotl.y, ndotl.y, pow2.z;" + // backlit
12539
+ "SUB ndotl.y, zero123.y, ndotl.y;" +
12540
+ //"SUB ndotl.y, zero123.y, ndotl.y;" +
12541
+ //"MUL ndotl.y, ndotl.y, pow2.z;" +
12542
+
12543
+ //"MAX ndotl.x, ndotl.x, ndotl.y;" + // Ambient
12544
+ //"MAX ndotl.x, ndotl.x, pow2.y;" + // Ambient
12545
+
12546
+ // Pigment
12547
+ "TEX temp, fragment.texcoord[0], texture[0], 2D;" +
12548
+ "LRP temp, zero123.w, temp, one;" + // texture proportion
12549
+ "MUL temp, temp, ndotl.x;" +
12550
+
12551
+ "MUL temp, temp, zero123.z;" +
12552
+
12553
+ //"MUL temp, temp, ndotl.y;" +
12554
+
12555
+ "MOV temp.w, zero123.y;" + // reset alpha
12556
+ "MOV result.color, temp;" +
12557
+ "END";
12558
+
12559
+ String programmax =
12560
+ "!!ARBfp1.0\n" +
12561
+
1108612562 //"OPTION ARB_fragment_program_shadow;" +
1108712563 "PARAM light2cam0 = program.env[10];" +
1108812564 "PARAM light2cam1 = program.env[11];" +
....@@ -11197,8 +12673,7 @@
1119712673 "TEMP shininess;" +
1119812674 "\n" +
1119912675 "MOV texSamp, one;" +
11200
- //"TEX texSamp, fragment.texcoord[0], texture[0], 2D;" +
11201
-
12676
+
1120212677 "MOV mapgrid.x, one2048th.x;" +
1120312678 "MOV temp, fragment.texcoord[1];" +
1120412679 /*
....@@ -11219,20 +12694,20 @@
1121912694 "MUL temp, floor, mapgrid.x;" +
1122012695 //"TEX depth0, temp, texture[1], 2D;" +
1122112696 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11222
- TextureFetch("depth0", "temp", "1") +
12697
+ ShadowTextureFetch("depth0", "temp", "1") +
1122312698 "") +
1122412699 "ADD temp.x, temp.x, mapgrid.x;" +
1122512700 //"TEX depth1, temp, texture[1], 2D;" +
1122612701 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11227
- TextureFetch("depth1", "temp", "1") +
12702
+ ShadowTextureFetch("depth1", "temp", "1") +
1122812703 "") +
1122912704 "ADD temp.y, temp.y, mapgrid.x;" +
1123012705 //"TEX depth2, temp, texture[1], 2D;" +
11231
- TextureFetch("depth2", "temp", "1") +
12706
+ ShadowTextureFetch("depth2", "temp", "1") +
1123212707 "SUB temp.x, temp.x, mapgrid.x;" +
1123312708 //"TEX depth3, temp, texture[1], 2D;" +
1123412709 (((mode & FP_SOFTSHADOW) == 0) ? "" :
11235
- TextureFetch("depth3", "temp", "1") +
12710
+ ShadowTextureFetch("depth3", "temp", "1") +
1123612711 "") +
1123712712 //"MUL texSamp0, texSamp0, state.material.front.diffuse;" +
1123812713 //"MOV params, material;" +
....@@ -11603,10 +13078,10 @@
1160313078 "MAD shadow.x, buffer.x, frac.y, shadow.x;" +
1160413079 "") +
1160513080
11606
- // display shadow only (bump == 0)
13081
+ // display shadow only (fakedepth == 0)
1160713082 "SUB temp.x, half.x, shadow.x;" +
11608
- "MOV temp.y, -params6.x;" +
11609
- "SLT temp.z, temp.y, zero.x;" +
13083
+ "MOV temp.y, -params5.z;" + // params6.x;" +
13084
+ "SLT temp.z, temp.y, -c256i.x;" +
1161013085 "SUB temp.y, one.x, temp.z;" +
1161113086 "MUL temp.x, temp.x, temp.y;" +
1161213087 "KIL temp.x;" +
....@@ -11735,8 +13210,10 @@
1173513210 "MAX ndotl.x, ndotl.x, -ndotl.x;" +
1173613211
1173713212 "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
13213
+ // Tuning for default skin
13214
+ //"ADD temp.x, temp.x, options2.z;" + // lightsheen
13215
+ "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
13216
+ "ADD temp.y, one.y, options2.y;" + // subsurface
1174013217 "MUL temp.x, temp.x, temp.y;" +
1174113218
1174213219 "MUL saturation, saturation, temp.xxxx;" +
....@@ -11935,7 +13412,14 @@
1193513412 //once = true;
1193613413 }
1193713414
11938
- System.out.print("Program #" + mode + "; length = " + program.length());
13415
+ String program = programmax;
13416
+
13417
+ if (Globals.MINSHADER)
13418
+ {
13419
+ program = programmin;
13420
+ }
13421
+
13422
+ System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
1193913423 System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
1194013424 loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
1194113425
....@@ -12028,25 +13512,26 @@
1202813512 return out;
1202913513 }
1203013514
12031
- String TextureFetch(String dest, String src, String unit)
13515
+ // Also does frustum culling
13516
+ String ShadowTextureFetch(String dest, String src, String unit)
1203213517 {
1203313518 return "TEX " + dest + ", " + src + ", texture[" + unit + "], 2D;" +
1203413519 "SGE " + src + ".w, " + src + ".x, eps.x;" +
1203513520 "SGE " + src + ".z, " + src + ".y, eps.x;" +
13521
+ "SLT " + dest + ".x, " + src + ".x, one.x;" +
13522
+ "SLT " + dest + ".y, " + src + ".y, one.x;" +
1203613523 "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;" +
13524
+ "MUL " + src + ".w, " + dest + ".x, " + src + ".w;" +
13525
+ "MUL " + src + ".w, " + dest + ".y, " + src + ".w;" +
1204113526 //"SWZ buffer, temp, w,w,w,w;";
12042
- "MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
13527
+ //"MUL " + dest + ".z, " + dest + ".z, " + src + ".w;" +
1204313528 "SUB " + src + ".z, " + "one.x, " + src + ".w;" +
1204413529 //"MUL " + src + ".z, " + src + ".z, infinity.x;" +
1204513530 //"ADD " + dest + ".z, " + dest + ".z, " + src + ".z;";
12046
- "MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
13531
+ //"MAD " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1204713532
12048
- //"LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
12049
- //"LRP " + dest + ".z" + ", " + src + ".w, infinity.x," + dest + ".z;";
13533
+ //?? "LRP " + dest + ".z, " + src + ".w," + dest + ".z, infinity.x;";
13534
+ "LRP " + dest + ".z, " + src + ".z, infinity.x," + dest + ".z;";
1205013535 }
1205113536
1205213537 String Shadow(String depth, String shadow)
....@@ -12068,12 +13553,16 @@
1206813553
1206913554 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
1207013555 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
13556
+
13557
+ // Compare fragment depth in light space with shadowmap.
1207113558 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
1207213559 "SGE temp.y, temp.x, zero.x;" +
12073
- "SUB " + shadow + ".y, one.x, temp.y;" +
13560
+ "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
13561
+
13562
+ // Reverse comparison
1207413563 "SUB temp.x, one.x, temp.x;" +
1207513564 "MUL " + shadow + ".x, temp.x, temp.y;" +
12076
- "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
13565
+ "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
1207713566 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
1207813567
1207913568 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
....@@ -12087,6 +13576,10 @@
1208713576 // No shadow for backface
1208813577 "DP3 temp.x, normal, lightd;" +
1208913578 "SLT temp.x, temp.x, zero.x;" + // shadoweps
13579
+ "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
13580
+
13581
+ // No shadow when out of frustum
13582
+ "SGE temp.x, " + depth + ".z, one.z;" +
1209013583 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
1209113584 "";
1209213585 }
....@@ -12233,7 +13726,8 @@
1223313726 /*static*/ float[] modelParams5 = new float[]{0, 0, 0, 0}; // texture, opacity, fakedepth, shadowbias
1223413727 /*static*/ float[] modelParams6 = new float[]{0, 0, 0, 0}; // bump, noise, borderfade, fog punchthrough
1223513728 /*static*/ float[] modelParams7 = new float[]{0, 0, 0, 0}; // noise power, opacity power
12236
- Object3D.cVector2[] vector2buffer;
13729
+
13730
+ //Object3D.cVector2[] vector2buffer;
1223713731
1223813732 // IN : ndotl, ndoth, xxx, NdotL //, snininess, lightarea
1223913733 // OUT : diff, spec
....@@ -12249,9 +13743,10 @@
1224913743 "DP3 " + dest + ".z," + "normals," + "eye;" +
1225013744 "MAX " + dest + ".w," + dest + ".z," + "eps.x;" +
1225113745 //"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;" +
13746
+// "MUL " + dest + ".z," + "params2.w," + dest + ".x;" + // PRETTY HEURISTIC FOR VELVET
13747
+// "MUL " + dest + ".z," + dest + ".z," + dest + ".x;" +
13748
+
13749
+ "MOV " + dest + ".z," + "params2.w;" + // EXACT
1225513750 "POW " + dest + ".w," + dest + ".w," + dest + ".z;" +
1225613751 "RCP " + dest + ".w," + dest + ".w;" +
1225713752 //"RSQ " + dest + ".w," + dest + ".w;" +
....@@ -12645,7 +14140,7 @@
1264514140 public void mousePressed(MouseEvent e)
1264614141 {
1264714142 //System.out.println("mousePressed: " + e);
12648
- clickStart(e.getX(), e.getY(), e.getModifiersEx());
14143
+ clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1264914144 }
1265014145
1265114146 static long prevtime = 0;
....@@ -12672,6 +14167,7 @@
1267214167
1267314168 //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
1267414169
14170
+ if (BUTTONLESSWHEEL)
1267514171 if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
1267614172 {
1267714173 return;
....@@ -12680,7 +14176,7 @@
1268014176 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
1268114177
1268214178 // TIMER
12683
- if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
14179
+ if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
1268414180 {
1268514181 keepboxmode = BOXMODE;
1268614182 keepsupport = SUPPORT;
....@@ -12720,8 +14216,8 @@
1272014216 // mode |= META;
1272114217 //}
1272214218
12723
- SetMouseMode(WHEEL | e.getModifiersEx());
12724
- drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
14219
+ SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
14220
+ drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
1272514221 anchorX = ax;
1272614222 anchorY = ay;
1272714223 prevX = px;
....@@ -12755,6 +14251,7 @@
1275514251 else
1275614252 if (evt.getSource() == AAtimer)
1275714253 {
14254
+ Globals.TIMERRUNNING = false;
1275814255 if (mouseDown)
1275914256 {
1276014257 //new Exception().printStackTrace();
....@@ -12780,6 +14277,10 @@
1278014277 // LIVE = waslive;
1278114278 // wasliveok = true;
1278214279 // waslive = false;
14280
+
14281
+ // May 2019 Forget it:
14282
+ if (true)
14283
+ return;
1278314284
1278414285 // source == timer
1278514286 if (mouseDown)
....@@ -12810,7 +14311,7 @@
1281014311
1281114312 // fev 2014???
1281214313 if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
12813
- object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
14314
+ object.GetWindow().ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
1281414315 pingthread.StepToTarget(true); // true);
1281514316 }
1281614317 // if (!LIVE)
....@@ -12819,12 +14320,13 @@
1281914320
1282014321 javax.swing.Timer timer = new javax.swing.Timer(350, this);
1282114322
12822
- void clickStart(int x, int y, int modifiers)
14323
+ void clickStart(int x, int y, int modifiers, int modifiersex)
1282314324 {
1282414325 if (!wasliveok)
1282514326 return;
1282614327
1282714328 AAtimer.restart(); //
14329
+ Globals.TIMERRUNNING = true;
1282814330
1282914331 // waslive = LIVE;
1283014332 // LIVE = false;
....@@ -12836,7 +14338,7 @@
1283614338 // touched = true; // main DL
1283714339 if (isRenderer)
1283814340 {
12839
- SetMouseMode(modifiers);
14341
+ SetMouseMode(modifiers, modifiersex);
1284014342 }
1284114343
1284214344 selectX = anchorX = x;
....@@ -12849,7 +14351,7 @@
1284914351 clicked = true;
1285014352 hold = false;
1285114353
12852
- if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
14354
+ if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
1285314355 // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
1285414356 {
1285514357 // System.out.println("RESTART II " + modifiers);
....@@ -12874,14 +14376,15 @@
1287414376 drag = false;
1287514377 //System.out.println("Mouse DOWN");
1287614378 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);
14379
+ //ClickInfo info = new ClickInfo();
14380
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14381
+ object.clickInfo.pane = this;
14382
+ object.clickInfo.camera = renderCamera;
14383
+ object.clickInfo.x = x;
14384
+ object.clickInfo.y = y;
14385
+ object.clickInfo.modifiers = modifiersex;
14386
+ editObj = object.doEditClick(//info,
14387
+ 0);
1288514388 if (!editObj)
1288614389 {
1288714390 hasMarquee = true;
....@@ -12897,11 +14400,14 @@
1289714400
1289814401 public void mouseDragged(MouseEvent e)
1289914402 {
14403
+ Globals.MOUSEDRAGGED = true;
14404
+
14405
+ //System.out.println("mouseDragged: " + e);
1290014406 if (isRenderer)
1290114407 movingcamera = true;
14408
+
1290214409 //if (drawing)
1290314410 //return;
12904
- //System.out.println("mouseDragged: " + e);
1290514411 if ((e.getModifiersEx() & CTRL) != 0
1290614412 || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
1290714413 {
....@@ -12909,7 +14415,7 @@
1290914415 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1291014416 }
1291114417 else
12912
- drag(e.getX(), e.getY(), e.getModifiersEx());
14418
+ drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
1291314419
1291414420 //try { Thread.sleep(1); } catch (Exception ex) {}
1291514421 }
....@@ -12921,6 +14427,11 @@
1292114427 cVector tmp = new cVector();
1292214428 cVector tmp2 = new cVector();
1292314429 boolean isMoving;
14430
+
14431
+ public cVector TargetLookAt()
14432
+ {
14433
+ return targetLookAt;
14434
+ }
1292414435
1292514436 class PingThread extends Thread
1292614437 {
....@@ -13077,6 +14588,7 @@
1307714588
1307814589 public void run()
1307914590 {
14591
+ new Exception().printStackTrace();
1308014592 System.exit(0);
1308114593 for (;;)
1308214594 {
....@@ -13140,7 +14652,7 @@
1314014652 {
1314114653 Globals.lighttouched = true;
1314214654 }
13143
- drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
14655
+ drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
1314414656 }
1314514657 //else
1314614658 }
....@@ -13154,12 +14666,12 @@
1315414666 void GoDown(int mod)
1315514667 {
1315614668 MODIFIERS |= COMMAND;
13157
- /*
14669
+ /**/
1315814670 if((mod&SHIFT) == SHIFT)
13159
- manipCamera.RotatePosition(0, -speed);
14671
+ manipCamera.BackForth(0, -speed*delta, 0); // getWidth());
1316014672 else
13161
- manipCamera.BackForth(0, -speed*delta, getWidth());
13162
- */
14673
+ manipCamera.RotatePosition(0, -speed);
14674
+ /**/
1316314675 if ((mod & SHIFT) == SHIFT)
1316414676 {
1316514677 mouseMode = mouseMode; // VR??
....@@ -13175,12 +14687,12 @@
1317514687 void GoUp(int mod)
1317614688 {
1317714689 MODIFIERS |= COMMAND;
13178
- /*
14690
+ /**/
1317914691 if((mod&SHIFT) == SHIFT)
13180
- manipCamera.RotatePosition(0, speed);
14692
+ manipCamera.BackForth(0, speed*delta, 0); // getWidth());
1318114693 else
13182
- manipCamera.BackForth(0, speed*delta, getWidth());
13183
- */
14694
+ manipCamera.RotatePosition(0, speed);
14695
+ /**/
1318414696 if ((mod & SHIFT) == SHIFT)
1318514697 {
1318614698 mouseMode = mouseMode;
....@@ -13196,12 +14708,12 @@
1319614708 void GoLeft(int mod)
1319714709 {
1319814710 MODIFIERS |= COMMAND;
13199
- /*
14711
+ /**/
1320014712 if((mod&SHIFT) == SHIFT)
13201
- manipCamera.RotatePosition(speed, 0);
13202
- else
1320314713 manipCamera.Translate(speed*delta, 0, getWidth());
13204
- */
14714
+ else
14715
+ manipCamera.RotatePosition(speed, 0);
14716
+ /**/
1320514717 if ((mod & SHIFT) == SHIFT)
1320614718 {
1320714719 mouseMode = mouseMode;
....@@ -13217,12 +14729,12 @@
1321714729 void GoRight(int mod)
1321814730 {
1321914731 MODIFIERS |= COMMAND;
13220
- /*
14732
+ /**/
1322114733 if((mod&SHIFT) == SHIFT)
13222
- manipCamera.RotatePosition(-speed, 0);
13223
- else
1322414734 manipCamera.Translate(-speed*delta, 0, getWidth());
13225
- */
14735
+ else
14736
+ manipCamera.RotatePosition(-speed, 0);
14737
+ /**/
1322614738 if ((mod & SHIFT) == SHIFT)
1322714739 {
1322814740 mouseMode = mouseMode;
....@@ -13240,7 +14752,7 @@
1324014752 int X, Y;
1324114753 boolean SX, SY;
1324214754
13243
- void drag(int x, int y, int modifiers)
14755
+ void drag(int x, int y, int modifiers, int modifiersex)
1324414756 {
1324514757 if (IsFrozen())
1324614758 {
....@@ -13249,17 +14761,17 @@
1324914761
1325014762 drag = true; // NEW
1325114763
13252
- boolean continuous = (modifiers & COMMAND) == COMMAND;
14764
+ boolean continuous = (modifiersex & COMMAND) == COMMAND;
1325314765
1325414766 X = x;
1325514767 Y = y;
1325614768 // floating state for animation
13257
- MODIFIERS = modifiers;
13258
- modifiers &= ~1024;
14769
+ MODIFIERS = modifiersex;
14770
+ modifiersex &= ~1024;
1325914771 if (false) // modifiers != 0)
1326014772 {
1326114773 //new Exception().printStackTrace();
13262
- System.out.println("mouseDragged: " + modifiers);
14774
+ System.out.println("mouseDragged: " + modifiersex);
1326314775 System.out.println("SHIFT = " + SHIFT);
1326414776 System.out.println("CONTROL = " + COMMAND);
1326514777 System.out.println("META = " + META);
....@@ -13272,14 +14784,16 @@
1327214784 if (editObj)
1327314785 {
1327414786 drag = true;
13275
- ClickInfo info = new ClickInfo();
13276
- info.bounds.setBounds(0, 0,
14787
+ //ClickInfo info = new ClickInfo();
14788
+ object.clickInfo.bounds.setBounds(0, 0,
1327714789 (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);
14790
+ object.clickInfo.pane = this;
14791
+ object.clickInfo.camera = renderCamera;
14792
+ object.clickInfo.x = x;
14793
+ object.clickInfo.y = y;
14794
+ object //.GetWindow().copy
14795
+ .doEditDrag(//info,
14796
+ (modifiers & MouseEvent.BUTTON3_MASK) != 0);
1328314797 } else
1328414798 {
1328514799 if (x < startX)
....@@ -13428,23 +14942,27 @@
1342814942 }
1342914943 }
1343014944
14945
+// ClickInfo clickInfo = new ClickInfo();
14946
+
1343114947 public void mouseMoved(MouseEvent e)
1343214948 {
1343314949 //System.out.println("mouseMoved: " + e);
13434
-
1343514950 if (isRenderer)
1343614951 return;
1343714952
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;
14953
+ // Mouse cursor feedback
14954
+ object.clickInfo.x = e.getX();
14955
+ object.clickInfo.y = e.getY();
14956
+ object.clickInfo.modifiers = e.getModifiersEx();
14957
+ object.clickInfo.bounds.setBounds(0, 0, (int) (getBounds().width * zoom), (int) (getBounds().height * zoom));
14958
+ object.clickInfo.pane = this;
14959
+ object.clickInfo.camera = renderCamera;
1344514960 if (!isRenderer)
1344614961 {
13447
- if (object.editWindow.copy.doEditClick(ci, 0))
14962
+ //ObjEditor editWindow = object.editWindow;
14963
+ //Object3D copy = editWindow.copy;
14964
+ if (object.doEditClick(//clickInfo,
14965
+ 0))
1344814966 {
1344914967 setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
1345014968 } else
....@@ -13456,7 +14974,11 @@
1345614974
1345714975 public void mouseReleased(MouseEvent e)
1345814976 {
14977
+ Globals.MOUSEDRAGGED = false;
14978
+
1345914979 movingcamera = false;
14980
+ X = 0; // getBounds().width/2;
14981
+ Y = 0; // getBounds().height/2;
1346014982 //System.out.println("mouseReleased: " + e);
1346114983 clickEnd(e.getX(), e.getY(), e.getModifiersEx());
1346214984 }
....@@ -13479,9 +15001,9 @@
1347915001 boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
1348015002 boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
1348115003
13482
- if (control || command || IsFrozen())
15004
+// No delay if (control || command || IsFrozen())
1348315005 timeout = true;
13484
- else
15006
+// ?? May 2019 else
1348515007 // timer.setDelay((modifiers & 128) != 0?0:350);
1348615008 mouseDown = false;
1348715009 if (!control && !command) // june 2013
....@@ -13591,7 +15113,7 @@
1359115113 System.out.println("keyReleased: " + e);
1359215114 }
1359315115
13594
- void SetMouseMode(int modifiers)
15116
+ void SetMouseMode(int modifiers, int modifiersex)
1359515117 {
1359615118 //System.out.println("SetMouseMode = " + modifiers);
1359715119 //modifiers &= ~1024;
....@@ -13603,25 +15125,25 @@
1360315125 //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
1360415126 // return;
1360515127 //System.out.println("SetMode = " + modifiers);
13606
- if ((modifiers & WHEEL) == WHEEL)
15128
+ if ((modifiersex & WHEEL) == WHEEL)
1360715129 {
1360815130 mouseMode |= ZOOM;
1360915131 }
1361015132
1361115133 boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
13612
- if (capsLocked || (modifiers & META) == META)
15134
+ if (capsLocked) // || (modifiers & META) == META)
1361315135 {
1361415136 mouseMode |= VR; // BACKFORTH;
1361515137 }
13616
- if ((modifiers & CTRLCLICK) == CTRLCLICK)
15138
+ if ((modifiersex & CTRLCLICK) == CTRLCLICK)
1361715139 {
1361815140 mouseMode |= SELECT;
1361915141 }
13620
- if ((modifiers & COMMAND) == COMMAND)
15142
+ if ((modifiersex & COMMAND) == COMMAND)
1362115143 {
1362215144 mouseMode |= SELECT;
1362315145 }
13624
- if ((modifiers & SHIFT) == SHIFT || forcetranslate)
15146
+ if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
1362515147 {
1362615148 mouseMode &= ~VR;
1362715149 mouseMode |= TRANSLATE;
....@@ -13650,10 +15172,10 @@
1365015172
1365115173 if (isRenderer) //
1365215174 {
13653
- SetMouseMode(modifiers);
15175
+ SetMouseMode(0, modifiers);
1365415176 }
1365515177
13656
- theRenderer.keyPressed(key);
15178
+ Globals.theRenderer.keyPressed(key);
1365715179 }
1365815180
1365915181 int kompactbit = 4; // power bit
....@@ -13665,7 +15187,7 @@
1366515187 float SATPOW = 1; // 2; // 0.5f;
1366615188 float BRIPOW = 1; // 0.5f; // 0.5f;
1366715189
13668
- void keyPressed(int key)
15190
+ public void keyPressed(int key)
1366915191 {
1367015192 if (key >= '0' && key <= '5')
1367115193 clampbit = (key-'0');
....@@ -13712,7 +15234,8 @@
1371215234 // break;
1371315235 case 'T':
1371415236 CACHETEXTURE ^= true;
13715
- textures.clear();
15237
+ texturepigment.clear();
15238
+ texturebump.clear();
1371615239 // repaint();
1371715240 break;
1371815241 case 'Y':
....@@ -13797,7 +15320,9 @@
1379715320 case 'E' : COMPACT ^= true;
1379815321 repaint();
1379915322 break;
13800
- case 'W' : DEBUGHSB ^= true;
15323
+ case 'W' : // Wide Window (fullscreen)
15324
+ //DEBUGHSB ^= true;
15325
+ ObjEditor.theFrame.ToggleFullScreen();
1380115326 repaint();
1380215327 break;
1380315328 case 'u' : Udebug ^= true; Vdebug = false; NORMALdebug = false; programInitialized = false; repaint(); break;
....@@ -13822,8 +15347,8 @@
1382215347 RevertCamera();
1382315348 repaint();
1382415349 break;
13825
- case 'L':
1382615350 case 'l':
15351
+ //case 'L':
1382715352 if (lightMode)
1382815353 {
1382915354 lightMode = false;
....@@ -13887,20 +15412,24 @@
1388715412 OCCLUSION_CULLING ^= true;
1388815413 System.out.println("OCCLUSION CULLING = " + OCCLUSION_CULLING);
1388915414 break;
13890
- case '0': envyoff ^= true; repaint(); break;
15415
+ //case '0': envyoff ^= true; repaint(); break;
1389115416 case '1':
1389215417 case '2':
1389315418 case '3':
1389415419 case '4':
1389515420 case '5':
13896
- newenvy = Character.getNumericValue(key);
13897
- repaint();
13898
- break;
1389915421 case '6':
1390015422 case '7':
1390115423 case '8':
1390215424 case '9':
13903
- BGcolor = (key - '6')/3.f;
15425
+ if (true) // envyoff)
15426
+ {
15427
+ BGcolor = (key - '1')/8.f;
15428
+ }
15429
+ else
15430
+ {
15431
+ //newenvy = Character.getNumericValue(key);
15432
+ }
1390415433 repaint();
1390515434 break;
1390615435 case '!':
....@@ -13966,9 +15495,9 @@
1396615495 case '_':
1396715496 kompactbit = 5;
1396815497 break;
13969
- case '+':
13970
- kompactbit = 6;
13971
- break;
15498
+// case '+':
15499
+// kompactbit = 6;
15500
+// break;
1397215501 case ' ':
1397315502 lightMode ^= true;
1397415503 Globals.lighttouched = true;
....@@ -13980,13 +15509,14 @@
1398015509 case ESC:
1398115510 RENDERPROGRAM += 1;
1398215511 RENDERPROGRAM %= 3;
15512
+
1398315513 repaint();
1398415514 break;
1398515515 case 'Z':
1398615516 //RESIZETEXTURE ^= true;
1398715517 //break;
1398815518 case 'z':
13989
- RENDERSHADOW ^= true;
15519
+ Globals.RENDERSHADOW ^= true;
1399015520 Globals.lighttouched = true;
1399115521 repaint();
1399215522 break;
....@@ -14019,8 +15549,9 @@
1401915549 case DELETE:
1402015550 ClearSelection();
1402115551 break;
14022
- /*
1402315552 case '+':
15553
+
15554
+ /*
1402415555 //fontsize += 1;
1402515556 bbzoom *= 2;
1402615557 repaint();
....@@ -14037,17 +15568,17 @@
1403715568 case '=':
1403815569 IncDepth();
1403915570 //fontsize += 1;
14040
- object.editWindow.refreshContents(true);
15571
+ object.GetWindow().refreshContents(true);
1404115572 maskbit = 6;
1404215573 break;
1404315574 case '-': //if (PixelThreshold>1) PixelThreshold /= 2;
1404415575 DecDepth();
1404515576 maskbit = 5;
1404615577 //if(fontsize > 1) fontsize -= 1;
14047
- if (object.editWindow == null)
14048
- new Exception().printStackTrace();
14049
- else
14050
- object.editWindow.refreshContents(true);
15578
+// if (object.editWindow == null)
15579
+// new Exception().printStackTrace();
15580
+// else
15581
+ object.GetWindow().refreshContents(true);
1405115582 break;
1405215583 case '{':
1405315584 manipCamera.shaper_fovy /= 1.1;
....@@ -14102,6 +15633,7 @@
1410215633 }
1410315634 //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
1410415635 }
15636
+
1410515637 static double OCCLUSIONBOOST = 1; // 0.5;
1410615638
1410715639 void keyReleased(int key, int modifiers)
....@@ -14109,11 +15641,11 @@
1410915641 //mode = ROTATE;
1411015642 if ((MODIFIERS & COMMAND) == 0) // VR??
1411115643 {
14112
- SetMouseMode(modifiers);
15644
+ SetMouseMode(0, modifiers);
1411315645 }
1411415646 }
1411515647
14116
- protected void processKeyEvent(KeyEvent e)
15648
+ public void processKeyEvent(KeyEvent e)
1411715649 {
1411815650 switch (e.getID())
1411915651 {
....@@ -14243,8 +15775,9 @@
1424315775
1424415776 protected void processMouseMotionEvent(MouseEvent e)
1424515777 {
14246
- //System.out.println("processMouseMotionEvent: " + mouseMode);
14247
- if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15778
+ //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
15779
+ //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
15780
+ if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
1424815781 {
1424915782 mouseMoved(e);
1425015783 } else
....@@ -14269,11 +15802,12 @@
1426915802 }
1427015803 */
1427115804
14272
- object.editWindow.EditSelection();
15805
+ object.GetWindow().EditSelection(false);
1427315806 }
1427415807
1427515808 void SelectParent()
1427615809 {
15810
+ new Exception().printStackTrace();
1427715811 System.exit(0);
1427815812 Composite group = (Composite) object;
1427915813 java.util.Vector selectees = new java.util.Vector(group.selection);
....@@ -14285,10 +15819,10 @@
1428515819 {
1428615820 //selectees.remove(i);
1428715821 System.out.println("select parent of " + elem);
14288
- group.editWindow.Select(elem.parent.GetTreePath(), first, true);
15822
+ group.GetWindow().Select(elem.parent.GetTreePath(), first, true);
1428915823 } else
1429015824 {
14291
- group.editWindow.Select(elem.GetTreePath(), first, true);
15825
+ group.GetWindow().Select(elem.GetTreePath(), first, true);
1429215826 }
1429315827
1429415828 first = false;
....@@ -14297,6 +15831,7 @@
1429715831
1429815832 void SelectChildren()
1429915833 {
15834
+ new Exception().printStackTrace();
1430015835 System.exit(0);
1430115836 /*
1430215837 Composite group = (Composite) object;
....@@ -14329,12 +15864,12 @@
1432915864 for (int j = 0; j < group.children.size(); j++)
1433015865 {
1433115866 elem = (Object3D) group.children.elementAt(j);
14332
- object.editWindow.Select(elem.GetTreePath(), first, true);
15867
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1433315868 first = false;
1433415869 }
1433515870 } else
1433615871 {
14337
- object.editWindow.Select(elem.GetTreePath(), first, true);
15872
+ object.GetWindow().Select(elem.GetTreePath(), first, true);
1433815873 }
1433915874
1434015875 first = false;
....@@ -14345,21 +15880,21 @@
1434515880 {
1434615881 //Composite group = (Composite) object;
1434715882 Object3D group = object;
14348
- group.editWindow.loadClipboard(true); // ClearSelection(false);
15883
+ group.GetWindow().loadClipboard(true); // ClearSelection(false);
1434915884 }
1435015885
1435115886 void ResetTransform(int mask)
1435215887 {
1435315888 //Composite group = (Composite) object;
1435415889 Object3D group = object;
14355
- group.editWindow.ResetTransform(mask);
15890
+ group.GetWindow().ResetTransform(mask);
1435615891 }
1435715892
1435815893 void FlipTransform()
1435915894 {
1436015895 //Composite group = (Composite) object;
1436115896 Object3D group = object;
14362
- group.editWindow.FlipTransform();
15897
+ group.GetWindow().FlipTransform();
1436315898 // group.editWindow.ReduceMesh(true);
1436415899 }
1436515900
....@@ -14367,7 +15902,7 @@
1436715902 {
1436815903 //Composite group = (Composite) object;
1436915904 Object3D group = object;
14370
- group.editWindow.PrintMemory();
15905
+ group.GetWindow().PrintMemory();
1437115906 // group.editWindow.ReduceMesh(true);
1437215907 }
1437315908
....@@ -14375,7 +15910,7 @@
1437515910 {
1437615911 //Composite group = (Composite) object;
1437715912 Object3D group = object;
14378
- group.editWindow.ResetCentroid();
15913
+ group.GetWindow().ResetCentroid();
1437915914 }
1438015915
1438115916 void IncDepth()
....@@ -14457,11 +15992,11 @@
1445715992
1445815993 int width = getBounds().width;
1445915994 int height = getBounds().height;
14460
- ClickInfo info = new ClickInfo();
14461
- info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
1446215995 //Image img = CreateImage(width, height);
1446315996 //System.out.println("width = " + width + "; height = " + height + "\n");
15997
+
1446415998 Graphics gr = g; // img.getGraphics();
15999
+
1446516000 if (!hasMarquee)
1446616001 {
1446716002 if (Xmin < Xmax) // !locked)
....@@ -14533,40 +16068,88 @@
1453316068 }
1453416069 if (object != null && !hasMarquee)
1453516070 {
16071
+ if (object.clickInfo == null)
16072
+ object.clickInfo = new ClickInfo();
16073
+ ClickInfo info = object.clickInfo;
16074
+ //ClickInfo info = new ClickInfo();
16075
+ info.bounds.setBounds(0, 0, (int) (width * zoom), (int) (height * zoom));
16076
+
1453616077 if (isRenderer)
1453716078 {
14538
- info.flags++;
16079
+ object.clickInfo.flags++;
1453916080 double frameAspect = (double) width / (double) height;
1454016081 if (frameAspect > renderCamera.aspect)
1454116082 {
1454216083 int desired = (int) ((double) height * renderCamera.aspect);
14543
- info.bounds.width -= width - desired;
14544
- info.bounds.x += (width - desired) / 2;
16084
+ object.clickInfo.bounds.width -= width - desired;
16085
+ object.clickInfo.bounds.x += (width - desired) / 2;
1454516086 } else
1454616087 {
1454716088 int desired = (int) ((double) width / renderCamera.aspect);
14548
- info.bounds.height -= height - desired;
14549
- info.bounds.y += (height - desired) / 2;
16089
+ object.clickInfo.bounds.height -= height - desired;
16090
+ object.clickInfo.bounds.y += (height - desired) / 2;
1455016091 }
1455116092 }
14552
- info.g = gr;
14553
- info.camera = renderCamera;
16093
+
16094
+ object.clickInfo.g = gr;
16095
+ object.clickInfo.camera = renderCamera;
1455416096 /*
1455516097 // Memory intensive (brep.verticescopy)
1455616098 if (!(object instanceof Composite))
1455716099 object.draw(info, 0, false); // SLOW :
1455816100 */
14559
- if (!isRenderer)
16101
+ if (!isRenderer) // && drag)
1456016102 {
14561
- object.drawEditHandles(info, 0);
16103
+ Grafreed.Assert(object != null);
16104
+ Grafreed.Assert(object.selection != null);
16105
+ if (object.selection.Size() > 0)
16106
+ {
16107
+ int hitSomething = object.selection.get(0).hitSomething;
16108
+
16109
+ object.clickInfo.DX = 0;
16110
+ object.clickInfo.DY = 0;
16111
+ object.clickInfo.W = 1;
16112
+ if (hitSomething == Object3D.hitCenter)
16113
+ {
16114
+ info.DX = X;
16115
+ if (X != 0)
16116
+ info.DX -= info.bounds.width/2;
16117
+
16118
+ info.DY = Y;
16119
+ if (Y != 0)
16120
+ info.DY -= info.bounds.height/2;
16121
+ }
16122
+
16123
+ object.drawEditHandles(//info,
16124
+ 0);
16125
+
16126
+ if (drag && (X != 0 || Y != 0))
16127
+ {
16128
+ switch (hitSomething)
16129
+ {
16130
+ case Object3D.hitCenter: gr.setColor(Color.pink);
16131
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16132
+ break;
16133
+ case Object3D.hitRotate: gr.setColor(Color.yellow);
16134
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16135
+ break;
16136
+ case Object3D.hitScale: gr.setColor(Color.cyan);
16137
+ gr.drawLine(X, Y, info.bounds.width/2, info.bounds.height/2);
16138
+ break;
16139
+ }
16140
+
16141
+ }
16142
+ }
1456216143 }
1456316144 }
16145
+
1456416146 if (isRenderer)
1456516147 {
1456616148 //gr.setColor(Color.black);
1456716149 //gr.drawRect(info.bounds.x - 1, info.bounds.y - 1, info.bounds.width + 1, info.bounds.height + 1);
1456816150 //gr.drawRect(info.bounds.x - 2, info.bounds.y - 2, info.bounds.width + 3, info.bounds.height + 3);
1456916151 }
16152
+
1457016153 if (hasMarquee)
1457116154 {
1457216155 gr.setXORMode(Color.white);
....@@ -14679,6 +16262,7 @@
1467916262 public boolean mouseDown(Event evt, int x, int y)
1468016263 {
1468116264 System.out.println("mouseDown: " + evt);
16265
+ System.exit(0);
1468216266 /*
1468316267 locked = true;
1468416268 drag = false;
....@@ -14722,7 +16306,7 @@
1472216306 {
1472316307 keyPressed(0, modifiers);
1472416308 }
14725
- clickStart(x, y, modifiers);
16309
+ // clickStart(x, y, modifiers);
1472616310 return true;
1472716311 }
1472816312
....@@ -14840,7 +16424,7 @@
1484016424 {
1484116425 keyReleased(0, 0);
1484216426 }
14843
- drag(x, y, modifiers);
16427
+ drag(x, y, 0, modifiers);
1484416428 return true;
1484516429 }
1484616430
....@@ -14972,7 +16556,7 @@
1497216556 Object3D object;
1497316557 static Object3D trackedobject;
1497416558 Camera renderCamera; // Light or Eye (or Occlusion)
14975
- /*static*/ Camera manipCamera; // Light or Eye
16559
+ /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
1497616560 /*static*/ Camera eyeCamera;
1497716561 /*static*/ Camera lightCamera;
1497816562 int cameracount;
....@@ -15036,6 +16620,8 @@
1503616620 private /*static*/ boolean firstime;
1503716621 private /*static*/ cVector newView = new cVector();
1503816622 private static final String[] suffixes = {"posx", "negx", "posy", "negy", "posz", "negz"};
16623
+ private static final String[] suffixes2 = {"east", "west", "top", "bottom", "north", "south"};
16624
+ private static final String[] suffixes3 = {"ft", "bk", "up", "dn", "rt", "lf"};
1503916625 private static final int[] targets = {GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
1504016626 GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
1504116627 GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
....@@ -15048,29 +16634,67 @@
1504816634 {
1504916635 com.sun.opengl.util.texture.Texture cubemap = TextureIO.newTexture(GL.GL_TEXTURE_CUBE_MAP);
1505016636
16637
+ int usedsuf = 0;
16638
+
1505116639 for (int i = 0; i < suffixes.length; i++)
1505216640 {
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)
16641
+ String[] suffixe = suffixes;
16642
+ String[] fallback = suffixes2;
16643
+ String[] fallfallback = suffixes3;
16644
+
16645
+ for (int c=usedsuf; --c>=0;)
1505816646 {
15059
- throw new IOException("Unable to load texture " + resourceName);
16647
+// String[] temp = suffixe;
16648
+// suffixe = fallback;
16649
+// fallback = fallfallback;
16650
+// fallfallback = temp;
1506016651 }
16652
+
16653
+ String resourceName = basename + suffixe[i] + "." + suffix;
16654
+ TextureData data;
16655
+
16656
+ try
16657
+ {
16658
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16659
+ mipmapped,
16660
+ FileUtil.getFileSuffix(resourceName));
16661
+ }
16662
+ catch (Exception e)
16663
+ {
16664
+ try
16665
+ {
16666
+ resourceName = basename + fallback[i] + "." + suffix;
16667
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16668
+ mipmapped,
16669
+ FileUtil.getFileSuffix(resourceName));
16670
+ }
16671
+ catch (Exception e2)
16672
+ {
16673
+ resourceName = basename + fallfallback[i] + "." + suffix;
16674
+ data = TextureIO.newTextureData(scope.getResourceAsStream(resourceName),
16675
+ mipmapped,
16676
+ FileUtil.getFileSuffix(resourceName));
16677
+ }
16678
+ }
16679
+
1506116680 //System.out.println("Target = " + targets[i]);
1506216681 cubemap.updateImage(data, targets[i]);
1506316682 }
1506416683
1506516684 return cubemap;
1506616685 }
16686
+
1506716687 int bigsphere = -1;
1506816688
1506916689 float BGcolor = 0.5f;
1507016690
15071
- private void DrawSkyBox(GL gl)
16691
+ float ambientLight[] = {1f, 1f, 1f, 1.0f};
16692
+
16693
+ private void DrawSkyBox(GL gl, float ratio)
1507216694 {
15073
- if (envyoff || cubemap == null)
16695
+ if (//envyoff ||
16696
+ WIREFRAME ||
16697
+ cubemap == null)
1507416698 {
1507516699 gl.glClearColor(BGcolor, BGcolor, BGcolor, 1);
1507616700 gl.glClear(gl.GL_COLOR_BUFFER_BIT);
....@@ -15085,7 +16709,17 @@
1508516709 // Compensates for ExaminerViewer's modification of modelview matrix
1508616710 gl.glMatrixMode(GL.GL_MODELVIEW);
1508716711 gl.glLoadIdentity();
16712
+ gl.glScalef(1,ratio,1);
1508816713
16714
+// colorV[0] = 2;
16715
+// colorV[1] = 2;
16716
+// colorV[2] = 2;
16717
+// colorV[3] = 1;
16718
+// gl.glDisable(gl.GL_COLOR_MATERIAL);
16719
+// gl.glMaterialfv(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT, colorV, 0);
16720
+//
16721
+// gl.glLightModelfv(gl.GL_LIGHT_MODEL_AMBIENT, ambientLight, 0);
16722
+
1508916723 //gl.glActiveTexture(GL.GL_TEXTURE1);
1509016724 //gl.glDisable(GL.GL_TEXTURE_CUBE_MAP);
1509116725
....@@ -15117,6 +16751,7 @@
1511716751 {
1511816752 gl.glScalef(1.0f, -1.0f, 1.0f);
1511916753 }
16754
+ gl.glScalef(-1.0f, 1.0f, 1.0f);
1512016755 gl.glMultMatrixd(viewrot_1, 0);
1512116756 gl.glTranslatef(0, 0, 0.5f); // (float)lightCamera.Distance()); // 0.5f);
1512216757 //viewer.updateInverseRotation(gl);
....@@ -15157,7 +16792,8 @@
1515716792 gl.glDisable(GL.GL_TEXTURE_GEN_R);
1515816793
1515916794 cubemap.disable();
15160
- ////cubemap.unbind();
16795
+ //cubemap.dispose();
16796
+
1516116797 if (CULLFACE)
1516216798 {
1516316799 gl.glEnable(gl.GL_CULL_FACE);
....@@ -15257,16 +16893,16 @@
1525716893 cStatic.objectstack[materialdepth++] = checker;
1525816894 //System.out.println("material " + material);
1525916895 //Applet3D.tracein(this, selected);
15260
- vector2buffer = checker.projectedVertices;
16896
+ //vector2buffer = checker.projectedVertices;
1526116897
1526216898 //checker.GetMaterial().Draw(this, false); // true);
15263
- DrawMaterial(checker.GetMaterial(), false); // true);
16899
+ DrawMaterial(checker.GetMaterial(), false, checker.projectedVertices); // true);
1526416900
1526516901 materialdepth -= 1;
1526616902 if (materialdepth > 0)
1526716903 {
15268
- vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
15269
- DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
16904
+ //vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
16905
+ DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1], cStatic.objectstack[materialdepth - 1].projectedVertices);
1527016906 }
1527116907 //checker.GetMaterial().opacity = 1f;
1527216908 ////checker.GetMaterial().ambient = 1f;
....@@ -15352,6 +16988,14 @@
1535216988 }
1535316989 }
1535416990
16991
+ private Object3D GetFolder()
16992
+ {
16993
+ Object3D folder = object.GetWindow().copy;
16994
+ if (object.GetWindow().copy.selection.Size() > 0)
16995
+ folder = object.GetWindow().copy.selection.elementAt(0);
16996
+ return folder;
16997
+ }
16998
+
1535516999 class SelectBuffer implements GLEventListener
1535617000 {
1535717001
....@@ -15367,7 +17011,7 @@
1536717011 //new Exception().printStackTrace();
1536817012 System.out.println("select buffer init");
1536917013 // Use debug pipeline
15370
- drawable.setGL(new DebugGL(drawable.getGL()));
17014
+ //drawable.setGL(new DebugGL(drawable.getGL()));
1537117015
1537217016 GL gl = drawable.getGL();
1537317017
....@@ -15410,6 +17054,7 @@
1541017054 {
1541117055 if (!selection)
1541217056 {
17057
+ new Exception().printStackTrace();
1541317058 System.exit(0);
1541417059 return;
1541517060 }
....@@ -15430,6 +17075,17 @@
1543017075
1543117076 //gl.glDisable(GL.GL_POLYGON_OFFSET_FILL);
1543217077
17078
+ if (PAINTMODE)
17079
+ {
17080
+ if (object.GetWindow().copy.selection.Size() > 0)
17081
+ {
17082
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17083
+
17084
+ // Make what you paint not selectable.
17085
+ paintobj.ResetSelectable();
17086
+ }
17087
+ }
17088
+
1543317089 //int tmp = selection_view;
1543417090 //selection_view = -1;
1543517091 int temp = DrawMode();
....@@ -15441,6 +17097,17 @@
1544117097 // temp = DEFAULT; // patch for selection debug
1544217098 Globals.drawMode = temp; // WARNING
1544317099
17100
+ if (PAINTMODE)
17101
+ {
17102
+ if (object.GetWindow().copy.selection.Size() > 0)
17103
+ {
17104
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
17105
+
17106
+ // Revert.
17107
+ paintobj.RestoreSelectable();
17108
+ }
17109
+ }
17110
+
1544417111 //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
1544517112
1544617113 // trying different ways of getting the depth info over
....@@ -15488,6 +17155,8 @@
1548817155 // System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
1548917156 // System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
1549017157 // System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
17158
+
17159
+ CreateSelectedPoint();
1549117160
1549217161 // Will fit the mesh !!!
1549317162 selectedpoint.toParent[0][0] = 0.0001;
....@@ -15537,34 +17206,36 @@
1553717206 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]));
1553817207 }
1553917208
15540
- previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
17209
+ previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
1554117210 }
1554217211 }
1554317212
1554417213 if (!movingcamera && !PAINTMODE)
15545
- object.editWindow.ScreenFitPoint(); // fev 2014
17214
+ object.GetWindow().ScreenFitPoint(); // fev 2014
1554617215
15547
- if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
17216
+ if (PAINTMODE) // && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
1554817217 {
15549
- Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
17218
+ //Object3D paintobj; // = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
1555017219
15551
- Object3D group = new Object3D("inst" + paintcount++);
17220
+ if (object.GetWindow().copy.selection.Size() > 0)
17221
+ {
17222
+ Object3D paintobj = object.GetWindow().copy.selection.elementAt(0);
1555217223
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();
17224
+ Object3D inst = new Object3D("inst" + paintcount++);
17225
+
17226
+ inst.CreateMaterial(); // use a void leaf to select instances
17227
+
17228
+ inst.add(paintobj); // link
17229
+
17230
+ object.GetWindow().SnapObject(inst);
17231
+
17232
+ Object3D folder = paintFolder; // GetFolder();
17233
+
17234
+ folder.add(inst);
17235
+
17236
+ object.GetWindow().ResetModel();
17237
+ object.GetWindow().refreshContents();
17238
+ }
1556817239 }
1556917240 else
1557017241 paintcount = 0;
....@@ -15603,6 +17274,11 @@
1560317274 //System.out.println("objects[color] = " + objects[color]);
1560417275 //objects[color].Select();
1560517276 indexcount = 0;
17277
+ ObjEditor window = object.GetWindow();
17278
+ if (window != null && deselect)
17279
+ {
17280
+ window.Select(null, deselect, true);
17281
+ }
1560617282 object.Select(color, deselect);
1560717283 }
1560817284
....@@ -15702,7 +17378,7 @@
1570217378 gl.glDisable(gl.GL_CULL_FACE);
1570317379 }
1570417380
15705
- if (!RENDERSHADOW)
17381
+ if (!Globals.RENDERSHADOW)
1570617382 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1570717383
1570817384 // SB gl.glPolygonOffset(2.5f, 10);
....@@ -15712,7 +17388,7 @@
1571217388 //gl.glColorMask(false, false, false, false);
1571317389
1571417390 //render_scene_from_light_view(gl, drawable, 0, 0);
15715
- if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
17391
+ if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
1571617392 {
1571717393 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
1571817394
....@@ -15772,7 +17448,6 @@
1577217448
1577317449 class AntialiasBuffer implements GLEventListener
1577417450 {
15775
-
1577617451 CameraPane parent = null;
1577717452
1577817453 AntialiasBuffer(CameraPane p)
....@@ -15882,10 +17557,14 @@
1588217557 gl.glFlush();
1588317558
1588417559 /**/
15885
- gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
17560
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusiondepthbuffer);
1588617561
15887
- float[] pixels = occlusionsizebuffer.array();
17562
+ float[] depths = occlusiondepthbuffer.array();
1588817563
17564
+ gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusioncolorbuffer);
17565
+
17566
+ int[] pixels = selectsizebuffer.array();
17567
+
1588917568 double r = 0, g = 0, b = 0;
1589017569
1589117570 double count = 0;
....@@ -15896,7 +17575,7 @@
1589617575
1589717576 double FACTOR = 1;
1589817577
15899
- for (int i = 0; i < pixels.length; i++)
17578
+ for (int i = 0; i < depths.length; i++)
1590017579 {
1590117580 int x = i / OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
1590217581 int y = i % OCCLUSION_SIZE - OCCLUSION_SIZE / 2;
....@@ -15979,7 +17658,7 @@
1597917658
1598017659 double scale = ray.z; // 1; // cos
1598117660
15982
- float depth = pixels[newindex];
17661
+ float depth = depths[newindex];
1598317662
1598417663 /*
1598517664 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
....@@ -16129,23 +17808,15 @@
1612917808 int AAbuffersize = 0;
1613017809
1613117810 //double[] selectedpoint = new double[3];
16132
- static Superellipsoid selectedpoint = new Superellipsoid();
17811
+ static Superellipsoid selectedpoint;
1613317812 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();
17813
+ static Sphere debugpointG;
17814
+ static Sphere debugpointP;
17815
+ static Sphere debugpointC;
17816
+ static Sphere debugpointR;
1613817817
1613917818 static Sphere debugpoints[] = new Sphere[8];
1614017819
16141
- static
16142
- {
16143
- for (int i=0; i<8; i++)
16144
- {
16145
- debugpoints[i] = new Sphere();
16146
- }
16147
- }
16148
-
1614917820 static void InitPoints(float radius)
1615017821 {
1615117822 for (int i=0; i<8; i++)
....@@ -16165,7 +17836,7 @@
1616517836 }
1616617837 }
1616717838
16168
- static void DrawPoints(CameraPane cpane)
17839
+ static void DrawPoints(iCameraPane cpane)
1616917840 {
1617017841 for (int i=0; i<8; i++) // first and last are red
1617117842 {
....@@ -16184,11 +17855,14 @@
1618417855 static IntBuffer AAbuffer; // = IntBuffer.allocate(MAX_SIZE*MAX_SIZE);
1618517856 static IntBuffer bigAAbuffer;
1618617857 static java.nio.FloatBuffer histogram = BufferUtil.newFloatBuffer(HISTOGRAM_SIZE * 3);
16187
- static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
17858
+ //static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
1618817859 static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1618917860 static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
1619017861 //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
16191
- static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17862
+ static java.nio.FloatBuffer occlusiondepthbuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17863
+
17864
+ static IntBuffer occlusioncolorbuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
17865
+
1619217866 static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
1619317867 static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
1619417868 static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
....@@ -16197,10 +17871,11 @@
1619717871 static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
1619817872 // Depth buffer format
1619917873 //private int depth_format;
16200
- static public void NextIndex(Object3D o, GL gl)
17874
+
17875
+ public void NextIndex()
1620117876 {
1620217877 indexcount+=16;
16203
- gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
17878
+ GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
1620417879 //objects[indexcount] = o;
1620517880 //System.out.println("indexcount = " + indexcount);
1620617881 }