From 24a2a946b35279605e645349bd6b82e9e60aac88 Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Wed, 14 Aug 2019 23:35:34 -0400
Subject: [PATCH] Fix textures in jar.

---
 ObjEditor.java | 1081 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 928 insertions(+), 153 deletions(-)

diff --git a/ObjEditor.java b/ObjEditor.java
index b1bbdf6..9f18912 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -34,6 +34,7 @@
         iSendInfo
 //KeyListener
 {
+    public cToggleButton pinButton;
         boolean timeline;
         boolean wasFullScreen;
 
@@ -41,64 +42,90 @@
     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);
+    }
+
+    static java.util.Hashtable<String, javax.swing.ImageIcon> icons = new java.util.Hashtable<String, javax.swing.ImageIcon>();
+    
+    ImageIcon GetIcon(String name)
+    {
+        javax.swing.ImageIcon iconCache = icons.get(name);
+        if (iconCache != null)
+        {
+            return iconCache;
+        }
+        
         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);
+            
+            icons.put(name, icon);
+            
+            return icon;
         }
         catch (Exception e)
         {
-            return new cCheckBox(name, border);
+            //icons.put(name, null);
+            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 +309,14 @@
         client = inClient;
         copy = client;
 
+//        if (copy.versionlist == null)
+//        {
+//            copy.versionlist = new Object3D[100];
+//            copy.versionindex = -1;
+//            
+//            callee.Save(true);
+//        }
+        
         // "this" is not called: SetupUI2(objEditor);
     }
 
@@ -295,6 +330,14 @@
         client = inClient;
         copy = client;
 
+        if (copy.versionlist == null)
+        {
+            copy.versionlist = new Object3D[100];
+            copy.versionindex = -1;
+            
+//            Save(true);
+        }
+        
         SetupUI2(callee.GetEditor());
     }
 
@@ -327,6 +370,14 @@
         copy = localCopy;
         copy.editWindow = this;
 
+//        if (copy.versionlist == null)
+//        {
+//            copy.versionlist = new Object3D[100];
+//            copy.versionindex = -1;
+//            
+//            Save(true);
+//        }
+        
         SetupMenu();
 
         //SetupName(objEditor); // new
@@ -394,6 +445,8 @@
         
         ChangeListener changeListener = new ChangeListener()
         {
+            //String name;
+            
             public void stateChanged(ChangeEvent changeEvent)
             {
 //                if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Material") && !materialFlushed)
@@ -412,18 +465,49 @@
 //                        EditSelection(false);
 //                }
 
-                refreshContents(false); // To refresh Info tab
+//                if (objectPanel.getSelectedIndex() == 4)
+//                {
+//                    name = copy.skyboxname;
+//                    
+//                    if (name == null)
+//                    {
+//                        name = "";
+//                    }
+//                    
+//                    copy.skyboxname = "cubemaps/default-skyboxes/rgb";
+//                    copy.skyboxext = "jpg";
+//                }
+//                else
+//                {
+//                    if (name != null)
+//                    {
+//                        if (name.equals(""))
+//                        {
+//                            copy.skyboxname = null;
+//                            copy.skyboxext = null;
+//                        }
+//                        else
+//                        {
+//                            copy.skyboxname = name;
+//                        }
+//                    }
+//                }
+                cameraView.transformMode = objectPanel.getSelectedIndex() == 4;
+                
+//                refreshContents(false); // To refresh Info tab
+                cameraView.repaint();
             }
         };
         objectPanel.addChangeListener(changeListener);
     
         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 +515,13 @@
         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");
+        skyboxPanel = new cGridBag().setVertical(true);
+        
+        materialPanel = new cGridBag().setVertical(false);
+        //materialPanel.setName("Material");
         
         /*JTextPane*/
         infoarea = createTextPane();
@@ -443,6 +529,7 @@
 
         infoarea.setEditable(true);
         SetText();
+        
 //            infoarea.setFont(infoarea.getFont().deriveFont(10, 14f));
 //            infoarea.setOpaque(false);
 //            //infoarea.setForeground(textcolor);
@@ -450,7 +537,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());
 
@@ -717,6 +804,7 @@
         boolean maximized;
     
         cButton fullscreenLayout;
