diff --git a/src/path_extrude.scad b/src/path_extrude.scad index eebcd288..8c031300 100644 --- a/src/path_extrude.scad +++ b/src/path_extrude.scad @@ -16,7 +16,16 @@ use use 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); @@ -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] ]; @@ -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) @@ -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] ]; @@ -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) { -} \ No newline at end of file +}