Normand Briere
2019-07-30 475f8cbdbd96fdbf8f5b216ffebb31a51f25c2f9
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.
....@@ -41,61 +44,47 @@
4144
4245 cButton GetButton(String name, boolean border)
4346 {
44
- try
45
- {
46
- ImageIcon icon = GetIcon(name);
47
- return new cButton(icon, border);
48
- }
49
- catch (Exception e)
50
- {
51
- return new cButton(name, border);
52
- }
47
+ ImageIcon icon = GetIcon(name);
48
+ return new cButton(icon, border);
5349 }
5450
5551 cToggleButton GetToggleButton(String name, boolean border)
5652 {
57
- try
58
- {
59
- ImageIcon icon = GetIcon(name);
60
- return new cToggleButton(icon, border);
61
- }
62
- catch (Exception e)
63
- {
64
- return new cToggleButton(name, border);
65
- }
53
+ ImageIcon icon = GetIcon(name);
54
+ return new cToggleButton(icon, border);
6655 }
6756
6857 cCheckBox GetCheckBox(String name, boolean border)
6958 {
59
+ ImageIcon icon = GetIcon(name);
60
+ return new cCheckBox(icon, border);
61
+ }
62
+
63
+ ImageIcon GetIcon(String name)
64
+ {
7065 try
7166 {
72
- ImageIcon icon = GetIcon(name);
73
- return new cCheckBox(icon, border);
67
+ BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
68
+
69
+// if (image.getWidth() > 48 && image.getHeight() > 48)
70
+// {
71
+// BufferedImage resized = new BufferedImage(48, 48, image.getType());
72
+// Graphics2D g = resized.createGraphics();
73
+// g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
74
+// //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
75
+// g.drawImage(image, 0, 0, 48, 48, 0, 0, image.getWidth(), image.getHeight(), null);
76
+// g.dispose();
77
+//
78
+// image = resized;
79
+// }
80
+
81
+ javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
82
+ return icon;
7483 }
7584 catch (Exception e)
7685 {
77
- return new cCheckBox(name, border);
86
+ return null;
7887 }
79
- }
80
-
81
- private ImageIcon GetIcon(String name) throws IOException
82
- {
83
- BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
84
-
85
- if (image.getWidth() != 24 && image.getHeight() != 24)
86
- {
87
- BufferedImage resized = new BufferedImage(24, 24, image.getType());
88
- Graphics2D g = resized.createGraphics();
89
- g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
90
- //g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
91
- g.drawImage(image, 0, 0, 24, 24, 0, 0, image.getWidth(), image.getHeight(), null);
92
- g.dispose();
93
-
94
- image = resized;
95
- }
96
-
97
- javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image);
98
- return icon;
9988 }
10089
10190 // SCRIPT
....@@ -207,7 +196,7 @@
207196
208197 objEditor.ctrlPanel.remove(namePanel);
209198
210
- if (!GroupEditor.allparams)
199
+ if (!allparams)
211200 return;
212201
213202 // objEditor.ctrlPanel.remove(liveCB);
....@@ -279,6 +268,12 @@
279268 client = inClient;
280269 copy = client;
281270
271
+ if (copy.versions == null)
272
+ {
273
+ copy.versions = new byte[100][];
274
+ copy.versionindex = -1;
275
+ }
276
+
282277 // "this" is not called: SetupUI2(objEditor);
283278 }
284279
....@@ -292,6 +287,12 @@
292287 client = inClient;
293288 copy = client;
294289
290
+ if (copy.versions == null)
291
+ {
292
+ copy.versions = new byte[100][];
293
+ copy.versionindex = -1;
294
+ }
295
+
295296 SetupUI2(callee.GetEditor());
296297 }
297298
....@@ -306,7 +307,7 @@
306307 //localCopy.parent = null;
307308
308309 frame = new JFrame();
309
- frame.setUndecorated(true);
310
+ frame.setUndecorated(false);
310311 objEditor = this;
311312 this.callee = callee;
312313
....@@ -324,6 +325,12 @@
324325 copy = localCopy;
325326 copy.editWindow = this;
326327
328
+ if (copy.versions == null)
329
+ {
330
+// copy.versions = new byte[100][];
331
+// copy.versionindex = -1;
332
+ }
333
+
327334 SetupMenu();
328335
329336 //SetupName(objEditor); // new
....@@ -337,12 +344,17 @@
337344 return frame.action(event, obj);
338345 }
339346
347
+ // Cannot work without static
348
+ static boolean allparams = true;
349
+
350
+ static java.util.Vector<Object3D> listUI = new java.util.Vector<Object3D>();
351
+
340352 void SetupMenu()
341353 {
342354 frame.setMenuBar(menuBar = new MenuBar());
343355 menuBar.add(fileMenu = new Menu("File"));
344356 fileMenu.add(newItem = new MenuItem("New"));
345
- fileMenu.add(loadItem = new MenuItem("Open..."));
357
+ fileMenu.add(openItem = new MenuItem("Open..."));
346358
347359 //oe.menuBar.add(menu = new Menu("Include"));
348360 Menu menu = new Menu("Import");
....@@ -374,7 +386,7 @@
374386 }
375387
376388 newItem.addActionListener(this);
377
- loadItem.addActionListener(this);
389
+ openItem.addActionListener(this);
378390 saveItem.addActionListener(this);
379391 saveAsItem.addActionListener(this);
380392 exportAsItem.addActionListener(this);
....@@ -383,13 +395,40 @@
383395 closeItem.addActionListener(this);
384396
385397 objectPanel = new JTabbedPane();
398
+
399
+ ChangeListener changeListener = new ChangeListener()
400
+ {
401
+ public void stateChanged(ChangeEvent changeEvent)
402
+ {
403
+// if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Material") && !materialFlushed)
404
+// {
405
+// if (latestObject != null)
406
+// {
407
+// refreshContents(true);
408
+// SetMaterial(latestObject);
409
+// }
410
+//
411
+// materialFlushed = true;
412
+// }
413
+// if (objectPanel.getSelectedIndex() == objectPanel.indexOfTab("Edit"))
414
+// {
415
+// if (listUI.size() == 0)
416
+// EditSelection(false);
417
+// }
418
+
419
+ refreshContents(false); // To refresh Info tab
420
+ }
421
+ };
422
+ objectPanel.addChangeListener(changeListener);
423
+
386424 toolbarPanel = new JPanel();
387425 toolbarPanel.setName("Toolbar");
426
+
388427 treePanel = new cGridBag();
389428 treePanel.setName("Tree");
390429
391430 editPanel = new cGridBag().setVertical(true);
392
- editPanel.setName("Edit");
431
+ //editPanel.setName("Edit");
393432
394433 ctrlPanel = new cGridBag().setVertical(false); // new GridBagLayout());
395434
....@@ -397,11 +436,11 @@
397436 editPanel.add(editCommandsPanel);
398437 editPanel.add(ctrlPanel);
399438
400
- toolboxPanel = new cGridBag().setVertical(false);
401
- toolboxPanel.setName("Toolbox");
439
+ toolboxPanel = new cGridBag().setVertical(true);
440
+ //toolboxPanel.setName("Toolbox");
402441
403442 materialPanel = new cGridBag().setVertical(true);
404
- materialPanel.setName("Material");
443
+ //materialPanel.setName("Material");
405444
406445 /*JTextPane*/
407446 infoarea = createTextPane();
....@@ -409,14 +448,15 @@
409448
410449 infoarea.setEditable(true);
411450 SetText();
451
+
412452 // infoarea.setFont(infoarea.getFont().deriveFont(10, 14f));
413453 // infoarea.setOpaque(false);
414454 // //infoarea.setForeground(textcolor);
415455 // TEXTAREA infoarea.setLineWrap(true);
416456 // TEXTAREA infoarea.setWrapStyleWord(true);
417457 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
418
- infoPanel.setPreferredSize(new Dimension(50, 200));
419
- infoPanel.setName("Info");
458
+ infoPanel.setPreferredSize(new Dimension(1, 1));
459
+ //infoPanel.setName("Info");
420460 //infoPanel.setLayout(new BorderLayout());
421461 //infoPanel.add(createTextPane());
422462
....@@ -427,7 +467,14 @@
427467 mainPanel.setDividerSize(9);
428468 mainPanel.setDividerLocation(0.5); //1.0);
429469 mainPanel.setResizeWeight(0.5);
430
-
470
+
471
+//mainPanel.setDividerSize((int) (mainPanel.getDividerSize() * 1.5));
472
+ BasicSplitPaneDivider divider = ( (BasicSplitPaneUI) mainPanel.getUI()).getDivider();
473
+ divider.setDividerSize(15);
474
+ divider.setBorder(BorderFactory.createTitledBorder(divider.getBorder(), "Custom border title -- gets rid of the one-touch arrows!"));
475
+
476
+ mainPanel.setUI(new BasicSplitPaneUI());
477
+
431478 //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5));
432479 //mainPanel.setLayout(new GridBagLayout());
433480 toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
....@@ -658,8 +705,8 @@
658705 }
659706 }
660707
661
-static GraphicsDevice device = GraphicsEnvironment
662
- .getLocalGraphicsEnvironment().getScreenDevices()[0];
708
+//static GraphicsDevice device = GraphicsEnvironment
709
+// .getLocalGraphicsEnvironment().getScreenDevices()[0];
663710
664711 Rectangle keeprect;
665712 cRadio radio;
....@@ -680,10 +727,19 @@
680727 void Minimize()
681728 {
682729 frame.setState(Frame.ICONIFIED);
730
+ frame.validate();
683731 }
684732
733
+// artifactURI=null, type=0, property=${file.reference.jfxrt.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@6767876f, broken=false, additional={}
734
+// artifactURI=null, type=0, property=${file.reference.mac-ui.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@16bdc817, broken=false, additional={}
735
+// artifactURI=null, type=0, property=${file.reference.classes.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@9daa9c17, broken=false, additional={}
685736 void Maximize()
686737 {
738
+ if (CameraPane.FULLSCREEN)
739
+ {
740
+ ToggleFullScreen();
741
+ }
742
+
687743 if (maximized)
688744 {
689745 frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
....@@ -691,20 +747,36 @@
691747 else
692748 {
693749 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);
750
+// Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
751
+// Dimension rect2 = frame.getToolkit().getScreenSize();
752
+// frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
697753 // frame.setState(Frame.MAXIMIZED_BOTH);
754
+ frame.setBounds(frame.getGraphicsConfiguration().getBounds());
698755 }
699756
700757 maximized ^= true;
758
+
759
+ frame.validate();
701760 }
761
+
762
+ cButton minButton;
763
+ cButton maxButton;
764
+ cButton fullButton;
702765
703766 void ToggleFullScreen()
704767 {
705
- if (CameraPane.FULLSCREEN)
768
+GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
769
+
770
+ cameraView.ToggleFullScreen();
771
+
772
+ if (!CameraPane.FULLSCREEN)
706773 {
707774 device.setFullScreenWindow(null);
775
+ frame.dispose();
776
+ frame.setUndecorated(false);
777
+ frame.validate();
778
+ frame.setVisible(true);
779
+
708780 //frame.setVisible(false);
709781 // frame.removeNotify();
710782 // frame.setUndecorated(false);
....@@ -714,7 +786,7 @@
714786 // X frame.getContentPane().remove(/*"Center",*/bigThree);
715787 // X framePanel.add(bigThree);
716788 // X frame.getContentPane().add(/*"Center",*/framePanel);
717
- framePanel.setDividerLocation(1);
789
+ framePanel.setDividerLocation(46);
718790
719791 //frame.setVisible(true);
720792 radio.layout = keepButton;
....@@ -729,7 +801,12 @@
729801 // frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
730802 // frame.getToolkit().getScreenSize().height);
731803 //frame.setVisible(false);
804
+
805
+ frame.dispose();
806
+ frame.setUndecorated(true);
732807 device.setFullScreenWindow(frame);
808
+ frame.validate();
809
+ frame.setVisible(true);
733810 // frame.removeNotify();
734811 // frame.setUndecorated(true);
735812 // frame.addNotify();
....@@ -742,9 +819,30 @@
742819 radio.layout.doClick();
743820 //frame.setVisible(true);
744821 }
745
-
746
- cameraView.ToggleFullScreen();
822
+ frame.validate();
747823 }
824
+
825
+ private byte[] CompressCopy()
826
+ {
827
+ boolean temp = CameraPane.SWITCH;
828
+ CameraPane.SWITCH = false;
829
+
830
+ copy.ExtractBigData(versiontable);
831
+ // if (copy == client)
832
+
833
+ byte[] versions[] = copy.versions;
834
+ copy.versions = null;
835
+
836
+ byte[] compress = Compress(copy);
837
+
838
+ copy.versions = versions;
839
+
840
+ copy.RestoreBigData(versiontable);
841
+
842
+ CameraPane.SWITCH = temp;
843
+
844
+ return compress;
845
+ }
748846
749847 private JTextPane createTextPane()
750848 {
....@@ -876,7 +974,7 @@
876974 // NumberSlider vDivsField;
877975 // JCheckBox endcaps;
878976 JCheckBox liveCB;
879
- JCheckBox selectCB;
977
+ JCheckBox selectableCB;
880978 JCheckBox hideCB;
881979 JCheckBox link2masterCB;
882980 JCheckBox markCB;
....@@ -884,7 +982,12 @@
884982 JCheckBox speedupCB;
885983 JCheckBox rewindCB;
886984 JCheckBox flipVCB;
985
+
986
+ cCheckBox toggleTextureCB;
987
+ cCheckBox toggleSwitchCB;
988
+
887989 JComboBox texresMenu;
990
+
888991 JButton resetButton;
889992 JButton stepButton;
890993 JButton stepAllButton;
....@@ -1071,38 +1174,42 @@
10711174 namePanel = new cGridBag();
10721175
10731176 nameField = AddText(namePanel, copy.GetName());
1074
- namePanel.add(nameField);
1177
+ namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
10751178 oe.ctrlPanel.add(namePanel);
10761179
10771180 oe.ctrlPanel.Return();
10781181
1079
- if (!GroupEditor.allparams)
1182
+ if (!allparams)
10801183 return;
10811184
10821185 setupPanel = new cGridBag().setVertical(false);
10831186
10841187 liveCB = AddCheckBox(setupPanel, "Live", copy.live);
10851188 liveCB.setToolTipText("Animate object");
1086
- selectCB = AddCheckBox(setupPanel, "Select", !copy.dontselect);
1087
- selectCB.setToolTipText("Make object selectable");
1189
+ selectableCB = AddCheckBox(setupPanel, "Select", !copy.dontselect);
1190
+ selectableCB.setToolTipText("Make object selectable");
10881191 // Return();
1192
+
10891193 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
10901194 hideCB.setToolTipText("Hide object");
10911195 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
1092
- markCB.setToolTipText("Set the animation target transform");
1196
+ markCB.setToolTipText("As animation target transform");
1197
+
1198
+ ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
10931199
10941200 setupPanel2 = new cGridBag().setVertical(false);
10951201
10961202 rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
10971203 rewindCB.setToolTipText("Rewind animation");
10981204
1099
- randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1100
- randomCB.setToolTipText("Randomly Rewind or Go back and forth");
1205
+ randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
1206
+ randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11011207
1208
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1209
+ link2masterCB.setToolTipText("Attach to support");
1210
+
11021211 if (Globals.ADVANCED)
11031212 {
1104
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1105
- link2masterCB.setToolTipText("Attach to support");
11061213 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
11071214 speedupCB.setToolTipText("Option motion capture");
11081215 }
....@@ -1376,6 +1483,7 @@
13761483 XYZPanel.addComponent(/*BorderLayout.SOUTH,*/sideView); // Scroll);
13771484 XYZPanel.addComponent(/*BorderLayout.CENTER,*/frontView); // Scroll);
13781485 XYZPanel.addComponent(/*BorderLayout.NORTH,*/topView); // Scroll);
1486
+ //XYZPanel.setName("XYZ");
13791487
13801488 /*
13811489 gridPanel = new JPanel(); //new BorderLayout());
....@@ -1412,14 +1520,24 @@
14121520
14131521 //JScrollPane tmp = new JScrollPane(ctrlPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
14141522 //tmp.setName("Edit");
1415
- objectPanel.add(toolboxPanel);
14161523 objectPanel.add(materialPanel);
1524
+ objectPanel.setIconAt(0, GetIcon("icons/material.png"));
14171525 // JPanel north = new JPanel(new BorderLayout());
14181526 // north.setName("Edit");
14191527 // north.add(ctrlPanel, BorderLayout.NORTH);
14201528 // objectPanel.add(north);
14211529 objectPanel.add(editPanel);
1422
- objectPanel.add(infoPanel);
1530
+ objectPanel.setIconAt(1, GetIcon("icons/write.png"));
1531
+
1532
+ //if (Globals.ADVANCED)
1533
+ objectPanel.add(infoPanel);
1534
+ objectPanel.setIconAt(2, GetIcon("icons/info.png"));
1535
+
1536
+ objectPanel.add(XYZPanel);
1537
+ objectPanel.setIconAt(3, GetIcon("icons/XYZ.png"));
1538
+
1539
+ objectPanel.add(toolboxPanel);
1540
+ objectPanel.setIconAt(4, GetIcon("icons/primitives.png"));
14231541
14241542 /*
14251543 aConstraints.gridx = 0;
....@@ -1428,7 +1546,7 @@
14281546 aConstraints.gridy += 1;
14291547 aConstraints.gridwidth = 1;
14301548 mainPanel.add(objectPanel, aConstraints);
1431
- */
1549
+ */
14321550
14331551 scrollpane = new JScrollPane(mainPanel, ScrollPaneConstants.// VERTICAL_SCROLLBAR_ALWAYS,
14341552 VERTICAL_SCROLLBAR_AS_NEEDED,
....@@ -1440,14 +1558,12 @@
14401558 scrollpane.addMouseWheelListener(this); // Default not fast enough
14411559
14421560 /*JTabbedPane*/ scenePanel = new cGridBag();
1443
- scenePanel.preferredWidth = 6;
1561
+ scenePanel.preferredWidth = 5;
14441562
14451563 JTabbedPane tabbedPane = new JTabbedPane();
14461564 tabbedPane.add(scrollpane);
14471565
1448
- tabbedPane.add(FSPane = new cFileSystemPane(this));
1449
-
1450
- optionsPanel = new cGridBag().setVertical(true);
1566
+ optionsPanel = new cGridBag().setVertical(false);
14511567
14521568 optionsPanel.setName("Options");
14531569
....@@ -1455,6 +1571,8 @@
14551571
14561572 tabbedPane.add(optionsPanel);
14571573
1574
+ tabbedPane.add(FSPane = new cFileSystemPane(this));
1575
+
14581576 scenePanel.add(tabbedPane);
14591577
14601578 /*
....@@ -1516,9 +1634,9 @@
15161634 /**/
15171635
15181636 bigThree = new cGridBag();
1519
- bigThree.addComponent(scenePanel);
15201637 bigThree.addComponent(centralPanel);
1521
- bigThree.addComponent(XYZPanel);
1638
+ bigThree.addComponent(scenePanel);
1639
+ //bigThree.addComponent(XYZPanel);
15221640
15231641 // // SIDE EFFECT!!!
15241642 // aConstraints.gridx = 0;
....@@ -1527,9 +1645,9 @@
15271645 // aConstraints.gridheight = 1;
15281646
15291647 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1530
- framePanel.setContinuousLayout(true);
1531
- framePanel.setOneTouchExpandable(true);
1532
- framePanel.setDividerLocation(0.8);
1648
+ framePanel.setContinuousLayout(false);
1649
+ framePanel.setOneTouchExpandable(false);
1650
+ //.setDividerLocation(0.8);
15331651 //framePanel.setDividerSize(15);
15341652 //framePanel.setResizeWeight(0.15);
15351653 framePanel.setName("Frame");
....@@ -1547,11 +1665,14 @@
15471665 // aConstraints = gbc; // (GridBagConstraints) GrafreeD.clone(gbc);
15481666
15491667 frame.setSize(1280, 860);
1550
- frame.setVisible(true);
1551
-
1668
+
15521669 cameraView.requestFocusInWindow();
15531670
15541671 gridPanel.setDividerLocation(1.0);
1672
+
1673
+ frame.validate();
1674
+
1675
+ frame.setVisible(true);
15551676
15561677 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
15571678 frame.addWindowListener(new WindowAdapter()
....@@ -1638,24 +1759,6 @@
16381759 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
16391760 colorSection.add(texture);
16401761
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
-
16591762 panel.add(new JSeparator());
16601763
16611764 panel.add(colorSection);
....@@ -1705,6 +1808,12 @@
17051808 fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17061809 fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
17071810 diffuseSection.add(fakedepth);
1811
+
1812
+ cGridBag shadowbias = new cGridBag();
1813
+ shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1814
+ shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1815
+ shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1816
+ diffuseSection.add(shadowbias);
17081817
17091818 panel.add(new JSeparator());
17101819
....@@ -1756,6 +1865,18 @@
17561865 // aConstraints.gridy += 1;
17571866 // aConstraints.gridwidth = 1;
17581867
1868
+ cGridBag anisoU = new cGridBag();
1869
+ anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1870
+ anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1871
+ anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1872
+ specularSection.add(anisoU);
1873
+
1874
+ cGridBag anisoV = new cGridBag();
1875
+ anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1876
+ anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1877
+ anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1878
+ specularSection.add(anisoV);
1879
+
17591880
17601881 panel.add(new JSeparator());
17611882
....@@ -1763,35 +1884,35 @@
17631884
17641885 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17651886
1766
- cGridBag globalSection = new cGridBag().setVertical(true);
1887
+ //cGridBag globalSection = new cGridBag().setVertical(true);
17671888
17681889 cGridBag camera = new cGridBag();
17691890 camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints);
17701891 cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17711892 camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1772
- globalSection.add(camera);
1893
+ colorSection.add(camera);
17731894
17741895 cGridBag ambient = new cGridBag();
17751896 ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints);
17761897 ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17771898 ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1778
- globalSection.add(ambient);
1899
+ colorSection.add(ambient);
17791900
17801901 cGridBag backlit = new cGridBag();
17811902 backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints);
17821903 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17831904 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1784
- globalSection.add(backlit);
1905
+ colorSection.add(backlit);
17851906
17861907 cGridBag opacity = new cGridBag();
17871908 opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
17881909 opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17891910 opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1790
- globalSection.add(opacity);
1911
+ colorSection.add(opacity);
17911912
1792
- panel.add(new JSeparator());
1913
+ //panel.add(new JSeparator());
17931914
1794
- panel.add(globalSection);
1915
+ //panel.add(globalSection);
17951916
17961917 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
17971918
....@@ -1898,8 +2019,9 @@
18982019 // 3D models
18992020 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
19002021 {
1901
- lastConverter = new com.jmex.model.converters.MaxToJme();
1902
- LoadFile(filename, lastConverter);
2022
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
2023
+ //LoadFile(filename, lastConverter);
2024
+ LoadObjFile(filename); // New 3ds loader
19032025 continue;
19042026 }
19052027 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2625,6 +2747,7 @@
26252747 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
26262748 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
26272749 }
2750
+
26282751 //cJME.count++;
26292752 //cJME.count %= 12;
26302753 if (gc)
....@@ -2808,6 +2931,7 @@
28082931 }
28092932 }
28102933 }
2934
+
28112935 cFileSystemPane FSPane;
28122936
28132937 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2861,11 +2985,14 @@
28612985 }
28622986 }
28632987 }
2988
+
28642989 freezematerial = false;
28652990 }
28662991
28672992 void SetMaterial(Object3D object)
28682993 {
2994
+ latestObject = object;
2995
+
28692996 cMaterial mat = object.material;
28702997
28712998 if (mat == null)
....@@ -2977,12 +3104,17 @@
29773104 // }
29783105
29793106 /**/
2980
- if (deselect)
3107
+ if (deselect || child == null)
29813108 {
29823109 //group.deselectAll();
29833110 //freeze = true;
29843111 GetTree().clearSelection();
29853112 //freeze = false;
3113
+
3114
+ if (child == null)
3115
+ {
3116
+ return;
3117
+ }
29863118 }
29873119
29883120 //group.addSelectee(child);
....@@ -3051,7 +3183,7 @@
30513183 cameraView.ToggleDL();
30523184 cameraView.repaint();
30533185 return;
3054
- } else if (event.getSource() == toggleTextureItem)
3186
+ } else if (event.getSource() == toggleTextureItem || event.getSource() == toggleTextureCB)
30553187 {
30563188 cameraView.ToggleTexture();
30573189 // june 2013 copy.HardTouch();
....@@ -3090,7 +3222,7 @@
30903222 frame.validate();
30913223
30923224 return;
3093
- } else if (event.getSource() == toggleSwitchItem)
3225
+ } else if (event.getSource() == toggleSwitchItem || event.getSource() == toggleSwitchCB)
30943226 {
30953227 cameraView.ToggleSwitch();
30963228 cameraView.repaint();
....@@ -3121,7 +3253,7 @@
31213253 {
31223254 copy.live ^= true;
31233255 return;
3124
- } else if (event.getSource() == selectCB)
3256
+ } else if (event.getSource() == selectableCB)
31253257 {
31263258 copy.dontselect ^= true;
31273259 return;
....@@ -3306,9 +3438,9 @@
33063438 {
33073439 Close();
33083440 //return true;
3309
- } else if (source == loadItem)
3441
+ } else if (source == openItem)
33103442 {
3311
- load();
3443
+ Open();
33123444 //return true;
33133445 } else if (source == newItem)
33143446 {
....@@ -3333,6 +3465,10 @@
33333465 {
33343466 generatePOV();
33353467 //return true;
3468
+ } else if (event.getSource() == archiveItem)
3469
+ {
3470
+ cTools.Archive(frame);
3471
+ return;
33363472 } else if (source == zBufferItem)
33373473 {
33383474 try
....@@ -3384,8 +3520,8 @@
33843520 try
33853521 {
33863522 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3387
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3388
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3523
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3524
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
33893525
33903526 Object3D parent = o.parent;
33913527 o.parent = null;
....@@ -3396,10 +3532,14 @@
33963532
33973533 out.flush();
33983534
3399
- zstream.close();
3535
+ baos //zstream
3536
+ .close();
34003537 out.close();
34013538
3402
- return baos.toByteArray();
3539
+ byte[] bytes = baos.toByteArray();
3540
+
3541
+ System.out.println("save #bytes = " + bytes.length);
3542
+ return bytes;
34033543 } catch (Exception e)
34043544 {
34053545 System.err.println(e);
....@@ -3409,13 +3549,16 @@
34093549
34103550 static public Object Uncompress(byte[] bytes)
34113551 {
3412
- System.out.println("#bytes = " + bytes.length);
3552
+ System.out.println("restore #bytes = " + bytes.length);
34133553 try
34143554 {
34153555 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3416
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3417
- ObjectInputStream in = new ObjectInputStream(istream);
3556
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3557
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
34183558 Object obj = in.readObject();
3559
+
3560
+ bais //istream
3561
+ .close();
34193562 in.close();
34203563
34213564 return obj;
....@@ -3470,39 +3613,77 @@
34703613 return null;
34713614 }
34723615
3473
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
34743616
34753617 public void Save()
3618
+ {
3619
+ //Save(true);
3620
+ Replace();
3621
+ }
3622
+
3623
+ private boolean Equal(byte[] compress, byte[] name)
3624
+ {
3625
+ if (compress.length != name.length)
3626
+ {
3627
+ return false;
3628
+ }
3629
+
3630
+ for (int i=compress.length; --i>=0;)
3631
+ {
3632
+ if (compress[i] != name[i])
3633
+ return false;
3634
+ }
3635
+
3636
+ return true;
3637
+ }
3638
+
3639
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
3640
+
3641
+ public boolean Save(boolean user)
34763642 {
34773643 System.err.println("Save");
34783644
34793645 cRadio tab = GetCurrentTab();
34803646
3481
- boolean temp = CameraPane.SWITCH;
3482
- CameraPane.SWITCH = false;
3647
+ byte[] compress = CompressCopy();
34833648
3484
- copy.ExtractBigData(hashtable);
3649
+ boolean thesame = false;
3650
+
3651
+ // Quick heuristic using length. Works only when stream is compressed.
3652
+ if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
3653
+ {
3654
+ thesame = true;
3655
+ }
34853656
34863657 //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++)
3658
+ if (!thesame)
34963659 {
3497
- tab.graphs[i] = null;
3660
+ //tab.user[tab.versionindex] = user;
3661
+ //boolean increment = true; // tab.graphs[tab.versionindex] == null;
3662
+
3663
+ copy.versions[++copy.versionindex] = compress;
3664
+
3665
+ // if (increment)
3666
+ // tab.versionindex++;
34983667 }
34993668
3669
+ //copy.RestoreBigData(versiontable);
3670
+
3671
+ //assert(hashtable.isEmpty());
3672
+
3673
+ for (int i = copy.versionindex+1; i < copy.versions.length; i++)
3674
+ {
3675
+ //tab.user[i] = false;
3676
+ copy.versions[i] = null;
3677
+ }
3678
+
3679
+ SetUndoStates();
3680
+
35003681 // test save
35013682 if (false)
35023683 {
35033684 try
35043685 {
3505
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3686
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
35063687 ObjectOutputStream p = new ObjectOutputStream(ostream);
35073688
35083689 p.writeObject(copy);
....@@ -3515,14 +3696,18 @@
35153696 e.printStackTrace();
35163697 }
35173698 }
3699
+
3700
+ return !thesame;
35183701 }
35193702
35203703 void CopyChanged(Object3D obj)
35213704 {
3705
+ SetUndoStates();
3706
+
35223707 boolean temp = CameraPane.SWITCH;
35233708 CameraPane.SWITCH = false;
35243709
3525
- copy.ExtractBigData(hashtable);
3710
+ copy.ExtractBigData(versiontable);
35263711
35273712 copy.clear();
35283713
....@@ -3531,7 +3716,7 @@
35313716 copy.add(obj.get(i));
35323717 }
35333718
3534
- copy.RestoreBigData(hashtable);
3719
+ copy.RestoreBigData(versiontable);
35353720
35363721 CameraPane.SWITCH = temp;
35373722
....@@ -3558,42 +3743,130 @@
35583743 refreshContents();
35593744 }
35603745
3561
- public void Undo()
3746
+ cButton undoButton;
3747
+ cButton restoreButton;
3748
+ cButton replaceButton;
3749
+ cButton redoButton;
3750
+
3751
+ boolean muteSlider;
3752
+
3753
+ int VersionCount()
35623754 {
3755
+ int count = 0;
3756
+
3757
+ for (int i = copy.versions.length; --i >= 0;)
3758
+ {
3759
+ if (copy.versions[i] != null)
3760
+ count++;
3761
+ }
3762
+
3763
+ return count;
3764
+ }
3765
+
3766
+ void SetUndoStates()
3767
+ {
3768
+ cRadio tab = GetCurrentTab();
3769
+
3770
+ restoreButton.setEnabled(copy.versionindex != -1);
3771
+ replaceButton.setEnabled(copy.versionindex != -1);
3772
+
3773
+ undoButton.setEnabled(copy.versionindex > 0);
3774
+ redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
3775
+
3776
+ muteSlider = true;
3777
+ versionSlider.setMaximum(VersionCount() - 1);
3778
+ versionSlider.setInteger(copy.versionindex);
3779
+ muteSlider = false;
3780
+ }
3781
+
3782
+ public boolean Undo()
3783
+ {
3784
+ // Option?
3785
+ Replace();
3786
+
35633787 System.err.println("Undo");
35643788
35653789 cRadio tab = GetCurrentTab();
35663790
3567
- if (tab.undoindex == 0)
3791
+ if (copy.versionindex == 0)
35683792 {
35693793 java.awt.Toolkit.getDefaultToolkit().beep();
3570
- return;
3794
+ return false;
35713795 }
35723796
3573
- if (tab.graphs[tab.undoindex] == null)
3797
+// if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex])
3798
+// {
3799
+// if (Save(false))
3800
+// tab.versionindex -= 1;
3801
+// else
3802
+// {
3803
+// if (tab.versionindex <= 0)
3804
+// return false;
3805
+// else
3806
+// tab.versionindex -= 1;
3807
+// }
3808
+// }
3809
+
3810
+ copy.versionindex -= 1;
3811
+
3812
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3813
+
3814
+ return true;
3815
+ }
3816
+
3817
+ public boolean Restore()
3818
+ {
3819
+ System.err.println("Restore");
3820
+
3821
+ cRadio tab = GetCurrentTab();
3822
+
3823
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
35743824 {
3575
- Save();
3576
- tab.undoindex -= 1;
3825
+ java.awt.Toolkit.getDefaultToolkit().beep();
3826
+ return false;
35773827 }
35783828
3579
- tab.undoindex -= 1;
3829
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3830
+
3831
+ return true;
3832
+ }
35803833
3581
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3834
+ public boolean Replace()
3835
+ {
3836
+ System.err.println("Replace");
3837
+
3838
+ cRadio tab = GetCurrentTab();
3839
+
3840
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
3841
+ {
3842
+ // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
3843
+ return false;
3844
+ }
3845
+
3846
+ copy.versions[copy.versionindex] = CompressCopy();
3847
+
3848
+ return true;
35823849 }
35833850
35843851 public void Redo()
35853852 {
3853
+ // Option?
3854
+ Replace();
3855
+
35863856 cRadio tab = GetCurrentTab();
35873857
3588
- if (tab.graphs[tab.undoindex + 1] == null)
3858
+ if (copy.versions[copy.versionindex + 1] == null)
35893859 {
35903860 java.awt.Toolkit.getDefaultToolkit().beep();
35913861 return;
35923862 }
35933863
3594
- tab.undoindex += 1;
3864
+ copy.versionindex += 1;
35953865
3596
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3866
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3867
+
3868
+ //if (!tab.user[tab.versionindex])
3869
+ // tab.graphs[tab.versionindex] = null;
35973870 }
35983871
35993872 void ImportGFD()
....@@ -3889,9 +4162,25 @@
38894162 //copy.Touch();
38904163 }
38914164
4165
+ cNumberSlider versionSlider;
4166
+
38924167 public void stateChanged(ChangeEvent e)
38934168 {
38944169 // assert(false);
4170
+ if (e.getSource() == versionSlider)
4171
+ {
4172
+ if (muteSlider)
4173
+ return;
4174
+
4175
+ int version = versionSlider.getInteger();
4176
+
4177
+ if (copy.versions[version] != null)
4178
+ {
4179
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
4180
+ }
4181
+
4182
+ return;
4183
+ }
38954184
38964185 if (freezematerial)
38974186 {
....@@ -4240,7 +4529,7 @@
42404529
42414530 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
42424531 {
4243
- if (Globals.SAVEONMAKE) // && resetmodel)
4532
+ if (Globals.REPLACEONMAKE) // && resetmodel)
42444533 Save();
42454534 //Tween.set(thing, 0).target(1).start(tweenManager);
42464535 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4482,7 +4771,9 @@
44824771 readobj.ResetDisplayList();
44834772 } catch (Exception e)
44844773 {
4485
- //e.printStackTrace();
4774
+ if (!e.toString().contains("GZIP"))
4775
+ e.printStackTrace();
4776
+
44864777 try
44874778 {
44884779 java.io.FileInputStream istream = new java.io.FileInputStream(fullname);
....@@ -4556,12 +4847,14 @@
45564847
45574848 if (readobj != null)
45584849 {
4559
- if (Globals.SAVEONMAKE)
4560
- Save();
4850
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4851
+ // Save();
45614852 try
45624853 {
45634854 //readobj.deepCopySelf(copy);
45644855 copy.clear(); // june 2014
4856
+ copy.skyboxname = readobj.skyboxname;
4857
+ copy.skyboxext = readobj.skyboxext;
45654858 for (int i = 0; i < readobj.size(); i++)
45664859 {
45674860 Object3D child = readobj.get(i); // reserve(i);
....@@ -4602,6 +4895,7 @@
46024895 }
46034896 } catch (ClassCastException e)
46044897 {
4898
+ e.printStackTrace();
46054899 assert (false);
46064900 Composite c = (Composite) copy;
46074901 c.children.clear();
....@@ -4612,13 +4906,24 @@
46124906 c.addChild(csg);
46134907 }
46144908
4909
+ copy.versions = readobj.versions;
4910
+ copy.versionindex = readobj.versionindex;
4911
+
4912
+ if (copy.versions == null)
4913
+ {
4914
+ copy.versions = new byte[100][];
4915
+ copy.versionindex = -1;
4916
+ }
4917
+
4918
+ //? SetUndoStates();
4919
+
46154920 ResetModel();
46164921 copy.HardTouch(); // recompile?
46174922 refreshContents();
46184923 }
46194924 }
46204925
4621
- void load() // throws ClassNotFoundException
4926
+ void Open() // throws ClassNotFoundException
46224927 {
46234928 if (Grafreed.standAlone)
46244929 {
....@@ -4721,6 +5026,7 @@
47215026 //ps.print(buffer.toString());
47225027 } catch (IOException e)
47235028 {
5029
+ e.printStackTrace();
47245030 }
47255031 }
47265032
....@@ -4735,6 +5041,8 @@
47355041 String filename = browser.getFile();
47365042 if (filename != null && filename.length() > 0)
47375043 {
5044
+ if (!filename.endsWith(".gfd"))
5045
+ filename += ".gfd";
47385046 lastname = browser.getDirectory() + filename;
47395047 save();
47405048 }
....@@ -4901,7 +5209,7 @@
49015209 MenuBar menuBar;
49025210 Menu fileMenu;
49035211 MenuItem newItem;
4904
- MenuItem loadItem;
5212
+ MenuItem openItem;
49055213 MenuItem saveItem;
49065214 MenuItem saveAsItem;
49075215 MenuItem exportAsItem;
....@@ -4924,6 +5232,7 @@
49245232 CheckboxMenuItem toggleSwitchItem;
49255233 CheckboxMenuItem toggleRootItem;
49265234 CheckboxMenuItem animationItem;
5235
+ MenuItem archiveItem;
49275236 CheckboxMenuItem toggleHandleItem;
49285237 CheckboxMenuItem togglePaintItem;
49295238 JSplitPane mainPanel;
....@@ -4945,6 +5254,8 @@
49455254 cGridBag optionsPanel;
49465255
49475256 JTabbedPane objectPanel;
5257
+ boolean materialFlushed;
5258
+ Object3D latestObject;
49485259
49495260 cGridBag XYZPanel;
49505261