+        cButton expandedLayout;
 
         void Minimize()
         {
@@ -756,10 +844,12 @@
 	cButton minButton;
 	cButton maxButton;
 	cButton fullButton;
+	cButton collapseButton;
+        cButton maximize3DButton;
         
         void ToggleFullScreen()
         {
-GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
+            GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
 
                 cameraView.ToggleFullScreen();
                 
@@ -780,13 +870,13 @@
 // X                   frame.getContentPane().remove(/*"Center",*/bigThree);
 // X                   framePanel.add(bigThree);
 // X                   frame.getContentPane().add(/*"Center",*/framePanel);
-                    framePanel.setDividerLocation(46);
+//                    framePanel.setDividerLocation(46); // icons are 24x24
                     
                     //frame.setVisible(true);
-                    radio.layout = keepButton;
+//                    radio.layout = keepButton;
                     //theFrame = null;
                     keepButton = null;
-                    radio.layout.doClick();
+//                    radio.layout.doClick();
                     
                 } else
                 {
@@ -807,14 +897,47 @@
 // X                   frame.getContentPane().remove(/*"Center",*/framePanel);
 // X                   framePanel.remove(bigThree);
 // X                   frame.getContentPane().add(/*"Center",*/bigThree);
-                    framePanel.setDividerLocation(0);
+//                    framePanel.setDividerLocation(0);
 
-                    radio.layout = fullscreenLayout;
-                    radio.layout.doClick();
+//                    radio.layout = fullscreenLayout;
+//                    radio.layout.doClick();
                     //frame.setVisible(true);
                 }
             frame.validate();
+            
+            cameraView.requestFocusInWindow();
         }
+
+        void CollapseToolbar()
+        {
+            framePanel.setDividerLocation(0);
+            //frame.validate();
+            
+            cameraView.requestFocusInWindow();
+        }
+        
+    private Object3D Duplicate(Object3D object)
+    {
+        boolean temp = CameraPane.SWITCH;
+        CameraPane.SWITCH = false;
+        
+        object.ExtractBigData(versiontable);
+        // if (copy == client)
+        
+        Object3D versions[] = object.versionlist;
+        object.versionlist = null;
+        
+        //byte[] compress = Compress(copy);
+        Object3D compress = (Object3D)Grafreed.clone(object);
+        
+        object.versionlist = versions;
+        
+        object.RestoreBigData(versiontable);
+        
+        CameraPane.SWITCH = temp;
+        
+        return compress;
+    }
 
     private JTextPane createTextPane()
     {
@@ -937,6 +1060,7 @@
         {
             SetupMaterial(materialPanel);
         }
+        
         //SetupName();
         //SetupViews();
     }
@@ -946,7 +1070,7 @@
 //    NumberSlider vDivsField;
 //    JCheckBox endcaps;
     JCheckBox liveCB;
-    JCheckBox selectCB;
+    JCheckBox selectableCB;
     JCheckBox hideCB;
     JCheckBox link2masterCB;
     JCheckBox markCB;
@@ -1145,6 +1269,18 @@
         
             namePanel = new cGridBag();
             
+        //if (copy.pinned)
+        {
+            pinButton = GetToggleButton("icons/pin.png", !Grafreed.NIMBUSLAF);
+            pinButton.setSelected(copy.pinned);
+            cGridBag t = new cGridBag();
+            t.preferredWidth = 2;
+            t.add(pinButton);
+            namePanel.add(t);
+            
+            pinButton.addItemListener(this);
+        }
+        
         nameField = AddText(namePanel, copy.GetName());
         namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
         oe.ctrlPanel.add(namePanel);
@@ -1158,13 +1294,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);
             
@@ -1452,6 +1591,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());
@@ -1489,17 +1629,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");
+    
+        objectPanel.add(toolboxPanel);
+        objectPanel.setIconAt(1, GetIcon("icons/primitives.png"));
+        objectPanel.setToolTipTextAt(1, "Objects & textures");
+
+        objectPanel.add(skyboxPanel);
+        objectPanel.setIconAt(2, GetIcon("icons/skybox.jpg"));
+        objectPanel.setToolTipTextAt(2, "Backgrounds");
+        
 //        JPanel north = new JPanel(new BorderLayout());
 //        north.setName("Edit");
 //        north.add(ctrlPanel, BorderLayout.NORTH);
 //        objectPanel.add(north);
         objectPanel.add(editPanel);
+        objectPanel.setIconAt(3, GetIcon("icons/write.png"));
+        objectPanel.setToolTipTextAt(3, "Edit controls");
         
-        //if (Globals.ADVANCED)
-            objectPanel.add(infoPanel);
+        objectPanel.add(XYZPanel);
+        objectPanel.setIconAt(4, GetIcon("icons/XYZ.png"));
+        objectPanel.setToolTipTextAt(4, "XYZ/RGB transform");
         
