From 564f4d12d93813b5d680fc24d4f118c3886d96ed Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Tue, 20 Aug 2019 19:56:41 -0400
Subject: [PATCH] Parallax mapping!

---
 ObjEditor.java |  811 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 615 insertions(+), 196 deletions(-)

diff --git a/ObjEditor.java b/ObjEditor.java
index c2efc4b..3f3be5b 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -34,6 +34,7 @@
         iSendInfo
 //KeyListener
 {
+    public cToggleButton pinButton;
         boolean timeline;
         boolean wasFullScreen;
 
@@ -41,6 +42,50 @@
     JFrame frame;
     
     static ObjEditor theFrame;
+
+    public void AllocProjectedVertices(Object3D object)
+    {
+        assert (object.projectedVertices != null);
+
+        if (object.projectedVertices.length <= 2)
+        {
+            // Side effect...
+            Object3D.cVector2[] keep = object.projectedVertices;
+            object.projectedVertices = new Object3D.cVector2[3];
+            for (int i = 0; i < 3; i++)
+            {
+                if (i < keep.length)
+                {
+                    object.projectedVertices[i] = keep[i];
+                } else
+                {
+                    object.projectedVertices[i] = new Object3D.cVector2();
+                }
+                /*
+                if(keep.length == 0)
+                object.projectedVertices[0] = new Object3D.cVector2();
+                else
+                object.projectedVertices[0] = keep[0];
+                object.projectedVertices[1] = new Object3D.cVector2();
+                 */
+            }
+        }
+    }
+
+    public Composite CreateCameras()
+    {
+        Composite cams = new cTemplate();
+        cams.name = "Cameras";
+        copy.insertElementAt(cams, 0);
+
+        cams.addChild(new Camera());
+        cams.addChild(new Camera(1));
+        cams.addChild(new Camera(2));
+        cams.addChild(new Camera(3));
+        cams.addChild(new Camera(4));
+        
+        return cams;
+    }
 
     public cGridBag GetSeparator()
     {
@@ -53,7 +98,10 @@
     cButton GetButton(String name, boolean border)
     {
         ImageIcon icon = GetIcon(name);
-        return new cButton(icon, border);
+        if (icon != null || name.contains("/"))
+            return new cButton(icon, border);
+        else
+            return new cButton(name, border);
     }
 
     cLabel GetLabel(String name, boolean border)
@@ -74,12 +122,26 @@
         return new cCheckBox(icon, border);
     }
 
-    ImageIcon GetIcon(String name)
+    static java.util.Hashtable<String, javax.swing.ImageIcon> icons = new java.util.Hashtable<String, javax.swing.ImageIcon>();
+    
+    static ImageIcon GetIcon(String name)
     {
+        javax.swing.ImageIcon iconCache = icons.get(name);
+        if (iconCache != null)
+        {
+            return iconCache;
+        }
+        
         try
         {
-            BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
-
+            BufferedImage image;
+            
+            if (name.endsWith("jpg"))
+                // Much faster!
+                image = new sun.awt.image.codec.JPEGImageDecoderImpl(ObjEditor.class.getClassLoader().getResourceAsStream(name)).decodeAsBufferedImage();
+            else
+                image = javax.imageio.ImageIO.read(ObjEditor.class.getClassLoader().getResourceAsStream(name));
+  
 //            if (image.getWidth() > 48 && image.getHeight() > 48)
 //            {
 //                BufferedImage resized = new BufferedImage(48, 48, image.getType());
@@ -93,10 +155,14 @@
 //            }
 
             javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
+            
+            icons.put(name, icon);
+            
             return icon;
         }
         catch (Exception e)
         {
+            //icons.put(name, null);
             return null;
         }
     }
@@ -296,11 +362,13 @@
         client = inClient;
         copy = client;
 
-        if (copy.versionlist == null)
-        {
-            copy.versionlist = new Object3D[100];
-            copy.versionindex = -1;
-        }
+//        if (copy.versionlist == null)
+//        {
+//            copy.versionlist = new Object3D[100];
+//            copy.versionindex = -1;
+//            
+//            callee.Save(true);
+//        }
         
         // "this" is not called: SetupUI2(objEditor);
     }
@@ -319,6 +387,8 @@
         {
             copy.versionlist = new Object3D[100];
             copy.versionindex = -1;
+            
+//            Save(true);
         }
         
         SetupUI2(callee.GetEditor());
@@ -342,7 +412,8 @@
         //parent = p;
 
         GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
-        System.out.println("getFullScreenWindow? " + gd.getFullScreenWindow());
+        if (Globals.DEBUG)
+            System.out.println("getFullScreenWindow? " + gd.getFullScreenWindow());
         //gd.setFullScreenWindow(this);
         //setResizable(false);
         //if (!isDisplayable())
@@ -353,11 +424,13 @@
         copy = localCopy;
         copy.editWindow = this;
 
-        if (copy.versionlist == null)
-        {
-//            copy.versions = new byte[100][];
+//        if (copy.versionlist == null)
+//        {
+//            copy.versionlist = new Object3D[100];
 //            copy.versionindex = -1;
-        }
+//            
+//            Save(true);
+//        }
         
         SetupMenu();
 
@@ -377,6 +450,9 @@
 
     static java.util.Vector<Object3D> listUI = new java.util.Vector<Object3D>();
 
