Normand Briere
2019-07-07 46dbce888e7c3eff8969f1ddbe22e144410b67f4
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.
....@@ -306,7 +309,7 @@
306309 //localCopy.parent = null;
307310
308311 frame = new JFrame();
309
- frame.setUndecorated(true);
312
+ frame.setUndecorated(false);
310313 objEditor = this;
311314 this.callee = callee;
312315
....@@ -347,7 +350,7 @@
347350 frame.setMenuBar(menuBar = new MenuBar());
348351 menuBar.add(fileMenu = new Menu("File"));
349352 fileMenu.add(newItem = new MenuItem("New"));
350
- fileMenu.add(loadItem = new MenuItem("Open..."));
353
+ fileMenu.add(openItem = new MenuItem("Open..."));
351354
352355 //oe.menuBar.add(menu = new Menu("Include"));
353356 Menu menu = new Menu("Import");
....@@ -379,7 +382,7 @@
379382 }
380383
381384 newItem.addActionListener(this);
382
- loadItem.addActionListener(this);
385
+ openItem.addActionListener(this);
383386 saveItem.addActionListener(this);
384387 saveAsItem.addActionListener(this);
385388 exportAsItem.addActionListener(this);
....@@ -446,7 +449,7 @@
446449 // TEXTAREA infoarea.setLineWrap(true);
447450 // TEXTAREA infoarea.setWrapStyleWord(true);
448451 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
449
- infoPanel.setPreferredSize(new Dimension(50, 200));
452
+ infoPanel.setPreferredSize(new Dimension(1, 1));
450453 infoPanel.setName("Info");
451454 //infoPanel.setLayout(new BorderLayout());
452455 //infoPanel.add(createTextPane());
....@@ -458,7 +461,14 @@
458461 mainPanel.setDividerSize(9);
459462 mainPanel.setDividerLocation(0.5); //1.0);
460463 mainPanel.setResizeWeight(0.5);
461
-
464
+
465
+//mainPanel.setDividerSize((int) (mainPanel.getDividerSize() * 1.5));
466
+ BasicSplitPaneDivider divider = ( (BasicSplitPaneUI) mainPanel.getUI()).getDivider();
467
+ divider.setDividerSize(15);
468
+ divider.setBorder(BorderFactory.createTitledBorder(divider.getBorder(), "Custom border title -- gets rid of the one-touch arrows!"));
469
+
470
+ mainPanel.setUI(new BasicSplitPaneUI());
471
+
462472 //ctrlPanel.setLayout(new GridLayout(4, 1, 5, 5));
463473 //mainPanel.setLayout(new GridBagLayout());
464474 toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
....@@ -689,8 +699,8 @@
689699 }
690700 }
691701
692
-static GraphicsDevice device = GraphicsEnvironment
693
- .getLocalGraphicsEnvironment().getScreenDevices()[0];
702
+//static GraphicsDevice device = GraphicsEnvironment
703
+// .getLocalGraphicsEnvironment().getScreenDevices()[0];
694704
695705 Rectangle keeprect;
696706 cRadio radio;
....@@ -711,10 +721,19 @@
711721 void Minimize()
712722 {
713723 frame.setState(Frame.ICONIFIED);
724
+ frame.validate();
714725 }
715726
727
+// artifactURI=null, type=0, property=${file.reference.jfxrt.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@6767876f, broken=false, additional={}
728
+// artifactURI=null, type=0, property=${file.reference.mac-ui.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@16bdc817, broken=false, additional={}
729
+// artifactURI=null, type=0, property=${file.reference.classes.jar}, object=org.netbeans.modules.java.api.common.classpath.ClassPathSupport$RelativePath@9daa9c17, broken=false, additional={}
716730 void Maximize()
717731 {
732
+ if (CameraPane.FULLSCREEN)
733
+ {
734
+ ToggleFullScreen();
735
+ }
736
+
718737 if (maximized)
719738 {
720739 frame.setBounds(keeprect.x, keeprect.y, keeprect.width, keeprect.height);
....@@ -722,22 +741,36 @@
722741 else
723742 {
724743 keeprect = frame.getBounds();
725
- Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
726
- Dimension rect2 = frame.getToolkit().getScreenSize();
727
- frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
744
+// Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
745
+// Dimension rect2 = frame.getToolkit().getScreenSize();
746
+// frame.setBounds(0, rect2.height - rect.height, rect.width, rect.height);
728747 // frame.setState(Frame.MAXIMIZED_BOTH);
748
+ frame.setBounds(frame.getGraphicsConfiguration().getBounds());
729749 }
730750
731751 maximized ^= true;
752
+
753
+ frame.validate();
732754 }
755
+
756
+ cButton minButton;
757
+ cButton maxButton;
758
+ cButton fullButton;
733759
734760 void ToggleFullScreen()
735761 {
762
+GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
763
+
736764 cameraView.ToggleFullScreen();
737765
738766 if (!CameraPane.FULLSCREEN)
739767 {
740768 device.setFullScreenWindow(null);
769
+ frame.dispose();
770
+ frame.setUndecorated(false);
771
+ frame.validate();
772
+ frame.setVisible(true);
773
+
741774 //frame.setVisible(false);
742775 // frame.removeNotify();
743776 // frame.setUndecorated(false);
....@@ -747,7 +780,7 @@
747780 // X frame.getContentPane().remove(/*"Center",*/bigThree);
748781 // X framePanel.add(bigThree);
749782 // X frame.getContentPane().add(/*"Center",*/framePanel);
750
- framePanel.setDividerLocation(1);
783
+ framePanel.setDividerLocation(46);
751784
752785 //frame.setVisible(true);
753786 radio.layout = keepButton;
....@@ -762,7 +795,12 @@
762795 // frame.setBounds(0, 0, frame.getToolkit().getScreenSize().width,
763796 // frame.getToolkit().getScreenSize().height);
764797 //frame.setVisible(false);
798
+
799
+ frame.dispose();
800
+ frame.setUndecorated(true);
765801 device.setFullScreenWindow(frame);
802
+ frame.validate();
803
+ frame.setVisible(true);
766804 // frame.removeNotify();
767805 // frame.setUndecorated(true);
768806 // frame.addNotify();
....@@ -775,6 +813,7 @@
775813 radio.layout.doClick();
776814 //frame.setVisible(true);
777815 }
816
+ frame.validate();
778817 }
779818
780819 private JTextPane createTextPane()
....@@ -1107,7 +1146,7 @@
11071146 namePanel = new cGridBag();
11081147
11091148 nameField = AddText(namePanel, copy.GetName());
1110
- namePanel.add(nameField);
1149
+ namePanel.add(new JScrollPane(nameField, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
11111150 oe.ctrlPanel.add(namePanel);
11121151
11131152 oe.ctrlPanel.Return();
....@@ -1125,15 +1164,15 @@
11251164 hideCB = AddCheckBox(setupPanel, "Hide", copy.hide);
11261165 hideCB.setToolTipText("Hide object");
11271166 markCB = AddCheckBox(setupPanel, "Mark", copy.marked);
1128
- markCB.setToolTipText("Set the animation target transform");
1167
+ markCB.setToolTipText("As animation target transform");
11291168
11301169 setupPanel2 = new cGridBag().setVertical(false);
11311170
11321171 rewindCB = AddCheckBox(setupPanel2, "Rewind", copy.rewind);
11331172 rewindCB.setToolTipText("Rewind animation");
11341173
1135
- randomCB = AddCheckBox(setupPanel2, "Rand", copy.random);
1136
- randomCB.setToolTipText("Randomly Rewind or Go back and forth");
1174
+ randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
1175
+ randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11371176
11381177 if (Globals.ADVANCED)
11391178 {
....@@ -1454,7 +1493,10 @@
14541493 // north.add(ctrlPanel, BorderLayout.NORTH);
14551494 // objectPanel.add(north);
14561495 objectPanel.add(editPanel);
1457
- objectPanel.add(infoPanel);
1496
+
1497
+ //if (Globals.ADVANCED)
1498
+ objectPanel.add(infoPanel);
1499
+
14581500 objectPanel.add(toolboxPanel);
14591501
14601502 /*
....@@ -1563,9 +1605,9 @@
15631605 // aConstraints.gridheight = 1;
15641606
15651607 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1566
- framePanel.setContinuousLayout(true);
1567
- framePanel.setOneTouchExpandable(true);
1568
- framePanel.setDividerLocation(0.8);
1608
+ framePanel.setContinuousLayout(false);
1609
+ framePanel.setOneTouchExpandable(false);
1610
+ //.setDividerLocation(0.8);
15691611 //framePanel.setDividerSize(15);
15701612 //framePanel.setResizeWeight(0.15);
15711613 framePanel.setName("Frame");
....@@ -1584,12 +1626,13 @@
15841626
15851627 frame.setSize(1280, 860);
15861628
1587
- frame.validate();
1588
- frame.setVisible(true);
1589
-
15901629 cameraView.requestFocusInWindow();
15911630
15921631 gridPanel.setDividerLocation(1.0);
1632
+
1633
+ frame.validate();
1634
+
1635
+ frame.setVisible(true);
15931636
15941637 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
15951638 frame.addWindowListener(new WindowAdapter()
....@@ -1676,24 +1719,6 @@
16761719 texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
16771720 colorSection.add(texture);
16781721
1679
- cGridBag anisoU = new cGridBag();
1680
- anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1681
- anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1682
- anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1683
- colorSection.add(anisoU);
1684
-
1685
- cGridBag anisoV = new cGridBag();
1686
- anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1687
- anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1688
- anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1689
- colorSection.add(anisoV);
1690
-
1691
- cGridBag shadowbias = new cGridBag();
1692
- shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1693
- shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1694
- shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1695
- colorSection.add(shadowbias);
1696
-
16971722 panel.add(new JSeparator());
16981723
16991724 panel.add(colorSection);
....@@ -1743,6 +1768,12 @@
17431768 fakedepthLabel.setHorizontalAlignment(SwingConstants.TRAILING);
17441769 fakedepth.add(fakedepthField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
17451770 diffuseSection.add(fakedepth);
1771
+
1772
+ cGridBag shadowbias = new cGridBag();
1773
+ shadowbias.add(shadowbiasLabel = new JLabel("Shadowbias")); // , aConstraints);
1774
+ shadowbiasLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1775
+ shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1776
+ diffuseSection.add(shadowbias);
17461777
17471778 panel.add(new JSeparator());
17481779
....@@ -1794,6 +1825,18 @@
17941825 // aConstraints.gridy += 1;
17951826 // aConstraints.gridwidth = 1;
17961827
1828
+ cGridBag anisoU = new cGridBag();
1829
+ anisoU.add(anisoLabel = new JLabel("AnisoU")); // , aConstraints);
1830
+ anisoLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1831
+ anisoU.add(anisoField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1832
+ specularSection.add(anisoU);
1833
+
1834
+ cGridBag anisoV = new cGridBag();
1835
+ anisoV.add(anisoVLabel = new JLabel("AnisoV")); // , aConstraints);
1836
+ anisoVLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1837
+ anisoV.add(anisoVField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1838
+ specularSection.add(anisoV);
1839
+
17971840
17981841 panel.add(new JSeparator());
17991842
....@@ -1801,35 +1844,35 @@
18011844
18021845 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
18031846
1804
- cGridBag globalSection = new cGridBag().setVertical(true);
1847
+ //cGridBag globalSection = new cGridBag().setVertical(true);
18051848
18061849 cGridBag camera = new cGridBag();
18071850 camera.add(cameraLabel = new JLabel("GlobalLight")); // , aConstraints);
18081851 cameraLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18091852 camera.add(cameraField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1810
- globalSection.add(camera);
1853
+ colorSection.add(camera);
18111854
18121855 cGridBag ambient = new cGridBag();
18131856 ambient.add(ambientLabel = new JLabel("Ambient")); // , aConstraints);
18141857 ambientLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18151858 ambient.add(ambientField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1816
- globalSection.add(ambient);
1859
+ colorSection.add(ambient);
18171860
18181861 cGridBag backlit = new cGridBag();
18191862 backlit.add(backlitLabel = new JLabel("Backlit")); // , aConstraints);
18201863 backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18211864 backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints);
1822
- globalSection.add(backlit);
1865
+ colorSection.add(backlit);
18231866
18241867 cGridBag opacity = new cGridBag();
18251868 opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints);
18261869 opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING);
18271870 opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints);
1828
- globalSection.add(opacity);
1871
+ colorSection.add(opacity);
18291872
1830
- panel.add(new JSeparator());
1873
+ //panel.add(new JSeparator());
18311874
1832
- panel.add(globalSection);
1875
+ //panel.add(globalSection);
18331876
18341877 //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints);
18351878
....@@ -1936,8 +1979,9 @@
19361979 // 3D models
19371980 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
19381981 {
1939
- lastConverter = new com.jmex.model.converters.MaxToJme();
1940
- LoadFile(filename, lastConverter);
1982
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
1983
+ //LoadFile(filename, lastConverter);
1984
+ LoadObjFile(filename); // New 3ds loader
19411985 continue;
19421986 }
19431987 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2663,6 +2707,7 @@
26632707 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
26642708 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
26652709 }
2710
+
26662711 //cJME.count++;
26672712 //cJME.count %= 12;
26682713 if (gc)
....@@ -2846,6 +2891,7 @@
28462891 }
28472892 }
28482893 }
2894
+
28492895 cFileSystemPane FSPane;
28502896
28512897 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2899,6 +2945,7 @@
28992945 }
29002946 }
29012947 }
2948
+
29022949 freezematerial = false;
29032950 }
29042951
....@@ -3017,12 +3064,17 @@
30173064 // }
30183065
30193066 /**/
3020
- if (deselect)
3067
+ if (deselect || child == null)
30213068 {
30223069 //group.deselectAll();
30233070 //freeze = true;
30243071 GetTree().clearSelection();
30253072 //freeze = false;
3073
+
3074
+ if (child == null)
3075
+ {
3076
+ return;
3077
+ }
30263078 }
30273079
30283080 //group.addSelectee(child);
....@@ -3346,9 +3398,9 @@
33463398 {
33473399 Close();
33483400 //return true;
3349
- } else if (source == loadItem)
3401
+ } else if (source == openItem)
33503402 {
3351
- load();
3403
+ Open();
33523404 //return true;
33533405 } else if (source == newItem)
33543406 {
....@@ -3373,6 +3425,10 @@
33733425 {
33743426 generatePOV();
33753427 //return true;
3428
+ } else if (event.getSource() == archiveItem)
3429
+ {
3430
+ cTools.Archive(frame);
3431
+ return;
33763432 } else if (source == zBufferItem)
33773433 {
33783434 try
....@@ -3514,6 +3570,28 @@
35143570
35153571 public void Save()
35163572 {
3573
+ // Default reduces the probability of heuristics errors.
3574
+ Save(true);
3575
+ }
3576
+
3577
+ private boolean Equal(byte[] compress, byte[] name)
3578
+ {
3579
+ if (compress.length != name.length)
3580
+ {
3581
+ return false;
3582
+ }
3583
+
3584
+ for (int i=compress.length; --i>=0;)
3585
+ {
3586
+ if (compress[i] != name[i])
3587
+ return false;
3588
+ }
3589
+
3590
+ return true;
3591
+ }
3592
+
3593
+ public boolean Save(boolean user)
3594
+ {
35173595 System.err.println("Save");
35183596
35193597 cRadio tab = GetCurrentTab();
....@@ -3523,17 +3601,32 @@
35233601
35243602 copy.ExtractBigData(hashtable);
35253603
3526
- //EditorFrame.m_MainFrame.requestFocusInWindow();
3527
- tab.graphs[tab.undoindex++] = Compress(copy);
3528
-
3529
- copy.RestoreBigData(hashtable);
3604
+ byte[] compress = Compress(copy);
35303605
35313606 CameraPane.SWITCH = temp;
35323607
3608
+ boolean thesame = false;
3609
+
3610
+ // Quick heuristic using length. Works only when stream is compressed.
3611
+ if (tab.undoindex > 0 && tab.graphs[tab.undoindex-1] != null && Equal(compress, tab.graphs[tab.undoindex-1]))
3612
+ {
3613
+ thesame = true;
3614
+ }
3615
+
3616
+ //EditorFrame.m_MainFrame.requestFocusInWindow();
3617
+ if (!thesame)
3618
+ {
3619
+ tab.user[tab.undoindex] = user;
3620
+ tab.graphs[tab.undoindex++] = compress;
3621
+ }
3622
+
3623
+ copy.RestoreBigData(hashtable);
3624
+
35333625 //assert(hashtable.isEmpty());
35343626
35353627 for (int i = tab.undoindex; i < tab.graphs.length; i++)
35363628 {
3629
+ tab.user[i] = false;
35373630 tab.graphs[i] = null;
35383631 }
35393632
....@@ -3557,6 +3650,8 @@
35573650 e.printStackTrace();
35583651 }
35593652 }
3653
+
3654
+ return !thesame;
35603655 }
35613656
35623657 void CopyChanged(Object3D obj)
....@@ -3613,7 +3708,7 @@
36133708 redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
36143709 }
36153710
3616
- public void Undo()
3711
+ public boolean Undo()
36173712 {
36183713 System.err.println("Undo");
36193714
....@@ -3622,18 +3717,27 @@
36223717 if (tab.undoindex == 0)
36233718 {
36243719 java.awt.Toolkit.getDefaultToolkit().beep();
3625
- return;
3720
+ return false;
36263721 }
36273722
3628
- if (tab.graphs[tab.undoindex] == null)
3723
+ if (tab.graphs[tab.undoindex] == null || !tab.user[tab.undoindex])
36293724 {
3630
- Save();
3631
- tab.undoindex -= 1;
3725
+ if (Save(false))
3726
+ tab.undoindex -= 1;
3727
+ else
3728
+ {
3729
+ if (tab.undoindex <= 0)
3730
+ return false;
3731
+ else
3732
+ tab.undoindex -= 1;
3733
+ }
36323734 }
36333735
36343736 tab.undoindex -= 1;
36353737
36363738 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3739
+
3740
+ return true;
36373741 }
36383742
36393743 public void Redo()
....@@ -3649,6 +3753,9 @@
36493753 tab.undoindex += 1;
36503754
36513755 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3756
+
3757
+ if (!tab.user[tab.undoindex])
3758
+ tab.graphs[tab.undoindex] = null;
36523759 }
36533760
36543761 void ImportGFD()
....@@ -4673,7 +4780,7 @@
46734780 }
46744781 }
46754782
4676
- void load() // throws ClassNotFoundException
4783
+ void Open() // throws ClassNotFoundException
46774784 {
46784785 if (Grafreed.standAlone)
46794786 {
....@@ -4958,7 +5065,7 @@
49585065 MenuBar menuBar;
49595066 Menu fileMenu;
49605067 MenuItem newItem;
4961
- MenuItem loadItem;
5068
+ MenuItem openItem;
49625069 MenuItem saveItem;
49635070 MenuItem saveAsItem;
49645071 MenuItem exportAsItem;
....@@ -4981,6 +5088,7 @@
49815088 CheckboxMenuItem toggleSwitchItem;
49825089 CheckboxMenuItem toggleRootItem;
49835090 CheckboxMenuItem animationItem;
5091
+ MenuItem archiveItem;
49845092 CheckboxMenuItem toggleHandleItem;
49855093 CheckboxMenuItem togglePaintItem;
49865094 JSplitPane mainPanel;