From 4a303a7b3635adfee8f46ac76af4e1b7b4a7029b Mon Sep 17 00:00:00 2001
From: Normand Briere <nbriere@noware.ca>
Date: Sun, 08 Sep 2019 15:35:13 -0400
Subject: [PATCH] Fix navigation arrows.

---
 ObjEditor.java | 1641 +++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 1,375 insertions(+), 266 deletions(-)

diff --git a/ObjEditor.java b/ObjEditor.java
index 3d12411..facfbbe 100644
--- a/ObjEditor.java
+++ b/ObjEditor.java
@@ -24,6 +24,7 @@
         matrix.Matrix;
 
 import grafeme.ui.*;
+import org.xj3d.ui.swt.widgets.ImageLoader;
 
 class ObjEditor /*extends JFrame*/ implements iCallBack, ObjectUI,
         ActionListener, ChangeListener,
@@ -34,6 +35,7 @@
         iSendInfo
 //KeyListener
 {
+    public cToggleButton pinButton;
         boolean timeline;
         boolean wasFullScreen;
 
@@ -41,11 +43,72 @@
     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()
+    {
+        cGridBag separator = new cGridBag();
+        separator.add(new JSeparator());
+        separator.preferredHeight = 5;
+        return separator;
+    }
     
     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)
+    {
+        //ImageIcon icon = GetIcon(name);
+        return new cLabel(GetImage(name), border);
     }
 
     cToggleButton GetToggleButton(String name, boolean border)
@@ -60,26 +123,67 @@
         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;
+            
+            if (!Grafreed.isWindows && name.endsWith("jpg"))
+            {
+                try
+                {
+                    // Much faster!
+                    image = JpegLoader.load(name);
+                }
+                catch (Exception e)
+                {
+                    image = javax.imageio.ImageIO.read(ObjEditor.class.getClassLoader().getResourceAsStream(name));
+                }
+            }
+            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());
+//                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)
+        {
+            //icons.put(name, null);
+            return null;
+        }
+    }
+    
+    BufferedImage GetImage(String name)
     {
         try
         {
             BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
 
-            if (image.getWidth() > 48 && image.getHeight() > 48)
-            {
-                BufferedImage resized = new BufferedImage(48, 48, image.getType());
-                Graphics2D g = resized.createGraphics();
-                g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
-                //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-                g.drawImage(image, 0, 0, 48, 48, 0, 0, image.getWidth(), image.getHeight(), null);
-                g.dispose();
-
-                image = resized;
-            }
-
-            javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
-            return icon;
+            return image;
         }
         catch (Exception e)
         {
@@ -222,6 +326,8 @@
         objEditor.ctrlPanel.remove(setupPanel2);
         objEditor.ctrlPanel.remove(objectCommandsPanel);
         objEditor.ctrlPanel.remove(pushPanel);
+        if (versionPanel != null)
+            objEditor.ctrlPanel.remove(versionPanel);
         //objEditor.ctrlPanel.remove(fillPanel);
         
         //Remove(normalpushField);
@@ -268,11 +374,13 @@
         client = inClient;
         copy = client;
 
-        if (copy.versions == null)
-        {
-            copy.versions = new byte[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);
     }
@@ -287,12 +395,6 @@
         client = inClient;
         copy = client;
 
-        if (copy.versions == null)
-        {
-            copy.versions = new byte[100][];
-            copy.versionindex = -1;
-        }
-        
         SetupUI2(callee.GetEditor());
     }
 
@@ -314,7 +416,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())
@@ -325,11 +428,13 @@
         copy = localCopy;
         copy.editWindow = this;
 
-        if (copy.versions == null)
-        {
-//            copy.versions = new byte[100][];
+//        if (copy.versionlist == null)
+//        {
+//            copy.versionlist = new Object3D[100];
 //            copy.versionindex = -1;
-        }
+//            
+//            Save(true);
+//        }
         
         SetupMenu();
 
@@ -349,6 +454,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());
@@ -362,8 +470,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);
@@ -394,10 +505,12 @@
         //povItem.addActionListener(this);
         closeItem.addActionListener(this);
 
-        objectPanel = new JTabbedPane();
+        objectTabbedPane = new JTabbedPane();
         
         ChangeListener changeListener = new ChangeListener()
         {
+            //String name;
+            
             public void stateChanged(ChangeEvent changeEvent)
             {
 //                if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Material") && !materialFlushed)
@@ -416,10 +529,40 @@
 //                        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 = objectTabbedPane.getSelectedIndex() == 5;
+                
+//                refreshContents(false); // To refresh Info tab
+                cameraView.repaint();
             }
         };