+    // This is to refresh the UI of the material panel.
+    boolean patchMaterial;
+    
     void SetupMenu()
     {
         frame.setMenuBar(menuBar = new MenuBar());
@@ -390,8 +466,11 @@
 		importOBJItem.addActionListener(this);
 		import3DSItem = menu.add(new MenuItem("3DS file..."));
 		import3DSItem.addActionListener(this);
+                if (Globals.ADVANCED)
+                {
 		importVRMLX3DItem = menu.add(new MenuItem("VRML/X3D file..."));
 		importVRMLX3DItem.addActionListener(this);
+                }
 		menu.add("-");
 		importGFDItem = menu.add(new MenuItem("Grafreed file..."));
 		importGFDItem.addActionListener(this);
@@ -426,6 +505,8 @@
         
         ChangeListener changeListener = new ChangeListener()
         {
+            //String name;
+            
             public void stateChanged(ChangeEvent changeEvent)
             {
 //                if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Material") && !materialFlushed)
@@ -444,7 +525,37 @@
 //                        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);
@@ -466,6 +577,8 @@
                 
         toolboxPanel = new cGridBag().setVertical(true);
         //toolboxPanel.setName("Toolbox");
+        
+        skyboxPanel = new cGridBag().setVertical(true);
         
         materialPanel = new cGridBag().setVertical(false);
         //materialPanel.setName("Material");
@@ -751,6 +864,7 @@
         boolean maximized;
     
         cButton fullscreenLayout;
+        cButton expandedLayout;
 
         void Minimize()
         {
@@ -790,10 +904,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();
                 
@@ -814,13 +930,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
                 {
@@ -841,10 +957,10 @@
 // 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();
@@ -852,23 +968,42 @@
             cameraView.requestFocusInWindow();
         }
 
-    private Object3D CompressCopy()
+        void CollapseToolbar()
+        {
+            framePanel.setDividerLocation(0);
+            //frame.validate();
+            
+            cameraView.requestFocusInWindow();
+        }
+        
+    private Object3D Duplicate(Object3D object)
     {
         boolean temp = CameraPane.SWITCH;
         CameraPane.SWITCH = false;
         
-        copy.ExtractBigData(versiontable);
+        if (Grafreed.grafreed.universe.versiontable == null)
+            Grafreed.grafreed.universe.versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
+         
+        object.ExtractBigData(Grafreed.grafreed.universe.versiontable);
         // if (copy == client)
         
-        Object3D versions[] = copy.versionlist;
-        copy.versionlist = null;
+        Object3D versions[] = object.versionlist;
+        java.util.Hashtable<java.util.UUID, Object3D> versiontable = object.versiontable; // if Grafreed.grafreed.universe
+        object.versionlist = null;
+        object.versiontable = null;
+        
+        Object3D parent = object.parent;
+        object.parent = null;
         
         //byte[] compress = Compress(copy);
-        Object3D compress = (Object3D)Grafreed.clone(copy);
+        Object3D compress = (Object3D)Grafreed.clone(object);
         
-        copy.versionlist = versions;
+        object.parent = parent;
         
-        copy.RestoreBigData(versiontable);
+        object.versionlist = versions;
+        object.versiontable = versiontable; // if Grafreed.grafreed.universe
+        
+        object.RestoreBigData(Grafreed.grafreed.universe.versiontable);
         
         CameraPane.SWITCH = temp;
         
@@ -1205,6 +1340,18 @@
         
             namePanel = new cGridBag();
             
+        //if (copy.pinned)
+        {
+            pinButton = GetToggleButton("icons/pin.png", !Globals.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);
@@ -1218,14 +1365,14 @@
             
         liveCB = AddCheckBox(setupPanel, "Live", copy.live);
                 liveCB.setToolTipText("Animate object");
+        markCB = AddCheckBox(setupPanel, "Anim", copy.marked);
+        markCB.setToolTipText("Set target transform");
         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);
         
@@ -1427,22 +1574,9 @@
 
         if (cam == null || !(copy.get(0) instanceof cGroup))
         {
-            System.out.println("CREATE CAMERAS");
-            cams = new cTemplate();
-            cams.name = "Cameras";
-            copy.insertElementAt(cams, 0);
-            //cams.parent = copy;
-
-            cam = new Camera(); // LA.newVector(3, 2, 1));
-            cams.addChild(cam);
-            cam = new Camera(1);
-            cams.addChild(cam);
-            cam = new Camera(2);
-            cams.addChild(cam);
-            cam = new Camera(3);
-            cams.addChild(cam);
-            cam = new Camera(4); // Light
-            cams.addChild(cam);
+            if (Globals.DEBUG)
+                System.out.println("CREATE CAMERAS");
+            cams = CreateCameras();
         } else
         {
             cams = (cGroup) copy.get(0);
@@ -1508,6 +1642,45 @@
         //frontView.object = copy;
         //sideView.object = copy;
 
+        transformPanel = new cGridBag().setVertical(true);
+        
+        cGridBag resetTransformPanel = new cGridBag();
+        
+        resetTransformPanel.preferredHeight = 2;
+        
+        cButton resetTransform = GetButton("Reset all", !Globals.NIMBUSLAF);
+        resetTransform.setToolTipText("Reset Translation, Rotation and Scale");
+        resetTransform.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                ResetTransform();
+            }
+        });
+        resetTransformPanel.add(resetTransform);
+        
+        resetTransform = GetButton("T only", !Globals.NIMBUSLAF);
+        resetTransform.setToolTipText("Reset Translation only");
+        resetTransform.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                ResetTransform(1);
+            }
+        });
+        resetTransformPanel.add(resetTransform);
+        
+        resetTransform = GetButton("RS only", !Globals.NIMBUSLAF);
+        resetTransform.setToolTipText("Reset Rotation and Scale only");
+        resetTransform.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                ResetTransform(2);
+            }
+        });
+        resetTransformPanel.add(resetTransform);
+        
         XYZPanel = new cGridBag().setVertical(true);
         //XYZPanel.setLayout(new GridLayout(3, 1, 5, 5));
 
@@ -1517,6 +1690,9 @@
         XYZPanel.addComponent(/*BorderLayout.NORTH,*/topView); // Scroll);
         //XYZPanel.setName("XYZ");
 
+        transformPanel.add(resetTransformPanel);
+        transformPanel.add(XYZPanel);
+        
         /*
         gridPanel = new JPanel(); //new BorderLayout());
         gridPanel.setLayout(new GridLayout(1, 2));
@@ -1524,12 +1700,12 @@
         gridPanel.add(cameraView);
         gridPanel.add(XYZPanel);
          */
