Normand Briere
2019-07-19 e79247ef52a0bbb3864d46bb1e2c716005b3ecf3
ObjEditor.java
....@@ -44,61 +44,47 @@
4444
4545 cButton GetButton(String name, boolean border)
4646 {
47
- try
48
- {
49
- ImageIcon icon = GetIcon(name);
50
- return new cButton(icon, border);
51
- }
52
- catch (Exception e)
53
- {
54
- return new cButton(name, border);
55
- }
47
+ ImageIcon icon = GetIcon(name);
48
+ return new cButton(icon, border);
5649 }
5750
5851 cToggleButton GetToggleButton(String name, boolean border)
5952 {
60
- try
61
- {
62
- ImageIcon icon = GetIcon(name);
63
- return new cToggleButton(icon, border);
64
- }
65
- catch (Exception e)
66
- {
67
- return new cToggleButton(name, border);
68
- }
53
+ ImageIcon icon = GetIcon(name);
54
+ return new cToggleButton(icon, border);
6955 }
7056
7157 cCheckBox GetCheckBox(String name, boolean border)
7258 {
59
+ ImageIcon icon = GetIcon(name);
60
+ return new cCheckBox(icon, border);
61
+ }
62
+
63
+ private ImageIcon GetIcon(String name)
64
+ {
7365 try
7466 {
75
- ImageIcon icon = GetIcon(name);
76
- return new cCheckBox(icon, border);
67
+ BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
68
+
69
+ if (image.getWidth() != 24 && image.getHeight() != 24)
70
+ {
71
+ BufferedImage resized = new BufferedImage(24, 24, image.getType());
72
+ Graphics2D g = resized.createGraphics();
73
+ g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
74
+ //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
75
+ g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
76
+ g.dispose();
77
+
78
+ image = resized;
79
+ }
80
+
81
+ javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
82
+ return icon;
7783 }
7884 catch (Exception e)
7985 {
80
- return new cCheckBox(name, border);
86
+ return null;
8187 }
82
- }
83
-
84
- private ImageIcon GetIcon(String name) throws IOException
85
- {
86
- BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
87
-
88
- if (image.getWidth() != 24 && image.getHeight() != 24)
89
- {
90
- BufferedImage resized = new BufferedImage(24, 24, image.getType());
91
- Graphics2D g = resized.createGraphics();
92
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
93
- //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
94
- g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
95
- g.dispose();
96
-
97
- image = resized;
98
- }
99
-
100
- javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
101
- return icon;
10288 }
10389
10490 // SCRIPT
....@@ -282,6 +268,12 @@
282268 client = inClient;
283269 copy = client;
284270
271
+ if (copy.versions == null)
272
+ {
273
+ copy.versions = new byte[100][];
274
+ copy.versionindex = -1;
275
+ }
276
+
285277 // "this" is not called: SetupUI2(objEditor);
286278 }
287279
....@@ -295,6 +287,12 @@
295287 client = inClient;
296288 copy = client;
297289
290
+ if (copy.versions == null)
291
+ {
292
+ copy.versions = new byte[100][];
293
+ copy.versionindex = -1;
294
+ }
295
+
298296 SetupUI2(callee.GetEditor());
299297 }
300298
....@@ -309,7 +307,7 @@
309307 //localCopy.parent = null;
310308
311309 frame = new JFrame();
312
- frame.setUndecorated(true);
310
+ frame.setUndecorated(false);
313311 objEditor = this;
314312 this.callee = callee;
315313
....@@ -327,6 +325,12 @@
327325 copy = localCopy;
328326 copy.editWindow = this;
329327
328
+ if (copy.versions == null)
329
+ {
330
+ copy.versions = new byte[100][];
331
+ copy.versionindex = -1;
332
+ }
333
+
330334 SetupMenu();
331335
332336 //SetupName(objEditor); // new
....@@ -350,7 +354,7 @@
350354 frame.setMenuBar(menuBar = new MenuBar());
351355 menuBar.add(fileMenu = new Menu("File"));
352356 fileMenu.add(newItem = new MenuItem("New"));
353
- fileMenu.add(loadItem = new MenuItem("Open..."));
357
+ fileMenu.add(openItem = new MenuItem("Open..."));
354358
355359 //oe.menuBar.add(menu = new Menu("Include"));
356360 Menu menu = new Menu("Import");
....@@ -382,7 +386,7 @@
382386 }
383387
384388 newItem.addActionListener(this);
385
- loadItem.addActionListener(this);
389
+ openItem.addActionListener(this);
386390 saveItem.addActionListener(this);
387391 saveAsItem.addActionListener(this);
388392 exportAsItem.addActionListener(this);
....@@ -419,11 +423,12 @@
419423
420424 toolbarPanel = new JPanel();
421425 toolbarPanel.setName("Toolbar");
426
+
422427 treePanel = new cGridBag();
423428 treePanel.setName("Tree");
424429
425430 editPanel = new cGridBag().setVertical(true);
426
- editPanel.setName("Edit");
431
+ //editPanel.setName("Edit");
427432
428433 ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout());
429434
....@@ -432,10 +437,10 @@
432437 editPanel.add(ctrlPanel);
433438
434439 toolboxPanel = new cGridBag().setVertical(false);
435
- toolboxPanel.setName("Toolbox");
440
+ //toolboxPanel.setName("Toolbox");
436441
437442 materialPanel = new cGridBag().setVertical(true);
438
- materialPanel.setName("Material");
443
+ //materialPanel.setName("Material");
439444
440445 /*JTextPane*/
441446 infoarea = createTextPane();
....@@ -443,14 +448,15 @@
443448
444449 infoarea.setEditable(true);
445450 SetText();
451
+
446452 // infoarea.setFont(infoarea.getFont().deriveFont(10, 14f));
447453 // infoarea.setOpaque(false);
448454 // //infoarea.setForeground(textcolor);
449455 // TEXTAREA infoarea.setLineWrap(true);
450456 // TEXTAREA infoarea.setWrapStyleWord(true);
451457 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
452
- infoPanel.setPreferredSize(new Dimension(50, 200));
453
- infoPanel.setName("Info");
458
+ infoPanel.setPreferredSize(new Dimension(1, 1));
459
+ //infoPanel.setName("Info");
454460 //infoPanel.setLayout(new BorderLayout());
455461 //infoPanel.add(createTextPane());
456462
....@@ -699,8 +705,8 @@
699705 }
700706 }
701707
702
-static GraphicsDevice device = GraphicsEnvironment
703
- .getLocalGraphicsEnvironment().getScreenDevices()[0];
708
+//static GraphicsDevice device = GraphicsEnvironment
709
+// .getLocalGraphicsEnvironment().getScreenDevices()[0];
704710
705711 Rectangle keeprect;
706712 cRadio radio;
....@@ -721,10 +727,19 @@
721727 void Minimize()
722728 {
723729 frame.setState(Frame.ICONIFIED);
730
+ frame.validate();
724731 }
725732
733
+// artifactURI=null, type=0, property=${file.reference.jfxrt.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@6767876f, broken=false, additional={}
734
+// artifactURI=null, type=0, property=${file.reference.mac-ui.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@16bdc817, broken=false, additional={}
735
+// artifactURI=null, type=0, property=${file.reference.classes.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@9daa9c17, broken=false, additional={}
726736 void Maximize()
727737 {
738
+ if (CameraPane.FULLSCREEN)
739
+ {
740
+ ToggleFullScreen();
741
+ }
742
+
728743 if (maximized)
729744 {
730745 frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
....@@ -732,22 +747,36 @@
732747 else
733748 {
734749 keeprect = frame.getBounds();
735
- Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
736
- Dimension rect2 = frame.getToolkit().getScreenSize();
737
- frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
750
+// Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
751
+// Dimension rect2 = frame.getToolkit().getScreenSize();
752
+// frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
738753 // frame.setState(Frame.MAXIMIZED_BOTH);
754
+ frame.setBounds(frame.getGraphicsConfiguration().getBounds());
739755 }
740756
741757 maximized ^= true;
758
+
759
+ frame.validate();
742760 }
761
+
762
+ cButton minButton;
763
+ cButton maxButton;
764
+ cButton fullButton;
743765
744766 void ToggleFullScreen()
745767 {
768
+GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
769
+
746770 cameraView.ToggleFullScreen();
747771
748772 if (!CameraPane.FULLSCREEN)
749773 {
750774 device.setFullScreenWindow(null);
775
+ frame.dispose();
776
+ frame.setUndecorated(false);
777
+ frame.validate();
778
+ frame.setVisible(true);
779
+
751780 //frame.setVisible(false);
752781 // frame.removeNotify();
753782 // frame.setUndecorated(false);
....@@ -757,7 +786,7 @@
757786 // X frame.getContentPane().remove(/*"Center",*/bigThree);
758787 // X framePanel.add(bigThree);
759788 // X frame.getContentPane().add(/*"Center",*/framePanel);
760
- framePanel.setDividerLocation(1);
789
+ framePanel.setDividerLocation(46);
761790
762791 //frame.setVisible(true);
763792 radio.layout = keepButton;
....@@ -772,7 +801,12 @@
772801 // frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
773802 // frame.getToolkit().getScreenSize().height);
774803 //frame.setVisible(false);
804
+
805
+ frame.dispose();
806
+ frame.setUndecorated(true);
775807 device.setFullScreenWindow(frame);
808
+ frame.validate();
809
+ frame.setVisible(true);
776810 // frame.removeNotify();
777811 // frame.setUndecorated(true);
778812 // frame.addNotify();
....@@ -785,7 +819,30 @@
785819 radio.layout.doClick();
786820 //frame.setVisible(true);
787821 }
822
+ frame.validate();
788823 }
824
+
825
+ private byte[] CompressCopy()
826
+ {
827
+ boolean temp = CameraPane.SWITCH;
828
+ CameraPane.SWITCH = false;
829
+
830
+ copy.ExtractBigData(versiontable);
831
+ // if (copy == client)
832
+
833
+ byte[] versions[] = copy.versions;
834
+ copy.versions = null;
835
+
836
+ byte[] compress = Compress(copy);
837
+
838
+ copy.versions = versions;
839
+
840
+ copy.RestoreBigData(versiontable);
841
+
842
+ CameraPane.SWITCH = temp;
843
+
844
+ return compress;
845
+ }
789846
790847 private JTextPane createTextPane()
791848 {
....@@ -1117,7 +1174,7 @@
11171174 namePanel = new cGridBag();
11181175
11191176 nameField = AddText(namePanel, copy.GetName());
1120
- namePanel.add(nameField);
1177
+ namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
11211178 oe.ctrlPanel.add(namePanel);
11221179
11231180 oe.ctrlPanel.Return();
....@@ -1142,13 +1199,14 @@
11421199 rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
11431200 rewindCB.setToolTipText("Rewind animation");
11441201
1145
- randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1202
+ randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
11461203 randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11471204
1205
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1206
+ link2masterCB.setToolTipText("Attach to support");
1207
+
11481208 if (Globals.ADVANCED)
11491209 {
1150
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1151
- link2masterCB.setToolTipText("Attach to support");
11521210 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
11531211 speedupCB.setToolTipText("Option motion capture");
11541212 }
....@@ -1422,6 +1480,7 @@
14221480 XYZPanel.addComponent(/*BorderLayout.SOUTH,*/sideView); // Scroll);
14231481 XYZPanel.addComponent(/*BorderLayout.CENTER,*/frontView); // Scroll);
14241482 XYZPanel.addComponent(/*BorderLayout.NORTH,*/topView); // Scroll);
1483
+ //XYZPanel.setName("XYZ");
14251484
14261485 /*
14271486 gridPanel = new JPanel(); //new BorderLayout());
....@@ -1459,13 +1518,23 @@
14591518 //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
14601519 //tmp.setName("Edit");
14611520 objectPanel.add(materialPanel);
1521
+ objectPanel.setIconAt(0, GetIcon("icons/material.png"));
14621522 // JPanel north = new JPanel(new BorderLayout());
14631523 // north.setName("Edit");
14641524 // north.add(ctrlPanel, BorderLayout.NORTH);
14651525 // objectPanel.add(north);
14661526 objectPanel.add(editPanel);
1467
- objectPanel.add(infoPanel);
1527
+ objectPanel.setIconAt(1, GetIcon("icons/write.png"));
1528
+
1529
+ //if (Globals.ADVANCED)
1530
+ objectPanel.add(infoPanel);
1531
+ objectPanel.setIconAt(2, GetIcon("icons/info.png"));
1532
+
1533
+ objectPanel.add(XYZPanel);
1534
+ objectPanel.setIconAt(3, GetIcon("icons/XYZ.png"));
1535
+
14681536 objectPanel.add(toolboxPanel);
1537
+ objectPanel.setIconAt(4, GetIcon("icons/primitives.png"));
14691538
14701539 /*
14711540 aConstraints.gridx = 0;
....@@ -1486,7 +1555,7 @@
14861555 scrollpane.addMouseWheelListener(this); // Default not fast enough
14871556
14881557 /*JTabbedPane*/ scenePanel = new cGridBag();
1489
- scenePanel.preferredWidth = 6;
1558
+ scenePanel.preferredWidth = 5;
14901559
14911560 JTabbedPane tabbedPane = new JTabbedPane();
14921561 tabbedPane.add(scrollpane);
....@@ -1564,7 +1633,7 @@
15641633 bigThree = new cGridBag();
15651634 bigThree.addComponent(scenePanel);
15661635 bigThree.addComponent(centralPanel);
1567
- bigThree.addComponent(XYZPanel);
1636
+ //bigThree.addComponent(XYZPanel);
15681637
15691638 // // SIDE EFFECT!!!
15701639 // aConstraints.gridx = 0;
....@@ -1573,9 +1642,9 @@
15731642 // aConstraints.gridheight = 1;
15741643
15751644 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1576
- framePanel.setContinuousLayout(true);
1577
- framePanel.setOneTouchExpandable(true);
1578
- framePanel.setDividerLocation(0.8);
1645
+ framePanel.setContinuousLayout(false);
1646
+ framePanel.setOneTouchExpandable(false);
1647
+ //.setDividerLocation(0.8);
15791648 //framePanel.setDividerSize(15);
15801649 //framePanel.setResizeWeight(0.15);
15811650 framePanel.setName("Frame");
....@@ -1594,12 +1663,13 @@
15941663
15951664 frame.setSize(1280, 860);
15961665
1597
- frame.validate();
1598
- frame.setVisible(true);
1599
-
16001666 cameraView.requestFocusInWindow();
16011667
16021668 gridPanel.setDividerLocation(1.0);
1669
+
1670
+ frame.validate();
1671
+
1672
+ frame.setVisible(true);
16031673
16041674 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
16051675 frame.addWindowListener(new WindowAdapter()
....@@ -1686,24 +1756,6 @@
16861756 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
16871757 colorSection.add(texture);
16881758
1689
- cGridBag anisoU = new cGridBag();
1690
- anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1691
- anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1692
- anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1693
- colorSection.add(anisoU);
1694
-
1695
- cGridBag anisoV = new cGridBag();
1696
- anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1697
- anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1698
- anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1699
- colorSection.add(anisoV);
1700
-
1701
- cGridBag shadowbias = new cGridBag();
1702
- shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1703
- shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1704
- shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1705
- colorSection.add(shadowbias);
1706
-
17071759 panel.add(new JSeparator());
17081760
17091761 panel.add(colorSection);
....@@ -1753,6 +1805,12 @@
17531805 fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17541806 fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
17551807 diffuseSection.add(fakedepth);
1808
+
1809
+ cGridBag shadowbias = new cGridBag();
1810
+ shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1811
+ shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1812
+ shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1813
+ diffuseSection.add(shadowbias);
17561814
17571815 panel.add(new JSeparator());
17581816
....@@ -1804,6 +1862,18 @@
18041862 // aConstraints.gridy += 1;
18051863 // aConstraints.gridwidth = 1;
18061864
1865
+ cGridBag anisoU = new cGridBag();
1866
+ anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1867
+ anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1868
+ anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1869
+ specularSection.add(anisoU);
1870
+
1871
+ cGridBag anisoV = new cGridBag();
1872
+ anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1873
+ anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1874
+ anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1875
+ specularSection.add(anisoV);
1876
+
18071877
18081878 panel.add(new JSeparator());
18091879
....@@ -1811,35 +1881,35 @@
18111881
18121882 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
18131883
1814
- cGridBag globalSection = new cGridBag().setVertical(true);
1884
+ //cGridBag globalSection = new cGridBag().setVertical(true);
18151885
18161886 cGridBag camera = new cGridBag();
18171887 camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints);
18181888 cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18191889 camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1820
- globalSection.add(camera);
1890
+ colorSection.add(camera);
18211891
18221892 cGridBag ambient = new cGridBag();
18231893 ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints);
18241894 ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18251895 ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1826
- globalSection.add(ambient);
1896
+ colorSection.add(ambient);
18271897
18281898 cGridBag backlit = new cGridBag();
18291899 backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints);
18301900 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18311901 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1832
- globalSection.add(backlit);
1902
+ colorSection.add(backlit);
18331903
18341904 cGridBag opacity = new cGridBag();
18351905 opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
18361906 opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18371907 opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1838
- globalSection.add(opacity);
1908
+ colorSection.add(opacity);
18391909
1840
- panel.add(new JSeparator());
1910
+ //panel.add(new JSeparator());
18411911
1842
- panel.add(globalSection);
1912
+ //panel.add(globalSection);
18431913
18441914 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
18451915
....@@ -1946,8 +2016,9 @@
19462016 // 3D models
19472017 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
19482018 {
1949
- lastConverter = new com.jmex.model.converters.MaxToJme();
1950
- LoadFile(filename, lastConverter);
2019
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
2020
+ //LoadFile(filename, lastConverter);
2021
+ LoadObjFile(filename); // New 3ds loader
19512022 continue;
19522023 }
19532024 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2673,6 +2744,7 @@
26732744 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
26742745 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
26752746 }
2747
+
26762748 //cJME.count++;
26772749 //cJME.count %= 12;
26782750 if (gc)
....@@ -2856,6 +2928,7 @@
28562928 }
28572929 }
28582930 }
2931
+
28592932 cFileSystemPane FSPane;
28602933
28612934 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2909,6 +2982,7 @@
29092982 }
29102983 }
29112984 }
2985
+
29122986 freezematerial = false;
29132987 }
29142988
....@@ -3361,9 +3435,9 @@
33613435 {
33623436 Close();
33633437 //return true;
3364
- } else if (source == loadItem)
3438
+ } else if (source == openItem)
33653439 {
3366
- load();
3440
+ Open();
33673441 //return true;
33683442 } else if (source == newItem)
33693443 {
....@@ -3388,6 +3462,10 @@
33883462 {
33893463 generatePOV();
33903464 //return true;
3465
+ } else if (event.getSource() == archiveItem)
3466
+ {
3467
+ cTools.Archive(frame);
3468
+ return;
33913469 } else if (source == zBufferItem)
33923470 {
33933471 try
....@@ -3439,8 +3517,8 @@
34393517 try
34403518 {
34413519 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3442
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3443
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3520
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3521
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
34443522
34453523 Object3D parent = o.parent;
34463524 o.parent = null;
....@@ -3451,10 +3529,14 @@
34513529
34523530 out.flush();
34533531
3454
- zstream.close();
3532
+ baos //zstream
3533
+ .close();
34553534 out.close();
34563535
3457
- return baos.toByteArray();
3536
+ byte[] bytes = baos.toByteArray();
3537
+
3538
+ System.out.println("save #bytes = " + bytes.length);
3539
+ return bytes;
34583540 } catch (Exception e)
34593541 {
34603542 System.err.println(e);
....@@ -3464,13 +3546,16 @@
34643546
34653547 static public Object Uncompress(byte[] bytes)
34663548 {
3467
- System.out.println("#bytes = " + bytes.length);
3549
+ System.out.println("restore #bytes = " + bytes.length);
34683550 try
34693551 {
34703552 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3471
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3472
- ObjectInputStream in = new ObjectInputStream(istream);
3553
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3554
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
34733555 Object obj = in.readObject();
3556
+
3557
+ bais //istream
3558
+ .close();
34743559 in.close();
34753560
34763561 return obj;
....@@ -3525,31 +3610,67 @@
35253610 return null;
35263611 }
35273612
3528
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
35293613
35303614 public void Save()
3615
+ {
3616
+ //Save(true);
3617
+ Replace();
3618
+ }
3619
+
3620
+ private boolean Equal(byte[] compress, byte[] name)
3621
+ {
3622
+ if (compress.length != name.length)
3623
+ {
3624
+ return false;
3625
+ }
3626
+
3627
+ for (int i=compress.length; --i>=0;)
3628
+ {
3629
+ if (compress[i] != name[i])
3630
+ return false;
3631
+ }
3632
+
3633
+ return true;
3634
+ }
3635
+
3636
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
3637
+
3638
+ public boolean Save(boolean user)
35313639 {
35323640 System.err.println("Save");
35333641
35343642 cRadio tab = GetCurrentTab();
35353643
3536
- boolean temp = CameraPane.SWITCH;
3537
- CameraPane.SWITCH = false;
3644
+ byte[] compress = CompressCopy();
35383645
3539
- copy.ExtractBigData(hashtable);
3646
+ boolean thesame = false;
3647
+
3648
+ // Quick heuristic using length. Works only when stream is compressed.
3649
+ if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
3650
+ {
3651
+ thesame = true;
3652
+ }
35403653
35413654 //EditorFrame.m_MainFrame.requestFocusInWindow();
3542
- tab.graphs[tab.undoindex++] = Compress(copy);
3655
+ if (!thesame)
3656
+ {
3657
+ //tab.user[tab.versionindex] = user;
3658
+ //boolean increment = true; // tab.graphs[tab.versionindex] == null;
3659
+
3660
+ copy.versions[++copy.versionindex] = compress;
3661
+
3662
+ // if (increment)
3663
+ // tab.versionindex++;
3664
+ }
35433665
3544
- copy.RestoreBigData(hashtable);
3666
+ //copy.RestoreBigData(versiontable);
35453667
3546
- CameraPane.SWITCH = temp;
3547
-
35483668 //assert(hashtable.isEmpty());
35493669
3550
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3670
+ for (int i = copy.versionindex+1; i < copy.versions.length; i++)
35513671 {
3552
- tab.graphs[i] = null;
3672
+ //tab.user[i] = false;
3673
+ copy.versions[i] = null;
35533674 }
35543675
35553676 SetUndoStates();
....@@ -3559,7 +3680,7 @@
35593680 {
35603681 try
35613682 {
3562
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3683
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
35633684 ObjectOutputStream p = new ObjectOutputStream(ostream);
35643685
35653686 p.writeObject(copy);
....@@ -3572,6 +3693,8 @@
35723693 e.printStackTrace();
35733694 }
35743695 }
3696
+
3697
+ return !thesame;
35753698 }
35763699
35773700 void CopyChanged(Object3D obj)
....@@ -3581,7 +3704,7 @@
35813704 boolean temp = CameraPane.SWITCH;
35823705 CameraPane.SWITCH = false;
35833706
3584
- copy.ExtractBigData(hashtable);
3707
+ copy.ExtractBigData(versiontable);
35853708
35863709 copy.clear();
35873710
....@@ -3590,7 +3713,7 @@
35903713 copy.add(obj.get(i));
35913714 }
35923715
3593
- copy.RestoreBigData(hashtable);
3716
+ copy.RestoreBigData(versiontable);
35943717
35953718 CameraPane.SWITCH = temp;
35963719
....@@ -3618,52 +3741,129 @@
36183741 }
36193742
36203743 cButton undoButton;
3744
+ cButton restoreButton;
3745
+ cButton replaceButton;
36213746 cButton redoButton;
36223747
3748
+ boolean muteSlider;
3749
+
3750
+ int VersionCount()
3751
+ {
3752
+ int count = 0;
3753
+
3754
+ for (int i = copy.versions.length; --i >= 0;)
3755
+ {
3756
+ if (copy.versions[i] != null)
3757
+ count++;
3758
+ }
3759
+
3760
+ return count;
3761
+ }
3762
+
36233763 void SetUndoStates()
36243764 {
36253765 cRadio tab = GetCurrentTab();
36263766
3627
- undoButton.setEnabled(tab.undoindex > 0);
3628
- redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
3767
+ restoreButton.setEnabled(copy.versionindex != -1);
3768
+ replaceButton.setEnabled(copy.versionindex != -1);
3769
+
3770
+ undoButton.setEnabled(copy.versionindex > 0);
3771
+ redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
3772
+
3773
+ muteSlider = true;
3774
+ versionSlider.setMaximum(VersionCount() - 1);
3775
+ versionSlider.setInteger(copy.versionindex);
3776
+ muteSlider = false;
36293777 }
36303778
3631
- public void Undo()
3779
+ public boolean Undo()
36323780 {
3781
+ // Option?
3782
+ Replace();
3783
+
36333784 System.err.println("Undo");
36343785
36353786 cRadio tab = GetCurrentTab();
36363787
3637
- if (tab.undoindex == 0)
3788
+ if (copy.versionindex == 0)
36383789 {
36393790 java.awt.Toolkit.getDefaultToolkit().beep();
3640
- return;
3791
+ return false;
36413792 }
36423793
3643
- if (tab.graphs[tab.undoindex] == null)
3794
+// if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex])
3795
+// {
3796
+// if (Save(false))
3797
+// tab.versionindex -= 1;
3798
+// else
3799
+// {
3800
+// if (tab.versionindex <= 0)
3801
+// return false;
3802
+// else
3803
+// tab.versionindex -= 1;
3804
+// }
3805
+// }
3806
+
3807
+ copy.versionindex -= 1;
3808
+
3809
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3810
+
3811
+ return true;
3812
+ }
3813
+
3814
+ public boolean Restore()
3815
+ {
3816
+ System.err.println("Restore");
3817
+
3818
+ cRadio tab = GetCurrentTab();
3819
+
3820
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
36443821 {
3645
- Save();
3646
- tab.undoindex -= 1;
3822
+ java.awt.Toolkit.getDefaultToolkit().beep();
3823
+ return false;
36473824 }
36483825
3649
- tab.undoindex -= 1;
3826
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3827
+
3828
+ return true;
3829
+ }
36503830
3651
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3831
+ public boolean Replace()
3832
+ {
3833
+ System.err.println("Replace");
3834
+
3835
+ cRadio tab = GetCurrentTab();
3836
+
3837
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
3838
+ {
3839
+ // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
3840
+ return false;
3841
+ }
3842
+
3843
+ copy.versions[copy.versionindex] = CompressCopy();
3844
+
3845
+ return true;
36523846 }
36533847
36543848 public void Redo()
36553849 {
3850
+ // Option?
3851
+ Replace();
3852
+
36563853 cRadio tab = GetCurrentTab();
36573854
3658
- if (tab.graphs[tab.undoindex + 1] == null)
3855
+ if (copy.versions[copy.versionindex + 1] == null)
36593856 {
36603857 java.awt.Toolkit.getDefaultToolkit().beep();
36613858 return;
36623859 }
36633860
3664
- tab.undoindex += 1;
3861
+ copy.versionindex += 1;
36653862
3666
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3863
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3864
+
3865
+ //if (!tab.user[tab.versionindex])
3866
+ // tab.graphs[tab.versionindex] = null;
36673867 }
36683868
36693869 void ImportGFD()
....@@ -3959,9 +4159,25 @@
39594159 //copy.Touch();
39604160 }
39614161
4162
+ cNumberSlider versionSlider;
4163
+
39624164 public void stateChanged(ChangeEvent e)
39634165 {
39644166 // assert(false);
4167
+ if (e.getSource() == versionSlider)
4168
+ {
4169
+ if (muteSlider)
4170
+ return;
4171
+
4172
+ int version = versionSlider.getInteger();
4173
+
4174
+ if (copy.versions[version] != null)
4175
+ {
4176
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
4177
+ }
4178
+
4179
+ return;
4180
+ }
39654181
39664182 if (freezematerial)
39674183 {
....@@ -4310,7 +4526,7 @@
43104526
43114527 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
43124528 {
4313
- if (Globals.SAVEONMAKE) // && resetmodel)
4529
+ if (Globals.REPLACEONMAKE) // && resetmodel)
43144530 Save();
43154531 //Tween.set(thing, 0).target(1).start(tweenManager);
43164532 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4626,8 +4842,8 @@
46264842
46274843 if (readobj != null)
46284844 {
4629
- if (Globals.SAVEONMAKE)
4630
- Save();
4845
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4846
+ // Save();
46314847 try
46324848 {
46334849 //readobj.deepCopySelf(copy);
....@@ -4682,13 +4898,24 @@
46824898 c.addChild(csg);
46834899 }
46844900
4901
+ copy.versions = readobj.versions;
4902
+ copy.versionindex = readobj.versionindex;
4903
+
4904
+ if (copy.versions == null)
4905
+ {
4906
+ copy.versions = new byte[100][];
4907
+ copy.versionindex = -1;
4908
+ }
4909
+
4910
+ //? SetUndoStates();
4911
+
46854912 ResetModel();
46864913 copy.HardTouch(); // recompile?
46874914 refreshContents();
46884915 }
46894916 }
46904917
4691
- void load() // throws ClassNotFoundException
4918
+ void Open() // throws ClassNotFoundException
46924919 {
46934920 if (Grafreed.standAlone)
46944921 {
....@@ -4973,7 +5200,7 @@
49735200 MenuBar menuBar;
49745201 Menu fileMenu;
49755202 MenuItem newItem;
4976
- MenuItem loadItem;
5203
+ MenuItem openItem;
49775204 MenuItem saveItem;
49785205 MenuItem saveAsItem;
49795206 MenuItem exportAsItem;
....@@ -4996,6 +5223,7 @@
49965223 CheckboxMenuItem toggleSwitchItem;
49975224 CheckboxMenuItem toggleRootItem;
49985225 CheckboxMenuItem animationItem;
5226
+ MenuItem archiveItem;
49995227 CheckboxMenuItem toggleHandleItem;
50005228 CheckboxMenuItem togglePaintItem;
50015229 JSplitPane mainPanel;