-        objectPanel.addChangeListener(changeListener);
+        objectTabbedPane.addChangeListener(changeListener);
     
         toolbarPanel = new JPanel();
         toolbarPanel.setName("Toolbar");
@@ -439,7 +582,9 @@
         toolboxPanel = new cGridBag().setVertical(true);
         //toolboxPanel.setName("Toolbox");
         
-        materialPanel = new cGridBag().setVertical(true);
+        skyboxPanel = new cGridBag().setVertical(true);
+        
+        materialPanel = new cGridBag().setVertical(false);
         //materialPanel.setName("Material");
         
         /*JTextPane*/
@@ -460,7 +605,7 @@
         //infoPanel.setLayout(new BorderLayout());
         //infoPanel.add(createTextPane());
 
-        mainPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, treePanel, objectPanel);
+        mainPanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, treePanel, objectTabbedPane);
         mainPanel.setName("Main");
         mainPanel.setContinuousLayout(true);
         mainPanel.setOneTouchExpandable(true);
@@ -723,6 +868,7 @@
         boolean maximized;
     
         cButton fullscreenLayout;
+        cButton expandedLayout;
 
         void Minimize()
         {
@@ -761,11 +907,23 @@
         
 	cButton minButton;
 	cButton maxButton;
-	cButton fullButton;
+	cButton fullScreenButton;
+	cButton collapseButton;
+        cButton maximize3DButton;
         
+    public void Show3DView()
+    {
+        // bug
+        //gridPanel.setDividerLocation(1.0);
+        //bigPanel.setDividerLocation(0.0);
+        bigThree.ClearUI();
+        bigThree.add(centralPanel);
+        bigThree.FlushUI();
+    }
+
         void ToggleFullScreen()
         {
-GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
+            GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
 
                 cameraView.ToggleFullScreen();
                 
@@ -786,7 +944,7 @@
 // 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;
@@ -797,6 +955,10 @@
                 } else
                 {
                     keepButton = radio.layout;
+                    
+                    radio.layout = twoButton;
+                    Show3DView();
+                        
                     //keeprect = frame.getBounds();
 //                frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
 //                        frame.getToolkit().getScreenSize().height);
@@ -813,31 +975,58 @@
 // 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);
+                    CollapseToolbar();
                 }
             frame.validate();
+            
+            cameraView.requestFocusInWindow();
         }
 
-    private byte[] 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)
         
-        byte[] versions[] = copy.versions;
-        copy.versions = null;
+        assert(!object.HasBigData());
         
-        byte[] compress = Compress(copy);
+        Object3D versions[] = object.versionlist;
+        java.util.Hashtable<java.util.UUID, Object3D> versiontable = object.versiontable; // if Grafreed.grafreed.universe
+        object.versionlist = null;
+        object.versiontable = null;
         
-        copy.versions = versions;
+        Object3D parent = object.parent;
+        object.parent = null;
         
-        copy.RestoreBigData(versiontable);
+        //byte[] compress = Compress(copy);
+        Object3D compress = (Object3D)Grafreed.clone(object);
+        
+        assert(!compress.HasBigData());
+        
+        object.parent = parent;
+        
+        object.versionlist = versions;
+        object.versiontable = versiontable; // if Grafreed.grafreed.universe
+        
+        object.RestoreBigData(Grafreed.grafreed.universe.versiontable);
         
         CameraPane.SWITCH = temp;
         
@@ -965,6 +1154,7 @@
         {
             SetupMaterial(materialPanel);
         }
+        
         //SetupName();
         //SetupViews();
     }
@@ -1004,6 +1194,7 @@
     cGridBag setupPanel2;
     cGridBag objectCommandsPanel;
     cGridBag pushPanel;
+    cGridBag versionPanel;
     cGridBag fillPanel;
 
     JCheckBox AddCheckBox(cGridBag panel, String label, boolean on)
@@ -1166,6 +1357,11 @@
             obj = o;
         }
     }
+    
+    String GetSupportText()
+    {
+        return "Support";
+    }
 
     void SetupUI2(ObjEditor oe)
     {
@@ -1173,6 +1369,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);
@@ -1186,14 +1394,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);
         
@@ -1205,7 +1413,7 @@
         randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
         randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
 
-        link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
+        link2masterCB = AddCheckBox(setupPanel2, GetSupportText(), copy.link2master);
         link2masterCB.setToolTipText("Attach to support");
         
         if (Globals.ADVANCED)
@@ -1238,9 +1446,14 @@
         oe.ctrlPanel.add(objectCommandsPanel);
         oe.ctrlPanel.Return();
 
