1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-10 08:44:20 +02:00
This commit is contained in:
Justin Lin
2021-10-15 10:20:18 +08:00
parent 59ae93ba5f
commit 37c3a647a5

View File

@@ -1,14 +1,11 @@
function _tri_subdivide(points, detail) = function _tri_subdivide(points, detail) =
let( let(
rows = detail + 1, rows = detail + 1,
vc = points[2] - points[0], dr = (points[2] - points[0]) / rows,
vr = points[1] - points[0], dc = (points[1] - points[0]) / rows,
dr = vr / (detail + 1),
dc = vc / (detail + 1),
pts = [ pts = [
for(ri = [0:rows]) for(ri = [0:rows])
let(cols = rows - ri) for(ci = [0:rows - ri])
for(ci = [0:cols])
points[0] + ci * dc + ri * dr points[0] + ci * dc + ri * dr
], ],
ri_base = [for(ri = 0, acc = 0; ri <= rows; ri = ri + 1, acc = acc + rows - ri + 2) acc], ri_base = [for(ri = 0, acc = 0; ri <= rows; ri = ri + 1, acc = acc + rows - ri + 2) acc],
@@ -17,7 +14,6 @@ function _tri_subdivide(points, detail) =
for(ri = [0:rows - 1]) for(ri = [0:rows - 1])
let(cols = rows - ri - 1) let(cols = rows - ri - 1)
for(ci = [0:cols]) for(ci = [0:cols])
let(pre = 0)
each (ci == cols ? each (ci == cols ?
[ [
[idx(ci, ri), idx(ci, ri + 1), idx(ci + 1, ri)] [idx(ci, ri), idx(ci, ri + 1), idx(ci + 1, ri)]
@@ -32,17 +28,18 @@ function _tri_subdivide(points, detail) =
[pts, faces]; [pts, faces];
function _subdivide_project(points, faces, radius, detail) = function _subdivide_project(points, faces, radius, detail) =
detail == 0 ? [[for(p = points) p / norm(p) * radius], faces] :
let( let(
subdivided_all = [ subdivided_all = [
for(face = faces) for(face = faces)
_tri_subdivide([for(i = face) points[i]], detail) _tri_subdivide([for(i = face) points[i]], detail)
], ],
pts_number_per_tri = len(subdivided_all[0][0]),
flatten_points = [ flatten_points = [
for(pts_faces = subdivided_all) for(pts_faces = subdivided_all)
for(p = pts_faces[0]) for(p = pts_faces[0])
p / norm(p) * radius p / norm(p) * radius
], ],
pts_number_per_tri = len(subdivided_all[0][0]),
flatten_faces = [ flatten_faces = [
for(i = [0:len(subdivided_all) - 1]) for(i = [0:len(subdivided_all) - 1])
let(faces = subdivided_all[i][1]) let(faces = subdivided_all[i][1])