Normand Briere
2019-08-17 d5d6485126da83b06645e90e3e4ce66659a56009
ObjEditor.java
....@@ -83,7 +83,10 @@
8383 cButton GetButton(String name, boolean border)
8484 {
8585 ImageIcon icon = GetIcon(name);
86
- return new cButton(icon, border);
86
+ if (icon != null)
87
+ return new cButton(icon, border);
88
+ else
89
+ return new cButton(name, border);
8790 }
8891
8992 cLabel GetLabel(String name, boolean border)
....@@ -106,7 +109,7 @@
106109
107110 static java.util.Hashtable<String, javax.swing.ImageIcon> icons = new java.util.Hashtable<String, javax.swing.ImageIcon>();
108111
109
- ImageIcon GetIcon(String name)
112
+ static ImageIcon GetIcon(String name)
110113 {
111114 javax.swing.ImageIcon iconCache = icons.get(name);
112115 if (iconCache != null)
....@@ -116,7 +119,7 @@
116119
117120 try
118121 {
119
- BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name));
122
+ BufferedImage image = javax.imageio.ImageIO.read(ObjEditor.class.getClassLoader().getResourceAsStream(name));
120123
121124 // if (image.getWidth() > 48 && image.getHeight() > 48)
122125 // {
....@@ -426,6 +429,9 @@
426429
427430 static java.util.Vector<Object3D> listUI = new java.util.Vector<Object3D>();
428431
432
+ // This is to refresh the UI of the material panel.
433
+ boolean patchMaterial;
434
+
429435 void SetupMenu()
430436 {
431437 frame.setMenuBar(menuBar = new MenuBar());
....@@ -962,8 +968,13 @@
962968 object.versionlist = null;
963969 object.versiontable = null;
964970
971
+ Object3D parent = object.parent;
972
+ object.parent = null;
973
+
965974 //byte[] compress = Compress(copy);
966975 Object3D compress = (Object3D)Grafreed.clone(object);
976
+
977
+ object.parent = parent;
967978
968979 object.versionlist = versions;
969980 object.versiontable = versiontable; // if Grafreed.grafreed.universe
....@@ -1621,6 +1632,42 @@
16211632 //frontView.object = copy;
16221633 //sideView.object = copy;
16231634
1635
+ transformPanel = new cGridBag().setVertical(true);
1636
+
1637
+ cGridBag resetTransformPanel = new cGridBag();
1638
+
1639
+ resetTransformPanel.preferredHeight = 2;
1640
+
1641
+ cButton resetTransform = GetButton("Reset all", !Grafreed.NIMBUSLAF);
1642
+ resetTransform.addMouseListener(new MouseAdapter()
1643
+ {
1644
+ public void mouseClicked(MouseEvent e)
1645
+ {
1646
+ ResetTransform();
1647
+ }
1648
+ });
1649
+ resetTransformPanel.add(resetTransform);
1650
+
1651
+ resetTransform = GetButton("T only", !Grafreed.NIMBUSLAF);
1652
+ resetTransform.addMouseListener(new MouseAdapter()
1653
+ {
1654
+ public void mouseClicked(MouseEvent e)
1655
+ {
1656
+ ResetTransform(1);
1657
+ }
1658
+ });
1659
+ resetTransformPanel.add(resetTransform);
1660
+
1661
+ resetTransform = GetButton("RS only", !Grafreed.NIMBUSLAF);
1662
+ resetTransform.addMouseListener(new MouseAdapter()
1663
+ {
1664
+ public void mouseClicked(MouseEvent e)
1665
+ {
1666
+ ResetTransform(2);
1667
+ }
1668
+ });
1669
+ resetTransformPanel.add(resetTransform);
1670
+
16241671 XYZPanel = new cGridBag().setVertical(true);
16251672 //XYZPanel.setLayout(new GridLayout(3, 1, 5, 5));
16261673
....@@ -1630,6 +1677,9 @@
16301677 XYZPanel.addComponent(/*BorderLayout.NORTH,*/topView); // Scroll);
16311678 //XYZPanel.setName("XYZ");
16321679
1680
+ transformPanel.add(resetTransformPanel);
1681
+ transformPanel.add(XYZPanel);
1682
+
16331683 /*
16341684 gridPanel = new JPanel(); //new BorderLayout());
16351685 gridPanel.setLayout(new GridLayout(1, 2));
....@@ -1637,12 +1687,12 @@
16371687 gridPanel.add(cameraView);
16381688 gridPanel.add(XYZPanel);
16391689 */
1640
- gridPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, centralPanel, XYZPanel); //new BorderLayout());
1641
- gridPanel.setContinuousLayout(true);
1642
- gridPanel.setOneTouchExpandable(true);
1643
- gridPanel.setDividerLocation(1.0);
1644
- gridPanel.setDividerSize(9);
1645
- gridPanel.setResizeWeight(0.85);
1690
+// gridPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, centralPanel, XYZPanel); //new BorderLayout());
1691
+// gridPanel.setContinuousLayout(true);
1692
+// gridPanel.setOneTouchExpandable(true);
1693
+// gridPanel.setDividerLocation(1.0);
1694
+// gridPanel.setDividerSize(9);
1695
+// gridPanel.setResizeWeight(0.85);
16461696
16471697 // aConstraints.weighty = 0;
16481698 //System.out.println("THIS = " + this);
....@@ -1685,10 +1735,14 @@
16851735 objectPanel.setIconAt(3, GetIcon("icons/write.png"));
16861736 objectPanel.setToolTipTextAt(3, "Edit controls");
16871737
1688
- objectPanel.add(XYZPanel);
1738
+ objectPanel.add(transformPanel);
16891739 objectPanel.setIconAt(4, GetIcon("icons/XYZ.png"));
1690
- objectPanel.setToolTipTextAt(4, "XYZ/RGB transform");
1740
+ objectPanel.setToolTipTextAt(4, "TRS transform");
16911741
1742
+ patchMaterial = true;
1743
+ cameraView.patchMaterial = this;
1744
+ objectPanel.setSelectedIndex(1);
1745
+
16921746 /*
16931747 aConstraints.gridx = 0;
16941748 aConstraints.gridwidth = 1;
....@@ -1708,7 +1762,7 @@
17081762 scrollpane.addMouseWheelListener(this); // Default not fast enough
17091763
17101764 /*JTabbedPane*/ scenePanel = new cGridBag();
1711
- scenePanel.preferredWidth = 5;
1765
+ scenePanel.preferredWidth = 6;
17121766
17131767 JTabbedPane tabbedPane = new JTabbedPane();
17141768 tabbedPane.add(scrollpane);
....@@ -1750,13 +1804,13 @@
17501804 jtp.add(tree);
17511805 */
17521806
1753
- bigPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scenePanel, gridPanel);
1754
- bigPanel.setContinuousLayout(true);
1755
- bigPanel.setOneTouchExpandable(true);
1756
- bigPanel.setDividerLocation(0.8);
1757
- bigPanel.setDividerSize(15);
1758
- bigPanel.setResizeWeight(0.15);
1759
- bigPanel.setName("Scene");
1807
+// bigPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scenePanel, gridPanel);
1808
+// bigPanel.setContinuousLayout(true);
1809
+// bigPanel.setOneTouchExpandable(true);
1810
+// bigPanel.setDividerLocation(0.8);
1811
+// bigPanel.setDividerSize(15);
1812
+// bigPanel.setResizeWeight(0.15);
1813
+// bigPanel.setName("Scene");
17601814
17611815 //bigPanel.setLayout(new BorderLayout());
17621816 //bigPanel.setSize(new Dimension(10,10));
....@@ -1840,7 +1894,7 @@
18401894
18411895 cameraView.requestFocusInWindow();
18421896
1843
- gridPanel.setDividerLocation(1.0);
1897
+// gridPanel.setDividerLocation(1.0);
18441898
18451899 frame.validate();
18461900
....@@ -1886,7 +1940,15 @@
18861940
18871941 // Skin
18881942 colorField.setFloat(material.color);
1889
- saturationField.setFloat(material.modulation);
1943
+ float saturation = material.modulation;
1944
+
1945
+ if (!cameraView.Skinshader)
1946
+ {
1947
+ saturation /= 1.5;
1948
+ }
1949
+
1950
+ saturationField.setFloat(saturation);
1951
+
18901952 subsurfaceField.setFloat(material.subsurface);
18911953 selfshadowField.setFloat(material.diffuseness);
18921954 diffusenessField.setFloat(material.factor);
....@@ -4417,6 +4479,8 @@
44174479 return count;
44184480 }
44194481
4482
+ public cGridBag versionSliderPane;
4483
+
44204484 void SetVersionStates()
44214485 {
44224486 //if (true)
....@@ -4424,21 +4488,36 @@
44244488
44254489 //cRadio tab = GetCurrentTab();
44264490
4427
- restoreButton.setEnabled(copy.versionindex != -1);
4428
- replaceButton.setEnabled(copy.versionindex != -1);
4429
-
4430
- previousVersionButton.setEnabled(copy.versionindex > 0);
4431
- nextVersionButton.setEnabled(copy.versionlist[copy.versionindex + 1] != null);
4432
-
4433
- deleteVersionButton.setEnabled(copy.versionindex != -1);
4434
- //copy.versionlist[copy.versionindex + 1] != null);
4435
-
4436
- muteSlider = true;
4437
- versionSlider.setMinimum(0);
4438
- versionSlider.setMaximum(VersionCount() - 1);
4439
- versionSlider.setInteger(copy.versionindex);
4440
- versionSlider.setEnabled(copy.versionindex != -1);
4441
- muteSlider = false;
4491
+ if (copy.versionlist == null)
4492
+ {
4493
+ saveVersionButton.setEnabled(false);
4494
+ restoreButton.setEnabled(false);
4495
+ replaceButton.setEnabled(false);
4496
+ previousVersionButton.setEnabled(false);
4497
+ nextVersionButton.setEnabled(false);
4498
+ deleteVersionButton.setEnabled(false);
4499
+ versionSliderPane.setVisible(false);
4500
+ }
4501
+ else
4502
+ {
4503
+ restoreButton.setEnabled(copy.versionindex != -1);
4504
+ replaceButton.setEnabled(copy.versionindex != -1);
4505
+
4506
+ previousVersionButton.setEnabled(copy.versionindex > 0);
4507
+ nextVersionButton.setEnabled(copy.versionlist[copy.versionindex + 1] != null);
4508
+
4509
+ deleteVersionButton.setEnabled(copy.versionindex != -1);
4510
+ //copy.versionlist[copy.versionindex + 1] != null);
4511
+
4512
+ muteSlider = true;
4513
+ versionSlider.setMinimum(0);
4514
+ versionSlider.setMaximum(VersionCount() - 1);
4515
+ versionSlider.setInteger(copy.versionindex);
4516
+ versionSlider.setEnabled(copy.versionindex != -1);
4517
+ muteSlider = false;
4518
+
4519
+ versionSliderPane.setVisible(true);
4520
+ }
44424521 }
44434522
44444523 public boolean PreviousVersion()
....@@ -4723,6 +4802,12 @@
47234802 // else
47244803 // applySelf(true);
47254804 // }
4805
+
4806
+ boolean Equal(double a, double b)
4807
+ {
4808
+ return Math.abs(a - b) < 0.001;
4809
+ }
4810
+
47264811 void applySelf0(boolean name)
47274812 {
47284813 if (name)
....@@ -4772,29 +4857,52 @@
47724857 {
47734858 cMaterial mat = copy.material;
47744859
4775
- colorField.SetToolTipValue((mat.color));
4776
- saturationField.SetToolTipValue((mat.modulation));
4777
- metalnessField.SetToolTipValue((mat.metalness));
4778
- diffuseField.SetToolTipValue((mat.diffuse));
4779
- specularField.SetToolTipValue((mat.specular));
4780
- shininessField.SetToolTipValue((mat.shininess));
4781
- shiftField.SetToolTipValue((mat.shift));
4782
- ambientField.SetToolTipValue((mat.ambient));
4783
- lightareaField.SetToolTipValue((mat.lightarea));
4784
- diffusenessField.SetToolTipValue((mat.factor));
4785
- velvetField.SetToolTipValue((mat.velvet));
4786
- sheenField.SetToolTipValue((mat.sheen));
4787
- subsurfaceField.SetToolTipValue((mat.subsurface));
4788
- backlitField.SetToolTipValue((mat.bump));
4789
- anisoField.SetToolTipValue((mat.aniso));
4790
- anisoVField.SetToolTipValue((mat.anisoV));
4791
- cameraField.SetToolTipValue((mat.cameralight));
4792
- selfshadowField.SetToolTipValue((mat.diffuseness));
4793
- shadowField.SetToolTipValue((mat.shadow));
4794
- textureField.SetToolTipValue((mat.texture));
4795
- opacityField.SetToolTipValue((mat.opacity));
4796
- fakedepthField.SetToolTipValue((mat.fakedepth));
4797
- shadowbiasField.SetToolTipValue((mat.shadowbias));
4860
+ if (!Equal(colorField.getFloat(), mat.color))
4861
+ colorField.SetToolTipValue((mat.color));
4862
+ if (!Equal(saturationField.getFloat(), mat.modulation))
4863
+ saturationField.SetToolTipValue((mat.modulation));
4864
+ if (!Equal(metalnessField.getFloat(), mat.metalness))
4865
+ metalnessField.SetToolTipValue((mat.metalness));
4866
+ if (!Equal(diffuseField.getFloat(), mat.diffuse))
4867
+ diffuseField.SetToolTipValue((mat.diffuse));
4868
+ if (!Equal(specularField.getFloat(), mat.specular))
4869
+ specularField.SetToolTipValue((mat.specular));
4870
+ if (!Equal(shininessField.getFloat(), mat.shininess))
4871
+ shininessField.SetToolTipValue((mat.shininess));
4872
+ if (!Equal(shiftField.getFloat(), mat.shift))
4873
+ shiftField.SetToolTipValue((mat.shift));
4874
+ if (!Equal(ambientField.getFloat(), mat.ambient))
4875
+ ambientField.SetToolTipValue((mat.ambient));
4876
+ if (!Equal(lightareaField.getFloat(), mat.lightarea))
4877
+ lightareaField.SetToolTipValue((mat.lightarea));
4878
+ if (!Equal(diffusenessField.getFloat(), mat.factor))
4879
+ diffusenessField.SetToolTipValue((mat.factor));
4880
+ if (!Equal(velvetField.getFloat(), mat.velvet))
4881
+ velvetField.SetToolTipValue((mat.velvet));
4882
+ if (!Equal(sheenField.getFloat(), mat.sheen))
4883
+ sheenField.SetToolTipValue((mat.sheen));
4884
+ if (!Equal(subsurfaceField.getFloat(), mat.subsurface))
4885
+ subsurfaceField.SetToolTipValue((mat.subsurface));
4886
+ if (!Equal(backlitField.getFloat(), mat.bump))
4887
+ backlitField.SetToolTipValue((mat.bump));
4888
+ if (!Equal(anisoField.getFloat(), mat.aniso))
4889
+ anisoField.SetToolTipValue((mat.aniso));
4890
+ if (!Equal(anisoVField.getFloat(), mat.anisoV))
4891
+ anisoVField.SetToolTipValue((mat.anisoV));
4892
+ if (!Equal(cameraField.getFloat(), mat.cameralight))
4893
+ cameraField.SetToolTipValue((mat.cameralight));
4894
+ if (!Equal(selfshadowField.getFloat(), mat.diffuseness))
4895
+ selfshadowField.SetToolTipValue((mat.diffuseness));
4896
+ if (!Equal(shadowField.getFloat(), mat.shadow))
4897
+ shadowField.SetToolTipValue((mat.shadow));
4898
+ if (!Equal(textureField.getFloat(), mat.texture))
4899
+ textureField.SetToolTipValue((mat.texture));
4900
+ if (!Equal(opacityField.getFloat(), mat.opacity))
4901
+ opacityField.SetToolTipValue((mat.opacity));
4902
+ if (!Equal(fakedepthField.getFloat(), mat.fakedepth))
4903
+ fakedepthField.SetToolTipValue((mat.fakedepth));
4904
+ if (!Equal(shadowbiasField.getFloat(), mat.shadowbias))
4905
+ shadowbiasField.SetToolTipValue((mat.shadowbias));
47984906 }
47994907
48004908 if (copy.material != null && copy.projectedVertices.length > 0 && copy.projectedVertices[0] != null)
....@@ -4829,7 +4937,7 @@
48294937
48304938 public void stateChanged(ChangeEvent e)
48314939 {
4832
- // assert(false);
4940
+ // assert(false);
48334941 if (e.getSource() == versionSlider)
48344942 {
48354943 if (muteSlider)
....@@ -5942,6 +6050,7 @@
59426050 boolean materialFlushed;
59436051 Object3D latestObject;
59446052
6053
+ cGridBag transformPanel;
59456054 cGridBag XYZPanel;
59466055
59476056 JSplitPane gridPanel;