From b33ef80d78f01a6a61f4248b1bb7deaade42d503 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sun, 16 Jun 2019 11:49:21 -0400
Subject: [PATCH] Attribute editor

---
 ObjEditor.java       |   21 ++++--
 AttributeEditor.java |   28 +++++----
 CameraPane.java      |   71 ++++++++++++++++-------
 Camera.java          |    1 
 Globals.java         |    2 
 Object3D.java        |   19 +++++-
 6 files changed, 95 insertions(+), 47 deletions(-)

diff --git a/AttributeEditor.java b/AttributeEditor.java
index 797e00a..4552a44 100644
--- a/AttributeEditor.java
+++ b/AttributeEditor.java
@@ -41,20 +41,24 @@
                 super.SetupUI2(oe); // Shows composite UI !!
                 //super.SetupName(oe);
                 
-                oe.aConstraints.weighty = 0;
-                
-		oe.aConstraints.gridwidth = 1;
-		oe.aConstraints.fill = GridBagConstraints.HORIZONTAL;
-                oe.aConstraints.gridwidth = 1;
-                oe.aConstraints.anchor = GridBagConstraints.WEST;
-                oe.ctrlPanel.add(cleardepth = new JCheckBox("Clear Depth", attribute.cleardepth), oe.aConstraints, oe.ctrlPanel.getComponentCount() - 2);
-                oe.aConstraints.gridx += 1;
+//                oe.aConstraints.weighty = 0;
+//                
+//		oe.aConstraints.gridwidth = 1;
+//		oe.aConstraints.fill = GridBagConstraints.HORIZONTAL;
+//                oe.aConstraints.gridwidth = 1;
+//                oe.aConstraints.anchor = GridBagConstraints.WEST;
+                oe.ctrlPanel.add(cleardepth = new JCheckBox("Clear Depth", attribute.cleardepth)); //, oe.aConstraints, oe.ctrlPanel.getComponentCount() - 2);
+
+                oe.ctrlPanel.Return();
+//                oe.aConstraints.gridx += 1;
 //                oe.ctrlPanel.add(passtest = new JCheckBox("Write depth", attribute.passtest), oe.aConstraints, oe.ctrlPanel.getComponentCount() - 2);
 //                oe.aConstraints.gridx += 1;
-                oe.ctrlPanel.add(passtest = new JCheckBox("Pass Test", attribute.passtest), oe.aConstraints, oe.ctrlPanel.getComponentCount() - 2);
-                oe.aConstraints.gridx += 1;
-                oe.ctrlPanel.add(backfacecull = new JCheckBox("Backface Cull", attribute.backfacecull), oe.aConstraints, oe.ctrlPanel.getComponentCount() - 2);
-                oe.aConstraints.gridx += 1;
+                oe.ctrlPanel.add(passtest = new JCheckBox("Pass Test", attribute.passtest)); //, oe.aConstraints, oe.ctrlPanel.getComponentCount() - 2);
+                oe.ctrlPanel.Return();
+//                oe.aConstraints.gridx += 1;
+                oe.ctrlPanel.add(backfacecull = new JCheckBox("Backface Cull", attribute.backfacecull)); //, oe.aConstraints, oe.ctrlPanel.getComponentCount() - 2);
+                oe.ctrlPanel.Return();
+//                oe.aConstraints.gridx += 1;
                 
 		cleardepth.addItemListener(this);
 		passtest.addItemListener(this);
diff --git a/Camera.java b/Camera.java
index 8454950..f5243d4 100644
--- a/Camera.java
+++ b/Camera.java
@@ -3,7 +3,6 @@
 // Decompiler options: packimports(3) 
 // Source File Name:   Camera.java
 
-
 class Camera extends Object3D
 {
     static final long serialVersionUID = 4754289789178680517L;
diff --git a/CameraPane.java b/CameraPane.java
index 16d28d9..b4be4fc 100644
--- a/CameraPane.java
+++ b/CameraPane.java
@@ -150,6 +150,8 @@
         defaultcaps.setAccumAlphaBits(16);
     }
     