-        objectPanel.add(toolboxPanel);
-
         /*
         aConstraints.gridx = 0;
         aConstraints.gridwidth = 1;
@@ -1519,7 +1671,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);
@@ -1536,6 +1688,11 @@
 
         scenePanel.add(tabbedPane);
 
+        //if (Globals.ADVANCED)
+//            tabbedPane.add(infoPanel);
+//        tabbedPane.setIconAt(3, GetIcon("icons/info.png"));
+//        tabbedPane.setToolTipTextAt(3, "Information");
+        
         /*
         cTree jTree = new cTree(null);
         ToolTipManager.sharedInstance().registerComponent(jTree);
@@ -1597,7 +1754,7 @@
         bigThree = new cGridBag();
         bigThree.addComponent(scenePanel);
         bigThree.addComponent(centralPanel);
-        bigThree.addComponent(XYZPanel);
+        //bigThree.addComponent(XYZPanel);
         
 //                // SIDE EFFECT!!!
 //		aConstraints.gridx = 0;
@@ -1606,6 +1763,23 @@
 //		aConstraints.gridheight = 1;
 
         framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
+        
+        framePanel.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY,
+                new java.beans.PropertyChangeListener()
+                {
+                    public void propertyChange(java.beans.PropertyChangeEvent pce)
+                    {
+                        if ((Integer)pce.getOldValue() == 1)
+                        {
+                            if (radio.layout != expandedLayout)
+                            {
+                                radio.layout = expandedLayout;
+                                radio.layout.doClick();
+                            }
+                        }
+                    }
+                });
+
         framePanel.setContinuousLayout(false);
         framePanel.setOneTouchExpandable(false);
         //.setDividerLocation(0.8);
@@ -1615,7 +1789,7 @@
 
         frame.getContentPane().setLayout(new BorderLayout());
         /**/
-        JTabbedPane worldPane = new JTabbedPane();
+        //JTabbedPane worldPane = new JTabbedPane();
         //worldPane.add(bigPanel);
         //worldPane.add(worldPanel);
                 /**/
