further transitioned to construct architecture
This commit is contained in:
parent
90c9817ab5
commit
dd6526201f
1 changed files with 67 additions and 63 deletions
130
src/main.rs
130
src/main.rs
|
@ -16,6 +16,7 @@ fn main() {
|
|||
let mut scad_file = ScadFile::new();
|
||||
//let mut parts: Vec<ScadObject> = Vec::new();
|
||||
|
||||
let mut parts = Vec::new();
|
||||
scad_file.set_detail(50);
|
||||
|
||||
// cambered airfoil, used in the wing
|
||||
|
@ -46,47 +47,23 @@ fn main() {
|
|||
|
||||
// rudder
|
||||
let mut rudder = scad!(Rotate(90.0, vec3(1.0, 0.0, 0.0)));
|
||||
rudder.add_child(wing(
|
||||
let (mut struts,mut spar) = wing(
|
||||
&control_airfoil,
|
||||
&RUDDER,
|
||||
SparType::Center,
|
||||
));
|
||||
rudder.add_child(spar(RUDDER_HEIGHT, false));
|
||||
);
|
||||
rudder.add_child(struts.visualization);
|
||||
rudder.add_child(spar.visualization);
|
||||
parts.append(struts.parts.as_mut());
|
||||
parts.append(spar.parts.as_mut());
|
||||
rudder = scad!(Translate(vec3(LENGTH-RUDDER_CHORD, 0.0, 0.0)); rudder);
|
||||
scad_file.add_object(rudder);
|
||||
|
||||
// elevator
|
||||
let mut elevator = scad!(Translate(vec3(LENGTH - ELEVATOR_CHORD, 0.0, 0.0)));
|
||||
let mut symetric_spar = scad!(Union);
|
||||
for port in [true, false] {
|
||||
let mut wing = wing(
|
||||
&wing_airfoil,
|
||||
&ELEVATOR,
|
||||
SparType::Top,
|
||||
);
|
||||
let top_spar = topwing_spar(
|
||||
&wing_airfoil,
|
||||
ELEVATOR_STRUTS,
|
||||
ELEVATOR_HEIGHT,
|
||||
ELEVATOR_CHORD,
|
||||
ELEVATOR_CHORD * ELEVATOR_TAPER,
|
||||
);
|
||||
let mut top_spar_neg = scad!(Difference; top_spar);
|
||||
top_spar_neg.add_child(wing.clone());
|
||||
symetric_spar.add_child(top_spar_neg.clone());
|
||||
wing = scad!(Translate(vec3(0.0, FUSELAGE_GAP,0.0)); wing);
|
||||
if port {
|
||||
wing = scad!(Mirror(vec3(0.0, 1.0, 0.0)); wing);
|
||||
}
|
||||
elevator.add_child(wing);
|
||||
}
|
||||
scad_file.add_object(elevator);
|
||||
|
||||
symetric_spar.add_child(centered_cube(
|
||||
vec3(CHORD, FUSELAGE_GAP * 2.0, 1.0),
|
||||
(false, true, false),
|
||||
));
|
||||
register_part(scad!(Projection(false); symetric_spar));
|
||||
let mut elevator = mirrored_wing(&wing_airfoil, &ELEVATOR);
|
||||
scad_file.add_object(scad!(Translate(vec3(LENGTH - ELEVATOR_CHORD, 0.0, 0.0)); elevator.visualization));
|
||||
parts.append(&mut elevator.parts);
|
||||
|
||||
let cardboard = vec3(0.38, 0.26, 0.26);
|
||||
scad_file.add_object(scad!(Color(cardboard); wing_transform.visualization));
|
||||
|
@ -124,9 +101,16 @@ impl Construct {
|
|||
}
|
||||
}
|
||||
|
||||
/// A construct with no parts
|
||||
fn cosmetic(visualization: ScadObject) -> Self {
|
||||
Construct { visualization, parts: Vec::new() }
|
||||
}
|
||||
|
||||
/// Convert to tuple
|
||||
/// (visualization, parts)
|
||||
fn tup(self) -> (ScadObject, Vec<ScadObject>) {
|
||||
(self.visualization, self.parts)
|
||||
}
|
||||
}
|
||||
|
||||
fn mirrored_wing(wing_airfoil: &SeligFile, wing_config: &WingConfig) -> Construct {
|
||||
|
@ -135,30 +119,26 @@ fn mirrored_wing(wing_airfoil: &SeligFile, wing_config: &WingConfig) -> Construc
|
|||
// struts
|
||||
let mut symetric_spar = scad!(Union);
|
||||
for port in [true, false] {
|
||||
let mut wing = wing(
|
||||
wing_airfoil,
|
||||
&wing_config,
|
||||
SparType::Top,
|
||||
);
|
||||
let top_spar = topwing_spar(
|
||||
wing_airfoil,
|
||||
STRUTS / 2,
|
||||
WINGSPAN / 2.0,
|
||||
CHORD,
|
||||
CHORD * WING_TAPER,
|
||||
);
|
||||
let (mut strut, spar) = wing(wing_airfoil, wing_config, SparType::Top);
|
||||
|
||||
let mut top_spar_neg = scad!(Difference; top_spar);
|
||||
top_spar_neg.add_child(wing.clone());
|
||||
let mut wing = strut.visualization;
|
||||
let mut top_spar_neg = spar.visualization;
|
||||
|
||||
wing.add_child(scad!(NamedColor("red".to_string()); top_spar_neg.clone()));
|
||||
parts.append(strut.parts.as_mut());
|
||||
|
||||
let transform = Translate(vec3(0.0, FUSELAGE_GAP,0.0));
|
||||
|
||||
wing = scad!(transform.clone(); wing);
|
||||
top_spar_neg = scad!(transform; top_spar_neg);
|
||||
|
||||
if port {
|
||||
let mirror = Mirror(vec3(0.0, 1.0, 0.0));
|
||||
wing = scad!(mirror.clone(); wing);
|
||||
top_spar_neg = scad!(mirror; top_spar_neg);
|
||||
}
|
||||
|
||||
symetric_spar.add_child(top_spar_neg);
|
||||
|
||||
wing = scad!(Translate(vec3(0.0, FUSELAGE_GAP,0.0)); wing);
|
||||
if port {
|
||||
wing = scad!(Mirror(vec3(0.0, 1.0, 0.0)); wing);
|
||||
}
|
||||
wing_transform.add_child(wing);
|
||||
}
|
||||
// fuselage affixment point
|
||||
|
@ -173,9 +153,34 @@ fn mirrored_wing(wing_airfoil: &SeligFile, wing_config: &WingConfig) -> Construc
|
|||
, parts)
|
||||
}
|
||||
|
||||
/// Returns (struts, spar)
|
||||
fn wing(wing_airfoil: &SeligFile, wing_config: &WingConfig, spar: SparType) -> (Construct, Construct) {
|
||||
let (mut wing, wing_parts) = wing_struts(
|
||||
wing_airfoil,
|
||||
&wing_config,
|
||||
spar,
|
||||
).tup();
|
||||
// TODO: other spar types
|
||||
let top_spar = topwing_spar(
|
||||
wing_airfoil,
|
||||
wing_config,
|
||||
);
|
||||
let mut spar = scad!(Difference; top_spar);
|
||||
spar.add_child(wing.clone());
|
||||
|
||||
let spar_flat = scad!(Projection(false); spar.clone());
|
||||
|
||||
let strut = Construct::new(wing, wing_parts);
|
||||
let spar = Construct::new(spar, vec![spar_flat]);
|
||||
(strut, spar)
|
||||
}
|
||||
|
||||
enum SparType {
|
||||
/// No spar, just struts
|
||||
None,
|
||||
/// Spar along the top of the wing
|
||||
Top,
|
||||
/// Spar that passes through each strut
|
||||
Center,
|
||||
}
|
||||
|
||||
|
@ -305,12 +310,13 @@ fn lerp(a: f32, b: f32, x: f32) -> f32 {
|
|||
a * (1.0 - x) + b * x
|
||||
}
|
||||
|
||||
fn wing(
|
||||
fn wing_struts(
|
||||
aerofoil: &SeligFile,
|
||||
config: &WingConfig,
|
||||
spar: SparType,
|
||||
) -> ScadObject {
|
||||
) -> Construct {
|
||||
let mut wing = scad!(Translate(vec3(0.0, 0.0, 0.0)));
|
||||
let mut parts = Vec::new();
|
||||
|
||||
// struts
|
||||
for strut_idx in 0..config.struts + 1 {
|
||||
|
@ -322,20 +328,18 @@ fn wing(
|
|||
|
||||
let mut transform = scad!(Translate(vec3(0.0, spacing, 0.0)));
|
||||
|
||||
let strut = strut(aerofoil, chord, CARDBOARD_WIDTH, &spar);
|
||||
let mut strut = strut(aerofoil, chord, CARDBOARD_WIDTH, &spar);
|
||||
transform.add_child(strut.visualization);
|
||||
parts.append(strut.parts.as_mut());
|
||||
wing.add_child(transform);
|
||||
}
|
||||
|
||||
wing
|
||||
Construct { visualization: wing, parts }
|
||||
}
|
||||
|
||||
fn topwing_spar(
|
||||
aerofoil: &SeligFile,
|
||||
struts: usize,
|
||||
length: f32,
|
||||
chord: f32,
|
||||
taper: f32,
|
||||
config: &WingConfig
|
||||
) -> ScadObject {
|
||||
let mut wing = scad!(Hull);
|
||||
|
||||
|
@ -343,10 +347,10 @@ fn topwing_spar(
|
|||
let mut pre_vis = scad!(Union);
|
||||
|
||||
// struts
|
||||
for strut_idx in 0..struts + 1 {
|
||||
let gap = length / struts as f32;
|
||||
for strut_idx in 0..config.struts + 1 {
|
||||
let gap = config.length / config.struts as f32;
|
||||
|
||||
let chord = lerp(chord, taper, strut_idx as f32 / struts as f32);
|
||||
let chord = lerp(config.chord, config.chord * config.taper, strut_idx as f32 / config.struts as f32);
|
||||
|
||||
let spacing = strut_idx as f32 * gap;
|
||||
|
||||
|
|
Loading…
Reference in a new issue