-        gridPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, centralPanel, XYZPanel); //new BorderLayout());
-        gridPanel.setContinuousLayout(true);
-        gridPanel.setOneTouchExpandable(true);
-        gridPanel.setDividerLocation(1.0);
-        gridPanel.setDividerSize(9);
-        gridPanel.setResizeWeight(0.85);
+//        gridPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, centralPanel, XYZPanel); //new BorderLayout());
+//        gridPanel.setContinuousLayout(true);
+//        gridPanel.setOneTouchExpandable(true);
+//        gridPanel.setDividerLocation(1.0);
+//        gridPanel.setDividerSize(9);
+//        gridPanel.setResizeWeight(0.85);
 
 //                aConstraints.weighty = 0;
         //System.out.println("THIS = " + this);
@@ -1552,31 +1728,34 @@
 
         //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(skyboxPanel);
+        objectPanel.setIconAt(0, GetIcon("icons/skybox.jpg"));
+        objectPanel.setToolTipTextAt(0, "Backgrounds");
+        
         objectPanel.add(toolboxPanel);
         objectPanel.setIconAt(1, GetIcon("icons/primitives.png"));
-        objectPanel.setToolTipTextAt(1, "Objects & backgrounds");
+        objectPanel.setToolTipTextAt(1, "Objects & textures");
 
+        objectPanel.add(materialPanel);
+        objectPanel.setIconAt(2, GetIcon("icons/material.png"));
+        objectPanel.setToolTipTextAt(2, "Material");
+    
 //        JPanel north = new JPanel(new BorderLayout());
 //        north.setName("Edit");
 //        north.add(ctrlPanel, BorderLayout.NORTH);
 //        objectPanel.add(north);
         objectPanel.add(editPanel);
-        objectPanel.setIconAt(2, GetIcon("icons/write.png"));
-        objectPanel.setToolTipTextAt(2, "Edit controls");
+        objectPanel.setIconAt(3, GetIcon("icons/writewhite.png"));
+        objectPanel.setToolTipTextAt(3, "Edit controls");
         
-        //if (Globals.ADVANCED)
-            objectPanel.add(infoPanel);
-        objectPanel.setIconAt(3, GetIcon("icons/info.png"));
-        objectPanel.setToolTipTextAt(3, "Information");
-        
-        objectPanel.add(XYZPanel);
+        objectPanel.add(transformPanel);
         objectPanel.setIconAt(4, GetIcon("icons/XYZ.png"));
-        objectPanel.setToolTipTextAt(4, "XYZ/RGB transform");
+        objectPanel.setToolTipTextAt(4, "TRS transform");
         
+        patchMaterial = true;
+        cameraView.patchMaterial = this;
+        objectPanel.setSelectedIndex(2);
+                
         /*
         aConstraints.gridx = 0;
         aConstraints.gridwidth = 1;
@@ -1596,7 +1775,7 @@
         scrollpane.addMouseWheelListener(this); // Default not fast enough
 
         /*JTabbedPane*/ scenePanel = new cGridBag();
-        scenePanel.preferredWidth = 5;
+        scenePanel.preferredWidth = 6;
         
         JTabbedPane tabbedPane = new JTabbedPane();
         tabbedPane.add(scrollpane);
@@ -1607,11 +1786,108 @@
         
         AddOptions(optionsPanel); //, aConstraints);
         
-        tabbedPane.add(optionsPanel);
-        
         tabbedPane.add(FSPane = new cFileSystemPane(this));
 
+        tabbedPane.add(optionsPanel);
+        
         scenePanel.add(tabbedPane);
+
+        cGridBag creditsPanel = new cGridBag().setVertical(true);
+        creditsPanel.setName("Credits");
+        
+        cLabel ogaLabel = new cLabel(" Skyboxes courtesy of OpenGameArt!", !Globals.NIMBUSLAF);
+	creditsPanel.add(ogaLabel);
+        
+        cButton creditButton;
+	creditsPanel.add(creditButton = GetButton("icons/sara-logo.png", !Globals.NIMBUSLAF));
+        creditButton.setToolTipText("https://opengameart.org");
+        
+        creditButton.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                try
+                {
+                    Desktop.getDesktop().browse(new java.net.URI("https://opengameart.org/"));
+                } catch (Exception e1)
+//                } catch (java.io.IOException | java.net.URISyntaxException e1)
+                {
+                    e1.printStackTrace();
+                }
+            }
+        });
+        
+        ogaLabel = new cLabel(" Download 3D models! (.3ds and .obj only)", !Globals.NIMBUSLAF);
+	creditsPanel.add(ogaLabel);
+        
+	creditsPanel.add(creditButton = GetButton("icons/3delicious.png", !Globals.NIMBUSLAF));
+        creditButton.setToolTipText("https://3delicious.net");
+        
+        creditButton.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                try
+                {
+                    Desktop.getDesktop().browse(new java.net.URI("https://3delicious.net"));
+                } catch (Exception e1)
+//                } catch (java.io.IOException | java.net.URISyntaxException e1)
+                {
+                    e1.printStackTrace();
+                }
+            }
+        });
+        
+	creditsPanel.add(creditButton = GetButton("icons/archive3d.png", !Globals.NIMBUSLAF));
+        creditButton.setToolTipText("https://archive3d.net");
+        
+        creditButton.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                try
+                {
+                    Desktop.getDesktop().browse(new java.net.URI("https://archive3d.net"));
+                } catch (Exception e1)
+//                } catch (java.io.IOException | java.net.URISyntaxException e1)
+                {
+                    e1.printStackTrace();
+                }
+            }
+        });
+        
+	creditsPanel.add(creditButton = GetButton("icons/turbosquid.png", !Globals.NIMBUSLAF));
+        creditButton.setToolTipText("https://turbosquid.com");
+        
+        creditButton.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                try
+                {
+                    Desktop.getDesktop().browse(new java.net.URI("https://www.turbosquid.com/Search/3D-Models/free"));
+                } catch (Exception e1)
+//                } catch (java.io.IOException | java.net.URISyntaxException e1)
+                {
+                    e1.printStackTrace();
+                }
+            }
+        });
+        
+        for (int i=6; --i>=0;)
+        {
+            creditsPanel.add(new cGridBag());
+        }
+        
+        tabbedPane.add(creditsPanel);
+        tabbedPane.setToolTipTextAt(3, "Credits");
+        
+        if (Globals.ADVANCED)
+        {
+            tabbedPane.add(infoPanel);
+            tabbedPane.setIconAt(4, GetIcon("icons/info.png"));
+            tabbedPane.setToolTipTextAt(4, "Information");
+        }
 
         /*
         cTree jTree = new cTree(null);
@@ -1633,13 +1909,13 @@
         jtp.add(tree);
          */
 