+    private File defaultDirectory = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();
+    
     void SetAsGLRenderer(boolean b)
     {
         isRenderer = b;
@@ -462,7 +464,7 @@
         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);
+            boolean hasnorm = pv.norm != null && (pv.norm.x != 0 || pv.norm.y != 0 || pv.norm.z != 0);
             if (!hasnorm)
             {
            //     System.out.println("FUCK!!");
@@ -2374,7 +2376,7 @@
     {
         return currentGL;
     }
-    
+
     /**/
     class CacheTexture
     {
@@ -8067,6 +8069,26 @@
         return; // true;
     }
     
+    java.util.HashSet<String> missingTextures = new java.util.HashSet<String>();
+    
+    private boolean FileExists(String tex)
+    {
+        if (missingTextures.contains(tex))
+        {
+            return false;
+        }
+        
+        boolean fileExists = new File(tex).exists();
+        
+        if (!fileExists)
+        {
+            // If file exists, the "new File()" is not executed sgain
+            missingTextures.add(tex);
+        }
+        
+        return fileExists;
+    }
+    
     CacheTexture GetCacheTexture(String tex, boolean bump, int resolution) throws Exception
     {
         CacheTexture/*com.sun.opengl.util.texture.Texture*/ texture = null;
@@ -8075,15 +8097,17 @@
         {
             String texname = tex;
             
+            String fallbackTextureName = defaultDirectory + "/Textures/" + texname;
+                
 //            String[] split = tex.split("Textures");
 //            if (split.length > 1)
 //                texname = "/Users/nbriere/Textures" + split[split.length-1];
 //            else
 //                if (!texname.startsWith("/"))
 //                    texname = "/Users/nbriere/Textures/" + texname;
-            if (!new File(tex).exists())
+            if (!FileExists(tex))
             {
-                    texname = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory() + "/Textures/" + texname;
+                    texname = fallbackTextureName;
             }
             
             if (CACHETEXTURE)
@@ -8153,7 +8177,7 @@
                                     }
                                 
                                     cachename = texname.substring(0, texname.length()-4)+ext+".jpg";
-                                    if (!new File(cachename).exists())
+                                    if (!FileExists(cachename))
                                         cachename = texname;
                                     else
                                         processbump = false; // don't process bump map again
@@ -8175,7 +8199,7 @@
                                     }
                                 
                                     cachename = texname.substring(0, texname.length()-4)+ext+".png";
-                                    if (!new File(cachename).exists())
+                                    if (!FileExists(cachename))
                                         cachename = texname;
                                     else
                                         processbump = false; // don't process bump map again
@@ -9310,8 +9334,8 @@
         assert (parentcam != renderCamera);
         
         if (renderCamera != lightCamera)
-        for (int count = parentcam.GetTransformCount(); --count>=0;)
-            LA.matConcat(matrix, parentcam.toParent, matrix);
+        //for (int count = parentcam.GetTransformCount(); --count>=0;)
+            LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
         
 //            LA.matConcat(renderCamera.toScreen, renderCamera.toParent, matrix);
             
@@ -9326,8 +9350,8 @@
             LA.matCopy(renderCamera.fromScreen, matrix);
             
         if (renderCamera != lightCamera)
-        for (int count = parentcam.GetTransformCount(); --count>=0;)
-            LA.matConcat(parentcam.fromParent, matrix, matrix);
+        //for (int count = parentcam.GetTransformCount(); --count>=0;)
+            LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
 
 //            LA.matConcat(renderCamera.fromParent, renderCamera.fromScreen, matrix);
             
@@ -10525,8 +10549,8 @@
             
 //        if (parentcam != renderCamera) // not a light
         if (cam != lightCamera)
-            for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.matConcat(matrix, parentcam.toParent, matrix);
+            //for (int count = parentcam.GetTransformCount(); --count>=0;)
+                LA.matConcat(matrix, parentcam.GlobalTransformInv(), matrix);
             
             for (int j = 0; j < 4; j++)
             {
@@ -10540,8 +10564,8 @@
             
 //        if (parentcam != renderCamera) // not a light
         if (cam != lightCamera)
-            for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.matConcat(parentcam.fromParent, matrix, matrix);
+            //for (int count = parentcam.GetTransformCount(); --count>=0;)
+                LA.matConcat(parentcam.GlobalTransform(), matrix, matrix);
         
             //LA.matConcat(cam.fromScreen, parentcam.fromParent, matrix);
             
@@ -10934,8 +10958,8 @@
                 System.err.println("parentcam != renderCamera");
 
 //            if (cam != lightCamera)
-            for (int count = parentcam.GetTransformCount(); --count>=0;)
-                LA.xformDir(lightposition, parentcam.toParent, lightposition); // may 2013
+            //for (int count = parentcam.GetTransformCount(); --count>=0;)
+                LA.xformDir(lightposition, parentcam.GlobalTransformInv(), lightposition); // may 2013
         }
         
         LA.xformDir(lightposition, cam.toScreen, lightposition);
@@ -10956,8 +10980,8 @@
             if (true) // TODO
             {
                 if (cam != lightCamera)
-                for (int count = parentcam.GetTransformCount(); --count>=0;)
-                   LA.xformDir(light0, parentcam.toParent, light0); // may 2013
+                //for (int count = parentcam.GetTransformCount(); --count>=0;)
+                   LA.xformDir(light0, parentcam.GlobalTransformInv(), light0); // may 2013
             }
             
             LA.xformPos(light0, cam.toScreen, light0);
@@ -11869,8 +11893,8 @@
             //obj.TransformToWorld(light, light);
             for (int i = tp.size(); --i >= 0;)
             {
-                for (int count = tp.get(i).GetTransformCount(); --count>=0;)
-                    LA.xformPos(light, tp.get(i).toParent, light);
+                //for (int count = tp.get(i).GetTransformCount(); --count>=0;)
+                    LA.xformPos(light, tp.get(i).GlobalTransformInv(), light);
             }
 
 
@@ -11887,8 +11911,8 @@
                 parentcam = cameras[0];
             }
             
