mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-06 06:47:46 +02:00
use geom_isosphere to rewrite
This commit is contained in:
@@ -1,46 +1,29 @@
|
|||||||
use <sweep.scad>;
|
|
||||||
use <util/rand.scad>;
|
use <util/rand.scad>;
|
||||||
use <noise/nz_worley3s.scad>;
|
use <noise/nz_worley3s.scad>;
|
||||||
use <ptf/ptf_rotate.scad>;
|
use <experimental/geom_isosphere.scad>;
|
||||||
|
|
||||||
$fn = 192;
|
|
||||||
|
|
||||||
radius = 30;
|
radius = 30;
|
||||||
amplitude = 20;
|
detail = 3;
|
||||||
sample_scale = 0.05;
|
amplitude = .1;
|
||||||
dist = "border"; // [euclidean, manhattan, chebyshev, border]
|
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, 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];
|
||||||
|
|
||||||
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;
|
sd = is_undef(seed) ? rand() * 1000: seed;
|
||||||
a_step = 360 / $fn;
|
nz = nz_worley3s(points, sd, gw, dist);
|
||||||
|
|
||||||
sections = [
|
noisy_points = [
|
||||||
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)
|
|
||||||
|
|
||||||
];
|
|
||||||
|
|
||||||
nz = nz_worley3s(sections * sample_scale, sd, grid_w, dist);
|
|
||||||
noisy_sphere = [
|
|
||||||
for(i = [0:len(nz) - 1])
|
for(i = [0:len(nz) - 1])
|
||||||
let(
|
let(p = points[i])
|
||||||
p = sections[i],
|
p / norm(p) * (radius + nz[i][3] * amplitude)
|
||||||
p2d = [p[0], p[1]],
|
|
||||||
noisyP = p2d + p2d / norm(p2d) * nz[i][3] * amplitude
|
|
||||||
)
|
|
||||||
[noisyP[0], noisyP[1], p[2]]
|
|
||||||
];
|
];
|
||||||
|
|
||||||
sweep([
|
polyhedron(noisy_points, faces);
|
||||||
for(i = [0:$fn:len(noisy_sphere) - $fn])
|
|
||||||
[
|
|
||||||
for(j = [0:$fn - 1])
|
|
||||||
noisy_sphere[i + j]
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user