@@ -1638,7 +1812,6 @@
         frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
         frame.addWindowListener(new WindowAdapter()
         {
-
             public void windowClosing(WindowEvent e)
             {
                 Close();
@@ -1661,12 +1834,403 @@
         ctrlPanel.removeAll();
     }
 
-    void SetupMaterial(cGridBag panel)
+    void SetupMaterial(cGridBag materialpanel)
     {
-         /*
+        cGridBag presetpanel = new cGridBag().setVertical(true);
+        
+        cLabel skin = GetLabel("icons/shadericons/shadericon00000.png", !Grafreed.NIMBUSLAF);
+        skin.setToolTipText("Skin");
+        skin.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[0].get(0);
+                cMaterial material = object.material;
+                
+                // Skin
+                colorField.setFloat(material.color);
+                saturationField.setFloat(material.modulation);
+                subsurfaceField.setFloat(material.subsurface);
+                selfshadowField.setFloat(material.diffuseness);
+                diffusenessField.setFloat(material.factor);
+                shininessField.setFloat(material.shininess);
+                shadowbiasField.setFloat(material.shadowbias);
+                diffuseField.setFloat(material.diffuse);
+                specularField.setFloat(material.specular);
+                
+                bumpField.setFloat(object.projectedVertices[0].x / 1000.0);
+                noiseField.setFloat(object.projectedVertices[0].y / 1000.0);
+                powerField.setFloat(object.projectedVertices[2].x / 1000.0);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(skin);
+        
+        cLabel lambert = GetLabel("icons/shadericons/shadericon00002.png", !Grafreed.NIMBUSLAF);
+        lambert.setToolTipText("Diffuse");
+        lambert.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[2].get(0);
+                cMaterial material = object.material;
+                
+                diffusenessField.setFloat(material.factor);
+                selfshadowField.setFloat(material.diffuseness);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(lambert);
+        
+        cLabel diffuse2 = GetLabel("icons/shadericons/shadericon00003.png", !Grafreed.NIMBUSLAF);
+        diffuse2.setToolTipText("Diffuse2");
+        diffuse2.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[3].get(0);
+                cMaterial material = object.material;
+                
+                diffusenessField.setFloat(material.factor);
+                selfshadowField.setFloat(material.diffuseness);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(diffuse2);
+        
+        cLabel diffusemoon = GetLabel("icons/shadericons/shadericon00004.png", !Grafreed.NIMBUSLAF);
+        diffusemoon.setToolTipText("Moon");
+        diffusemoon.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[4].get(0);
+                cMaterial material = object.material;
+                
+                diffusenessField.setFloat(material.factor);
+                selfshadowField.setFloat(material.diffuseness);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(diffusemoon);
+        
+        cLabel diffusemoon2 = GetLabel("icons/shadericons/shadericon00005.png", !Grafreed.NIMBUSLAF);
+        diffusemoon2.setToolTipText("Moon2");
+        diffusemoon2.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[5].get(0);
+                cMaterial material = object.material;
+                
+                diffusenessField.setFloat(material.factor);
+                selfshadowField.setFloat(material.diffuseness);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(diffusemoon2);
+        
+        cLabel diffusemoon3 = GetLabel("icons/shadericons/shadericon00006.png", !Grafreed.NIMBUSLAF);
+        diffusemoon3.setToolTipText("Moon3");
+        diffusemoon3.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[6].get(0);
+                cMaterial material = object.material;
+                
+                diffusenessField.setFloat(material.factor);
+                selfshadowField.setFloat(material.diffuseness);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(diffusemoon3);
+        
+        cLabel diffusesheen = GetLabel("icons/shadericons/shadericon00007.png", !Grafreed.NIMBUSLAF);
+        diffusesheen.setToolTipText("Sheen");
+        diffusesheen.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[7].get(0);
+                cMaterial material = object.material;
+                
+                sheenField.setFloat(material.sheen);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(diffusesheen);
+        
+        cLabel rough = GetLabel("icons/shadericons/shadericon00001.png", !Grafreed.NIMBUSLAF);
+        rough.setToolTipText("Rough metal");
+        rough.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[1].get(0);
+                cMaterial material = object.material;
+                
+                shininessField.setFloat(material.shininess);
+                velvetField.setFloat(material.velvet);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(rough);
+        
+        cLabel rough2 = GetLabel("icons/shadericons/shadericon00013.png", !Grafreed.NIMBUSLAF);
+        rough2.setToolTipText("Medium metal");
+        rough2.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[13].get(0);
+                cMaterial material = object.material;
+                
+                shininessField.setFloat(material.shininess);
+                lightareaField.setFloat(material.lightarea);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(rough2);
+        
+        cLabel shini0 = GetLabel("icons/shadericons/shadericon00014.png", !Grafreed.NIMBUSLAF);
+        shini0.setToolTipText("Shiny");
+        shini0.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[14].get(0);
+                cMaterial material = object.material;
+                
+                shininessField.setFloat(material.shininess);
+                lightareaField.setFloat(material.lightarea);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(shini0);
+        
+        cLabel shini1 = GetLabel("icons/shadericons/shadericon00011.png", !Grafreed.NIMBUSLAF);
+        shini1.setToolTipText("Shiny2");
+        shini1.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[11].get(0);
+                cMaterial material = object.material;
+                
+                shininessField.setFloat(material.shininess);
+                lightareaField.setFloat(material.lightarea);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(shini1);
+        
+        cLabel shini2 = GetLabel("icons/shadericons/shadericon00012.png", !Grafreed.NIMBUSLAF);
+        shini2.setToolTipText("Shiny3");
+        shini2.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[12].get(0);
+                cMaterial material = object.material;
+                
+                shininessField.setFloat(material.shininess);
+                lightareaField.setFloat(material.lightarea);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(shini2);
+        
+        cLabel aniso = GetLabel("icons/shadericons/shadericon00008.png", !Grafreed.NIMBUSLAF);
+        aniso.setToolTipText("AnisoU");
+        aniso.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[8].get(0);
+                cMaterial material = object.material;
+                
+                anisoField.setFloat(material.aniso);
+                anisoVField.setFloat(material.anisoV);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(aniso);
+        
+        cLabel aniso2 = GetLabel("icons/shadericons/shadericon00009.png", !Grafreed.NIMBUSLAF);
+        aniso2.setToolTipText("AnisoV");
+        aniso2.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[9].get(0);
+                cMaterial material = object.material;
+                
+                anisoField.setFloat(material.aniso);
+                anisoVField.setFloat(material.anisoV);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(aniso2);
+        
+        cLabel aniso3 = GetLabel("icons/shadericons/shadericon00010.png", !Grafreed.NIMBUSLAF);
+        aniso3.setToolTipText("AnisoUV");
+        aniso3.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[10].get(0);
+                cMaterial material = object.material;
+                
+                anisoField.setFloat(material.aniso);
+                anisoVField.setFloat(material.anisoV);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(aniso3);
+        
+        cLabel velvet0 = GetLabel("icons/shadericons/shadericon00015.png", !Grafreed.NIMBUSLAF);
+        velvet0.setToolTipText("Velvet");
+        velvet0.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[15].get(0);
+                cMaterial material = object.material;
+                
+                diffusenessField.setFloat(material.factor);
+                selfshadowField.setFloat(material.diffuseness);
+                sheenField.setFloat(material.sheen);
+                shininessField.setFloat(material.shininess);
+                velvetField.setFloat(material.velvet);
+                shiftField.setFloat(material.shift);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(velvet0);
+        
+        cLabel bump0 = GetLabel("icons/shadericons/shadericon00016.png", !Grafreed.NIMBUSLAF);
+        bump0.setToolTipText("Bump texture");
+        bump0.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[16].get(0);
+                cMaterial material = object.material;
+                
+                bumpField.setFloat(object.projectedVertices[0].x / 1000.0);
+                noiseField.setFloat(object.projectedVertices[0].y / 1000.0);
+                powerField.setFloat(object.projectedVertices[2].x / 1000.0);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(bump0);
+        
+        cLabel halo = GetLabel("icons/shadericons/shadericon00017.png", !Grafreed.NIMBUSLAF);
+        halo.setToolTipText("Halo");
+        halo.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[17].get(0);
+                cMaterial material = object.material;
+                
+                opacityPowerField.setFloat(object.projectedVertices[2].y / 1000.0);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(halo);
+        
+        cLabel candle = GetLabel("icons/shadericons/shadericon00018.png", !Grafreed.NIMBUSLAF);
+        candle.setToolTipText("Candle");
+        candle.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                Object3D object = Grafreed.materials.versionlist[18].get(0);
+                cMaterial material = object.material;
+                
+                subsurfaceField.setFloat(material.subsurface);
+                shadowbiasField.setFloat(material.shadowbias);
+                ambientField.setFloat(material.ambient);
+                specularField.setFloat(material.specular);
+                lightareaField.setFloat(material.lightarea);
+                shininessField.setFloat(material.shininess);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(candle);
+        
+        cLabel shadowShader = GetLabel("icons/shadericons/shadow.png", !Grafreed.NIMBUSLAF);
+        shadowShader.setToolTipText("Shadow");
+        shadowShader.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                diffuseField.setFloat(0.001);
+                ambientField.setFloat(0.001);
+                cameraField.setFloat(0.001);
+                specularField.setFloat(0.001);
+                fakedepthField.setFloat(0.001);
+                opacityField.setFloat(0.6);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(shadowShader);
+        
+        cGridBag panel = new cGridBag().setVertical(true);
+        
+        presetpanel.preferredWidth = 1;
+        
+        materialpanel.add(presetpanel);
+        materialpanel.add(panel);
+        
+        panel.preferredWidth = 8;
+        
+        /*
         ctrlPanel.add(materialLabel = new JLabel("MATERIAL : "), aConstraints);
         materialLabel.setHorizontalAlignment(SwingConstants.TRAILING);
-         */
+        */
 
         cGridBag editBar = new cGridBag().setVertical(false);
             
@@ -1700,27 +2264,50 @@
         //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
 
         cGridBag colorSection = new cGridBag().setVertical(true);
+
+        cGridBag huepanel = new cGridBag();
+            cGridBag huelabel = new cGridBag();
+        skin = GetLabel("icons/hue.png", false);
+        skin.fit = true;
+            huelabel.add(skin);
+            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(saturationField = 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);
         
@@ -1776,7 +2363,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);
         
@@ -1839,7 +2426,7 @@
         specularSection.add(anisoV);
 
 
-        panel.add(new JSeparator());
+        panel.add(GetSeparator());
         
         panel.add(specularSection);
         
@@ -1864,12 +2451,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());
         
@@ -1915,7 +2496,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);
         