-        bigPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scenePanel, gridPanel);
-        bigPanel.setContinuousLayout(true);
-        bigPanel.setOneTouchExpandable(true);
-        bigPanel.setDividerLocation(0.8);
-        bigPanel.setDividerSize(15);
-        bigPanel.setResizeWeight(0.15);
-        bigPanel.setName("Scene");
+//        bigPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scenePanel, gridPanel);
+//        bigPanel.setContinuousLayout(true);
+//        bigPanel.setOneTouchExpandable(true);
+//        bigPanel.setDividerLocation(0.8);
+//        bigPanel.setDividerSize(15);
+//        bigPanel.setResizeWeight(0.15);
+//        bigPanel.setName("Scene");
 
         //bigPanel.setLayout(new BorderLayout());
         //bigPanel.setSize(new Dimension(10,10));
@@ -1683,6 +1959,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);
@@ -1692,7 +1985,7 @@
 
         frame.getContentPane().setLayout(new BorderLayout());
         /**/
-        JTabbedPane worldPane = new JTabbedPane();
+        //JTabbedPane worldPane = new JTabbedPane();
         //worldPane.add(bigPanel);
         //worldPane.add(worldPanel);
                 /**/
@@ -1706,7 +1999,7 @@
         
                     cameraView.requestFocusInWindow();
                     
-        gridPanel.setDividerLocation(1.0);
+//        gridPanel.setDividerLocation(1.0);
         
         frame.validate();
 
