From 29d5516687020263d3ae0454ce81879a3a450af0 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Thu, 01 Aug 2019 00:20:18 -0400
Subject: [PATCH] Min shader option.

---
 ObjEditor.java |  429 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 312 insertions(+), 117 deletions(-)

diff --git a/ObjEditor.java b/ObjEditor.java
index 5d7d1bb..3b8dd95 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -41,64 +41,78 @@
     JFrame frame;
     
     static ObjEditor theFrame;
+
+    public cGridBag GetSeparator()
+    {
+        cGridBag separator = new cGridBag();
+        separator.add(new JSeparator());
+        separator.preferredHeight = 5;
+        return separator;
+    }
     
     cButton GetButton(String name, boolean border)
     {
-        try
-        {
-            ImageIcon icon = GetIcon(name);
-            return new cButton(icon, border);
-        }
-        catch (Exception e)
-        {
-            return new cButton(name, border);
-        }
+        ImageIcon icon = GetIcon(name);
+        return new cButton(icon, border);
+    }
+
+    cLabel GetLabel(String name, boolean border)
+    {
+        //ImageIcon icon = GetIcon(name);
+        return new cLabel(GetImage(name), border);
     }
 
     cToggleButton GetToggleButton(String name, boolean border)
     {
-        try
-        {
-            ImageIcon icon = GetIcon(name);
-            return new cToggleButton(icon, border);
-        }
-        catch (Exception e)
-        {
-            return new cToggleButton(name, border);
-        }
+        ImageIcon icon = GetIcon(name);
+        return new cToggleButton(icon, border);
     }
 
     cCheckBox GetCheckBox(String name, boolean border)
     {
+        ImageIcon icon = GetIcon(name);
+        return new cCheckBox(icon, border);
+    }
+
+    ImageIcon GetIcon(String name)
+    {
         try
         {
-            ImageIcon icon = GetIcon(name);
-            return new cCheckBox(icon, border);
+            BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
+
+//            if (image.getWidth() > 48 && image.getHeight() > 48)
+//            {
+//                BufferedImage resized = new BufferedImage(48, 48, image.getType());
+//                Graphics2D g = resized.createGraphics();
+//                g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+//                //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+//                g.drawImage(image, 0, 0, 48, 48, 0, 0, image.getWidth(), image.getHeight(), null);
+//                g.dispose();
+//
+//                image = resized;
+//            }
+
+            javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
+            return icon;
         }
         catch (Exception e)
         {
-            return new cCheckBox(name, border);
+            return null;
         }
     }
-
-    private ImageIcon GetIcon(String name) throws IOException
+    
+    BufferedImage GetImage(String name)
     {
-        BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
-        
-        if (image.getWidth() != 24 && image.getHeight() != 24)
+        try
         {
-            BufferedImage resized = new BufferedImage(24, 24, image.getType());
-            Graphics2D g = resized.createGraphics();
-            g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
-            //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-            g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
-            g.dispose();
-            
-            image = resized;
+            BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
+
+            return image;
         }
-        
-        javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
-        return icon;
+        catch (Exception e)
+        {
+            return null;
+        }
     }
     
     // SCRIPT
@@ -282,6 +296,12 @@
         client = inClient;
         copy = client;
 
+        if (copy.versions == null)
+        {
+            copy.versions = new byte[100][];
+            copy.versionindex = -1;
+        }
+        
         // "this" is not called: SetupUI2(objEditor);
     }
 
@@ -295,6 +315,12 @@
         client = inClient;
         copy = client;
 
+        if (copy.versions == null)
+        {
+            copy.versions = new byte[100][];
+            copy.versionindex = -1;
+        }
+        
         SetupUI2(callee.GetEditor());
     }
 
@@ -327,6 +353,12 @@
         copy = localCopy;
         copy.editWindow = this;
 
+        if (copy.versions == null)
+        {
+//            copy.versions = new byte[100][];
+//            copy.versionindex = -1;
+        }
+        
         SetupMenu();
 
         //SetupName(objEditor); // new
