1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-01 04:20:27 +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(
rows = len(levels),
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 = [
for(r = [0:rows - 1])
let(level = levels[rows - r - 1])
[
for(c = [0:columns - 1])
let(lv = invert ? 255 - levels[rows - r - 1][c] : levels[rows - r - 1][c])
[c, r, lv / 255 * depth + offset_z]
[c, r, lv_offset(level[c])]
]
],
surface2 = [

View File

@@ -22,20 +22,19 @@ module sf_hull(points, thickness) {
twintri_lt =
[
for(yi = yi_range)
for(xi = xi_range)
[
[
points[yi][xi],
points[yi][xi + 1],
points[yi + 1][xi]
],
[
points[yi + 1][xi],
points[yi][xi + 1],
points[yi + 1][xi + 1]
]
]
for(yi = yi_range, xi = xi_range)
[
[
points[yi][xi],
points[yi][xi + 1],
points[yi + 1][xi]
],
[
points[yi + 1][xi],
points[yi][xi + 1],
points[yi + 1][xi + 1]
]
]
];
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]);
size = [columns - 1, rows - 1];
offset_z = invert ? thickness : 0;
centered = invert ? [0, 0, thickness] : [0, 0, thickness / 2];
if(invert) {
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(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(
points = concat(points1, points2),
faces = concat(
tris,
[for(tri = triangles) tri + [leng, leng, leng]],
[for(tri = triangles) tri + off],
side_faces
),
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)];
dp = is_undef(depth) ? thickness / 2 : depth;
surface = _sf_square_surfaces(levels, thickness, dp, invert);
offset_z = invert ? thickness : 0;
off = [0, 0, invert ? thickness : 0];
sf_solidify(
[
for(row = surface[0]) [
for(p = row)
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
)
]

View File

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

View File

@@ -49,7 +49,8 @@ module sf_thickenT(points, thickness, triangles = undef, direction = "BOTH", con
mid = sort(points)[leng_pts / 2];
tri = cnn_tris[find_index(points, function(p) p == mid)][0];
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) {
sf_solidifyT(pts, points, real_triangles, convexity = convexity);