1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-18 12:31:17 +02:00

optimization

This commit is contained in:
Justin Lin
2022-05-14 17:19:02 +08:00
parent 3f504c0034
commit eb901f5bba

View File

@@ -14,24 +14,34 @@ use <sf_solidify.scad>;
module sf_thicken(points, thickness, direction = "BOTH", convexity = 1) { module sf_thicken(points, thickness, direction = "BOTH", convexity = 1) {
// clockwise // clockwise
dirs1 = [[1, 0], [0, -1], [-1, 0], [0, 1]]; dirs = [
dirs2 = [[0, -1], [-1, 0], [0, 1], [1, 0]]; [[ 1, 0], [ 0, -1]],
function vertex_normal(sf, xi, yi) = [[ 0, -1], [-1, 0]],
let( [[-1, 0], [ 0, 1]],
normals = [ [[ 0, 1], [ 1, 0]]
for(i = [0:3]) ];
function vertex_normal_xs(sf, x_range, yi) =
let(sfyi = sf[yi])
[
for(xi = x_range)
let(v0 = sfyi[xi])
if(!is_undef(v0))
let( let(
v0 = sf[yi][xi], xyi = [xi, yi],
dir1 = dirs1[i], normals = [
dir2 = dirs2[i], for(dir = dirs)
v1 = sf[dir1.y + yi][dir1.x + xi], let(
v2 = sf[dir2.y + yi][dir2.x + xi] p1 = dir[0] + xyi,
v1 = sf[p1.y][p1.x],
p2 = dir[1] + xyi,
v2 = sf[p2.y][p2.x]
)
if(!(is_undef(v1) || is_undef(v2)))
_face_normal([v0, v1, v2])
]
) )
if(!(is_undef(v0) || is_undef(v1) || is_undef(v2))) sum(normals) / len(normals)
_face_normal([v0, v1, v2]) ];
]
)
sum(normals) / len(normals);
leng_points = len(points); leng_points = len(points);
leng_point0 = len(points[0]); leng_point0 = len(points[0]);
@@ -57,10 +67,7 @@ module sf_thicken(points, thickness, direction = "BOTH", convexity = 1) {
else { else {
vertex_normals = [ vertex_normals = [
for(y = [0:leng_points - 1]) for(y = [0:leng_points - 1])
[ vertex_normal_xs(points, [0:leng_point0 - 1], y)
for(x = [0:leng_point0 - 1])
vertex_normal(points, x, y)
]
]; ];
if(direction == "BOTH") { if(direction == "BOTH") {