From 9cf2c36d644d0aaa28797f57a3e71591d8e66973 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sun, 06 Oct 2019 10:56:18 -0400
Subject: [PATCH] Save image helper.

---
 Object3D.java |   96 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 69 insertions(+), 27 deletions(-)

diff --git a/Object3D.java b/Object3D.java
index ba7e5c6..0843864 100644
--- a/Object3D.java
+++ b/Object3D.java
@@ -41,6 +41,8 @@
         
     java.util.Hashtable<java.util.UUID, Object3D> versiontable; // = new java.util.Hashtable<java.util.UUID, Object3D>();
     
+    transient int tabIndex; // Tabs can change between sessions.
+    
     ScriptNode scriptnode;
 
     void deepCopyNode(Object3D other)
@@ -100,7 +102,7 @@
         other.softtouched = softtouched;
         
         other.random = random;
-        other.link2master = link2master;
+        other.link2master = Link2Support();
         other.transformcount = transformcount;
         other.marked = marked;
         other.skip = skip;
@@ -220,7 +222,7 @@
             return;
 
         transientsupport = support;
-        transientlink2master = link2master;
+        transientlink2master = Link2Support();
 
         support = null;
         link2master = false;
@@ -633,7 +635,10 @@
     transient boolean keepdontselect;
     boolean dontselect = false;
     boolean hide = false;
+    
     boolean link2master = false; // performs reset support/master at each frame (cannot rename due to serialization)
+    boolean link2support = false; // (cannot rename due to serialization)
+    
     boolean marked = false; // animation node
     boolean skip = false; // centroid issue
     boolean skipmocap = false; // mocap data
@@ -1023,7 +1028,7 @@
     
     void Step()
     {
-        // marde pour serialization de Texture
+        // patch pour serialization de Texture
         resetmaxcount();
         resettransformcount();
         resetstep();
@@ -1137,6 +1142,8 @@
                 (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || !Globals.COMPUTESHADOWWHENLIVE) &&
                 currentframe != Globals.framecount)
         {
+            Globals.lighttouched = true;
+            
             currentframe = Globals.framecount;
             
 //            System.err.println("transformcount = " + transformcount);
@@ -3414,7 +3421,7 @@
         }
     }
     
-    public void Scale(int scale)
+    public void Scale(float scale)
     {
         Object3D obj = this;
         
@@ -4101,11 +4108,6 @@
         Step();
         Touch();
         
-        StepRecur();
-    }
-    
-    void StepRecur()
-    {
         for (int i = 0; i < size(); i++)
         {
             Object3D child = (Object3D) get(i); // reserve(i);
@@ -6159,7 +6161,7 @@
     boolean NeedSupport()
     {
         return
-                CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && link2master && /*live &&*/ support != null
+                CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && Link2Support() && /*live &&*/ support != null
                  // PROBLEM with CROWD!!
                     && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
     }
@@ -6182,6 +6184,15 @@
         return live && bRep != null;
     }
     
+    boolean Link2Support()
+    {
+        return link2master || link2support;
+    }
+    
+    static cVector minima = new cVector();
+    static cVector maxima = new cVector();
+    static javax.vecmath.Point3d center = new javax.vecmath.Point3d();
+    
     void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
     {
         Invariants(); // june 2013
@@ -6189,6 +6200,29 @@
         if (support != null)
         {
         //    System.err.println("Draw " + this + " Frame # " + ((Mocap)((Merge)support).object).frame);
+        }
+        
+        if (false) // live && Link2Support() && support == null && !this.marked) // project on ground
+        {
+            getBounds(minima, maxima, true);
+            center.x = (minima.x + maxima.x) / 2;
+            center.y = 10000; // (minima.y + maxima.y) / 2;
+            center.z = (minima.z + maxima.z) / 2;
+
+            Ray ray = new Ray(center, new Vector3d(0,-1,0));
+
+            IntersectResult res = new IntersectResult();
+            res.t = Double.POSITIVE_INFINITY;
+
+            if (Grafreed.grafreed.universe.intersect(ray, res))
+            {
+                double resx = ray.eyePoint.x + ray.viewDirection.x * res.t;
+                double resy = ray.eyePoint.y + ray.viewDirection.y * res.t;
+                double resz = ray.eyePoint.z + ray.viewDirection.z * res.t;
+                
+                LA.matTranslate(toParent, 0, resy - minima.y, 0);
+                LA.matInvert(toParent, fromParent);
+            }
         }
         
         if (display.DrawMode() == iCameraPane.SELECTION &&
@@ -6243,7 +6277,7 @@
             support = support;
         
         boolean usecalllists = !IsDynamic() &&
-                                    IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
+                                    IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !Link2Support()); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
         //boolean usecalllists = false; //!IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
         
         //usecalllists &= display.DrawMode() == display.DEFAULT; // Don't compute list in shadow pass.
@@ -6254,7 +6288,8 @@
             bRep.displaylist = 0;
         }
    //     usecalllists &= !(parent instanceof RandomNode);
-   //     usecalllists = false;
+        if (CameraPane.BOXMODE) // Too dynamic
+            usecalllists = false;
 
         if (display.DrawMode() == display.SHADOW)
             //GetBRep() != null)
@@ -6268,7 +6303,7 @@
         
         if (!selectmode && //display.DrawMode() != display.SELECTION &&
                 //(touched || (bRep != null && bRep.displaylist <= 0)))
-                (Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE || touched && Globals.COMPUTESHADOWWHENLIVE)) // || (bRep != null && bRep.displaylist <= 0)))
+                ((Globals.isLIVE() && Globals.COMPUTESHADOWWHENLIVE) || touched)) // || (bRep != null && bRep.displaylist <= 0)))
         {
             Globals.lighttouched = true;
         } // all panes...
