From cd87df088b1850ba0c90beb6c866c443e4eaf3b9 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sat, 08 Jun 2019 23:56:42 -0400
Subject: [PATCH] Fix shadow and bump issue.

---
 CameraPane.java | 1031 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 880 insertions(+), 151 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index c4bdcc2..0d3d46b 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -56,8 +56,6 @@
     static int CURRENTANTIALIAS = 0; // 1;
 	/*static*/ boolean RENDERSHADOW = true;
     /*static*/ int RENDERPROGRAM = 2; // 0 == none, 1 == fast, 2 == normal
-    static boolean ANIMATION = false;
-    static String filename;
     
     boolean DISPLAYTEXT = false;
     //boolean REDUCETEXTURE = true;
@@ -92,6 +90,8 @@
 
 static    int tickcount = 0; // slow pose issue
 
+static    boolean BUTTONLESSWHEEL = false;
+static    boolean ZOOMBOXMODE = false;
 static    boolean BOXMODE = false;
 static    boolean IMAGEFLIP = false;
 static    boolean SMOOTHFOCUS = false;
@@ -106,7 +106,7 @@
 static    boolean OEIL = true;
 static    boolean OEILONCE = false; // do oeilon then oeiloff
 static    boolean LOOKAT = true;
-static    boolean RANDOM = true; // false;
+static    boolean SWITCH = true; // false;
 static    boolean HANDLES = false; // selection doesn't work!!
 static  boolean PAINTMODE = false;
 
@@ -149,12 +149,11 @@
         defaultcaps.setAccumBlueBits(16);
         defaultcaps.setAccumAlphaBits(16);
     }
-    static CameraPane theRenderer;
-
+    
     void SetAsGLRenderer(boolean b)
     {
         isRenderer = b;
-        theRenderer = this;
+        Globals.theRenderer = this;
     }
 
     CameraPane(Object3D o, Camera cam, boolean withcontext)
@@ -192,9 +191,43 @@
     
     /// INTERFACE
     
+    public javax.media.opengl.GL GetGL0()
+    {
+            return null;
+    }
+    
+    public int GenList()
+    {
+            javax.media.opengl.GL gl = GetGL();
+        return gl.glGenLists(1);
+    }
+    
+    public void NewList(int id)
+    {
+            javax.media.opengl.GL gl = GetGL();
+        gl.glNewList(id, gl.GL_COMPILE); //_AND_EXECUTE);
+    }
+    
+    public void CallList(int id)
+    {
+        javax.media.opengl.GL gl = GetGL();
+        gl.glCallList(id);
+    }
+    
+    public void EndList()
+    {
+            javax.media.opengl.GL gl = GetGL();
+        gl.glEndList();
+    }
+    
     public boolean IsBoxMode()
     {
             return BOXMODE;
+    }
+    
+    public boolean IsZoomBoxMode()
+    {
+            return ZOOMBOXMODE;
     }
     
     public void ClearDepth()
@@ -236,9 +269,14 @@
             return this.ambientOcclusion;
     }
     
+    public boolean IsDebugSelection()
+    {
+            return DEBUG_SELECTION;
+    }
+    
     public boolean IsFrozen()
     {
-        boolean selectmode = this.DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
+        boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
         
         return !selectmode && cameracount == 0; // != 0;
     }
@@ -259,9 +297,19 @@
             return lightCamera;
     }
     
+    public Camera ManipCamera()
+    {
+            return manipCamera;
+    }
+    
     public Camera RenderCamera()
     {
             return renderCamera;
+    }
+    
+    public Camera[] Cameras()
+    {
+            return cameras;
     }
     
     public void PushMaterial(Object3D obj, boolean selected)
@@ -408,7 +456,7 @@
         
         javax.media.opengl.GL gl = display.GetGL();
         
-        boolean selectmode = display.DrawMode() == display.SELECTION || CameraPane.DEBUG_SELECTION;
+        boolean selectmode = display.DrawMode() == display.SELECTION || display.IsDebugSelection();
         
         //System.out.println("p = " + pv + "; q = " + qv + "; r = " + rv);
         if (!selectmode) // display.drawMode != display.SELECTION) // && display.drawMode != display.SHADOW) // (attributes & FILL) != 0)
@@ -760,7 +808,621 @@
 ////        tris.postdraw(this);
     }
 