@@ -419,11 +451,12 @@
     
         toolbarPanel = new JPanel();
         toolbarPanel.setName("Toolbar");
+        
         treePanel = new cGridBag();
         treePanel.setName("Tree");
         
         editPanel = new cGridBag().setVertical(true);
-        editPanel.setName("Edit");
+        //editPanel.setName("Edit");
         
         ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout());
         
@@ -431,11 +464,11 @@
         editPanel.add(editCommandsPanel);
         editPanel.add(ctrlPanel);
                 
-        toolboxPanel = new cGridBag().setVertical(false);
-        toolboxPanel.setName("Toolbox");
+        toolboxPanel = new cGridBag().setVertical(true);
+        //toolboxPanel.setName("Toolbox");
         
         materialPanel = new cGridBag().setVertical(true);
-        materialPanel.setName("Material");
+        //materialPanel.setName("Material");
         
         /*JTextPane*/
         infoarea = createTextPane();
@@ -443,6 +476,7 @@
 
         infoarea.setEditable(true);
         SetText();
+        
 //            infoarea.setFont(infoarea.getFont().deriveFont(10, 14f));
 //            infoarea.setOpaque(false);
 //            //infoarea.setForeground(textcolor);
@@ -450,7 +484,7 @@
 // TEXTAREA           infoarea.setWrapStyleWord(true);
         infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
         infoPanel.setPreferredSize(new Dimension(1, 1));
-        infoPanel.setName("Info");
+        //infoPanel.setName("Info");
         //infoPanel.setLayout(new BorderLayout());
         //infoPanel.add(createTextPane());
 
@@ -816,6 +850,28 @@
             frame.validate();
         }
 