@@ -6350,7 +6385,7 @@
         {
             if (display.DrawMode() == iCameraPane.SHADOW)
             {
-                if (!link2master // tricky to cull in shadow mode.
+                if (!Link2Support() // tricky to cull in shadow mode.
                          && GetBRep().FrustumCull(this, null, display.LightCamera(), true))
                 {
                     //System.out.print("CULLED");
@@ -6823,7 +6858,8 @@
 
         //javax.media.opengl.GL gl = display.GetGL();
 
-        if (CameraPane.BOXMODE && !selected) // || CameraPane.movingcamera)
+        if (CameraPane.BOXMODE && //!Link2Support()) //
+                                !selected) // || CameraPane.movingcamera)
         {
             int fc = bRep.FaceCount();
             int vc = bRep.VertexCount();
@@ -6985,7 +7021,7 @@
                         facescompare[k] = new FaceCompare(k);
                     }
                     
-                    center = new cVector();
+                    centertriangle = new cVector();
                 }
                 else
                 {
@@ -7108,7 +7144,7 @@
          */
     }
 
-    transient cVector center;
+    transient cVector centertriangle;
     
     class FaceCompare implements Comparable
     {
@@ -7137,14 +7173,14 @@
                 Vertex q = bRep.GetVertex(face.q);
                 Vertex r = bRep.GetVertex(face.r);
 
-                center.set(p);
-                center.add(q);
-                center.add(r);
-                center.mul(1.0/3);
+                centertriangle.set(p);
+                centertriangle.add(q);
+                centertriangle.add(r);
+                centertriangle.mul(1.0/3);
                 
-                center.sub(Globals.theRenderer.EyeCamera().location);
+                centertriangle.sub(Globals.theRenderer.EyeCamera().location);
                 
-                distance = center.dot(center);
+                distance = centertriangle.dot(centertriangle);
             }
             
             return distance;
@@ -8327,7 +8363,7 @@
 
     public int hashCode()
     {
-        // Fuck Vector...
+        // Do not use Vector...
         return System.identityHashCode(this);
     }
     
@@ -8894,7 +8930,7 @@
         
         boolean touch = false;
         
-        if (bRep != null && link2master)
+        if (bRep != null && Link2Support())
         {
             if (bbox == null)
             {
@@ -8903,7 +8939,7 @@
                 cVector min = new cVector();
                 cVector max = new cVector();
                 
-                this.getBounds(min, max, false);
+                this.getBounds(min, max, true);
                 
                 bbox.min.x = min.x;
                 bbox.min.y = min.y;
@@ -8914,7 +8950,7 @@
                 bbox.max.z = max.z;
             }
             
-            if (bbox.intersect(ray, result))
+            if (true) // NOT WORKING bbox.intersect(ray, result))
             {
                 success |= intersectMesh(ray, result);
             }
@@ -8958,6 +8994,12 @@
     
     private boolean intersectTriangle(Ray ray, IntersectResult result, Vertex v1, Vertex v2, Vertex v3)
     {
+        if (false)
+        {
+            result.t = 0;
+            return true;
+        }
+        
         /*
         Fast, Minimum Storage Ray/Triangle Intersection, Moller et al.
         

--
Gitblit v1.6.2