@@ -2902,7 +3483,7 @@
 
         freezematerial = true;
         colorField.setFloat(mat.color);
-        modulationField.setFloat(mat.modulation);
+        saturationField.setFloat(mat.modulation);
         metalnessField.setFloat(mat.metalness);
         diffuseField.setFloat(mat.diffuse);
         specularField.setFloat(mat.specular);
@@ -3109,6 +3690,17 @@
     public void itemStateChanged(ItemEvent event)
     {
         //                   System.out.println("Propagate = " + propagate);
+        if (event.getSource() == pinButton)
+        {
+            copy.pinned ^= true;
+            if (!copy.pinned && !copy.editWindow.copy.selection.contains(copy))
+            {
+                ((GroupEditor)copy.editWindow).listUI.remove(copy);
+                copy.CloseUI();
+                //copy.editWindow.refreshContents();
+            }
+        }
+        else
         if (event.getSource() == propagateToggle)
         {
             propagate ^= true;
@@ -3213,8 +3805,9 @@
         } else if (event.getSource() == liveCB)
         {
             copy.live ^= true;
+            objEditor.refreshContents(true); // To show item colors
             return;
-        } else if (event.getSource() == selectCB)
+        } else if (event.getSource() == selectableCB)
         {
             copy.dontselect ^= true;
             return;
@@ -3222,7 +3815,7 @@
         {
             copy.hide ^= true;
             copy.Touch(); // display list issue
-            objEditor.refreshContents();
+            objEditor.refreshContents(true); // To show item colors
             return;
         } else if (event.getSource() == link2masterCB)
         {
@@ -3478,6 +4071,7 @@
     
     static public byte[] Compress(Object3D o)
     {
+        // Slower to actually compress.
         try
         {
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -3574,11 +4168,12 @@
         return null;
     }
     
-    java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
     
     public void Save()
     {
-        Save(true);
+        //Save(true);
+        Replace();
+        SetVersionStates();
     }
     
     private boolean Equal(byte[] compress, byte[] name)
@@ -3597,59 +4192,71 @@
         return true;
     }
 
+    java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
+    
+    void DeleteVersion()
+    {
+        for (int i = copy.versionindex; i < copy.versionlist.length-1; i++)
+        {
+            copy.versionlist[i] = copy.versionlist[i+1];
+        }
+        
+        CopyChanged();
+        
+        SetVersionStates();
+    }
+    
     public boolean Save(boolean user)
     {
         System.err.println("Save");
+        Replace();
         
-        cRadio tab = GetCurrentTab();
+        //cRadio tab = GetCurrentTab();
         
-        boolean temp = CameraPane.SWITCH;
-        CameraPane.SWITCH = false;
-        
-        copy.ExtractBigData(hashtable);
-        
-        byte[] compress = Compress(copy);
-
-        CameraPane.SWITCH = temp;
+        Object3D compress = Duplicate(copy); // 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]))
-        {
-            thesame = true;
-        }
+//        if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
+//        {
+//            thesame = true;
+//        }
         
         //EditorFrame.m_MainFrame.requestFocusInWindow();
         if (!thesame)
         {
-            //tab.user[tab.undoindex] = user;
-            boolean increment = tab.graphs[tab.undoindex] == null;
+            for (int i = copy.versionlist.length; --i > copy.versionindex+1;)
+            {
+                copy.versionlist[i] = copy.versionlist[i-1];
+            }
             
-            tab.graphs[tab.undoindex] = compress;
+            //tab.user[tab.versionindex] = user;
+            //boolean increment = true; // tab.graphs[tab.versionindex] == null;
             
-            if (increment)
-                tab.undoindex++;
+            copy.versionlist[++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++)
-        {
-            //tab.user[i] = false;
-        //    tab.graphs[i] = null;
-        }
+//        for (int i = copy.versionindex+1; i < copy.versionlist.length; i++)
+//        {
+//            //tab.user[i] = false;
+//            copy.versionlist[i] = null;
+//        }
 
-        SetUndoStates();
+        SetVersionStates();
         
         // test save
         if (false)
         {
             try
             {
-                FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
+                FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
                 ObjectOutputStream p = new ObjectOutputStream(ostream);
 
                 p.writeObject(copy);
@@ -3665,27 +4272,65 @@
         
         return !thesame;
     }
-
-    void CopyChanged(Object3D obj)
+    
+    boolean flashIt = true;
+        
+    void RefreshSelection()
     {
-        SetUndoStates();
+        Object3D selection = new Object3D();
+        
+        for (int i = 0; i < copy.selection.size(); i++)
+        {
+            Object3D elem = copy.selection.elementAt(i);
+            
+            Object3D obj = copy.GetObject(elem.GetUUID());
+            
+            if (obj == null)
+            {
+                copy.selection.remove(i--);
+            }
+            else
+            {
+                selection.add(obj);
+                copy.selection.setElementAt(obj, i);
+            }
+        }
+        
+        flashIt = false;        
+        GetTree().clearSelection();
+        for (int i = 0; i < selection.size(); i++)
+            GetTree().addSelectionPath(selection.elementAt(i).GetTreePath().GetTreePath());
+        flashIt = true;
+        
+        //refreshContents(false);
+    }
+
+    void CopyChanged()
+    {
+        Object3D obj = (Object3D)Grafreed.clone(copy.versionlist[copy.versionindex]);
+        
+        SetVersionStates();
         
         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;
         
+        RefreshSelection();
         //assert(hashtable.isEmpty());
         
         copy.Touch();
@@ -3706,68 +4351,144 @@
             }
         }
         
-        refreshContents();
+        refreshContents(true);
     }
     
-    cButton undoButton;
-    cButton redoButton;
+    cButton previousVersionButton;
+    cButton restoreButton;
+    cButton replaceButton;
+    cButton nextVersionButton;
+    cButton saveVersionButton;
+    cButton deleteVersionButton;
         
-    void SetUndoStates()
+    boolean muteSlider;
+    
+    int VersionCount()
     {
-        cRadio tab = GetCurrentTab();
+        int count = 0;
         
-        undoButton.setEnabled(tab.undoindex > 0);
-        redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
+        for (int i = copy.versionlist.length; --i >= 0;)
+        {
+            if (copy.versionlist[i] != null)
+                count++;
+        }
+        
+        return count;
     }
     
-    public boolean Undo()
+    void SetVersionStates()
     {
+        //if (true)
+        //    return;
+                    
+        //cRadio tab = GetCurrentTab();
+        
+        restoreButton.setEnabled(copy.versionindex != -1);
+        replaceButton.setEnabled(copy.versionindex != -1);
+        
+        previousVersionButton.setEnabled(copy.versionindex > 0);
+        nextVersionButton.setEnabled(copy.versionlist[copy.versionindex + 1] != null);
+        
+        deleteVersionButton.setEnabled(//copy.versionindex > 0 &&
+                                        copy.versionlist[copy.versionindex + 1] != null);
+        
+        muteSlider = true;
+        versionSlider.setMinimum(0);
+        versionSlider.setMaximum(VersionCount() - 1);
+        versionSlider.setInteger(copy.versionindex);
+        versionSlider.setEnabled(copy.versionindex != -1);
+        muteSlider = false;
+    }
+    
+    public boolean PreviousVersion()
+    {
+        // Option?
+        Replace();
+        
         System.err.println("Undo");
         
-        cRadio tab = GetCurrentTab();
+        //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 (Save(false))
-                tab.undoindex -= 1;
-            else
-            {
-                if (tab.undoindex <= 0)
-                    return false;
-                else
-                    tab.undoindex -= 1;
-            }
-        }
+//        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;
+//            }
+//        }
 
-        tab.undoindex -= 1;
+        copy.versionindex -= 1;
 
-        CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
+        CopyChanged();
         
         return true;
     }
 
-    public void Redo()
+    public boolean Restore()
     {
-        cRadio tab = GetCurrentTab();
+        System.err.println("Restore");
         
-        if (tab.graphs[tab.undoindex + 1] == null)
+        //cRadio tab = GetCurrentTab();
+        
+        if (copy.versionindex == -1 || copy.versionlist[copy.versionindex] == null)
+        {
+            java.awt.Toolkit.getDefaultToolkit().beep();
+            return false;
+        }
+
+        //CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
+        CopyChanged();
+        
+        return true;
+    }
+
+    public boolean Replace()
+    {
+        System.err.println("Replace");
+        
+        //cRadio tab = GetCurrentTab();
+        
+        if (copy.versionindex == -1 || copy.versionlist[copy.versionindex] == null)
+        {
+            // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
+            return false;
+        }
+
+        copy.versionlist[copy.versionindex] = Duplicate(copy);
+        
+        return true;
+    }
+
+    public void NextVersion()
+    {
+        // Option?
+        Replace();
+        
+        //cRadio tab = GetCurrentTab();
+        
+        if (copy.versionlist[copy.versionindex + 1] == null)
         {
             java.awt.Toolkit.getDefaultToolkit().beep();
             return;
         }
 
-        tab.undoindex += 1;
+        copy.versionindex += 1;
 
-        CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
+        CopyChanged();
         
-        //if (!tab.user[tab.undoindex])
-        //    tab.graphs[tab.undoindex] = null;
+        //if (!tab.user[tab.versionindex])
+        //    tab.graphs[tab.versionindex] = null;
     }
 
         void ImportGFD()
@@ -3978,7 +4699,7 @@
             //copy.material = new cMaterial(copy.GetMaterial());
 
             current.color = (float) colorField.getFloat();
-            current.modulation = (float) modulationField.getFloat();
+            current.modulation = (float) saturationField.getFloat();
             current.metalness = (float) metalnessField.getFloat();
             current.diffuse = (float) diffuseField.getFloat();
             current.specular = (float) specularField.getFloat();
@@ -4011,7 +4732,7 @@
                     cMaterial mat = copy.material;
                             
                     colorField.SetToolTipValue((mat.color));
-                    modulationField.SetToolTipValue((mat.modulation));
+                    saturationField.SetToolTipValue((mat.modulation));
                     metalnessField.SetToolTipValue((mat.metalness));
                     diffuseField.SetToolTipValue((mat.diffuse));
                     specularField.SetToolTipValue((mat.specular));
@@ -4063,9 +4784,28 @@
         //copy.Touch();
     }
 
+    cNumberSlider versionSlider;
+    
     public void stateChanged(ChangeEvent e)
     {
         //    assert(false);
+        if (e.getSource() == versionSlider)
+        {
+            if (muteSlider)
+                return;
+            
+            Replace();
+            
+            int version = versionSlider.getInteger();
+            
+            if (version != -1 && copy.versionlist[version] != null)
+            {
+                copy.versionindex = version;
+                CopyChanged();
+            }
+            
+            return;
+        }
 
         if (freezematerial)
         {
@@ -4101,6 +4841,12 @@
         {
             //System.out.println("stateChanged = " + this);
             materialtouched = true;
+            
+            if (Globals.AUTOSATURATE && e.getSource() == colorField && saturationField.getFloat() == 0.001)
+            {
+                saturationField.setFloat(1);
+            }
+
             applySelf();
             //System.out.println("this = " + this);
             //System.out.println("PARENT = " + parent);
@@ -4400,6 +5146,7 @@
         {
             if (GetTree() != null)
             {
+                GetTree().revalidate();
                 GetTree().repaint();
             }
 
@@ -4408,13 +5155,16 @@
             ctrlPanel.validate(); // ? new
             ctrlPanel.repaint();
         }
+        
+        if (previousVersionButton != null && copy.versionlist != null)
+            SetVersionStates();
     }
     
     static TweenManager tweenManager = new TweenManager();
 
     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);
@@ -4656,7 +5406,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);
@@ -4736,6 +5488,8 @@
             {
                 //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);
@@ -4776,6 +5530,7 @@
                 }
             } catch (ClassCastException e)
             {
+                e.printStackTrace();
                 assert (false);
                 Composite c = (Composite) copy;
                 c.children.clear();
@@ -4786,6 +5541,20 @@
                 c.addChild(csg);
             }
 