-    pushPanel = AddSlider(oe.ctrlPanel, "Push", -1, 1, copy.NORMALPUSH, 1.1); // To have the buttons
+    pushPanel = AddSlider(oe.ctrlPanel, "Push", -1, 1, copy.NORMALPUSH * 100, 1.1); // To have the buttons
     normalpushField = (cNumberSlider)pushPanel.getComponent(1);
-    //Return();
+    if (false && copy.versionlist != null && copy.versionindex != -1)
+    {
+        oe.ctrlPanel.Return();
+        versionPanel = AddSlider(oe.ctrlPanel, "Version", 0, copy.VersionCount() - 1, copy.versionindex);
+        versionField = (cNumberSlider)versionPanel.getComponent(1);
+    }
 
         oe.ctrlPanel.Return();
             
@@ -1377,6 +1590,8 @@
 
         return null;
     }
+    
+    int objectTabCount;
 
     void SetupViews()
     {
@@ -1395,22 +1610,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);
@@ -1476,6 +1678,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));
 
@@ -1485,6 +1726,15 @@
         XYZPanel.addComponent(/*BorderLayout.NORTH,*/topView); // Scroll);
         //XYZPanel.setName("XYZ");
 
+        transformPanel.add(resetTransformPanel);
+        
+        cGridBag scalePanel = AddSlider(transformPanel, "Scale", 1, 10, 1);
+        scalePanel.preferredHeight = 2;
+        scaleSlider = (cNumberSlider)scalePanel.getComponent(1);        
+        transformPanel.add(scalePanel);
+        
+        transformPanel.add(XYZPanel);
+        
         /*
         gridPanel = new JPanel(); //new BorderLayout());
         gridPanel.setLayout(new GridLayout(1, 2));
@@ -1492,12 +1742,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);
@@ -1520,25 +1770,43 @@
 
         //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"));
+        
+        objectTabCount = 0;
+        
+        objectTabbedPane.add(skyboxPanel);
+        objectTabbedPane.setIconAt(objectTabCount, GetIcon("icons/skybox.jpg"));
+        objectTabbedPane.setToolTipTextAt(objectTabCount++, "Backgrounds");
+        
+        objectTabbedPane.add(toolboxPanel);
+        objectTabbedPane.setIconAt(objectTabCount, GetIcon("icons/primitives.png"));
+        objectTabbedPane.setToolTipTextAt(objectTabCount++, "Objects & textures");
+
+        objectTabbedPane.add(materialPanel);
+        objectTabbedPane.setIconAt(objectTabCount, GetIcon("icons/material.png"));
+        objectTabbedPane.setToolTipTextAt(objectTabCount++, "Material");
+    
+        figurePanel = new cGridBag();
+        figurePanel.add(new cButton("FIGURES amd POSES coming soon!"));
+        objectTabbedPane.add(figurePanel);
+        objectTabbedPane.setIconAt(objectTabCount, GetIcon("icons/figure.png"));
+        objectTabbedPane.setToolTipTextAt(objectTabCount++, "Figures and poses");
+        
 //        JPanel north = new JPanel(new BorderLayout());
 //        north.setName("Edit");
 //        north.add(ctrlPanel, BorderLayout.NORTH);
 //        objectPanel.add(north);
-        objectPanel.add(editPanel);
-        objectPanel.setIconAt(1, GetIcon("icons/write.png"));
+        objectTabbedPane.add(editPanel);
+        objectTabbedPane.setIconAt(objectTabCount, GetIcon("icons/writewhite.png"));
+        objectTabbedPane.setToolTipTextAt(objectTabCount++, "Edit controls");
         
-        //if (Globals.ADVANCED)
-            objectPanel.add(infoPanel);
-        objectPanel.setIconAt(2, GetIcon("icons/info.png"));
+        objectTabbedPane.add(transformPanel);
+        objectTabbedPane.setIconAt(objectTabCount, GetIcon("icons/XYZ.png"));
+        objectTabbedPane.setToolTipTextAt(objectTabCount++, "TRS transform");
         
-        objectPanel.add(XYZPanel);
-        objectPanel.setIconAt(3, GetIcon("icons/XYZ.png"));
-        
-        objectPanel.add(toolboxPanel);
-        objectPanel.setIconAt(4, GetIcon("icons/primitives.png"));
-
+        patchMaterial = true;
+        cameraView.patchMaterial = this;
+        objectTabbedPane.setSelectedIndex(2);
+                
         /*
         aConstraints.gridx = 0;
         aConstraints.gridwidth = 1;
@@ -1558,7 +1826,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);
@@ -1569,11 +1837,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.SHOWINFO)
+        {
+            objectTabbedPane.add(infoPanel);
+            objectTabbedPane.setIconAt(objectTabCount, GetIcon("icons/info.png"));
+            objectTabbedPane.setToolTipTextAt(objectTabCount++, "Information");
+        }
 
         /*
         cTree jTree = new cTree(null);
@@ -1595,13 +1960,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));
@@ -1634,8 +1999,8 @@
         /**/
 
         bigThree = new cGridBag();
