[fixes #969] Added custom left and right side appearance fins

This commit is contained in:
Sibo Van Gool 2021-07-01 20:04:46 +02:00 committed by Sibo Van Gool
parent 9eea6edfe4
commit 354c05fa60
6 changed files with 144 additions and 60 deletions

View File

@ -810,9 +810,13 @@ AppearanceCfg.lbl.texture.center = Center:
AppearanceCfg.lbl.texture.rotation = Rotation: AppearanceCfg.lbl.texture.rotation = Rotation:
AppearanceCfg.lbl.texture.repeat = Repeat: AppearanceCfg.lbl.texture.repeat = Repeat:
AppearanceCfg.lbl.InsideSameAsOutside = Same as outside AppearanceCfg.lbl.InsideSameAsOutside = Same as outside
AppearanceCfg.lbl.LeftSideSameAsRightSide = Same as right side
AppearanceCfg.lbl.ttip.InsideSameAsOutside = Use the same appearance for the inside as for the outside AppearanceCfg.lbl.ttip.InsideSameAsOutside = Use the same appearance for the inside as for the outside
AppearanceCfg.lbl.ttip.LeftSideSameAsRightSide = Use the same appearance for the left side as for the right side
AppearanceCfg.lbl.EdgesSameAsInside = Use inside appearance for edges AppearanceCfg.lbl.EdgesSameAsInside = Use inside appearance for edges
AppearanceCfg.lbl.EdgesSameAsLeftSide = Use left side appearance for edges
AppearanceCfg.lbl.ttip.EdgesSameAsInside = Use the inside appearance (checked) or outside appearance (unchecked) for the edges AppearanceCfg.lbl.ttip.EdgesSameAsInside = Use the inside appearance (checked) or outside appearance (unchecked) for the edges
AppearanceCfg.lbl.ttip.EdgesSameAsLeftSide = Use the left side appearance (checked) or right side appearance (unchecked) for the edges
! Texture Wrap Modes ! Texture Wrap Modes
TextureWrap.Repeat = Repeat TextureWrap.Repeat = Repeat
@ -878,6 +882,8 @@ RocketCompCfg.lbl.InstanceCount = Instance Count
RocketCompCfg.lbl.InstanceSeparation = Instance Separation RocketCompCfg.lbl.InstanceSeparation = Instance Separation
RocketCompCfg.tab.Outside = Outside RocketCompCfg.tab.Outside = Outside
RocketCompCfg.tab.Inside = Inside RocketCompCfg.tab.Inside = Inside
RocketCompCfg.tab.RightSide = Right Side
RocketCompCfg.tab.LeftSide = Left Side
! BulkheadConfig ! BulkheadConfig
BulkheadCfg.tab.Diameter = Diameter: BulkheadCfg.tab.Diameter = Diameter:

View File

@ -1,12 +1,13 @@
package net.sf.openrocket.rocketcomponent; package net.sf.openrocket.rocketcomponent;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.util.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import net.sf.openrocket.appearance.Appearance;
import net.sf.openrocket.appearance.Decal;
import net.sf.openrocket.util.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -18,15 +19,10 @@ import net.sf.openrocket.rocketcomponent.position.AxialMethod;
import net.sf.openrocket.rocketcomponent.position.AxialPositionable; import net.sf.openrocket.rocketcomponent.position.AxialPositionable;
import net.sf.openrocket.rocketcomponent.position.RadiusMethod; import net.sf.openrocket.rocketcomponent.position.RadiusMethod;
import net.sf.openrocket.startup.Application; import net.sf.openrocket.startup.Application;
import net.sf.openrocket.util.BoundingBox;
import net.sf.openrocket.rocketcomponent.Transition.Shape; import net.sf.openrocket.rocketcomponent.Transition.Shape;
import net.sf.openrocket.util.Coordinate; public abstract class FinSet extends ExternalComponent implements AxialPositionable, BoxBounded, RingInstanceable, InsideColorComponent {
import net.sf.openrocket.util.MathUtil;
import net.sf.openrocket.util.Transformation;
public abstract class FinSet extends ExternalComponent implements AxialPositionable, BoxBounded, RingInstanceable {
private static final Logger log = LoggerFactory.getLogger(FinSet.class); private static final Logger log = LoggerFactory.getLogger(FinSet.class);
private static final Translator trans = Application.getTranslator(); private static final Translator trans = Application.getTranslator();
@ -125,6 +121,11 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona
private double singlePlanformArea = Double.NaN; private double singlePlanformArea = Double.NaN;
private double totalVolume = Double.NaN; private double totalVolume = Double.NaN;
private Coordinate centerOfMass = Coordinate.NaN; private Coordinate centerOfMass = Coordinate.NaN;
// Settings for inside/edge appearance
private Appearance insideAppearance = null;
private boolean insideSameAsOutside = true;
private boolean edgesSameAsInside = true;
/** /**
* New FinSet with given number of fins and given base rotation angle. * New FinSet with given number of fins and given base rotation angle.
@ -1269,4 +1270,49 @@ public abstract class FinSet extends ExternalComponent implements AxialPositiona
return toReturn; return toReturn;
} }
@Override
public Appearance getInsideAppearance() {
return this.insideAppearance;
}
@Override
public void setInsideAppearance(Appearance appearance) {
this.insideAppearance = appearance;
if (this.insideAppearance != null) {
Decal d = this.insideAppearance.getTexture();
if (d != null) {
d.getImage().addChangeListener(new StateChangeListener() {
@Override
public void stateChanged(EventObject e) {
fireComponentChangeEvent(ComponentChangeEvent.TEXTURE_CHANGE);
}
});
}
}
// CHECK - should this be a TEXTURE_CHANGE and not NONFUNCTIONAL_CHANGE?
fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE);
}
@Override
public boolean isEdgesSameAsInside() {
return this.edgesSameAsInside;
}
@Override
public void setEdgesSameAsInside(boolean newState) {
this.edgesSameAsInside = newState;
}
@Override
public boolean isInsideSameAsOutside() {
return this.insideSameAsOutside;
}
@Override
public void setInsideSameAsOutside(boolean newState) {
this.insideSameAsOutside = newState;
}
} }

View File

@ -34,6 +34,7 @@ import net.sf.openrocket.gui.util.EditDecalHelper.EditDecalHelperException;
import net.sf.openrocket.gui.util.SwingPreferences; import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator; import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.rocketcomponent.ComponentChangeEvent; import net.sf.openrocket.rocketcomponent.ComponentChangeEvent;
import net.sf.openrocket.rocketcomponent.FinSet;
import net.sf.openrocket.rocketcomponent.InsideColorComponent; import net.sf.openrocket.rocketcomponent.InsideColorComponent;
import net.sf.openrocket.rocketcomponent.InsideColorComponentHandler; import net.sf.openrocket.rocketcomponent.InsideColorComponentHandler;
import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.rocketcomponent.RocketComponent;
@ -309,17 +310,32 @@ public class AppearancePanel extends JPanel {
appearanceSection(document, c, false, outsidePanel); appearanceSection(document, c, false, outsidePanel);
appearanceSection(document, c, true, insidePanel); appearanceSection(document, c, true, insidePanel);
tabbedPane.addTab(trans.get("RocketCompCfg.tab.Outside"), null, outsidePanel, // Get translator keys
String tr_outside, tr_inside, tr_edges, tr_edges_ttip;
if (c instanceof FinSet) {
tr_outside = "RocketCompCfg.tab.RightSide";
tr_inside = "RocketCompCfg.tab.LeftSide";
tr_edges = "AppearanceCfg.lbl.EdgesSameAsLeftSide";
tr_edges_ttip = "AppearanceCfg.lbl.ttip.EdgesSameAsLeftSide";
}
else {
tr_outside = "RocketCompCfg.tab.Outside";
tr_inside = "RocketCompCfg.tab.Inside";
tr_edges = "AppearanceCfg.lbl.EdgesSameAsInside";
tr_edges_ttip = "AppearanceCfg.lbl.ttip.EdgesSameAsInside";
}
tabbedPane.addTab(trans.get(tr_outside), null, outsidePanel,
"Outside Tool Tip"); "Outside Tool Tip");
tabbedPane.addTab(trans.get("RocketCompCfg.tab.Inside"), null, insidePanel, tabbedPane.addTab(trans.get(tr_inside), null, insidePanel,
"Inside Tool Tip"); "Inside Tool Tip");
add(tabbedPane, "span 4, growx, wrap"); add(tabbedPane, "span 4, growx, wrap");
// Checkbox to set edges the same as inside/outside // Checkbox to set edges the same as inside/outside
BooleanModel b = new BooleanModel(handler.isEdgesSameAsInside()); BooleanModel b = new BooleanModel(handler.isEdgesSameAsInside());
JCheckBox edges = new JCheckBox(b); JCheckBox edges = new JCheckBox(b);
edges.setText(trans.get("AppearanceCfg.lbl.EdgesSameAsInside")); edges.setText(trans.get(tr_edges));
edges.setToolTipText(trans.get("AppearanceCfg.lbl.ttip.EdgesSameAsInside")); edges.setToolTipText(trans.get(tr_edges_ttip));
add(edges, "wrap"); add(edges, "wrap");
edges.addActionListener(new ActionListener() { edges.addActionListener(new ActionListener() {
@ -406,13 +422,24 @@ public class AppearancePanel extends JPanel {
else else
panel.add(materialDefault, "wrap"); panel.add(materialDefault, "wrap");
// Get translation keys
String tr_insideOutside, tr_insideOutside_ttip;
if (c instanceof FinSet) {
tr_insideOutside = "AppearanceCfg.lbl.LeftSideSameAsRightSide";
tr_insideOutside_ttip = "AppearanceCfg.lbl.ttip.LeftSideSameAsRightSide";
}
else {
tr_insideOutside = "AppearanceCfg.lbl.InsideSameAsOutside";
tr_insideOutside_ttip = "AppearanceCfg.lbl.ttip.InsideSameAsOutside";
}
// Custom inside color // Custom inside color
if (insideBuilder) { if (insideBuilder) {
InsideColorComponentHandler handler = ((InsideColorComponent)c).getInsideColorComponentHandler(); InsideColorComponentHandler handler = ((InsideColorComponent)c).getInsideColorComponentHandler();
BooleanModel b = new BooleanModel(handler.isInsideSameAsOutside()); BooleanModel b = new BooleanModel(handler.isInsideSameAsOutside());
JCheckBox customInside = new JCheckBox(b); JCheckBox customInside = new JCheckBox(b);
customInside.setText(trans.get("AppearanceCfg.lbl.InsideSameAsOutside")); customInside.setText(trans.get(tr_insideOutside));
customInside.setToolTipText(trans.get("AppearanceCfg.lbl.ttip.InsideSameAsOutside")); customInside.setToolTipText(trans.get(tr_insideOutside_ttip));
customInside.addActionListener(new ActionListener() { customInside.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {

View File

@ -99,13 +99,13 @@ public class RealisticRenderer extends RocketRenderer {
render(gl, geom, Surface.INSIDE, innerApp, true, alpha); render(gl, geom, Surface.INSIDE, innerApp, true, alpha);
if (((InsideColorComponent) c).getInsideColorComponentHandler().isEdgesSameAsInside()) if (((InsideColorComponent) c).getInsideColorComponentHandler().isEdgesSameAsInside())
render(gl, geom, Surface.EDGES, innerApp, false, alpha); render(gl, geom, Surface.EDGES, innerApp, true, alpha);
else else
render(gl, geom, Surface.EDGES, app, false, alpha); render(gl, geom, Surface.EDGES, app, true, alpha);
} }
else { else {
render(gl, geom, Surface.INSIDE, app, true, alpha); render(gl, geom, Surface.INSIDE, app, true, alpha);
render(gl, geom, Surface.EDGES, app, false, alpha); render(gl, geom, Surface.EDGES, app, true, alpha);
} }
render(gl, geom, Surface.OUTSIDE, app, true, alpha); render(gl, geom, Surface.OUTSIDE, app, true, alpha);

View File

@ -112,9 +112,7 @@ public class ComponentRenderer {
renderMassObject(gl, (MassObject) c); renderMassObject(gl, (MassObject) c);
} else if (c instanceof FinSet) { } else if (c instanceof FinSet) {
FinSet fins = (FinSet) c; FinSet fins = (FinSet) c;
if (which == Surface.OUTSIDE) { fr.renderFinSet(gl, fins, which);
fr.renderFinSet(gl, fins);
}
} else if (c instanceof TubeFinSet) { } else if (c instanceof TubeFinSet) {
renderTubeFins( gl, (TubeFinSet) c, which); renderTubeFins( gl, (TubeFinSet) c, which);
} else if ( c instanceof AxialStage ) { } else if ( c instanceof AxialStage ) {

View File

@ -13,11 +13,12 @@ import net.sf.openrocket.rocketcomponent.EllipticalFinSet;
import net.sf.openrocket.rocketcomponent.FinSet; import net.sf.openrocket.rocketcomponent.FinSet;
import net.sf.openrocket.util.BoundingBox; import net.sf.openrocket.util.BoundingBox;
import net.sf.openrocket.util.Coordinate; import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.gui.figure3d.geometry.Geometry.Surface;
public class FinRenderer { public class FinRenderer {
private GLUtessellator tobj = GLU.gluNewTess(); private GLUtessellator tobj = GLU.gluNewTess();
public void renderFinSet(final GL2 gl, FinSet finSet ) { public void renderFinSet(final GL2 gl, FinSet finSet, Surface which) {
BoundingBox bounds = finSet.getInstanceBoundingBox(); BoundingBox bounds = finSet.getInstanceBoundingBox();
gl.glMatrixMode(GL.GL_TEXTURE); gl.glMatrixMode(GL.GL_TEXTURE);
@ -61,51 +62,57 @@ public class FinRenderer {
GLU.gluTessCallback(tobj, GLU.GLU_TESS_END, cb); GLU.gluTessCallback(tobj, GLU.GLU_TESS_END, cb);
// fin side: +z // fin side: +z
GLU.gluTessBeginPolygon(tobj, null); if (which == Surface.OUTSIDE) {
GLU.gluTessBeginContour(tobj); GLU.gluTessBeginPolygon(tobj, null);
gl.glNormal3f(0, 0, 1); GLU.gluTessBeginContour(tobj);
for (int i = finPoints.length - 1; i >= 0; i--) { gl.glNormal3f(0, 0, 1);
Coordinate c = finPoints[i]; for (int i = finPoints.length - 1; i >= 0; i--) {
double[] p = new double[] { c.x, c.y + finSet.getBodyRadius(), Coordinate c = finPoints[i];
c.z + finSet.getThickness() / 2.0 }; double[] p = new double[]{c.x, c.y + finSet.getBodyRadius(),
GLU.gluTessVertex(tobj, p, 0, p); c.z + finSet.getThickness() / 2.0};
GLU.gluTessVertex(tobj, p, 0, p);
}
GLU.gluTessEndContour(tobj);
GLU.gluTessEndPolygon(tobj);
} }
GLU.gluTessEndContour(tobj);
GLU.gluTessEndPolygon(tobj);
// fin side: -z // fin side: -z
GLU.gluTessBeginPolygon(tobj, null); if (which == Surface.INSIDE) {
GLU.gluTessBeginContour(tobj); GLU.gluTessBeginPolygon(tobj, null);
gl.glNormal3f(0, 0, -1); GLU.gluTessBeginContour(tobj);
for (int i = 0; i < finPoints.length; i++) { gl.glNormal3f(0, 0, -1);
Coordinate c = finPoints[i]; for (int i = 0; i < finPoints.length; i++) {
double[] p = new double[] { c.x, c.y + finSet.getBodyRadius(), Coordinate c = finPoints[i];
c.z - finSet.getThickness() / 2.0 }; double[] p = new double[]{c.x, c.y + finSet.getBodyRadius(),
GLU.gluTessVertex(tobj, p, 0, p); c.z - finSet.getThickness() / 2.0};
GLU.gluTessVertex(tobj, p, 0, p);
}
GLU.gluTessEndContour(tobj);
GLU.gluTessEndPolygon(tobj);
} }
GLU.gluTessEndContour(tobj);
GLU.gluTessEndPolygon(tobj);
// Strip around the edge // Strip around the edge
if (!(finSet instanceof EllipticalFinSet)) if (which == Surface.EDGES) {
gl.glShadeModel(GLLightingFunc.GL_FLAT); if (!(finSet instanceof EllipticalFinSet))
gl.glBegin(GL.GL_TRIANGLE_STRIP); gl.glShadeModel(GLLightingFunc.GL_FLAT);
for (int i = 0; i <= finPoints.length; i++) { gl.glBegin(GL.GL_TRIANGLE_STRIP);
Coordinate c = finPoints[i % finPoints.length]; for (int i = 0; i <= finPoints.length; i++) {
// if ( i > 1 ){ Coordinate c = finPoints[i % finPoints.length];
Coordinate c2 = finPoints[(i - 1 + finPoints.length) // if ( i > 1 ){
% finPoints.length]; Coordinate c2 = finPoints[(i - 1 + finPoints.length)
gl.glNormal3d(c2.y - c.y, c.x - c2.x, 0); % finPoints.length];
// } gl.glNormal3d(c2.y - c.y, c.x - c2.x, 0);
gl.glTexCoord2d(c.x, c.y + finSet.getBodyRadius()); // }
gl.glVertex3d(c.x, c.y + finSet.getBodyRadius(), gl.glTexCoord2d(c.x, c.y + finSet.getBodyRadius());
c.z - finSet.getThickness() / 2.0); gl.glVertex3d(c.x, c.y + finSet.getBodyRadius(),
gl.glVertex3d(c.x, c.y + finSet.getBodyRadius(), c.z - finSet.getThickness() / 2.0);
c.z + finSet.getThickness() / 2.0); gl.glVertex3d(c.x, c.y + finSet.getBodyRadius(),
c.z + finSet.getThickness() / 2.0);
}
gl.glEnd();
} }
gl.glEnd();
if (!(finSet instanceof EllipticalFinSet)) if (!(finSet instanceof EllipticalFinSet))
gl.glShadeModel(GLLightingFunc.GL_SMOOTH); gl.glShadeModel(GLLightingFunc.GL_SMOOTH);