@@ -1741,7 +2034,7 @@
     {
         cGridBag presetpanel = new cGridBag().setVertical(true);
         
-        cLabel skin = GetLabel("icons/shadericons/shadericon00000.png", !Grafreed.NIMBUSLAF);
+        cLabel skin = GetLabel("icons/shadericons/shadericon00000.png", !Globals.NIMBUSLAF);
         skin.setToolTipText("Skin");
         skin.addMouseListener(new MouseAdapter()
         {
@@ -1752,7 +2045,15 @@
                 
                 // Skin
                 colorField.setFloat(material.color);
-                saturationField.setFloat(material.modulation);
+                float saturation = material.modulation;
+                
+                if (!cameraView.Skinshader)
+                {
+                    saturation /= 1.5;
+                }
+                
+                saturationField.setFloat(saturation);
+                
                 subsurfaceField.setFloat(material.subsurface);
                 selfshadowField.setFloat(material.diffuseness);
                 diffusenessField.setFloat(material.factor);
@@ -1771,7 +2072,7 @@
         });
         presetpanel.add(skin);
         
-        cLabel lambert = GetLabel("icons/shadericons/shadericon00002.png", !Grafreed.NIMBUSLAF);
+        cLabel lambert = GetLabel("icons/shadericons/shadericon00002.png", !Globals.NIMBUSLAF);
         lambert.setToolTipText("Diffuse");
         lambert.addMouseListener(new MouseAdapter()
         {
@@ -1789,7 +2090,7 @@
         });
         presetpanel.add(lambert);
         
-        cLabel diffuse2 = GetLabel("icons/shadericons/shadericon00003.png", !Grafreed.NIMBUSLAF);
+        cLabel diffuse2 = GetLabel("icons/shadericons/shadericon00003.png", !Globals.NIMBUSLAF);
         diffuse2.setToolTipText("Diffuse2");
         diffuse2.addMouseListener(new MouseAdapter()
         {
@@ -1807,7 +2108,7 @@
         });
         presetpanel.add(diffuse2);
         
-        cLabel diffusemoon = GetLabel("icons/shadericons/shadericon00004.png", !Grafreed.NIMBUSLAF);
+        cLabel diffusemoon = GetLabel("icons/shadericons/shadericon00004.png", !Globals.NIMBUSLAF);
         diffusemoon.setToolTipText("Moon");
         diffusemoon.addMouseListener(new MouseAdapter()
         {
@@ -1825,7 +2126,7 @@
         });
         presetpanel.add(diffusemoon);
         
-        cLabel diffusemoon2 = GetLabel("icons/shadericons/shadericon00005.png", !Grafreed.NIMBUSLAF);
+        cLabel diffusemoon2 = GetLabel("icons/shadericons/shadericon00005.png", !Globals.NIMBUSLAF);
         diffusemoon2.setToolTipText("Moon2");
         diffusemoon2.addMouseListener(new MouseAdapter()
         {
@@ -1843,7 +2144,7 @@
         });
         presetpanel.add(diffusemoon2);
         
-        cLabel diffusemoon3 = GetLabel("icons/shadericons/shadericon00006.png", !Grafreed.NIMBUSLAF);
+        cLabel diffusemoon3 = GetLabel("icons/shadericons/shadericon00006.png", !Globals.NIMBUSLAF);
         diffusemoon3.setToolTipText("Moon3");
         diffusemoon3.addMouseListener(new MouseAdapter()
         {
@@ -1861,7 +2162,7 @@
         });
         presetpanel.add(diffusemoon3);
         
-        cLabel diffusesheen = GetLabel("icons/shadericons/shadericon00007.png", !Grafreed.NIMBUSLAF);
+        cLabel diffusesheen = GetLabel("icons/shadericons/shadericon00007.png", !Globals.NIMBUSLAF);
         diffusesheen.setToolTipText("Sheen");
         diffusesheen.addMouseListener(new MouseAdapter()
         {
@@ -1878,7 +2179,7 @@
         });
         presetpanel.add(diffusesheen);
         
-        cLabel rough = GetLabel("icons/shadericons/shadericon00001.png", !Grafreed.NIMBUSLAF);
+        cLabel rough = GetLabel("icons/shadericons/shadericon00001.png", !Globals.NIMBUSLAF);
         rough.setToolTipText("Rough metal");
         rough.addMouseListener(new MouseAdapter()
         {
@@ -1896,7 +2197,7 @@
         });
         presetpanel.add(rough);
         
-        cLabel rough2 = GetLabel("icons/shadericons/shadericon00013.png", !Grafreed.NIMBUSLAF);
+        cLabel rough2 = GetLabel("icons/shadericons/shadericon00013.png", !Globals.NIMBUSLAF);
         rough2.setToolTipText("Medium metal");
         rough2.addMouseListener(new MouseAdapter()
         {
@@ -1914,7 +2215,7 @@
         });
         presetpanel.add(rough2);
         
-        cLabel shini0 = GetLabel("icons/shadericons/shadericon00014.png", !Grafreed.NIMBUSLAF);
+        cLabel shini0 = GetLabel("icons/shadericons/shadericon00014.png", !Globals.NIMBUSLAF);
         shini0.setToolTipText("Shiny");
         shini0.addMouseListener(new MouseAdapter()
         {
@@ -1932,7 +2233,7 @@
         });
         presetpanel.add(shini0);
         
-        cLabel shini1 = GetLabel("icons/shadericons/shadericon00011.png", !Grafreed.NIMBUSLAF);
+        cLabel shini1 = GetLabel("icons/shadericons/shadericon00011.png", !Globals.NIMBUSLAF);
         shini1.setToolTipText("Shiny2");
         shini1.addMouseListener(new MouseAdapter()
         {
@@ -1950,7 +2251,7 @@
         });
         presetpanel.add(shini1);
         
-        cLabel shini2 = GetLabel("icons/shadericons/shadericon00012.png", !Grafreed.NIMBUSLAF);
+        cLabel shini2 = GetLabel("icons/shadericons/shadericon00012.png", !Globals.NIMBUSLAF);
         shini2.setToolTipText("Shiny3");
         shini2.addMouseListener(new MouseAdapter()
         {
@@ -1968,7 +2269,7 @@
         });
         presetpanel.add(shini2);
         
-        cLabel aniso = GetLabel("icons/shadericons/shadericon00008.png", !Grafreed.NIMBUSLAF);
+        cLabel aniso = GetLabel("icons/shadericons/shadericon00008.png", !Globals.NIMBUSLAF);
         aniso.setToolTipText("AnisoU");
         aniso.addMouseListener(new MouseAdapter()
         {
@@ -1986,7 +2287,7 @@
         });
         presetpanel.add(aniso);
         
-        cLabel aniso2 = GetLabel("icons/shadericons/shadericon00009.png", !Grafreed.NIMBUSLAF);
+        cLabel aniso2 = GetLabel("icons/shadericons/shadericon00009.png", !Globals.NIMBUSLAF);
         aniso2.setToolTipText("AnisoV");
         aniso2.addMouseListener(new MouseAdapter()
         {
@@ -2004,7 +2305,7 @@
         });
         presetpanel.add(aniso2);
         
-        cLabel aniso3 = GetLabel("icons/shadericons/shadericon00010.png", !Grafreed.NIMBUSLAF);
+        cLabel aniso3 = GetLabel("icons/shadericons/shadericon00010.png", !Globals.NIMBUSLAF);
         aniso3.setToolTipText("AnisoUV");
         aniso3.addMouseListener(new MouseAdapter()
         {
@@ -2022,7 +2323,7 @@
         });
         presetpanel.add(aniso3);
         
-        cLabel velvet0 = GetLabel("icons/shadericons/shadericon00015.png", !Grafreed.NIMBUSLAF);
+        cLabel velvet0 = GetLabel("icons/shadericons/shadericon00015.png", !Globals.NIMBUSLAF);
         velvet0.setToolTipText("Velvet");
         velvet0.addMouseListener(new MouseAdapter()
         {
@@ -2044,7 +2345,7 @@
         });
         presetpanel.add(velvet0);
         
-        cLabel bump0 = GetLabel("icons/shadericons/shadericon00016.png", !Grafreed.NIMBUSLAF);
+        cLabel bump0 = GetLabel("icons/shadericons/shadericon00016.png", !Globals.NIMBUSLAF);
         bump0.setToolTipText("Bump texture");
         bump0.addMouseListener(new MouseAdapter()
         {
@@ -2063,7 +2364,22 @@
         });
         presetpanel.add(bump0);
         
-        cLabel halo = GetLabel("icons/shadericons/shadericon00017.png", !Grafreed.NIMBUSLAF);
+        cLabel borderShader = GetLabel("icons/shadericons/borderfade.jpg", !Globals.NIMBUSLAF);
+        borderShader.setToolTipText("Border fade");
+        borderShader.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                borderfadeField.setFloat(0.5);
+                opacityField.setFloat(0.75);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(borderShader);
+        
+        cLabel halo = GetLabel("icons/shadericons/shadericon00017.png", !Globals.NIMBUSLAF);
         halo.setToolTipText("Halo");
         halo.addMouseListener(new MouseAdapter()
         {
@@ -2080,7 +2396,7 @@
         });
         presetpanel.add(halo);
         
-        cLabel candle = GetLabel("icons/shadericons/shadericon00018.png", !Grafreed.NIMBUSLAF);
+        cLabel candle = GetLabel("icons/shadericons/shadericon00018.png", !Globals.NIMBUSLAF);
         candle.setToolTipText("Candle");
         candle.addMouseListener(new MouseAdapter()
         {
@@ -2102,6 +2418,25 @@
         });
         presetpanel.add(candle);
         
+        cLabel shadowShader = GetLabel("icons/shadericons/shadow.png", !Globals.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;
@@ -2118,19 +2453,19 @@
 
         cGridBag editBar = new cGridBag().setVertical(false);
             
-        editBar.add(createMaterialButton = new cButton("Create", !Grafreed.NIMBUSLAF)); // , aConstraints);
+        editBar.add(createMaterialButton = new cButton("Create", !Globals.NIMBUSLAF)); // , aConstraints);
                 createMaterialButton.setToolTipText("Create material");
 
         /*
         ctrlPanel.add(resetSlidersButton = new cButton("Reset All"), aConstraints);
          */
 
-        editBar.add(clearMaterialButton = new cButton("Clear", !Grafreed.NIMBUSLAF)); // , aConstraints);
+        editBar.add(clearMaterialButton = new cButton("Clear", !Globals.NIMBUSLAF)); // , aConstraints);
                 clearMaterialButton.setToolTipText("Clear material");
         
         if (Globals.ADVANCED)
         {
-                editBar.add(resetSlidersButton = new cButton("Reset", !Grafreed.NIMBUSLAF)); // , aConstraints);
+                editBar.add(resetSlidersButton = new cButton("Reset", !Globals.NIMBUSLAF)); // , aConstraints);
                 editBar.add(propagateToggle = new cCheckBox("Prop", propagate)); // , aConstraints);
                 editBar.add(multiplyToggle = new cCheckBox("Mult", false)); // , aConstraints);
         }
@@ -2151,9 +2486,20 @@
 
         cGridBag huepanel = new cGridBag();
             cGridBag huelabel = new cGridBag();
-        skin = GetLabel("icons/hue.png", false);
-        skin.fit = true;
-            huelabel.add(skin);
+        cLabel hue = GetLabel("icons/hue.png", false);
+        hue.fit = true;
+        
+        hue.addMouseListener(new MouseAdapter()
+        {
+            public void mousePressed(MouseEvent e)
+            {
+                int x = e.getX();
+                
+                colorField.setFloat((double)x / ((cLabel)e.getSource()).getWidth());
+            }
+        });
+        
+            huelabel.add(hue);
             huelabel.preferredWidth = 20;
             huepanel.add(new cGridBag()); // Label
             huepanel.add(huelabel); // Field/slider
@@ -2336,6 +2682,12 @@
                 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
         colorSection.add(backlit);
 
+        cGridBag parallax = new cGridBag();
+                parallax.add(parallaxLabel = new JLabel("Parallax")); // , aConstraints);
+                parallaxLabel.setHorizontalAlignment(SwingConstants.TRAILING);
+                parallax.add(parallaxField = new cNumberSlider(this, 0.001, 0.5, -0.25)); // , aConstraints);
+        colorSection.add(parallax);
+        
         //panel.add(new JSeparator());
         
         //panel.add(globalSection);
@@ -3387,6 +3739,7 @@
         shadowField.setFloat(mat.shadow);
         textureField.setFloat(mat.texture);
         opacityField.setFloat(mat.opacity);
+        parallaxField.setFloat(mat.parallax + 0.25f);
         fakedepthField.setFloat(mat.fakedepth);
         shadowbiasField.setFloat(mat.shadowbias);
         bumpField.setInteger(1); // dec 2013
@@ -3429,32 +3782,8 @@
 
         if (multiplyToggle != null)
                 multiplyToggle.setSelected(mat.multiply);
-
-        assert (object.projectedVertices != null);
-
-        if (object.projectedVertices.length <= 2)
-        {
-            // Side effect...
-            Object3D.cVector2[] keep = object.projectedVertices;
-            object.projectedVertices = new Object3D.cVector2[3];
-            for (int i = 0; i < 3; i++)
-            {
-                if (i < keep.length)
-                {
-                    object.projectedVertices[i] = keep[i];
-                } else
-                {
-                    object.projectedVertices[i] = new Object3D.cVector2();
-                }
-                /*
-                if(keep.length == 0)
-                object.projectedVertices[0] = new Object3D.cVector2();
-                else
-                object.projectedVertices[0] = keep[0];
-                object.projectedVertices[1] = new Object3D.cVector2();
-                 */
-            }
-        }
+        
+        AllocProjectedVertices(object);
 
         SetMaterial(mat, object.projectedVertices);
     }
@@ -3574,6 +3903,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;
@@ -3753,7 +4093,7 @@
             //System.out.println("ObjEditor " + event);
             applySelf0(true);
             //parent.applySelf();
-            objEditor.refreshContents();
+     // conflicts with requestFocus       objEditor.refreshContents();
         } else if (source == resetButton)
         {
             CameraPane.fullreset = true;
@@ -3933,11 +4273,18 @@
 
     void New()
     {
-        while (copy.Size() > 1)
+        while (copy.Size() > 0)
         {
-            copy.remove(1);
+            copy.remove(0);
         }
         
+        copy.selection.clear();
+        
+        if (copy == Grafreed.grafreed.universe)
+        {
+            CreateCameras();
+            cameraView.SetCamera(GetCamera(copy, 0));
+        }
         ResetModel();
         objEditor.refreshContents();
     }
@@ -4046,7 +4393,7 @@
     {
         //Save(true);
         Replace();
-        SetUndoStates();
+        SetVersionStates();
     }
     
     private boolean Equal(byte[] compress, byte[] name)
@@ -4065,8 +4412,6 @@
         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++)
