Normand Briere
2019-07-18 d7a17c35c443e2cb6c09eaa3cfeaf590a571faa1
ObjEditor.java
....@@ -15,6 +15,9 @@
1515 //import javax.swing.plaf.ColorUIResource;
1616 //import javax.swing.plaf.metal.DefaultMetalTheme;
1717
18
+import javax.swing.plaf.basic.BasicSplitPaneDivider;
19
+import javax.swing.plaf.basic.BasicSplitPaneUI;
20
+
1821 //import javax.media.opengl.GLCanvas;
1922
2023 import //weka.core.
....@@ -207,7 +210,7 @@
207210
208211 objEditor.ctrlPanel.remove(namePanel);
209212
210
- if (!GroupEditor.allparams)
213
+ if (!allparams)
211214 return;
212215
213216 // objEditor.ctrlPanel.remove(liveCB);
....@@ -279,6 +282,12 @@
279282 client = inClient;
280283 copy = client;
281284
285
+ if (copy.versions == null)
286
+ {
287
+ copy.versions = new byte[100][];
288
+ copy.versionindex = -1;
289
+ }
290
+
282291 // "this" is not called: SetupUI2(objEditor);
283292 }
284293
....@@ -292,6 +301,12 @@
292301 client = inClient;
293302 copy = client;
294303
304
+ if (copy.versions == null)
305
+ {
306
+ copy.versions = new byte[100][];
307
+ copy.versionindex = -1;
308
+ }
309
+
295310 SetupUI2(callee.GetEditor());
296311 }
297312
....@@ -306,7 +321,7 @@
306321 //localCopy.parent = null;
307322
308323 frame = new JFrame();
309
- frame.setUndecorated(true);
324
+ frame.setUndecorated(false);
310325 objEditor = this;
311326 this.callee = callee;
312327
....@@ -324,6 +339,12 @@
324339 copy = localCopy;
325340 copy.editWindow = this;
326341
342
+ if (copy.versions == null)
343
+ {
344
+ copy.versions = new byte[100][];
345
+ copy.versionindex = -1;
346
+ }
347
+
327348 SetupMenu();
328349
329350 //SetupName(objEditor); // new
....@@ -337,12 +358,17 @@
337358 return frame.action(event, obj);
338359 }
339360
361
+ // Cannot work without static
362
+ static boolean allparams = true;
363
+
364
+ static java.util.Vector<Object3D> listUI = new java.util.Vector<Object3D>();
365
+
340366 void SetupMenu()
341367 {
342368 frame.setMenuBar(menuBar = new MenuBar());
343369 menuBar.add(fileMenu = new Menu("File"));
344370 fileMenu.add(newItem = new MenuItem("New"));
345
- fileMenu.add(loadItem = new MenuItem("Open..."));
371
+ fileMenu.add(openItem = new MenuItem("Open..."));
346372
347373 //oe.menuBar.add(menu = new Menu("Include"));
348374 Menu menu = new Menu("Import");
....@@ -374,7 +400,7 @@
374400 }
375401
376402 newItem.addActionListener(this);
377
- loadItem.addActionListener(this);
403
+ openItem.addActionListener(this);
378404 saveItem.addActionListener(this);
379405 saveAsItem.addActionListener(this);
380406 exportAsItem.addActionListener(this);
....@@ -383,6 +409,32 @@
383409 closeItem.addActionListener(this);
384410
385411 objectPanel = new JTabbedPane();
412
+
413
+ ChangeListener changeListener = new ChangeListener()
414
+ {
415
+ public void stateChanged(ChangeEvent changeEvent)
416
+ {
417
+// if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Material") && !materialFlushed)
418
+// {
419
+// if (latestObject != null)
420
+// {
421
+// refreshContents(true);
422
+// SetMaterial(latestObject);
423
+// }
424
+//
425
+// materialFlushed = true;
426
+// }
427
+// if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Edit"))
428
+// {
429
+// if (listUI.size() == 0)
430
+// EditSelection(false);
431
+// }
432
+
433
+ refreshContents(false); // To refresh Info tab
434
+ }
435
+ };
436
+ objectPanel.addChangeListener(changeListener);
437
+
386438 toolbarPanel = new JPanel();
387439 toolbarPanel.setName("Toolbar");
388440 treePanel = new cGridBag();
....@@ -415,7 +467,7 @@
415467 // TEXTAREA infoarea.setLineWrap(true);
416468 // TEXTAREA infoarea.setWrapStyleWord(true);
417469 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
418
- infoPanel.setPreferredSize(new Dimension(50, 200));
470
+ infoPanel.setPreferredSize(new Dimension(1, 1));
419471 infoPanel.setName("Info");
420472 //infoPanel.setLayout(new BorderLayout());
421473 //infoPanel.add(createTextPane());
....@@ -427,7 +479,14 @@
427479 mainPanel.setDividerSize(9);
428480 mainPanel.setDividerLocation(0.5); //1.0);
429481 mainPanel.setResizeWeight(0.5);
430
-
482
+
483
+//mainPanel.setDividerSize((int) (mainPanel.getDividerSize() * 1.5));
484
+ BasicSplitPaneDivider divider = ( (BasicSplitPaneUI) mainPanel.getUI()).getDivider();
485
+ divider.setDividerSize(15);
486
+ divider.setBorder(BorderFactory.createTitledBorder(divider.getBorder(), "Custom border title -- gets rid of the one-touch arrows!"));
487
+
488
+ mainPanel.setUI(new BasicSplitPaneUI());
489
+
431490 //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5));
432491 //mainPanel.setLayout(new GridBagLayout());
433492 toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
....@@ -658,8 +717,8 @@
658717 }
659718 }
660719
661
-static GraphicsDevice device = GraphicsEnvironment
662
- .getLocalGraphicsEnvironment().getScreenDevices()[0];
720
+//static GraphicsDevice device = GraphicsEnvironment
721
+// .getLocalGraphicsEnvironment().getScreenDevices()[0];
663722
664723 Rectangle keeprect;
665724 cRadio radio;
....@@ -680,10 +739,19 @@
680739 void Minimize()
681740 {
682741 frame.setState(Frame.ICONIFIED);
742
+ frame.validate();
683743 }
684744
745
+// artifactURI=null, type=0, property=${file.reference.jfxrt.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@6767876f, broken=false, additional={}
746
+// artifactURI=null, type=0, property=${file.reference.mac-ui.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@16bdc817, broken=false, additional={}
747
+// artifactURI=null, type=0, property=${file.reference.classes.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@9daa9c17, broken=false, additional={}
685748 void Maximize()
686749 {
750
+ if (CameraPane.FULLSCREEN)
751
+ {
752
+ ToggleFullScreen();
753
+ }
754
+
687755 if (maximized)
688756 {
689757 frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
....@@ -691,20 +759,36 @@
691759 else
692760 {
693761 keeprect = frame.getBounds();
694
- Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
695
- Dimension rect2 = frame.getToolkit().getScreenSize();
696
- frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
762
+// Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
763
+// Dimension rect2 = frame.getToolkit().getScreenSize();
764
+// frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
697765 // frame.setState(Frame.MAXIMIZED_BOTH);
766
+ frame.setBounds(frame.getGraphicsConfiguration().getBounds());
698767 }
699768
700769 maximized ^= true;
770
+
771
+ frame.validate();
701772 }
773
+
774
+ cButton minButton;
775
+ cButton maxButton;
776
+ cButton fullButton;
702777
703778 void ToggleFullScreen()
704779 {
705
- if (CameraPane.FULLSCREEN)
780
+GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
781
+
782
+ cameraView.ToggleFullScreen();
783
+
784
+ if (!CameraPane.FULLSCREEN)
706785 {
707786 device.setFullScreenWindow(null);
787
+ frame.dispose();
788
+ frame.setUndecorated(false);
789
+ frame.validate();
790
+ frame.setVisible(true);
791
+
708792 //frame.setVisible(false);
709793 // frame.removeNotify();
710794 // frame.setUndecorated(false);
....@@ -714,7 +798,7 @@
714798 // X frame.getContentPane().remove(/*"Center",*/bigThree);
715799 // X framePanel.add(bigThree);
716800 // X frame.getContentPane().add(/*"Center",*/framePanel);
717
- framePanel.setDividerLocation(1);
801
+ framePanel.setDividerLocation(46);
718802
719803 //frame.setVisible(true);
720804 radio.layout = keepButton;
....@@ -729,7 +813,12 @@
729813 // frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
730814 // frame.getToolkit().getScreenSize().height);
731815 //frame.setVisible(false);
816
+
817
+ frame.dispose();
818
+ frame.setUndecorated(true);
732819 device.setFullScreenWindow(frame);
820
+ frame.validate();
821
+ frame.setVisible(true);
733822 // frame.removeNotify();
734823 // frame.setUndecorated(true);
735824 // frame.addNotify();
....@@ -742,9 +831,30 @@
742831 radio.layout.doClick();
743832 //frame.setVisible(true);
744833 }
745
-
746
- cameraView.ToggleFullScreen();
834
+ frame.validate();
747835 }
836
+
837
+ private byte[] CompressCopy()
838
+ {
839
+ boolean temp = CameraPane.SWITCH;
840
+ CameraPane.SWITCH = false;
841
+
842
+ copy.ExtractBigData(versiontable);
843
+ // if (copy == client)
844
+
845
+ byte[] versions[] = copy.versions;
846
+ copy.versions = null;
847
+
848
+ byte[] compress = Compress(copy);
849
+
850
+ copy.versions = versions;
851
+
852
+ copy.RestoreBigData(versiontable);
853
+
854
+ CameraPane.SWITCH = temp;
855
+
856
+ return compress;
857
+ }
748858
749859 private JTextPane createTextPane()
750860 {
....@@ -884,7 +994,12 @@
884994 JCheckBox speedupCB;
885995 JCheckBox rewindCB;
886996 JCheckBox flipVCB;
997
+
998
+ cCheckBox toggleTextureCB;
999
+ cCheckBox toggleSwitchCB;
1000
+
8871001 JComboBox texresMenu;
1002
+
8881003 JButton resetButton;
8891004 JButton stepButton;
8901005 JButton stepAllButton;
....@@ -1071,12 +1186,12 @@
10711186 namePanel = new cGridBag();
10721187
10731188 nameField = AddText(namePanel, copy.GetName());
1074
- namePanel.add(nameField);
1189
+ namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
10751190 oe.ctrlPanel.add(namePanel);
10761191
10771192 oe.ctrlPanel.Return();
10781193
1079
- if (!GroupEditor.allparams)
1194
+ if (!allparams)
10801195 return;
10811196
10821197 setupPanel = new cGridBag().setVertical(false);
....@@ -1089,20 +1204,21 @@
10891204 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
10901205 hideCB.setToolTipText("Hide object");
10911206 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
1092
- markCB.setToolTipText("Set the animation target transform");
1207
+ markCB.setToolTipText("As animation target transform");
10931208
10941209 setupPanel2 = new cGridBag().setVertical(false);
10951210
10961211 rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
10971212 rewindCB.setToolTipText("Rewind animation");
10981213
1099
- randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1100
- randomCB.setToolTipText("Randomly Rewind or Go back and forth");
1214
+ randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
1215
+ randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11011216
1217
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1218
+ link2masterCB.setToolTipText("Attach to support");
1219
+
11021220 if (Globals.ADVANCED)
11031221 {
1104
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1105
- link2masterCB.setToolTipText("Attach to support");
11061222 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
11071223 speedupCB.setToolTipText("Option motion capture");
11081224 }
....@@ -1412,14 +1528,17 @@
14121528
14131529 //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
14141530 //tmp.setName("Edit");
1415
- objectPanel.add(toolboxPanel);
14161531 objectPanel.add(materialPanel);
14171532 // JPanel north = new JPanel(new BorderLayout());
14181533 // north.setName("Edit");
14191534 // north.add(ctrlPanel, BorderLayout.NORTH);
14201535 // objectPanel.add(north);
14211536 objectPanel.add(editPanel);
1422
- objectPanel.add(infoPanel);
1537
+
1538
+ //if (Globals.ADVANCED)
1539
+ objectPanel.add(infoPanel);
1540
+
1541
+ objectPanel.add(toolboxPanel);
14231542
14241543 /*
14251544 aConstraints.gridx = 0;
....@@ -1428,7 +1547,7 @@
14281547 aConstraints.gridy += 1;
14291548 aConstraints.gridwidth = 1;
14301549 mainPanel.add(objectPanel, aConstraints);
1431
- */
1550
+ */
14321551
14331552 scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
14341553 VERTICAL_SCROLLBAR_AS_NEEDED,
....@@ -1445,9 +1564,7 @@
14451564 JTabbedPane tabbedPane = new JTabbedPane();
14461565 tabbedPane.add(scrollpane);
14471566
1448
- tabbedPane.add(FSPane = new cFileSystemPane(this));
1449
-
1450
- optionsPanel = new cGridBag().setVertical(true);
1567
+ optionsPanel = new cGridBag().setVertical(false);
14511568
14521569 optionsPanel.setName("Options");
14531570
....@@ -1455,6 +1572,8 @@
14551572
14561573 tabbedPane.add(optionsPanel);
14571574
1575
+ tabbedPane.add(FSPane = new cFileSystemPane(this));
1576
+
14581577 scenePanel.add(tabbedPane);
14591578
14601579 /*
....@@ -1527,9 +1646,9 @@
15271646 // aConstraints.gridheight = 1;
15281647
15291648 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1530
- framePanel.setContinuousLayout(true);
1531
- framePanel.setOneTouchExpandable(true);
1532
- framePanel.setDividerLocation(0.8);
1649
+ framePanel.setContinuousLayout(false);
1650
+ framePanel.setOneTouchExpandable(false);
1651
+ //.setDividerLocation(0.8);
15331652 //framePanel.setDividerSize(15);
15341653 //framePanel.setResizeWeight(0.15);
15351654 framePanel.setName("Frame");
....@@ -1547,11 +1666,14 @@
15471666 // aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc);
15481667
15491668 frame.setSize(1280, 860);
1550
- frame.setVisible(true);
1551
-
1669
+
15521670 cameraView.requestFocusInWindow();
15531671
15541672 gridPanel.setDividerLocation(1.0);
1673
+
1674
+ frame.validate();
1675
+
1676
+ frame.setVisible(true);
15551677
15561678 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
15571679 frame.addWindowListener(new WindowAdapter()
....@@ -1638,24 +1760,6 @@
16381760 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
16391761 colorSection.add(texture);
16401762
1641
- cGridBag anisoU = new cGridBag();
1642
- anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1643
- anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1644
- anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1645
- colorSection.add(anisoU);
1646
-
1647
- cGridBag anisoV = new cGridBag();
1648
- anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1649
- anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1650
- anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1651
- colorSection.add(anisoV);
1652
-
1653
- cGridBag shadowbias = new cGridBag();
1654
- shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1655
- shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1656
- shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1657
- colorSection.add(shadowbias);
1658
-
16591763 panel.add(new JSeparator());
16601764
16611765 panel.add(colorSection);
....@@ -1705,6 +1809,12 @@
17051809 fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17061810 fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
17071811 diffuseSection.add(fakedepth);
1812
+
1813
+ cGridBag shadowbias = new cGridBag();
1814
+ shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1815
+ shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1816
+ shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1817
+ diffuseSection.add(shadowbias);
17081818
17091819 panel.add(new JSeparator());
17101820
....@@ -1756,6 +1866,18 @@
17561866 // aConstraints.gridy += 1;
17571867 // aConstraints.gridwidth = 1;
17581868
1869
+ cGridBag anisoU = new cGridBag();
1870
+ anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1871
+ anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1872
+ anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1873
+ specularSection.add(anisoU);
1874
+
1875
+ cGridBag anisoV = new cGridBag();
1876
+ anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1877
+ anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1878
+ anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1879
+ specularSection.add(anisoV);
1880
+
17591881
17601882 panel.add(new JSeparator());
17611883
....@@ -1763,35 +1885,35 @@
17631885
17641886 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17651887
1766
- cGridBag globalSection = new cGridBag().setVertical(true);
1888
+ //cGridBag globalSection = new cGridBag().setVertical(true);
17671889
17681890 cGridBag camera = new cGridBag();
17691891 camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints);
17701892 cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17711893 camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1772
- globalSection.add(camera);
1894
+ colorSection.add(camera);
17731895
17741896 cGridBag ambient = new cGridBag();
17751897 ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints);
17761898 ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17771899 ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1778
- globalSection.add(ambient);
1900
+ colorSection.add(ambient);
17791901
17801902 cGridBag backlit = new cGridBag();
17811903 backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints);
17821904 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17831905 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1784
- globalSection.add(backlit);
1906
+ colorSection.add(backlit);
17851907
17861908 cGridBag opacity = new cGridBag();
17871909 opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
17881910 opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17891911 opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1790
- globalSection.add(opacity);
1912
+ colorSection.add(opacity);
17911913
1792
- panel.add(new JSeparator());
1914
+ //panel.add(new JSeparator());
17931915
1794
- panel.add(globalSection);
1916
+ //panel.add(globalSection);
17951917
17961918 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17971919
....@@ -1898,8 +2020,9 @@
18982020 // 3D models
18992021 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
19002022 {
1901
- lastConverter = new com.jmex.model.converters.MaxToJme();
1902
- LoadFile(filename, lastConverter);
2023
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
2024
+ //LoadFile(filename, lastConverter);
2025
+ LoadObjFile(filename); // New 3ds loader
19032026 continue;
19042027 }
19052028 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2625,6 +2748,7 @@
26252748 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
26262749 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
26272750 }
2751
+
26282752 //cJME.count++;
26292753 //cJME.count %= 12;
26302754 if (gc)
....@@ -2808,6 +2932,7 @@
28082932 }
28092933 }
28102934 }
2935
+
28112936 cFileSystemPane FSPane;
28122937
28132938 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2861,11 +2986,14 @@
28612986 }
28622987 }
28632988 }
2989
+
28642990 freezematerial = false;
28652991 }
28662992
28672993 void SetMaterial(Object3D object)
28682994 {
2995
+ latestObject = object;
2996
+
28692997 cMaterial mat = object.material;
28702998
28712999 if (mat == null)
....@@ -2977,12 +3105,17 @@
29773105 // }
29783106
29793107 /**/
2980
- if (deselect)
3108
+ if (deselect || child == null)
29813109 {
29823110 //group.deselectAll();
29833111 //freeze = true;
29843112 GetTree().clearSelection();
29853113 //freeze = false;
3114
+
3115
+ if (child == null)
3116
+ {
3117
+ return;
3118
+ }
29863119 }
29873120
29883121 //group.addSelectee(child);
....@@ -3051,7 +3184,7 @@
30513184 cameraView.ToggleDL();
30523185 cameraView.repaint();
30533186 return;
3054
- } else if (event.getSource() == toggleTextureItem)
3187
+ } else if (event.getSource() == toggleTextureItem || event.getSource() == toggleTextureCB)
30553188 {
30563189 cameraView.ToggleTexture();
30573190 // june 2013 copy.HardTouch();
....@@ -3090,7 +3223,7 @@
30903223 frame.validate();
30913224
30923225 return;
3093
- } else if (event.getSource() == toggleSwitchItem)
3226
+ } else if (event.getSource() == toggleSwitchItem || event.getSource() == toggleSwitchCB)
30943227 {
30953228 cameraView.ToggleSwitch();
30963229 cameraView.repaint();
....@@ -3306,9 +3439,9 @@
33063439 {
33073440 Close();
33083441 //return true;
3309
- } else if (source == loadItem)
3442
+ } else if (source == openItem)
33103443 {
3311
- load();
3444
+ Open();
33123445 //return true;
33133446 } else if (source == newItem)
33143447 {
....@@ -3333,6 +3466,10 @@
33333466 {
33343467 generatePOV();
33353468 //return true;
3469
+ } else if (event.getSource() == archiveItem)
3470
+ {
3471
+ cTools.Archive(frame);
3472
+ return;
33363473 } else if (source == zBufferItem)
33373474 {
33383475 try
....@@ -3384,8 +3521,8 @@
33843521 try
33853522 {
33863523 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3387
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3388
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3524
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3525
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
33893526
33903527 Object3D parent = o.parent;
33913528 o.parent = null;
....@@ -3396,10 +3533,14 @@
33963533
33973534 out.flush();
33983535
3399
- zstream.close();
3536
+ baos //zstream
3537
+ .close();
34003538 out.close();
34013539
3402
- return baos.toByteArray();
3540
+ byte[] bytes = baos.toByteArray();
3541
+
3542
+ System.out.println("save #bytes = " + bytes.length);
3543
+ return bytes;
34033544 } catch (Exception e)
34043545 {
34053546 System.err.println(e);
....@@ -3409,13 +3550,16 @@
34093550
34103551 static public Object Uncompress(byte[] bytes)
34113552 {
3412
- System.out.println("#bytes = " + bytes.length);
3553
+ System.out.println("restore #bytes = " + bytes.length);
34133554 try
34143555 {
34153556 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3416
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3417
- ObjectInputStream in = new ObjectInputStream(istream);
3557
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3558
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
34183559 Object obj = in.readObject();
3560
+
3561
+ bais //istream
3562
+ .close();
34193563 in.close();
34203564
34213565 return obj;
....@@ -3470,39 +3614,77 @@
34703614 return null;
34713615 }
34723616
3473
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
34743617
34753618 public void Save()
3619
+ {
3620
+ //Save(true);
3621
+ Replace();
3622
+ }
3623
+
3624
+ private boolean Equal(byte[] compress, byte[] name)
3625
+ {
3626
+ if (compress.length != name.length)
3627
+ {
3628
+ return false;
3629
+ }
3630
+
3631
+ for (int i=compress.length; --i>=0;)
3632
+ {
3633
+ if (compress[i] != name[i])
3634
+ return false;
3635
+ }
3636
+
3637
+ return true;
3638
+ }
3639
+
3640
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
3641
+
3642
+ public boolean Save(boolean user)
34763643 {
34773644 System.err.println("Save");
34783645
34793646 cRadio tab = GetCurrentTab();
34803647
3481
- boolean temp = CameraPane.SWITCH;
3482
- CameraPane.SWITCH = false;
3648
+ byte[] compress = CompressCopy();
34833649
3484
- copy.ExtractBigData(hashtable);
3650
+ boolean thesame = false;
3651
+
3652
+ // Quick heuristic using length. Works only when stream is compressed.
3653
+ if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
3654
+ {
3655
+ thesame = true;
3656
+ }
34853657
34863658 //EditorFrame.m_MainFrame.requestFocusInWindow();
3487
- tab.graphs[tab.undoindex++] = Compress(copy);
3488
-
3489
- copy.RestoreBigData(hashtable);
3490
-
3491
- CameraPane.SWITCH = temp;
3492
-
3493
- //assert(hashtable.isEmpty());
3494
-
3495
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3659
+ if (!thesame)
34963660 {
3497
- tab.graphs[i] = null;
3661
+ //tab.user[tab.versionindex] = user;
3662
+ //boolean increment = true; // tab.graphs[tab.versionindex] == null;
3663
+
3664
+ copy.versions[++copy.versionindex] = compress;
3665
+
3666
+ // if (increment)
3667
+ // tab.versionindex++;
34983668 }
34993669
3670
+ //copy.RestoreBigData(versiontable);
3671
+
3672
+ //assert(hashtable.isEmpty());
3673
+
3674
+ for (int i = copy.versionindex+1; i < copy.versions.length; i++)
3675
+ {
3676
+ //tab.user[i] = false;
3677
+ copy.versions[i] = null;
3678
+ }
3679
+
3680
+ SetUndoStates();
3681
+
35003682 // test save
35013683 if (false)
35023684 {
35033685 try
35043686 {
3505
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3687
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
35063688 ObjectOutputStream p = new ObjectOutputStream(ostream);
35073689
35083690 p.writeObject(copy);
....@@ -3515,14 +3697,18 @@
35153697 e.printStackTrace();
35163698 }
35173699 }
3700
+
3701
+ return !thesame;
35183702 }
35193703
35203704 void CopyChanged(Object3D obj)
35213705 {
3706
+ SetUndoStates();
3707
+
35223708 boolean temp = CameraPane.SWITCH;
35233709 CameraPane.SWITCH = false;
35243710
3525
- copy.ExtractBigData(hashtable);
3711
+ copy.ExtractBigData(versiontable);
35263712
35273713 copy.clear();
35283714
....@@ -3531,7 +3717,7 @@
35313717 copy.add(obj.get(i));
35323718 }
35333719
3534
- copy.RestoreBigData(hashtable);
3720
+ copy.RestoreBigData(versiontable);
35353721
35363722 CameraPane.SWITCH = temp;
35373723
....@@ -3558,42 +3744,130 @@
35583744 refreshContents();
35593745 }
35603746
3561
- public void Undo()
3747
+ cButton undoButton;
3748
+ cButton restoreButton;
3749
+ cButton replaceButton;
3750
+ cButton redoButton;
3751
+
3752
+ boolean muteSlider;
3753
+
3754
+ int VersionCount()
35623755 {
3756
+ int count = 0;
3757
+
3758
+ for (int i = copy.versions.length; --i >= 0;)
3759
+ {
3760
+ if (copy.versions[i] != null)
3761
+ count++;
3762
+ }
3763
+
3764
+ return count;
3765
+ }
3766
+
3767
+ void SetUndoStates()
3768
+ {
3769
+ cRadio tab = GetCurrentTab();
3770
+
3771
+ restoreButton.setEnabled(copy.versionindex != -1);
3772
+ replaceButton.setEnabled(copy.versionindex != -1);
3773
+
3774
+ undoButton.setEnabled(copy.versionindex > 0);
3775
+ redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
3776
+
3777
+ muteSlider = true;
3778
+ versionSlider.setMaximum(VersionCount() - 1);
3779
+ versionSlider.setInteger(copy.versionindex);
3780
+ muteSlider = false;
3781
+ }
3782
+
3783
+ public boolean Undo()
3784
+ {
3785
+ // Option?
3786
+ Replace();
3787
+
35633788 System.err.println("Undo");
35643789
35653790 cRadio tab = GetCurrentTab();
35663791
3567
- if (tab.undoindex == 0)
3792
+ if (copy.versionindex == 0)
35683793 {
35693794 java.awt.Toolkit.getDefaultToolkit().beep();
3570
- return;
3795
+ return false;
35713796 }
35723797
3573
- if (tab.graphs[tab.undoindex] == null)
3798
+// if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex])
3799
+// {
3800
+// if (Save(false))
3801
+// tab.versionindex -= 1;
3802
+// else
3803
+// {
3804
+// if (tab.versionindex <= 0)
3805
+// return false;
3806
+// else
3807
+// tab.versionindex -= 1;
3808
+// }
3809
+// }
3810
+
3811
+ copy.versionindex -= 1;
3812
+
3813
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3814
+
3815
+ return true;
3816
+ }
3817
+
3818
+ public boolean Restore()
3819
+ {
3820
+ System.err.println("Restore");
3821
+
3822
+ cRadio tab = GetCurrentTab();
3823
+
3824
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
35743825 {
3575
- Save();
3576
- tab.undoindex -= 1;
3826
+ java.awt.Toolkit.getDefaultToolkit().beep();
3827
+ return false;
35773828 }
35783829
3579
- tab.undoindex -= 1;
3830
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3831
+
3832
+ return true;
3833
+ }
35803834
3581
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3835
+ public boolean Replace()
3836
+ {
3837
+ System.err.println("Replace");
3838
+
3839
+ cRadio tab = GetCurrentTab();
3840
+
3841
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
3842
+ {
3843
+ // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
3844
+ return false;
3845
+ }
3846
+
3847
+ copy.versions[copy.versionindex] = CompressCopy();
3848
+
3849
+ return true;
35823850 }
35833851
35843852 public void Redo()
35853853 {
3854
+ // Option?
3855
+ Replace();
3856
+
35863857 cRadio tab = GetCurrentTab();
35873858
3588
- if (tab.graphs[tab.undoindex + 1] == null)
3859
+ if (copy.versions[copy.versionindex + 1] == null)
35893860 {
35903861 java.awt.Toolkit.getDefaultToolkit().beep();
35913862 return;
35923863 }
35933864
3594
- tab.undoindex += 1;
3865
+ copy.versionindex += 1;
35953866
3596
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3867
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3868
+
3869
+ //if (!tab.user[tab.versionindex])
3870
+ // tab.graphs[tab.versionindex] = null;
35973871 }
35983872
35993873 void ImportGFD()
....@@ -3889,9 +4163,25 @@
38894163 //copy.Touch();
38904164 }
38914165
4166
+ cNumberSlider versionSlider;
4167
+
38924168 public void stateChanged(ChangeEvent e)
38934169 {
38944170 // assert(false);
4171
+ if (e.getSource() == versionSlider)
4172
+ {
4173
+ if (muteSlider)
4174
+ return;
4175
+
4176
+ int version = versionSlider.getInteger();
4177
+
4178
+ if (copy.versions[version] != null)
4179
+ {
4180
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
4181
+ }
4182
+
4183
+ return;
4184
+ }
38954185
38964186 if (freezematerial)
38974187 {
....@@ -4240,7 +4530,7 @@
42404530
42414531 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
42424532 {
4243
- if (Globals.SAVEONMAKE) // && resetmodel)
4533
+ if (Globals.REPLACEONMAKE) // && resetmodel)
42444534 Save();
42454535 //Tween.set(thing, 0).target(1).start(tweenManager);
42464536 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4556,8 +4846,8 @@
45564846
45574847 if (readobj != null)
45584848 {
4559
- if (Globals.SAVEONMAKE)
4560
- Save();
4849
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4850
+ // Save();
45614851 try
45624852 {
45634853 //readobj.deepCopySelf(copy);
....@@ -4612,13 +4902,24 @@
46124902 c.addChild(csg);
46134903 }
46144904
4905
+ copy.versions = readobj.versions;
4906
+ copy.versionindex = readobj.versionindex;
4907
+
4908
+ if (copy.versions == null)
4909
+ {
4910
+ copy.versions = new byte[100][];
4911
+ copy.versionindex = -1;
4912
+ }
4913
+
4914
+ //? SetUndoStates();
4915
+
46154916 ResetModel();
46164917 copy.HardTouch(); // recompile?
46174918 refreshContents();
46184919 }
46194920 }
46204921
4621
- void load() // throws ClassNotFoundException
4922
+ void Open() // throws ClassNotFoundException
46224923 {
46234924 if (Grafreed.standAlone)
46244925 {
....@@ -4735,6 +5036,8 @@
47355036 String filename = browser.getFile();
47365037 if (filename != null && filename.length() > 0)
47375038 {
5039
+ if (!filename.endsWith(".gfd"))
5040
+ filename += ".gfd";
47385041 lastname = browser.getDirectory() + filename;
47395042 save();
47405043 }
....@@ -4901,7 +5204,7 @@
49015204 MenuBar menuBar;
49025205 Menu fileMenu;
49035206 MenuItem newItem;
4904
- MenuItem loadItem;
5207
+ MenuItem openItem;
49055208 MenuItem saveItem;
49065209 MenuItem saveAsItem;
49075210 MenuItem exportAsItem;
....@@ -4924,6 +5227,7 @@
49245227 CheckboxMenuItem toggleSwitchItem;
49255228 CheckboxMenuItem toggleRootItem;
49265229 CheckboxMenuItem animationItem;
5230
+ MenuItem archiveItem;
49275231 CheckboxMenuItem toggleHandleItem;
49285232 CheckboxMenuItem togglePaintItem;
49295233 JSplitPane mainPanel;
....@@ -4945,6 +5249,8 @@
49455249 cGridBag optionsPanel;
49465250
49475251 JTabbedPane objectPanel;
5252
+ boolean materialFlushed;
5253
+ Object3D latestObject;
49485254
49495255 cGridBag XYZPanel;
49505256