Initial tube & balsa default appearances

This commit is contained in:
bkuker 2013-01-09 14:42:38 -05:00
parent 88e87d5925
commit 8dd0a6abc1
9 changed files with 120 additions and 16 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1023 B

View File

@ -16,13 +16,13 @@ public class Appearance {
private final double shine;
private final Decal texture;
Appearance(final Color paint, final double shine, final Decal texture) {
public Appearance(final Color paint, final double shine, final Decal texture) {
this.paint = paint;
this.shine = MathUtil.clamp(shine, 0, 1);
this.texture = texture;
}
Appearance(final Color paint, final double shine) {
public Appearance(final Color paint, final double shine) {
this.paint = paint;
this.shine = MathUtil.clamp(shine, 0, 1);
this.texture = null;

View File

@ -9,25 +9,27 @@ import net.sf.openrocket.util.Coordinate;
* @author Bill Kuker <bkuker@billkuker.com>
*/
public class Decal {
public static enum EdgeMode {
REPEAT("TextureWrap.Repeat"), MIRROR("TextureWrap.Mirror"), CLAMP("TextureWrap.Clamp"), STICKER("TextureWrap.Sticker");
private final String transName;
EdgeMode(final String name){
EdgeMode(final String name) {
this.transName = name;
}
@Override
public String toString(){
public String toString() {
return Application.getTranslator().get(transName);
}
}
private final Coordinate offset, center, scale;
private final double rotation;
private final DecalImage image;
private final EdgeMode mode;
Decal(final Coordinate offset, final Coordinate center, final Coordinate scale, final double rotation,
public Decal(final Coordinate offset, final Coordinate center, final Coordinate scale, final double rotation,
final DecalImage image, final EdgeMode mode) {
this.offset = offset;
this.center = center;
@ -36,35 +38,35 @@ public class Decal {
this.image = image;
this.mode = mode;
}
public Coordinate getOffset() {
return offset;
}
public Coordinate getCenter() {
return center;
}
public Coordinate getScale() {
return scale;
}
public double getRotation() {
return rotation;
}
public EdgeMode getEdgeMode() {
return mode;
}
public DecalImage getImage() {
return image;
}
@Override
public String toString() {
return "Texture [offset=" + offset + ", center=" + center + ", scale=" + scale + ", rotation=" + rotation
+ ", image=" + image + "]";
}
}

View File

@ -0,0 +1,23 @@
package net.sf.openrocket.appearance.defaults;
import net.sf.openrocket.appearance.Appearance;
import net.sf.openrocket.appearance.Decal;
import net.sf.openrocket.appearance.Decal.EdgeMode;
import net.sf.openrocket.util.Color;
import net.sf.openrocket.util.Coordinate;
class Balsa extends Appearance {
public static final Balsa INSTANCE = new Balsa();
private Balsa() {
super(
new Color(1, 1, 1),
0,
new Decal(
new Coordinate(0, 0),
new Coordinate(0, 0),
new Coordinate(1, 1),
0,
new ResourceDecalImage("/datafiles/textures/balsa.png"), EdgeMode.REPEAT));
}
}

View File

@ -0,0 +1,19 @@
package net.sf.openrocket.appearance.defaults;
import net.sf.openrocket.appearance.Appearance;
import net.sf.openrocket.rocketcomponent.BodyTube;
import net.sf.openrocket.rocketcomponent.FinSet;
import net.sf.openrocket.rocketcomponent.LaunchLug;
import net.sf.openrocket.rocketcomponent.RocketComponent;
public class DefaultAppearance {
public static Appearance getDefaultAppearance(RocketComponent c) {
if (c instanceof BodyTube)
return SpiralWound.ESTES_BT;
if (c instanceof FinSet)
return Balsa.INSTANCE;
if (c instanceof LaunchLug)
return SpiralWound.WHITE;
return Appearance.MISSING;
}
}

View File

@ -0,0 +1,32 @@
package net.sf.openrocket.appearance.defaults;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import net.sf.openrocket.appearance.DecalImage;
class ResourceDecalImage implements DecalImage {
final String resource;
ResourceDecalImage(final String resource) {
this.resource = resource;
}
@Override
public String getName() {
return resource;
}
@Override
public InputStream getBytes() throws FileNotFoundException, IOException {
return this.getClass().getResourceAsStream(resource);
}
@Override
public void exportImage(File file, boolean watchForChanges) throws IOException {
}
}

View File

@ -0,0 +1,27 @@
package net.sf.openrocket.appearance.defaults;
import net.sf.openrocket.appearance.Appearance;
import net.sf.openrocket.appearance.Decal;
import net.sf.openrocket.appearance.Decal.EdgeMode;
import net.sf.openrocket.util.Color;
import net.sf.openrocket.util.Coordinate;
class SpiralWound extends Appearance {
public static final SpiralWound ESTES_BT = new SpiralWound(new Color(212, 185, 145), .3, 45);
public static final SpiralWound BLUE = new SpiralWound(new Color(212, 185, 145), .3, 45);
public static final SpiralWound WHITE = new SpiralWound(new Color(240, 240, 240), .3, 45);
public SpiralWound(Color paint, double shine, double angle) {
super(
paint,
shine,
new Decal(
new Coordinate(0, 0),
new Coordinate(0, 0),
new Coordinate(1, 1),
0,
new ResourceDecalImage("/datafiles/textures/spiral-wound-alpha.png"), EdgeMode.REPEAT));
}
}

View File

@ -14,6 +14,7 @@ import javax.media.opengl.fixedfunc.GLMatrixFunc;
import net.sf.openrocket.appearance.Appearance;
import net.sf.openrocket.appearance.Decal;
import net.sf.openrocket.appearance.defaults.DefaultAppearance;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.util.Color;
@ -216,7 +217,7 @@ public class RealisticRenderer extends RocketRenderer {
private Appearance getAppearance(RocketComponent c) {
Appearance ret = c.getAppearance();
if (ret == null) {
ret = Appearance.MISSING;
ret = DefaultAppearance.getDefaultAppearance(c);
}
return ret;
}