From f1c718cce66e5651a0dae91375db6ebfaded1a92 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sat, 27 Apr 2019 21:33:41 -0400
Subject: [PATCH] Test unfold UV

---
 CameraPane.java | 2302 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 2,001 insertions(+), 301 deletions(-)

diff --git a/CameraPane.java b/CameraPane.java
index dda961a..55e5ab4 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -31,8 +31,12 @@
 
 import gleem.linalg.Mat4f;
 
-class CameraPane extends GLCanvas implements Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
+class CameraPane extends GLCanvas implements iCameraPane, Runnable, GLEventListener, ActionListener, MouseWheelListener, MouseMotionListener, MouseListener, KeyListener
 {
+    static cMaterial[] materialstack = new cMaterial[65536];
+    static boolean[] selectedstack = new boolean[65536];
+    static int materialdepth = 0;
+
     static boolean DEBUG = false;
     static boolean FRUSTUM = false; // still bogus true; // frustum culling
 
@@ -42,25 +46,7 @@
     
     static int STEP = 1;
 
-    static boolean ONESTEP = false; // do LIVE once
-    
-    /**
-     * @return the LIVE
-     */
-    public static boolean isLIVE()
-    {
-        return LIVE || ONESTEP;
-    }
-
-    /**
-     * @param aLIVE the LIVE to set
-     */
-    public static void setLIVE(boolean aLIVE)
-    {
-        LIVE = aLIVE;
-    }
-    
-    /*static*/ boolean CULLFACE = false; // true;
+    /*static*/ private boolean CULLFACE = false; // true;
     /*static*/ boolean NEAREST = false; // true;
     /*static*/ boolean WIREFRAME = false; // true;
     
@@ -97,17 +83,17 @@
 
 static    boolean textureon = true;
 static    boolean LOCALTRANSFORM = false;
-private static    boolean LIVE = false;
 static    boolean FULLSCREEN = false;
 static    boolean SUPPORT = true;
-static    boolean CROWD = false;
 static    boolean INERTIA = true;
-static    boolean FAST = false;
+static    boolean FAST = true; // false;
 static    boolean SLOWPOSE = false;
 static    boolean FOOTCONTACT = true;
 
 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;
@@ -165,12 +151,39 @@
         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)
+    {
+        super(defaultcaps, null, withcontext?glcontext:null, null);
+
+        //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395  +  2736391  + 1943018 +  1289475 +  1141569  + 1069350 +  911559 +  721229 +  395886  + 377972 +   246700 +  211156  +  173985 +  141133  + 118279 +  112079 +  108523));
+        glcontext = getContext();
+
+        cameras = new Camera[2];
+        targetLookAts = new cVector[2];
+
+        SetCamera(cam);
+
+        SetLight(new Camera(new cVector(10, 10, -20)));
+
+        object = o;
+
+        setBackground(Color.white);
+
+        addKeyListener(this);
+        addMouseListener(this);
+        addMouseMotionListener(this);
+        addMouseWheelListener(this);
+        //System.out.println("addGLEventListener: " + this);
+        addGLEventListener(this);
+
+//        pingthread.start(); // may 2013
     }
 
     static boolean AntialiasingEnabled()
@@ -178,12 +191,53 @@
         return CURRENTANTIALIAS > 0;
     }
     
-    void ClearDepth()
+    /// 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()
     {
         GetGL().glClear(GetGL().GL_DEPTH_BUFFER_BIT);
     }
     
-    void DepthTest(boolean depthtest)
+    public void DepthTest(boolean depthtest)
     {
         if (depthtest)
             GetGL().glDepthFunc(GL.GL_LEQUAL);
@@ -191,7 +245,7 @@
             GetGL().glDepthFunc(GL.GL_ALWAYS);
     }
     
-    void DepthWrite(boolean depthwrite)
+    public void DepthWrite(boolean depthwrite)
     {
         if (depthwrite)
             GetGL().glDepthMask(true);
@@ -199,12 +253,1594 @@
             GetGL().glDepthMask(false);
     }
     
