mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-05 06:17:32 +02:00
performance improved
This commit is contained in:
@@ -1,13 +1,17 @@
|
|||||||
|
use <__comm__/_pt3_hash.scad>;
|
||||||
use <util/rand.scad>;
|
use <util/rand.scad>;
|
||||||
|
use <util/dedup.scad>;
|
||||||
|
use <util/map/hashmap.scad>;
|
||||||
|
use <util/map/hashmap_get.scad>;
|
||||||
use <noise/nz_worley3s.scad>;
|
use <noise/nz_worley3s.scad>;
|
||||||
use <experimental/geom_icosahedron.scad>;
|
use <experimental/geom_icosahedron.scad>;
|
||||||
|
|
||||||
radius = 30;
|
// radius = 30;
|
||||||
detail = 3;
|
// detail = 3;
|
||||||
amplitude = .1;
|
// amplitude = .05;
|
||||||
dist = "border"; // [euclidean, manhattan, chebyshev, border]
|
// dist = "border"; // [euclidean, manhattan, chebyshev, border]
|
||||||
|
|
||||||
worley_sphere(radius, detail, amplitude);
|
// worley_sphere(radius, detail, amplitude, dist);
|
||||||
|
|
||||||
module worley_sphere(radius, detail, amplitude, dist = "border", grid_w = undef, seed = undef) {
|
module worley_sphere(radius, detail, amplitude, dist = "border", grid_w = undef, seed = undef) {
|
||||||
gw = is_undef(grid_w) ? radius : grid_w;
|
gw = is_undef(grid_w) ? radius : grid_w;
|
||||||
@@ -15,14 +19,24 @@ module worley_sphere(radius, detail, amplitude, dist = "border", grid_w = undef,
|
|||||||
points_faces = geom_icosahedron(radius, detail);
|
points_faces = geom_icosahedron(radius, detail);
|
||||||
points = points_faces[0];
|
points = points_faces[0];
|
||||||
faces = points_faces[1];
|
faces = points_faces[1];
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
sd = is_undef(seed) ? rand() * 1000: seed;
|
sd = is_undef(seed) ? rand() * 1000: seed;
|
||||||
nz = nz_worley3s(points, sd, gw, dist);
|
noisy = nz_worley3s(deduped_pts, sd, gw, dist);
|
||||||
|
|
||||||
|
p_nz = hashmap([
|
||||||
|
for(i = [0:len(deduped_pts) - 1])
|
||||||
|
[deduped_pts[i], noisy[i][3]]
|
||||||
|
], hash = hash, number_of_buckets = number_of_buckets);
|
||||||
|
|
||||||
noisy_points = [
|
noisy_points = [
|
||||||
for(i = [0:len(nz) - 1])
|
for(p = points)
|
||||||
let(p = points[i])
|
let(nz = hashmap_get(p_nz, p, hash = hash))
|
||||||
p / norm(p) * (radius + nz[i][3] * amplitude)
|
p / norm(p) * (radius + nz * amplitude)
|
||||||
];
|
];
|
||||||
|
|
||||||
polyhedron(noisy_points, faces);
|
polyhedron(noisy_points, faces);
|
||||||
|
Reference in New Issue
Block a user