-        bigThree.addComponent(centralPanel);
         bigThree.addComponent(scenePanel);
+        bigThree.addComponent(centralPanel);
         //bigThree.addComponent(XYZPanel);
         
 //                // SIDE EFFECT!!!
@@ -1645,6 +2010,28 @@
 //		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 (CameraPane.FULLSCREEN)
+                            {
+                                ToggleFullScreen();
+                            }
+                            
+//                            if (radio.layout != expandedLayout)
+//                            {
+//                                radio.layout = expandedLayout;
+//                                radio.layout.doClick();
+//                            }
+                        }
+                    }
+                });
+
         framePanel.setContinuousLayout(false);
         framePanel.setOneTouchExpandable(false);
         //.setDividerLocation(0.8);
@@ -1654,7 +2041,7 @@
 
         frame.getContentPane().setLayout(new BorderLayout());
         /**/
-        JTabbedPane worldPane = new JTabbedPane();
+        //JTabbedPane worldPane = new JTabbedPane();
         //worldPane.add(bigPanel);
         //worldPane.add(worldPanel);
                 /**/
@@ -1664,11 +2051,11 @@
 
 //            aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc);
 
-        frame.setSize(1280, 860);
+        frame.setSize(1280, 900);
         
                     cameraView.requestFocusInWindow();
                     
-        gridPanel.setDividerLocation(1.0);
+//        gridPanel.setDividerLocation(1.0);
         
         frame.validate();
 