-    void BackFaceCull(boolean bfc)
+    public void BackFaceCull(boolean bfc)
     {
         if (bfc)
             GetGL().glEnable(GetGL().GL_CULL_FACE);
         else
             GetGL().glDisable(GetGL().GL_CULL_FACE);
+    }
+    
+    public boolean BackFaceCullMode()
+    {
+            return this.CULLFACE;
+    }
+    
+    public boolean IsAmbientOcclusionOn()
+    {
+            return this.ambientOcclusion;
+    }
+    
+    public boolean IsDebugSelection()
+    {
+            return DEBUG_SELECTION;
+    }
+    
+    public boolean IsFrozen()
+    {
+        boolean selectmode = this.DrawMode() == SELECTION || this.IsDebugSelection();
+        
+        return !selectmode && cameracount == 0; // != 0;
+    }
+    
+    // Currently in Globals
+        public int DrawMode()
+        {
+                return Globals.DrawMode();
+        }
+        
+    public Camera EyeCamera()
+    {
+            return eyeCamera;
+    }
+    
+    public Camera LightCamera()
+    {
+            return lightCamera;
+    }
+    
+    public Camera ManipCamera()
+    {
+            return manipCamera;
+    }
+    
+    public Camera RenderCamera()
+    {
+            return renderCamera;
+    }
+    
+    public Camera[] Cameras()
+    {
+            return cameras;
+    }
+    
+    public void PushMaterial(Object3D obj, boolean selected)
+    {
+            CameraPane display = this;
+            javax.media.opengl.GL gl = display.GetGL();
+            cMaterial material = obj.material;
+            
+            if (material != null)
+            {
+                materialstack[materialdepth] = material;
+                selectedstack[materialdepth] = selected;
+                cStatic.objectstack[materialdepth++] = obj;
+                //System.out.println("material " + material);
+                //Applet3D.tracein(this, selected);
+                display.vector2buffer = obj.projectedVertices;
+                if (obj instanceof Camera)
+                {
+                    display.options1[0] = material.shift;
+                //System.out.println("shift " + material.shift);
+                    display.options1[1] = material.lightarea;
+                    display.options1[2] = material.shadowbias;
+                    display.options1[3] = material.aniso;
+                    display.options1[4] = material.anisoV;
+                    display.options2[0] = material.opacity;
+                    display.options2[1] = material.diffuse;
+                    display.options2[2] = material.factor;
+
+                    cColor.HSBtoRGB(material.color, material.modulation, 1, display.options3);
+                    display.options4[0] = material.cameralight/0.2f;
+                    display.options4[1] = material.subsurface;
+                    display.options4[2] = material.sheen;
+                    
+                 //   if (display.CURRENTANTIALIAS > 0)
+                 //       display.options3[3] /= 4;
+
+                    /*
+                    System.out.println("Focus = " + display.options1[0]);
+                    System.out.println("Aperture = " + display.options1[1]);
+                    System.out.println("ShadowBlur = " + display.options1[2]);
+                    System.out.println("Antialiasing = " + display.options1[3]);
+                    System.out.println("Fog = " + display.options2[0]);
+                    System.out.println("Intensity = " + display.options2[1]);
+                    System.out.println("Elevation = " + display.options2[2]);
+                /**/
+                } else
+                {
+                    DrawMaterial(material, selected);
+                }
+            } else
+            {
+                if (selected && CameraPane.flash)
+                {
+                    display.modelParams4[1] = 100;
+                    gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
+                }
+            }
+    }
+    
+    public void PushMaterial2(Object3D obj, boolean selected)
+    {
+            CameraPane display = this;
+            cMaterial material = obj.material;
+            
+        if (material != null)
+        {
+            materialstack[materialdepth] = material;
+            selectedstack[materialdepth] = selected;
+            cStatic.objectstack[materialdepth++] = obj;
+            //System.out.println("material " + material);
+            //Applet3D.tracein("selected ", selected);
+            display.vector2buffer = obj.projectedVertices;
+            display.DrawMaterial(material, selected);
+        }
+    }
+    
+    public void PopMaterial(Object3D obj, boolean selected)
+    {
+            CameraPane display = this;
+            javax.media.opengl.GL gl = display.GetGL();
+            cMaterial material = obj.material;
+            
+            //if (parent != null && parent.GetMaterial() != null)
+            //	parent.GetMaterial().Draw(display, parent.IsSelected(this));
+            if (material != null)
+            {
+                materialdepth -= 1;
+                if (materialdepth > 0)
+                {
+                    display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
+                    display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
+                }
+            //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
+            } else if (selected && CameraPane.flash && obj.GetMaterial() != null)
+            {
+                display.modelParams4[1] = obj.GetMaterial().cameralight;
+                gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
+            }
+    }
+    
+    public void PopMaterial2(Object3D obj)
+    {
+            CameraPane display = this;
+            cMaterial material = obj.material;
+            
+        if (material != null)
+        {
+            materialdepth -= 1;
+            if (materialdepth > 0)
+            {
+                display.vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
+                display.DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
+            }
+        //Applet3D.traceout("selected ", (stackdepth>0)?selectedstack[stackdepth-1]:"???");
+        //else
+        //material.Draw(display, false);
+        }
+    }
+    
+    public void DrawFace(Object3D obj, Vertex pv, Vertex qv, Vertex rv, Face face)
+    {
+            CameraPane display = this;
+            
+        if (pv.y == -10000 ||
+            qv.y == -10000 ||
+            rv.y == -10000)
+            return;
+            
+//        float b = f.nbiterations & 1;
+//        float g = (f.nbiterations>>1) & 1;
+//        float r = (f.nbiterations>>2) & 1;
+//
+//        //if (f.weight == 10000)
+//        //{
+//        //    r = 1; g = b = 0;
+//        //}
+//        //else
+//        //{
+//        //    assert(f.weight < 10000);
+//            r = g = b = (float)bRep.FaceWeight(f)*100;
+//            if (r<0)
+//            assert(r>=0);
+//        //}
+        
+        javax.media.opengl.GL gl = display.GetGL();
+        
+        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)
+        {
+            //gl.glBegin(gl.GL_TRIANGLES);
+            boolean hasnorm = pv.norm != null; // && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
+            if (!hasnorm)
+            {
+           //     System.out.println("FUCK!!");
+                LA.vecSub(pv/*.pos*/, qv/*.pos*/, obj.v0);
+                LA.vecSub(pv/*.pos*/, rv/*.pos*/, obj.v1);
+                LA.vecCross(obj.v0, obj.v1, obj.v2);
+                LA.vecNormalize(obj.v2);
+                gl.glNormal3f((float) obj.v2.x, (float) obj.v2.y, (float) obj.v2.z);
+            }
+
+            // P
+            float x = (float)pv.x;
+            float y = (float)pv.y;
+            float z = (float)pv.z;
+            
+            if (hasnorm)
+            {
+//            if (!pv.norm.normalized())
+//                assert(pv.norm.normalized());
+            
+                //System.out.println("normalp = " + pv.norm.x + ", " + pv.norm.y + ", " + pv.norm.z);
+                    float nx = (float)pv.norm.x;
+                    float ny = (float)pv.norm.y;
+                    float nz = (float)pv.norm.z;
+                    
+                x += nx * obj.NORMALPUSH;
+                y += ny * obj.NORMALPUSH;
+                z += nz * obj.NORMALPUSH;
+                
+                gl.glNormal3f(nx, ny, nz);
+            }
+            gl.glColor4f(pv.AO, pv.AO, pv.AO, 1);
+            SetColor(obj, pv);
+            //gl.glColor4f(r, g, b, 1);
+    //gl.glColor4f(pv.boundary, pv.boundary, pv.boundary, 1);
+            if (obj.flipV)
+                gl.glTexCoord2f((float) pv.s, 1-(float) pv.t);
+            else
+                gl.glTexCoord2f((float) pv.s, (float) pv.t);
+            //System.out.println("vertexp = " + pv.x + ", " + pv.y + ", " + pv.z);
+            
+            gl.glVertex3f(x, y, z);
+            
+            // Q
+            x = (float)qv.x;
+            y = (float)qv.y;
+            z = (float)qv.z;
+            
+//            Print(pv);
+            if (hasnorm)
+            {
+//            assert(qv.norm.normalized());
+                //System.out.println("normalq = " + qv.norm.x + ", " + qv.norm.y + ", " + qv.norm.z);
+                    float nx = (float)qv.norm.x;
+                    float ny = (float)qv.norm.y;
+                    float nz = (float)qv.norm.z;
+                    
+                x += nx * obj.NORMALPUSH;
+                y += ny * obj.NORMALPUSH;
+                z += nz * obj.NORMALPUSH;
+                
+                gl.glNormal3f(nx, ny, nz);
+            }
+            //System.out.println("vertexq = " + qv.s + ", " + qv.t);
+        //    boolean locked = false;
+        //    float eps = 0.1f;
+        //    boolean wrap = CameraPane.UVWRAP; // true; // UV WRAP TEXTURE ISSUE: true = artifacts, false = nice
+            
+        //    int dot = 0; //*/ (int)f.dot;
+            
+        //    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)
+            if (obj.flipV)
+                gl.glTexCoord2f((float) qv.s, 1-(float) qv.t);
+            else
+                gl.glTexCoord2f((float) qv.s, (float) qv.t);
+        //    else
+        //    {
+        //        locked = true;
+        //        gl.glTexCoord2f((float) pv.s, (float) pv.t);
+        //    }
+            gl.glColor4f(qv.AO, qv.AO, qv.AO, 1);
+            SetColor(obj, qv);
+            
+            gl.glVertex3f(x, y, z);
+            //gl.glColor4f(r, g, b, 1);
+   //gl.glColor4f(qv.boundary, qv.boundary, qv.boundary, 1);
+            //System.out.println("vertexq = " + qv.x + ", " + qv.y + ", " + qv.z);
+//            Print(qv);
+
+            // R
+            x = (float)rv.x;
+            y = (float)rv.y;
+            z = (float)rv.z;
+            
+            if (hasnorm)
+            {
+//            assert(rv.norm.normalized());
+                //System.out.println("normalr = " + rv.norm.x + ", " + rv.norm.y + ", " + rv.norm.z);
+                    float nx = (float)rv.norm.x;
+                    float ny = (float)rv.norm.y;
+                    float nz = (float)rv.norm.z;
+                    
+                x += nx * obj.NORMALPUSH;
+                y += ny * obj.NORMALPUSH;
+                z += nz * obj.NORMALPUSH;
+                
+                gl.glNormal3f(nx, ny, nz);
+            }
+            
+        //    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)
+            if (obj.flipV)
+                gl.glTexCoord2f((float) rv.s, 1-(float) rv.t);
+            else
+                gl.glTexCoord2f((float) rv.s, (float) rv.t);
+        //    else
+        //        gl.glTexCoord2f((float) pv.s, (float) pv.t);
+            
+        //    f.dot = dot;
+            
+            gl.glColor4f(rv.AO, rv.AO, rv.AO, 1);
+            SetColor(obj, rv);
+            //gl.glColor4f(r, g, b, 1);
+   //gl.glColor4f(rv.boundary, rv.boundary, rv.boundary, 1);
+            //System.out.println("vertexr = " + rv.x + ", " + rv.y + ", " + rv.z);
+            gl.glVertex3f(x, y, z);
+//            Print(rv);
+        //gl.glEnd();
+        }
+        else
+        {
+            gl.glVertex3f((float) pv.x, (float) pv.y, (float) pv.z);
+            gl.glVertex3f((float) qv.x, (float) qv.y, (float) qv.z);
+            gl.glVertex3f((float) rv.x, (float) rv.y, (float) rv.z);
+            
+        }
+
+        if (false) // (attributes & WIREFRAME) != 0)
+        {
+            gl.glDisable(gl.GL_LIGHTING);
+
+            gl.glBegin(gl.GL_LINE_LOOP);
+            gl.glVertex3d(pv./*pos.*/x, pv./*pos.*/y, pv./*pos.*/z);
+            gl.glVertex3d(qv./*pos.*/x, qv./*pos.*/y, qv./*pos.*/z);
+            gl.glVertex3d(rv./*pos.*/x, rv./*pos.*/y, rv./*pos.*/z);
+            gl.glEnd();
+
+            gl.glEnable(gl.GL_LIGHTING);
+        }
+    }
+
+    /**
+     * <code>draw</code> renders a <code>TriMesh</code> object including
+     * it's normals, colors, textures and vertices.
+     *
+     * @see Renderer#draw(TriMesh)
+     * @param tris
+     *            the mesh to render.
+     */
+    public void DrawParticles(TriMesh geo, Object3D shape, boolean selected, boolean rotate) // TriMesh tris)
+    {
+            CameraPane display = this;
+            
+        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();
+        
+        FloatBuffer vertBuf = geo.vertBuf;
+
+        int v = vertBuf.capacity();
+
+        int count = 0;
+        
+        boolean cf = gl.glIsEnabled(gl.GL_CULL_FACE);
+        gl.glEnable(gl.GL_CULL_FACE);
+   //     gl.glScalef(1.0f/1024,1.0f/1024,1.0f/1024);
+        for (int i=0; i<v/3; i++)
+        {
+            int index3 = i*3;
+            
+            if (geo.sizeBuf.get(index3+1) == 0)
+                continue;
+            
+            count++;
+            
+            int index4 = i*4;
+            
+            float tx = vertBuf.get(index3);
+            float ty = vertBuf.get(index3+1);
+            float tz = vertBuf.get(index3+2);
+            
+        //    if (tx == 0 && ty == 0 && tz == 0)
+        //        continue;
+            
+        gl.glMatrixMode(gl.GL_TEXTURE);
+        gl.glPushMatrix();
+        
+        float[] texmat = geo.texmat;
+        texmat[12] = texmat[13] = texmat[14] = i;
+        
+        gl.glMultMatrixf(texmat, 0);
+        
+            gl.glMatrixMode(gl.GL_MODELVIEW);
+            gl.glPushMatrix();
+            
+            gl.glTranslatef(tx,ty,tz);
+
+            if (rotate)
+                gl.glRotatef(i, 0, 1, 0);
+            
+            float size = geo.sizeBuf.get(index3) / 100;
+            gl.glScalef(size,size,size);
+            
+            float cr = geo.colorBuf.get(index4);
+            float cg = geo.colorBuf.get(index4+1);
+            float cb = geo.colorBuf.get(index4+2);
+            float ca = geo.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)geo.sizeBuf.get(index3+2); // i;
+        RandomNode.globalseed2 = RandomNode.globalseed;
+        
+//            gl.glColor4f(cr,cg,cb,ca);
+   //         gl.glScalef(1024/16,1024/16,1024/16);
+            shape.Draw/*Node*/(display,null,selected,false); // blocked
+   //         gl.glScalef(16.0f/1024,16.0f/1024,16.0f/1024);
+            //gl.glTranslatef(-tx,-ty,-tz);
+            gl.glPopMatrix();
+            
+        gl.glMatrixMode(gl.GL_TEXTURE);
+        gl.glPopMatrix();
+        }
+   //     gl.glScalef(1024,1024,1024);
+        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);
+        
+//        System.err.println("total = " + v/3 + "; displayed = " + count);
+        if (true)
+        return;
+        
+////        if (!tris.predraw(this))
+////        {
+////            return;
+////        }
+////        if (Debug.stats)
+////        {
+////            StatCollector.addStat(StatType.STAT_TRIANGLE_COUNT, tris.getTriangleCount());
+////            StatCollector.addStat(StatType.STAT_VERTEX_COUNT, tris.getVertexCount());
+////            StatCollector.addStat(StatType.STAT_GEOM_COUNT, 1);
+////        }
+////
+////        if (tris.getDisplayListID() != -1)
+////        {
+////            renderDisplayList(tris);
+////            return;
+////        }
+////
+////        if (!generatingDisplayList)
+////        {
+////            applyStates(tris.states, tris);
+////        }
+////        if (Debug.stats)
+////        {
+////            StatCollector.startStat(StatType.STAT_RENDER_TIMER);
+////        }
+////        boolean transformed = doTransforms(tris);
+//
+//        int glMode = GL.GL_TRIANGLES;
+//        switch (getMode())
+//        {
+//            case Triangles:
+//                glMode = GL.GL_TRIANGLES;
+//                break;
+//            case Strip:
+//                glMode = GL.GL_TRIANGLE_STRIP;
+//                break;
+//            case Fan:
+//                glMode = GL.GL_TRIANGLE_FAN;
+//                break;
+//        }
+//
+//        if (!predrawGeometry(gl))
+//        {
+//            // make sure only the necessary indices are sent through on old
+//            // cards.
+//            IntBuffer indices = this.getIndexBuffer();
+//            if (indices == null)
+//            {
+//                logger.severe("missing indices on geometry object: " + this.toString());
+//            } else
+//            {
+//                indices.rewind();
+//                indices.limit(this.getMaxIndex());
+//
+//                gl.glDrawElements(glMode, indices.limit(), GL.GL_UNSIGNED_INT, indices); // TODO Check <count> and assumed <type> of GL_UNSIGNED_INT
+//
+//                indices.clear();
+//            }
+//        } else
+//        {
+//            gl.glDrawElements(glMode, this.getIndexBuffer().limit(),
+//                    GL.GL_UNSIGNED_INT, 0);
+//        }
+//
+////        postdrawGeometry(tris);
+////        if (transformed)
+////        {
+////            undoTransforms(tris);
+////        }
+////
+////        if (Debug.stats)
+////        {
+////            StatCollector.endStat(StatType.STAT_RENDER_TIMER);
+////        }
+////        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)
+    {
+        CameraPane display = this;
+        BoundaryRep bRep = obj.bRep;
+         
+        if (RENDERPROGRAM == 0)
+        {
+            float r = 0;
+            if (bRep != null)
+            {
+                if (bRep.stripified)
+                {
+                    r = 1;
+                }
+            }
+            float g = 0;
+            if (bRep != null)
+            {
+                if (bRep.trimmed)
+                {
+                    g = 1;
+                }
+            }
+            float b = 0;
+            if (obj.support != null && obj.link2master)
+            {
+                b = 1;
+            }
+            display.GetGL().glColor3f(r*p0.AO, g*p0.AO, b*p0.AO);
+            return;
+        }
+        
+        if (display.DrawMode() != CameraPane.SHADOW)
+            return;
+        
+        javax.media.opengl.GL gl = display.GetGL();
+//        if (true) return;
+//        float ao = p.AO;
+//        
+//    //    if (ao == 0 && !bRep.AOdone) // transient problem!
+//    //        ao = 1;
+//        
+//        gl.glColor4f(ao, ao, ao, 1);
+        
+//        CameraPane.selectedpoint.
+//            getAverage(cStatic.point1, true);
+        if (CameraPane.pointflow == null) // !random) // live)
+        {
+            return;
+        }
+        
+        cStatic.point1.set(0,0,0);
+        LA.xformPos(cStatic.point1, CameraPane.selectedpoint.toParent, cStatic.point1);
+
+        cStatic.point1.sub(p0);
+
+
+//        if (marked && (p0.vertexlinks == null || support == null || support.bRep == null)) // no position delta?
+//        {
+//            return;
+//        }
+        
+        //if (true)
+        if (cStatic.point1.dot(cStatic.point1) > 0.000001)
+        {
+            return;
+        }
+        
+        float[] colorV = new float[3];
+        
+        if (false) // marked)
+        {
+            // debug rigging weights
+            for (int object = 0; object < p0.vertexlinks.length; object++)
+            {
+                float weight = p0.weights[object] / p0.totalweight;
+
+    //            if (weight < 0.1)
+    //            {
+    //                assert(weight == 0);
+    //                continue;
+    //            }
+
+                if (p0.vertexlinks[object] == -1)
+                    continue;
+
+                Vertex q = obj.support.bRep.GetVertex(p0.vertexlinks[object]);
+
+                int color = //1 << object; //
+                            //p.vertexlinks.length;
+                        obj.support.bRep.supports[p0.closestsupport].links[object];
+                colorV[2] += (color & 1) * weight;
+                colorV[1] += ((color & 2) >> 1) * weight;
+                colorV[0] += ((color & 4) >> 2) * weight;
+            }
+        }
+        else
+        {
+            if (obj.drawingstarted)
+            {
+                // find next point
+                if (bRep.GetVertex(0).faceindices == null)
+                {
+                    bRep.InitFaceIndices();
+                }
+                
+                double ymin = p0.y;
+                
+                Vertex newp = p0;
+
+                for (int fii = 0; fii < p0.faceindices.length; fii++)
+                {
+                    int fi = p0.faceindices[fii];
+
+                    if (fi == -1)
+                        break;
+
+                    Face f = bRep.GetFace(fi);
+
+                    Vertex p = bRep.GetVertex(f.p);
+                    Vertex q = bRep.GetVertex(f.q);
+                    Vertex r = bRep.GetVertex(f.r);
+                    
+                    int swap = (int)(Math.random()*3);
+                    
+//                    for (int s=swap; --s>=0;)
+//                    {
+//                        Vertex t = p;
+//                        p = q;
+//                        q = r;
+//                        r = t;
+//                    }
+                    if (ymin > p.y)
+                    {
+                        ymin = p.y;
+                        newp = p;
+//                        break;
+                    }
+                    if (ymin > q.y)
+                    {
+                        ymin = q.y;
+                        newp = q;
+//                        break;
+                    }
+                    if (ymin > r.y)
+                    {
+                        ymin = r.y;
+                        newp = r;
+//                        break;
+                    }
+                }
+             
+                CameraPane.selectedpoint.toParent[3][0] = newp.x;
+                CameraPane.selectedpoint.toParent[3][1] = newp.y;
+                CameraPane.selectedpoint.toParent[3][2] = newp.z;
+                
+                obj.drawingstarted = false;
+                
+               // return;
+            }
+            
+            if (false) // CameraPane.DRAW
+            {
+                p0.AO = colorV[0] = 2;
+                colorV[1] = 2;
+                colorV[2] = 2;
+            }
+            
+            CameraPane.pointflow.add(p0);
+            CameraPane.pointflow.Touch();
+        }
+        
+//        gl.glColor3f(colorV[0], colorV[1], colorV[2]);
+//        gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
+//        gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
+    }
+    
+    void DrawMaterial(cMaterial material, boolean selected)
+    {
+            CameraPane display = this;
+        //new Exception().printStackTrace();
+
+        if (display.IsFrozen() && !selected || display.IsAmbientOcclusionOn()) // || display.drawMode == display.SHADOW)
+        {
+            return;
+        }
+
+        javax.media.opengl.GL gl = display.GetGL();
+
+        //Color col = Color.getHSBColor(color,modulation,1);
+        //col.getColorComponents(ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB), CameraPane.modelParams0);
+        if (!material.multiply)
+        {
+            display.color = material.color;
+            display.saturation = material.modulation;
+        }
+        else
+        {
+            display.color *= material.color*2;
+            display.saturation *= material.modulation*2;
+        }
+            
+        cColor.HSBtoRGB(display.color, display.saturation, 1, display.modelParams0);
+
+        float[] colorV = GrafreeD.colorV;
+
+        /**/
+        if (display.DrawMode() == display.DEFAULT) // && display.RENDERPROGRAM == 0)
+        {
+            colorV[0] = display.modelParams0[0] * material.diffuse;
+            colorV[1] = display.modelParams0[1] * material.diffuse;
+            colorV[2] = display.modelParams0[2] * material.diffuse;
+            colorV[3] = material.opacity;
+
+            gl.glColor4f(colorV[0], colorV[1], colorV[2], material.opacity);
+            //System.out.println("Opacity = " + opacity);
+
+            gl.glMaterialfv(gl.GL_FRONT, gl.GL_DIFFUSE, colorV, 0);
+            //color[0] /= 2; color[1] /= 2; color[2] /= 2;
+            gl.glMaterialfv(gl.GL_BACK, gl.GL_DIFFUSE, colorV, 0);
+
+            float amb = material.ambient;
+            if (amb < material.cameralight)
+            {
+                amb = material.cameralight;
+            }
+            colorV[0] = display.modelParams0[0] * material.diffuse * amb;
+            colorV[1] = display.modelParams0[1] * material.diffuse * amb;
+            colorV[2] = display.modelParams0[2] * material.diffuse * amb;
+            gl.glMaterialfv(gl.GL_FRONT, gl.GL_AMBIENT, colorV, 0);
+            //color[0] /= 2; color[1] /= 2; color[2] /= 2;
+            gl.glMaterialfv(gl.GL_BACK, gl.GL_AMBIENT, colorV, 0);
+
+            /**/
+            colorV[0] = ((1 - material.metalness) + display.modelParams0[0] * material.metalness) * material.specular;
+            colorV[1] = ((1 - material.metalness) + display.modelParams0[1] * material.metalness) * material.specular;
+            colorV[2] = ((1 - material.metalness) + display.modelParams0[2] * material.metalness) * material.specular;
+            gl.glMaterialfv(gl.GL_FRONT, gl.GL_SPECULAR, colorV, 0);
+            //color[0] /= 2; color[1] /= 2; color[2] /= 2;
+            gl.glMaterialfv(gl.GL_BACK, gl.GL_SPECULAR, colorV, 0);
+            colorV[0] = 10 / material.shininess; // 1/0.005f;
+            //System.out.println("shininess = " + colorV[0]);
+            if (colorV[0] > 128)
+            {
+                colorV[0] = 128;
+            }
+            gl.glMaterialfv(gl.GL_FRONT, gl.GL_SHININESS, colorV, 0);
+            gl.glMaterialfv(gl.GL_BACK, gl.GL_SHININESS, colorV, 0);
+        /**/
+        }
+        /**/
+
+        //selected = false;
+        selected = selected && display.flash;
+
+        //display.modelParams0[0] = 0; // pigment.r;
+        //display.modelParams0[1] = 0; // pigment.g;
+        //display.modelParams0[2] = 0; // pigment.b;
+        if (!material.multiply)
+        {
+            display.modelParams0[3] = material.metalness;
+            display.modelParams1[0] = material.diffuse;
+            display.modelParams1[1] = material.specular;
+            display.modelParams1[2] = 1 / material.shininess;
+            display.modelParams1[3] = material.shift;
+            display.modelParams2[0] = material.ambient;
+            display.modelParams2[1] = material.lightarea;
+            //System.out.println("light area = " + lightarea);
+            display.modelParams2[2] = 1 / material.factor; // diffuseness
+            display.modelParams2[3] = material.velvet;
+            display.modelParams3[0] = material.sheen;
+            display.modelParams3[1] = material.subsurface;
+            display.modelParams3[2] = material.bump; // backlit
+            display.modelParams3[3] = material.aniso;
+            display.modelParams4[0] = material.anisoV;
+            display.modelParams4[1] = selected ? 100 : material.cameralight;
+            //System.out.println("selected = " + selected);
+            display.modelParams4[2] = material.diffuseness;
+            display.modelParams4[3] = material.shadow;
+            display.modelParams5[0] = material.texture;
+            display.modelParams5[1] = material.opacity;
+            display.modelParams5[2] = material.fakedepth;
+            display.modelParams5[3] = CameraPane.SHADOWCULLFACE ? 0f : (material.shadowbias - 0.005f) / 10;
+        }
+        else
+        {
+            display.modelParams0[3] *= material.metalness*2;
+            display.modelParams1[0] *= material.diffuse*2;
+            display.modelParams1[1] *= material.specular*2;
+            display.modelParams1[2] *= material.shininess*2;
+            display.modelParams1[3] *= material.shift*2;
+            display.modelParams2[0] *= material.ambient*2;
+            display.modelParams2[1] *= material.lightarea*2;
+            display.modelParams2[2] *= material.factor*2;
+            display.modelParams2[3] *= material.velvet*2;
+            display.modelParams3[0] *= material.sheen*2;
+            display.modelParams3[1] *= material.subsurface*2;
+            display.modelParams3[2] *= material.bump*2;
+            display.modelParams3[3] *= material.aniso*2;
+            display.modelParams4[0] *= material.anisoV*2;
+            display.modelParams4[1] *= material.cameralight*2;
+            //System.out.println("selected = " + selected);
+            display.modelParams4[2] *= material.diffuseness*2;
+            display.modelParams4[3] *= material.shadow*2;
+            display.modelParams5[0] *= material.texture*2;
+            display.modelParams5[1] *= material.opacity*2;
+            display.modelParams5[2] *= material.fakedepth*2;
+            display.modelParams5[3] *= material.shadowbias*2;
+        }
+
+        display.modelParams6[0] = 0;
+        display.modelParams6[1] = 0;
+        display.modelParams6[2] = 0;
+        display.modelParams6[3] = 0;
+
+        display.modelParams7[0] = 0;
+        display.modelParams7[1] = 1000;
+        display.modelParams7[2] = 0;
+        display.modelParams7[3] = 0;
+
+        display.modelParams6[0] = 100; // criss de bug de bump
+        
+        Object3D.cVector2[] extparams = display.vector2buffer;
+        if (extparams != null && extparams.length > 0 && extparams[0] != null)
+        {
+            display.modelParams6[0] = extparams[0].x / 1000.0f; // bump
+            display.modelParams6[1] = extparams[0].y / 1000.0f; // noise
+            if (extparams.length > 1)
+            {
+                display.modelParams6[2] = extparams[1].x / 1000.0f; // borderfade
+                display.modelParams6[3] = extparams[1].y / 1000.0f; // (float)Math.exp(-extparams[1].y / 1000.0f); // fog punchthrough
+                if (extparams.length > 2)
+                {
+                    display.modelParams7[0] = extparams[2].x / 1000.0f; // noise power
+                    float x = extparams[2].y / 1000.0f;
+                    //if (x == 0)
+                    //    x = 1f;
+                    display.modelParams7[1] = 1 / x / x / x / x / x / x / x / x / x / x / x / x / x; // (float)Math.pow(-Math.log((extparams[2].y+0.00) / 1000.0f), 1); // opacity power
+                    if (extparams[2].y > 0)
+                    {
+                    //System.out.println("extparams[1].y = " + extparams[1].y);
+                    //System.out.println("extparams[2].y = " + extparams[2].y);
+                    //System.out.println("opacity power = " + display.modelParams7[1]);
+                    }
+                }
+            }
+        }
+
+        //if (display.modelParams6[2] != 0)
+        /*
+        System.out.println("modelParams0[0] = " + display.modelParams0[0]);
+        System.out.println("modelParams0[1] = " + display.modelParams0[1]);
+        System.out.println("modelParams0[2] = " + display.modelParams0[2]);
+        System.out.println("modelParams0[3] = " + display.modelParams0[3]);
+        System.out.println("modelParams1[0] = " + display.modelParams1[0]);
+        System.out.println("modelParams1[1] = " + display.modelParams1[1]);
+        System.out.println("modelParams1[2] = " + display.modelParams1[2]);
+        System.out.println("modelParams1[3] = " + display.modelParams1[3]);
+        System.out.println("modelParams2[0] = " + display.modelParams2[0]);
+        System.out.println("modelParams2[1] = " + display.modelParams2[1]);
+        System.out.println("modelParams2[2] = " + display.modelParams2[2]);
+        System.out.println("modelParams2[3] = " + display.modelParams2[3]);
+        System.out.println("modelParams3[0] = " + display.modelParams3[0]);
+        System.out.println("modelParams3[1] = " + display.modelParams3[1]);
+        System.out.println("modelParams3[2] = " + display.modelParams3[2]);
+        System.out.println("modelParams3[3] = " + display.modelParams3[3]);
+        System.out.println("modelParams4[0] = " + display.modelParams4[0]);
+        System.out.println("modelParams4[1] = " + display.modelParams4[1]);
+        System.out.println("modelParams4[2] = " + display.modelParams4[2]);
+        System.out.println("modelParams4[3] = " + display.modelParams4[3]);
+        System.out.println("modelParams5[0] = " + display.modelParams5[0]);
+        System.out.println("modelParams5[1] = " + display.modelParams5[1]);
+        System.out.println("modelParams5[2] = " + display.modelParams5[2]);
+        System.out.println("modelParams5[3] = " + display.modelParams5[3]);
+        System.out.println("modelParams6[0] = " + display.modelParams6[0]);
+        System.out.println("modelParams6[1] = " + display.modelParams6[1]);
+        System.out.println("modelParams6[2] = " + display.modelParams6[2]);
+        System.out.println("modelParams6[3] = " + display.modelParams6[3]);
+        System.out.println("modelParams7[0] = " + display.modelParams7[0]);
+        System.out.println("modelParams7[1] = " + display.modelParams7[1]);
+        System.out.println("modelParams7[2] = " + display.modelParams7[2]);
+        System.out.println("modelParams7[3] = " + display.modelParams7[3]);
+        /**/
+        //assert (display.modelParams6[2] == 0);
+
+        //System.out.println("noise power = " + display.modelParams7[0]);
+        //System.out.println("shadowbias = " + shadowbias);
+
+        gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 0, display.modelParams0, 0);
+        gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 1, display.modelParams1, 0);
+        gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 2, display.modelParams2, 0);
+        gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 3, display.modelParams3, 0);
+        gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 4, display.modelParams4, 0);
+        gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 5, display.modelParams5, 0);
+        gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 6, display.modelParams6, 0);
+        gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 7, display.modelParams7, 0);
+
+        int mode = display.FP_SHADER;
+
+        if (material.aniso != material.anisoV || material.aniso > 0.002)
+        {
+            mode |= display.FP_ANISO;
+        }
+
+        display.EnableProgram(mode);
+        
+        //System.out.println("opacity power = " + display.modelParams7[1]);
+        
+        if (!material.multiply)
+        {
+            if (Globals.drawMode == CameraPane.SHADOW)
+                gl.glDepthMask(material.opacity >= 0.9 && display.modelParams7[1] > 0.1);
+            else
+                gl.glDepthMask(material.opacity >= 0.99);
+        }
     }
     
     int matrixdepth = 0; // 10000; // CONFLICT WITH cMESH... WARNING WARNING WARNING WARNING WARNING WARNING !!!!!!!!!!!!    0;
