Normand Briere
2019-07-07 46dbce888e7c3eff8969f1ddbe22e144410b67f4
ObjEditor.java
....@@ -1979,8 +1979,9 @@
19791979 // 3D models
19801980 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
19811981 {
1982
- lastConverter = new com.jmex.model.converters.MaxToJme();
1983
- LoadFile(filename, lastConverter);
1982
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
1983
+ //LoadFile(filename, lastConverter);
1984
+ LoadObjFile(filename); // New 3ds loader
19841985 continue;
19851986 }
19861987 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2706,6 +2707,7 @@
27062707 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
27072708 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
27082709 }
2710
+
27092711 //cJME.count++;
27102712 //cJME.count %= 12;
27112713 if (gc)
....@@ -2889,6 +2891,7 @@
28892891 }
28902892 }
28912893 }
2894
+
28922895 cFileSystemPane FSPane;
28932896
28942897 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2942,6 +2945,7 @@
29422945 }
29432946 }
29442947 }
2948
+
29452949 freezematerial = false;
29462950 }
29472951
....@@ -3566,6 +3570,28 @@
35663570
35673571 public void Save()
35683572 {
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
+ {
35693595 System.err.println("Save");
35703596
35713597 cRadio tab = GetCurrentTab();
....@@ -3576,18 +3602,31 @@
35763602 copy.ExtractBigData(hashtable);
35773603
35783604 byte[] compress = Compress(copy);
3579
-
3580
- //EditorFrame.m_MainFrame.requestFocusInWindow();
3581
- tab.graphs[tab.undoindex++] = compress;
3582
-
3583
- copy.RestoreBigData(hashtable);
35843605
35853606 CameraPane.SWITCH = temp;
35863607
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
+
35873625 //assert(hashtable.isEmpty());
35883626
35893627 for (int i = tab.undoindex; i < tab.graphs.length; i++)
35903628 {
3629
+ tab.user[i] = false;
35913630 tab.graphs[i] = null;
35923631 }
35933632
....@@ -3611,6 +3650,8 @@
36113650 e.printStackTrace();
36123651 }
36133652 }
3653
+
3654
+ return !thesame;
36143655 }
36153656
36163657 void CopyChanged(Object3D obj)
....@@ -3667,7 +3708,7 @@
36673708 redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
36683709 }
36693710
3670
- public void Undo()
3711
+ public boolean Undo()
36713712 {
36723713 System.err.println("Undo");
36733714
....@@ -3676,18 +3717,27 @@
36763717 if (tab.undoindex == 0)
36773718 {
36783719 java.awt.Toolkit.getDefaultToolkit().beep();
3679
- return;
3720
+ return false;
36803721 }
36813722
3682
- if (tab.graphs[tab.undoindex] == null)
3723
+ if (tab.graphs[tab.undoindex] == null || !tab.user[tab.undoindex])
36833724 {
3684
- Save();
3685
- 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
+ }
36863734 }
36873735
36883736 tab.undoindex -= 1;
36893737
36903738 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3739
+
3740
+ return true;
36913741 }
36923742
36933743 public void Redo()
....@@ -3703,6 +3753,9 @@
37033753 tab.undoindex += 1;
37043754
37053755 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3756
+
3757
+ if (!tab.user[tab.undoindex])
3758
+ tab.graphs[tab.undoindex] = null;
37063759 }
37073760
37083761 void ImportGFD()