1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-01 04:20:27 +02:00

voronoi noise 3D first attempt

This commit is contained in:
Justin Lin
2020-03-29 18:42:14 +08:00
parent 368caa2d29
commit fae0991e21
2 changed files with 27 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
use <experimental/_impl/_nz_worley3_impl.scad>;
use <util/sort.scad>;
function _nz_voronoi3(p, seed, dim, m, n, o) =
let(
fcord = [floor(p[0] / m), floor(p[1] / n), floor(p[2] / o)],
nbrs = _neighbors(fcord, seed, dim, m, n, o),
dists = [
for(nbr = nbrs)
if(!is_undef(nbr[1])) // Here's a workaround for a weired undef problem. bug of 2019.05?
[norm(nbr - p)]
],
sorted = sort(dists)
)
sorted[1][0] - sorted[0][0];

View File

@@ -0,0 +1,12 @@
use <util/rand.scad>;
use <experimental/_impl/_nz_voronoi3_impl.scad>;
function nz_voronoi3(size, x, y, z, seed, dim = 2) =
let(
sd = 6 + (is_undef(seed) ? floor(rand(0, 256)) : seed % 256),
// m*n pixels per grid
m = size[0] / dim,
n = size[1] / dim,
o = size[2] / dim
)
_nz_voronoi3([x, y, z], sd, dim, m, n, o);