1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-04-13 18:51:53 +02:00

use geom_isosphere to rewrite

This commit is contained in:
Justin Lin 2021-09-07 10:14:45 +08:00
parent e5af7b3027
commit 69e2a79488

View File

@ -1,46 +1,29 @@
use <sweep.scad>;
use <util/rand.scad>;
use <noise/nz_worley3s.scad>;
use <ptf/ptf_rotate.scad>;
$fn = 192;
use <experimental/geom_isosphere.scad>;
radius = 30;
amplitude = 20;
sample_scale = 0.05;
detail = 3;
amplitude = .1;
dist = "border"; // [euclidean, manhattan, chebyshev, border]
grid_w = 1;
worley_sphere(radius, amplitude, sample_scale, grid_w, dist);
worley_sphere(radius, detail, amplitude);
module worley_sphere(radius, amplitude, sample_scale, grid_w = 1, dist = "border", angle_boundary = 180 / $fn, seed = undef) {
sd = is_undef(seed) ? rand() * 1000: seed;
a_step = 360 / $fn;
module worley_sphere(radius, detail, amplitude, dist = "border", grid_w = undef, seed = undef) {
gw = is_undef(grid_w) ? radius : grid_w;
points_faces = geom_isosphere(radius, detail);
points = points_faces[0];
faces = points_faces[1];
sd = is_undef(seed) ? rand() * 1000: seed;
nz = nz_worley3s(points, sd, gw, dist);
sections = [
for(a = [-90 + angle_boundary:a_step:90 - angle_boundary])
let(p = [radius * cos(-a), 0, radius * sin(-a)])
for(a = [0:a_step:360 - a_step])
ptf_rotate(p, a)
noisy_points = [
for(i = [0:len(nz) - 1])
let(p = points[i])
p / norm(p) * (radius + nz[i][3] * amplitude)
];
nz = nz_worley3s(sections * sample_scale, sd, grid_w, dist);
noisy_sphere = [
for(i = [0:len(nz) - 1])
let(
p = sections[i],
p2d = [p[0], p[1]],
noisyP = p2d + p2d / norm(p2d) * nz[i][3] * amplitude
)
[noisyP[0], noisyP[1], p[2]]
];
sweep([
for(i = [0:$fn:len(noisy_sphere) - $fn])
[
for(j = [0:$fn - 1])
noisy_sphere[i + j]
]
]);
polyhedron(noisy_points, faces);
}