-        for (int count = parentcam.GetTransformCount(); --count>=0;)
-            LA.xformPos(light, parentcam.toParent, light); // may 2013
+        //for (int count = parentcam.GetTransformCount(); --count>=0;)
+            LA.xformPos(light, parentcam.GlobalTransformInv(), light); // may 2013
 
             LA.xformPos(light, renderCamera.toScreen, light);
             
@@ -13812,6 +13836,7 @@
         //System.out.println("mouseDragged: " + e);
         if (isRenderer)
             movingcamera = true;
+        
         //if (drawing)
         //return;
         if ((e.getModifiersEx() & CTRL) != 0
@@ -15911,7 +15936,7 @@
     Object3D object;
     static Object3D trackedobject;
     Camera renderCamera; // Light or Eye (or Occlusion)
-    /*static*/ Camera manipCamera; // Light or Eye
+    /*static*/ Camera manipCamera; // Light or Eye. Can be Light when Eye, not Eye when Light
 	/*static*/ Camera eyeCamera;
     /*static*/ Camera lightCamera;
     int cameracount;
diff --git a/Globals.java b/Globals.java
index e0c7291..f6ac3a4 100644
--- a/Globals.java
+++ b/Globals.java
@@ -7,6 +7,8 @@
     
         private static boolean LIVE = false;
         public static boolean RENDERSHADOW = true;
+        
+        // Hold on calculation when moving camera
         public static boolean FREEZEONMOVE = false; // true;
         
         static boolean CROWD = false;
diff --git a/ObjEditor.java b/ObjEditor.java
index 1319073..747c30b 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -278,7 +278,7 @@
         frame.setMenuBar(menuBar = new MenuBar());
         menuBar.add(fileMenu = new Menu("File"));
         fileMenu.add(newItem = new MenuItem("New"));
-        fileMenu.add(loadItem = new MenuItem("Load..."));
+        fileMenu.add(loadItem = new MenuItem("Open..."));
         
                 //oe.menuBar.add(menu = new Menu("Include"));
         Menu menu = new Menu("Import");
@@ -2072,19 +2072,19 @@
 
     void LoadObjFile(String fullname)
     {
-        /*
+        System.out.println("Loading " + fullname);
+        /**/
         //lastFilename = fullname;
         if(loadObjThread == null)
         {
-        loadObjThread = new LoadOBJThread();
-        loadObjThread.start();
+            loadObjThread = new LoadOBJThread();
+            loadObjThread.start();
         }
         
         loadObjThread.add(fullname);
-         */
+        /**/
 
-        System.out.println("Loading " + fullname);
-        makeSomething(new FileObject(fullname, true), true);
+        //makeSomething(new FileObject(fullname, true), true);
     }
 
     void LoadGFDFile(String fullname)
@@ -3214,7 +3214,7 @@
         objEditor.refreshContents();
     }
     
