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

provide quick_mode

This commit is contained in:
Justin Lin
2021-09-08 08:36:33 +08:00
parent 23ed306148
commit c59fdc5f1d
2 changed files with 45 additions and 10 deletions

View File

@@ -1,8 +1,47 @@
use <__comm__/_pt3_hash.scad>;
use <util/dedup.scad>;
use <util/map/hashmap.scad>;
use <util/map/hashmap_get.scad>;
use <experimental/tri_subdivide.scad>; use <experimental/tri_subdivide.scad>;
function _prj2sphere(t, r) = [for(p = t) p / norm(p) * r]; function _prj2sphere(t, r) = [for(p = t) p / norm(p) * r];
function geom_icosahedron(radius, detail = 0) = function _geom_icosahedron(icosahedron_points, icosahedron_faces, tris, radius, detail) =
let(
points = detail == 0 ? [for(tri = tris) each tri] : [
for(tri = tris)
each [for(t = tri_subdivide(tri, detail)) each t]
],
number_of_buckets = ceil(sqrt(len(points))),
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),
faces = [
for(i = [0:3:len(points) - 3])
[
hashmap_get(m, points[i], hash = hash),
hashmap_get(m, points[i + 1], hash = hash),
hashmap_get(m, points[i + 2], hash = hash)
]
]
)
[pts, faces];
function _geom_icosahedron_quick(icosahedron_points, icosahedron_faces, tris, radius, detail) =
let(
points = detail == 0 ? [for(tri = tris) each _prj2sphere(tri, radius)] : [
for(tri = tris)
each [for(t = tri_subdivide(tri, detail)) each _prj2sphere(t, radius)]
],
faces = [for(i = [0:3:len(points) - 3]) [i, i + 1, i + 2]]
)
[points, faces];
function geom_icosahedron(radius, detail = 0, quick_mode = true) =
let( let(
t = (1 + sqrt(5)) / 2 , t = (1 + sqrt(5)) / 2 ,
icosahedron_points = [ icosahedron_points = [
@@ -19,12 +58,8 @@ function geom_icosahedron(radius, detail = 0) =
tris = [ tris = [
for(face = icosahedron_faces) for(face = icosahedron_faces)
[for(i = face) icosahedron_points[i]] [for(i = face) icosahedron_points[i]]
], ]
points = detail == 0 ? [for(tri = tris) each _prj2sphere(tri, radius)] : [
for(tri = tris)
each [for(t = tri_subdivide(tri, detail)) each _prj2sphere(t, radius)]
],
faces = [for(i = [0:3:len(points) - 3]) [i, i + 1, i + 2]]
) )
[points, faces]; quick_mode ? _geom_icosahedron_quick(icosahedron_points, icosahedron_faces, tris, radius, detail) :
_geom_icosahedron(icosahedron_points, icosahedron_faces, tris, radius, detail);

View File

@@ -1,6 +1,6 @@
use <experimental/geom_icosahedron.scad>; use <experimental/geom_icosahedron.scad>;
module icosahedron(radius, detail = 0) { module icosahedron(radius, detail = 0, quick_mode = true) {
points_faces = geom_icosahedron(radius, detail); points_faces = geom_icosahedron(radius, detail, quick_mode);
polyhedron(points_faces[0], points_faces[1]); polyhedron(points_faces[0], points_faces[1]);
} }