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);
....@@ -171,7 +234,7 @@
171234
172235 objEditor.ctrlPanel.remove(setupPanel);
173236 objEditor.ctrlPanel.remove(setupPanel2);
174
- objEditor.ctrlPanel.remove(commandsPanel);
237
+ objEditor.ctrlPanel.remove(objectCommandsPanel);
175238 objEditor.ctrlPanel.remove(pushPanel);
176239 //objEditor.ctrlPanel.remove(fillPanel);
177240
....@@ -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,14 +409,52 @@
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();
329441 treePanel.setName("Tree");
442
+
443
+ editPanel = new cGridBag().setVertical(true);
444
+ editPanel.setName("Edit");
445
+
330446 ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout());
331
- ctrlPanel.setName("Edit");
447
+
448
+ editCommandsPanel = new cGridBag();
449
+ editPanel.add(editCommandsPanel);
450
+ editPanel.add(ctrlPanel);
451
+
452
+ toolboxPanel = new cGridBag().setVertical(false);
453
+ toolboxPanel.setName("Toolbox");
454
+
332455 materialPanel = new cGridBag().setVertical(true);
333456 materialPanel.setName("Material");
457
+
334458 /*JTextPane*/
335459 infoarea = createTextPane();
336460 doc = infoarea.getStyledDocument();
....@@ -343,7 +467,7 @@
343467 // TEXTAREA infoarea.setLineWrap(true);
344468 // TEXTAREA infoarea.setWrapStyleWord(true);
345469 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
346
- infoPanel.setPreferredSize(new Dimension(50, 200));
470
+ infoPanel.setPreferredSize(new Dimension(1, 1));
347471 infoPanel.setName("Info");
348472 //infoPanel.setLayout(new BorderLayout());
349473 //infoPanel.add(createTextPane());
....@@ -355,7 +479,14 @@
355479 mainPanel.setDividerSize(9);
356480 mainPanel.setDividerLocation(0.5); //1.0);
357481 mainPanel.setResizeWeight(0.5);
358
-
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
+
359490 //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5));
360491 //mainPanel.setLayout(new GridBagLayout());
361492 toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
....@@ -586,8 +717,8 @@
586717 }
587718 }
588719
589
-static GraphicsDevice device = GraphicsEnvironment
590
- .getLocalGraphicsEnvironment().getScreenDevices()[0];
720
+//static GraphicsDevice device = GraphicsEnvironment
721
+// .getLocalGraphicsEnvironment().getScreenDevices()[0];
591722
592723 Rectangle keeprect;
593724 cRadio radio;
....@@ -603,13 +734,24 @@
603734
604735 boolean maximized;
605736
737
+ cButton fullscreenLayout;
738
+
606739 void Minimize()
607740 {
608741 frame.setState(Frame.ICONIFIED);
742
+ frame.validate();
609743 }
610744
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={}
611748 void Maximize()
612749 {
750
+ if (CameraPane.FULLSCREEN)
751
+ {
752
+ ToggleFullScreen();
753
+ }
754
+
613755 if (maximized)
614756 {
615757 frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
....@@ -617,20 +759,36 @@
617759 else
618760 {
619761 keeprect = frame.getBounds();
620
- Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
621
- Dimension rect2 = frame.getToolkit().getScreenSize();
622
- 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);
623765 // frame.setState(Frame.MAXIMIZED_BOTH);
766
+ frame.setBounds(frame.getGraphicsConfiguration().getBounds());
624767 }
625768
626769 maximized ^= true;
770
+
771
+ frame.validate();
627772 }
773
+
774
+ cButton minButton;
775
+ cButton maxButton;
776
+ cButton fullButton;
628777
629778 void ToggleFullScreen()
630779 {
631
- if (CameraPane.FULLSCREEN)
780
+GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
781
+
782
+ cameraView.ToggleFullScreen();
783
+
784
+ if (!CameraPane.FULLSCREEN)
632785 {
633786 device.setFullScreenWindow(null);
787
+ frame.dispose();
788
+ frame.setUndecorated(false);
789
+ frame.validate();
790
+ frame.setVisible(true);
791
+
634792 //frame.setVisible(false);
635793 // frame.removeNotify();
636794 // frame.setUndecorated(false);
....@@ -640,7 +798,7 @@
640798 // X frame.getContentPane().remove(/*"Center",*/bigThree);
641799 // X framePanel.add(bigThree);
642800 // X frame.getContentPane().add(/*"Center",*/framePanel);
643
- framePanel.setDividerLocation(1);
801
+ framePanel.setDividerLocation(46);
644802
645803 //frame.setVisible(true);
646804 radio.layout = keepButton;
....@@ -655,7 +813,12 @@
655813 // frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
656814 // frame.getToolkit().getScreenSize().height);
657815 //frame.setVisible(false);
816
+
817
+ frame.dispose();
818
+ frame.setUndecorated(true);
658819 device.setFullScreenWindow(frame);
820
+ frame.validate();
821
+ frame.setVisible(true);
659822 // frame.removeNotify();
660823 // frame.setUndecorated(true);
661824 // frame.addNotify();
....@@ -664,13 +827,34 @@
664827 // X frame.getContentPane().add(/*"Center",*/bigThree);
665828 framePanel.setDividerLocation(0);
666829
667
- radio.layout = twoButton;
830
+ radio.layout = fullscreenLayout;
668831 radio.layout.doClick();
669832 //frame.setVisible(true);
670833 }
671
-
672
- cameraView.ToggleFullScreen();
834
+ frame.validate();
673835 }
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
+ }
674858
675859 private JTextPane createTextPane()
676860 {
....@@ -810,7 +994,12 @@
810994 JCheckBox speedupCB;
811995 JCheckBox rewindCB;
812996 JCheckBox flipVCB;
997
+
998
+ cCheckBox toggleTextureCB;
999
+ cCheckBox toggleSwitchCB;
1000
+
8131001 JComboBox texresMenu;
1002
+
8141003 JButton resetButton;
8151004 JButton stepButton;
8161005 JButton stepAllButton;
....@@ -819,10 +1008,13 @@
8191008 JButton fasterButton;
8201009 JButton remarkButton;
8211010
1011
+ cGridBag editPanel;
1012
+ cGridBag editCommandsPanel;
1013
+
8221014 cGridBag namePanel;
8231015 cGridBag setupPanel;
8241016 cGridBag setupPanel2;
825
- cGridBag commandsPanel;
1017
+ cGridBag objectCommandsPanel;
8261018 cGridBag pushPanel;
8271019 cGridBag fillPanel;
8281020
....@@ -994,12 +1186,12 @@
9941186 namePanel = new cGridBag();
9951187
9961188 nameField = AddText(namePanel, copy.GetName());
997
- namePanel.add(nameField);
1189
+ namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
9981190 oe.ctrlPanel.add(namePanel);
9991191
10001192 oe.ctrlPanel.Return();
10011193
1002
- if (!GroupEditor.allparams)
1194
+ if (!allparams)
10031195 return;
10041196
10051197 setupPanel = new cGridBag().setVertical(false);
....@@ -1012,20 +1204,21 @@
10121204 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
10131205 hideCB.setToolTipText("Hide object");
10141206 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
1015
- markCB.setToolTipText("Set the animation target transform");
1207
+ markCB.setToolTipText("As animation target transform");
10161208
10171209 setupPanel2 = new cGridBag().setVertical(false);
10181210
10191211 rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
10201212 rewindCB.setToolTipText("Rewind animation");
10211213
1022
- randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1023
- 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)");
10241216
1217
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1218
+ link2masterCB.setToolTipText("Attach to support");
1219
+
10251220 if (Globals.ADVANCED)
10261221 {
1027
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1028
- link2masterCB.setToolTipText("Attach to support");
10291222 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
10301223 speedupCB.setToolTipText("Option motion capture");
10311224 }
....@@ -1035,23 +1228,23 @@
10351228 oe.ctrlPanel.add(setupPanel2);
10361229 oe.ctrlPanel.Return();
10371230
1038
- commandsPanel = new cGridBag().setVertical(false);
1231
+ objectCommandsPanel = new cGridBag().setVertical(false);
10391232
1040
- resetButton = AddButton(commandsPanel, "Reset");
1233
+ resetButton = AddButton(objectCommandsPanel, "Reset");
10411234 resetButton.setToolTipText("Jump to frame zero");
1042
- stepButton = AddButton(commandsPanel, "Step");
1235
+ stepButton = AddButton(objectCommandsPanel, "Step");
10431236 stepButton.setToolTipText("Step one frame");
10441237 // resetAllButton = AddButton(oe, "Reset All");
10451238 // stepAllButton = AddButton(oe, "Step All");
10461239 // Return();
1047
- slowerButton = AddButton(commandsPanel, "Slow");
1240
+ slowerButton = AddButton(objectCommandsPanel, "Slow");
10481241 slowerButton.setToolTipText("Decrease animation speed");
1049
- fasterButton = AddButton(commandsPanel, "Fast");
1242
+ fasterButton = AddButton(objectCommandsPanel, "Fast");
10501243 fasterButton.setToolTipText("Increase animation speed");
1051
- remarkButton = AddButton(commandsPanel, "Remark");
1244
+ remarkButton = AddButton(objectCommandsPanel, "Remark");
10521245 remarkButton.setToolTipText("Set the current transform as the target");
10531246
1054
- oe.ctrlPanel.add(commandsPanel);
1247
+ oe.ctrlPanel.add(objectCommandsPanel);
10551248 oe.ctrlPanel.Return();
10561249
10571250 pushPanel = AddSlider(oe.ctrlPanel, "Push", -1, 1, copy.NORMALPUSH, 1.1); // To have the buttons
....@@ -1340,8 +1533,12 @@
13401533 // north.setName("Edit");
13411534 // north.add(ctrlPanel, BorderLayout.NORTH);
13421535 // objectPanel.add(north);
1343
- objectPanel.add(ctrlPanel);
1344
- objectPanel.add(infoPanel);
1536
+ objectPanel.add(editPanel);
1537
+
1538
+ //if (Globals.ADVANCED)
1539
+ objectPanel.add(infoPanel);
1540
+
1541
+ objectPanel.add(toolboxPanel);
13451542
13461543 /*
13471544 aConstraints.gridx = 0;
....@@ -1350,7 +1547,7 @@
13501547 aConstraints.gridy += 1;
13511548 aConstraints.gridwidth = 1;
13521549 mainPanel.add(objectPanel, aConstraints);
1353
- */
1550
+ */
13541551
13551552 scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
13561553 VERTICAL_SCROLLBAR_AS_NEEDED,
....@@ -1367,9 +1564,7 @@
13671564 JTabbedPane tabbedPane = new JTabbedPane();
13681565 tabbedPane.add(scrollpane);
13691566
1370
- tabbedPane.add(FSPane = new cFileSystemPane(this));
1371
-
1372
- optionsPanel = new cGridBag().setVertical(true);
1567
+ optionsPanel = new cGridBag().setVertical(false);
13731568
13741569 optionsPanel.setName("Options");
13751570
....@@ -1377,6 +1572,8 @@
13771572
13781573 tabbedPane.add(optionsPanel);
13791574
1575
+ tabbedPane.add(FSPane = new cFileSystemPane(this));
1576
+
13801577 scenePanel.add(tabbedPane);
13811578
13821579 /*
....@@ -1449,9 +1646,9 @@
14491646 // aConstraints.gridheight = 1;
14501647
14511648 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1452
- framePanel.setContinuousLayout(true);
1453
- framePanel.setOneTouchExpandable(true);
1454
- framePanel.setDividerLocation(0.8);
1649
+ framePanel.setContinuousLayout(false);
1650
+ framePanel.setOneTouchExpandable(false);
1651
+ //.setDividerLocation(0.8);
14551652 //framePanel.setDividerSize(15);
14561653 //framePanel.setResizeWeight(0.15);
14571654 framePanel.setName("Frame");
....@@ -1469,11 +1666,14 @@
14691666 // aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc);
14701667
14711668 frame.setSize(1280, 860);
1472
- frame.setVisible(true);
1473
-
1669
+
14741670 cameraView.requestFocusInWindow();
14751671
14761672 gridPanel.setDividerLocation(1.0);
1673
+
1674
+ frame.validate();
1675
+
1676
+ frame.setVisible(true);
14771677
14781678 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
14791679 frame.addWindowListener(new WindowAdapter()
....@@ -1560,24 +1760,6 @@
15601760 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
15611761 colorSection.add(texture);
15621762
1563
- cGridBag anisoU = new cGridBag();
1564
- anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1565
- anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1566
- anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1567
- colorSection.add(anisoU);
1568
-
1569
- cGridBag anisoV = new cGridBag();
1570
- anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1571
- anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1572
- anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1573
- colorSection.add(anisoV);
1574
-
1575
- cGridBag shadowbias = new cGridBag();
1576
- shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1577
- shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1578
- shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1579
- colorSection.add(shadowbias);
1580
-
15811763 panel.add(new JSeparator());
15821764
15831765 panel.add(colorSection);
....@@ -1627,6 +1809,12 @@
16271809 fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING);
16281810 fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
16291811 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);
16301818
16311819 panel.add(new JSeparator());
16321820
....@@ -1678,6 +1866,18 @@
16781866 // aConstraints.gridy += 1;
16791867 // aConstraints.gridwidth = 1;
16801868
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
+
16811881
16821882 panel.add(new JSeparator());
16831883
....@@ -1685,35 +1885,35 @@
16851885
16861886 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
16871887
1688
- cGridBag globalSection = new cGridBag().setVertical(true);
1888
+ //cGridBag globalSection = new cGridBag().setVertical(true);
16891889
16901890 cGridBag camera = new cGridBag();
16911891 camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints);
16921892 cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING);
16931893 camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1694
- globalSection.add(camera);
1894
+ colorSection.add(camera);
16951895
16961896 cGridBag ambient = new cGridBag();
16971897 ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints);
16981898 ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING);
16991899 ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1700
- globalSection.add(ambient);
1900
+ colorSection.add(ambient);
17011901
17021902 cGridBag backlit = new cGridBag();
17031903 backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints);
17041904 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17051905 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1706
- globalSection.add(backlit);
1906
+ colorSection.add(backlit);
17071907
17081908 cGridBag opacity = new cGridBag();
17091909 opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
17101910 opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17111911 opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1712
- globalSection.add(opacity);
1912
+ colorSection.add(opacity);
17131913
1714
- panel.add(new JSeparator());
1914
+ //panel.add(new JSeparator());
17151915
1716
- panel.add(globalSection);
1916
+ //panel.add(globalSection);
17171917
17181918 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17191919
....@@ -1820,8 +2020,9 @@
18202020 // 3D models
18212021 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
18222022 {
1823
- lastConverter = new com.jmex.model.converters.MaxToJme();
1824
- LoadFile(filename, lastConverter);
2023
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
2024
+ //LoadFile(filename, lastConverter);
2025
+ LoadObjFile(filename); // New 3ds loader
18252026 continue;
18262027 }
18272028 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2547,6 +2748,7 @@
25472748 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
25482749 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
25492750 }
2751
+
25502752 //cJME.count++;
25512753 //cJME.count %= 12;
25522754 if (gc)
....@@ -2730,6 +2932,7 @@
27302932 }
27312933 }
27322934 }
2935
+
27332936 cFileSystemPane FSPane;
27342937
27352938 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2783,11 +2986,14 @@
27832986 }
27842987 }
27852988 }
2989
+
27862990 freezematerial = false;
27872991 }
27882992
27892993 void SetMaterial(Object3D object)
27902994 {
2995
+ latestObject = object;
2996
+
27912997 cMaterial mat = object.material;
27922998
27932999 if (mat == null)
....@@ -2899,12 +3105,17 @@
28993105 // }
29003106
29013107 /**/
2902
- if (deselect)
3108
+ if (deselect || child == null)
29033109 {
29043110 //group.deselectAll();
29053111 //freeze = true;
29063112 GetTree().clearSelection();
29073113 //freeze = false;
3114
+
3115
+ if (child == null)
3116
+ {
3117
+ return;
3118
+ }
29083119 }
29093120
29103121 //group.addSelectee(child);
....@@ -2973,7 +3184,7 @@
29733184 cameraView.ToggleDL();
29743185 cameraView.repaint();
29753186 return;
2976
- } else if (event.getSource() == toggleTextureItem)
3187
+ } else if (event.getSource() == toggleTextureItem || event.getSource() == toggleTextureCB)
29773188 {
29783189 cameraView.ToggleTexture();
29793190 // june 2013 copy.HardTouch();
....@@ -3012,7 +3223,7 @@
30123223 frame.validate();
30133224
30143225 return;
3015
- } else if (event.getSource() == toggleSwitchItem)
3226
+ } else if (event.getSource() == toggleSwitchItem || event.getSource() == toggleSwitchCB)
30163227 {
30173228 cameraView.ToggleSwitch();
30183229 cameraView.repaint();
....@@ -3228,9 +3439,9 @@
32283439 {
32293440 Close();
32303441 //return true;
3231
- } else if (source == loadItem)
3442
+ } else if (source == openItem)
32323443 {
3233
- load();
3444
+ Open();
32343445 //return true;
32353446 } else if (source == newItem)
32363447 {
....@@ -3255,6 +3466,10 @@
32553466 {
32563467 generatePOV();
32573468 //return true;
3469
+ } else if (event.getSource() == archiveItem)
3470
+ {
3471
+ cTools.Archive(frame);
3472
+ return;
32583473 } else if (source == zBufferItem)
32593474 {
32603475 try
....@@ -3306,8 +3521,8 @@
33063521 try
33073522 {
33083523 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3309
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3310
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3524
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3525
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
33113526
33123527 Object3D parent = o.parent;
33133528 o.parent = null;
....@@ -3318,10 +3533,14 @@
33183533
33193534 out.flush();
33203535
3321
- zstream.close();
3536
+ baos //zstream
3537
+ .close();
33223538 out.close();
33233539
3324
- return baos.toByteArray();
3540
+ byte[] bytes = baos.toByteArray();
3541
+
3542
+ System.out.println("save #bytes = " + bytes.length);
3543
+ return bytes;
33253544 } catch (Exception e)
33263545 {
33273546 System.err.println(e);
....@@ -3331,13 +3550,16 @@
33313550
33323551 static public Object Uncompress(byte[] bytes)
33333552 {
3334
- System.out.println("#bytes = " + bytes.length);
3553
+ System.out.println("restore #bytes = " + bytes.length);
33353554 try
33363555 {
33373556 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3338
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3339
- ObjectInputStream in = new ObjectInputStream(istream);
3557
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3558
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
33403559 Object obj = in.readObject();
3560
+
3561
+ bais //istream
3562
+ .close();
33413563 in.close();
33423564
33433565 return obj;
....@@ -3392,37 +3614,77 @@
33923614 return null;
33933615 }
33943616
3395
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
33963617
33973618 public void Save()
33983619 {
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
+
33993646 cRadio tab = GetCurrentTab();
34003647
3401
- boolean temp = CameraPane.SWITCH;
3402
- CameraPane.SWITCH = false;
3648
+ byte[] compress = CompressCopy();
34033649
3404
- 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
+ }
34053657
34063658 //EditorFrame.m_MainFrame.requestFocusInWindow();
3407
- tab.graphs[tab.undoindex++] = Compress(copy);
3408
-
3409
- copy.RestoreBigData(hashtable);
3410
-
3411
- CameraPane.SWITCH = temp;
3412
-
3413
- //assert(hashtable.isEmpty());
3414
-
3415
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3659
+ if (!thesame)
34163660 {
3417
- 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++;
34183668 }
34193669
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
+
34203682 // test save
34213683 if (false)
34223684 {
34233685 try
34243686 {
3425
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3687
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
34263688 ObjectOutputStream p = new ObjectOutputStream(ostream);
34273689
34283690 p.writeObject(copy);
....@@ -3435,14 +3697,18 @@
34353697 e.printStackTrace();
34363698 }
34373699 }
3700
+
3701
+ return !thesame;
34383702 }
34393703
34403704 void CopyChanged(Object3D obj)
34413705 {
3706
+ SetUndoStates();
3707
+
34423708 boolean temp = CameraPane.SWITCH;
34433709 CameraPane.SWITCH = false;
34443710
3445
- copy.ExtractBigData(hashtable);
3711
+ copy.ExtractBigData(versiontable);
34463712
34473713 copy.clear();
34483714
....@@ -3451,7 +3717,7 @@
34513717 copy.add(obj.get(i));
34523718 }
34533719
3454
- copy.RestoreBigData(hashtable);
3720
+ copy.RestoreBigData(versiontable);
34553721
34563722 CameraPane.SWITCH = temp;
34573723
....@@ -3478,40 +3744,130 @@
34783744 refreshContents();
34793745 }
34803746
3481
- 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()
34823768 {
34833769 cRadio tab = GetCurrentTab();
34843770
3485
- 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)
34863793 {
34873794 java.awt.Toolkit.getDefaultToolkit().beep();
3488
- return;
3795
+ return false;
34893796 }
34903797
3491
- 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)
34923825 {
3493
- Save();
3494
- tab.undoindex -= 1;
3826
+ java.awt.Toolkit.getDefaultToolkit().beep();
3827
+ return false;
34953828 }
34963829
3497
- tab.undoindex -= 1;
3830
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3831
+
3832
+ return true;
3833
+ }
34983834
3499
- 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;
35003850 }
35013851
35023852 public void Redo()
35033853 {
3854
+ // Option?
3855
+ Replace();
3856
+
35043857 cRadio tab = GetCurrentTab();
35053858
3506
- if (tab.graphs[tab.undoindex + 1] == null)
3859
+ if (copy.versions[copy.versionindex + 1] == null)
35073860 {
35083861 java.awt.Toolkit.getDefaultToolkit().beep();
35093862 return;
35103863 }
35113864
3512
- tab.undoindex += 1;
3865
+ copy.versionindex += 1;
35133866
3514
- 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;
35153871 }
35163872
35173873 void ImportGFD()
....@@ -3663,7 +4019,7 @@
36634019 assert false;
36644020 }
36654021
3666
- void EditSelection()
4022
+ void EditSelection(boolean newWindow)
36674023 {
36684024 }
36694025
....@@ -3807,9 +4163,25 @@
38074163 //copy.Touch();
38084164 }
38094165
4166
+ cNumberSlider versionSlider;
4167
+
38104168 public void stateChanged(ChangeEvent e)
38114169 {
38124170 // 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
+ }
38134185
38144186 if (freezematerial)
38154187 {
....@@ -4158,7 +4530,8 @@
41584530
41594531 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
41604532 {
4161
- Save();
4533
+ if (Globals.REPLACEONMAKE) // && resetmodel)
4534
+ Save();
41624535 //Tween.set(thing, 0).target(1).start(tweenManager);
41634536 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
41644537 // if (thing instanceof GenericJointDemo)
....@@ -4245,6 +4618,12 @@
42454618 {
42464619 ResetModel();
42474620 Select(thing.GetTreePath(), true, false); // unselect... false);
4621
+
4622
+ if (thing.Size() == 0)
4623
+ {
4624
+ //EditSelection(false);
4625
+ }
4626
+
42484627 refreshContents();
42494628 }
42504629
....@@ -4467,7 +4846,8 @@
44674846
44684847 if (readobj != null)
44694848 {
4470
- Save();
4849
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4850
+ // Save();
44714851 try
44724852 {
44734853 //readobj.deepCopySelf(copy);
....@@ -4522,13 +4902,24 @@
45224902 c.addChild(csg);
45234903 }
45244904
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
+
45254916 ResetModel();
45264917 copy.HardTouch(); // recompile?
45274918 refreshContents();
45284919 }
45294920 }
45304921
4531
- void load() // throws ClassNotFoundException
4922
+ void Open() // throws ClassNotFoundException
45324923 {
45334924 if (Grafreed.standAlone)
45344925 {
....@@ -4645,6 +5036,8 @@
46455036 String filename = browser.getFile();
46465037 if (filename != null && filename.length() > 0)
46475038 {
5039
+ if (!filename.endsWith(".gfd"))
5040
+ filename += ".gfd";
46485041 lastname = browser.getDirectory() + filename;
46495042 save();
46505043 }
....@@ -4811,7 +5204,7 @@
48115204 MenuBar menuBar;
48125205 Menu fileMenu;
48135206 MenuItem newItem;
4814
- MenuItem loadItem;
5207
+ MenuItem openItem;
48155208 MenuItem saveItem;
48165209 MenuItem saveAsItem;
48175210 MenuItem exportAsItem;
....@@ -4834,22 +5227,36 @@
48345227 CheckboxMenuItem toggleSwitchItem;
48355228 CheckboxMenuItem toggleRootItem;
48365229 CheckboxMenuItem animationItem;
5230
+ MenuItem archiveItem;
48375231 CheckboxMenuItem toggleHandleItem;
48385232 CheckboxMenuItem togglePaintItem;
48395233 JSplitPane mainPanel;
48405234 JScrollPane scrollpane;
5235
+
48415236 JPanel toolbarPanel;
5237
+
48425238 cGridBag treePanel;
5239
+
48435240 JPanel radioPanel;
48445241 ButtonGroup buttonGroup;
4845
- cGridBag ctrlPanel;
5242
+
5243
+ cGridBag toolboxPanel;
48465244 cGridBag materialPanel;
5245
+ cGridBag ctrlPanel;
5246
+
48475247 JScrollPane infoPanel;
5248
+
48485249 cGridBag optionsPanel;
5250
+
48495251 JTabbedPane objectPanel;
5252
+ boolean materialFlushed;
5253
+ Object3D latestObject;
5254
+
48505255 cGridBag XYZPanel;
5256
+
48515257 JSplitPane gridPanel;
48525258 JSplitPane bigPanel;
5259
+
48535260 cGridBag bigThree;
48545261 cGridBag scenePanel;
48555262 cGridBag centralPanel;
....@@ -4964,7 +5371,7 @@
49645371 cNumberSlider fogField;
49655372 JLabel opacityPowerLabel;
49665373 cNumberSlider opacityPowerField;
4967
- JTree jTree;
5374
+ cTree jTree;
49685375 //ObjectUI parent;
49695376
49705377 cNumberSlider normalpushField;