-    static public byte[] Compress(Object o)
+    static public byte[] Compress(Object3D o)
     {
         try
         {
@@ -3222,8 +3222,13 @@
             java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
             ObjectOutputStream out = new ObjectOutputStream(zstream);
 
+        Object3D parent = o.parent;
+        o.parent = null;
+        
             out.writeObject(o);
             
+        o.parent = parent;
+        
             out.flush();
 
             zstream.close();
diff --git a/Object3D.java b/Object3D.java
index d7a346f..28b696b 100644
--- a/Object3D.java
+++ b/Object3D.java
@@ -174,7 +174,7 @@
         {
             Object3D o = hashtable.get(GetUUID());
 
-            assert(this.bRep == o.bRep);
+            Grafreed.Assert(this.bRep == o.bRep);
             if (this.bRep != null)
                 assert(this.bRep.support == o.transientrep);
 
@@ -563,12 +563,14 @@
             toParent = LA.newMatrix();
             fromParent = LA.newMatrix();
         }
+        
         if (toParentMarked == null)
         {
             if (maxcount != 1)
             {
                 new Exception().printStackTrace();
             }
+            
             toParentMarked = LA.newMatrix();
             fromParentMarked = LA.newMatrix();
         }
@@ -5572,12 +5574,23 @@
     boolean NeedSupport()
     {
         return
-                CameraPane.SUPPORT && (!CameraPane.movingcamera || !Globals.FREEZEONMOVE) && link2master && /*live &&*/ support != null
+                CameraPane.SUPPORT && (!CameraPane.movingcamera || (!Globals.FREEZEONMOVE && Globals.isLIVE())) && link2master && /*live &&*/ support != null
                  // PROBLEM with CROWD!!
                     && (Globals.DrawMode() == iCameraPane.SHADOW || !Globals.RENDERSHADOW || Globals.CROWD);
     }
     
     static boolean DEBUG_SELECTION = false;
+    
+    boolean IsLive()
+    {
+        if (live)
+            return true;
+        
+        if (parent == null)
+            return false;
+        
+        return parent.IsLive();
+    }
     
     void Draw(iCameraPane display, Object3D /*Composite*/ root, boolean selected, boolean blocked)
     {
@@ -5640,7 +5653,7 @@
             support = support;
         
         //boolean usecalllists = IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null || !link2master); // !(this instanceof cSpring) && !(this instanceof BezierPatch);
-        boolean usecalllists = false; // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
+        boolean usecalllists = IsLive(); // IsStatic() && GetBRep() != null && (!CameraPane.SUPPORT || support == null) && !link2master; // !(this instanceof cSpring) && !(this instanceof BezierPatch);
         
         if (!usecalllists && bRep != null && bRep.displaylist > 0)
         {

--
Gitblit v1.6.2