Simplified appearance. Is this really what we want?

This commit is contained in:
bkuker 2013-01-03 09:19:58 -05:00
parent 98db1885c2
commit cbb78cf095
8 changed files with 77 additions and 210 deletions

View File

@ -9,42 +9,30 @@ import net.sf.openrocket.util.Color;
* @author Bill Kuker <bkuker@billkuker.com>
*/
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 int 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 int 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 int 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 int 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 + "]";
}
}

View File

@ -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 int shine;
private double offsetU, offsetV;
private double centerU, centerV;
private double scaleU, scaleV;
@ -36,15 +36,12 @@ 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());
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());
@ -54,10 +51,8 @@ public class AppearanceBuilder extends AbstractChangeSource {
}
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 int 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(int 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;

View File

@ -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);
}
}

View File

@ -42,25 +42,11 @@ class AppearanceHandler extends AbstractElementHandler {
}
@Override
public void closeElement(String element,HashMap<String, String> 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));
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));
builder.setPaint( new Color(red,green,blue));
return;
}
if ( isInDecal && "center".equals(element) ) {
@ -78,7 +64,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) ) {

View File

@ -45,12 +45,8 @@ public class RocketComponentSaver {
Appearance ap = c.getAppearance();
if ( ap != null ) {
elements.add("<appearance>");
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);
Decal decal = ap.getTexture();
if ( decal != null ) {
String name = decal.getImage();

View File

@ -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());
}

View File

@ -22,7 +22,7 @@ import javax.swing.SwingUtilities;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.appearance.Decal.EdgeMode;
import net.sf.openrocket.appearance.SimpleAppearanceBuilder;
import net.sf.openrocket.appearance.AppearanceBuilder;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.gui.SpinnerEditor;
import net.sf.openrocket.gui.adaptors.BooleanModel;
@ -51,7 +51,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 +117,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 +125,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 +133,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 +150,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);

View File

@ -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] = (int)(a.getShine()*2.55);
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, a.getShine());
gl.glMaterialfv(GL.GL_BACK, GLLightingFunc.GL_SPECULAR, colorBlack, 0);
gl.glMateriali(GL.GL_BACK, GLLightingFunc.GL_SHININESS, 0);