@@ -4074,19 +4419,23 @@
             copy.versionlist[i] = copy.versionlist[i+1];
         }
         
-        CopyChanged();
+        if (copy.versionlist[copy.versionindex] == null)
+            copy.versionindex -= 1;
         
-        SetUndoStates();
+        if (copy.versionindex != -1)
+            CopyChanged();
+        
+        SetVersionStates();
     }
     
     public boolean Save(boolean user)
     {
         System.err.println("Save");
-        //Replace();
+        Replace();
         
-        cRadio tab = GetCurrentTab();
+        //cRadio tab = GetCurrentTab();
         
-        Object3D compress = CompressCopy(); // Saved version. No need for "Replace"?
+        Object3D compress = Duplicate(copy); // Saved version. No need for "Replace"?
         
         boolean thesame = false;
         
@@ -4122,7 +4471,7 @@
 //            copy.versionlist[i] = null;
 //        }
 
-        SetUndoStates();
+        SetVersionStates();
         
         // test save
         if (false)
@@ -4180,14 +4529,14 @@
 
     void CopyChanged()
     {
-        Object3D obj = copy.versionlist[copy.versionindex];
+        Object3D obj = (Object3D)Grafreed.clone(copy.versionlist[copy.versionindex]);
         
-        SetUndoStates();
+        SetVersionStates();
         
         boolean temp = CameraPane.SWITCH;
         CameraPane.SWITCH = false;
         
-        copy.ExtractBigData(versiontable);
+        copy.ExtractBigData(Grafreed.grafreed.universe.versiontable);
         
         copy.clear();
         
@@ -4199,7 +4548,7 @@
             copy.add(obj.get(i));
         }
         
-        copy.RestoreBigData(versiontable);
+        copy.RestoreBigData(Grafreed.grafreed.universe.versiontable);
         
         CameraPane.SWITCH = temp;
         
@@ -4249,23 +4598,45 @@
         return count;
     }
     