@@ -225,7 +1861,7 @@
         currentGL.glMultMatrixd(model, 0);
     }
 
-    void PushMatrix(double[][] matrix, int count)
+    public void PushMatrix(double[][] matrix, int count) // INTERFACE
     {
         matrixdepth++;
      //   GrafreeD.tracein(matrix);
@@ -270,7 +1906,7 @@
     
     double[][] tmpmat = new double[4][4];
 
-    void PopMatrix(double[][] inverse)
+    public void PopMatrix(double[][] inverse) // INTERFACE
     {
         --matrixdepth;
         
@@ -310,7 +1946,7 @@
         PushTextureMatrix(matrix, 1);
     }
 
-    void PushTextureMatrix(double[][] matrix, int count)
+    public void PushTextureMatrix(double[][] matrix, int count) // INTERFACE
     {
         currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
 
@@ -324,7 +1960,7 @@
         currentGL.glMatrixMode(GetGL().GL_MODELVIEW);
     }
 
-    void PopTextureMatrix(double[][] inverse)
+    public void PopTextureMatrix(double[][] inverse) // INTERFACE
     {
         currentGL.glActiveTexture(GetGL().GL_TEXTURE0);
         currentGL.glMatrixMode(GetGL().GL_TEXTURE);
@@ -351,15 +1987,15 @@
     
     static int camerachangeframe;
     
-    boolean SetCamera(Camera cam)
+    public boolean SetCamera(Camera cam)
     {
         // may 2014 if (cam == cameras[0] || cam == cameras[1])
         //    return false;
         
-        if (REFUSEMODE && isLIVE() && camerachangeframe != 0 && camerachangeframe != framecount)
+        if (REFUSEMODE && Globals.isLIVE() && camerachangeframe != 0 && camerachangeframe != Globals.framecount)
         {
             // check for last change
-            if (framecount < camerachangeframe + 400) // 120 == 1 second
+            if (Globals.framecount < camerachangeframe + 400) // 120 == 1 second
             {
                 // refuse the camera change
                 System.err.println("Camera " + cam + " REFUSED");
@@ -367,7 +2003,7 @@
             }
         }
         
-        camerachangeframe = framecount;
+        camerachangeframe = Globals.framecount;
         
         cam.hAspect = -1; // Read only
 
@@ -398,7 +2034,7 @@
         {
             //System.err.println("Oeil on");
             TRACK = true;
-// JUNE 2014            if (TRACK && trackedobject != null && drawMode == SHADOW) // && !lightMode)
+// JUNE 2014            if (TRACK && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
 //                object.editWindow.ScreenFit(trackedobject);
             //pingthread.StepToTarget(true);
         }
@@ -407,7 +2043,7 @@
         {
             //System.err.println("Oeil on");
             OEIL = true;
-            if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
+            if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
                 object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
             //pingthread.StepToTarget(true);
         }
@@ -471,39 +2107,12 @@
     {
         frozen ^= true;
         // Weird...
-        lighttouched = true;
+        Globals.lighttouched = true;
     }
 
     void ToggleDL()
     {
         mainDL ^= true;
-    }
-
-    void ToggleTexture()
-    {
-        textureon ^= true;
-    }
-
-    void ToggleLive()
-    {
-        setLIVE(isLIVE() ^ true);
-        
-        System.err.println("LIVE = " + isLIVE());
-        
-        if (!isLIVE()) // save sound
-            GrafreeD.savesound = true; // wav.save();
-     //   else
-            repaint(); // start loop // may 2013
-    }
-
-    void ToggleSupport()
-    {
-        SUPPORT ^= true;
-    }
-
-    void ToggleAbort()
-    {
-        ABORTMODE ^= true;
     }
 
     void ToggleFullScreen()
@@ -513,12 +2122,7 @@
 
     void ToggleCrowd()
     {
-        CROWD ^= true;
-    }
-
-    void ToggleInertia()
-    {
-        INERTIA ^= true;
+        Globals.CROWD ^= true;
     }
 
     void ToggleLocal()
@@ -526,62 +2130,89 @@
         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)
@@ -600,25 +2231,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()
@@ -672,34 +2313,6 @@
         //assert (cam.hAspect == 0);
         cam.hAspect = 0;
         lightCamera = cam;
-    }
-
-    CameraPane(Object3D o, Camera cam, boolean withcontext)
-    {
-        super(defaultcaps, null, withcontext?glcontext:null, null);
-
-        //System.out.println("AMERICA AREA = " + (9458886 + 9210755 + 8480395  +  2736391  + 1943018 +  1289475 +  1141569  + 1069350 +  911559 +  721229 +  395886  + 377972 +   246700 +  211156  +  173985 +  141133  + 118279 +  112079 +  108523));
-        glcontext = getContext();
-
-        cameras = new Camera[2];
-        targetLookAts = new cVector[2];
-
-        SetCamera(cam);
-
-        SetLight(new Camera(new cVector(10, 10, -20)));
-
-        object = o;
-
-        setBackground(Color.white);
-
-        addKeyListener(this);
-        addMouseListener(this);
-        addMouseMotionListener(this);
-        addMouseWheelListener(this);
-        //System.out.println("addGLEventListener: " + this);
-        addGLEventListener(this);
-
-//        pingthread.start(); // may 2013
     }
 
     private static void ApplyTransform(GL gl, Mat4f xform)
@@ -759,7 +2372,7 @@
     
     GL currentGL;
 
-    GL GetGL()
+    public GL GetGL() // INTERFACE
     {
         return currentGL;
     }
@@ -2000,10 +3613,12 @@
          */
     TextureData ReduceTexture(TextureData texturedata, int resolution) // String name)
     {
+        int pixelformat = texturedata.getPixelFormat();
+        
         int stride = 1;
-        if (texturedata.getPixelFormat() == GetGL().GL_RGB || texturedata.getPixelFormat() == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
+        if (pixelformat == GetGL().GL_RGB || pixelformat == GetGL().GL_BGR) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE)
             stride = 3;
-        if (texturedata.getPixelFormat() == GetGL().GL_RGBA || texturedata.getPixelFormat() == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
+        if (pixelformat == GetGL().GL_RGBA || pixelformat == GetGL().GL_BGRA) // || texturedata.getPixelFormat() == GL.GL_LUMINANCE_ALPHA)
             stride = 4;
 
         int width = texturedata.getWidth();
@@ -6269,7 +7884,7 @@
         return null;
     }
 
-    void ReleaseTextures(cTexture tex)
+    public void ReleaseTextures(cTexture tex) // INTERFACE
     {
         if (/*tex == null ||*/ ambientOcclusion ) // || !textureon)
         {
@@ -6307,7 +7922,7 @@
     
     void ReleaseTexture(String tex, boolean bump)
     {
-        if (// drawMode != 0 || /*tex == null ||*/
+        if (// DrawMode() != 0 || /*tex == null ||*/
                 ambientOcclusion ) // || !textureon)
         {
             return;
@@ -6408,9 +8023,9 @@
         }
     }
 
-    /*boolean*/ void BindTextures(cTexture tex, int resolution)
+    /*boolean*/ public void BindTextures(cTexture tex, int resolution) // INTERFACE
     {
-        if (// drawMode != 0 || /*tex == null ||*/
+        if (// DrawMode() != 0 || /*tex == null ||*/
                 ambientOcclusion ) // || !textureon)
         {
             return; // false;
@@ -6706,7 +8321,7 @@
         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)
     {
         CacheTexture texture = GetCacheTexture(tex, bump, resolution);
                 
@@ -7310,9 +8925,9 @@
     static boolean occlusionInitialized = false;
     boolean selection = false;
     boolean pointselection = false;
-    /*static*/ boolean lighttouched = true;
+    ///*static*/ boolean lighttouched = true;
     boolean deselect;
-    boolean ambientOcclusion = false;
+    private boolean ambientOcclusion = false;
     static boolean flash = false;
     /*static*/ boolean wait = false;
     boolean displaydone = false; // after repaint() calls
@@ -7442,6 +9057,8 @@
             //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
             //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
             double scale = lightCamera.SCALE / lightCamera.Distance();
+// PATCH FILLE AUX JEANS           
+            //scale *= lightCamera.shaper_fovy / 25;
             gl.glScaled(2 * scale, 2 * scale, -scale);
             gl.glTranslated(0, 0, lightCamera.DECAL);
 
@@ -7590,15 +9207,14 @@
     
     float[] options1 = new float[]{1000, 0.00001f, 20, 0, 0}; // focus, aperture, Shadow blur, aniso, anisoV
     float[] options2 = new float[]{0, 1, 0, 0}; // fog density, intensity, elevation
-    float[] options3 = new float[]{1, 1, 1, 1}; // fog color. image intensity
+    float[] options3 = new float[]{1, 1, 1, 0}; // fog color
+    float[] options4 = new float[]{1, 0, 1, 0}; // image intensity, subsurface, lightsheen
 
     static int imagecount = 0; // movie generation
     
     static int jitter = 0;
     
     boolean restartframe = false;
-    
-    static int framecount = 0; // general-purpose global count
     
     void displayAntiAliased(javax.media.opengl.GL gl)
     {
@@ -7630,7 +9246,7 @@
         gl.glClear(gl.GL_ACCUM_BUFFER_BIT);
         for (jitter = 0; jitter < ACSIZE; jitter++) //, GrafreeD.wav.cursor += LIVE ? 735 : 0)
         {
-            framecount++;
+            Globals.framecount++;
             
             if (CameraPane.tickcount > 0)
                 CameraPane.tickcount--;
@@ -7668,7 +9284,7 @@
 
         gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, pos, 0);
         */
-            lighttouched = true;
+            Globals.lighttouched = true;
     //System.err.println("    shadowbuffer: " + jitter);
             shadowbuffer.display();
             
@@ -7690,7 +9306,7 @@
         
         if (renderCamera != lightCamera)
         for (int count = parentcam.GetTransformCount(); --count>=0;)
-            LA.matConcat(parentcam.toParent, matrix, matrix);
+            LA.matConcat(matrix, parentcam.toParent, matrix);
         
 //            LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
             
@@ -7706,7 +9322,7 @@
             
         if (renderCamera != lightCamera)
         for (int count = parentcam.GetTransformCount(); --count>=0;)
-            LA.matConcat(matrix, parentcam.fromParent, matrix);
+            LA.matConcat(parentcam.fromParent, matrix, matrix);
 
 //            LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
             
@@ -7923,7 +9539,7 @@
             
             if (!BOXMODE)
             {
-                System.out.println("image: " + fullname + " (" + (GrafreeD.wav.cursor / 735 / 4) + ")");
+                System.out.println("image: " + fullname + " (wav cursor=" + (GrafreeD.wav.cursor / 735 / 4) + ")");
             }
     
             if (!BOXMODE)
@@ -8615,13 +10231,6 @@
         }
     }
 
-    boolean IsFrozen()
-    {
-        boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
-        
-        return !selectmode && cameracount == 0; // != 0;
-    }
-    
     boolean niceon = false;
     javax.swing.Timer AAtimer = new javax.swing.Timer(750, this);
     boolean currentlydrawing = false;
@@ -8639,8 +10248,8 @@
         }
 //        if (DEBUG_SELECTION)
 //        {
-//            if (drawMode != SELECTION)
-//                drawMode = SELECTION;
+//            if (DrawMode() != SELECTION)
+//                DrawMode() = SELECTION;
 //        }
         
         if (!isRenderer)
@@ -8696,9 +10305,9 @@
 
             //ANTIALIAS = 0;
 
-            if (drawMode == DEFAULT) // && CURRENTANTIALIAS > 0)
+            if (DrawMode() == DEFAULT) // && CURRENTANTIALIAS > 0)
             {
-                if (niceon || isLIVE())
+                if (niceon || Globals.isLIVE())
                 {
                     //if(active == 0)
                     //  antialiaser = null;
@@ -8723,7 +10332,7 @@
         assert eyeCamera.shaper_zFar == 1E5f; // 500.0f;
          */
 
-        if (drawMode == DEFAULT)
+        if (DrawMode() == DEFAULT)
         {
             currentlydrawing = true;
         }
@@ -8754,12 +10363,12 @@
 
 //                if(Applet3D.clipboard != null)
 //                    System.out.println("Clipboard = " + Applet3D.clipboard); //.get(0).parent);
-//drawMode = SELECTION;
+//DrawMode() = SELECTION;
 indexcount = 0;
 
-        if (drawMode == OCCLUSION)
+        if (DrawMode() == OCCLUSION)
         {
-            drawMode = DEFAULT;
+            Globals.drawMode = DEFAULT; // WARNING
             ambientOcclusion = true;
             setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
             Object3D theobject = object;
@@ -8778,19 +10387,19 @@
             ambientOcclusion = false;
         }
 
-        if (lighttouched && drawMode == DEFAULT && !lightMode) // && !FROZEN)
+        if (Globals.lighttouched && DrawMode() == DEFAULT && !lightMode) // && !FROZEN)
         {
             //if (RENDERSHADOW) // ?
             if (!IsFrozen())
             {
                 // dec 2012
-                if (!(!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0))
+                if (!ambientOcclusion && !(!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0))
                 {
-            framecount++;
+            Globals.framecount++;
                     shadowbuffer.display();
                 }
             }
-            lighttouched = false; // ??
+            Globals.lighttouched = false; // ??
         //drawing = true;
         //lighttouched = true;
         }
@@ -8811,9 +10420,9 @@
         //eyeCamera.shaper_fovy = 1;
         }
 
-        if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && drawMode == DEFAULT) // SELECTION)
+        if ((RENDERPROGRAM != 0 || ambientOcclusion || spherical) && DrawMode() == DEFAULT) // SELECTION)
         {
-            //System.out.println("drawMode = " + drawMode);
+            //System.out.println("DrawMode() = " + DrawMode());
             vertexMode |= VP_PASS;
             //vertexMode |= VP_PROJECTION;
             if (!ambientOcclusion)
@@ -8873,7 +10482,7 @@
         Camera cam = renderCamera; // lightMode?lightCamera:eyeCamera;
         //Camera lightcam = new Camera(light0);
 
-        if (drawMode == SHADOW)
+        if (DrawMode() == SHADOW)
         {
             /*
             gl.glMatrixMode(GL.GL_MODELVIEW);
@@ -8912,7 +10521,7 @@
 //        if (parentcam != renderCamera) // not a light
         if (cam != lightCamera)
             for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.matConcat(parentcam.toParent, matrix, matrix);
+                LA.matConcat(matrix, parentcam.toParent, matrix);
             
             for (int j = 0; j < 4; j++)
             {
@@ -8927,7 +10536,7 @@
 //        if (parentcam != renderCamera) // not a light
         if (cam != lightCamera)
             for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.matConcat(matrix, parentcam.fromParent, matrix);
+                LA.matConcat(parentcam.fromParent, matrix, matrix);
         
             //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
             
@@ -8963,7 +10572,7 @@
             gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
         } else
         {
-            if (drawMode != DEFAULT)
+            if (DrawMode() != DEFAULT)
             {
                 gl.glClearColor(1, 1, 1, 0);
             } // 1);
@@ -9028,7 +10637,7 @@
 
         fast &= !ambientOcclusion;
         
-        if (drawMode == DEFAULT)
+        if (DrawMode() == DEFAULT)
         {
             //gl.glEnable(gl.GL_ALPHA_TEST);		
             //gl.glActiveTexture(GL.GL_TEXTURE0);
@@ -9089,6 +10698,8 @@
             //gl.glFrustum(-0.5*scale, 0.5*scale, -0.5*scale, 0.5*scale, 1, 100);
             //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
             double scale = lightCamera.SCALE / lightCamera.Distance();
+// PATCH FILLE AUX JEANS           
+            //scale *= lightCamera.shaper_fovy / 25;
             gl.glScaled(2 * scale, 2 * scale, -scale);
             gl.glTranslated(0, 0, lightCamera.DECAL);
 
@@ -9224,10 +10835,12 @@
         gl.glMatrixMode(gl.GL_PROJECTION);
         gl.glLoadIdentity();
 
-        if (drawMode == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
+        if (DrawMode() == SHADOW || cam == lightCamera) // || (vertexMode&VP_PROJECTION) != 0)
         {
             //glu.gluPerspective(lightshaper_fovy, 1, lightshaper_zNear, lightshaper_zFar);
             double scale = lightCamera.SCALE / lightCamera.Distance();
+// PATCH FILLE AUX JEANS            
+            //scale *= lightCamera.shaper_fovy / 25;
             gl.glScaled(2 * scale, 2 * scale, -scale);
             gl.glTranslated(0, 0, lightCamera.DECAL);
         //System.out.println("DECAL = " + LIGHTDECAL + "; SCALE = " + LIGHTSCALE);
@@ -9280,7 +10893,7 @@
         //gl.glPushMatrix();
         gl.glLoadIdentity();
 
-    if (!ambientOcclusion) // drawMode != OCCLUSION)
+    if (!ambientOcclusion) // DrawMode() != OCCLUSION)
     {
         //LA.xformPos(light0, lightCamera.fromScreen, light);
         LA.xformDir(dirlight, lightCamera.fromScreen, lightposition);
@@ -9367,7 +10980,7 @@
         }
 
         /**/
-        if (true) // drawMode == SELECTION) // != DEFAULT)
+        if (true) // DrawMode() == SELECTION) // != DEFAULT)
             gl.glDisable(gl.GL_LIGHTING);
         else
             gl.glEnable(gl.GL_LIGHTING);
@@ -9379,12 +10992,13 @@
 
         gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 63, options2, 0);
         gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 62, options3, 0);
+        gl.glProgramEnvParameter4fvARB(gl.GL_FRAGMENT_PROGRAM_ARB, 61, options4, 0);
 
         options2[0] *= renderCamera.Distance();
 
         lightslot = 64;
 
-        if (!frozen && !ambientOcclusion && isRenderer && drawMode == DEFAULT)
+        if (!frozen && !ambientOcclusion && isRenderer && DrawMode() == DEFAULT)
         {
             DrawLights(object);
         }
@@ -9395,7 +11009,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))
@@ -9428,7 +11042,7 @@
             }
         }
 
-        if (drawMode == DEFAULT)
+        if (DrawMode() == DEFAULT)
         {
             if (WIREFRAME && !ambientOcclusion)
             {
@@ -9446,7 +11060,7 @@
                 gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
                 gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
         
-        if (!fast/*RENDERPROGRAM != 0*/ && (drawMode == DEFAULT || drawMode == SHADOW)) // && !WIREFRAME) //
+        if (!fast/*RENDERPROGRAM != 0*/ && (DrawMode() == DEFAULT || DrawMode() == SHADOW)) // && !WIREFRAME) //
         {
             if (vertexMode != 0) // && !fast)
             {
@@ -9466,7 +11080,7 @@
             }
         }
 
-        if (false) // fast && !IsFreezed() && drawMode != SELECTION && !ambientOcclusion)
+        if (false) // fast && !IsFreezed() && DrawMode() != SELECTION && !ambientOcclusion)
         {
             //gl.glDepthFunc(GL.GL_LEQUAL);
             //gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
@@ -9494,7 +11108,7 @@
         //gl.glDepthMask(false);
         }
 
-        if (false) // drawMode == SHADOW)
+        if (false) // DrawMode() == SHADOW)
         {
         //SetColumnMajorData(cameraInverseTransform, view_1);
         //System.out.println("light = " + cameraInverseTransform);
@@ -9508,16 +11122,16 @@
         //System.out.println("object = " + object);
         if (!frozen && !imageLocked)
         {
-            if (!flash && !lightMode && drawMode == DEFAULT && ANTIALIAS > 0)
+            if (!flash && !lightMode && DrawMode() == DEFAULT && ANTIALIAS > 0)
             {
                 displayAntiAliased(gl);
             } else
             {
                 programcount = 0;
-                int keepmode = drawMode;
+                int keepmode = DrawMode();
 //        if (DEBUG_SELECTION)
 //        {
-//            drawMode = SELECTION;
+//            DrawMode() = SELECTION;
 //        }
                 // for point selection
 //                gl.glGetDoublev(gl.GL_MODELVIEW_MATRIX, tempmat, 0);
@@ -9527,10 +11141,10 @@
                 DrawObject(gl);
                 
 // jan 2013    System.err.println("RESET ABORT (display)");
-        //        if (drawMode == DEFAULT)
+        //        if (DrawMode() == DEFAULT)
         //            ABORTED = false;
                 fullreset = false;
-                drawMode = keepmode;
+                Globals.drawMode = keepmode; // WARNING
             //System.out.println("PROGRAM SWITCH " + programcount);
             }
         }
@@ -9538,11 +11152,11 @@
         gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
         gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
 
-        if (drawMode == DEFAULT)
+        if (DrawMode() == DEFAULT)
         {
             ReleaseTexture(NOISE_TEXTURE, false);
         }
-        //if (drawMode == DEFAULT)
+        //if (DrawMode() == DEFAULT)
         {
 
             gl.glActiveTexture(GL.GL_TEXTURE1);
@@ -9554,7 +11168,7 @@
         //else
         //gl.glDisable(gl.GL_TEXTURE_2D);
         //gl.glPopMatrix();
-        if (imageCompleted && ANTIALIAS > 0 && drawMode == DEFAULT && cam != lightCamera && !ambientOcclusion)
+        if (imageCompleted && ANTIALIAS > 0 && DrawMode() == DEFAULT && cam != lightCamera && !ambientOcclusion)
         {
             //new Exception().printStackTrace();
             //System.out.println("Draw image " + width + ", " + height);
@@ -9596,7 +11210,7 @@
         //gl.glFlush();
         }
 
-        if (flash && drawMode == DEFAULT)
+        if (flash && DrawMode() == DEFAULT)
         {
             flash = false;
             wait = true;
@@ -9604,9 +11218,9 @@
         }
 
         //drawing = false;
-        //if(drawMode == DEFAULT)
+        //if(DrawMode() == DEFAULT)
         //       niceon = false;
-        if (drawMode == DEFAULT)
+        if (DrawMode() == DEFAULT)
         {
             currentlydrawing = false;
         }
@@ -9626,7 +11240,7 @@
             repaint();
         }
         
-        if (isLIVE() && drawMode == DEFAULT) // may 2013
+        if (Globals.isLIVE() && DrawMode() == DEFAULT) // may 2013
             repaint();
         
         displaydone = true;
@@ -9663,7 +11277,7 @@
         if (GrafreeD.RENDERME > 0)
             GrafreeD.RENDERME--; // mechante magouille
         
-        ONESTEP = false;
+        Globals.ONESTEP = false;
     }
 
     static boolean zoomonce = false;
@@ -9671,11 +11285,11 @@
     void DrawObject(GL gl, boolean draw)
     {
         //System.out.println("DRAW OBJECT " + mouseDown);
-//        drawMode = SELECTION;
+//        DrawMode() = SELECTION;
         //GL gl = getGL();
         if ((TRACK || SHADOWTRACK) || zoomonce)
         {
-            if ((TRACK || SHADOWTRACK) && trackedobject != null && drawMode == SHADOW) // && !lightMode)
+            if ((TRACK || SHADOWTRACK) && trackedobject != null && DrawMode() == SHADOW) // && !lightMode)
                 object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
             pingthread.StepToTarget(true); // true);
        //     zoomonce = false;
@@ -9696,9 +11310,9 @@
             callist = gl.glGenLists(1);
         }
 
-        boolean selectmode = drawMode == SELECTION || CameraPane.DEBUG_SELECTION;
+        boolean selectmode = DrawMode() == SELECTION || IsDebugSelection();
         
-        boolean active = !selectmode; // drawMode != SELECTION; // mouseDown;
+        boolean active = !selectmode; // DrawMode() != SELECTION; // mouseDown;
         
         if (!mainDL || !active || touched)
         {
@@ -9725,7 +11339,7 @@
                 PushMatrix(ClickInfo.matbuffer);
             }
 
-            if (drawMode == 0)
+            if (DrawMode() == 0)
             {
 //                System.out.println("CLEAR  +++++++++++++++ +++++++++++++++ +++++++++++++++ +++++++++++++++");
 
@@ -9739,7 +11353,7 @@
         // DRAW
         object.draw(this, /*(Composite)*/ object, false, false);
             
-            if (drawMode == DEFAULT)
+            if (DrawMode() == DEFAULT)
             {
                 if (DEBUG)
                 {
@@ -9750,40 +11364,40 @@
                         selectedpoint.radius = radius;
                         selectedpoint.recalculate();
                         selectedpoint.material = new cMaterial();
-                        selectedpoint.material.color = 0.25f;
+                        selectedpoint.material.color = 0.15f; // Yellow
                         selectedpoint.material.modulation = 0.75f;
                         
-                        debugpoint.radius = radius;
-                        debugpoint.recalculate();
-                        debugpoint.material = new cMaterial();
-                        debugpoint.material.color = 0.25f;
-                        debugpoint.material.modulation = 0.75f;
+                        debugpointG.radius = radius;
+                        debugpointG.recalculate();
+                        debugpointG.material = new cMaterial();
+                        debugpointG.material.color = 0.25f; // Green
+                        debugpointG.material.modulation = 0.75f;
                         
-                        debugpoint2.radius = radius;
-                        debugpoint2.recalculate();
-                        debugpoint2.material = new cMaterial();
-                        debugpoint2.material.color = 0.75f;
-                        debugpoint2.material.modulation = 0.75f;
+                        debugpointP.radius = radius;
+                        debugpointP.recalculate();
+                        debugpointP.material = new cMaterial();
+                        debugpointP.material.color = 0.75f; // Purple
+                        debugpointP.material.modulation = 0.75f;
                         
-                        debugpoint3.radius = radius;
-                        debugpoint3.recalculate();
-                        debugpoint3.material = new cMaterial();
-                        debugpoint3.material.color = 0.5f;
-                        debugpoint3.material.modulation = 0.75f;
+                        debugpointC.radius = radius;
+                        debugpointC.recalculate();
+                        debugpointC.material = new cMaterial();
+                        debugpointC.material.color = 0.5f; // Cyan
+                        debugpointC.material.modulation = 0.75f;
                         
-                        debugpoint4.radius = radius;
-                        debugpoint4.recalculate();
-                        debugpoint4.material = new cMaterial();
-                        debugpoint4.material.color = 0f;
-                        debugpoint4.material.modulation = 0.75f;
+                        debugpointR.radius = radius;
+                        debugpointR.recalculate();
+                        debugpointR.material = new cMaterial();
+                        debugpointR.material.color = 0f; // Red
+                        debugpointR.material.modulation = 0.75f;
                         
                         InitPoints(radius);
                     }
                     selectedpoint.draw(this, /*(Composite)*/ null, false, false);
-                    debugpoint.draw(this, /*(Composite)*/ null, false,false);
-                    debugpoint2.draw(this, /*(Composite)*/ null, false,false);
-                    debugpoint3.draw(this, /*(Composite)*/ null, false,false);
-                    debugpoint4.draw(this, /*(Composite)*/ null, false,false);
+                    debugpointG.draw(this, /*(Composite)*/ null, false,false);
+                    debugpointP.draw(this, /*(Composite)*/ null, false,false);
+                    debugpointC.draw(this, /*(Composite)*/ null, false,false);
+                    debugpointR.draw(this, /*(Composite)*/ null, false,false);
                     // DrawPoints(this);
                 }
                 
@@ -9791,7 +11405,7 @@
             }
 //            GrafreeD.traceoff();
             //System.out.println(stackdepth);
-            if (drawMode == 0)
+            if (DrawMode() == 0)
             {
                 ReleaseTextures(DEFAULT_TEXTURES);
 
@@ -9816,17 +11430,19 @@
 
             checker = null;
 
-            if (!ambientOcclusion && !IsFrozen() && drawMode == DEFAULT)
+            if (!ambientOcclusion && !IsFrozen() && DrawMode() == DEFAULT)
                 FindChecker(object);
 
-            if (checker != null && drawMode == DEFAULT)
+            if (checker != null && DrawMode() == DEFAULT)
             {
-               // BindTexture(IMMORTAL_TEXTURE);
+                //BindTexture(IMMORTAL_TEXTURE);
+                BindTextures(checker.GetTextures(), checker.texres);
                 // NEAREST
                 GetGL().glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST); // GL.GL_LINEAR);
                 DrawChecker(gl);
                 //checker.Draw(this, null, false);
               //  ReleaseTexture(IMMORTAL_TEXTURE);
+                ReleaseTextures(checker.GetTextures());
             }
 
             if (object.parent != null)
@@ -9839,7 +11455,7 @@
             //gl.glDisable(GL.GL_VERTEX_PROGRAM_ARB);
             //gl.glDisable(GL.GL_FRAGMENT_PROGRAM_ARB);
 
-            if (DISPLAYTEXT && drawMode == DEFAULT)
+            if (DISPLAYTEXT && DrawMode() == DEFAULT)
             {
                 // Draw it once, then use the raster
                 Balloon(gl, balloon.createGraphics());
@@ -9895,9 +11511,9 @@
     int[] xs = new int[3];
     int[] ys = new int[3];
 
-    void DrawString(Object3D obj) // String string)
+    public void DrawString(Object3D obj) // String string) // INTERFACE
     {
-        if (!DISPLAYTEXT || drawMode != DEFAULT)
+        if (!DISPLAYTEXT || DrawMode() != DEFAULT)
         {
             return;
         }
@@ -10357,11 +11973,13 @@
                 "PARAM params6   = program.env[6];" + // bump, noise, borderfade, fog punchthrough
                 "PARAM params7   = program.env[7];" + // noise power, opacity power
                 "PARAM options0   = program.env[63];" + // fog density, intensity, elevation
-                "PARAM options1   = program.env[62];" + // fog rgb color, image intensity
+                "PARAM options1   = program.env[62];" + // fog rgb color
+                "PARAM options2   = program.env[61];" + // image intensity, subsurface, lightsheen
                 "PARAM pointlight   = program.env[127];" + // ...
                 "PARAM zero     = { 0.0, 0.0, 0.0, 0.0 };" +
                 "PARAM halfhalf = { 0.25, 0.25, 0.25, 1.0 };" +
                 "PARAM half     = { 0.5, 0.5, 0.5, 1.0 };" +
+                "PARAM threequarter = { 0.75, 0.75, 0.75, 1.0 };" +
                 "PARAM two      = { 2.0, 2.0, 2.0, 1.0 };" +
                 "PARAM ten      = { 10, 10, 10, 1.0 };" +
                 "PARAM one3rd  = { 0.5, 0.33333333333, 0.333333333, 1.0 };" +
@@ -10382,6 +12000,7 @@
                 "PARAM lodbias = { 10,10,10,10 };" + // 20, -2, -20, 1.0 };" +
                 "PARAM infinity  = { 100000000, 100000000, 100000000, 1.0 };" +
                 "PARAM one2048th = { 0.00048828125, 0.00048828125, 0.00048828125, 1.0 };" +
+                "PARAM ninetenth = { 0.9, 0.9, 0.9, 1.0 };" +
                 "PARAM almostone = { 0.999, 0.999, 0.999, 1.0 };" +
                 "PARAM c256 = { 256, 256, 256, 1.0 };" +
                 "PARAM c256i = { 0.00390625, 0.00390625, 0.00390625, 1.0 };" +
@@ -10422,6 +12041,10 @@
                 "TEMP R1;" +
                 "TEMP R2;" +
                 "TEMP R3;" +
+                "TEMP min;" +
+                "TEMP max;" +
+                "TEMP average;" +
+                "TEMP saturation;" +
                 "TEMP keep1;" +
                 "TEMP keep2;" +
                 "TEMP keep3;" +
@@ -10952,10 +12575,40 @@
 
                 // skin?
                 // Saturation for skin
-                /**/ // c'est ici
-    (Skinshader?                "DP3 temp.x, final,one;" +
+                /**/
+   (Skinshader?
+                "DP3 average.x, final,one;" +
+                "MUL average, one3rd.xxxx,average.xxxx;" +
+
+                "MIN min.x, final.x,final.y;" +
+                "MIN min.x, min.x,final.z;" +
+
+                "MAX max.x, final.x,final.y;" +
+                "MAX max.x, max.x,final.z;" +
+                "MOV max, max.xxxx;" +
+                
+                "SUB saturation, max, final;" +
+                
+                "ADD temp.x, max.x, one10th.x;" +
+                "RCP temp.x, temp.x;" +
+                "MUL temp.x, temp.x, half.x;" +
+                "MUL saturation, saturation, temp.xxxx;" +
+                
+            "DP3 ndotl.x, normald, light;" +
+            "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
+                "MUL temp.x, temp.x, temp.y;" +
+                                
+                "MUL saturation, saturation, temp.xxxx;" +
+                "SUB_SAT temp, max, saturation;" +
+/**
+                "DP3 temp.x, final,one;" +
                 "MUL R2, one3rd.xxxx,temp.xxxx;" +
-                "SUB temp, final,R2;" +
+                "SUB temp, final, R2;" +
+                  
             // using light angle
             "DP3 ndotl.x, normald,light;" +
             //"SLT ndotl.y, ndotl.x, zero.x;" +
@@ -10968,7 +12621,6 @@
             // using light intensity
             "MOV ndotl.z, R2.x;" +
             "MUL ndotl.z, ndotl.z, ndotl.z;" + // tuning...
-                
 // june 2014
                 "MAD R1.x, ndotl.z,slope.y,one.x;" +
 //                "SUB ndotl.x, one.x, ndotl.x;" +
@@ -10980,6 +12632,7 @@
 //"MUL R2.y, shadow.x,R2.y;" + // avril 2014
                 
         "MAD temp.x, R2.y, ndotl.y, temp.x;" + // red shift (skin)
+/**/
                 
              //   "ADD final, R2,temp;" +
                 "MOV final, temp;"
@@ -11069,7 +12722,7 @@
                 /**/
                 // HDR
                 "MOV temp.z, final.a;" +
-                "MUL final, final,options1.w;" +
+                "MUL final, final,options2.x;" +
                 "MOV final.a, temp.z;" +
                 /**/
                 
@@ -11262,6 +12915,7 @@
     String Shadow(String depth, String shadow)
     {
         return "MAX temp.x, ndotl.x, one64th.x;" +
+               "MIN temp.x, temp.x, ninetenth.x;" +
                 /**/
                 // Sine
                 "MUL temp.y, temp.x, temp.x;" +
@@ -11881,14 +13535,16 @@
 	
         //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;
 	}
         
+        boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
         
         // TIMER
-        if (!wheeltimer.isRunning() && e.getModifiersEx() == 0) // VR
+        if (ZOOMBOXMODE && !wheeltimer.isRunning() && e.getModifiersEx() == 0 && !capsLocked) // VR
         {
             keepboxmode = BOXMODE;
             keepsupport = SUPPORT;
@@ -12017,7 +13673,7 @@
 //            ObjEditor.tweenManager.update(1f / 60f);
             
 // fev 2014???
-            if ((TRACK || SHADOWTRACK) && trackedobject != null) // && drawMode == SHADOW) // && !lightMode)
+            if ((TRACK || SHADOWTRACK) && trackedobject != null) // && DrawMode() == SHADOW) // && !lightMode)
                 object.editWindow.ScreenFit(trackedobject, SHADOWTRACK && !TRACK);
             pingthread.StepToTarget(true); // true);
         }
@@ -12105,11 +13761,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())
         {
@@ -12129,6 +13785,11 @@
     cVector tmp = new cVector();
     cVector tmp2 = new cVector();
     boolean isMoving;
+
+    public cVector TargetLookAt()
+    {
+            return targetLookAt;
+    }
 
     class PingThread extends Thread
     {
@@ -12268,7 +13929,7 @@
             //System.out.println("----------------   ----------      Paint " + tmp.length2());
             if (lightMode)
             {
-                lighttouched = true;
+                Globals.lighttouched = true;
             }
             
             if (OEILONCE && OEIL)
@@ -12326,7 +13987,7 @@
                             mouseDown = false;
                             if (lightMode)
                             {
-                                lighttouched = true;
+                                Globals.lighttouched = true;
                             }
                             repaint();
                             alreadypainted = true;
@@ -12334,7 +13995,7 @@
                         isMoving = false;
                     } //??
 
-                        if (isLIVE() && !alreadypainted)
+                        if (Globals.isLIVE() && !alreadypainted)
                         {
                             // FOR DEBUG BREAKPOINT USING PAUSE: while (true)
                             repaint();
@@ -12346,7 +14007,7 @@
                 {
                     if (lightMode)
                     {
-                        lighttouched = true;
+                        Globals.lighttouched = true;
                     }
                     drag(X, (mouseMode != 0) ? Y : anchorY, MODIFIERS);
                 }
@@ -12589,6 +14250,7 @@
                 {
                     manipCamera.Translate(dx, dy, getWidth());
                 }
+                else
                 if ((mouseMode & ZOOM) == 0 && (mouseMode & VR) != 0)
                 {
                     manipCamera.RotateInterest(dx, dy);
@@ -12599,7 +14261,7 @@
 
             if (manipCamera == lightCamera)
             {
-                lighttouched = true;
+                Globals.lighttouched = true;
             }
             /*
             switch (mode)
@@ -12638,7 +14300,6 @@
     public void mouseMoved(MouseEvent e)
     {
         //System.out.println("mouseMoved: " + e);
-
         if (isRenderer)
             return;
         
@@ -12814,13 +14475,15 @@
         {
             mouseMode |= ZOOM;
         }
-        if ((modifiers & META) == META)
+        
+        boolean capsLocked = Toolkit.getDefaultToolkit().getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
+        if (capsLocked || (modifiers & META) == META)
         {
             mouseMode |= VR; // BACKFORTH;
         }
         if ((modifiers & CTRLCLICK) == CTRLCLICK)
         {
-            mouseMode |= SELECT; // BACKFORTH;
+            mouseMode |= SELECT;
         }
         if ((modifiers & COMMAND) == COMMAND)
         {
@@ -12828,6 +14491,7 @@
         }
         if ((modifiers & SHIFT) == SHIFT || forcetranslate)
         {
+            mouseMode &= ~VR;
             mouseMode |= TRANSLATE;
         }
     //    if ((modifiers & SHIFT_META) == SHIFT_META)
@@ -12857,7 +14521,7 @@
             SetMouseMode(modifiers);
         }
 
-        theRenderer.keyPressed(key);
+        Globals.theRenderer.keyPressed(key);
     }
 
     int kompactbit = 4; // power bit
@@ -12869,7 +14533,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');
@@ -12984,7 +14648,7 @@
             case 'B':
                 BRISMOOTH ^= true;
                 SHADOWCULLFACE ^= true;
-                lighttouched = true;
+                Globals.lighttouched = true;
                 repaint();
                 break;
             case 'b':
@@ -13084,7 +14748,7 @@
                 repaint();
                 break;
             case 'O':
-                drawMode = OCCLUSION;
+                Globals.drawMode = OCCLUSION; // WARNING
                 repaint();
                 break;
             case 'o':
@@ -13175,7 +14839,7 @@
                 break;
             case ' ':
                 lightMode ^= true;
-                lighttouched = true;
+                Globals.lighttouched = true;
                 manipCamera = renderCamera = lightMode ? lightCamera : eyeCamera;
                 targetLookAt.set(manipCamera.lookAt);
                 repaint();
@@ -13187,11 +14851,11 @@
                 repaint();
                 break;
             case 'Z':
-                RESIZETEXTURE ^= true;
-                break;
+                //RESIZETEXTURE ^= true;
+                //break;
             case 'z':
                 RENDERSHADOW ^= true;
-                lighttouched = true;
+                Globals.lighttouched = true;
                 repaint();
                 break;
             //case UP:
@@ -13217,7 +14881,8 @@
                 FlipTransform();
                 break;
             case ENTER:
-                object.editWindow.ScreenFit(); // Edit();
+                // object.editWindow.ScreenFit(); // Edit();
+                ToggleLive();
                 break;
             case DELETE:
                 ClearSelection();
@@ -13305,6 +14970,7 @@
         }
     //System.out.println("shaper_fovy = " + manipCamera.shaper_fovy);
     }
+    
     static double OCCLUSIONBOOST = 1; // 0.5;
 
     void keyReleased(int key, int modifiers)
@@ -13316,7 +14982,7 @@
         }
     }
 
-    protected void processKeyEvent(KeyEvent e)
+    public void processKeyEvent(KeyEvent e)
     {
         switch (e.getID())
         {
@@ -13446,8 +15112,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 && (mouseMode & SELECT) == 0)
         {
             mouseMoved(e);
         } else
@@ -13792,6 +15459,7 @@
     //if (g != gr) g.drawImage(img, 0, 0, width, height, null);
     }
 
+    // To avoid clear.
     public void update(Graphics g)
     {
         paint(g);
@@ -14394,7 +16062,7 @@
         gl.glPushAttrib(GL.GL_ALL_ATTRIB_BITS);
         gl.glPushMatrix();
         gl.glLoadIdentity();
-        PushMatrix(checker.toParent);
+        //PushMatrix(checker.toParent);
 
         gl.glMatrixMode(GL.GL_TEXTURE);
         gl.glPushMatrix();
@@ -14417,8 +16085,8 @@
 
         gl.glNormal3f(0.0f, 0.0f, 1.0f);
             
-        float step = 0.1666f; //0.25f;
-        float stepv = step * 1652 / 998;
+        float step = 2; // 0.1666f; //0.25f;
+        float stepv = 2; // step * 1652 / 998;
 
         int i0 = 0;
         /*
@@ -14454,20 +16122,21 @@
         /**/
         //checker.GetMaterial().opacity = 1.1f;
         ////checker.GetMaterial().ambient = 0.99f;
-                Object3D.materialstack[Object3D.materialdepth] = checker.material;
-                Object3D.selectedstack[Object3D.materialdepth] = false;
-                cStatic.objectstack[Object3D.materialdepth++] = checker;
+                materialstack[materialdepth] = checker.material;
+                selectedstack[materialdepth] = false;
+                cStatic.objectstack[materialdepth++] = checker;
                 //System.out.println("material " + material);
                 //Applet3D.tracein(this, selected);
                 vector2buffer = checker.projectedVertices;
 
-        checker.GetMaterial().Draw(this, false); // true);
+        //checker.GetMaterial().Draw(this, false); // true);
+        DrawMaterial(checker.GetMaterial(), false); // true);
 
-                Object3D.materialdepth -= 1;
-                if (Object3D.materialdepth > 0)
+                materialdepth -= 1;
+                if (materialdepth > 0)
                 {
-                    vector2buffer = cStatic.objectstack[Object3D.materialdepth - 1].projectedVertices;
-                    Object3D.materialstack[Object3D.materialdepth - 1].Draw(this, Object3D.selectedstack[Object3D.materialdepth - 1]);
+                    vector2buffer = cStatic.objectstack[materialdepth - 1].projectedVertices;
+                    DrawMaterial(materialstack[materialdepth - 1], selectedstack[materialdepth - 1]);
                 }
         //checker.GetMaterial().opacity = 1f;
         ////checker.GetMaterial().ambient = 1f;
@@ -14488,15 +16157,27 @@
 
                 //float u = (i+1)/2;
                 //float v = (j+1)/2;
-                gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
+                if (checker.flipV)
+                        gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1) / 2);
+                else
+                        gl.glTexCoord2f((i + 1) / 2, (j + 1) / 2); // (1,0) // (i+1+step)/2,(j+1)/2);
                 gl.glVertex3f(i, j, -0.5f);
 
+                if (checker.flipV)
+                gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
+                else
                 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1) / 2); // (1,1) // (i+1+step)/2,(j+1+step)/2);
                 gl.glVertex3f(i + step, j, -0.5f);
 
+                if (checker.flipV)
+                gl.glTexCoord2f((i + 1 + step) / 2, 1 - (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
+                else
                 gl.glTexCoord2f((i + 1 + step) / 2, (j + 1 + stepv) / 2); // (0,1) //(i+1)/2,(j+1+step)/2);
                 gl.glVertex3f(i + step, j + stepv, -0.5f);
 
+                if (checker.flipV)
+                gl.glTexCoord2f((i + 1) / 2, 1 - (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
+                else
                 gl.glTexCoord2f((i + 1) / 2, (j + 1 + stepv) / 2); // (0,0) //(i+1)/2,(j+1)/2);
                 gl.glVertex3f(i, j + stepv, -0.5f);
             }
@@ -14508,7 +16189,7 @@
         gl.glMatrixMode(GL.GL_PROJECTION);
         gl.glPopMatrix();
         gl.glMatrixMode(GL.GL_MODELVIEW);
-        PopMatrix(null); // checker.toParent); // null);
+        //PopMatrix(null); // checker.toParent); // null);
         gl.glPopMatrix();
         PopTextureMatrix(checker.toParent);
         gl.glMatrixMode(GL.GL_TEXTURE);
@@ -14621,14 +16302,14 @@
 
             //int tmp = selection_view;
             //selection_view = -1;
-            int temp = drawMode;
-            drawMode = SELECTION;
+            int temp = DrawMode();
+            Globals.drawMode = SELECTION; // WARNING
             indexcount = 0;
             parent.display(drawable);
             //selection_view = tmp;
             //if (temp == SELECTION)
             //    temp = DEFAULT; // patch for selection debug
-            drawMode = temp;
+            Globals.drawMode = temp; // WARNING
 
             //gl.glBindTexture(GL.GL_TEXTURE_2D, selection_view);
 
@@ -14677,6 +16358,11 @@
 //                System.err.println("view = " + view[4] + " " + view[5] + " " + view[6] + " " + view[7]);
 //                System.err.println("view = " + view[8] + " " + view[9] + " " + view[10] + " " + view[11]);
 //                System.err.println("view = " + view[12] + " " + view[13] + " " + view[14] + " " + view[15]);
+                
+                // Will fit the mesh !!!
+                selectedpoint.toParent[0][0] = 0.0001;
+                selectedpoint.toParent[1][1] = 0.0001;
+                selectedpoint.toParent[2][2] = 0.0001;
                 
                 glu.gluUnProject(x,y,depth,view,0,tempmat2,0,viewport,0,selectedpoint.toParent[3],0);
                 
@@ -14896,14 +16582,14 @@
             //gl.glColorMask(false, false, false, false);
 
             //render_scene_from_light_view(gl, drawable, 0, 0);
-            if (RENDERSHADOW && lighttouched && !movingcamera) // && !parent.IsFreezed())
+            if (RENDERSHADOW && Globals.lighttouched && !movingcamera) // && !parent.IsFreezed())
             {
                 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
 
-                int temp = drawMode;
-                drawMode = SHADOW;
+                int temp = DrawMode();
+                Globals.drawMode = SHADOW; // WARNING
                 parent.display(drawable);
-                drawMode = temp;
+                Globals.drawMode = temp; // WARNING
             }
 
             gl.glCullFace(gl.GL_BACK);
@@ -14956,7 +16642,6 @@
 
     class AntialiasBuffer implements GLEventListener
     {
-
         CameraPane parent = null;
 
         AntialiasBuffer(CameraPane p)
@@ -15066,13 +16751,19 @@
             gl.glFlush();
             
             /**/
-            gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_BGRA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, occlusionsizebuffer);
+            gl.glReadPixels(0, 0, OCCLUSION_SIZE, OCCLUSION_SIZE, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, occlusionsizebuffer);
 
-            int[] pixels = occlusionsizebuffer.array();
+            float[] pixels = occlusionsizebuffer.array();
 
             double r = 0, g = 0, b = 0;
 
             double count = 0;
+            
+        gl.glGetDoublev(gl.GL_PROJECTION_MATRIX, tempmat2, 0);
+                                
+            float mindepth = 1;
+            
+            double FACTOR = 1;
 
             for (int i = 0; i < pixels.length; i++)
             {
@@ -15157,7 +16848,7 @@
 
                 double scale = ray.z; // 1; // cos
 
-                int p = pixels[newindex];
+                float depth = pixels[newindex];
 
                 /*
                 int newindex2 = (x + 1) * OCCLUSION_SIZE + y;
@@ -15181,10 +16872,23 @@
                 scale = (1 - modu) * modv;
                  */
 
-                r += ((p >> 16) & 0xFF) * scale / 255;
-                g += ((p >> 8) & 0xFF) * scale / 255;
-                b += (p & 0xFF) * scale / 255;
+                //r += ((p >> 16) & 0xFF) * scale / 255;
+                //g += ((p >> 8) & 0xFF) * scale / 255;
+                //b += (p & 0xFF) * scale / 255;
+                
+                if (mindepth > depth)
+                {
+                    mindepth = depth;
+                }
 
+                double z_eye = tempmat2[3*4 + 2] / (depth * -2.0 + 1.0 - tempmat2[2*4 + 2]);
+                
+                double factor = 1 - Math.exp(-z_eye * z_eye / FACTOR);
+                
+                r += factor * scale;
+                g += factor * scale;
+                b += factor * scale;
+                
                 count += scale;
             }
             
@@ -15282,12 +16986,6 @@
     GLUT glut = new GLUT();
     
     
-    static final public int DEFAULT = 0;
-    static final public int SELECTION = 1;
-    static final public int SHADOW = 2;
-    static final public int OCCLUSION = 3;
-    static
-            public int drawMode = DEFAULT;
     public boolean spherical = false;
     static boolean DEBUG_OCCLUSION = false;
     static boolean DEBUG_SELECTION = false;
@@ -15300,12 +16998,12 @@
     int AAbuffersize = 0;
     
     //double[] selectedpoint = new double[3];
-    static Sphere selectedpoint = new Sphere();
+    static Superellipsoid selectedpoint = new Superellipsoid();
     static Sphere previousselectedpoint = null;
-    static Sphere debugpoint = new Sphere();
-    static Sphere debugpoint2 = new Sphere();
-    static Sphere debugpoint3 = new Sphere();
-    static Sphere debugpoint4 = new Sphere();
+    static Sphere debugpointG = new Sphere();
+    static Sphere debugpointP = new Sphere();
+    static Sphere debugpointC = new Sphere();
+    static Sphere debugpointR = new Sphere();
     
     static Sphere debugpoints[] = new Sphere[8];
  
@@ -15336,7 +17034,7 @@
         }
     }
     
-    static void DrawPoints(CameraPane cpane)
+    static void DrawPoints(iCameraPane cpane)
     {
         for (int i=0; i<8; i++) // first and last are red
         {
@@ -15358,7 +17056,8 @@
     static IntBuffer texturesizebuffer = IntBuffer.allocate(TEX_SIZE * TEX_SIZE);
     static IntBuffer selectsizebuffer = IntBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
     static java.nio.FloatBuffer pointselectsizebuffer = java.nio.FloatBuffer.allocate(SELECT_SIZE * SELECT_SIZE);
-    static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
+    //static IntBuffer occlusionsizebuffer = IntBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
+    static java.nio.FloatBuffer occlusionsizebuffer = java.nio.FloatBuffer.allocate(OCCLUSION_SIZE * OCCLUSION_SIZE);
     static BufferedImage bufimage = new BufferedImage(TEX_SIZE, TEX_SIZE, BufferedImage.TYPE_INT_RGB);
     static BufferedImage textest = new cBufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
     static java.util.Vector<BufferedImage> billboards = new java.util.Vector<BufferedImage>();
@@ -15367,10 +17066,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