From 0c85af6e46f48b7425d59fc776b193c06a4a1f52 Mon Sep 17 00:00:00 2001 From: Normand Briere <nbriere@noware.ca> Date: Sun, 04 Aug 2019 12:08:30 -0400 Subject: [PATCH] Material icons --- ObjEditor.java | 263 ++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 204 insertions(+), 59 deletions(-) diff --git a/ObjEditor.java b/ObjEditor.java index f27298a..4f2f437 100644 --- a/ObjEditor.java +++ b/ObjEditor.java @@ -41,11 +41,25 @@ JFrame frame; static ObjEditor theFrame; + + public cGridBag GetSeparator() + { + cGridBag separator = new cGridBag(); + separator.add(new JSeparator()); + separator.preferredHeight = 5; + return separator; + } cButton GetButton(String name, boolean border) { ImageIcon icon = GetIcon(name); return new cButton(icon, border); + } + + cLabel GetLabel(String name, boolean border) + { + //ImageIcon icon = GetIcon(name); + return new cLabel(GetImage(name), border); } cToggleButton GetToggleButton(String name, boolean border) @@ -80,6 +94,20 @@ javax.swing.ImageIcon icon = new javax.swing.ImageIcon(image); return icon; + } + catch (Exception e) + { + return null; + } + } + + BufferedImage GetImage(String name) + { + try + { + BufferedImage image = javax.imageio.ImageIO.read(getClass().getClassLoader().getResourceAsStream(name)); + + return image; } catch (Exception e) { @@ -268,9 +296,9 @@ client = inClient; copy = client; - if (copy.versions == null) + if (copy.versionlist == null) { - copy.versions = new byte[100][]; + copy.versionlist = new Object3D[100]; copy.versionindex = -1; } @@ -287,9 +315,9 @@ client = inClient; copy = client; - if (copy.versions == null) + if (copy.versionlist == null) { - copy.versions = new byte[100][]; + copy.versionlist = new Object3D[100]; copy.versionindex = -1; } @@ -325,7 +353,7 @@ copy = localCopy; copy.editWindow = this; - if (copy.versions == null) + if (copy.versionlist == null) { // copy.versions = new byte[100][]; // copy.versionindex = -1; @@ -439,7 +467,7 @@ toolboxPanel = new cGridBag().setVertical(true); //toolboxPanel.setName("Toolbox"); - materialPanel = new cGridBag().setVertical(true); + materialPanel = new cGridBag().setVertical(false); //materialPanel.setName("Material"); /*JTextPane*/ @@ -822,7 +850,7 @@ frame.validate(); } - private byte[] CompressCopy() + private Object3D CompressCopy() { boolean temp = CameraPane.SWITCH; CameraPane.SWITCH = false; @@ -830,12 +858,13 @@ copy.ExtractBigData(versiontable); // if (copy == client) - byte[] versions[] = copy.versions; - copy.versions = null; + Object3D versions[] = copy.versionlist; + copy.versionlist = null; - byte[] compress = Compress(copy); + //byte[] compress = Compress(copy); + Object3D compress = (Object3D)Grafreed.clone(copy); - copy.versions = versions; + copy.versionlist = versions; copy.RestoreBigData(versiontable); @@ -965,6 +994,7 @@ { SetupMaterial(materialPanel); } + //SetupName(); //SetupViews(); } @@ -1522,22 +1552,28 @@ //tmp.setName("Edit"); objectPanel.add(materialPanel); objectPanel.setIconAt(0, GetIcon("icons/material.png")); + objectPanel.setToolTipTextAt(0, "Material"); + // JPanel north = new JPanel(new BorderLayout()); // north.setName("Edit"); // north.add(ctrlPanel, BorderLayout.NORTH); // objectPanel.add(north); objectPanel.add(editPanel); objectPanel.setIconAt(1, GetIcon("icons/write.png")); + objectPanel.setToolTipTextAt(1, "Edit controls"); //if (Globals.ADVANCED) objectPanel.add(infoPanel); objectPanel.setIconAt(2, GetIcon("icons/info.png")); + objectPanel.setToolTipTextAt(2, "Information"); objectPanel.add(XYZPanel); objectPanel.setIconAt(3, GetIcon("icons/XYZ.png")); + objectPanel.setToolTipTextAt(3, "XYZ/RGB transform"); objectPanel.add(toolboxPanel); objectPanel.setIconAt(4, GetIcon("icons/primitives.png")); + objectPanel.setToolTipTextAt(4, "Objects & backgrounds"); /* aConstraints.gridx = 0; @@ -1634,8 +1670,8 @@ /**/ bigThree = new cGridBag(); - bigThree.addComponent(centralPanel); bigThree.addComponent(scenePanel); + bigThree.addComponent(centralPanel); //bigThree.addComponent(XYZPanel); // // SIDE EFFECT!!! @@ -1677,7 +1713,6 @@ frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { Close(); @@ -1700,12 +1735,56 @@ ctrlPanel.removeAll(); } - void SetupMaterial(cGridBag panel) + void SetupMaterial(cGridBag materialpanel) { - /* + cGridBag presetpanel = new cGridBag().setVertical(true); + cLabel label = GetLabel("icons/shadericons/shadericon00000.png", !Grafreed.NIMBUSLAF); + label.addMouseListener(new MouseAdapter() + { + public void mouseClicked(MouseEvent e) + { + colorField.setFloat(0); + saturationField.setFloat(1); + materialtouched = true; + applySelf(); + } + }); + presetpanel.add(label); + + presetpanel.add(GetLabel("icons/shadericons/shadericon00001.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00002.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00003.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00004.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00005.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00006.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00007.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00008.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00009.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00010.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00011.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00012.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00013.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00014.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00015.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00016.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00017.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00018.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00019.png", !Grafreed.NIMBUSLAF)); + presetpanel.add(GetLabel("icons/shadericons/shadericon00020.png", !Grafreed.NIMBUSLAF)); + + cGridBag panel = new cGridBag().setVertical(true); + + presetpanel.preferredWidth = 1; + + materialpanel.add(panel); + materialpanel.add(presetpanel); + + panel.preferredWidth = 8; + + /* ctrlPanel.add(materialLabel = new JLabel("MATERIAL : "), aConstraints); materialLabel.setHorizontalAlignment(SwingConstants.TRAILING); - */ + */ cGridBag editBar = new cGridBag().setVertical(false); @@ -1739,27 +1818,50 @@ //ctrlPanel.add(new JLabel("----------------------------------")); // , aConstraints); cGridBag colorSection = new cGridBag().setVertical(true); + + cGridBag huepanel = new cGridBag(); + cGridBag huelabel = new cGridBag(); + label = GetLabel("icons/hue.png", false); + label.fit = true; + huelabel.add(label); + huelabel.preferredWidth = 20; + huepanel.add(new cGridBag()); // Label + huepanel.add(huelabel); // Field/slider + + huepanel.preferredHeight = 7; + + colorSection.add(huepanel); cGridBag color = new cGridBag(); - color.add(colorLabel = new JLabel("Color/hue")); // , aConstraints); - colorLabel.setHorizontalAlignment(SwingConstants.TRAILING); - color.add(colorField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints); + + color.add(colorLabel = new JLabel("Color/hue")); // , aConstraints); + colorLabel.setHorizontalAlignment(SwingConstants.TRAILING); + color.add(colorField = new cNumberSlider(this, 0.001, 1)); // , aConstraints); + //colorField.preferredWidth = 200; colorSection.add(color); cGridBag modulation = new cGridBag(); modulation.add(modulationLabel = new JLabel("Saturation")); // , aConstraints); modulationLabel.setHorizontalAlignment(SwingConstants.TRAILING); - modulation.add(modulationField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints); + modulation.add(saturationField = new cNumberSlider(this, 0.001, 1)); // , aConstraints); colorSection.add(modulation); + cGridBag opacity = new cGridBag(); + opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints); + opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING); + opacity.add(opacityField = new cNumberSlider(this, 0.001, 1)); // , aConstraints); + colorSection.add(opacity); + + colorSection.add(GetSeparator()); + cGridBag texture = new cGridBag(); texture.add(textureLabel = new JLabel("Texture")); // , aConstraints); textureLabel.setHorizontalAlignment(SwingConstants.TRAILING); texture.add(textureField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints); colorSection.add(texture); - panel.add(new JSeparator()); + panel.add(GetSeparator()); panel.add(colorSection); @@ -1815,7 +1917,7 @@ shadowbias.add(shadowbiasField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints); diffuseSection.add(shadowbias); - panel.add(new JSeparator()); + panel.add(GetSeparator()); panel.add(diffuseSection); @@ -1878,7 +1980,7 @@ specularSection.add(anisoV); - panel.add(new JSeparator()); + panel.add(GetSeparator()); panel.add(specularSection); @@ -1903,12 +2005,6 @@ backlitLabel.setHorizontalAlignment(SwingConstants.TRAILING); backlit.add(backlitField = new cNumberSlider(this, 0.001, 50, -1)); // , aConstraints); colorSection.add(backlit); - - cGridBag opacity = new cGridBag(); - opacity.add(opacityLabel = new JLabel("Opacity")); // , aConstraints); - opacityLabel.setHorizontalAlignment(SwingConstants.TRAILING); - opacity.add(opacityField = new cNumberSlider(this, 0.001, 1, -0.5)); // , aConstraints); - colorSection.add(opacity); //panel.add(new JSeparator()); @@ -1954,7 +2050,7 @@ opacityPower.add(opacityPowerField = new cNumberSlider(this, 0.0, 10 /*10 dec 2013*/)); // , aConstraints); textureSection.add(opacityPower); - panel.add(new JSeparator()); + panel.add(GetSeparator()); panel.add(textureSection); @@ -2941,7 +3037,7 @@ freezematerial = true; colorField.setFloat(mat.color); - modulationField.setFloat(mat.modulation); + saturationField.setFloat(mat.modulation); metalnessField.setFloat(mat.metalness); diffuseField.setFloat(mat.diffuse); specularField.setFloat(mat.specular); @@ -3252,6 +3348,7 @@ } else if (event.getSource() == liveCB) { copy.live ^= true; + objEditor.refreshContents(true); // To show item colors return; } else if (event.getSource() == selectableCB) { @@ -3261,7 +3358,7 @@ { copy.hide ^= true; copy.Touch(); // display list issue - objEditor.refreshContents(); + objEditor.refreshContents(true); // To show item colors return; } else if (event.getSource() == link2masterCB) { @@ -3517,6 +3614,7 @@ static public byte[] Compress(Object3D o) { + // Slower to actually compress. try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -3618,6 +3716,7 @@ { //Save(true); Replace(); + SetUndoStates(); } private boolean Equal(byte[] compress, byte[] name) @@ -3641,18 +3740,18 @@ public boolean Save(boolean user) { System.err.println("Save"); + Replace(); cRadio tab = GetCurrentTab(); - byte[] compress = CompressCopy(); + Object3D compress = CompressCopy(); // Saved version. No need for "Replace". boolean thesame = false; - // Quick heuristic using length. Works only when stream is compressed. - if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1])) - { - thesame = true; - } +// if (copy.versionindex > 0 && copy.versions[copy.versionindex-1] != null && Equal(compress, copy.versions[copy.versionindex-1])) +// { +// thesame = true; +// } //EditorFrame.m_MainFrame.requestFocusInWindow(); if (!thesame) @@ -3660,7 +3759,7 @@ //tab.user[tab.versionindex] = user; //boolean increment = true; // tab.graphs[tab.versionindex] == null; - copy.versions[++copy.versionindex] = compress; + copy.versionlist[++copy.versionindex] = compress; // if (increment) // tab.versionindex++; @@ -3670,10 +3769,10 @@ //assert(hashtable.isEmpty()); - for (int i = copy.versionindex+1; i < copy.versions.length; i++) + for (int i = copy.versionindex+1; i < copy.versionlist.length; i++) { //tab.user[i] = false; - copy.versions[i] = null; + copy.versionlist[i] = null; } SetUndoStates(); @@ -3699,6 +3798,38 @@ return !thesame; } + + boolean flashIt = true; + + void RefreshSelection() + { + Object3D selection = new Object3D(); + + for (int i = 0; i < copy.selection.size(); i++) + { + Object3D elem = copy.selection.elementAt(i); + + Object3D obj = copy.GetObject(elem.GetUUID()); + + if (obj == null) + { + copy.selection.remove(i--); + } + else + { + selection.add(obj); + copy.selection.setElementAt(obj, i); + } + } + + flashIt = false; + GetTree().clearSelection(); + for (int i = 0; i < selection.size(); i++) + GetTree().addSelectionPath(selection.elementAt(i).GetTreePath().GetTreePath()); + flashIt = true; + + refreshContents(false); + } void CopyChanged(Object3D obj) { @@ -3711,6 +3842,9 @@ copy.clear(); + copy.skyboxname = obj.skyboxname; + copy.skyboxext = obj.skyboxext; + for (int i=0; i<obj.Size(); i++) { copy.add(obj.get(i)); @@ -3720,6 +3854,7 @@ CameraPane.SWITCH = temp; + RefreshSelection(); //assert(hashtable.isEmpty()); copy.Touch(); @@ -3754,9 +3889,9 @@ { int count = 0; - for (int i = copy.versions.length; --i >= 0;) + for (int i = copy.versionlist.length; --i >= 0;) { - if (copy.versions[i] != null) + if (copy.versionlist[i] != null) count++; } @@ -3771,7 +3906,7 @@ replaceButton.setEnabled(copy.versionindex != -1); undoButton.setEnabled(copy.versionindex > 0); - redoButton.setEnabled(copy.versions[copy.versionindex + 1] != null); + redoButton.setEnabled(copy.versionlist[copy.versionindex + 1] != null); muteSlider = true; versionSlider.setMaximum(VersionCount() - 1); @@ -3809,7 +3944,7 @@ copy.versionindex -= 1; - CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex])); + CopyChanged((Object3D)copy.versionlist[copy.versionindex]); return true; } @@ -3820,13 +3955,14 @@ cRadio tab = GetCurrentTab(); - if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null) + if (copy.versionindex == -1 || copy.versionlist[copy.versionindex] == null) { java.awt.Toolkit.getDefaultToolkit().beep(); return false; } - CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex])); + //CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex])); + CopyChanged(copy.versionlist[copy.versionindex]); return true; } @@ -3837,13 +3973,13 @@ cRadio tab = GetCurrentTab(); - if (copy.versionindex == -1 || copy.versions[copy.versionindex] == null) + if (copy.versionindex == -1 || copy.versionlist[copy.versionindex] == null) { // No version yet. OK. java.awt.Toolkit.getDefaultToolkit().beep(); return false; } - copy.versions[copy.versionindex] = CompressCopy(); + copy.versionlist[copy.versionindex] = CompressCopy(); return true; } @@ -3855,7 +3991,7 @@ cRadio tab = GetCurrentTab(); - if (copy.versions[copy.versionindex + 1] == null) + if (copy.versionlist[copy.versionindex + 1] == null) { java.awt.Toolkit.getDefaultToolkit().beep(); return; @@ -3863,7 +3999,7 @@ copy.versionindex += 1; - CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex])); + CopyChanged(copy.versionlist[copy.versionindex]); //if (!tab.user[tab.versionindex]) // tab.graphs[tab.versionindex] = null; @@ -4077,7 +4213,7 @@ //copy.material = new cMaterial(copy.GetMaterial()); current.color = (float) colorField.getFloat(); - current.modulation = (float) modulationField.getFloat(); + current.modulation = (float) saturationField.getFloat(); current.metalness = (float) metalnessField.getFloat(); current.diffuse = (float) diffuseField.getFloat(); current.specular = (float) specularField.getFloat(); @@ -4110,7 +4246,7 @@ cMaterial mat = copy.material; colorField.SetToolTipValue((mat.color)); - modulationField.SetToolTipValue((mat.modulation)); + saturationField.SetToolTipValue((mat.modulation)); metalnessField.SetToolTipValue((mat.metalness)); diffuseField.SetToolTipValue((mat.diffuse)); specularField.SetToolTipValue((mat.specular)); @@ -4174,9 +4310,9 @@ int version = versionSlider.getInteger(); - if (copy.versions[version] != null) + if (copy.versionlist[version] != null) { - CopyChanged((Object3D)Uncompress(copy.versions[copy.versionindex = version])); + CopyChanged(copy.versionlist[copy.versionindex = version]); } return; @@ -4216,6 +4352,12 @@ { //System.out.println("stateChanged = " + this); materialtouched = true; + + if (e.getSource() == colorField && saturationField.getFloat() == 0.001) + { + saturationField.setFloat(1); + } + applySelf(); //System.out.println("this = " + this); //System.out.println("PARENT = " + parent); @@ -4515,6 +4657,7 @@ { if (GetTree() != null) { + GetTree().revalidate(); GetTree().repaint(); } @@ -4853,6 +4996,8 @@ { //readobj.deepCopySelf(copy); copy.clear(); // june 2014 + copy.skyboxname = readobj.skyboxname; + copy.skyboxext = readobj.skyboxext; for (int i = 0; i < readobj.size(); i++) { Object3D child = readobj.get(i); // reserve(i); @@ -4904,12 +5049,12 @@ c.addChild(csg); } - copy.versions = readobj.versions; + copy.versionlist = readobj.versionlist; copy.versionindex = readobj.versionindex; - if (copy.versions == null) + if (copy.versionlist == null) { - copy.versions = new byte[100][]; + copy.versionlist = new Object3D[100]; copy.versionindex = -1; } @@ -5317,7 +5462,7 @@ JLabel colorLabel; cNumberSlider colorField; JLabel modulationLabel; - cNumberSlider modulationField; + cNumberSlider saturationField; JLabel metalnessLabel; cNumberSlider metalnessField; JLabel diffuseLabel; -- Gitblit v1.6.2