+    static Camera localcamera = new Camera();
+    static cVector from = new cVector();
+    static cVector to = new cVector();
+    
+        public void PrepOcclusion(BoundaryRep br, double[][] transform)
+        {
+                CameraPane cp = this;
+
+                Camera keep = cp.RenderCamera();
+                cp.renderCamera = localcamera;
+
+                if (br.trimmed)
+                {
+                    float[] colors = new float[br.positions.length / 3];
+
+                    int i3 = 0;
+                    for (int i = 0; i < br.positions.length / 3; i++, i3 += 3)
+                    {
+                        if (br.normals[i3] == 0 && br.normals[i3+1] == 0 && br.normals[i3+2] == 0)
+                            continue;
+
+                        from.set(br.positions[i3], br.positions[i3 + 1], br.positions[i3 + 2]);
+                        to.set(br.positions[i3] + br.normals[i3],
+                                br.positions[i3 + 1] + br.normals[i3 + 1],
+                                br.positions[i3 + 2] + br.normals[i3 + 2]);
+                        LA.xformPos(from, transform, from);
+                        LA.xformPos(to, transform, to); // RIGID ONLY
+                        localcamera.setAim(from, to);
+
+                        CameraPane.occlusionbuffer.display();
+
+                        if (CameraPane.DEBUG_OCCLUSION)
+                            cp.display(); // debug
+
+                        colors[i] = cp.vertexOcclusion.r;
+                        //colors[i3 + 1] = cp.vertexOcclusion.g;
+                        //colors[i3 + 2] = cp.vertexOcclusion.b;
+
+                        if ((i % 100) == 0 && i != 0)
+                        {
+                    Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
+                            //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
+                                System.out.println((int) (100.0 * i / (br.positions.length / 3)) + "% (" + i + " of " + (br.positions.length / 3) + ")");
+                        }
+                    }
+
+                    br.colors = colors;
+                }
+                else
+                {
+                    for (int i = 0; i < br.VertexCount(); i++)
+                    {
+                        Vertex v = br.GetVertex(i);
+
+                        if (v.norm == null || v.norm.x == 0 && v.norm.y == 0 && v.norm.z == 0)
+                            continue;
+
+                        from.set(v.x, v.y, v.z);
+                        to.set(v.x+v.norm.x, v.y+v.norm.y, v.z+v.norm.z);
+                        LA.xformPos(from, transform, from);
+                        LA.xformPos(to, transform, to); // RIGID ONLY
+                        localcamera.setAim(from, to);
+
+                        CameraPane.occlusionbuffer.display();
+
+                        if (CameraPane.DEBUG_OCCLUSION)
+                            cp.display(); // debug
+
+                        v.AO = cp.vertexOcclusion.r;
+
+                        if ((i % 100) == 0 && i != 0)
+                        {
+                    Globals.theRenderer.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
+                            //System.out.println("Color = " + cp.vertexOcclusion.r + ", " + cp.vertexOcclusion.g + ", " + cp.vertexOcclusion.b + "; " + (int)(100.0*i/(positions.length/3)) + "% done");
+                                System.out.println((int) (100.0 * i / br.VertexCount()) + "% (" + i + " of " + br.VertexCount() + ")");
+                        }
+                    }
+                }
+
+                //System.out.println("done.");
+
+                cp.renderCamera = keep;
+        }
+        
+    void DrawPointFLow(PointFlow pointFlow, Object3D /*Composite*/ root, boolean selected, boolean blocked)
+    {
+            CameraPane display = this;
+        pointFlow.CreateHT();
+        
+        float r = display.modelParams0[0];
+        float g = display.modelParams0[1];
+        float b = display.modelParams0[2];
+        float opacity = display.modelParams5[1];        
+        
+        //final GL gl = GLU.getCurrentGL();
+        GL gl = display.GetGL(); // getGL();
+
+        int s = pointFlow.points.size();
+
+        boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
+        gl.glEnable(gl.GL_CULL_FACE);
+        
+        for (int i=s; --i>=0;)
+        //for (int i=0; i<s; i++)
+        {
+            cVector v = pointFlow.points.get(i);
+            
+            double mindist = Double.MAX_VALUE;
+            
+            double size = pointFlow.minimumSize;
+            
+            double distancenext = 0;
+            
+            if (i > 0)
+            {
+                cVector w = pointFlow.points.get(i-1);
+                
+                double dist = w.distance(v);
+                
+                distancenext = dist;
+        
+                if (mindist > dist)
+                {
+                    mindist = dist;
+                    size = mindist*pointFlow.resizefactor;
+                }
+            }
+            
+            if (i < s-1)
+            {
+                cVector w = pointFlow.points.get(i+1);
+                
+                double dist = w.distance(v);
+                
+                if (mindist > dist)
+                {
+                    mindist = dist;
+                    size = mindist*pointFlow.resizefactor;
+                }
+            }
+            
+            if (size < pointFlow.minimumSize)
+                size = pointFlow.minimumSize;
+            if (size > pointFlow.maximumSize)
+                size = pointFlow.maximumSize;
+            
+            double tx = v.x;
+            double ty = v.y;
+            double tz = v.z;
+            
+        //    if (tx == 0 && ty == 0 && tz == 0)
+        //        continue;
+            
+        gl.glMatrixMode(gl.GL_TEXTURE);
+        gl.glPushMatrix();
+        pointFlow.texmat[12] = pointFlow.texmat[13] = pointFlow.texmat[14] = i;
+        
+        gl.glMultMatrixf(pointFlow.texmat, 0);
+        
+            gl.glMatrixMode(gl.GL_MODELVIEW);
+            gl.glPushMatrix();
+            
+            gl.glTranslated(tx,ty,tz);
+
+            gl.glScaled(size,size,size);
+            
+//            float cr = colorBuf.get(index4);
+//            float cg = colorBuf.get(index4+1);
+//            float cb = colorBuf.get(index4+2);
+//            float ca = colorBuf.get(index4+3);
+//            
+//            display.modelParams0[0] = r * cr;
+//            display.modelParams0[1] = g * cg;
+//            display.modelParams0[2] = b * cb;
+//            
+//            display.modelParams5[1] = opacity * ca;
+//            
+//        gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
+//        gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
+//        
+//        RandomNode.globalseed = (int)sizeBuf.get(index3+2); // i;
+//        RandomNode.globalseed2 = RandomNode.globalseed;
+//        
+////            gl.glColor4f(cr,cg,cb,ca);
+//   //         gl.glScalef(1024/16,1024/16,1024/16);
+            pointFlow.geo.Draw/*Node*/(display,null,selected, blocked);
+            
+            gl.glPopMatrix();
+
+            double step = size/4; //
+            
+            if (i == 0 || size == 0 || distancenext > 8*size || distancenext < step)
+                continue;
+            
+            int nbsteps = (int)(distancenext/step);
+            
+            step = distancenext/nbsteps;
+            
+            cVector next = pointFlow.points.get(i-1);
+            
+            tmp.set(next);
+            tmp.sub(v);
+            tmp.normalize();
+            tmp.mul(step);
+            
+            // calculate next size
+            mindist = Double.MAX_VALUE;
+            
+            double nextsize = pointFlow.minimumSize;
+            
+            if (i > 1)
+            {
+                cVector w = pointFlow.points.get(i-2);
+                
+                double dist = w.distance(next);
+                
+                if (mindist > dist)
+                {
+                    mindist = dist;
+                    nextsize = mindist*pointFlow.resizefactor;
+                }
+            }
+            
+            double dist = v.distance(next);
+
+            if (mindist > dist)
+            {
+                mindist = dist;
+                nextsize = mindist*pointFlow.resizefactor;
+            }
+            
+            if (nextsize < pointFlow.minimumSize)
+                nextsize = pointFlow.minimumSize;
+            if (nextsize > pointFlow.maximumSize)
+                nextsize = pointFlow.maximumSize;
+            //
+            
+            double count = 0;
+            
+            while (distancenext > 0.000000001) // step
+            {
+                gl.glPushMatrix();
+
+                gl.glTranslated(tx + tmp.x*count, ty + tmp.y*count, tz + tmp.z*count);
+
+                double K = count/nbsteps;
+                
+                double intersize = K*nextsize + (1-K)*size;
+                
+                gl.glScaled(intersize,intersize,intersize);
+
+                pointFlow.geo.Draw/*Node*/(display,null,selected,blocked);
+            
+                count++;
+                
+                distancenext -= step;
+                
+                gl.glPopMatrix();
+            }
+            
+            if (count != nbsteps)
+                assert(count == nbsteps);
+            
+   //         gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
+            //gl.glTranslatef(-tx,-ty,-tz);
+            
+        gl.glMatrixMode(gl.GL_TEXTURE);
+        gl.glPopMatrix();
+        }
+
+        if (!cf)
+            gl.glDisable(gl.GL_CULL_FACE);
+        
+//        display.modelParams0[0] = r;
+//        display.modelParams0[1] = g;
+//        display.modelParams0[2] = b;
+//            
+//        display.modelParams5[1] = opacity;
+//            
+//        gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
+//        gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
+        
+        gl.glMatrixMode(gl.GL_MODELVIEW);
+    }
+    
+        public void DrawBox(cVector min, cVector max)
+        {
+            javax.media.opengl.GL gl = GetGL();
+                gl.glBegin(gl.GL_LINES);
+                
+                gl.glVertex3d(min.x, min.y, min.z);
+                gl.glVertex3d(min.x, min.y, max.z);
+                gl.glVertex3d(min.x, min.y, min.z);
+                gl.glVertex3d(min.x, max.y, min.z);
+                gl.glVertex3d(min.x, min.y, min.z);
+                gl.glVertex3d(max.x, min.y, min.z);
+                
+                gl.glVertex3d(max.x, max.y, max.z);
+                gl.glVertex3d(min.x, max.y, max.z);
+                gl.glVertex3d(max.x, max.y, max.z);
+                gl.glVertex3d(max.x, min.y, max.z);
+                gl.glVertex3d(max.x, max.y, max.z);
+                gl.glVertex3d(max.x, max.y, min.z);
+                
+                gl.glEnd();
+        }
+
+        public void DrawGeometry(BoundaryRep bRep, boolean flipV, boolean selectmode)
+        {
+            int[] strips = bRep.getRawIndices();
+            
+            javax.media.opengl.GL gl = GetGL();
+        
+                // TRIANGLE STRIP ARRAY
+                if (bRep.trimmed)
+                {
+                    float[] v = bRep.getRawVertices();
+                    float[] n = bRep.getRawNormals();
+                    float[] c = bRep.getRawColors();
+                    float[] uv = bRep.getRawUVMap();
+
+                    int count2 = 0;
+                    int count3 = 0;
+
+                    if (n.length > 0)
+                    {
+                        for (int i = 0; i < strips.length; i++)
+                        {
+                            gl.glBegin(gl.GL_TRIANGLE_STRIP);
+
+                            /*
+                    boolean locked = false;
+                    float eps = 0.1f;
+                    boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
+
+                    int dot = 0;
+
+                    if ((dot&1) == 0)
+                        dot |= (Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps) ? 3 : 1;
+
+                    if (wrap || (dot&2) != 0) // Math.abs(qv.s - pv.s) < eps && Math.abs(qv.t - pv.t) < eps)
+                        gl.glTexCoord2f((float) qv.s, (float) qv.t);
+                    else
+                    {
+                        locked = true;
+                        gl.glTexCoord2f((float) pv.s, (float) pv.t);
+                    }
+                    //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
+                    gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
+                    if (hasnorm)
+                    {
+                        //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
+                        gl.glNormal3f((float) rv.norm.x, (float) rv.norm.y, (float) rv.norm.z);
+                    }
+
+                    if ((dot&4) == 0)
+                        dot |= (Math.abs(rv.s - pv.s) < eps && Math.abs(rv.t - pv.t) < eps) ? 12 : 4;
+
+                    if (wrap || !locked && (dot&8) != 0)
+                        gl.glTexCoord2f((float) rv.s, (float) rv.t);
+                    else
+                        gl.glTexCoord2f((float) pv.s, (float) pv.t);
+
+                    f.dot = dot;
+                    */
+
+                            if (!selectmode)
+                            {
+                                if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
+                                {
+                                    gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
+                                } else
+                                {
+                                    gl.glNormal3f(0, 0, 1);
+                                }
+
+                                if (c != null)
+                                //System.out.println("glcolor = " + c[count3] + ", " + c[count3+1] + ", " + c[count3+2]);
+                                {
+                                    gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
+                                }
+                            }
+                            if (flipV)
+                                gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
+                            else
+                                gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
+                            //System.out.println("vertex1 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
+                            gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
+
+                            count2 += 2;
+                            count3 += 3;
+                            if (!selectmode)
+                            {
+                                if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
+                                {
+                                    gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
+                                } else
+                                {
+                                    gl.glNormal3f(0, 0, 1);
+                                }
+                                if (c != null)
+                                {
+                                    gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
+                                }
+                            }
+                            if (flipV)
+                                gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
+                            else
+                                gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
+                            //System.out.println("vertex2 = " + v[count3] + ", " + v[count3+1] + ", " + v[count3+2]);
+                            gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
+
+                            count2 += 2;
+                            count3 += 3;
+                            for (int j = 0; j < strips[i] - 2; j++)
+                            {
+                                //gl.glTexCoord2d(...);
+                                if (!selectmode)
+                                {
+                                    if (n[count3] != 0 || n[count3 + 1] != 0 || n[count3 + 2] != 0)
+                                    {
+                                        gl.glNormal3f(n[count3], n[count3 + 1], n[count3 + 2]);
+                                    } else
+                                    {
+                                        gl.glNormal3f(0, 0, 1);
+                                    }
+                                    if (c != null)
+                                    {
+                                        gl.glColor4f(c[count3/3], c[count3/3 /* + 1*/], c[count3/3 /* + 2*/], 1);
+                                    }
+                                }
+
+                                if (flipV)
+                                    gl.glTexCoord2f(uv[count2], 1-uv[count2 + 1]);
+                                else
+                                    gl.glTexCoord2f(uv[count2], uv[count2 + 1]);
+                                //System.out.println("coord3 = " + uv[count2] + ", " + uv[count2+1]);
+                                gl.glVertex3f(v[count3], v[count3 + 1], v[count3 + 2]);
+                                count2 += 2;
+                                count3 += 3;
+                            }
+
+                            gl.glEnd();
+                        }
+                    }
+
+                    assert count3 == v.length;
+                }
+                else // !trimmed
+                {
+                    int count = 0;
+                    for (int i = 0; i < strips.length; i++)
+                    {
+                        gl.glBegin(gl.GL_TRIANGLE_STRIP);
+                        
+                        Vertex p = bRep.GetVertex(bRep.indices[count++]);
+                        Vertex q = bRep.GetVertex(bRep.indices[count++]);
+                        
+                        drawVertex(gl, p, flipV, selectmode);
+                        drawVertex(gl, q, flipV, selectmode);
+                        
+                        for (int j = 0; j < strips[i] - 2; j++)
+                        {
+                            Vertex r = bRep.GetVertex(bRep.indices[count++]);
+
+    //                        if (j%2 == 0)
+    //                            drawFace(p, q, r, display, null);
+    //                        else
+    //                            drawFace(p, r, q, display, null);
+                            
+    //                        p = q;
+    //                        q = r;
+                            drawVertex(gl, r, flipV, selectmode);
+                        }
+
+                        gl.glEnd();
+                    }
+                }
+        }
+
+    static cSpring.Point3D temp = new cSpring.Point3D();
+    static cSpring.Point3D temp2 = new cSpring.Point3D();
+    static cSpring.Point3D temp3 = new cSpring.Point3D();
+    
+        public void DrawDynamicMesh(cMesh mesh)
+        {
+                GL gl = GetGL(); // getGL();
+
+                cSpring.PhysicsController3D Phys = mesh.Phys;
+                
+                gl.glDisable(gl.GL_LIGHTING);
+                
+                gl.glLineWidth(1);
+                gl.glColor3f(1,1,1);
+                gl.glBegin(gl.GL_LINES);
+                double scale = 0;
+                int count = 0;
+                for (int s=0; s<Phys.allSprings.size(); s++)
+                {
+                    cSpring.Spring spring = Phys.allSprings.get(s);
+                        if(s == 0)
+                        {
+                            //System.out.println(" spring : " + spring.a.position + "; " + spring.b.position);
+                        }
+                if (mesh.showsprings)
+                {
+                    temp.set(spring.a.position);
+                    temp.add(spring.b.position);
+                    temp.mul(0.5);
+                    temp2.set(spring.a.position);
+                    temp2.sub(spring.b.position);
+                    temp2.mul(spring.restLength/2);
+                    temp.sub(temp2);
+                    gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
+                    temp.add(temp2);
+                    temp.add(temp2);
+                    gl.glVertex3f((float)temp.x, (float)temp.y, (float)temp.z);
+                }
+
+                    if (spring.isHandle)
+                        continue;
+                    
+                    //if (scale < spring.restLength)
+                        scale += spring.restLength;
+                        count++;
+                }
+                gl.glEnd();
+
+                if (count == 0)
+                    scale = 0.01;
+                else
+                    scale /= count * 3;
+                
+                //scale = 0.25;
+                
+                if (mesh.ShowInfo())
+                {
+                    gl.glLineWidth(4);
+                    for (int s=0; s<Phys.allNodes.size(); s++)
+                    {
+                        cSpring.DynamicNode node = Phys.allNodes.get(s);
+                        if (node.mass == 0)
+                            continue;
+                        
+                        int i = node.springs==null?-1:node.springs.size();
+                        gl.glColor3f((i>>2)&1,(i>>1)&1,i&1);
+                        //temp.set(node.springForce.x, node.springForce.y, node.springForce.z);
+                        //temp.normalize();
+                        //gl.glColor3d((temp.x+1)/2, (temp.y+1)/2, (temp.z+1)/2);
+                        gl.glBegin(gl.GL_LINES);
+                        gl.glVertex3d(node.position.x, node.position.y, node.position.z);
+                        //gl.glVertex3d(node.position.x + node.normal.x*scale, node.position.y + node.normal.y*scale, node.position.z + node.normal.z*scale);
+                        gl.glVertex3d(node.position.x + mesh.bRep.GetVertex(s).norm.x*scale,
+                                node.position.y + mesh.bRep.GetVertex(s).norm.y*scale,
+                                node.position.z + mesh.bRep.GetVertex(s).norm.z*scale);
+                        gl.glEnd();
+                    }
+
+                    gl.glLineWidth(8);
+                    for (int s=0; s<Phys.allNodes.size(); s++)
+                    {
+                        cSpring.DynamicNode node = Phys.allNodes.get(s);
+
+                        if (node.springs != null)
+                        {
+                            for (int i=0; i<node.springs.size(); i+=1)
+                            {
+                                cSpring.DynamicNode f = node.springs.get(i).GetOther(node);
+                                
+                                int c = i+1;
+                           //     c = node.springs.get(i).nbcopies;
+
+                                gl.glColor3f((c>>2)&1,(c>>1)&1,c&1);
+                                gl.glBegin(gl.GL_LINES);
+                                    gl.glVertex3d(node.position.x, node.position.y, node.position.z);
+                                    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);
+                                gl.glEnd();
+                            }
+                        }
+                    }
+
+                    gl.glLineWidth(1);
+                }
+                
+                gl.glEnable(gl.GL_LIGHTING);
+        }
+    
     /// INTERFACE
