Normand Briere
2019-07-18 d7a17c35c443e2cb6c09eaa3cfeaf590a571faa1
ObjEditor.java
....@@ -4,6 +4,7 @@
44
55 import java.awt.*;
66 import java.awt.event.*;
7
+import java.awt.image.BufferedImage;
78 import javax.swing.*;
89 import javax.swing.event.*;
910 import javax.swing.text.*;
....@@ -13,6 +14,9 @@
1314 import javax.swing.plaf.metal.MetalLookAndFeel;
1415 //import javax.swing.plaf.ColorUIResource;
1516 //import javax.swing.plaf.metal.DefaultMetalTheme;
17
+
18
+import javax.swing.plaf.basic.BasicSplitPaneDivider;
19
+import javax.swing.plaf.basic.BasicSplitPaneUI;
1620
1721 //import javax.media.opengl.GLCanvas;
1822
....@@ -37,6 +41,65 @@
3741 JFrame frame;
3842
3943 static ObjEditor theFrame;
44
+
45
+ cButton GetButton(String name, boolean border)
46
+ {
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
+ }
56
+ }
57
+
58
+ cToggleButton GetToggleButton(String name, boolean border)
59
+ {
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
+ }
69
+ }
70
+
71
+ cCheckBox GetCheckBox(String name, boolean border)
72
+ {
73
+ try
74
+ {
75
+ ImageIcon icon = GetIcon(name);
76
+ return new cCheckBox(icon, border);
77
+ }
78
+ catch (Exception e)
79
+ {
80
+ return new cCheckBox(name, border);
81
+ }
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;
102
+ }
40103
41104 // SCRIPT
42105
....@@ -147,7 +210,7 @@
147210
148211 objEditor.ctrlPanel.remove(namePanel);
149212
150
- if (!GroupEditor.allparams)
213
+ if (!allparams)
151214 return;
152215
153216 // objEditor.ctrlPanel.remove(liveCB);
....@@ -219,6 +282,12 @@
219282 client = inClient;
220283 copy = client;
221284
285
+ if (copy.versions == null)
286
+ {
287
+ copy.versions = new byte[100][];
288
+ copy.versionindex = -1;
289
+ }
290
+
222291 // "this" is not called: SetupUI2(objEditor);
223292 }
224293
....@@ -232,6 +301,12 @@
232301 client = inClient;
233302 copy = client;
234303
304
+ if (copy.versions == null)
305
+ {
306
+ copy.versions = new byte[100][];
307
+ copy.versionindex = -1;
308
+ }
309
+
235310 SetupUI2(callee.GetEditor());
236311 }
237312
....@@ -246,7 +321,7 @@
246321 //localCopy.parent = null;
247322
248323 frame = new JFrame();
249
- frame.setUndecorated(true);
324
+ frame.setUndecorated(false);
250325 objEditor = this;
251326 this.callee = callee;
252327
....@@ -264,6 +339,12 @@
264339 copy = localCopy;
265340 copy.editWindow = this;
266341
342
+ if (copy.versions == null)
343
+ {
344
+ copy.versions = new byte[100][];
345
+ copy.versionindex = -1;
346
+ }
347
+
267348 SetupMenu();
268349
269350 //SetupName(objEditor); // new
....@@ -277,12 +358,17 @@
277358 return frame.action(event, obj);
278359 }
279360
361
+ // Cannot work without static
362
+ static boolean allparams = true;
363
+
364
+ static java.util.Vector<Object3D> listUI = new java.util.Vector<Object3D>();
365
+
280366 void SetupMenu()
281367 {
282368 frame.setMenuBar(menuBar = new MenuBar());
283369 menuBar.add(fileMenu = new Menu("File"));
284370 fileMenu.add(newItem = new MenuItem("New"));
285
- fileMenu.add(loadItem = new MenuItem("Open..."));
371
+ fileMenu.add(openItem = new MenuItem("Open..."));
286372
287373 //oe.menuBar.add(menu = new Menu("Include"));
288374 Menu menu = new Menu("Import");
....@@ -314,7 +400,7 @@
314400 }
315401
316402 newItem.addActionListener(this);
317
- loadItem.addActionListener(this);
403
+ openItem.addActionListener(this);
318404 saveItem.addActionListener(this);
319405 saveAsItem.addActionListener(this);
320406 exportAsItem.addActionListener(this);
....@@ -323,6 +409,32 @@
323409 closeItem.addActionListener(this);
324410
325411 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
+
326438 toolbarPanel = new JPanel();
327439 toolbarPanel.setName("Toolbar");
328440 treePanel = new cGridBag();
....@@ -337,9 +449,12 @@
337449 editPanel.add(editCommandsPanel);
338450 editPanel.add(ctrlPanel);
339451
340
- materialPanel = new cGridBag().setVertical(true);
452
+ toolboxPanel = new cGridBag().setVertical(false);
453
+ toolboxPanel.setName("Toolbox");
341454
455
+ materialPanel = new cGridBag().setVertical(true);
342456 materialPanel.setName("Material");
457
+
343458 /*JTextPane*/
344459 infoarea = createTextPane();
345460 doc = infoarea.getStyledDocument();
....@@ -352,7 +467,7 @@
352467 // TEXTAREA infoarea.setLineWrap(true);
353468 // TEXTAREA infoarea.setWrapStyleWord(true);
354469 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
355
- infoPanel.setPreferredSize(new Dimension(50, 200));
470
+ infoPanel.setPreferredSize(new Dimension(1, 1));
356471 infoPanel.setName("Info");
357472 //infoPanel.setLayout(new BorderLayout());
358473 //infoPanel.add(createTextPane());
....@@ -364,7 +479,14 @@
364479 mainPanel.setDividerSize(9);
365480 mainPanel.setDividerLocation(0.5); //1.0);
366481 mainPanel.setResizeWeight(0.5);
367
-
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
+
368490 //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5));
369491 //mainPanel.setLayout(new GridBagLayout());
370492 toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
....@@ -595,8 +717,8 @@
595717 }
596718 }
597719
598
-static GraphicsDevice device = GraphicsEnvironment
599
- .getLocalGraphicsEnvironment().getScreenDevices()[0];
720
+//static GraphicsDevice device = GraphicsEnvironment
721
+// .getLocalGraphicsEnvironment().getScreenDevices()[0];
600722
601723 Rectangle keeprect;
602724 cRadio radio;
....@@ -612,13 +734,24 @@
612734
613735 boolean maximized;
614736
737
+ cButton fullscreenLayout;
738
+
615739 void Minimize()
616740 {
617741 frame.setState(Frame.ICONIFIED);
742
+ frame.validate();
618743 }
619744
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={}
620748 void Maximize()
621749 {
750
+ if (CameraPane.FULLSCREEN)
751
+ {
752
+ ToggleFullScreen();
753
+ }
754
+
622755 if (maximized)
623756 {
624757 frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
....@@ -626,20 +759,36 @@
626759 else
627760 {
628761 keeprect = frame.getBounds();
629
- Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
630
- Dimension rect2 = frame.getToolkit().getScreenSize();
631
- 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);
632765 // frame.setState(Frame.MAXIMIZED_BOTH);
766
+ frame.setBounds(frame.getGraphicsConfiguration().getBounds());
633767 }
634768
635769 maximized ^= true;
770
+
771
+ frame.validate();
636772 }
773
+
774
+ cButton minButton;
775
+ cButton maxButton;
776
+ cButton fullButton;
637777
638778 void ToggleFullScreen()
639779 {
640
- if (CameraPane.FULLSCREEN)
780
+GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
781
+
782
+ cameraView.ToggleFullScreen();
783
+
784
+ if (!CameraPane.FULLSCREEN)
641785 {
642786 device.setFullScreenWindow(null);
787
+ frame.dispose();
788
+ frame.setUndecorated(false);
789
+ frame.validate();
790
+ frame.setVisible(true);
791
+
643792 //frame.setVisible(false);
644793 // frame.removeNotify();
645794 // frame.setUndecorated(false);
....@@ -649,7 +798,7 @@
649798 // X frame.getContentPane().remove(/*"Center",*/bigThree);
650799 // X framePanel.add(bigThree);
651800 // X frame.getContentPane().add(/*"Center",*/framePanel);
652
- framePanel.setDividerLocation(1);
801
+ framePanel.setDividerLocation(46);
653802
654803 //frame.setVisible(true);
655804 radio.layout = keepButton;
....@@ -664,7 +813,12 @@
664813 // frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
665814 // frame.getToolkit().getScreenSize().height);
666815 //frame.setVisible(false);
816
+
817
+ frame.dispose();
818
+ frame.setUndecorated(true);
667819 device.setFullScreenWindow(frame);
820
+ frame.validate();
821
+ frame.setVisible(true);
668822 // frame.removeNotify();
669823 // frame.setUndecorated(true);
670824 // frame.addNotify();
....@@ -673,13 +827,34 @@
673827 // X frame.getContentPane().add(/*"Center",*/bigThree);
674828 framePanel.setDividerLocation(0);
675829
676
- radio.layout = twoButton;
830
+ radio.layout = fullscreenLayout;
677831 radio.layout.doClick();
678832 //frame.setVisible(true);
679833 }
680
-
681
- cameraView.ToggleFullScreen();
834
+ frame.validate();
682835 }
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
+ }
683858
684859 private JTextPane createTextPane()
685860 {
....@@ -819,7 +994,12 @@
819994 JCheckBox speedupCB;
820995 JCheckBox rewindCB;
821996 JCheckBox flipVCB;
997
+
998
+ cCheckBox toggleTextureCB;
999
+ cCheckBox toggleSwitchCB;
1000
+
8221001 JComboBox texresMenu;
1002
+
8231003 JButton resetButton;
8241004 JButton stepButton;
8251005 JButton stepAllButton;
....@@ -1006,12 +1186,12 @@
10061186 namePanel = new cGridBag();
10071187
10081188 nameField = AddText(namePanel, copy.GetName());
1009
- namePanel.add(nameField);
1189
+ namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
10101190 oe.ctrlPanel.add(namePanel);
10111191
10121192 oe.ctrlPanel.Return();
10131193
1014
- if (!GroupEditor.allparams)
1194
+ if (!allparams)
10151195 return;
10161196
10171197 setupPanel = new cGridBag().setVertical(false);
....@@ -1024,20 +1204,21 @@
10241204 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
10251205 hideCB.setToolTipText("Hide object");
10261206 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
1027
- markCB.setToolTipText("Set the animation target transform");
1207
+ markCB.setToolTipText("As animation target transform");
10281208
10291209 setupPanel2 = new cGridBag().setVertical(false);
10301210
10311211 rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
10321212 rewindCB.setToolTipText("Rewind animation");
10331213
1034
- randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1035
- 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)");
10361216
1217
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1218
+ link2masterCB.setToolTipText("Attach to support");
1219
+
10371220 if (Globals.ADVANCED)
10381221 {
1039
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1040
- link2masterCB.setToolTipText("Attach to support");
10411222 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
10421223 speedupCB.setToolTipText("Option motion capture");
10431224 }
....@@ -1353,7 +1534,11 @@
13531534 // north.add(ctrlPanel, BorderLayout.NORTH);
13541535 // objectPanel.add(north);
13551536 objectPanel.add(editPanel);
1356
- objectPanel.add(infoPanel);
1537
+
1538
+ //if (Globals.ADVANCED)
1539
+ objectPanel.add(infoPanel);
1540
+
1541
+ objectPanel.add(toolboxPanel);
13571542
13581543 /*
13591544 aConstraints.gridx = 0;
....@@ -1362,7 +1547,7 @@
13621547 aConstraints.gridy += 1;
13631548 aConstraints.gridwidth = 1;
13641549 mainPanel.add(objectPanel, aConstraints);
1365
- */
1550
+ */
13661551
13671552 scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
13681553 VERTICAL_SCROLLBAR_AS_NEEDED,
....@@ -1379,9 +1564,7 @@
13791564 JTabbedPane tabbedPane = new JTabbedPane();
13801565 tabbedPane.add(scrollpane);
13811566
1382
- tabbedPane.add(FSPane = new cFileSystemPane(this));
1383
-
1384
- optionsPanel = new cGridBag().setVertical(true);
1567
+ optionsPanel = new cGridBag().setVertical(false);
13851568
13861569 optionsPanel.setName("Options");
13871570
....@@ -1389,6 +1572,8 @@
13891572
13901573 tabbedPane.add(optionsPanel);
13911574
1575
+ tabbedPane.add(FSPane = new cFileSystemPane(this));
1576
+
13921577 scenePanel.add(tabbedPane);
13931578
13941579 /*
....@@ -1461,9 +1646,9 @@
14611646 // aConstraints.gridheight = 1;
14621647
14631648 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1464
- framePanel.setContinuousLayout(true);
1465
- framePanel.setOneTouchExpandable(true);
1466
- framePanel.setDividerLocation(0.8);
1649
+ framePanel.setContinuousLayout(false);
1650
+ framePanel.setOneTouchExpandable(false);
1651
+ //.setDividerLocation(0.8);
14671652 //framePanel.setDividerSize(15);
14681653 //framePanel.setResizeWeight(0.15);
14691654 framePanel.setName("Frame");
....@@ -1481,11 +1666,14 @@
14811666 // aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc);
14821667
14831668 frame.setSize(1280, 860);
1484
- frame.setVisible(true);
1485
-
1669
+
14861670 cameraView.requestFocusInWindow();
14871671
14881672 gridPanel.setDividerLocation(1.0);
1673
+
1674
+ frame.validate();
1675
+
1676
+ frame.setVisible(true);
14891677
14901678 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
14911679 frame.addWindowListener(new WindowAdapter()
....@@ -1572,24 +1760,6 @@
15721760 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
15731761 colorSection.add(texture);
15741762
1575
- cGridBag anisoU = new cGridBag();
1576
- anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1577
- anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1578
- anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1579
- colorSection.add(anisoU);
1580
-
1581
- cGridBag anisoV = new cGridBag();
1582
- anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1583
- anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1584
- anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1585
- colorSection.add(anisoV);
1586
-
1587
- cGridBag shadowbias = new cGridBag();
1588
- shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1589
- shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1590
- shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1591
- colorSection.add(shadowbias);
1592
-
15931763 panel.add(new JSeparator());
15941764
15951765 panel.add(colorSection);
....@@ -1639,6 +1809,12 @@
16391809 fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING);
16401810 fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
16411811 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);
16421818
16431819 panel.add(new JSeparator());
16441820
....@@ -1690,6 +1866,18 @@
16901866 // aConstraints.gridy += 1;
16911867 // aConstraints.gridwidth = 1;
16921868
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
+
16931881
16941882 panel.add(new JSeparator());
16951883
....@@ -1697,35 +1885,35 @@
16971885
16981886 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
16991887
1700
- cGridBag globalSection = new cGridBag().setVertical(true);
1888
+ //cGridBag globalSection = new cGridBag().setVertical(true);
17011889
17021890 cGridBag camera = new cGridBag();
17031891 camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints);
17041892 cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17051893 camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1706
- globalSection.add(camera);
1894
+ colorSection.add(camera);
17071895
17081896 cGridBag ambient = new cGridBag();
17091897 ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints);
17101898 ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17111899 ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1712
- globalSection.add(ambient);
1900
+ colorSection.add(ambient);
17131901
17141902 cGridBag backlit = new cGridBag();
17151903 backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints);
17161904 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17171905 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1718
- globalSection.add(backlit);
1906
+ colorSection.add(backlit);
17191907
17201908 cGridBag opacity = new cGridBag();
17211909 opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
17221910 opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17231911 opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1724
- globalSection.add(opacity);
1912
+ colorSection.add(opacity);
17251913
1726
- panel.add(new JSeparator());
1914
+ //panel.add(new JSeparator());
17271915
1728
- panel.add(globalSection);
1916
+ //panel.add(globalSection);
17291917
17301918 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17311919
....@@ -1832,8 +2020,9 @@
18322020 // 3D models
18332021 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
18342022 {
1835
- lastConverter = new com.jmex.model.converters.MaxToJme();
1836
- LoadFile(filename, lastConverter);
2023
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
2024
+ //LoadFile(filename, lastConverter);
2025
+ LoadObjFile(filename); // New 3ds loader
18372026 continue;
18382027 }
18392028 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2559,6 +2748,7 @@
25592748 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
25602749 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
25612750 }
2751
+
25622752 //cJME.count++;
25632753 //cJME.count %= 12;
25642754 if (gc)
....@@ -2742,6 +2932,7 @@
27422932 }
27432933 }
27442934 }
2935
+
27452936 cFileSystemPane FSPane;
27462937
27472938 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2795,11 +2986,14 @@
27952986 }
27962987 }
27972988 }
2989
+
27982990 freezematerial = false;
27992991 }
28002992
28012993 void SetMaterial(Object3D object)
28022994 {
2995
+ latestObject = object;
2996
+
28032997 cMaterial mat = object.material;
28042998
28052999 if (mat == null)
....@@ -2911,12 +3105,17 @@
29113105 // }
29123106
29133107 /**/
2914
- if (deselect)
3108
+ if (deselect || child == null)
29153109 {
29163110 //group.deselectAll();
29173111 //freeze = true;
29183112 GetTree().clearSelection();
29193113 //freeze = false;
3114
+
3115
+ if (child == null)
3116
+ {
3117
+ return;
3118
+ }
29203119 }
29213120
29223121 //group.addSelectee(child);
....@@ -2985,7 +3184,7 @@
29853184 cameraView.ToggleDL();
29863185 cameraView.repaint();
29873186 return;
2988
- } else if (event.getSource() == toggleTextureItem)
3187
+ } else if (event.getSource() == toggleTextureItem || event.getSource() == toggleTextureCB)
29893188 {
29903189 cameraView.ToggleTexture();
29913190 // june 2013 copy.HardTouch();
....@@ -3024,7 +3223,7 @@
30243223 frame.validate();
30253224
30263225 return;
3027
- } else if (event.getSource() == toggleSwitchItem)
3226
+ } else if (event.getSource() == toggleSwitchItem || event.getSource() == toggleSwitchCB)
30283227 {
30293228 cameraView.ToggleSwitch();
30303229 cameraView.repaint();
....@@ -3240,9 +3439,9 @@
32403439 {
32413440 Close();
32423441 //return true;
3243
- } else if (source == loadItem)
3442
+ } else if (source == openItem)
32443443 {
3245
- load();
3444
+ Open();
32463445 //return true;
32473446 } else if (source == newItem)
32483447 {
....@@ -3267,6 +3466,10 @@
32673466 {
32683467 generatePOV();
32693468 //return true;
3469
+ } else if (event.getSource() == archiveItem)
3470
+ {
3471
+ cTools.Archive(frame);
3472
+ return;
32703473 } else if (source == zBufferItem)
32713474 {
32723475 try
....@@ -3318,8 +3521,8 @@
33183521 try
33193522 {
33203523 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3321
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3322
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3524
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3525
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
33233526
33243527 Object3D parent = o.parent;
33253528 o.parent = null;
....@@ -3330,10 +3533,14 @@
33303533
33313534 out.flush();
33323535
3333
- zstream.close();
3536
+ baos //zstream
3537
+ .close();
33343538 out.close();
33353539
3336
- return baos.toByteArray();
3540
+ byte[] bytes = baos.toByteArray();
3541
+
3542
+ System.out.println("save #bytes = " + bytes.length);
3543
+ return bytes;
33373544 } catch (Exception e)
33383545 {
33393546 System.err.println(e);
....@@ -3343,13 +3550,16 @@
33433550
33443551 static public Object Uncompress(byte[] bytes)
33453552 {
3346
- System.out.println("#bytes = " + bytes.length);
3553
+ System.out.println("restore #bytes = " + bytes.length);
33473554 try
33483555 {
33493556 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3350
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3351
- ObjectInputStream in = new ObjectInputStream(istream);
3557
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3558
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
33523559 Object obj = in.readObject();
3560
+
3561
+ bais //istream
3562
+ .close();
33533563 in.close();
33543564
33553565 return obj;
....@@ -3404,37 +3614,77 @@
34043614 return null;
34053615 }
34063616
3407
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
34083617
34093618 public void Save()
34103619 {
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)
3643
+ {
3644
+ System.err.println("Save");
3645
+
34113646 cRadio tab = GetCurrentTab();
34123647
3413
- boolean temp = CameraPane.SWITCH;
3414
- CameraPane.SWITCH = false;
3648
+ byte[] compress = CompressCopy();
34153649
3416
- 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
+ }
34173657
34183658 //EditorFrame.m_MainFrame.requestFocusInWindow();
3419
- tab.graphs[tab.undoindex++] = Compress(copy);
3420
-
3421
- copy.RestoreBigData(hashtable);
3422
-
3423
- CameraPane.SWITCH = temp;
3424
-
3425
- //assert(hashtable.isEmpty());
3426
-
3427
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3659
+ if (!thesame)
34283660 {
3429
- 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++;
34303668 }
34313669
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
+
34323682 // test save
34333683 if (false)
34343684 {
34353685 try
34363686 {
3437
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3687
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
34383688 ObjectOutputStream p = new ObjectOutputStream(ostream);
34393689
34403690 p.writeObject(copy);
....@@ -3447,14 +3697,18 @@
34473697 e.printStackTrace();
34483698 }
34493699 }
3700
+
3701
+ return !thesame;
34503702 }
34513703
34523704 void CopyChanged(Object3D obj)
34533705 {
3706
+ SetUndoStates();
3707
+
34543708 boolean temp = CameraPane.SWITCH;
34553709 CameraPane.SWITCH = false;
34563710
3457
- copy.ExtractBigData(hashtable);
3711
+ copy.ExtractBigData(versiontable);
34583712
34593713 copy.clear();
34603714
....@@ -3463,7 +3717,7 @@
34633717 copy.add(obj.get(i));
34643718 }
34653719
3466
- copy.RestoreBigData(hashtable);
3720
+ copy.RestoreBigData(versiontable);
34673721
34683722 CameraPane.SWITCH = temp;
34693723
....@@ -3490,40 +3744,130 @@
34903744 refreshContents();
34913745 }
34923746
3493
- public void Undo()
3747
+ cButton undoButton;
3748
+ cButton restoreButton;
3749
+ cButton replaceButton;
3750
+ cButton redoButton;
3751
+
3752
+ boolean muteSlider;
3753
+
3754
+ int VersionCount()
3755
+ {
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()
34943768 {
34953769 cRadio tab = GetCurrentTab();
34963770
3497
- if (tab.undoindex == 0)
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
+
3788
+ System.err.println("Undo");
3789
+
3790
+ cRadio tab = GetCurrentTab();
3791
+
3792
+ if (copy.versionindex == 0)
34983793 {
34993794 java.awt.Toolkit.getDefaultToolkit().beep();
3500
- return;
3795
+ return false;
35013796 }
35023797
3503
- 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)
35043825 {
3505
- Save();
3506
- tab.undoindex -= 1;
3826
+ java.awt.Toolkit.getDefaultToolkit().beep();
3827
+ return false;
35073828 }
35083829
3509
- tab.undoindex -= 1;
3830
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3831
+
3832
+ return true;
3833
+ }
35103834
3511
- 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;
35123850 }
35133851
35143852 public void Redo()
35153853 {
3854
+ // Option?
3855
+ Replace();
3856
+
35163857 cRadio tab = GetCurrentTab();
35173858
3518
- if (tab.graphs[tab.undoindex + 1] == null)
3859
+ if (copy.versions[copy.versionindex + 1] == null)
35193860 {
35203861 java.awt.Toolkit.getDefaultToolkit().beep();
35213862 return;
35223863 }
35233864
3524
- tab.undoindex += 1;
3865
+ copy.versionindex += 1;
35253866
3526
- 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;
35273871 }
35283872
35293873 void ImportGFD()
....@@ -3675,7 +4019,7 @@
36754019 assert false;
36764020 }
36774021
3678
- void EditSelection()
4022
+ void EditSelection(boolean newWindow)
36794023 {
36804024 }
36814025
....@@ -3819,9 +4163,25 @@
38194163 //copy.Touch();
38204164 }
38214165
4166
+ cNumberSlider versionSlider;
4167
+
38224168 public void stateChanged(ChangeEvent e)
38234169 {
38244170 // 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
+ }
38254185
38264186 if (freezematerial)
38274187 {
....@@ -4170,7 +4530,8 @@
41704530
41714531 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
41724532 {
4173
- Save();
4533
+ if (Globals.REPLACEONMAKE) // && resetmodel)
4534
+ Save();
41744535 //Tween.set(thing, 0).target(1).start(tweenManager);
41754536 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
41764537 // if (thing instanceof GenericJointDemo)
....@@ -4257,6 +4618,12 @@
42574618 {
42584619 ResetModel();
42594620 Select(thing.GetTreePath(), true, false); // unselect... false);
4621
+
4622
+ if (thing.Size() == 0)
4623
+ {
4624
+ //EditSelection(false);
4625
+ }
4626
+
42604627 refreshContents();
42614628 }
42624629
....@@ -4479,7 +4846,8 @@
44794846
44804847 if (readobj != null)
44814848 {
4482
- Save();
4849
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4850
+ // Save();
44834851 try
44844852 {
44854853 //readobj.deepCopySelf(copy);
....@@ -4534,13 +4902,24 @@
45344902 c.addChild(csg);
45354903 }
45364904
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
+
45374916 ResetModel();
45384917 copy.HardTouch(); // recompile?
45394918 refreshContents();
45404919 }
45414920 }
45424921
4543
- void load() // throws ClassNotFoundException
4922
+ void Open() // throws ClassNotFoundException
45444923 {
45454924 if (Grafreed.standAlone)
45464925 {
....@@ -4657,6 +5036,8 @@
46575036 String filename = browser.getFile();
46585037 if (filename != null && filename.length() > 0)
46595038 {
5039
+ if (!filename.endsWith(".gfd"))
5040
+ filename += ".gfd";
46605041 lastname = browser.getDirectory() + filename;
46615042 save();
46625043 }
....@@ -4823,7 +5204,7 @@
48235204 MenuBar menuBar;
48245205 Menu fileMenu;
48255206 MenuItem newItem;
4826
- MenuItem loadItem;
5207
+ MenuItem openItem;
48275208 MenuItem saveItem;
48285209 MenuItem saveAsItem;
48295210 MenuItem exportAsItem;
....@@ -4846,22 +5227,36 @@
48465227 CheckboxMenuItem toggleSwitchItem;
48475228 CheckboxMenuItem toggleRootItem;
48485229 CheckboxMenuItem animationItem;
5230
+ MenuItem archiveItem;
48495231 CheckboxMenuItem toggleHandleItem;
48505232 CheckboxMenuItem togglePaintItem;
48515233 JSplitPane mainPanel;
48525234 JScrollPane scrollpane;
5235
+
48535236 JPanel toolbarPanel;
5237
+
48545238 cGridBag treePanel;
5239
+
48555240 JPanel radioPanel;
48565241 ButtonGroup buttonGroup;
4857
- cGridBag ctrlPanel;
5242
+
5243
+ cGridBag toolboxPanel;
48585244 cGridBag materialPanel;
5245
+ cGridBag ctrlPanel;
5246
+
48595247 JScrollPane infoPanel;
5248
+
48605249 cGridBag optionsPanel;
5250
+
48615251 JTabbedPane objectPanel;
5252
+ boolean materialFlushed;
5253
+ Object3D latestObject;
5254
+
48625255 cGridBag XYZPanel;
5256
+
48635257 JSplitPane gridPanel;
48645258 JSplitPane bigPanel;
5259
+
48655260 cGridBag bigThree;
48665261 cGridBag scenePanel;
48675262 cGridBag centralPanel;
....@@ -4976,7 +5371,7 @@
49765371 cNumberSlider fogField;
49775372 JLabel opacityPowerLabel;
49785373 cNumberSlider opacityPowerField;
4979
- JTree jTree;
5374
+ cTree jTree;
49805375 //ObjectUI parent;
49815376
49825377 cNumberSlider normalpushField;