1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-08 15:56:42 +02:00
This commit is contained in:
Justin Lin
2022-03-10 21:41:06 +08:00
parent 2b2d4dbefa
commit 63ddbd3104
7 changed files with 38 additions and 30 deletions

View File

@@ -2,13 +2,14 @@ function _sf_square_surfaces(levels, thickness, depth, invert) =
let( let(
rows = len(levels), rows = len(levels),
columns = len(levels[0]), columns = len(levels[0]),
offset_z = invert ? 0 : thickness - depth, lv_offset = invert ? function(lv) (255 - lv) / 255 * depth :
function(lv) lv / 255 * depth + (thickness - depth),
surface1 = [ surface1 = [
for(r = [0:rows - 1]) for(r = [0:rows - 1])
let(level = levels[rows - r - 1])
[ [
for(c = [0:columns - 1]) for(c = [0:columns - 1])
let(lv = invert ? 255 - levels[rows - r - 1][c] : levels[rows - r - 1][c]) [c, r, lv_offset(level[c])]
[c, r, lv / 255 * depth + offset_z]
] ]
], ],
surface2 = [ surface2 = [

View File

@@ -22,20 +22,19 @@ module sf_hull(points, thickness) {
twintri_lt = twintri_lt =
[ [
for(yi = yi_range) for(yi = yi_range, xi = xi_range)
for(xi = xi_range) [
[ [
[ points[yi][xi],
points[yi][xi], points[yi][xi + 1],
points[yi][xi + 1], points[yi + 1][xi]
points[yi + 1][xi] ],
], [
[ points[yi + 1][xi],
points[yi + 1][xi], points[yi][xi + 1],
points[yi][xi + 1], points[yi + 1][xi + 1]
points[yi + 1][xi + 1] ]
] ]
]
]; ];
for(twintri = twintri_lt) { for(twintri = twintri_lt) {

View File

@@ -19,7 +19,6 @@ module sf_ring(levels, radius, thickness, depth, angle = 360, twist = 0, invert
columns = len(levels[0]); columns = len(levels[0]);
size = [columns - 1, rows - 1]; size = [columns - 1, rows - 1];
offset_z = invert ? thickness : 0;
centered = invert ? [0, 0, thickness] : [0, 0, thickness / 2]; centered = invert ? [0, 0, thickness] : [0, 0, thickness / 2];
if(invert) { if(invert) {
mirror([0, 0, 1]) mirror([0, 0, 1])
@@ -46,7 +45,7 @@ module sf_ring(levels, radius, thickness, depth, angle = 360, twist = 0, invert
for(row = surface[0]) for(row = surface[0])
[ [
for(p = row) for(p = row)
ptf_ring(size, p - centered, radius, angle, twist) + [0, 0, offset_z] ptf_ring(size, p - centered, radius, angle, twist)
] ]
], ],
[ [

View File

@@ -54,11 +54,12 @@ module sf_solidifyT(points1, points2, triangles, convexity = 1) {
] ]
]; ];
off = [leng, leng, leng];
polyhedron( polyhedron(
points = concat(points1, points2), points = concat(points1, points2),
faces = concat( faces = concat(
tris, tris,
[for(tri = triangles) tri + [leng, leng, leng]], [for(tri = triangles) tri + off],
side_faces side_faces
), ),
convexity = convexity convexity = convexity

View File

@@ -17,14 +17,14 @@ module sf_square(levels, thickness, depth, x_twist = 0, y_twist = 0, invert = fa
size = [len(levels[0]), len(levels)]; size = [len(levels[0]), len(levels)];
dp = is_undef(depth) ? thickness / 2 : depth; dp = is_undef(depth) ? thickness / 2 : depth;
surface = _sf_square_surfaces(levels, thickness, dp, invert); surface = _sf_square_surfaces(levels, thickness, dp, invert);
offset_z = invert ? thickness : 0;
off = [0, 0, invert ? thickness : 0];
sf_solidify( sf_solidify(
[ [
for(row = surface[0]) [ for(row = surface[0]) [
for(p = row) for(p = row)
ptf_y_twist(size, ptf_y_twist(size,
ptf_x_twist(size, p + [0, 0, offset_z], x_twist), ptf_x_twist(size, p + off, x_twist),
y_twist y_twist
) )
] ]

View File

@@ -19,7 +19,12 @@ module sf_thicken(points, thickness, direction = "BOTH", convexity = 1) {
let( let(
xy = [xi, yi], xy = [xi, yi],
// clockwise // clockwise
vi = [for(coord_offset = [[1, 0], [0, -1], [-1, 0], [0, 1]]) coord_offset + xy], vi = [
[1, 0] + xy,
[0, -1] + xy,
[-1, 0] + xy,
[0, 1] + xy
],
normals = [ normals = [
for(i = [0:3]) for(i = [0:3])
let( let(
@@ -36,18 +41,20 @@ module sf_thicken(points, thickness, direction = "BOTH", convexity = 1) {
) )
sum(normals) / len(normals); sum(normals) / len(normals);
leng_points = len(points);
leng_point0 = len(points[0]);
if(is_list(direction)) { if(is_list(direction)) {
dir_v = direction / norm(direction); dir_v = direction / norm(direction);
surface_another = points + thickness * [ surface_another = points + thickness * [
for(y = [0:len(points) - 1]) for(y = [0:leng_points - 1])
[ [
for(x = [0:len(points[0]) - 1]) for(x = [0:leng_point0 - 1])
dir_v dir_v
] ]
]; ];
midy = len(points) / 2; midy = leng_points / 2;
midx = len(points[0]) / 2; midx = leng_point0 / 2;
nv = tri_normal([points[midy][midx], points[midy + 1][midx], points[midy][midx + 1]]); nv = tri_normal([points[midy][midx], points[midy + 1][midx], points[midy][midx + 1]]);
if(nv * dir_v > 0) { if(nv * dir_v > 0) {
@@ -59,9 +66,9 @@ module sf_thicken(points, thickness, direction = "BOTH", convexity = 1) {
} }
else { else {
vertex_normals = [ vertex_normals = [
for(y = [0:len(points) - 1]) for(y = [0:leng_points - 1])
[ [
for(x = [0:len(points[0]) - 1]) for(x = [0:leng_point0 - 1])
vertex_normal(points, x, y) vertex_normal(points, x, y)
] ]
]; ];

View File

@@ -49,7 +49,8 @@ module sf_thickenT(points, thickness, triangles = undef, direction = "BOTH", con
mid = sort(points)[leng_pts / 2]; mid = sort(points)[leng_pts / 2];
tri = cnn_tris[find_index(points, function(p) p == mid)][0]; tri = cnn_tris[find_index(points, function(p) p == mid)][0];
nv = _face_normal([points[tri[0]], points[tri[1]], points[tri[2]]]); nv = _face_normal([points[tri[0]], points[tri[1]], points[tri[2]]]);
pts = [for(p = points) p + dir_v * thickness]; off = dir_v * thickness;
pts = [for(p = points) p + off];
if(nv * dir_v > 0) { if(nv * dir_v > 0) {
sf_solidifyT(pts, points, real_triangles, convexity = convexity); sf_solidifyT(pts, points, real_triangles, convexity = convexity);