1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-12 09:44:16 +02:00
This commit is contained in:
Justin Lin
2021-09-22 16:22:09 +08:00
parent af9cfb16e4
commit 4eef2c6dde
2 changed files with 59 additions and 53 deletions

View File

@@ -0,0 +1,56 @@
use <__comm__/_pt3_hash.scad>;
use <util/map/hashmap.scad>;
use <util/map/hashmap_put.scad>;
use <util/map/hashmap_get.scad>;
use <experimental/tri_subdivide.scad>;
function _geom_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_pts_faces(points, radius) =
let(
number_of_buckets = ceil(sqrt(len(points)) * 1.5),
hash = function(p) _pt3_hash(p),
leng = len(points),
m_pts = _pimap_pts(
radius,
points,
leng,
hash,
hashmap(number_of_buckets = number_of_buckets)
),
faces = [
for(i = [0:3:leng - 3])
[
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)
]
]
)
[m_pts[1], faces];
function _geom_info(tris, radius, detail) =
let(
points = detail == 0 ? [for(tri = tris) each tri] : [
for(tri = tris)
each [for(t = tri_subdivide(tri, detail)) each t]
]
)
_geom_pts_faces(points, radius);
function _geom_info_quick(tris, radius, detail) =
let(
points = detail == 0 ? [for(tri = tris) each _geom_prj2sphere(tri, radius)] : [
for(tri = tris)
each [for(t = tri_subdivide(tri, detail)) each _geom_prj2sphere(t, radius)]
],
faces = [for(i = [0:3:len(points) - 3]) [i, i + 1, i + 2]]
)
[points, faces];

View File

@@ -1,55 +1,5 @@
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] : [
for(tri = tris)
each [for(t = tri_subdivide(tri, detail)) each t]
],
number_of_buckets = ceil(sqrt(len(points)) * 1.5),
hash = function(p) _pt3_hash(p),
leng = len(points),
m_pts = _pimap_pts(
radius,
points,
leng,
hash,
hashmap(number_of_buckets = number_of_buckets)
),
faces = [
for(i = [0:3:leng - 3])
[
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)
]
]
)
[m_pts[1], 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];
use <experimental/_impl/_geom_platonic_polyhedra.scad>;
function geom_icosahedron(radius, detail = 0, quick_mode = true) =
let(
@@ -70,6 +20,6 @@ function geom_icosahedron(radius, detail = 0, quick_mode = true) =
[for(i = face) icosahedron_points[i]]
]
)
quick_mode ? _geom_icosahedron_quick(icosahedron_points, icosahedron_faces, tris, radius, detail) :
_geom_icosahedron(icosahedron_points, icosahedron_faces, tris, radius, detail);
quick_mode ? _geom_info_quick(tris, radius, detail) :
_geom_info(tris, radius, detail);