mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-18 12:31:17 +02:00
provide an option to switch the metohd of extrude
This commit is contained in:
@@ -16,8 +16,17 @@ include <__private__/__angy_angz.scad>;
|
||||
// For backward compatibility, I directly include m_rotation here.
|
||||
include <m_rotation.scad>;
|
||||
|
||||
module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale = 1.0, closed = false) {
|
||||
// pre-process parameters
|
||||
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 ? shape_pts : [for(p = shape_pts) __to3d(p)];
|
||||
pth_pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) __to3d(p)];
|
||||
|
||||
len_path_pts = len(pth_pts);
|
||||
len_path_pts_minus_one = len_path_pts - 1;
|
||||
|
||||
|
||||
module axis_angle_path_extrude() {
|
||||
twist_step_a = twist / len_path_pts;
|
||||
|
||||
function scale_pts(pts, s) = [
|
||||
for(p = pts) [p[0] * s[0], p[1] * s[1], p[2] * s[2]]
|
||||
];
|
||||
@@ -28,13 +37,6 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
|
||||
|
||||
function rotate_pts(pts, a, v) = [for(p = pts) rotate_p(p, a, v)];
|
||||
|
||||
sh_pts = len(shape_pts[0]) == 3 ? shape_pts : [for(p = shape_pts) __to3d(p)];
|
||||
pth_pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) __to3d(p)];
|
||||
|
||||
len_path_pts = len(pth_pts);
|
||||
len_path_pts_minus_one = len_path_pts - 1;
|
||||
twist_step_a = twist / len_path_pts;
|
||||
|
||||
function scale_step() =
|
||||
let(s = (scale - 1) / len_path_pts_minus_one)
|
||||
[s, s, s];
|
||||
@@ -163,6 +165,65 @@ module path_extrude(shape_pts, path_pts, triangles = "SOLID", twist = 0, scale =
|
||||
test_path_extrude(sects);
|
||||
}
|
||||
|
||||
module euler_angles_path_extrude() {
|
||||
scale_step_vt = __is_float(scale) ?
|
||||
[(scale - 1) / len_path_pts_minus_one, (scale - 1) / len_path_pts_minus_one] :
|
||||
[(scale[0] - 1) / len_path_pts_minus_one, (scale[1] - 1) / len_path_pts_minus_one];
|
||||
|
||||
scale_step_x = scale_step_vt[0];
|
||||
scale_step_y = scale_step_vt[1];
|
||||
twist_step = twist / len_path_pts_minus_one;
|
||||
|
||||
function section(p1, p2, i) =
|
||||
let(
|
||||
length = norm(p1 - p2),
|
||||
angy_angz = __angy_angz(p1, p2),
|
||||
ay = -angy_angz[0],
|
||||
az = angy_angz[1]
|
||||
)
|
||||
[
|
||||
for(p = sh_pts)
|
||||
let(scaled_p = [p[0] * (1 + scale_step_x * i), p[1] * (1 + scale_step_y * i), p[2]])
|
||||
rotate_p(
|
||||
rotate_p(
|
||||
rotate_p(scaled_p, twist_step * i), [90, 0, -90]
|
||||
) + [i == 0 ? 0 : length, 0, 0],
|
||||
[0, ay, az]
|
||||
) + p1
|
||||
];
|
||||
|
||||
function path_extrude_inner(index) =
|
||||
index == len_path_pts ? [] :
|
||||
concat(
|
||||
[section(pth_pts[index - 1], pth_pts[index], index)],
|
||||
path_extrude_inner(index + 1)
|
||||
);
|
||||
|
||||
function calculated_sections() =
|
||||
let(sections = path_extrude_inner(1))
|
||||
closed && pth_pts[0] == pth_pts[len_path_pts_minus_one] ?
|
||||
concat(sections, [sections[0]]) : // round-robin
|
||||
concat([section(pth_pts[0], pth_pts[1], 0)], sections);
|
||||
|
||||
sections = calculated_sections();
|
||||
|
||||
polysections(
|
||||
sections,
|
||||
triangles = triangles
|
||||
);
|
||||
|
||||
// hook for testing
|
||||
test_path_extrude(sections);
|
||||
}
|
||||
|
||||
if(method == "AXIS_ANGLE") {
|
||||
axis_angle_path_extrude();
|
||||
}
|
||||
else if(method == "EULER_ANGLE") {
|
||||
euler_angles_path_extrude();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// override to test
|
||||
module test_path_extrude(sections) {
|
||||
|
Reference in New Issue
Block a user