Normand Briere
2019-08-05 de0d8d87447fea5faea469ccf8072a7aead35b6d
ObjEditor.java
....@@ -296,9 +296,9 @@
296296 client = inClient;
297297 copy = client;
298298
299
- if (copy.versions == null)
299
+ if (copy.versionlist == null)
300300 {
301
- copy.versions = new byte[100][];
301
+ copy.versionlist = new Object3D[100];
302302 copy.versionindex = -1;
303303 }
304304
....@@ -315,9 +315,9 @@
315315 client = inClient;
316316 copy = client;
317317
318
- if (copy.versions == null)
318
+ if (copy.versionlist == null)
319319 {
320
- copy.versions = new byte[100][];
320
+ copy.versionlist = new Object3D[100];
321321 copy.versionindex = -1;
322322 }
323323
....@@ -353,7 +353,7 @@
353353 copy = localCopy;
354354 copy.editWindow = this;
355355
356
- if (copy.versions == null)
356
+ if (copy.versionlist == null)
357357 {
358358 // copy.versions = new byte[100][];
359359 // copy.versionindex = -1;
....@@ -467,7 +467,7 @@
467467 toolboxPanel = new cGridBag().setVertical(true);
468468 //toolboxPanel.setName("Toolbox");
469469
470
- materialPanel = new cGridBag().setVertical(true);
470
+ materialPanel = new cGridBag().setVertical(false);
471471 //materialPanel.setName("Material");
472472
473473 /*JTextPane*/
....@@ -848,9 +848,11 @@
848848 //frame.setVisible(true);
849849 }
850850 frame.validate();
851
+
852
+ cameraView.requestFocusInWindow();
851853 }
852854
853
- private byte[] CompressCopy()
855
+ private Object3D CompressCopy()
854856 {
855857 boolean temp = CameraPane.SWITCH;
856858 CameraPane.SWITCH = false;
....@@ -858,12 +860,13 @@
858860 copy.ExtractBigData(versiontable);
859861 // if (copy == client)
860862
861
- byte[] versions[] = copy.versions;
862
- copy.versions = null;
863
+ Object3D versions[] = copy.versionlist;
864
+ copy.versionlist = null;
863865
864
- byte[] compress = Compress(copy);
866
+ //byte[] compress = Compress(copy);
867
+ Object3D compress = (Object3D)Grafreed.clone(copy);
865868
866
- copy.versions = versions;
869
+ copy.versionlist = versions;
867870
868871 copy.RestoreBigData(versiontable);
869872
....@@ -993,6 +996,7 @@
993996 {
994997 SetupMaterial(materialPanel);
995998 }
999
+
9961000 //SetupName();
9971001 //SetupViews();
9981002 }
....@@ -1550,7 +1554,7 @@
15501554 //tmp.setName("Edit");
15511555 objectPanel.add(materialPanel);
15521556 objectPanel.setIconAt(0, GetIcon("icons/material.png"));
1553
- objectPanel.setToolTipTextAt(0, "Material panel");
1557
+ objectPanel.setToolTipTextAt(0, "Material");
15541558
15551559 // JPanel north = new JPanel(new BorderLayout());
15561560 // north.setName("Edit");
....@@ -1558,20 +1562,20 @@
15581562 // objectPanel.add(north);
15591563 objectPanel.add(editPanel);
15601564 objectPanel.setIconAt(1, GetIcon("icons/write.png"));
1561
- objectPanel.setToolTipTextAt(1, "Edit panel");
1565
+ objectPanel.setToolTipTextAt(1, "Edit controls");
15621566
15631567 //if (Globals.ADVANCED)
15641568 objectPanel.add(infoPanel);
15651569 objectPanel.setIconAt(2, GetIcon("icons/info.png"));
1566
- objectPanel.setToolTipTextAt(2, "Info panel");
1570
+ objectPanel.setToolTipTextAt(2, "Information");
15671571
15681572 objectPanel.add(XYZPanel);
15691573 objectPanel.setIconAt(3, GetIcon("icons/XYZ.png"));
1570
- objectPanel.setToolTipTextAt(3, "XYZ/RGB panel");
1574
+ objectPanel.setToolTipTextAt(3, "XYZ/RGB transform");
15711575
15721576 objectPanel.add(toolboxPanel);
15731577 objectPanel.setIconAt(4, GetIcon("icons/primitives.png"));
1574
- objectPanel.setToolTipTextAt(4, "Objects/backgrounds panel");
1578
+ objectPanel.setToolTipTextAt(4, "Objects & backgrounds");
15751579
15761580 /*
15771581 aConstraints.gridx = 0;
....@@ -1733,12 +1737,85 @@
17331737 ctrlPanel.removeAll();
17341738 }
17351739
1736
- void SetupMaterial(cGridBag panel)
1740
+ void SetupMaterial(cGridBag materialpanel)
17371741 {
1738
- /*
1742
+ cGridBag presetpanel = new cGridBag().setVertical(true);
1743
+ cLabel skin = GetLabel("icons/shadericons/shadericon00000.png", !Grafreed.NIMBUSLAF);
1744
+ skin.addMouseListener(new MouseAdapter()
1745
+ {
1746
+ public void mouseClicked(MouseEvent e)
1747
+ {
1748
+ Object3D object = Grafreed.materials.versionlist[0].get(0);
1749
+ cMaterial material = object.material;
1750
+
1751
+ // Skin
1752
+ colorField.setFloat(material.color);
1753
+ saturationField.setFloat(material.modulation);
1754
+ subsurfaceField.setFloat(material.subsurface);
1755
+ selfshadowField.setFloat(material.diffuseness);
1756
+ diffusenessField.setFloat(material.factor);
1757
+ shininessField.setFloat(material.shininess);
1758
+ shadowbiasField.setFloat(material.shadowbias);
1759
+ diffuseField.setFloat(material.diffuse);
1760
+ specularField.setFloat(material.specular);
1761
+
1762
+ bumpField.setFloat(object.projectedVertices[0].x / 1000.0);
1763
+ noiseField.setFloat(object.projectedVertices[0].y / 1000.0);
1764
+ powerField.setFloat(object.projectedVertices[2].x / 1000.0);
1765
+
1766
+ materialtouched = true;
1767
+ applySelf();
1768
+ }
1769
+ });
1770
+ presetpanel.add(skin);
1771
+
1772
+ cLabel rough2 = GetLabel("icons/shadericons/shadericon00001.png", !Grafreed.NIMBUSLAF);
1773
+ rough2.addMouseListener(new MouseAdapter()
1774
+ {
1775
+ public void mouseClicked(MouseEvent e)
1776
+ {
1777
+ Object3D object = Grafreed.materials.versionlist[1].get(0);
1778
+ cMaterial material = object.material;
1779
+
1780
+ shininessField.setFloat(material.shininess);
1781
+ velvetField.setFloat(material.velvet);
1782
+
1783
+ materialtouched = true;
1784
+ applySelf();
1785
+ }
1786
+ });
1787
+ presetpanel.add(rough2);
1788
+
1789
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00002.png", !Grafreed.NIMBUSLAF));
1790
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00003.png", !Grafreed.NIMBUSLAF));
1791
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00004.png", !Grafreed.NIMBUSLAF));
1792
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00005.png", !Grafreed.NIMBUSLAF));
1793
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00006.png", !Grafreed.NIMBUSLAF));
1794
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00007.png", !Grafreed.NIMBUSLAF));
1795
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00008.png", !Grafreed.NIMBUSLAF));
1796
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00009.png", !Grafreed.NIMBUSLAF));
1797
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00010.png", !Grafreed.NIMBUSLAF));
1798
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00011.png", !Grafreed.NIMBUSLAF));
1799
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00012.png", !Grafreed.NIMBUSLAF));
1800
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00013.png", !Grafreed.NIMBUSLAF));
1801
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00014.png", !Grafreed.NIMBUSLAF));
1802
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00015.png", !Grafreed.NIMBUSLAF));
1803
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00016.png", !Grafreed.NIMBUSLAF));
1804
+ presetpanel.add(GetLabel("icons/shadericons/shadericon00017.png", !Grafreed.NIMBUSLAF));
1805
+
1806
+ cGridBag panel = new cGridBag().setVertical(true);
1807
+
1808
+ presetpanel.preferredWidth = 1;
1809
+
1810
+ materialpanel.add(panel);
1811
+ materialpanel.add(presetpanel);
1812
+
1813
+ panel.preferredWidth = 8;
1814
+
1815
+ /*
17391816 ctrlPanel.add(materialLabel = new JLabel("MATERIAL : "), aConstraints);
17401817 materialLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1741
- */
1818
+ */
17421819
17431820 cGridBag editBar = new cGridBag().setVertical(false);
17441821
....@@ -1775,7 +1852,9 @@
17751852
17761853 cGridBag huepanel = new cGridBag();
17771854 cGridBag huelabel = new cGridBag();
1778
- huelabel.add(GetLabel("icons/hue.png", false));
1855
+ skin = GetLabel("icons/hue.png", false);
1856
+ skin.fit = true;
1857
+ huelabel.add(skin);
17791858 huelabel.preferredWidth = 20;
17801859 huepanel.add(new cGridBag()); // Label
17811860 huepanel.add(huelabel); // Field/slider
....@@ -1796,7 +1875,7 @@
17961875 cGridBag modulation = new cGridBag();
17971876 modulation.add(modulationLabel = new JLabel("Saturation")); // , aConstraints);
17981877 modulationLabel.setHorizontalAlignment(SwingConstants.TRAILING);
1799
- modulation.add(modulationField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
1878
+ modulation.add(saturationField = new cNumberSlider(this, 0.001, 1)); // , aConstraints);
18001879 colorSection.add(modulation);
18011880
18021881 cGridBag opacity = new cGridBag();
....@@ -2989,7 +3068,7 @@
29893068
29903069 freezematerial = true;
29913070 colorField.setFloat(mat.color);
2992
- modulationField.setFloat(mat.modulation);
3071
+ saturationField.setFloat(mat.modulation);
29933072 metalnessField.setFloat(mat.metalness);
29943073 diffuseField.setFloat(mat.diffuse);
29953074 specularField.setFloat(mat.specular);
....@@ -3300,6 +3379,7 @@
33003379 } else if (event.getSource() == liveCB)
33013380 {
33023381 copy.live ^= true;
3382
+ objEditor.refreshContents(true); // To show item colors
33033383 return;
33043384 } else if (event.getSource() == selectableCB)
33053385 {
....@@ -3309,7 +3389,7 @@
33093389 {
33103390 copy.hide ^= true;
33113391 copy.Touch(); // display list issue
3312
- objEditor.refreshContents();
3392
+ objEditor.refreshContents(true); // To show item colors
33133393 return;
33143394 } else if (event.getSource() == link2masterCB)
33153395 {
....@@ -3565,6 +3645,7 @@
35653645
35663646 static public byte[] Compress(Object3D o)
35673647 {
3648
+ // Slower to actually compress.
35683649 try
35693650 {
35703651 ByteArrayOutputStream baos = new ByteArrayOutputStream();
....@@ -3666,6 +3747,7 @@
36663747 {
36673748 //Save(true);
36683749 Replace();
3750
+ SetUndoStates();
36693751 }
36703752
36713753 private boolean Equal(byte[] compress, byte[] name)
....@@ -3686,29 +3768,46 @@
36863768
36873769 java.util.Hashtable<java.util.UUID, Object3D> versiontable = new java.util.Hashtable<java.util.UUID, Object3D>();
36883770
3771
+ void DeleteVersion()
3772
+ {
3773
+ for (int i = copy.versionindex; i < copy.versionlist.length-1; i++)
3774
+ {
3775
+ copy.versionlist[i] = copy.versionlist[i+1];
3776
+ }
3777
+
3778
+ CopyChanged();
3779
+
3780
+ SetUndoStates();
3781
+ }
3782
+
36893783 public boolean Save(boolean user)
36903784 {
36913785 System.err.println("Save");
3786
+ //Replace();
36923787
36933788 cRadio tab = GetCurrentTab();
36943789
3695
- byte[] compress = CompressCopy(); // Saved version. No need for "Replace".
3790
+ Object3D compress = CompressCopy(); // Saved version. No need for "Replace"?
36963791
36973792 boolean thesame = false;
36983793
3699
- // Quick heuristic using length. Works only when stream is compressed.
3700
- if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
3701
- {
3702
- thesame = true;
3703
- }
3794
+// if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1]))
3795
+// {
3796
+// thesame = true;
3797
+// }
37043798
37053799 //EditorFrame.m_MainFrame.requestFocusInWindow();
37063800 if (!thesame)
37073801 {
3802
+ for (int i = copy.versionlist.length; --i > copy.versionindex+1;)
3803
+ {
3804
+ copy.versionlist[i] = copy.versionlist[i-1];
3805
+ }
3806
+
37083807 //tab.user[tab.versionindex] = user;
37093808 //boolean increment = true; // tab.graphs[tab.versionindex] == null;
37103809
3711
- copy.versions[++copy.versionindex] = compress;
3810
+ copy.versionlist[++copy.versionindex] = compress;
37123811
37133812 // if (increment)
37143813 // tab.versionindex++;
....@@ -3718,11 +3817,11 @@
37183817
37193818 //assert(hashtable.isEmpty());
37203819
3721
- for (int i = copy.versionindex+1; i < copy.versions.length; i++)
3722
- {
3723
- //tab.user[i] = false;
3724
- copy.versions[i] = null;
3725
- }
3820
+// for (int i = copy.versionindex+1; i < copy.versionlist.length; i++)
3821
+// {
3822
+// //tab.user[i] = false;
3823
+// copy.versionlist[i] = null;
3824
+// }
37263825
37273826 SetUndoStates();
37283827
....@@ -3747,9 +3846,43 @@
37473846
37483847 return !thesame;
37493848 }
3750
-
3751
- void CopyChanged(Object3D obj)
3849
+
3850
+ boolean flashIt = true;
3851
+
3852
+ void RefreshSelection()
37523853 {
3854
+ Object3D selection = new Object3D();
3855
+
3856
+ for (int i = 0; i < copy.selection.size(); i++)
3857
+ {
3858
+ Object3D elem = copy.selection.elementAt(i);
3859
+
3860
+ Object3D obj = copy.GetObject(elem.GetUUID());
3861
+
3862
+ if (obj == null)
3863
+ {
3864
+ copy.selection.remove(i--);
3865
+ }
3866
+ else
3867
+ {
3868
+ selection.add(obj);
3869
+ copy.selection.setElementAt(obj, i);
3870
+ }
3871
+ }
3872
+
3873
+ flashIt = false;
3874
+ GetTree().clearSelection();
3875
+ for (int i = 0; i < selection.size(); i++)
3876
+ GetTree().addSelectionPath(selection.elementAt(i).GetTreePath().GetTreePath());
3877
+ flashIt = true;
3878
+
3879
+ //refreshContents(false);
3880
+ }
3881
+
3882
+ void CopyChanged()
3883
+ {
3884
+ Object3D obj = copy.versionlist[copy.versionindex];
3885
+
37533886 SetUndoStates();
37543887
37553888 boolean temp = CameraPane.SWITCH;
....@@ -3771,6 +3904,7 @@
37713904
37723905 CameraPane.SWITCH = temp;
37733906
3907
+ RefreshSelection();
37743908 //assert(hashtable.isEmpty());
37753909
37763910 copy.Touch();
....@@ -3791,13 +3925,15 @@
37913925 }
37923926 }
37933927
3794
- refreshContents();
3928
+ refreshContents(true);
37953929 }
37963930
3797
- cButton undoButton;
3931
+ cButton previousVersionButton;
37983932 cButton restoreButton;
37993933 cButton replaceButton;
3800
- cButton redoButton;
3934
+ cButton nextVersionButton;
3935
+ cButton saveVersionButton;
3936
+ cButton deleteVersionButton;
38013937
38023938 boolean muteSlider;
38033939
....@@ -3805,9 +3941,9 @@
38053941 {
38063942 int count = 0;
38073943
3808
- for (int i = copy.versions.length; --i >= 0;)
3944
+ for (int i = copy.versionlist.length; --i >= 0;)
38093945 {
3810
- if (copy.versions[i] != null)
3946
+ if (copy.versionlist[i] != null)
38113947 count++;
38123948 }
38133949
....@@ -3818,11 +3954,14 @@
38183954 {
38193955 cRadio tab = GetCurrentTab();
38203956
3821
- restoreButton.setEnabled(copy.versionindex != -1);
3822
- replaceButton.setEnabled(copy.versionindex != -1);
3957
+ restoreButton.setEnabled(true); // copy.versionindex != -1);
3958
+ replaceButton.setEnabled(true); // copy.versionindex != -1);
38233959
3824
- undoButton.setEnabled(copy.versionindex > 0);
3825
- redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null);
3960
+ previousVersionButton.setEnabled(copy.versionindex > 0);
3961
+ nextVersionButton.setEnabled(copy.versionlist[copy.versionindex + 1] != null);
3962
+
3963
+ deleteVersionButton.setEnabled(//copy.versionindex > 0 &&
3964
+ copy.versionlist[copy.versionindex + 1] != null);
38263965
38273966 muteSlider = true;
38283967 versionSlider.setMaximum(VersionCount() - 1);
....@@ -3830,7 +3969,7 @@
38303969 muteSlider = false;
38313970 }
38323971
3833
- public boolean Undo()
3972
+ public boolean PreviousVersion()
38343973 {
38353974 // Option?
38363975 Replace();
....@@ -3860,7 +3999,7 @@
38603999
38614000 copy.versionindex -= 1;
38624001
3863
- CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
4002
+ CopyChanged();
38644003
38654004 return true;
38664005 }
....@@ -3871,13 +4010,14 @@
38714010
38724011 cRadio tab = GetCurrentTab();
38734012
3874
- if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
4013
+ if (copy.versionindex == -1 || copy.versionlist[copy.versionindex] == null)
38754014 {
38764015 java.awt.Toolkit.getDefaultToolkit().beep();
38774016 return false;
38784017 }
38794018
3880
- CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
4019
+ //CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
4020
+ CopyChanged();
38814021
38824022 return true;
38834023 }
....@@ -3888,25 +4028,25 @@
38884028
38894029 cRadio tab = GetCurrentTab();
38904030
3891
- if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null)
4031
+ if (copy.versionindex == -1 || copy.versionlist[copy.versionindex] == null)
38924032 {
38934033 // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep();
38944034 return false;
38954035 }
38964036
3897
- copy.versions[copy.versionindex] = CompressCopy();
4037
+ copy.versionlist[copy.versionindex] = CompressCopy();
38984038
38994039 return true;
39004040 }
39014041
3902
- public void Redo()
4042
+ public void NextVersion()
39034043 {
39044044 // Option?
39054045 Replace();
39064046
39074047 cRadio tab = GetCurrentTab();
39084048
3909
- if (copy.versions[copy.versionindex + 1] == null)
4049
+ if (copy.versionlist[copy.versionindex + 1] == null)
39104050 {
39114051 java.awt.Toolkit.getDefaultToolkit().beep();
39124052 return;
....@@ -3914,7 +4054,7 @@
39144054
39154055 copy.versionindex += 1;
39164056
3917
- CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex]));
4057
+ CopyChanged();
39184058
39194059 //if (!tab.user[tab.versionindex])
39204060 // tab.graphs[tab.versionindex] = null;
....@@ -4128,7 +4268,7 @@
41284268 //copy.material = new cMaterial(copy.GetMaterial());
41294269
41304270 current.color = (float) colorField.getFloat();
4131
- current.modulation = (float) modulationField.getFloat();
4271
+ current.modulation = (float) saturationField.getFloat();
41324272 current.metalness = (float) metalnessField.getFloat();
41334273 current.diffuse = (float) diffuseField.getFloat();
41344274 current.specular = (float) specularField.getFloat();
....@@ -4161,7 +4301,7 @@
41614301 cMaterial mat = copy.material;
41624302
41634303 colorField.SetToolTipValue((mat.color));
4164
- modulationField.SetToolTipValue((mat.modulation));
4304
+ saturationField.SetToolTipValue((mat.modulation));
41654305 metalnessField.SetToolTipValue((mat.metalness));
41664306 diffuseField.SetToolTipValue((mat.diffuse));
41674307 specularField.SetToolTipValue((mat.specular));
....@@ -4225,9 +4365,10 @@
42254365
42264366 int version = versionSlider.getInteger();
42274367
4228
- if (copy.versions[version] != null)
4368
+ if (copy.versionlist[version] != null)
42294369 {
4230
- CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version]));
4370
+ copy.versionindex = version;
4371
+ CopyChanged();
42314372 }
42324373
42334374 return;
....@@ -4267,6 +4408,12 @@
42674408 {
42684409 //System.out.println("stateChanged = " + this);
42694410 materialtouched = true;
4411
+
4412
+ if (e.getSource() == colorField && saturationField.getFloat() == 0.001)
4413
+ {
4414
+ saturationField.setFloat(1);
4415
+ }
4416
+
42704417 applySelf();
42714418 //System.out.println("this = " + this);
42724419 //System.out.println("PARENT = " + parent);
....@@ -4566,6 +4713,7 @@
45664713 {
45674714 if (GetTree() != null)
45684715 {
4716
+ GetTree().revalidate();
45694717 GetTree().repaint();
45704718 }
45714719
....@@ -4574,6 +4722,9 @@
45744722 ctrlPanel.validate(); // ? new
45754723 ctrlPanel.repaint();
45764724 }
4725
+
4726
+ if (previousVersionButton != null && copy.versionlist != null)
4727
+ SetUndoStates();
45774728 }
45784729
45794730 static TweenManager tweenManager = new TweenManager();
....@@ -4957,12 +5108,12 @@
49575108 c.addChild(csg);
49585109 }
49595110
4960
- copy.versions = readobj.versions;
5111
+ copy.versionlist = readobj.versionlist;
49615112 copy.versionindex = readobj.versionindex;
49625113
4963
- if (copy.versions == null)
5114
+ if (copy.versionlist == null)
49645115 {
4965
- copy.versions = new byte[100][];
5116
+ copy.versionlist = new Object3D[100];
49665117 copy.versionindex = -1;
49675118 }
49685119
....@@ -4978,7 +5129,7 @@
49785129 {
49795130 if (Grafreed.standAlone)
49805131 {
4981
- FileDialog browser = new FileDialog(frame, "Load", FileDialog.LOAD);
5132
+ FileDialog browser = new FileDialog(frame, "Open", FileDialog.LOAD);
49825133 browser.show();
49835134 String filename = browser.getFile();
49845135 if (filename != null && filename.length() > 0)
....@@ -5370,7 +5521,7 @@
53705521 JLabel colorLabel;
53715522 cNumberSlider colorField;
53725523 JLabel modulationLabel;
5373
- cNumberSlider modulationField;
5524
+ cNumberSlider saturationField;
53745525 JLabel metalnessLabel;
53755526 cNumberSlider metalnessField;
53765527 JLabel diffuseLabel;