+    private byte[] CompressCopy()
+    {
+        boolean temp = CameraPane.SWITCH;
+        CameraPane.SWITCH = false;
+        
+        copy.ExtractBigData(versiontable);
+        // if (copy == client)
+        
+        byte[] versions[] = copy.versions;
+        copy.versions = null;
+        
+        byte[] compress = Compress(copy);
+        
+        copy.versions = versions;
+        
+        copy.RestoreBigData(versiontable);
+        
+        CameraPane.SWITCH = temp;
+        
+        return compress;
+    }
+
     private JTextPane createTextPane()
     {
 // TEXTAREA       String[] initString =
@@ -946,7 +1002,7 @@
 //    NumberSlider vDivsField;
 //    JCheckBox endcaps;
     JCheckBox liveCB;
-    JCheckBox selectCB;
+    JCheckBox selectableCB;
     JCheckBox hideCB;
     JCheckBox link2masterCB;
     JCheckBox markCB;
@@ -1158,13 +1214,16 @@
             
         liveCB = AddCheckBox(setupPanel, "Live", copy.live);
                 liveCB.setToolTipText("Animate object");
-        selectCB = AddCheckBox(setupPanel, "Select", !copy.dontselect);
-                selectCB.setToolTipText("Make object selectable");
+        selectableCB = AddCheckBox(setupPanel, "Select", !copy.dontselect);
+                selectableCB.setToolTipText("Make object selectable");
 //            Return();
+                
         hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
                 hideCB.setToolTipText("Hide object");
         markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
         markCB.setToolTipText("As animation target transform");
+        
+        ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
         
             setupPanel2 = new cGridBag().setVertical(false);
             
@@ -1174,10 +1233,11 @@
         randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
         randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
 
+        link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
+        link2masterCB.setToolTipText("Attach to support");
+        
         if (Globals.ADVANCED)
         {
-                link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
-                link2masterCB.setToolTipText("Attach to support");
                 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
                 speedupCB.setToolTipText("Option motion capture");
         }
@@ -1451,6 +1511,7 @@
         XYZPanel.addComponent(/*BorderLayout.SOUTH,*/sideView); // Scroll);
         XYZPanel.addComponent(/*BorderLayout.CENTER,*/frontView); // Scroll);
         XYZPanel.addComponent(/*BorderLayout.NORTH,*/topView); // Scroll);
+        //XYZPanel.setName("XYZ");
 
         /*
         gridPanel = new JPanel(); //new BorderLayout());
@@ -1488,16 +1549,29 @@
         //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
         //tmp.setName("Edit");
         objectPanel.add(materialPanel);
+        objectPanel.setIconAt(0, GetIcon("icons/material.png"));
+        objectPanel.setToolTipTextAt(0, "Material panel");
+    
 //        JPanel north = new JPanel(new BorderLayout());
 //        north.setName("Edit");
 //        north.add(ctrlPanel, BorderLayout.NORTH);
 //        objectPanel.add(north);
         objectPanel.add(editPanel);
+        objectPanel.setIconAt(1, GetIcon("icons/write.png"));
+        objectPanel.setToolTipTextAt(1, "Edit panel");
         
         //if (Globals.ADVANCED)
             objectPanel.add(infoPanel);
+        objectPanel.setIconAt(2, GetIcon("icons/info.png"));
+        objectPanel.setToolTipTextAt(2, "Info panel");
+        
+        objectPanel.add(XYZPanel);
+        objectPanel.setIconAt(3, GetIcon("icons/XYZ.png"));
+        objectPanel.setToolTipTextAt(3, "XYZ/RGB panel");
         
         objectPanel.add(toolboxPanel);
+        objectPanel.setIconAt(4, GetIcon("icons/primitives.png"));
+        objectPanel.setToolTipTextAt(4, "Objects/backgrounds panel");
 
         /*
         aConstraints.gridx = 0;
@@ -1518,7 +1592,7 @@
         scrollpane.addMouseWheelListener(this); // Default not fast enough
 
         /*JTabbedPane*/ scenePanel = new cGridBag();
-        scenePanel.preferredWidth = 6;
+        scenePanel.preferredWidth = 5;
         
         JTabbedPane tabbedPane = new JTabbedPane();
         tabbedPane.add(scrollpane);
@@ -1596,7 +1670,7 @@
         bigThree = new cGridBag();
         bigThree.addComponent(scenePanel);
         bigThree.addComponent(centralPanel);
-        bigThree.addComponent(XYZPanel);
+        //bigThree.addComponent(XYZPanel);
         
 //                // SIDE EFFECT!!!
 //		aConstraints.gridx = 0;
@@ -1637,7 +1711,6 @@
         frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
         frame.addWindowListener(new WindowAdapter()
         {
-
             public void windowClosing(WindowEvent e)
             {
                 Close();
@@ -1699,27 +1772,48 @@
         //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
 
         cGridBag colorSection = new cGridBag().setVertical(true);
+
+        cGridBag huepanel = new cGridBag();
+            cGridBag huelabel = new cGridBag();
+            huelabel.add(GetLabel("icons/hue.png", false));
+            huelabel.preferredWidth = 20;
+            huepanel.add(new cGridBag()); // Label
+            huepanel.add(huelabel); // Field/slider
+            
+        huepanel.preferredHeight = 7;
+
+        colorSection.add(huepanel);
         
         cGridBag color = new cGridBag();
-                color.add(colorLabel = new JLabel("Color/hue")); // , aConstraints);
-                colorLabel.setHorizontalAlignment(SwingConstants.TRAILING);
-                color.add(colorField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
+        
+            color.add(colorLabel = new JLabel("Color/hue")); // , aConstraints);
+            colorLabel.setHorizontalAlignment(SwingConstants.TRAILING);
+            color.add(colorField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
+
         //colorField.preferredWidth = 200;
         colorSection.add(color);
 
         cGridBag modulation = new cGridBag();
                 modulation.add(modulationLabel = new JLabel("Saturation")); // , aConstraints);
                 modulationLabel.setHorizontalAlignment(SwingConstants.TRAILING);
-                modulation.add(modulationField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
+                modulation.add(modulationField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
         colorSection.add(modulation);
 
+        cGridBag opacity = new cGridBag();
+                opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
+                opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
+                opacity.add(opacityField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
+        colorSection.add(opacity);
+
+        colorSection.add(GetSeparator());
+        
         cGridBag texture = new cGridBag();
                 texture.add(textureLabel = new JLabel("Texture")); // , aConstraints);
                 textureLabel.setHorizontalAlignment(SwingConstants.TRAILING);
                 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
         colorSection.add(texture);
 
-        panel.add(new JSeparator());
+        panel.add(GetSeparator());
         
         panel.add(colorSection);
         
@@ -1775,7 +1869,7 @@
                 shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
         diffuseSection.add(shadowbias);
 
-        panel.add(new JSeparator());
+        panel.add(GetSeparator());
         
         panel.add(diffuseSection);
         
@@ -1838,7 +1932,7 @@
         specularSection.add(anisoV);
 
 
-        panel.add(new JSeparator());
+        panel.add(GetSeparator());
         
         panel.add(specularSection);
         
@@ -1863,12 +1957,6 @@
                 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
                 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
         colorSection.add(backlit);
-
-        cGridBag opacity = new cGridBag();
-                opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
-                opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
-                opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
-        colorSection.add(opacity);
 
         //panel.add(new JSeparator());
         
@@ -1914,7 +2002,7 @@
                 opacityPower.add(opacityPowerField = new cNumberSlider(this, 0.0, 10 /*10 dec 2013*/)); // , aConstraints);
         textureSection.add(opacityPower);
 
-        panel.add(new JSeparator());
+        panel.add(GetSeparator());
         
         panel.add(textureSection);
         
@@ -3213,7 +3301,7 @@
         {
             copy.live ^= true;
             return;
-        } else if (event.getSource() == selectCB)
+        } else if (event.getSource() == selectableCB)
         {
             copy.dontselect ^= true;
             return;
@@ -3480,8 +3568,8 @@
         try
         {
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
-            ObjectOutputStream out = new ObjectOutputStream(zstream);
+//            java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
+            ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
 
         Object3D parent = o.parent;
         o.parent = null;
@@ -3492,10 +3580,14 @@
         
             out.flush();
 
-            zstream.close();
+            baos //zstream
+                    .close();
             out.close();
             
-            return baos.toByteArray();
+            byte[] bytes = baos.toByteArray();
+            
+        System.out.println("save #bytes = " + bytes.length);
+            return bytes;
         } catch (Exception e)
         {
             System.err.println(e);
@@ -3505,13 +3597,16 @@
 
     static public Object Uncompress(byte[] bytes)
     {
-        System.out.println("#bytes = " + bytes.length);
+        System.out.println("restore #bytes = " + bytes.length);
         try
         {
             ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
-            java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
-            ObjectInputStream in = new ObjectInputStream(istream);
+            //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
+            ObjectInputStream in = new ObjectInputStream(bais); // istream);
             Object obj = in.readObject();
+            
+            bais //istream
+                    .close();
             in.close();
             
             return obj;
@@ -3566,12 +3661,11 @@
         return null;
     }
     
-    java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
     
     public void Save()
     {
-        // Default reduces the probability of heuristics errors.
-        Save(true);
+        //Save(true);
+        Replace();
     }
     
     private boolean Equal(byte[] compress, byte[] name)
@@ -3590,25 +3684,20 @@
         return true;
     }
 
+    java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
+    
     public boolean Save(boolean user)
     {
         System.err.println("Save");
         
         cRadio tab = GetCurrentTab();
         
-        boolean temp = CameraPane.SWITCH;
-        CameraPane.SWITCH = false;
-        
-        copy.ExtractBigData(hashtable);
-        
-        byte[] compress = Compress(copy);
-
-        CameraPane.SWITCH = temp;
+        byte[] compress = CompressCopy(); // Saved version. No need for "Replace".
         
         boolean thesame = false;
         
         // Quick heuristic using length. Works only when stream is compressed.
-        if (tab.undoindex > 0 && tab.graphs[tab.undoindex-1] != null && Equal(compress, tab.graphs[tab.undoindex-1]))
+        if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
         {
             thesame = true;
         }
@@ -3616,18 +3705,23 @@
         //EditorFrame.m_MainFrame.requestFocusInWindow();
         if (!thesame)
         {
-            tab.user[tab.undoindex] = user;
-            tab.graphs[tab.undoindex++] = compress;
+            //tab.user[tab.versionindex] = user;
+            //boolean increment = true; // tab.graphs[tab.versionindex] == null;
+            
+            copy.versions[++copy.versionindex] = compress;
+            
+            // if (increment)
+            //     tab.versionindex++;
         }
 
-        copy.RestoreBigData(hashtable);
+        //copy.RestoreBigData(versiontable);
 
         //assert(hashtable.isEmpty());
         
-        for (int i = tab.undoindex; i < tab.graphs.length; i++)
+        for (int i = copy.versionindex+1; i < copy.versions.length; i++)
         {
-            tab.user[i] = false;
-            tab.graphs[i] = null;
+            //tab.user[i] = false;
+            copy.versions[i] = null;
         }
 
         SetUndoStates();
@@ -3637,7 +3731,7 @@
         {
             try
             {
-                FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
+                FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
                 ObjectOutputStream p = new ObjectOutputStream(ostream);
 
                 p.writeObject(copy);
@@ -3661,16 +3755,19 @@
         boolean temp = CameraPane.SWITCH;
         CameraPane.SWITCH = false;
         
-        copy.ExtractBigData(hashtable);
+        copy.ExtractBigData(versiontable);
         
         copy.clear();
         
+        copy.skyboxname = obj.skyboxname;
+        copy.skyboxext = obj.skyboxext;
+                
         for (int i=0; i<obj.Size(); i++)
         {
             copy.add(obj.get(i));
         }
         
-        copy.RestoreBigData(hashtable);
+        copy.RestoreBigData(versiontable);
         
         CameraPane.SWITCH = temp;
         
@@ -3698,64 +3795,129 @@
     }
     
     cButton undoButton;
+    cButton restoreButton;
+    cButton replaceButton;
     cButton redoButton;
         
+    boolean muteSlider;
+    
+    int VersionCount()
+    {
+        int count = 0;
+        
+        for (int i = copy.versions.length; --i >= 0;)
+        {
+            if (copy.versions[i] != null)
+                count++;
+        }
+        
+        return count;
+    }
+    
     void SetUndoStates()
     {
         cRadio tab = GetCurrentTab();
         
-        undoButton.setEnabled(tab.undoindex > 0);
-        redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
+        restoreButton.setEnabled(copy.versionindex != -1);
+        replaceButton.setEnabled(copy.versionindex != -1);
+        
+        undoButton.setEnabled(copy.versionindex > 0);
+        redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
+        
+        muteSlider = true;
+        versionSlider.setMaximum(VersionCount() - 1);
+        versionSlider.setInteger(copy.versionindex);
+        muteSlider = false;
     }
     
     public boolean Undo()
     {
+        // Option?
+        Replace();
+        
         System.err.println("Undo");
         
         cRadio tab = GetCurrentTab();
         
-        if (tab.undoindex == 0)
+        if (copy.versionindex == 0)
         {
             java.awt.Toolkit.getDefaultToolkit().beep();
             return false;
         }
 
-        if (tab.graphs[tab.undoindex] == null || !tab.user[tab.undoindex])
+//        if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex])
+//        {
+//            if (Save(false))
+//                tab.versionindex -= 1;
+//            else
+//            {
+//                if (tab.versionindex <= 0)
+//                    return false;
+//                else
+//                    tab.versionindex -= 1;
+//            }
+//        }
+
+        copy.versionindex -= 1;
+
+        CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
+        
+        return true;
+    }
+
+    public boolean Restore()
+    {
+        System.err.println("Restore");
+        
+        cRadio tab = GetCurrentTab();
+        
+        if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
         {
-            if (Save(false))
-                tab.undoindex -= 1;
-            else
-            {
-                if (tab.undoindex <= 0)
-                    return false;
-                else
-                    tab.undoindex -= 1;
-            }
+            java.awt.Toolkit.getDefaultToolkit().beep();
+            return false;
         }
 
-        tab.undoindex -= 1;
+        CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
+        
+        return true;
+    }
 
-        CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
+    public boolean Replace()
+    {
+        System.err.println("Replace");
+        
+        cRadio tab = GetCurrentTab();
+        
+        if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
+        {
+            // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
+            return false;
+        }
+
+        copy.versions[copy.versionindex] = CompressCopy();
         
         return true;
     }
 
     public void Redo()
     {
+        // Option?
+        Replace();
+        
         cRadio tab = GetCurrentTab();
         
-        if (tab.graphs[tab.undoindex + 1] == null)
+        if (copy.versions[copy.versionindex + 1] == null)
         {
             java.awt.Toolkit.getDefaultToolkit().beep();
             return;
         }
 
-        tab.undoindex += 1;
+        copy.versionindex += 1;
 
-        CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
+        CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
         
-        if (!tab.user[tab.undoindex])
-            tab.graphs[tab.undoindex] = null;
+        //if (!tab.user[tab.versionindex])
+        //    tab.graphs[tab.versionindex] = null;
     }
 
         void ImportGFD()
@@ -4051,9 +4213,25 @@
         //copy.Touch();
     }
 
+    cNumberSlider versionSlider;
+    
     public void stateChanged(ChangeEvent e)
     {
         //    assert(false);
+        if (e.getSource() == versionSlider)
+        {
+            if (muteSlider)
+                return;
+            
+            int version = versionSlider.getInteger();
+            
+            if (copy.versions[version] != null)
+            {
+                CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
+            }
+            
+            return;
+        }
 
         if (freezematerial)
         {
@@ -4402,7 +4580,7 @@
 
     void makeSomething(Object3D thing, boolean resetmodel) // deselect)
     {
-        if (Globals.SAVEONMAKE) // && resetmodel)
+        if (Globals.REPLACEONMAKE) // && resetmodel)
             Save();
         //Tween.set(thing, 0).target(1).start(tweenManager);
         //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
@@ -4644,7 +4822,9 @@
             readobj.ResetDisplayList();
         } catch (Exception e)
         {
-            //e.printStackTrace();
+            if (!e.toString().contains("GZIP"))
+                e.printStackTrace();
+            
             try
             {
                 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
@@ -4718,12 +4898,14 @@
         
         if (readobj != null)
         {
-        if (Globals.SAVEONMAKE)
-            Save();
+        //if (Globals.SAVEONMAKE) // A new object cannot share meshes
+        //    Save();
             try
             {
                 //readobj.deepCopySelf(copy);
                 copy.clear(); // june 2014
+                copy.skyboxname = readobj.skyboxname;
+                copy.skyboxext = readobj.skyboxext;
                 for (int i = 0; i < readobj.size(); i++)
                 {
                     Object3D child = readobj.get(i); // reserve(i);
@@ -4764,6 +4946,7 @@
                 }
             } catch (ClassCastException e)
             {
+                e.printStackTrace();
                 assert (false);
                 Composite c = (Composite) copy;
                 c.children.clear();
@@ -4774,6 +4957,17 @@
                 c.addChild(csg);
             }
 
+            copy.versions = readobj.versions;
+            copy.versionindex = readobj.versionindex;
+            
+        if (copy.versions == null)
+        {
+            copy.versions = new byte[100][];
+            copy.versionindex = -1;
+        }
+        
+            //? SetUndoStates();
+            
             ResetModel();
             copy.HardTouch(); // recompile?
             refreshContents();
@@ -4883,6 +5077,7 @@
             //ps.print(buffer.toString());
         } catch (IOException e)
         {
+            e.printStackTrace();
         }
     }
     

--
Gitblit v1.6.2