mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-03-14 02:59:42 +01:00
performance improved
This commit is contained in:
parent
5e7b5f1691
commit
ea36c97ac7
@ -1,11 +1,19 @@
|
||||
use <__comm__/_pt3_hash.scad>;
|
||||
use <util/dedup.scad>;
|
||||
use <util/map/hashmap.scad>;
|
||||
use <util/map/hashmap_put.scad>;
|
||||
use <util/map/hashmap_get.scad>;
|
||||
use <experimental/tri_subdivide.scad>;
|
||||
|
||||
function _prj2sphere(t, r) = [for(p = t) p / norm(p) * r];
|
||||
|
||||
function _pimap_pts(radius, points, leng, hash, m, deduped_pts = [], n = -1, i = 0) =
|
||||
i == leng ? [m, deduped_pts] :
|
||||
let(v = hashmap_get(m, points[i], hash = hash))
|
||||
is_undef(v) ?
|
||||
_pimap_pts(radius, points, leng, hash, hashmap_put(m, points[i], n + 1, hash = hash), concat(deduped_pts, [points[i] / norm(points[i]) * radius]), n + 1, i + 1) :
|
||||
_pimap_pts(radius, points, leng, hash, m, deduped_pts, n, i + 1);
|
||||
|
||||
function _geom_icosahedron(icosahedron_points, icosahedron_faces, tris, radius, detail) =
|
||||
let(
|
||||
points = detail == 0 ? [for(tri = tris) each tri] : [
|
||||
@ -13,23 +21,25 @@ function _geom_icosahedron(icosahedron_points, icosahedron_faces, tris, radius,
|
||||
each [for(t = tri_subdivide(tri, detail)) each t]
|
||||
],
|
||||
number_of_buckets = ceil(sqrt(len(points)) * 1.5),
|
||||
hash = _pt3_hash(number_of_buckets),
|
||||
deduped_pts = dedup(points, hash = hash, number_of_buckets = number_of_buckets),
|
||||
pts = [for(p = deduped_pts) p / norm(p) * radius],
|
||||
m = hashmap([
|
||||
for(i = [0:len(deduped_pts) - 1])
|
||||
[deduped_pts[i], i]
|
||||
], hash = hash, number_of_buckets = number_of_buckets),
|
||||
hash = _pt3_hash(number_of_buckets),
|
||||
leng = len(points),
|
||||
m_pts = _pimap_pts(
|
||||
radius,
|
||||
points,
|
||||
leng,
|
||||
hash,
|
||||
hashmap(number_of_buckets = number_of_buckets)
|
||||
),
|
||||
faces = [
|
||||
for(i = [0:3:len(points) - 3])
|
||||
for(i = [0:3:leng - 3])
|
||||
[
|
||||
hashmap_get(m, points[i], hash = hash),
|
||||
hashmap_get(m, points[i + 1], hash = hash),
|
||||
hashmap_get(m, points[i + 2], hash = hash)
|
||||
hashmap_get(m_pts[0], points[i], hash = hash),
|
||||
hashmap_get(m_pts[0], points[i + 1], hash = hash),
|
||||
hashmap_get(m_pts[0], points[i + 2], hash = hash)
|
||||
]
|
||||
]
|
||||
)
|
||||
[pts, faces];
|
||||
[m_pts[1], faces];
|
||||
|
||||
function _geom_icosahedron_quick(icosahedron_points, icosahedron_faces, tris, radius, detail) =
|
||||
let(
|
||||
|
Loading…
x
Reference in New Issue
Block a user