Normand Briere
2019-07-14 bc829f47837b5a001f911542140b0b8e63c2bb0c
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;
....@@ -1174,10 +1174,11 @@
11741174 randomCB = AddCheckBox(setupPanel2, "Random", copy.random);
11751175 randomCB.setToolTipText("Randomly Rewind (or Go back and forth)");
11761176
1177
+ link2masterCB = AddCheckBox(setupPanel2, "Support", copy.link2master);
1178
+ link2masterCB.setToolTipText("Attach to support");
1179
+
11771180 if (Globals.ADVANCED)
11781181 {
1179
- link2masterCB = AddCheckBox(setupPanel2, "Supp", copy.link2master);
1180
- link2masterCB.setToolTipText("Attach to support");
11811182 speedupCB = AddCheckBox(setupPanel2, "Speed", copy.speedup);
11821183 speedupCB.setToolTipText("Option motion capture");
11831184 }
....@@ -1493,7 +1494,10 @@
14931494 // north.add(ctrlPanel, BorderLayout.NORTH);
14941495 // objectPanel.add(north);
14951496 objectPanel.add(editPanel);
1496
- objectPanel.add(infoPanel);
1497
+
1498
+ //if (Globals.ADVANCED)
1499
+ objectPanel.add(infoPanel);
1500
+
14971501 objectPanel.add(toolboxPanel);
14981502
14991503 /*
....@@ -1602,9 +1606,9 @@
16021606 // aConstraints.gridheight = 1;
16031607
16041608 framePanel = new JSplitPane(JSplitPane.VERTICAL_SPLIT, toolbarPanel, bigThree);
1605
- framePanel.setContinuousLayout(true);
1606
- framePanel.setOneTouchExpandable(true);
1607
- framePanel.setDividerLocation(0.8);
1609
+ framePanel.setContinuousLayout(false);
1610
+ framePanel.setOneTouchExpandable(false);
1611
+ //.setDividerLocation(0.8);
16081612 //framePanel.setDividerSize(15);
16091613 //framePanel.setResizeWeight(0.15);
16101614 framePanel.setName("Frame");
....@@ -1976,8 +1980,9 @@
19761980 // 3D models
19771981 if (filename.endsWith(".3ds") || filename.endsWith(".3DS"))
19781982 {
1979
- lastConverter = new com.jmex.model.converters.MaxToJme();
1980
- LoadFile(filename, lastConverter);
1983
+ //lastConverter = new com.jmex.model.converters.MaxToJme();
1984
+ //LoadFile(filename, lastConverter);
1985
+ LoadObjFile(filename); // New 3ds loader
19811986 continue;
19821987 }
19831988 if (filename.endsWith(".dae") || filename.endsWith(".DAE"))
....@@ -2703,6 +2708,7 @@
27032708 LA.matXRotate(((Object3D) group.get(group.size() - 1)).toParent, -Math.PI / 2);
27042709 LA.matXRotate(((Object3D) group.get(group.size() - 1)).fromParent, Math.PI / 2);
27052710 }
2711
+
27062712 //cJME.count++;
27072713 //cJME.count %= 12;
27082714 if (gc)
....@@ -2886,6 +2892,7 @@
28862892 }
28872893 }
28882894 }
2895
+
28892896 cFileSystemPane FSPane;
28902897
28912898 void SetMaterial(cMaterial mat, Object3D.cVector2[] others)
....@@ -2939,6 +2946,7 @@
29392946 }
29402947 }
29412948 }
2949
+
29422950 freezematerial = false;
29432951 }
29442952
....@@ -3391,9 +3399,9 @@
33913399 {
33923400 Close();
33933401 //return true;
3394
- } else if (source == loadItem)
3402
+ } else if (source == openItem)
33953403 {
3396
- load();
3404
+ Open();
33973405 //return true;
33983406 } else if (source == newItem)
33993407 {
....@@ -3418,6 +3426,10 @@
34183426 {
34193427 generatePOV();
34203428 //return true;
3429
+ } else if (event.getSource() == archiveItem)
3430
+ {
3431
+ cTools.Archive(frame);
3432
+ return;
34213433 } else if (source == zBufferItem)
34223434 {
34233435 try
....@@ -3469,8 +3481,8 @@
34693481 try
34703482 {
34713483 ByteArrayOutputStream baos = new ByteArrayOutputStream();
3472
- java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3473
- ObjectOutputStream out = new ObjectOutputStream(zstream);
3484
+// java.util.zip.GZIPOutputStream zstream = new java.util.zip.GZIPOutputStream(baos);
3485
+ ObjectOutputStream out = new ObjectOutputStream(baos); //zstream);
34743486
34753487 Object3D parent = o.parent;
34763488 o.parent = null;
....@@ -3481,10 +3493,14 @@
34813493
34823494 out.flush();
34833495
3484
- zstream.close();
3496
+ baos //zstream
3497
+ .close();
34853498 out.close();
34863499
3487
- return baos.toByteArray();
3500
+ byte[] bytes = baos.toByteArray();
3501
+
3502
+ System.out.println("save #bytes = " + bytes.length);
3503
+ return bytes;
34883504 } catch (Exception e)
34893505 {
34903506 System.err.println(e);
....@@ -3494,13 +3510,16 @@
34943510
34953511 static public Object Uncompress(byte[] bytes)
34963512 {
3497
- System.out.println("#bytes = " + bytes.length);
3513
+ System.out.println("restore #bytes = " + bytes.length);
34983514 try
34993515 {
35003516 ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
3501
- java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3502
- ObjectInputStream in = new ObjectInputStream(istream);
3517
+ //java.util.zip.GZIPInputStream istream = new java.util.zip.GZIPInputStream(bais);
3518
+ ObjectInputStream in = new ObjectInputStream(bais); // istream);
35033519 Object obj = in.readObject();
3520
+
3521
+ bais //istream
3522
+ .close();
35043523 in.close();
35053524
35063525 return obj;
....@@ -3559,6 +3578,27 @@
35593578
35603579 public void Save()
35613580 {
3581
+ Save(true);
3582
+ }
3583
+
3584
+ private boolean Equal(byte[] compress, byte[] name)
3585
+ {
3586
+ if (compress.length != name.length)
3587
+ {
3588
+ return false;
3589
+ }
3590
+
3591
+ for (int i=compress.length; --i>=0;)
3592
+ {
3593
+ if (compress[i] != name[i])
3594
+ return false;
3595
+ }
3596
+
3597
+ return true;
3598
+ }
3599
+
3600
+ public boolean Save(boolean user)
3601
+ {
35623602 System.err.println("Save");
35633603
35643604 cRadio tab = GetCurrentTab();
....@@ -3569,19 +3609,37 @@
35693609 copy.ExtractBigData(hashtable);
35703610
35713611 byte[] compress = Compress(copy);
3572
-
3573
- //EditorFrame.m_MainFrame.requestFocusInWindow();
3574
- tab.graphs[tab.undoindex++] = compress;
3575
-
3576
- copy.RestoreBigData(hashtable);
35773612
35783613 CameraPane.SWITCH = temp;
35793614
3615
+ boolean thesame = false;
3616
+
3617
+ // Quick heuristic using length. Works only when stream is compressed.
3618
+ if (tab.undoindex > 0 && tab.graphs[tab.undoindex-1] != null && Equal(compress, tab.graphs[tab.undoindex-1]))
3619
+ {
3620
+ thesame = true;
3621
+ }
3622
+
3623
+ //EditorFrame.m_MainFrame.requestFocusInWindow();
3624
+ if (!thesame)
3625
+ {
3626
+ //tab.user[tab.undoindex] = user;
3627
+ boolean increment = tab.graphs[tab.undoindex] == null;
3628
+
3629
+ tab.graphs[tab.undoindex] = compress;
3630
+
3631
+ if (increment)
3632
+ tab.undoindex++;
3633
+ }
3634
+
3635
+ copy.RestoreBigData(hashtable);
3636
+
35803637 //assert(hashtable.isEmpty());
35813638
35823639 for (int i = tab.undoindex; i < tab.graphs.length; i++)
35833640 {
3584
- tab.graphs[i] = null;
3641
+ //tab.user[i] = false;
3642
+ // tab.graphs[i] = null;
35853643 }
35863644
35873645 SetUndoStates();
....@@ -3604,6 +3662,8 @@
36043662 e.printStackTrace();
36053663 }
36063664 }
3665
+
3666
+ return !thesame;
36073667 }
36083668
36093669 void CopyChanged(Object3D obj)
....@@ -3660,7 +3720,7 @@
36603720 redoButton.setEnabled(tab.graphs[tab.undoindex + 1] != null);
36613721 }
36623722
3663
- public void Undo()
3723
+ public boolean Undo()
36643724 {
36653725 System.err.println("Undo");
36663726
....@@ -3669,18 +3729,27 @@
36693729 if (tab.undoindex == 0)
36703730 {
36713731 java.awt.Toolkit.getDefaultToolkit().beep();
3672
- return;
3732
+ return false;
36733733 }
36743734
3675
- if (tab.graphs[tab.undoindex] == null)
3735
+ if (tab.graphs[tab.undoindex] == null) // || !tab.user[tab.undoindex])
36763736 {
3677
- Save();
3678
- tab.undoindex -= 1;
3737
+ if (Save(false))
3738
+ tab.undoindex -= 1;
3739
+ else
3740
+ {
3741
+ if (tab.undoindex <= 0)
3742
+ return false;
3743
+ else
3744
+ tab.undoindex -= 1;
3745
+ }
36793746 }
36803747
36813748 tab.undoindex -= 1;
36823749
36833750 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3751
+
3752
+ return true;
36843753 }
36853754
36863755 public void Redo()
....@@ -3696,6 +3765,9 @@
36963765 tab.undoindex += 1;
36973766
36983767 CopyChanged((Object3D)Uncompress(tab.graphs[tab.undoindex]));
3768
+
3769
+ //if (!tab.user[tab.undoindex])
3770
+ // tab.graphs[tab.undoindex] = null;
36993771 }
37003772
37013773 void ImportGFD()
....@@ -4658,8 +4730,8 @@
46584730
46594731 if (readobj != null)
46604732 {
4661
- if (Globals.SAVEONMAKE)
4662
- Save();
4733
+ //if (Globals.SAVEONMAKE) // A new object cannot share meshes
4734
+ // Save();
46634735 try
46644736 {
46654737 //readobj.deepCopySelf(copy);
....@@ -4720,7 +4792,7 @@
47204792 }
47214793 }
47224794
4723
- void load() // throws ClassNotFoundException
4795
+ void Open() // throws ClassNotFoundException
47244796 {
47254797 if (Grafreed.standAlone)
47264798 {
....@@ -5005,7 +5077,7 @@
50055077 MenuBar menuBar;
50065078 Menu fileMenu;
50075079 MenuItem newItem;
5008
- MenuItem loadItem;
5080
+ MenuItem openItem;
50095081 MenuItem saveItem;
50105082 MenuItem saveAsItem;
50115083 MenuItem exportAsItem;
....@@ -5028,6 +5100,7 @@
50285100 CheckboxMenuItem toggleSwitchItem;
50295101 CheckboxMenuItem toggleRootItem;
50305102 CheckboxMenuItem animationItem;
5103
+ MenuItem archiveItem;
50315104 CheckboxMenuItem toggleHandleItem;
50325105 CheckboxMenuItem togglePaintItem;
50335106 JSplitPane mainPanel;