Normand Briere
2019-07-07 46dbce888e7c3eff8969f1ddbe22e144410b67f4
ObjEditor.java
....@@ -350,7 +350,7 @@
350350 frame.setMenuBar(menuBar = new MenuBar());
351351 menuBar.add(fileMenu = new Menu("File"));
352352 fileMenu.add(newItem = new MenuItem("New"));
353
- fileMenu.add(loadItem = new MenuItem("Open..."));
353
+ fileMenu.add(openItem = new MenuItem("Open..."));
354354
355355 //oe.menuBar.add(menu = new Menu("Include"));
356356 Menu menu = new Menu("Import");
....@@ -382,7 +382,7 @@
382382 }
383383
384384 newItem.addActionListener(this);
385
- loadItem.addActionListener(this);
385
+ openItem.addActionListener(this);
386386 saveItem.addActionListener(this);
387387 saveAsItem.addActionListener(this);
388388 exportAsItem.addActionListener(this);
....@@ -449,7 +449,7 @@
449449 // TEXTAREA infoarea.setLineWrap(true);
450450 // TEXTAREA infoarea.setWrapStyleWord(true);
451451 infoPanel = new JScrollPane(infoarea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); //AS_NEEDED);
452
- //infoPanel.setPreferredSize(new Dimension(50, 200));
452
+ infoPanel.setPreferredSize(new Dimension(1, 1));
453453 infoPanel.setName("Info");
454454 //infoPanel.setLayout(new BorderLayout());
455455 //infoPanel.add(createTextPane());
....@@ -780,7 +780,7 @@
780780 // X frame.getContentPane().remove(/*"Center",*/bigThree);
781781 // X framePanel.add(bigThree);
782782 // X frame.getContentPane().add(/*"Center",*/framePanel);
783
- framePanel.setDividerLocation(1);
783
+ framePanel.setDividerLocation(46);
784784
785785 //frame.setVisible(true);
786786 radio.layout = keepButton;
....@@ -1493,7 +1493,10 @@
14931493 // north.add(ctrlPanel, BorderLayout.NORTH);
14941494 // objectPanel.add(north);
14951495 objectPanel.add(editPanel);
1496
- objectPanel.add(infoPanel);
1496
+
1497
+ //if (Globals.ADVANCED)
1498
+ objectPanel.add(infoPanel);
1499
+
14971500 objectPanel.add(toolboxPanel);
14981501
14991502 /*
....@@ -1602,9 +1605,9 @@
16021605 // aConstraints.gridheight = 1;
16031606
16041607 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1605
- framePanel.setContinuousLayout(true);
1606
- framePanel.setOneTouchExpandable(true);
1607
- framePanel.setDividerLocation(0.8);
1608
+ framePanel.setContinuousLayout(false);
1609
+ framePanel.setOneTouchExpandable(false);
1610
+ //.setDividerLocation(0.8);
16081611 //framePanel.setDividerSize(15);
16091612 //framePanel.setResizeWeight(0.15);
16101613 framePanel.setName("Frame");
....@@ -1976,8 +1979,9 @@
19761979 // 3D models
19771980 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
19781981 {
1979
- lastConverter = new com.jmex.model.converters.MaxToJme();
1980
- LoadFile(filename, lastConverter);
1982
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
1983
+ //LoadFile(filename, lastConverter);
1984
+ LoadObjFile(filename); // New 3ds loader
19811985 continue;
19821986 }
19831987 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2703,6 +2707,7 @@
27032707 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
27042708 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
27052709 }
2710
+
27062711 //cJME.count++;
27072712 //cJME.count %= 12;
27082713 if (gc)
....@@ -2886,6 +2891,7 @@
28862891 }
28872892 }
28882893 }
2894
+
28892895 cFileSystemPane FSPane;
28902896
28912897 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2939,6 +2945,7 @@
29392945 }
29402946 }
29412947 }
2948
+
29422949 freezematerial = false;
29432950 }
29442951
....@@ -3391,9 +3398,9 @@
33913398 {
33923399 Close();
33933400 //return true;
3394
- } else if (source == loadItem)
3401
+ } else if (source == openItem)
33953402 {
3396
- load();
3403
+ Open();
33973404 //return true;
33983405 } else if (source == newItem)
33993406 {
....@@ -3418,6 +3425,10 @@
34183425 {
34193426 generatePOV();
34203427 //return true;
3428
+ } else if (event.getSource() == archiveItem)
3429
+ {
3430
+ cTools.Archive(frame);
3431
+ return;
34213432 } else if (source == zBufferItem)
34223433 {
34233434 try
....@@ -3559,6 +3570,28 @@
35593570
35603571 public void Save()
35613572 {
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
+ {
35623595 System.err.println("Save");
35633596
35643597 cRadio tab = GetCurrentTab();
....@@ -3569,18 +3602,31 @@
35693602 copy.ExtractBigData(hashtable);
35703603
35713604 byte[] compress = Compress(copy);
3572
-
3573
- //EditorFrame.m_MainFrame.requestFocusInWindow();
3574
- tab.graphs[tab.undoindex++] = compress;
3575
-
3576
- copy.RestoreBigData(hashtable);
35773605
35783606 CameraPane.SWITCH = temp;
35793607
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
+
35803625 //assert(hashtable.isEmpty());
35813626
35823627 for (int i = tab.undoindex; i < tab.graphs.length; i++)
35833628 {
3629
+ tab.user[i] = false;
35843630 tab.graphs[i] = null;
35853631 }
35863632
....@@ -3604,6 +3650,8 @@
36043650 e.printStackTrace();
36053651 }
36063652 }
3653
+
3654
+ return !thesame;
36073655 }
36083656
36093657 void CopyChanged(Object3D obj)
....@@ -3660,7 +3708,7 @@
36603708 redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
36613709 }
36623710
3663
- public void Undo()
3711
+ public boolean Undo()
36643712 {
36653713 System.err.println("Undo");
36663714
....@@ -3669,18 +3717,27 @@
36693717 if (tab.undoindex == 0)
36703718 {
36713719 java.awt.Toolkit.getDefaultToolkit().beep();
3672
- return;
3720
+ return false;
36733721 }
36743722
3675
- if (tab.graphs[tab.undoindex] == null)
3723
+ if (tab.graphs[tab.undoindex] == null || !tab.user[tab.undoindex])
36763724 {
3677
- Save();
3678
- 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
+ }
36793734 }
36803735
36813736 tab.undoindex -= 1;
36823737
36833738 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3739
+
3740
+ return true;
36843741 }
36853742
36863743 public void Redo()
....@@ -3696,6 +3753,9 @@
36963753 tab.undoindex += 1;
36973754
36983755 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3756
+
3757
+ if (!tab.user[tab.undoindex])
3758
+ tab.graphs[tab.undoindex] = null;
36993759 }
37003760
37013761 void ImportGFD()
....@@ -4720,7 +4780,7 @@
47204780 }
47214781 }
47224782
4723
- void load() // throws ClassNotFoundException
4783
+ void Open() // throws ClassNotFoundException
47244784 {
47254785 if (Grafreed.standAlone)
47264786 {
....@@ -5005,7 +5065,7 @@
50055065 MenuBar menuBar;
50065066 Menu fileMenu;
50075067 MenuItem newItem;
5008
- MenuItem loadItem;
5068
+ MenuItem openItem;
50095069 MenuItem saveItem;
50105070 MenuItem saveAsItem;
50115071 MenuItem exportAsItem;
....@@ -5028,6 +5088,7 @@
50285088 CheckboxMenuItem toggleSwitchItem;
50295089 CheckboxMenuItem toggleRootItem;
50305090 CheckboxMenuItem animationItem;
5091
+ MenuItem archiveItem;
50315092 CheckboxMenuItem toggleHandleItem;
50325093 CheckboxMenuItem togglePaintItem;
50335094 JSplitPane mainPanel;