diff --git a/core/resources/datafiles/examples/Apocalypse with decals.ork b/core/resources/datafiles/examples/Apocalypse with decals.ork index 9150c47d8..0b215d31a 100644 Binary files a/core/resources/datafiles/examples/Apocalypse with decals.ork and b/core/resources/datafiles/examples/Apocalypse with decals.ork differ diff --git a/core/src/net/sf/openrocket/appearance/Appearance.java b/core/src/net/sf/openrocket/appearance/Appearance.java index 43ee54936..365c81037 100644 --- a/core/src/net/sf/openrocket/appearance/Appearance.java +++ b/core/src/net/sf/openrocket/appearance/Appearance.java @@ -9,42 +9,30 @@ import net.sf.openrocket.util.Color; * @author Bill Kuker */ public class Appearance { - public static final Appearance MISSING = new Appearance(new Color(0,0,0), new Color(128,128,128), new Color(255,255,255), 100, null); + public static final Appearance MISSING = new Appearance(new Color(0,0,0), 100, null); - private final Color ambient, diffuse, specular; - private final int shininess; + private final Color paint; + private final double shine; private final Decal texture; - Appearance(final Color ambient, final Color diffuse, final Color specular, final int shininess, final Decal texture){ - this.ambient = ambient; - this.diffuse = diffuse; - this.specular = specular; - this.shininess = shininess; + Appearance(final Color paint, final double shine, final Decal texture){ + this.paint = paint; + this.shine = shine; this.texture = texture; } - Appearance(final Color ambient, final Color diffuse, final Color specular, final int shininess){ - this.ambient = ambient; - this.diffuse = diffuse; - this.specular = specular; - this.shininess = shininess; + Appearance(final Color paint, final double shine){ + this.paint = paint; + this.shine = shine; this.texture = null; } - public Color getAmbient() { - return ambient; + public Color getPaint() { + return paint; } - public Color getDiffuse() { - return diffuse; - } - - public Color getSpecular() { - return specular; - } - - public int getShininess() { - return shininess; + public double getShine() { + return shine; } public Decal getTexture() { @@ -53,8 +41,8 @@ public class Appearance { @Override public String toString() { - return "Appearance [ambient=" + ambient + ", diffuse=" + diffuse + ", specular=" + specular + ", shininess=" - + shininess + ", texture=" + texture + "]"; + return "Appearance [paint=" + paint + ", shine=" + + shine + ", texture=" + texture + "]"; } } diff --git a/core/src/net/sf/openrocket/appearance/AppearanceBuilder.java b/core/src/net/sf/openrocket/appearance/AppearanceBuilder.java index cfb95f636..2fdea33d9 100644 --- a/core/src/net/sf/openrocket/appearance/AppearanceBuilder.java +++ b/core/src/net/sf/openrocket/appearance/AppearanceBuilder.java @@ -18,8 +18,8 @@ import net.sf.openrocket.util.Coordinate; */ public class AppearanceBuilder extends AbstractChangeSource { - private Color ambient, diffuse, specular; - private int shininess; + private Color paint; + private double shine; private double offsetU, offsetV; private double centerU, centerV; private double scaleU, scaleV; @@ -36,28 +36,23 @@ public class AppearanceBuilder extends AbstractChangeSource { public AppearanceBuilder(Appearance a) { resetToDefaults(); if ( a != null ){ - setAmbient(a.getAmbient()); - setDiffuse(a.getDiffuse()); - setSpecular(a.getSpecular()); - setShininess(a.getShininess()); + setPaint(a.getPaint()); + setShine(a.getShine()); Decal d = a.getTexture(); if ( d != null ){ setOffset(d.getOffset().x, d.getOffset().y); setCenter(d.getCenter().x, d.getCenter().y); - setScale(d.getScale().x, d.getScale().y); + setScaleUV(d.getScale().x, d.getScale().y); setRotation(d.getRotation()); setEdgeMode(d.getEdgeMode()); setImage(d.getImage()); } - // TODO Critical the rest of this! } } public void resetToDefaults() { - ambient = new Color(0, 0, 0); - diffuse = new Color(128, 128, 128); - specular = new Color(255, 255, 255); - shininess = 100; + paint = new Color(0, 0, 0); + shine = 0; offsetU = offsetV = 0; centerU = centerV = 0; scaleU = scaleV = 1; @@ -80,44 +75,26 @@ public class AppearanceBuilder extends AbstractChangeSource { edgeMode); } - return new Appearance( ambient, diffuse, specular, shininess, t); + return new Appearance( paint, shine, t); } - public Color getAmbient() { - return ambient; + public Color getPaint() { + return paint; } - public void setAmbient(Color ambient) { - this.ambient = ambient; + public void setPaint(Color paint) { + this.paint = paint; fireChangeEvent(); } - public Color getDiffuse() { - return diffuse; + public double getShine() { + return shine; } - public void setDiffuse(Color diffuse) { - this.diffuse = diffuse; - fireChangeEvent(); - } - - public Color getSpecular() { - return specular; - } - - public void setSpecular(Color specular) { - this.specular = specular; - fireChangeEvent(); - } - - public int getShininess() { - return shininess; - } - - public void setShininess(int shininess) { - this.shininess = shininess; + public void setShine(double shine) { + this.shine = shine; fireChangeEvent(); } @@ -185,10 +162,26 @@ public class AppearanceBuilder extends AbstractChangeSource { fireChangeEvent(); } - public void setScale(double u, double v) { + public void setScaleUV(double u, double v) { setScaleU(u); setScaleV(v); } + + public double getScaleX() { + return 1.0 / getScaleU(); + } + + public void setScaleX(double scaleU) { + setScaleU(1.0 / scaleU); + } + + public double getScaleY() { + return 1.0 / getScaleV(); + } + + public void setScaleY(double scaleV) { + setScaleV(1.0 / scaleV); + } public double getRotation() { return rotation; diff --git a/core/src/net/sf/openrocket/appearance/SimpleAppearanceBuilder.java b/core/src/net/sf/openrocket/appearance/SimpleAppearanceBuilder.java deleted file mode 100644 index 0575069d8..000000000 --- a/core/src/net/sf/openrocket/appearance/SimpleAppearanceBuilder.java +++ /dev/null @@ -1,77 +0,0 @@ -package net.sf.openrocket.appearance; - -import net.sf.openrocket.util.Color; - -public class SimpleAppearanceBuilder extends AppearanceBuilder { - - public SimpleAppearanceBuilder() { - super(); - } - - public SimpleAppearanceBuilder(Appearance a) { - super(a); - } - - public Color getColor() { - return getDiffuse(); - } - - public void setColor(final Color c) { - batch(new Runnable() { - @Override - public void run() { - setAmbient(c); - setDiffuse(c); - } - }); - } - - public void setShine(final int s) { - batch(new Runnable() { - @Override - public void run() { - setShininess(s); - int c = (int) (s * 2.55); - setSpecular(new net.sf.openrocket.util.Color(c, c, c)); - } - }); - } - - public int getShine() { - return getShininess(); - } - - private Color oldColor = null; - - @Override - public void setImage(final String image) { - batch(new Runnable() { - @Override - public void run() { - if (getImage() == null && image != null) { - oldColor = getColor(); - setColor(new Color(255, 255, 255)); - } else if (getImage() != null && image == null && oldColor != null) { - setColor(oldColor); - } - SimpleAppearanceBuilder.super.setImage(image); - } - }); - } - - public double getScaleX() { - return 1.0 / super.getScaleU(); - } - - public void setScaleX(double scaleU) { - super.setScaleU(1.0 / scaleU); - } - - public double getScaleY() { - return 1.0 / super.getScaleV(); - } - - public void setScaleY(double scaleV) { - super.setScaleV(1.0 / scaleV); - } -} diff --git a/core/src/net/sf/openrocket/file/openrocket/importt/AppearanceHandler.java b/core/src/net/sf/openrocket/file/openrocket/importt/AppearanceHandler.java index caaa561d3..ae25b8dc2 100644 --- a/core/src/net/sf/openrocket/file/openrocket/importt/AppearanceHandler.java +++ b/core/src/net/sf/openrocket/file/openrocket/importt/AppearanceHandler.java @@ -42,25 +42,16 @@ class AppearanceHandler extends AbstractElementHandler { } @Override public void closeElement(String element,HashMap attributes, String content, WarningSet warnings) throws SAXException { - if ( "ambient".equals(element) ) { + if ( "paint".equals(element) ) { int red = Integer.parseInt(attributes.get("red")); int green = Integer.parseInt(attributes.get("green")); int blue = Integer.parseInt(attributes.get("blue")); - builder.setAmbient( new Color(red,green,blue)); + builder.setPaint( new Color(red,green,blue)); return; } - if ( "diffuse".equals(element) ) { - int red = Integer.parseInt(attributes.get("red")); - int green = Integer.parseInt(attributes.get("green")); - int blue = Integer.parseInt(attributes.get("blue")); - builder.setDiffuse( new Color(red,green,blue)); - return; - } - if ( "specular".equals(element) ) { - int red = Integer.parseInt(attributes.get("red")); - int green = Integer.parseInt(attributes.get("green")); - int blue = Integer.parseInt(attributes.get("blue")); - builder.setSpecular( new Color(red,green,blue)); + if ( "shine".equals(element) ){ + double shine = Double.parseDouble(content); + builder.setShine(shine); return; } if ( isInDecal && "center".equals(element) ) { @@ -78,7 +69,7 @@ class AppearanceHandler extends AbstractElementHandler { if ( isInDecal && "scale".equals(element) ) { double x = Double.parseDouble(attributes.get("x")); double y = Double.parseDouble(attributes.get("y")); - builder.setScale(x,y); + builder.setScaleUV(x,y); return; } if( isInDecal && "decal".equals(element) ) { diff --git a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java index 6429fe3da..56405a4ed 100644 --- a/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java +++ b/core/src/net/sf/openrocket/file/openrocket/savers/RocketComponentSaver.java @@ -45,12 +45,9 @@ public class RocketComponentSaver { Appearance ap = c.getAppearance(); if ( ap != null ) { elements.add(""); - Color ambient = ap.getAmbient(); - emitColor("ambient",elements,ambient); - Color diffuse = ap.getDiffuse(); - emitColor("diffuse",elements,diffuse); - Color specular = ap.getSpecular(); - emitColor("specular",elements,specular); + Color paint = ap.getPaint(); + emitColor("paint",elements,paint); + elements.add("" + ap.getShine() + ""); Decal decal = ap.getTexture(); if ( decal != null ) { String name = decal.getImage(); diff --git a/core/src/net/sf/openrocket/file/rocksim/importt/RockSimAppearanceBuilder.java b/core/src/net/sf/openrocket/file/rocksim/importt/RockSimAppearanceBuilder.java index 397e63750..abf584eeb 100644 --- a/core/src/net/sf/openrocket/file/rocksim/importt/RockSimAppearanceBuilder.java +++ b/core/src/net/sf/openrocket/file/rocksim/importt/RockSimAppearanceBuilder.java @@ -5,55 +5,35 @@ import java.io.FileNotFoundException; import java.net.MalformedURLException; import net.sf.openrocket.aerodynamics.WarningSet; -import net.sf.openrocket.appearance.Appearance; import net.sf.openrocket.appearance.AppearanceBuilder; import net.sf.openrocket.appearance.Decal.EdgeMode; import net.sf.openrocket.file.rocksim.RocksimCommonConstants; import net.sf.openrocket.util.Color; public class RockSimAppearanceBuilder extends AppearanceBuilder { - private double specularW = 1, ambientW = 1, diffuseW = 1; - private boolean oneColor; + boolean preventSeam = false; boolean repeat = false; - @Override - public Appearance getAppearance() { - if (oneColor) { - setDiffuse(weight(getDiffuse(), diffuseW)); - setAmbient(weight(getDiffuse(), diffuseW)); - setSpecular(weight(getDiffuse(), diffuseW)); - } else { - setDiffuse(weight(getDiffuse(), diffuseW)); - setAmbient(weight(getAmbient(), ambientW)); - setSpecular(weight(getSpecular(), specularW)); - } - - - - return super.getAppearance(); - } public void processElement(String element, String content, WarningSet warnings) { try { if (RocksimCommonConstants.TEXTURE.equals(element)) { parseTexture(content); } else if ("Ambient".equals(element)) { - ambientW = Double.parseDouble(content); + //ignored } else if ("Diffuse".equals(element)) { - diffuseW = Double.parseDouble(content); + //ignored } else if ("Specular".equals(element)) { - specularW = Double.parseDouble(content); + //ignored } else if ("AbientColor".equals(element)) { - setAmbient(parseColor(content)); + setPaint(parseColor(content)); } else if ("DiffuseColor".equals(element)) { - setDiffuse(parseColor(content)); + //ignored } else if ("SpecularColor".equals(element)) { - setSpecular(parseColor(content)); + //Ignored } else if ("UseSingleColor".equals(element) || "SimpleColorModel".equals(element) ) { - if ("1".equals(content)) { - oneColor = true; - } + //Ignored } } catch (Exception e) { warnings.add("Could not convert " + element + " value of " + content + ": " + e.getMessage()); @@ -104,7 +84,7 @@ public class RockSimAppearanceBuilder extends AppearanceBuilder { setCenter(Double.parseDouble(c[0]), Double.parseDouble(c[1])); } else if ("scale".equals(name)) { String[] c = value.split(","); - setScale(Double.parseDouble(c[0]), Double.parseDouble(c[1])); + setScaleUV(Double.parseDouble(c[0]), Double.parseDouble(c[1])); } } @@ -117,11 +97,11 @@ public class RockSimAppearanceBuilder extends AppearanceBuilder { } if ( !flips ){ - setScale(getScaleU(), getScaleV() * -1); + setScaleUV(getScaleU(), getScaleV() * -1); setOffset(getOffsetU(), -1 - getOffsetV()); } if ( !flipr ){ - setScale(getScaleU() * -1, getScaleV()); + setScaleUV(getScaleU() * -1, getScaleV()); setOffset(-1 - getOffsetU(), getOffsetV()); } diff --git a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java index ffc989835..5cb71a5bc 100644 --- a/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java +++ b/core/src/net/sf/openrocket/gui/configdialog/AppearancePanel.java @@ -21,15 +21,14 @@ import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import net.miginfocom.swing.MigLayout; +import net.sf.openrocket.appearance.AppearanceBuilder; import net.sf.openrocket.appearance.Decal.EdgeMode; -import net.sf.openrocket.appearance.SimpleAppearanceBuilder; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.gui.SpinnerEditor; import net.sf.openrocket.gui.adaptors.BooleanModel; import net.sf.openrocket.gui.adaptors.DecalModel; import net.sf.openrocket.gui.adaptors.DoubleModel; import net.sf.openrocket.gui.adaptors.EnumModel; -import net.sf.openrocket.gui.adaptors.IntegerModel; import net.sf.openrocket.gui.components.BasicSlider; import net.sf.openrocket.gui.components.ColorIcon; import net.sf.openrocket.gui.components.StyledLabel; @@ -51,7 +50,7 @@ import net.sf.openrocket.util.StateChangeListener; public class AppearancePanel extends JPanel { private static final Translator trans = Application.getTranslator(); - private SimpleAppearanceBuilder ab; + private AppearanceBuilder ab; /** * A non-unit that adjusts by a small amount, suitable for @@ -117,7 +116,7 @@ public class AppearancePanel extends JPanel { public AppearancePanel(final OpenRocketDocument document, final RocketComponent c) { super(new MigLayout("fill", "[150][grow][150][grow]")); - ab = new SimpleAppearanceBuilder(c.getAppearance()); + ab = new AppearanceBuilder(c.getAppearance()); net.sf.openrocket.util.Color figureColor = c.getColor(); if (figureColor == null) { @@ -125,7 +124,7 @@ public class AppearancePanel extends JPanel { } final JButton figureColorButton = new JButton(new ColorIcon(figureColor)); - final JButton colorButton = new JButton(new ColorIcon(ab.getColor())); + final JButton colorButton = new JButton(new ColorIcon(ab.getPaint())); final JComboBox textureDropDown = new JComboBox( new DecalModel(this,document,ab));; @@ -133,7 +132,7 @@ public class AppearancePanel extends JPanel { @Override public void stateChanged(EventObject e) { figureColorButton.setIcon(new ColorIcon(c.getColor())); - colorButton.setIcon(new ColorIcon(ab.getColor())); + colorButton.setIcon(new ColorIcon(ab.getPaint())); c.setAppearance(ab.getAppearance()); } }); @@ -150,7 +149,7 @@ public class AppearancePanel extends JPanel { }); figureColorButton.addActionListener(new ColorActionListener(c, "Color")); - colorButton.addActionListener(new ColorActionListener(ab, "Color")); + colorButton.addActionListener(new ColorActionListener(ab, "Paint")); BooleanModel fDefault = new BooleanModel(c.getColor() == null); @@ -276,11 +275,14 @@ public class AppearancePanel extends JPanel { {// Shine add(new JLabel(trans.get("AppearanceCfg.lbl.shine"))); - IntegerModel shineModel = new IntegerModel(ab, "Shine", 0, 100); + DoubleModel shineModel = new DoubleModel(ab, "Shine", UnitGroup.UNITS_RELATIVE); JSpinner spin = new JSpinner(shineModel.getSpinnerModel()); - JSlider slide = new JSlider(shineModel.getSliderModel()); + spin.setEditor(new SpinnerEditor(spin)); + JSlider slide = new JSlider(shineModel.getSliderModel(0, 1)); + UnitSelector unit = new UnitSelector(shineModel); - add(spin, "split 2, w 50"); + add(spin, "split 3, w 50"); + add(unit, "growx"); add(slide, "w 50"); } diff --git a/core/src/net/sf/openrocket/gui/figure3d/RealisticRenderStrategy.java b/core/src/net/sf/openrocket/gui/figure3d/RealisticRenderStrategy.java index 02652288a..5be92c5e2 100644 --- a/core/src/net/sf/openrocket/gui/figure3d/RealisticRenderStrategy.java +++ b/core/src/net/sf/openrocket/gui/figure3d/RealisticRenderStrategy.java @@ -108,20 +108,21 @@ public class RealisticRenderStrategy extends RenderStrategy { gl.glLightModeli(GL2.GL_LIGHT_MODEL_COLOR_CONTROL,GL2.GL_SEPARATE_SPECULAR_COLOR); - convertColor(a.getDiffuse(), color); - color[3] = alpha; + if ( a.getTexture() != null ){ + color[0] = color[1] = color[2] = 1; + } else { + convertColor(a.getPaint(), color); + color[3] = alpha; + } gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_DIFFUSE, color, 0); gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_DIFFUSE, color, 0); - - convertColor(a.getAmbient(), color); - color[3] = alpha; gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT, color, 0); gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_AMBIENT, color, 0); - convertColor(a.getSpecular(), color); + color[0] = color[1] = color[2] = (float)a.getShine(); color[3] = alpha; gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SPECULAR, color, 0); - gl.glMateriali(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, a.getShininess()); + gl.glMateriali(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, (int)(100 * a.getShine())); gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_SPECULAR, colorBlack, 0); gl.glMateriali(GL.GL_BACK, GLLightingFunc.GL_SHININESS, 0);