-    void SetUndoStates()
+    public cGridBag versionSliderPane;
+    
+    void SetVersionStates()
     {
-        cRadio tab = GetCurrentTab();
+        //if (true)
+        //    return;
+                    
+        //cRadio tab = GetCurrentTab();
         
-        restoreButton.setEnabled(true); // copy.versionindex != -1);
-        replaceButton.setEnabled(true); // 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.setMaximum(VersionCount() - 1);
-        versionSlider.setInteger(copy.versionindex);
-        muteSlider = false;
+        if (copy.versionlist == null)
+        {
+            saveVersionButton.setEnabled(false);
+            restoreButton.setEnabled(false);
+            replaceButton.setEnabled(false);
+            previousVersionButton.setEnabled(false);
+            nextVersionButton.setEnabled(false);
+            deleteVersionButton.setEnabled(false);
+            versionSliderPane.setVisible(false);
+        }
+        else
+        {
+            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 != -1);
+                                            //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;
+            
+            versionSliderPane.setVisible(true);
+        }
     }
     
     public boolean PreviousVersion()
@@ -4275,7 +4646,7 @@
         
         System.err.println("Undo");
         
-        cRadio tab = GetCurrentTab();
+        //cRadio tab = GetCurrentTab();
         
         if (copy.versionindex == 0)
         {
@@ -4307,7 +4678,7 @@
     {
         System.err.println("Restore");
         
-        cRadio tab = GetCurrentTab();
+        //cRadio tab = GetCurrentTab();
         
         if (copy.versionindex == -1 || copy.versionlist[copy.versionindex] == null)
         {
@@ -4323,9 +4694,9 @@
 
     public boolean Replace()
     {
-        System.err.println("Replace");
+        //System.err.println("Replace");
         
-        cRadio tab = GetCurrentTab();
+        //cRadio tab = GetCurrentTab();
         
         if (copy.versionindex == -1 || copy.versionlist[copy.versionindex] == null)
         {
@@ -4333,7 +4704,7 @@
             return false;
         }
 
-        copy.versionlist[copy.versionindex] = CompressCopy();
+        copy.versionlist[copy.versionindex] = Duplicate(copy);
         
         return true;
     }
@@ -4343,7 +4714,7 @@
         // Option?
         Replace();
         
-        cRadio tab = GetCurrentTab();
+        //cRadio tab = GetCurrentTab();
         
         if (copy.versionlist[copy.versionindex + 1] == null)
         {
@@ -4550,6 +4921,12 @@
 //            else
 //		applySelf(true);
 //	}
+    
+    boolean Equal(double a, double b)
+    {
+        return Math.abs(a - b) < 0.001;
+    }
+    
     void applySelf0(boolean name)
     {
         if (name)
@@ -4587,6 +4964,7 @@
             current.shadow = (float) shadowField.getFloat();
             current.texture = (float) textureField.getFloat();
             current.opacity = (float) opacityField.getFloat();
+            current.parallax = (float) parallaxField.getFloat() - 0.25f;
             current.fakedepth = (float) fakedepthField.getFloat();
             current.shadowbias = (float) shadowbiasField.getFloat();
 
@@ -4599,29 +4977,54 @@
                 {
                     cMaterial mat = copy.material;
                             
-                    colorField.SetToolTipValue((mat.color));
-                    saturationField.SetToolTipValue((mat.modulation));
-                    metalnessField.SetToolTipValue((mat.metalness));
-                    diffuseField.SetToolTipValue((mat.diffuse));
-                    specularField.SetToolTipValue((mat.specular));
-                    shininessField.SetToolTipValue((mat.shininess));
-                    shiftField.SetToolTipValue((mat.shift));
-                    ambientField.SetToolTipValue((mat.ambient));
-                    lightareaField.SetToolTipValue((mat.lightarea));
-                    diffusenessField.SetToolTipValue((mat.factor));
-                    velvetField.SetToolTipValue((mat.velvet));
-                    sheenField.SetToolTipValue((mat.sheen));
-                    subsurfaceField.SetToolTipValue((mat.subsurface));
-                    backlitField.SetToolTipValue((mat.bump));
-                    anisoField.SetToolTipValue((mat.aniso));
-                    anisoVField.SetToolTipValue((mat.anisoV));
-                    cameraField.SetToolTipValue((mat.cameralight));
-                    selfshadowField.SetToolTipValue((mat.diffuseness));
-                    shadowField.SetToolTipValue((mat.shadow));
-                    textureField.SetToolTipValue((mat.texture));
-                    opacityField.SetToolTipValue((mat.opacity));
-                    fakedepthField.SetToolTipValue((mat.fakedepth));
-                    shadowbiasField.SetToolTipValue((mat.shadowbias));
+                    if (!Equal(colorField.getFloat(), mat.color))
+                        colorField.SetToolTipValue((mat.color));
+                    if (!Equal(saturationField.getFloat(), mat.modulation))
+                        saturationField.SetToolTipValue((mat.modulation));
+                    if (!Equal(metalnessField.getFloat(), mat.metalness))
+                        metalnessField.SetToolTipValue((mat.metalness));
+                    if (!Equal(diffuseField.getFloat(), mat.diffuse))
+                        diffuseField.SetToolTipValue((mat.diffuse));
+                    if (!Equal(specularField.getFloat(), mat.specular))
+                        specularField.SetToolTipValue((mat.specular));
+                    if (!Equal(shininessField.getFloat(), mat.shininess))
+                        shininessField.SetToolTipValue((mat.shininess));
+                    if (!Equal(shiftField.getFloat(), mat.shift))
+                        shiftField.SetToolTipValue((mat.shift));
+                    if (!Equal(ambientField.getFloat(), mat.ambient))
+                        ambientField.SetToolTipValue((mat.ambient));
+                    if (!Equal(lightareaField.getFloat(), mat.lightarea))
+                        lightareaField.SetToolTipValue((mat.lightarea));
+                    if (!Equal(diffusenessField.getFloat(), mat.factor))
+                        diffusenessField.SetToolTipValue((mat.factor));
+                    if (!Equal(velvetField.getFloat(), mat.velvet))
+                        velvetField.SetToolTipValue((mat.velvet));
+                    if (!Equal(sheenField.getFloat(), mat.sheen))
+                        sheenField.SetToolTipValue((mat.sheen));
+                    if (!Equal(subsurfaceField.getFloat(), mat.subsurface))
+                        subsurfaceField.SetToolTipValue((mat.subsurface));
+                    if (!Equal(backlitField.getFloat(), mat.bump))
+                        backlitField.SetToolTipValue((mat.bump));
+                    if (!Equal(anisoField.getFloat(), mat.aniso))
+                        anisoField.SetToolTipValue((mat.aniso));
+                    if (!Equal(anisoVField.getFloat(), mat.anisoV))
+                        anisoVField.SetToolTipValue((mat.anisoV));
+                    if (!Equal(cameraField.getFloat(), mat.cameralight))
+                        cameraField.SetToolTipValue((mat.cameralight));
+                    if (!Equal(selfshadowField.getFloat(), mat.diffuseness))
+                        selfshadowField.SetToolTipValue((mat.diffuseness));
+                    if (!Equal(shadowField.getFloat(), mat.shadow))
+                        shadowField.SetToolTipValue((mat.shadow));
+                    if (!Equal(textureField.getFloat(), mat.texture))
+                        textureField.SetToolTipValue((mat.texture));
+                    if (!Equal(opacityField.getFloat(), mat.opacity))
+                        opacityField.SetToolTipValue((mat.opacity));
+                    //if (!Equal(parallaxField.getFloat(), mat.parallax))
+                        parallaxField.SetToolTipValue((mat.parallax));
+                    if (!Equal(fakedepthField.getFloat(), mat.fakedepth))
+                        fakedepthField.SetToolTipValue((mat.fakedepth));
+                    if (!Equal(shadowbiasField.getFloat(), mat.shadowbias))
+                        shadowbiasField.SetToolTipValue((mat.shadowbias));
                 }
                 
                 if (copy.material != null && copy.projectedVertices.length > 0 && copy.projectedVertices[0] != null)
@@ -4656,15 +5059,17 @@
     
     public void stateChanged(ChangeEvent e)
     {
-        //    assert(false);
+        // assert(false);
         if (e.getSource() == versionSlider)
         {
             if (muteSlider)
                 return;
             
+            Replace();
+            
             int version = versionSlider.getInteger();
             
-            if (copy.versionlist[version] != null)
+            if (version != -1 && copy.versionlist[version] != null)
             {
                 copy.versionindex = version;
                 CopyChanged();
@@ -4708,7 +5113,7 @@
             //System.out.println("stateChanged = " + this);
             materialtouched = true;
             
-            if (e.getSource() == colorField && saturationField.getFloat() == 0.001)
+            if (Globals.AUTOSATURATE && e.getSource() == colorField && saturationField.getFloat() == 0.001)
             {
                 saturationField.setFloat(1);
             }
@@ -5023,7 +5428,9 @@
         }
         
         if (previousVersionButton != null && copy.versionlist != null)
-            SetUndoStates();
+            SetVersionStates();
+        
+        cameraView.requestFocusInWindow();
     }
     
     static TweenManager tweenManager = new TweenManager();
@@ -5055,7 +5462,7 @@
 //                group = (Composite) group.get(0);
 //            }
 
-        System.out.println("makeSomething of " + thing);
+        //System.out.println("makeSomething of " + thing);
 
         /*
         if (deselect && jList != null)
@@ -5409,11 +5816,15 @@
 
             copy.versionlist = readobj.versionlist;
             copy.versionindex = readobj.versionindex;
+            copy.versiontable = readobj.versiontable;
             
         if (copy.versionlist == null)
         {
+            // Backward compatibility
             copy.versionlist = new Object3D[100];
             copy.versionindex = -1;
+            
+            //Save(true);
         }
         
             //? SetUndoStates();
@@ -5505,6 +5916,8 @@
 
     void save()
     {
+        Replace();
+        
         if (lastname == null)
         {
             return;
@@ -5747,6 +6160,7 @@
     ButtonGroup buttonGroup;
     
     cGridBag toolboxPanel;
+    cGridBag skyboxPanel;
     cGridBag materialPanel;
     cGridBag ctrlPanel;
     
@@ -5758,6 +6172,7 @@
     boolean materialFlushed;
     Object3D latestObject;
     
+    cGridBag transformPanel;
     cGridBag XYZPanel;
     
     JSplitPane gridPanel;
@@ -5851,6 +6266,7 @@
     cNumberSlider anisoField;
     JLabel anisoVLabel;
     cNumberSlider anisoVField;
+    
     JLabel cameraLabel;
     cNumberSlider cameraField;
     JLabel selfshadowLabel;
@@ -5861,10 +6277,13 @@
     cNumberSlider textureField;
     JLabel opacityLabel;
     cNumberSlider opacityField;
+    JLabel parallaxLabel;
+    cNumberSlider parallaxField;
     JLabel fakedepthLabel;
     cNumberSlider fakedepthField;
     JLabel shadowbiasLabel;
     cNumberSlider shadowbiasField;
+    
     JLabel bumpLabel;
     cNumberSlider bumpField;
     JLabel noiseLabel;

--
Gitblit v1.6.2