+    
+    public void StartTriangles()
+    {
+         javax.media.opengl.GL gl = GetGL();
+         gl.glBegin(gl.GL_TRIANGLES);
+    }
+    
+    public void EndTriangles()
+    {
+         GetGL().glEnd();
+    }
+    
+    void drawVertex(javax.media.opengl.GL gl, Vertex pv, boolean flipV, boolean selectmode)
+    {
+        if (!selectmode)
+        {
+            gl.glNormal3f((float) pv.norm.x, (float) pv.norm.y, (float) pv.norm.z);
+            gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
+            
+            if (flipV)
+                gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
+            else
+                gl.glTexCoord2f((float) pv.s, (float) pv.t);
+        }
+
+        gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
+    }
     
     void SetColor(Object3D obj, Vertex p0)
     {
@@ -955,18 +1617,18 @@
         //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
         if (!material.multiply)
         {
-            display.color = color;
+            display.color = material.color;
             display.saturation = material.modulation;
         }
         else
         {
-            display.color *= color*2;
+            display.color *= material.color*2;
             display.saturation *= material.modulation*2;
         }
             
         cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
 
-        float[] colorV = GrafreeD.colorV;
+        float[] colorV = Grafreed.colorV;
 
         /**/
         if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
@@ -1323,7 +1985,7 @@
     
     static int camerachangeframe;
     
-    boolean SetCamera(Camera cam)
+    public boolean SetCamera(Camera cam)
     {
         // may 2014 if (cam == cameras[0] || cam == cameras[1])
         //    return false;
@@ -1451,33 +2113,6 @@
         mainDL ^= true;
     }
 
-    void ToggleTexture()
-    {
-        textureon ^= true;
-    }
-
-    void ToggleLive()
-    {
-        Globals.setLIVE(Globals.isLIVE() ^ true);
-        
-        System.err.println("LIVE = " + Globals.isLIVE());
-        
-        if (!Globals.isLIVE()) // save sound
-            GrafreeD.savesound = true; // wav.save();
-     //   else
-            repaint(); // start loop // may 2013
-    }
-
-    void ToggleSupport()
-    {
-        SUPPORT ^= true;
-    }
-
-    void ToggleAbort()
-    {
-        ABORTMODE ^= true;
-    }
-
     void ToggleFullScreen()
     {
         FULLSCREEN ^= true;
@@ -1488,72 +2123,94 @@
         Globals.CROWD ^= true;
     }
 
-    void ToggleInertia()
-    {
-        INERTIA ^= true;
-    }
-
     void ToggleLocal()
     {
         LOCALTRANSFORM ^= true;
     }
 
-    void ToggleFast()
+    public void ToggleTexture()
+    {
+        textureon ^= true;
+    }
+
+    public void ToggleLive()
+    {
+        Globals.setLIVE(Globals.isLIVE() ^ true);
+        
+        System.err.println("LIVE = " + Globals.isLIVE());
+        
+        if (!Globals.isLIVE()) // save sound
+            Grafreed.savesound = true; // wav.save();
+     //   else
+            repaint(); // start loop // may 2013
+    }
+
+    public void ToggleSupport()
+    {
+        SUPPORT ^= true;
+    }
+
+    public void ToggleAbort()
+    {
+        ABORTMODE ^= true;
+    }
+
+    public void ToggleInertia()
+    {
+        INERTIA ^= true;
+    }
+
+    public void ToggleFast()
     {
         FAST ^= true;
     }
 
-    void ToggleSlowPose()
+    public void ToggleSlowPose()
     {
         SLOWPOSE ^= true;
     }
 
-    void ToggleFootContact()
-    {
-        FOOTCONTACT ^= true;
-    }
-    
-    void ToggleBoxMode()
+    public void ToggleBoxMode()
     {
         BOXMODE ^= true;
     }
 
-    void ToggleSmoothFocus()
+    public void ToggleZoomBoxMode()
+    {
+        ZOOMBOXMODE ^= true;
+    }
+
+    public void ToggleSmoothFocus()
     {
         SMOOTHFOCUS ^= true;
     }
 
-    void ToggleImageFlip()
+    public void ToggleImageFlip()
     {
         IMAGEFLIP ^= true;
     }
 
-    void ToggleSpeakerMocap()
+    public void ToggleSpeakerMocap()
     {
         SPEAKERMOCAP ^= true;
     }
 
-    void ToggleSpeakerCamera()
+    public void ToggleSpeakerCamera()
     {
         SPEAKERCAMERA ^= true;
     }
 
-    void ToggleSpeakerFocus()
+    public void ToggleSpeakerFocus()
     {
         SPEAKERFOCUS ^= true;
     }
 
-    void ToggleDebug()
-    {
-        DEBUG ^= true;
-    }
-
-    void ToggleFrustum()
+    public void ToggleFrustum()
     {
         FRUSTUM ^= true;
     }
 
-    void ToggleTrack()
+    public void ToggleTrack()
     {
         TRACK ^= true;
         if (TRACK)
@@ -1572,25 +2229,35 @@
         repaint();
     }
 
-    void ToggleTrackOnce()
+    public void ToggleTrackOnce()
     {
         TRACKONCE ^= true;
     }
 
-    void ToggleShadowTrack()
+    public void ToggleShadowTrack()
     {
         SHADOWTRACK ^= true;
         repaint();
     }
 
-    void ToggleOeil()
+    public void ToggleOeil()
     {
         OEIL ^= true;
     }
 
-    void ToggleOeilOnce()
+    public void ToggleOeilOnce()
     {
         OEILONCE ^= true;
+    }
+
+    void ToggleFootContact()
+    {
+        FOOTCONTACT ^= true;
+    }
+    
+    void ToggleDebug()
+    {
+        DEBUG ^= true;
     }
 
     void ToggleLookAt()
@@ -1600,7 +2267,7 @@
 
     void ToggleRandom()
     {
-        RANDOM ^= true;
+        SWITCH ^= true;
     }
 
     void ToggleHandles()
@@ -3539,6 +4206,7 @@
     
     com.sun.opengl.util.texture.Texture CompressTexture2(String name)
     {
+                new Exception().printStackTrace();
         System.exit(0);
         com.sun.opengl.util.texture.Texture texture = null;
 
@@ -7354,7 +8022,7 @@
         }
     }
 
