From bc4eb4f6432b99a33d65cf401f546edcbabc611a Mon Sep 17 00:00:00 2001 From: Dealga McArdle Date: Sun, 16 May 2021 10:06:44 +0200 Subject: [PATCH 1/3] add file --- utils/modules/sdf_utils.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 utils/modules/sdf_utils.py diff --git a/utils/modules/sdf_utils.py b/utils/modules/sdf_utils.py new file mode 100644 index 000000000..9b66ef73b --- /dev/null +++ b/utils/modules/sdf_utils.py @@ -0,0 +1,32 @@ +import numpy as np + +def geometry_from_points(points, mode="python"): + """ + using sdf module from: https://github.com/fogleman/sdf + + f.ex: + f = sdf.sphere() + points = f.generate(samples=1200) # higher is slower, but more precise. + geom = geometry_from_points(points, mode="np") + + >>> geom.verts + >>> geom.tris + + input: + points: the direct output from `f.generate()` + mode: "np" (numpy), or "python" + output: + geom: with a `.verts` atribute and `.tris` + verts and tris are output in numpy arrays if the mode is "np", + else standard python lists. + """ + + geom = lambda: None + num_points = len(points) + if mode == "python": + geom.verts = [plist.tolist() for plist in points] + geom.tris = np.arange(0, num_points, 1).reshape((-1, 3)).tolist() + elif mode == "np": + geom.verts = np.array(points) + geom.tris = np.arange(0, num_points, 1).reshape((-1, 3)) + return geom \ No newline at end of file -- GitLab From 5a58945f6e91ee8e398b2bf6af6e368f60494f4c Mon Sep 17 00:00:00 2001 From: Dealga McArdle Date: Sun, 16 May 2021 10:14:07 +0200 Subject: [PATCH 2/3] add description --- utils/modules/sdf_utils.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/utils/modules/sdf_utils.py b/utils/modules/sdf_utils.py index 9b66ef73b..d2da6368a 100644 --- a/utils/modules/sdf_utils.py +++ b/utils/modules/sdf_utils.py @@ -4,14 +4,6 @@ def geometry_from_points(points, mode="python"): """ using sdf module from: https://github.com/fogleman/sdf - f.ex: - f = sdf.sphere() - points = f.generate(samples=1200) # higher is slower, but more precise. - geom = geometry_from_points(points, mode="np") - - >>> geom.verts - >>> geom.tris - input: points: the direct output from `f.generate()` mode: "np" (numpy), or "python" @@ -19,8 +11,31 @@ def geometry_from_points(points, mode="python"): geom: with a `.verts` atribute and `.tris` verts and tris are output in numpy arrays if the mode is "np", else standard python lists. + + usage in snlite: + + ''' + in scale v + out verts v + out faces s + ''' + + from sdf import * + from sverchok.utils.modules.sdf_utils import geometry_from_points + + f = box(2) & slab(z0=-0.5, z1=0.5).k(0.1) + f.scale((1, 0.5, 1)) + f -= cylinder(0.25).circular_array(6, 0.6).k(0.05) + + points = f.generate(samples=23200) + + geom = geometry_from_points(points, mode="np") + verts.append(geom.verts) + faces.append(geom.tris) + """ + geom = lambda: None num_points = len(points) if mode == "python": -- GitLab From d90df89afcb2c2355a4ca91cb061de28b4c527c9 Mon Sep 17 00:00:00 2001 From: Dealga McArdle Date: Sun, 16 May 2021 10:16:14 +0200 Subject: [PATCH 3/3] newline --- utils/modules/sdf_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/modules/sdf_utils.py b/utils/modules/sdf_utils.py index d2da6368a..77eb84d74 100644 --- a/utils/modules/sdf_utils.py +++ b/utils/modules/sdf_utils.py @@ -44,4 +44,4 @@ def geometry_from_points(points, mode="python"): elif mode == "np": geom.verts = np.array(points) geom.tris = np.arange(0, num_points, 1).reshape((-1, 3)) - return geom \ No newline at end of file + return geom -- GitLab