rustfmt
This commit is contained in:
parent
f59aeb6594
commit
04dd82cbd7
1 changed files with 101 additions and 63 deletions
164
src/main.rs
164
src/main.rs
|
@ -49,10 +49,22 @@ fn main() {
|
||||||
parts.append(fuselage.parts.as_mut());
|
parts.append(fuselage.parts.as_mut());
|
||||||
|
|
||||||
if gen_t_tail {
|
if gen_t_tail {
|
||||||
t_tail(&control_airfoil, &mut parts, &mut scad_file, &wing_airfoil, gen_film);
|
t_tail(
|
||||||
|
&control_airfoil,
|
||||||
|
&mut parts,
|
||||||
|
&mut scad_file,
|
||||||
|
&wing_airfoil,
|
||||||
|
gen_film,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if gen_v_tail {
|
if gen_v_tail {
|
||||||
v_tail(control_airfoil, &mut parts, &mut scad_file, wing_airfoil, gen_film);
|
v_tail(
|
||||||
|
control_airfoil,
|
||||||
|
&mut parts,
|
||||||
|
&mut scad_file,
|
||||||
|
wing_airfoil,
|
||||||
|
gen_film,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if gen_assembly {
|
if gen_assembly {
|
||||||
|
@ -92,14 +104,16 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn t_tail(control_airfoil: &SeligFile, parts: &mut Vec<ScadObject>, scad_file: &mut ScadFile, wing_airfoil: &SeligFile, gen_film: bool) {
|
fn t_tail(
|
||||||
|
control_airfoil: &SeligFile,
|
||||||
|
parts: &mut Vec<ScadObject>,
|
||||||
|
scad_file: &mut ScadFile,
|
||||||
|
wing_airfoil: &SeligFile,
|
||||||
|
gen_film: bool,
|
||||||
|
) {
|
||||||
// rudder
|
// rudder
|
||||||
let mut rudder = scad!(Rotate(90.0, vec3(1.0, 0.0, 0.0)));
|
let mut rudder = scad!(Rotate(90.0, vec3(1.0, 0.0, 0.0)));
|
||||||
let (mut struts,mut spar) = wing(
|
let (mut struts, mut spar) = wing(&control_airfoil, &RUDDER, SparType::Center);
|
||||||
&control_airfoil,
|
|
||||||
&RUDDER,
|
|
||||||
SparType::Center,
|
|
||||||
);
|
|
||||||
rudder.add_child(struts.visualization);
|
rudder.add_child(struts.visualization);
|
||||||
rudder.add_child(spar.visualization);
|
rudder.add_child(spar.visualization);
|
||||||
parts.append(struts.parts.as_mut());
|
parts.append(struts.parts.as_mut());
|
||||||
|
@ -126,20 +140,24 @@ fn t_tail(control_airfoil: &SeligFile, parts: &mut Vec<ScadObject>, scad_file: &
|
||||||
scad_file.add_object(scad!(NamedColor("clear-red".to_string()); wrapped));
|
scad_file.add_object(scad!(NamedColor("clear-red".to_string()); wrapped));
|
||||||
}
|
}
|
||||||
|
|
||||||
scad_file.add_object(scad!(Translate(vec3(LENGTH - ELEVATOR_CHORD, 0.0, 0.0)); elevator.visualization));
|
scad_file.add_object(
|
||||||
|
scad!(Translate(vec3(LENGTH - ELEVATOR_CHORD, 0.0, 0.0)); elevator.visualization),
|
||||||
|
);
|
||||||
parts.append(&mut elevator.parts);
|
parts.append(&mut elevator.parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn v_tail(control_airfoil: SeligFile, parts: &mut Vec<ScadObject>, scad_file: &mut ScadFile, wing_airfoil: SeligFile, gen_film: bool) {
|
fn v_tail(
|
||||||
|
control_airfoil: SeligFile,
|
||||||
|
parts: &mut Vec<ScadObject>,
|
||||||
|
scad_file: &mut ScadFile,
|
||||||
|
wing_airfoil: SeligFile,
|
||||||
|
gen_film: bool,
|
||||||
|
) {
|
||||||
// rudder
|
// rudder
|
||||||
let mut ruddervators = scad!(Union);
|
let mut ruddervators = scad!(Union);
|
||||||
let mut ruddervator = scad!(Union);//scad!(Rotate(90.0, vec3(1.0, 0.0, 0.0)));
|
let mut ruddervator = scad!(Union); //scad!(Rotate(90.0, vec3(1.0, 0.0, 0.0)));
|
||||||
ruddervator = scad!(Rotate(60.0, vec3(1.0, 0.0, 0.0)); ruddervator);
|
ruddervator = scad!(Rotate(60.0, vec3(1.0, 0.0, 0.0)); ruddervator);
|
||||||
let (mut struts,mut spar) = wing(
|
let (mut struts, mut spar) = wing(&control_airfoil, &RUDDER, SparType::Top);
|
||||||
&control_airfoil,
|
|
||||||
&RUDDER,
|
|
||||||
SparType::Top,
|
|
||||||
);
|
|
||||||
ruddervator.add_child(struts.visualization);
|
ruddervator.add_child(struts.visualization);
|
||||||
ruddervator.add_child(spar.visualization);
|
ruddervator.add_child(spar.visualization);
|
||||||
ruddervator = scad!(Translate(vec3(0.0, FUSELAGE_GAP, 0.0)); ruddervator);
|
ruddervator = scad!(Translate(vec3(0.0, FUSELAGE_GAP, 0.0)); ruddervator);
|
||||||
|
@ -175,10 +193,13 @@ impl Construct {
|
||||||
parts,
|
parts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A construct with no parts
|
/// A construct with no parts
|
||||||
fn cosmetic(visualization: ScadObject) -> Self {
|
fn cosmetic(visualization: ScadObject) -> Self {
|
||||||
Construct { visualization, parts: Vec::new() }
|
Construct {
|
||||||
|
visualization,
|
||||||
|
parts: Vec::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert to tuple
|
/// Convert to tuple
|
||||||
|
@ -201,7 +222,7 @@ fn mirrored_wing(wing_airfoil: &SeligFile, wing_config: &WingConfig) -> Construc
|
||||||
|
|
||||||
parts.append(strut.parts.as_mut());
|
parts.append(strut.parts.as_mut());
|
||||||
|
|
||||||
let transform = Translate(vec3(0.0, FUSELAGE_GAP,0.0));
|
let transform = Translate(vec3(0.0, FUSELAGE_GAP, 0.0));
|
||||||
|
|
||||||
wing = scad!(transform.clone(); wing);
|
wing = scad!(transform.clone(); wing);
|
||||||
top_spar_neg = scad!(transform; top_spar_neg);
|
top_spar_neg = scad!(transform; top_spar_neg);
|
||||||
|
@ -223,46 +244,53 @@ fn mirrored_wing(wing_airfoil: &SeligFile, wing_config: &WingConfig) -> Construc
|
||||||
(false, true, false),
|
(false, true, false),
|
||||||
));
|
));
|
||||||
parts.push(scad!(Projection(false); symetric_spar.clone()));
|
parts.push(scad!(Projection(false); symetric_spar.clone()));
|
||||||
Construct::new(
|
Construct::new(wing_transform.clone(), parts)
|
||||||
wing_transform.clone()
|
|
||||||
, parts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns (struts, spar)
|
/// Returns (struts, spar)
|
||||||
fn wing(wing_airfoil: &SeligFile, wing_config: &WingConfig, spar: SparType) -> (Construct, Construct) {
|
fn wing(
|
||||||
let (wing, wing_parts) = wing_struts(
|
wing_airfoil: &SeligFile,
|
||||||
wing_airfoil,
|
wing_config: &WingConfig,
|
||||||
wing_config,
|
spar: SparType,
|
||||||
&spar,
|
) -> (Construct, Construct) {
|
||||||
).tup();
|
let (wing, wing_parts) = wing_struts(wing_airfoil, wing_config, &spar).tup();
|
||||||
// TODO: other spar types
|
// TODO: other spar types
|
||||||
let spar = match spar {
|
let spar = match spar {
|
||||||
SparType::None => {
|
SparType::None => {
|
||||||
|
|
||||||
scad!(Union)
|
scad!(Union)
|
||||||
},
|
}
|
||||||
SparType::Top => {
|
SparType::Top => {
|
||||||
let top_spar = topwing_spar(
|
let top_spar = topwing_spar(wing_airfoil, wing_config);
|
||||||
wing_airfoil,
|
|
||||||
wing_config,
|
|
||||||
);
|
|
||||||
let mut spar = scad!(Difference; top_spar);
|
let mut spar = scad!(Difference; top_spar);
|
||||||
spar.add_child(wing.clone());
|
spar.add_child(wing.clone());
|
||||||
spar
|
spar
|
||||||
},
|
}
|
||||||
SparType::Center => {
|
SparType::Center => {
|
||||||
// TODO: taper
|
// TODO: taper
|
||||||
let mut mid_spar = scad!(Hull);
|
let mut mid_spar = scad!(Hull);
|
||||||
let bottom = centered_cube(vec3(wing_config.chord * (MIDSPAR_RANGE.end - MIDSPAR_RANGE.start) , CARDBOARD_WIDTH, CARDBOARD_WIDTH), (false, false, true));
|
let bottom = centered_cube(
|
||||||
let mut top = scad!(Translate(vec3(wing_config.taper * MIDSPAR_RANGE.start * wing_config.chord - MIDSPAR_RANGE.start * wing_config.chord, wing_config.length, 0.0)));
|
vec3(
|
||||||
|
wing_config.chord * (MIDSPAR_RANGE.end - MIDSPAR_RANGE.start),
|
||||||
|
CARDBOARD_WIDTH,
|
||||||
|
CARDBOARD_WIDTH,
|
||||||
|
),
|
||||||
|
(false, false, true),
|
||||||
|
);
|
||||||
|
let mut top = scad!(Translate(vec3(
|
||||||
|
wing_config.taper * MIDSPAR_RANGE.start * wing_config.chord
|
||||||
|
- MIDSPAR_RANGE.start * wing_config.chord,
|
||||||
|
wing_config.length,
|
||||||
|
0.0
|
||||||
|
)));
|
||||||
top.add_child(scad!(Scale(vec3(wing_config.taper, 1.0, 1.0)); bottom.clone()));
|
top.add_child(scad!(Scale(vec3(wing_config.taper, 1.0, 1.0)); bottom.clone()));
|
||||||
mid_spar.add_child(top);
|
mid_spar.add_child(top);
|
||||||
mid_spar.add_child(bottom);
|
mid_spar.add_child(bottom);
|
||||||
mid_spar = scad!(Translate(vec3(MIDSPAR_RANGE.start * wing_config.chord, 0.0, 0.0)); mid_spar);
|
mid_spar =
|
||||||
|
scad!(Translate(vec3(MIDSPAR_RANGE.start * wing_config.chord, 0.0, 0.0)); mid_spar);
|
||||||
let mut spar = scad!(Difference; mid_spar);
|
let mut spar = scad!(Difference; mid_spar);
|
||||||
spar.add_child(wing.clone());
|
spar.add_child(wing.clone());
|
||||||
spar
|
spar
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let spar_flat = scad!(Projection(false); spar.clone());
|
let spar_flat = scad!(Projection(false); spar.clone());
|
||||||
|
@ -291,7 +319,7 @@ fn strut(airfoil: &SeligFile, chord: f32, width: f32, spar: &SparType) -> Constr
|
||||||
match spar {
|
match spar {
|
||||||
SparType::Top => topspar_negative(airfoil, chord, TOPSPAR_RANGE),
|
SparType::Top => topspar_negative(airfoil, chord, TOPSPAR_RANGE),
|
||||||
SparType::Center => {
|
SparType::Center => {
|
||||||
scad!(Translate2d(vec2(MIDSPAR_RANGE.start, 0.0));
|
scad!(Translate2d(vec2(MIDSPAR_RANGE.start, 0.0));
|
||||||
centered_square(vec2(MIDSPAR_RANGE.end - MIDSPAR_RANGE.start, CARDBOARD_WIDTH/ chord), (false,true))
|
centered_square(vec2(MIDSPAR_RANGE.end - MIDSPAR_RANGE.start, CARDBOARD_WIDTH/ chord), (false,true))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -326,12 +354,7 @@ fn strut(airfoil: &SeligFile, chord: f32, width: f32, spar: &SparType) -> Constr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extrude_strut(
|
fn extrude_strut(shape: ScadObject, strut_hole: ScadObject, width: f32, chord: f32) -> ScadObject {
|
||||||
shape: ScadObject,
|
|
||||||
strut_hole: ScadObject,
|
|
||||||
width: f32,
|
|
||||||
chord: f32,
|
|
||||||
) -> ScadObject {
|
|
||||||
let mut strut_shape = scad!(Difference);
|
let mut strut_shape = scad!(Difference);
|
||||||
strut_shape.add_child(shape);
|
strut_shape.add_child(shape);
|
||||||
strut_shape.add_child(strut_hole);
|
strut_shape.add_child(strut_hole);
|
||||||
|
@ -383,8 +406,14 @@ fn spar(length: f32) -> Construct {
|
||||||
|
|
||||||
let parts = vec![scad!(Square(vec2(length, SPAR_SIDE_WIDTH * 3.0)))];
|
let parts = vec![scad!(Square(vec2(length, SPAR_SIDE_WIDTH * 3.0)))];
|
||||||
|
|
||||||
let top = centered_cube(vec3(SPAR_SIDE_WIDTH, length, CARDBOARD_WIDTH), (true,false,false));
|
let top = centered_cube(
|
||||||
let mut left = centered_cube(vec3(SPAR_SIDE_WIDTH, length, CARDBOARD_WIDTH), (false,false,false));
|
vec3(SPAR_SIDE_WIDTH, length, CARDBOARD_WIDTH),
|
||||||
|
(true, false, false),
|
||||||
|
);
|
||||||
|
let mut left = centered_cube(
|
||||||
|
vec3(SPAR_SIDE_WIDTH, length, CARDBOARD_WIDTH),
|
||||||
|
(false, false, false),
|
||||||
|
);
|
||||||
left = scad!(Rotate(120.0, vec3(0.0, 1.0, 0.0)); left);
|
left = scad!(Rotate(120.0, vec3(0.0, 1.0, 0.0)); left);
|
||||||
left = scad!(Translate(vec3(SPAR_SIDE_WIDTH/2.0, 1.0, 0.0)); left);
|
left = scad!(Translate(vec3(SPAR_SIDE_WIDTH/2.0, 1.0, 0.0)); left);
|
||||||
let right = scad!(Mirror(vec3(1.0, 0.0, 0.0)); left.clone());
|
let right = scad!(Mirror(vec3(1.0, 0.0, 0.0)); left.clone());
|
||||||
|
@ -393,18 +422,17 @@ fn spar(length: f32) -> Construct {
|
||||||
spar.add_child(right);
|
spar.add_child(right);
|
||||||
spar.add_child(top);
|
spar.add_child(top);
|
||||||
|
|
||||||
Construct { visualization: spar, parts }
|
Construct {
|
||||||
|
visualization: spar,
|
||||||
|
parts,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lerp(a: f32, b: f32, x: f32) -> f32 {
|
fn lerp(a: f32, b: f32, x: f32) -> f32 {
|
||||||
a * (1.0 - x) + b * x
|
a * (1.0 - x) + b * x
|
||||||
}
|
}
|
||||||
|
|
||||||
fn wing_struts(
|
fn wing_struts(aerofoil: &SeligFile, config: &WingConfig, spar: &SparType) -> Construct {
|
||||||
aerofoil: &SeligFile,
|
|
||||||
config: &WingConfig,
|
|
||||||
spar: &SparType,
|
|
||||||
) -> Construct {
|
|
||||||
let mut wing = scad!(Translate(vec3(0.0, 0.0, 0.0)));
|
let mut wing = scad!(Translate(vec3(0.0, 0.0, 0.0)));
|
||||||
let mut parts = Vec::new();
|
let mut parts = Vec::new();
|
||||||
|
|
||||||
|
@ -412,7 +440,11 @@ fn wing_struts(
|
||||||
for strut_idx in 0..config.struts + 1 {
|
for strut_idx in 0..config.struts + 1 {
|
||||||
let gap = config.length / config.struts as f32;
|
let gap = config.length / config.struts as f32;
|
||||||
|
|
||||||
let chord = lerp(config.chord, config.chord * config.taper, strut_idx as f32 / config.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;
|
let spacing = strut_idx as f32 * gap;
|
||||||
|
|
||||||
|
@ -424,13 +456,13 @@ fn wing_struts(
|
||||||
wing.add_child(transform);
|
wing.add_child(transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
Construct { visualization: wing, parts }
|
Construct {
|
||||||
|
visualization: wing,
|
||||||
|
parts,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn topwing_spar(
|
fn topwing_spar(aerofoil: &SeligFile, config: &WingConfig) -> ScadObject {
|
||||||
aerofoil: &SeligFile,
|
|
||||||
config: &WingConfig
|
|
||||||
) -> ScadObject {
|
|
||||||
let mut wing = scad!(Hull);
|
let mut wing = scad!(Hull);
|
||||||
|
|
||||||
let mut pre_vis = scad!(Union);
|
let mut pre_vis = scad!(Union);
|
||||||
|
@ -439,7 +471,11 @@ fn topwing_spar(
|
||||||
for strut_idx in 0..config.struts + 1 {
|
for strut_idx in 0..config.struts + 1 {
|
||||||
let gap = config.length / config.struts as f32;
|
let gap = config.length / config.struts as f32;
|
||||||
|
|
||||||
let chord = lerp(config.chord, config.chord * config.taper, strut_idx as f32 / config.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;
|
let spacing = strut_idx as f32 * gap;
|
||||||
|
|
||||||
|
@ -460,8 +496,10 @@ fn topwing_spar(
|
||||||
/// Parameters for what would be half of a symmetrical (port/starboard) wing
|
/// Parameters for what would be half of a symmetrical (port/starboard) wing
|
||||||
/// All distance units are millimeters
|
/// All distance units are millimeters
|
||||||
pub struct WingConfig {
|
pub struct WingConfig {
|
||||||
pub length: f32, /// half of the wingspan
|
pub length: f32,
|
||||||
|
/// half of the wingspan
|
||||||
pub chord: f32,
|
pub chord: f32,
|
||||||
pub taper: f32, /// chord at wingtip in relation to the chord at the root
|
pub taper: f32,
|
||||||
|
/// chord at wingtip in relation to the chord at the root
|
||||||
pub struts: usize,
|
pub struts: usize,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue