Normand Briere
2019-07-17 a5580a47d246c1272b10adba68070f6e13da5e41
ObjEditor.java
....@@ -816,6 +816,28 @@
816816 frame.validate();
817817 }
818818
819
+ private byte[] CompressCopy()
820
+ {
821
+ boolean temp = CameraPane.SWITCH;
822
+ CameraPane.SWITCH = false;
823
+
824
+ copy.ExtractBigData(versiontable);
825
+ // if (copy == client)
826
+
827
+ byte[] versions[] = copy.versions;
828
+ copy.versions = null;
829
+
830
+ byte[] compress = Compress(copy);
831
+
832
+ copy.versions = versions;
833
+
834
+ copy.RestoreBigData(versiontable);
835
+
836
+ CameraPane.SWITCH = temp;
837
+
838
+ return compress;
839
+ }
840
+
819841 private JTextPane createTextPane()
820842 {
821843 // TEXTAREA String[] initString =
....@@ -1174,10 +1196,11 @@
11741196 randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
11751197 randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11761198
1199
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1200
+ link2masterCB.setToolTipText("Attach to support");
1201
+
11771202 if (Globals.ADVANCED)
11781203 {
1179
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1180
- link2masterCB.setToolTipText("Attach to support");
11811204 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
11821205 speedupCB.setToolTipText("Option motion capture");
11831206 }
....@@ -1979,8 +2002,9 @@
19792002 // 3D models
19802003 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
19812004 {
1982
- lastConverter = new com.jmex.model.converters.MaxToJme();
1983
- LoadFile(filename, lastConverter);
2005
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
2006
+ //LoadFile(filename, lastConverter);
2007
+ LoadObjFile(filename); // New 3ds loader
19842008 continue;
19852009 }
19862010 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2706,6 +2730,7 @@
27062730 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
27072731 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
27082732 }
2733
+
27092734 //cJME.count++;
27102735 //cJME.count %= 12;
27112736 if (gc)
....@@ -2889,6 +2914,7 @@
28892914 }
28902915 }
28912916 }
2917
+
28922918 cFileSystemPane FSPane;
28932919
28942920 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2942,6 +2968,7 @@
29422968 }
29432969 }
29442970 }
2971
+
29452972 freezematerial = false;
29462973 }
29472974
....@@ -3476,8 +3503,8 @@
34763503 try
34773504 {
34783505 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3479
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3480
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3506
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3507
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
34813508
34823509 Object3D parent = o.parent;
34833510 o.parent = null;
....@@ -3488,10 +3515,14 @@
34883515
34893516 out.flush();
34903517
3491
- zstream.close();
3518
+ baos //zstream
3519
+ .close();
34923520 out.close();
34933521
3494
- return baos.toByteArray();
3522
+ byte[] bytes = baos.toByteArray();
3523
+
3524
+ System.out.println("save #bytes = " + bytes.length);
3525
+ return bytes;
34953526 } catch (Exception e)
34963527 {
34973528 System.err.println(e);
....@@ -3501,13 +3532,16 @@
35013532
35023533 static public Object Uncompress(byte[] bytes)
35033534 {
3504
- System.out.println("#bytes = " + bytes.length);
3535
+ System.out.println("restore #bytes = " + bytes.length);
35053536 try
35063537 {
35073538 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3508
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3509
- ObjectInputStream in = new ObjectInputStream(istream);
3539
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3540
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
35103541 Object obj = in.readObject();
3542
+
3543
+ bais //istream
3544
+ .close();
35113545 in.close();
35123546
35133547 return obj;
....@@ -3562,33 +3596,67 @@
35623596 return null;
35633597 }
35643598
3565
- java.util.Hashtable<java.util.UUID, Object3D> hashtable = new java.util.Hashtable<java.util.UUID, Object3D>();
35663599
35673600 public void Save()
3601
+ {
3602
+ //Save(true);
3603
+ Replace();
3604
+ }
3605
+
3606
+ private boolean Equal(byte[] compress, byte[] name)
3607
+ {
3608
+ if (compress.length != name.length)
3609
+ {
3610
+ return false;
3611
+ }
3612
+
3613
+ for (int i=compress.length; --i>=0;)
3614
+ {
3615
+ if (compress[i] != name[i])
3616
+ return false;
3617
+ }
3618
+
3619
+ return true;
3620
+ }
3621
+
3622
+ java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
3623
+
3624
+ public boolean Save(boolean user)
35683625 {
35693626 System.err.println("Save");
35703627
35713628 cRadio tab = GetCurrentTab();
35723629
3573
- boolean temp = CameraPane.SWITCH;
3574
- CameraPane.SWITCH = false;
3630
+ byte[] compress = CompressCopy();
35753631
3576
- copy.ExtractBigData(hashtable);
3632
+ boolean thesame = false;
35773633
3578
- byte[] compress = Compress(copy);
3634
+ // Quick heuristic using length. Works only when stream is compressed.
3635
+ if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
3636
+ {
3637
+ thesame = true;
3638
+ }
35793639
35803640 //EditorFrame.m_MainFrame.requestFocusInWindow();
3581
- tab.graphs[tab.undoindex++] = compress;
3641
+ if (!thesame)
3642
+ {
3643
+ //tab.user[tab.versionindex] = user;
3644
+ //boolean increment = true; // tab.graphs[tab.versionindex] == null;
3645
+
3646
+ copy.versions[++copy.versionindex] = compress;
3647
+
3648
+ // if (increment)
3649
+ // tab.versionindex++;
3650
+ }
35823651
3583
- copy.RestoreBigData(hashtable);
3652
+ //copy.RestoreBigData(versiontable);
35843653
3585
- CameraPane.SWITCH = temp;
3586
-
35873654 //assert(hashtable.isEmpty());
35883655
3589
- for (int i = tab.undoindex; i < tab.graphs.length; i++)
3656
+ for (int i = copy.versionindex+1; i < copy.versions.length; i++)
35903657 {
3591
- tab.graphs[i] = null;
3658
+ //tab.user[i] = false;
3659
+ copy.versions[i] = null;
35923660 }
35933661
35943662 SetUndoStates();
....@@ -3598,7 +3666,7 @@
35983666 {
35993667 try
36003668 {
3601
- FileOutputStream ostream = new FileOutputStream("save" + tab.undoindex);
3669
+ FileOutputStream ostream = new FileOutputStream("save" + copy.versionindex);
36023670 ObjectOutputStream p = new ObjectOutputStream(ostream);
36033671
36043672 p.writeObject(copy);
....@@ -3611,6 +3679,8 @@
36113679 e.printStackTrace();
36123680 }
36133681 }
3682
+
3683
+ return !thesame;
36143684 }
36153685
36163686 void CopyChanged(Object3D obj)
....@@ -3620,7 +3690,7 @@
36203690 boolean temp = CameraPane.SWITCH;
36213691 CameraPane.SWITCH = false;
36223692
3623
- copy.ExtractBigData(hashtable);
3693
+ copy.ExtractBigData(versiontable);
36243694
36253695 copy.clear();
36263696
....@@ -3629,7 +3699,7 @@
36293699 copy.add(obj.get(i));
36303700 }
36313701
3632
- copy.RestoreBigData(hashtable);
3702
+ copy.RestoreBigData(versiontable);
36333703
36343704 CameraPane.SWITCH = temp;
36353705
....@@ -3657,52 +3727,102 @@
36573727 }
36583728
36593729 cButton undoButton;
3730
+ cButton restoreButton;
3731
+ cButton replaceButton;
36603732 cButton redoButton;
36613733
36623734 void SetUndoStates()
36633735 {
36643736 cRadio tab = GetCurrentTab();
36653737
3666
- undoButton.setEnabled(tab.undoindex > 0);
3667
- redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
3738
+ restoreButton.setEnabled(copy.versionindex != -1);
3739
+ replaceButton.setEnabled(copy.versionindex != -1);
3740
+ undoButton.setEnabled(copy.versionindex > 0);
3741
+ redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
36683742 }
36693743
3670
- public void Undo()
3744
+ public boolean Undo()
36713745 {
36723746 System.err.println("Undo");
36733747
36743748 cRadio tab = GetCurrentTab();
36753749
3676
- if (tab.undoindex == 0)
3750
+ if (copy.versionindex == 0)
36773751 {
36783752 java.awt.Toolkit.getDefaultToolkit().beep();
3679
- return;
3753
+ return false;
36803754 }
36813755
3682
- if (tab.graphs[tab.undoindex] == null)
3756
+// if (tab.graphs[tab.versionindex] == null) // || !tab.user[tab.versionindex])
3757
+// {
3758
+// if (Save(false))
3759
+// tab.versionindex -= 1;
3760
+// else
3761
+// {
3762
+// if (tab.versionindex <= 0)
3763
+// return false;
3764
+// else
3765
+// tab.versionindex -= 1;
3766
+// }
3767
+// }
3768
+
3769
+ copy.versionindex -= 1;
3770
+
3771
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3772
+
3773
+ return true;
3774
+ }
3775
+
3776
+ public boolean Restore()
3777
+ {
3778
+ System.err.println("Restore");
3779
+
3780
+ cRadio tab = GetCurrentTab();
3781
+
3782
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
36833783 {
3684
- Save();
3685
- tab.undoindex -= 1;
3784
+ java.awt.Toolkit.getDefaultToolkit().beep();
3785
+ return false;
36863786 }
36873787
3688
- tab.undoindex -= 1;
3788
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3789
+
3790
+ return true;
3791
+ }
36893792
3690
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3793
+ public boolean Replace()
3794
+ {
3795
+ System.err.println("Replace");
3796
+
3797
+ cRadio tab = GetCurrentTab();
3798
+
3799
+ if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
3800
+ {
3801
+ // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
3802
+ return false;
3803
+ }
3804
+
3805
+ copy.versions[copy.versionindex] = CompressCopy();
3806
+
3807
+ return true;
36913808 }
36923809
36933810 public void Redo()
36943811 {
36953812 cRadio tab = GetCurrentTab();
36963813
3697
- if (tab.graphs[tab.undoindex + 1] == null)
3814
+ if (copy.versions[copy.versionindex + 1] == null)
36983815 {
36993816 java.awt.Toolkit.getDefaultToolkit().beep();
37003817 return;
37013818 }
37023819
3703
- tab.undoindex += 1;
3820
+ copy.versionindex += 1;
37043821
3705
- CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3822
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
3823
+
3824
+ //if (!tab.user[tab.versionindex])
3825
+ // tab.graphs[tab.versionindex] = null;
37063826 }
37073827
37083828 void ImportGFD()
....@@ -3998,9 +4118,22 @@
39984118 //copy.Touch();
39994119 }
40004120
4121
+ cNumberSlider versionField;
4122
+
40014123 public void stateChanged(ChangeEvent e)
40024124 {
40034125 // assert(false);
4126
+ if (e.getSource() == versionField)
4127
+ {
4128
+ int version = versionField.getInteger();
4129
+
4130
+ if (copy.versions[version] != null)
4131
+ {
4132
+ CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
4133
+ }
4134
+
4135
+ return;
4136
+ }
40044137
40054138 if (freezematerial)
40064139 {
....@@ -4349,7 +4482,7 @@
43494482
43504483 void makeSomething(Object3D thing, boolean resetmodel) // deselect)
43514484 {
4352
- if (Globals.SAVEONMAKE) // && resetmodel)
4485
+ if (Globals.REPLACEONMAKE) // && resetmodel)
43534486 Save();
43544487 //Tween.set(thing, 0).target(1).start(tweenManager);
43554488 //Tween.to(thing, 0, 0.5f).target(0).start(tweenManager);
....@@ -4665,8 +4798,8 @@
46654798
46664799 if (readobj != null)
46674800 {
4668
- if (Globals.SAVEONMAKE)
4669
- Save();
4801
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4802
+ // Save();
46704803 try
46714804 {
46724805 //readobj.deepCopySelf(copy);
....@@ -4721,6 +4854,11 @@
47214854 c.addChild(csg);
47224855 }
47234856
4857
+ copy.versions = readobj.versions;
4858
+ copy.versionindex = readobj.versionindex;
4859
+
4860
+ SetUndoStates();
4861
+
47244862 ResetModel();
47254863 copy.HardTouch(); // recompile?
47264864 refreshContents();