Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/path_extrude.scad
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ use <matrix/m_translation.scad>
use <matrix/m_rotation.scad>

module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale = 1.0, closed = false, method = "AXIS_ANGLE") {
sh_pts = len(shape_pts[0]) == 3 ? [for(p = shape_pts) [each p, 1]] : [for(p = shape_pts) [p.x, p.y, 0, 1]];
shape_pts_fn = function(t) shape_pts;
path_extrude_fn(shape_pts_fn, path_pts, triangles, twist, scale, closed, method);
}

module path_extrude_fn(shape_pts_fn, path_pts, triangles = "SOLID", twist = 0, scale = 1.0, closed = false, method = "AXIS_ANGLE") {
sh_pts_fn = function(t)
let(shape_pts = shape_pts_fn(t))
len(shape_pts[0]) == 3
? [for(p = shape_pts) [each p, 1]]
: [for(p = shape_pts) [p.x, p.y, 0, 1]];
pth_pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) __to3d(p)];

len_path_pts = len(pth_pts);
Expand Down Expand Up @@ -70,10 +79,10 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =

// get all sections
angleyz_pts01 = __angy_angz(pth_pts[0], pth_pts[1]);
function init_section(a, s) =
function init_section(a, s, t) =
let(transform_m = m_rotation([0, -angleyz_pts01[0], angleyz_pts01[1]]) * m_rot_90_0_n90 * m_rotation(a) * m_scaling(s))
[
for(p = sh_pts)
for(p = sh_pts_fn(t))
let(transformed = transform_m * p)
[transformed.x, transformed.y, transformed.z]
];
Expand All @@ -89,14 +98,14 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
ms2p = [ms2[0], ms2[1], ms2[2]]
)
[
for(p = init_section(init_a, init_s))
for(p = init_section(init_a, init_s, (j+1) / len_path_pts_minus_one))
[ms0p * p, ms1p * p, ms2p * p]
];

sections =
let(
fst_section = translate_pts(init_section(0, one), pth_pts[0]),
snd_section = translate_pts(init_section(0, one + scale_step_vt), pth_pts[1]),
fst_section = translate_pts(init_section(0, one, 0), pth_pts[0]),
snd_section = translate_pts(init_section(0, one + scale_step_vt, 1 / len_path_pts_minus_one), pth_pts[1]),
end_i = closed ? len_path_pts - 2 : len_path_pts - 1,
remain_sections = [
for(i = 1; i < end_i; i = i + 1)
Expand Down Expand Up @@ -139,7 +148,7 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
m_scaling([1 + scale_step_vt.x * i, 1 + scale_step_vt.y * i, 1])
)
[
for(p = sh_pts)
for(p = sh_pts_fn(i / len_path_pts_minus_one))
let(transformed = transform_m * p)
[transformed.x, transformed.y, transformed.z]
];
Expand Down Expand Up @@ -174,4 +183,4 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
// override to test
module test_path_extrude(sections, method) {

}
}