-    /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
+    /*boolean*/ public void BindTextures(cTexture tex, int resolution) throws Exception // INTERFACE
     {
         if (// DrawMode() != 0 || /*tex == null ||*/
                 ambientOcclusion ) // || !textureon)
@@ -7399,7 +8067,7 @@
         return; // true;
     }
     
-    CacheTexture GetCacheTexture(String tex, boolean bump, int resolution)
+    CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
     {
         CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
         
@@ -7407,12 +8075,16 @@
         {
             String texname = tex;
             
-            String[] split = tex.split("Textures");
-            if (split.length > 1)
-                texname = "/Users/nbriere/Textures" + split[split.length-1];
-            else
-                if (!texname.startsWith("/"))
-                    texname = "/Users/nbriere/Textures/" + texname;
+//            String[] split = tex.split("Textures");
+//            if (split.length > 1)
+//                texname = "/Users/nbriere/Textures" + split[split.length-1];
+//            else
+//                if (!texname.startsWith("/"))
+//                    texname = "/Users/nbriere/Textures/" + texname;
+            if (!new File(tex).exists())
+            {
+                    texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname;
+            }
             
             if (CACHETEXTURE)
                 texture = textures.get(texname); // TEXTURE CACHE
@@ -7512,7 +8184,9 @@
                                 texturedata = GetFileTexture(cachename, processbump, resolution);                                
                                 
                                 
-                                if (texturedata != null)
+                                if (texturedata == null)
+                                    throw new Exception();
+                                    
                                     texture = new CacheTexture(com.sun.opengl.util.texture.TextureIO.newTexture(texturedata),resolution);
         //texture = GetTexture(tex, bump);
                             }
@@ -7634,7 +8308,7 @@
         return texture;
     }
     