@@ -1677,7 +2064,6 @@
         frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
         frame.addWindowListener(new WindowAdapter()
         {
-
             public void windowClosing(WindowEvent e)
             {
                 Close();
@@ -1700,28 +2086,484 @@
         ctrlPanel.removeAll();
     }
 
-    void SetupMaterial(cGridBag panel)
+    void SetupMaterial(cGridBag materialpanel)
     {
-         /*
+        cGridBag presetpanel = new cGridBag().setVertical(true);
+        
+        cLabel skin = GetLabel("icons/shadericons/shadericon00000.png", !Globals.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);
+                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);
+                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", !Globals.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", !Globals.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", !Globals.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", !Globals.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", !Globals.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", !Globals.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", !Globals.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", !Globals.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", !Globals.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", !Globals.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", !Globals.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", !Globals.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", !Globals.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", !Globals.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", !Globals.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", !Globals.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 borderShader = GetLabel("icons/shadericons/borderfade.jpg", !Globals.NIMBUSLAF);
+        borderShader.setToolTipText("Border fade");
+        borderShader.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                borderfadeField.setFloat(0.4);
+                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()
+        {
+            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", !Globals.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", !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.4);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(shadowShader);
+        
+        cLabel para0 = GetLabel("icons/shadericons/parallax0.png", !Globals.NIMBUSLAF);
+        para0.setToolTipText("No parallax");
+        para0.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                parallaxField.setFloat(0.125);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(para0);
+        
+        cLabel para1 = GetLabel("icons/shadericons/parallax1.png", !Globals.NIMBUSLAF);
+        para1.setToolTipText("With parallax");
+        para1.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                parallaxField.setFloat(0.13);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(para1);
+        
+        cLabel para2 = GetLabel("icons/shadericons/parallax2.png", !Globals.NIMBUSLAF);
+        para2.setToolTipText("Reset parallax");
+        para2.addMouseListener(new MouseAdapter()
+        {
+            public void mouseClicked(MouseEvent e)
+            {
+                parallaxField.setFloat(0.14);
+
+                materialtouched = true;
+                applySelf();
+            }
+        });
+        presetpanel.add(para2);
+        
+        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);
             
-        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);
         }
@@ -1739,27 +2581,61 @@
         //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
 
         cGridBag colorSection = new cGridBag().setVertical(true);
+
+        cGridBag huepanel = new cGridBag();
+            cGridBag huelabel = new cGridBag();
+        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
+            
+        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);
         
@@ -1815,7 +2691,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);
         
@@ -1878,7 +2754,7 @@
         specularSection.add(anisoV);
 
 
-        panel.add(new JSeparator());
+        panel.add(GetSeparator());
         
         panel.add(specularSection);
         
@@ -1904,12 +2780,12 @@
                 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);
-
+        cGridBag parallax = new cGridBag();
+                parallax.add(parallaxLabel = new JLabel("Parallax")); // , aConstraints);
+                parallaxLabel.setHorizontalAlignment(SwingConstants.TRAILING);
+                parallax.add(parallaxField = new cNumberSlider(this, 0.001, 0.25, -0.125)); // , aConstraints);
+        colorSection.add(parallax);
+        
         //panel.add(new JSeparator());
         
         //panel.add(globalSection);
@@ -1954,7 +2830,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);
         
@@ -2941,7 +3817,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);
@@ -2961,6 +3837,7 @@
         shadowField.setFloat(mat.shadow);
         textureField.setFloat(mat.texture);
         opacityField.setFloat(mat.opacity);
+        parallaxField.setFloat(mat.parallax + 0.125f);
         fakedepthField.setFloat(mat.fakedepth);
         shadowbiasField.setFloat(mat.shadowbias);
         bumpField.setInteger(1); // dec 2013
@@ -3003,32 +3880,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);
     }
@@ -3148,6 +4001,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;
@@ -3252,6 +4116,7 @@
         } else if (event.getSource() == liveCB)
         {
             copy.live ^= true;
+            objEditor.refreshContents(true); // To show item colors
             return;
         } else if (event.getSource() == selectableCB)
         {
@@ -3261,16 +4126,31 @@
         {
             copy.hide ^= true;
             copy.Touch(); // display list issue
-            objEditor.refreshContents();
+            objEditor.refreshContents(true); // To show item colors
             return;
         } else if (event.getSource() == link2masterCB)
         {
             copy.link2master ^= true;
+            objEditor.refreshContents();
             return;
         }
         if (event.getSource() == randomCB)
         {
             copy.random ^= true;
+            if (this instanceof RandomEditor)
+            {
+                cGridBag itemPanel = ((RandomEditor)this).itemPanel;
+                itemPanel.getComponent(0).setEnabled(!copy.random);
+                
+                // Tooltip?
+                if (copy.random)
+                {
+                }
+                else
+                {
+                }
+            }
+            
             objEditor.refreshContents();
             return;
         }
@@ -3326,7 +4206,7 @@
             //System.out.println("ObjEditor " + event);
             applySelf0(true);
             //parent.applySelf();
-            objEditor.refreshContents();
+     // conflicts with requestFocus       objEditor.refreshContents();
         } else if (source == resetButton)
         {
             CameraPane.fullreset = true;
@@ -3506,17 +4386,37 @@
 
     void New()
     {
-        while (copy.Size() > 1)
+        copy.skyboxname = "cubemaps/penguins-skyboxes/yonder";
+        copy.skyboxext = "jpg";
+        
+        copy.versionlist = null;
+        copy.versionindex = -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));
+            cameraView.SetLight(GetCamera(copy, 4));
         }
         
         ResetModel();
+        
+        DuplicateVersion();
+        
+        this.SetVersionStates();
         objEditor.refreshContents();
     }
     
     static public byte[] Compress(Object3D o)
     {
+        // Slower to actually compress.
         try
         {
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -3618,6 +4518,7 @@
     {
         //Save(true);
         Replace();
+        SetVersionStates();
     }
     
     private boolean Equal(byte[] compress, byte[] name)
@@ -3636,31 +4537,56 @@
         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];
+        }
+        
+        if (copy.versionlist[copy.versionindex] == null)
+            copy.versionindex -= 1;
+        
+        if (copy.versionindex != -1)
+            CopyChanged(copy);
+        
+        SetVersionStates();
+        
+        SetCameras();
+    }
     
-    public boolean Save(boolean user)
+    public boolean DuplicateVersion() // boolean user)
     {
         System.err.println("Save");
+        //Replace();
         
-        cRadio tab = GetCurrentTab();
+        if (copy.versionlist == null)
+        {
+            copy.versionlist = new Object3D[100];
+            copy.versionindex = -1;
+        }
         
-        byte[] compress = CompressCopy();
+        Object3D compress = Duplicate(copy); // Saved version. No need for "Replace"?
         
         boolean thesame = false;
         
-        // Quick heuristic using length. Works only when stream is compressed.
-        if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-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)
         {
+            for (int i = copy.versionlist.length; --i > copy.versionindex+1;)
+            {
+                copy.versionlist[i] = copy.versionlist[i-1];
+            }
+            
             //tab.user[tab.versionindex] = user;
             //boolean increment = true; // tab.graphs[tab.versionindex] == null;
             
-            copy.versions[++copy.versionindex] = compress;
+            copy.versionlist[++copy.versionindex] = compress;
             
             // if (increment)
             //     tab.versionindex++;
@@ -3670,13 +4596,13 @@
 
         //assert(hashtable.isEmpty());
         
-        for (int i = copy.versionindex+1; i < copy.versions.length; i++)
-        {
-            //tab.user[i] = false;
-            copy.versions[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)
@@ -3699,39 +4625,82 @@
         
         return !thesame;
     }
-
-    void CopyChanged(Object3D obj)
+    
+    boolean flashIt = true;
+        
+    void RefreshSelection()
     {
-        SetUndoStates();
+        Object3D selection = new Object3D();
+        
+        if (objEditor.copy.selection == null)
+        {
+            objEditor.copy.selection = new Object3D();
+        }
+        
+        for (int i = 0; i < objEditor.copy.selection.size(); i++)
+        {
+            Object3D elem = objEditor.copy.selection.elementAt(i);
+            
+            Object3D obj = objEditor.copy.GetObject(elem.GetUUID());
+            
+            if (obj == null)
+            {
+                objEditor.copy.selection.remove(i--);
+            }
+            else
+            {
+                selection.add(obj);
+                objEditor.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 changed)
+    {
+        Object3D obj = (Object3D)Grafreed.clone(changed.versionlist[copy.versionindex]);
+        
+        assert(!obj.HasBigData());
         
         boolean temp = CameraPane.SWITCH;
         CameraPane.SWITCH = false;
         
-        copy.ExtractBigData(versiontable);
+        changed.ExtractBigData(Grafreed.grafreed.universe.versiontable);
         
-        copy.clear();
-        
+        changed.clear();
+
+        obj.deepCopyNode(changed);
+                
         for (int i=0; i<obj.Size(); i++)
         {
-            copy.add(obj.get(i));
+            changed.add(obj.get(i));
         }
         
-        copy.RestoreBigData(versiontable);
+        changed.RestoreBigData(Grafreed.grafreed.universe.versiontable);
         
         CameraPane.SWITCH = temp;
         
+        if (objEditor == this)
+            RefreshSelection();
         //assert(hashtable.isEmpty());
         
-        copy.Touch();
+        objEditor.copy.Touch();
         
         ResetModel();
-        copy.HardTouch(); // recompile?
+        objEditor.copy.HardTouch(); // recompile?
         
         cRadio ab;
-        for (java.util.Enumeration e = buttonGroup.getElements(); e.hasMoreElements();)
+        for (java.util.Enumeration e = objEditor.buttonGroup.getElements(); e.hasMoreElements();)
         {
             ab = (cRadio)e.nextElement();
-            Object3D test = copy.GetObject(ab.object.GetUUID());
+            Object3D test = objEditor.copy.GetObject(ab.object.GetUUID());
             //ab.camera = (Camera)copy.GetObject(ab.camera.GetUUID());
             if (test != null)
             {
@@ -3740,53 +4709,72 @@
             }
         }
         
-        refreshContents();
+        objEditor.refreshContents(true);
     }
     
-    cButton undoButton;
+    cButton previousVersionButton;
     cButton restoreButton;
     cButton replaceButton;
-    cButton redoButton;
+    cButton nextVersionButton;
+    cButton saveVersionButton;
+    cButton deleteVersionButton;
         
     boolean muteSlider;
     
     int VersionCount()
     {
-        int count = 0;
-        
-        for (int i = copy.versions.length; --i >= 0;)
-        {
-            if (copy.versions[i] != null)
-                count++;
-        }
-        
-        return count;
+        return copy.VersionCount();
     }
     
-    void SetUndoStates()
+    public cGridBag versionSliderPane;
+    
+    void SetVersionStates()
     {
-        cRadio tab = GetCurrentTab();
+        //if (true)
+        //    return;
+                    
+        //cRadio tab = GetCurrentTab();
         
-        restoreButton.setEnabled(copy.versionindex != -1);
-        replaceButton.setEnabled(copy.versionindex != -1);
-        
-        undoButton.setEnabled(copy.versionindex > 0);
-        redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
-        
-        muteSlider = true;
-        versionSlider.setMaximum(VersionCount() - 1);
-        versionSlider.setInteger(copy.versionindex);
-        muteSlider = false;
+        if (copy.versionindex == -2)
+        {
+            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 != null && 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 Undo()
+    public boolean PreviousVersion()
     {
         // Option?
         Replace();
         
-        System.err.println("Undo");
+        //System.err.println("Previous");
         
-        cRadio tab = GetCurrentTab();
+        //cRadio tab = GetCurrentTab();
         
         if (copy.versionindex == 0)
         {
@@ -3809,7 +4797,11 @@
 
         copy.versionindex -= 1;
 
-        CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
+        CopyChanged(copy);
+        
+        SetVersionStates();
+        
+        SetCameras();
         
         return true;
     }
@@ -3818,44 +4810,49 @@
     {
         System.err.println("Restore");
         
-        cRadio tab = GetCurrentTab();
+        //cRadio tab = GetCurrentTab();
         
-        if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
+        if (copy.versionindex == -1 || copy.versionlist[copy.versionindex] == null)
         {
             java.awt.Toolkit.getDefaultToolkit().beep();
             return false;
         }
 
-        CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
+        //CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
+        CopyChanged(copy);
+        
+        SetVersionStates();
+        
+        SetCameras();
         
         return true;
     }
 
     public boolean Replace()
     {
-        System.err.println("Replace");
+        //System.err.println("Replace");
         
-        cRadio tab = GetCurrentTab();
+        //cRadio tab = GetCurrentTab();
         
-        if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
+        if (copy.versionindex == -1 || copy.versionlist[copy.versionindex] == null)
         {
             // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
             return false;
         }
 
-        copy.versions[copy.versionindex] = CompressCopy();
+        copy.versionlist[copy.versionindex] = Duplicate(copy);
         
         return true;
     }
 
-    public void Redo()
+    public void NextVersion()
     {
         // Option?
         Replace();
         
-        cRadio tab = GetCurrentTab();
+        //cRadio tab = GetCurrentTab();
         
-        if (copy.versions[copy.versionindex + 1] == null)
+        if (copy.versionlist[copy.versionindex + 1] == null)
         {
             java.awt.Toolkit.getDefaultToolkit().beep();
             return;
@@ -3863,12 +4860,28 @@
 
         copy.versionindex += 1;
 
-        CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
+        CopyChanged(copy);
         
         //if (!tab.user[tab.versionindex])
         //    tab.graphs[tab.versionindex] = null;
+        
+        SetVersionStates();
+        
+        SetCameras();
     }
 
+    void SetCameras()
+    {
+        if (copy == Grafreed.grafreed.universe)
+        {
+            Camera neweye = (Camera)copy.GetObject(cameraView.cameras[cameraView.cameracount^1].GetUUID());
+            Camera newlight = (Camera)copy.GetObject(cameraView.LightCamera().GetUUID());
+
+            cameraView.SetCamera(neweye);
+            cameraView.SetLight(newlight);
+        }
+    }
+    
         void ImportGFD()
         {
             FileDialog browser = new FileDialog(objEditor.frame, "Import GrafreeD", FileDialog.LOAD);
@@ -4060,6 +5073,12 @@
 //            else
 //		applySelf(true);
 //	}
+    
+    boolean Equal(double a, double b)
+    {
+        return Math.abs(a - b) < 0.001;
+    }
+    
     void applySelf0(boolean name)
     {
         if (name)
@@ -4077,7 +5096,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();
@@ -4097,6 +5116,7 @@
             current.shadow = (float) shadowField.getFloat();
             current.texture = (float) textureField.getFloat();
             current.opacity = (float) opacityField.getFloat();
+            current.parallax = (float) parallaxField.getFloat() - 0.125f;
             current.fakedepth = (float) fakedepthField.getFloat();
             current.shadowbias = (float) shadowbiasField.getFloat();
 
@@ -4109,29 +5129,54 @@
                 {
                     cMaterial mat = copy.material;
                             
-                    colorField.SetToolTipValue((mat.color));
-                    modulationField.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)
@@ -4163,22 +5208,57 @@
     }
 
     cNumberSlider versionSlider;
+    cNumberSlider versionField;
     
+    cNumberSlider scaleSlider;
+    
+    void ScaleSelection(int scale)
+    {
+    }
+            
     public void stateChanged(ChangeEvent e)
     {
-        //    assert(false);
+        // assert(false);
+        // Main version slider
         if (e.getSource() == versionSlider)
         {
             if (muteSlider)
                 return;
             
+            Replace();
+            
             int version = versionSlider.getInteger();
             
-            if (copy.versions[version] != null)
+            if (version != -1 && copy.versionlist[version] != null)
             {
-                CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
+                copy.versionindex = version;
+                CopyChanged(copy);
+                SetVersionStates();
+                SetCameras();
             }
             
+            return;
+        }
+
+        // Version slider of edited object
+        if (e.getSource() == versionField)
+        {
+            int version = versionField.getInteger();
+            
+            if (version != -1 && copy.versionindex != version && copy.versionlist[version] != null)
+            {
+                copy.versionindex = version;
+                CopyChanged(copy);
+            }
+            
+            return;
+        }
+        
+        if (e.getSource() == scaleSlider)
+        {
+            int scale = scaleSlider.getInteger();
+
+            ScaleSelection(scale);
             return;
         }
 
@@ -4216,6 +5296,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);
@@ -4265,7 +5351,7 @@
         }
         
         if (normalpushField != null)
-                copy.NORMALPUSH = (float)normalpushField.getFloat()/100;
+                copy.NORMALPUSH = (float)normalpushField.getFloat() / 100;
     }
 
         void SnapObject()
@@ -4515,6 +5601,7 @@
         {
             if (GetTree() != null)
             {
+                GetTree().revalidate();
                 GetTree().repaint();
             }
 
@@ -4523,6 +5610,11 @@
             ctrlPanel.validate(); // ? new
             ctrlPanel.repaint();
         }
+        
+        if (previousVersionButton != null && copy.versionlist != null)
+            SetVersionStates();
+        
+        cameraView.requestFocusInWindow();
     }
     
     static TweenManager tweenManager = new TweenManager();
@@ -4554,7 +5646,7 @@
 //                group = (Composite) group.get(0);
 //            }
 
-        System.out.println("makeSomething of " + thing);
+        //System.out.println("makeSomething of " + thing);
 
         /*
         if (deselect && jList != null)
@@ -4633,7 +5725,7 @@
     void ResetModel()
     {
         //assert(copy instanceof Composite);
-        Object3D /*Composite*/ group = (Object3D /*Composite*/) copy;
+        Object3D /*Composite*/ group = (Object3D /*Composite*/) objEditor.copy;
 
 // necessary?		group.selection = new Object3D(); // java.util.Vector();
 
@@ -4644,14 +5736,14 @@
         //group.refreshEditWindow();
         //refreshContents();
 
-        if (copy.selection == null)
+        if (objEditor.copy.selection == null)
         {
-            copy.selection = new Object3D();
+            objEditor.copy.selection = new Object3D();
         }
 
-        for (int j = 0; j < copy.selection.size(); j++)
+        for (int j = 0; j < objEditor.copy.selection.size(); j++)
         {
-            Object3D item = copy.selection.get(j);
+            Object3D item = objEditor.copy.selection.get(j);
 
             if (item instanceof cGroup && ((cGroup) item).transientlink)
             {
@@ -4660,15 +5752,15 @@
 
             if (item.count <= 1) // ??? == 0)
             {
-                copy.selection.remove(item);
+                objEditor.copy.selection.remove(item);
             }
         }
 
         boolean first = true;
 
-        for (int i = copy.selection.size(); --i >= 0;)
+        for (int i = objEditor.copy.selection.size(); --i >= 0;)
         {
-            Object3D item = copy.selection.get(i);
+            Object3D item = objEditor.copy.selection.get(i);
 
             if (item instanceof cGroup && ((cGroup) item).transientlink)
             {
@@ -4853,6 +5945,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);
@@ -4904,16 +5998,22 @@
                 c.addChild(csg);
             }
 
-            copy.versions = readobj.versions;
+            copy.versionlist = readobj.versionlist;
             copy.versionindex = readobj.versionindex;
+            copy.versiontable = readobj.versiontable;
             
-        if (copy.versions == null)
+        if (copy.versionlist == null)
         {
-            copy.versions = new byte[100][];
+            // Backward compatibility
+            copy.versionlist = new Object3D[100];
             copy.versionindex = -1;
+            
+            //Save(true);
         }
         
             //? SetUndoStates();
+            
+            cameraView.RevertCamera();
             
             ResetModel();
             copy.HardTouch(); // recompile?
@@ -4925,7 +6025,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)
@@ -5002,6 +6102,8 @@
 
     void save()
     {
+        Replace();
+        
         if (lastname == null)
         {
             return;
@@ -5244,17 +6346,20 @@
     ButtonGroup buttonGroup;
     
     cGridBag toolboxPanel;
+    cGridBag skyboxPanel;
     cGridBag materialPanel;
     cGridBag ctrlPanel;
+    cGridBag figurePanel;
     
     JScrollPane infoPanel;
     
     cGridBag optionsPanel;
     
-    JTabbedPane objectPanel;
+    JTabbedPane objectTabbedPane;
     boolean materialFlushed;
     Object3D latestObject;
     
+    cGridBag transformPanel;
     cGridBag XYZPanel;
     
     JSplitPane gridPanel;
@@ -5317,7 +6422,7 @@
     JLabel colorLabel;
     cNumberSlider colorField;
     JLabel modulationLabel;
-    cNumberSlider modulationField;
+    cNumberSlider saturationField;
     JLabel metalnessLabel;
     cNumberSlider metalnessField;
     JLabel diffuseLabel;
@@ -5348,6 +6453,7 @@
     cNumberSlider anisoField;
     JLabel anisoVLabel;
     cNumberSlider anisoVField;
+    
     JLabel cameraLabel;
     cNumberSlider cameraField;
     JLabel selfshadowLabel;
@@ -5358,10 +6464,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