+            copy.versionlist = readobj.versionlist;
+            copy.versionindex = readobj.versionindex;
+            
+        if (copy.versionlist == null)
+        {
+            // Backward compatibility
+            copy.versionlist = new Object3D[100];
+            copy.versionindex = -1;
+            
+            //Save(true);
+        }
+        
+            //? SetUndoStates();
+            
             ResetModel();
             copy.HardTouch(); // recompile?
             refreshContents();
@@ -4796,7 +5565,7 @@
     {
         if (Grafreed.standAlone)
         {
-            FileDialog browser = new FileDialog(frame, "Load", FileDialog.LOAD);
+            FileDialog browser = new FileDialog(frame, "Open", FileDialog.LOAD);
             browser.show();
             String filename = browser.getFile();
             if (filename != null && filename.length() > 0)
@@ -4873,6 +5642,8 @@
 
     void save()
     {
+        Replace();
+        
         if (lastname == null)
         {
             return;
@@ -4895,6 +5666,7 @@
             //ps.print(buffer.toString());
         } catch (IOException e)
         {
+            e.printStackTrace();
         }
     }
     
@@ -5114,6 +5886,7 @@
     ButtonGroup buttonGroup;
     
     cGridBag toolboxPanel;
+    cGridBag skyboxPanel;
     cGridBag materialPanel;
     cGridBag ctrlPanel;
     
@@ -5187,7 +5960,7 @@
     JLabel colorLabel;
     cNumberSlider colorField;
     JLabel modulationLabel;
-    cNumberSlider modulationField;
+    cNumberSlider saturationField;
     JLabel metalnessLabel;
     cNumberSlider metalnessField;
     JLabel diffuseLabel;
@@ -5218,6 +5991,7 @@
     cNumberSlider anisoField;
     JLabel anisoVLabel;
     cNumberSlider anisoVField;
+    
     JLabel cameraLabel;
     cNumberSlider cameraField;
     JLabel selfshadowLabel;
@@ -5232,6 +6006,7 @@
     cNumberSlider fakedepthField;
     JLabel shadowbiasLabel;
     cNumberSlider shadowbiasField;
+    
     JLabel bumpLabel;
     cNumberSlider bumpField;
     JLabel noiseLabel;

--
Gitblit v1.6.2