-    com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution)
+    com.sun.opengl.util.texture.Texture GetTexture(String tex, boolean bump, int resolution) throws Exception
     {
         CacheTexture texture = GetCacheTexture(tex, bump, resolution);
                 
@@ -7652,14 +8326,14 @@
         return texture!=null?texture.texture:null;
     }
     
-    com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution)
+    public com.sun.opengl.util.texture.TextureData GetTextureData(String tex, boolean bump, int resolution) throws Exception
     {
         CacheTexture texture = GetCacheTexture(tex, bump, resolution);
                 
         return texture!=null?texture.texturedata:null;
     }
     
-    boolean BindTexture(String tex, boolean bump, int resolution)
+    boolean BindTexture(String tex, boolean bump, int resolution) throws Exception
     {
         if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
         {
@@ -8725,7 +9399,7 @@
             //gl.glFlush();
             gl.glAccum(gl.GL_ACCUM, 1.0f / ACSIZE);
 
-            if (ANIMATION && ABORTED)
+            if (Globals.ANIMATION && ABORTED)
             {
     System.err.println("    ABORTED FRAME");
                 break;
@@ -8755,7 +9429,7 @@
         setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
 
         // save image
-        if (ANIMATION && !ABORTED)
+        if (Globals.ANIMATION && !ABORTED)
         {
             VPwidth = viewport[2];
             VPheight = viewport[3];
@@ -8866,11 +9540,11 @@
             
 //            imagecount++;
             
-            String fullname = filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
+            String fullname = Globals.filename + (i%100000)/10000 + "" + (i%10000)/1000 + "" + (i%1000)/100 + "" + (i%100)/10 + "" + (i%10) + "." + ext;
             
             if (!BOXMODE)
             {
-                System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
+                System.out.println("image: " + fullname + " (wav cursor=" + (Grafreed.wav.cursor / 735 / 4) + ")");
             }
     
             if (!BOXMODE)
@@ -8908,7 +9582,7 @@
             ABORTED = false;
         }
         else
-            GrafreeD.wav.cursor += 735 * ACSIZE;
+            Grafreed.wav.cursor += 735 * ACSIZE;
         
         if (false)
         {
@@ -9571,11 +10245,11 @@
 
     public void display(GLAutoDrawable drawable)
     {
-        if (GrafreeD.savesound && GrafreeD.hassound)
+        if (Grafreed.savesound && Grafreed.hassound)
         {
-            GrafreeD.wav.save();
-            GrafreeD.savesound = false;
-            GrafreeD.hassound = false;
+            Grafreed.wav.save();
+            Grafreed.savesound = false;
+            Grafreed.hassound = false;
         }
 //        if (DEBUG_SELECTION)
 //        {
@@ -9705,7 +10379,7 @@
             Object3D theobject = object;
             Object3D theparent = object.parent;
             object.parent = null;
-            object = (Object3D)GrafreeD.clone(object);
+            object = (Object3D)Grafreed.clone(object);
             object.Stripify();
             if (theobject.selection == null || theobject.selection.Size() == 0)
                 theobject.PreprocessOcclusion(this);
@@ -10126,7 +10800,16 @@
             // Bump noise
             gl.glActiveTexture(GL.GL_TEXTURE6);
             //gl.glBindTexture(GL.GL_TEXTURE_2D, bump_noise);
-            BindTexture(NOISE_TEXTURE, false, 2);
+            
+    try
+    {
+        BindTexture(NOISE_TEXTURE, false, 2);
+    }
+    catch (Exception e)
+    {
+        System.err.println("FAILED: " + NOISE_TEXTURE);
+    }
+           
 
             gl.glActiveTexture(GL.GL_TEXTURE0);
             gl.glEnable(GL.GL_TEXTURE_2D);
@@ -10340,7 +11023,7 @@
         fragmentMode |= (lightslot - 64) << 2; // 1; // first bit is available for aniso
         //System.out.println("fragmentMode = " + fragmentMode);
 
-        if (DrawMode() == DEFAULT || DrawMode() == SELECTION || DEBUG_SELECTION)
+        if (DrawMode() == DEFAULT || DrawMode() == SELECTION || IsDebugSelection())
         {
             /*
             if (CULLFACE || (ambientOcclusion && OCCLUSION_CULLING))
@@ -10590,8 +11273,14 @@
     {
             renderpass++;
 //        System.out.println("Draw object... ");
+        STEP = 1;
         if (FAST) // in case there is no script
-            STEP = 16;
+            STEP = 8;
+            
+        if (CURRENTANTIALIAS == 0 || ACSIZE == 1)
+        {
+            STEP *= 4;
+        }
             
         //object.FullInvariants();
         
@@ -10605,8 +11294,8 @@
             e.printStackTrace();
         }
         
-        if (GrafreeD.RENDERME > 0)
-            GrafreeD.RENDERME--; // mechante magouille
+        if (Grafreed.RENDERME > 0)
+            Grafreed.RENDERME--; // mechante magouille
         
         Globals.ONESTEP = false;
     }
@@ -10641,7 +11330,7 @@
             callist = gl.glGenLists(1);
         }
 
-        boolean selectmode = DrawMode() == SELECTION || CameraPane.DEBUG_SELECTION;
+        boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
         
         boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
         
@@ -10676,7 +11365,14 @@
 
                 usedtextures.clear();
             
-                BindTextures(DEFAULT_TEXTURES, 2);
+    try
+    {
+        BindTextures(DEFAULT_TEXTURES, 2);
+    }
+    catch (Exception e)
+    {
+        System.err.println("FAILED: " + DEFAULT_TEXTURES);
+    }
             }
             //System.out.println("--> " + stackdepth);
 //            GrafreeD.traceon();
@@ -10767,7 +11463,14 @@
             if (checker != null && DrawMode() == DEFAULT)
             {
                 //BindTexture(IMMORTAL_TEXTURE);
-                BindTextures(checker.GetTextures(), checker.texres);
+    try
+    {
+        BindTextures(checker.GetTextures(), checker.texres);
+    }
+    catch (Exception e)
+    {
+        System.err.println("FAILED: " + checker.GetTextures());
+    }
                 // NEAREST
                 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
                 DrawChecker(gl);
@@ -11799,8 +12502,8 @@
 
            // display shadow only (bump == 0)
          "SUB temp.x, half.x, shadow.x;" +
-         "MOV temp.y, -params6.x;" +
-         "SLT temp.z, temp.y, zero.x;" +
+         "MOV temp.y, -params5.z;" + // params6.x;" +
+         "SLT temp.z, temp.y, -one2048th.x;" +
          "SUB temp.y, one.x, temp.z;" +
          "MUL temp.x, temp.x, temp.y;" +
          "KIL temp.x;" +
@@ -11929,8 +12632,10 @@
             "MAX ndotl.x, ndotl.x, -ndotl.x;" +
                 
                 "SUB temp.x, one.x, ndotl.x;" +
-                "ADD temp.x, temp.x, options2.z;" + // lightsheen
-                "ADD temp.y, one.y, options2.y;" + // sursurface
+                // Tuning for default skin
+                //"ADD temp.x, temp.x, options2.z;" + // lightsheen
+                "MAD temp.x, options2.z, half.y, temp.x;" + // lightsheen
+                "ADD temp.y, one.y, options2.y;" + // subsurface
                 "MUL temp.x, temp.x, temp.y;" +
                                 
                 "MUL saturation, saturation, temp.xxxx;" +
@@ -12129,7 +12834,7 @@
             //once = true;
         }
 
-        System.out.print("Program #" + mode + "; length = " + program.length());
+        System.out.print("Program #" + mode + "; instructions = " + program.split(";").length + "; length = " + program.length());
         System.out.println(" - " + (mode >> 3) + " lights; " + ((mode & 2) == 2 ? "anisoUV " : "") + ((mode & 4) == 4 ? "SoftShadow " : ""));
         loadProgram(gl, GL.GL_FRAGMENT_PROGRAM_ARB, program);
 
@@ -12262,12 +12967,16 @@
 
                 "ADD " + depth + ".z, " + depth + ".z, temp.x;" +
                 //"SUB " + depth + ".z, " + depth + ".z, temp.x;" + // back face shadowing!
+                
+                // Compare fragment depth in light space with shadowmap.
                 "SUB temp.x, fragment.texcoord[1].z, " + depth + ".z;" +
                 "SGE temp.y, temp.x, zero.x;" +
-                "SUB " + shadow + ".y, one.x, temp.y;" +
+                "SUB " + shadow + ".y, one.x, temp.y;" + // Specular is fully occluded
+                
+                // Reverse comparison
                 "SUB temp.x, one.x, temp.x;" +
                 "MUL " + shadow + ".x, temp.x, temp.y;" +
-                "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // specular is fully occluded
+                "SUB " + shadow + ".x, one.x, " + shadow + ".x;" + // diffuse
                 "POW " + shadow + ".x, " + shadow + ".x, params5.z;" + // fake depth
 
                 "SLT " + shadow + ".z, fragment.texcoord[1].z, " + depth + ".z;" +
@@ -12281,6 +12990,10 @@
                 // No shadow for backface
                 "DP3 temp.x, normal, lightd;" +
                 "SLT temp.x, temp.x, zero.x;" + // shadoweps
+                "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
+
+                // No shadow when out of frustrum
+                "SGE temp.x, " + depth + ".z, one.z;" +
                 "LRP " + shadow + ", temp.x, one, " + shadow + ";" +
                 "";
     }
@@ -12839,7 +13552,7 @@
     public void mousePressed(MouseEvent e)
     {
         //System.out.println("mousePressed: " + e);
-        clickStart(e.getX(), e.getY(), e.getModifiersEx());
+        clickStart(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
     }
 
     static long prevtime = 0;
@@ -12866,6 +13579,7 @@
 	
         //System.err.println("Dtime = " + Dtime + "; units = " + e.getUnitsToScroll() + "; ratio (units/ms) = " + ratio);
             
+        if (BUTTONLESSWHEEL)
 	if (Math.abs(ratio) < 0.1 || Math.abs(Dtime) == 0) // < 30)
 	{
             return;
@@ -12874,7 +13588,7 @@
         boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
         
         // TIMER
-        if (!wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
+        if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
         {
             keepboxmode = BOXMODE;
             keepsupport = SUPPORT;
@@ -12914,8 +13628,8 @@
       //      mode |= META;
         //}
         
-        SetMouseMode(WHEEL | e.getModifiersEx());
-        drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0);
+        SetMouseMode(e.getModifiers(), WHEEL | e.getModifiersEx());
+        drag(anchorX, anchorY + e.getUnitsToScroll()*8, 0, 0);
         anchorX = ax;
         anchorY = ay;
         prevX = px;
@@ -12975,6 +13689,10 @@
 //            wasliveok = true;
 //            waslive = false;
             
+            // May 2019 Forget it:
+            if (true)
+                    return;
+            
             // source == timer
             if (mouseDown)
             {
@@ -13013,7 +13731,7 @@
     
     javax.swing.Timer timer = new javax.swing.Timer(350, this);
 
-    void clickStart(int x, int y, int modifiers)
+    void clickStart(int x, int y, int modifiers, int modifiersex)
     {
         if (!wasliveok)
             return;
@@ -13030,7 +13748,7 @@
 //        touched = true; // main DL
         if (isRenderer)
         {
-            SetMouseMode(modifiers);
+            SetMouseMode(modifiers, modifiersex);
         }
 
         selectX = anchorX = x;
@@ -13043,7 +13761,7 @@
         clicked = true;
         hold = false;
 
-        if (((modifiers & ~1024) & ~0) == 0) // Single or multiple selection
+        if (((modifiersex & ~1024) & ~0) == 0) // Single or multiple selection
         // june 2013 means CTRL_CLICK: if (((modifiers & ~1024) & ~128) == 0) // Single or multiple selection
         {
       //  System.out.println("RESTART II " + modifiers);
@@ -13074,7 +13792,7 @@
             info.camera = renderCamera;
             info.x = x;
             info.y = y;
-            info.modifiers = modifiers;
+            info.modifiers = modifiersex;
             editObj = object.doEditClick(info, 0);
             if (!editObj)
             {
@@ -13091,11 +13809,11 @@
     
     public void mouseDragged(MouseEvent e)
     {
+        //System.out.println("mouseDragged: " + e);
         if (isRenderer)
             movingcamera = true;
         //if (drawing)
         //return;
-        //System.out.println("mouseDragged: " + e);
         if ((e.getModifiersEx() & CTRL) != 0
             || (e.getModifiersEx() & COMMAND) != 0) // || IsFrozen())
         {
@@ -13103,7 +13821,7 @@
             clickEnd(e.getX(), e.getY(), e.getModifiersEx());
         }
         else
-            drag(e.getX(), e.getY(), e.getModifiersEx());
+            drag(e.getX(), e.getY(), e.getModifiers(), e.getModifiersEx());
         
     //try { Thread.sleep(1); } catch (Exception ex) {}
     }
@@ -13115,6 +13833,11 @@
     cVector tmp = new cVector();
     cVector tmp2 = new cVector();
     boolean isMoving;
+
+    public cVector TargetLookAt()
+    {
+            return targetLookAt;
+    }
 
     class PingThread extends Thread
     {
@@ -13271,6 +13994,7 @@
         
         public void run()
         {
+                new Exception().printStackTrace();
             System.exit(0);
             for (;;)
             {
@@ -13334,7 +14058,7 @@
                     {
                         Globals.lighttouched = true;
                     }
-                    drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
+                    drag(X, (mouseMode != 0) ? Y : anchorY, 0, MODIFIERS);
                 }
             //else
             }
@@ -13434,7 +14158,7 @@
     int X, Y;
     boolean SX, SY;
 
-    void drag(int x, int y, int modifiers)
+    void drag(int x, int y, int modifiers, int modifiersex)
     {
         if (IsFrozen())
         {
@@ -13443,17 +14167,17 @@
 
         drag = true; // NEW
         
-        boolean continuous = (modifiers & COMMAND) == COMMAND;
+        boolean continuous = (modifiersex & COMMAND) == COMMAND;
 
         X = x;
         Y = y;
         // floating state for animation
-        MODIFIERS = modifiers;
-        modifiers &= ~1024;
+        MODIFIERS = modifiersex;
+        modifiersex &= ~1024;
         if (false) // modifiers != 0)
         {
             //new Exception().printStackTrace();
-            System.out.println("mouseDragged: " + modifiers);
+            System.out.println("mouseDragged: " + modifiersex);
             System.out.println("SHIFT = " + SHIFT);
             System.out.println("CONTROL = " + COMMAND);
             System.out.println("META = " + META);
@@ -13473,7 +14197,7 @@
                 info.camera = renderCamera;
                 info.x = x;
                 info.y = y;
-                object.editWindow.copy.doEditDrag(info);
+                object.editWindow.copy.doEditDrag(info, (modifiers & MouseEvent.BUTTON3_MASK) != 0);
             } else
             {
                 if (x < startX)
@@ -13625,7 +14349,6 @@
     public void mouseMoved(MouseEvent e)
     {
         //System.out.println("mouseMoved: " + e);
-
         if (isRenderer)
             return;
         
@@ -13673,9 +14396,9 @@
         boolean control = ((modifiers & CTRL) != 0); // june 2013: for point selection
         boolean command = ((modifiers & COMMAND) != 0); // june 2013: for multiple selection
         
-        if (control || command || IsFrozen())
+// No delay        if (control || command || IsFrozen())
             timeout = true;
-        else
+// ?? May 2019        else
        // timer.setDelay((modifiers & 128) != 0?0:350);
         mouseDown = false;
     if (!control && !command) // june 2013
@@ -13785,7 +14508,7 @@
         System.out.println("keyReleased: " + e);
     }
 
-    void SetMouseMode(int modifiers)
+    void SetMouseMode(int modifiers, int modifiersex)
     {
         //System.out.println("SetMouseMode = " + modifiers);
         //modifiers &= ~1024;
@@ -13797,25 +14520,25 @@
         //if (modifiers == 0) // || (modifiers == (1024 | CONTROL)))
         //	return;
         //System.out.println("SetMode = " + modifiers);
-        if ((modifiers & WHEEL) == WHEEL)
+        if ((modifiersex & WHEEL) == WHEEL)
         {
             mouseMode |= ZOOM;
         }
         
         boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
-        if (capsLocked || (modifiers & META) == META)
+        if (capsLocked) // || (modifiers & META) == META)
         {
             mouseMode |= VR; // BACKFORTH;
         }
-        if ((modifiers & CTRLCLICK) == CTRLCLICK)
+        if ((modifiersex & CTRLCLICK) == CTRLCLICK)
         {
             mouseMode |= SELECT;
         }
-        if ((modifiers & COMMAND) == COMMAND)
+        if ((modifiersex & COMMAND) == COMMAND)
         {
             mouseMode |= SELECT;
         }
-        if ((modifiers & SHIFT) == SHIFT || forcetranslate)
+        if ((modifiersex & SHIFT) == SHIFT || forcetranslate || (modifiers & MouseEvent.BUTTON3_MASK) != 0)
         {
             mouseMode &= ~VR;
             mouseMode |= TRANSLATE;
@@ -13844,10 +14567,10 @@
 
         if (isRenderer) //
         {
-            SetMouseMode(modifiers);
+            SetMouseMode(0, modifiers);
         }
 
-        theRenderer.keyPressed(key);
+        Globals.theRenderer.keyPressed(key);
     }
 
     int kompactbit = 4; // power bit
@@ -13859,7 +14582,7 @@
     float SATPOW = 1; // 2; // 0.5f;
     float BRIPOW = 1; // 0.5f; // 0.5f;
     
-    void keyPressed(int key)
+    public void keyPressed(int key)
     {
         if (key >= '0' && key <= '5')
             clampbit = (key-'0');
@@ -14180,7 +14903,7 @@
                 //RESIZETEXTURE ^= true;
                 //break;
             case 'z':
-                RENDERSHADOW ^= true;
+                Globals.RENDERSHADOW ^= true;
                 Globals.lighttouched = true;
                 repaint();
                 break;
@@ -14296,6 +15019,7 @@
         }
     //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
     }
+    
     static double OCCLUSIONBOOST = 1; // 0.5;
 
     void keyReleased(int key, int modifiers)
@@ -14303,11 +15027,11 @@
         //mode = ROTATE;
         if ((MODIFIERS & COMMAND) == 0) // VR??
         {
-            SetMouseMode(modifiers);
+            SetMouseMode(0, modifiers);
         }
     }
 
-    protected void processKeyEvent(KeyEvent e)
+    public void processKeyEvent(KeyEvent e)
     {
         switch (e.getID())
         {
@@ -14437,8 +15161,9 @@
 
     protected void processMouseMotionEvent(MouseEvent e)
     {
-        //System.out.println("processMouseMotionEvent: " + mouseMode);
-        if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
+        //System.out.println("processMouseMotionEvent: " + mouseMode + " " + e.getModifiers() + " " + e.getModifiersEx() + " " + e.getButton());
+        //if (e.getButton() == MouseEvent.NOBUTTON && (mouseMode & SELECT) == 0)
+        if ((e.getModifiers() & MouseEvent.BUTTON1_MASK) == 0 && (e.getModifiers() & MouseEvent.BUTTON3_MASK) == 0 && (mouseMode & SELECT) == 0)
         {
             mouseMoved(e);
         } else
@@ -14468,6 +15193,7 @@
 
     void SelectParent()
     {
+                new Exception().printStackTrace();
         System.exit(0);
         Composite group = (Composite) object;
         java.util.Vector selectees = new java.util.Vector(group.selection);
@@ -14491,6 +15217,7 @@
 
     void SelectChildren()
     {
+                new Exception().printStackTrace();
         System.exit(0);
         /*
         Composite group = (Composite) object;
@@ -14873,6 +15600,7 @@
     public boolean mouseDown(Event evt, int x, int y)
     {
         System.out.println("mouseDown: " + evt);
+        System.exit(0);
         /*
         locked = true;
         drag = false;
@@ -14916,7 +15644,7 @@
         {
             keyPressed(0, modifiers);
         }
-        clickStart(x, y, modifiers);
+ //       clickStart(x, y, modifiers);
         return true;
     }
 
@@ -15034,7 +15762,7 @@
         {
             keyReleased(0, 0);
         }
-        drag(x, y, modifiers);
+        drag(x, y, 0, modifiers);
         return true;
     }
 
@@ -15604,6 +16332,7 @@
         {
             if (!selection)
             {
+                new Exception().printStackTrace();
                 System.exit(0);
                 return;
             }
@@ -15731,16 +16460,16 @@
                             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]));
                         }
                         
-                        previousselectedpoint = (Sphere) GrafreeD.clone(selectedpoint);
+                        previousselectedpoint = (Sphere) Grafreed.clone(selectedpoint);
                     }
                 }
                 
                 if (!movingcamera && !PAINTMODE)
                     object.editWindow.ScreenFitPoint(); // fev 2014
                 
-                if (PAINTMODE && GrafreeD.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
+                if (PAINTMODE && Grafreed.clipboard.size() == 1) // object.editWindow.copy.selection.Size() > 0)
                 {
-                    Object3D paintobj = GrafreeD.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
+                    Object3D paintobj = Grafreed.clipboard.get(0); // object.editWindow.copy.selection.elementAt(0);
                     
                     Object3D group = new Object3D("inst" + paintcount++);
                     
@@ -15896,7 +16625,7 @@
                 gl.glDisable(gl.GL_CULL_FACE);
             }
 
-            if (!RENDERSHADOW)
+            if (!Globals.RENDERSHADOW)
                 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
 
             // SB gl.glPolygonOffset(2.5f, 10);
@@ -15906,7 +16635,7 @@
             //gl.glColorMask(false, false, false, false);
 
             //render_scene_from_light_view(gl, drawable, 0, 0);
-            if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
+            if (Globals.RENDERSHADOW && Globals.lighttouched && (!movingcamera || !Globals.FREEZEONMOVE)) // && !parent.IsFreezed())
             {
                 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
 
@@ -15966,7 +16695,6 @@
 
     class AntialiasBuffer implements GLEventListener
     {
-
         CameraPane parent = null;
 
         AntialiasBuffer(CameraPane p)
@@ -16359,7 +17087,7 @@
         }
     }
     
-    static void DrawPoints(CameraPane cpane)
+    static void DrawPoints(iCameraPane cpane)
     {
         for (int i=0; i<8; i++) // first and last are red
         {
@@ -16391,10 +17119,11 @@
     static IntBuffer textbuffer = null; // IntBuffer.allocate(TEXT_WIDTH*8*8 * TEXT_HEIGHT);
     // Depth buffer format
     //private int depth_format;
-    static public void NextIndex(Object3D o, GL gl)
+    
+    public void NextIndex()
     {
         indexcount+=16;
-        gl.glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
+        GetGL().glColor3d(((indexcount >>> 16) & 255) / 255.0, ((indexcount >>> 8) & 255) / 255.0, ((indexcount) & 255) / 255.0);
     //objects[indexcount] = o;
     //System.out.println("indexcount = " + indexcount);
     }

--
Gitblit v1.6.2