1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 14:18:13 +01:00

optimization

This commit is contained in:
Justin Lin 2022-05-05 15:54:08 +08:00
parent 88801575e8
commit 3fd7fd60d9

View File

@ -1,45 +1,44 @@
function _tri_subdivide(points, detail) = function _tri_subdivide_pts(points, radius, rows) =
let( let(
rows = detail + 1,
p0 = points[0], p0 = points[0],
basis = [points[2] - p0, points[1] - p0] / rows, basis = [points[2] - p0, points[1] - p0] / rows
pts = [
for(ri = [0:rows], ci = [0:rows - ri])
p0 + [ri, ci] * basis
],
ri_base = [for(ri = 0, row_2 = rows + 2; ri <= rows; ri = ri + 1) ri * row_2 - ri * (ri + 1) * 0.5],
faces = [
for(ri = [0:rows - 1], base_i = ri_base[ri], base_i1 = ri_base[ri + 1])
let(cols = rows - ri - 1)
for(ci = [0:cols])
if(ci != cols)
each [
[ci + 1 + base_i, ci + base_i1, ci + base_i],
[ci + 1 + base_i1, ci + base_i1, ci + 1 + base_i]
]
else
[ci + 1 + base_i, ci + base_i1, ci + base_i]
]
) )
[pts, faces]; [
for(ri = [0:rows], ci = [0:rows - ri])
let(p = p0 + [ri, ci] * basis)
radius * p / norm(p)
];
function _tri_subdivide_faces(rows) =
let(
ri_base = [for(ri = 0, row_2 = rows + 2; ri <= rows; ri = ri + 1) ri * row_2 - ri * (ri + 1) * 0.5]
)
[
for(ri = [0:rows - 1], base_i = ri_base[ri], base_i1 = ri_base[ri + 1])
let(cols = rows - ri - 1)
for(ci = [0:cols])
if(ci != cols)
each [
[ci + 1 + base_i, ci + base_i1, ci + base_i],
[ci + 1 + base_i1, ci + base_i1, ci + 1 + base_i]
]
else
[ci + 1 + base_i, ci + base_i1, ci + base_i]
];
function _subdivide_project(points, faces, radius, detail) = function _subdivide_project(points, faces, radius, detail) =
detail == 0 ? [[for(p = points) p / norm(p) * radius], faces] : detail == 0 ? [points * radius / norm(points[0]), faces] :
let( let(
subdivided_all = [ rows = detail + 1,
subdivided_pts = [
for(face = faces) for(face = faces)
_tri_subdivide([for(i = face) points[i]], detail) each _tri_subdivide_pts([for(i = face) points[i]], radius, rows)
], ],
flatten_points = [ pts_number_per_tri = (rows + 1) * (rows + 2) / 2,
for(pts_faces = subdivided_all, p = pts_faces[0]) subdivided_faces = _tri_subdivide_faces(rows),
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(faces) - 1], face = subdivided_faces)
let(faces = subdivided_all[i][1], off = [i, i, i] * pts_number_per_tri) face + [i, i, i] * pts_number_per_tri
for(face = faces)
face + off
] ]
) )
[flatten_points, flatten_faces]; [subdivided_pts, flatten_faces];