diff --git a/node_scripts/SNLite_templates/demo/numpy_geometry_stacking.py b/node_scripts/SNLite_templates/demo/numpy_geometry_stacking.py new file mode 100644 index 0000000000000000000000000000000000000000..3b8370cb5a77a81a38b68d4cda17b588e47a1204 --- /dev/null +++ b/node_scripts/SNLite_templates/demo/numpy_geometry_stacking.py @@ -0,0 +1,30 @@ +""" +in p1 s d=0.3 n=2 +in p2 s d=0.7 n=2 +in vdivs s d=20 n=2 +in points s d=200 n=2 +out verts_out v +""" + +from numpy import vstack, arange, cos, sin, pi, tile + +r2 = 20 * p1 +r1 = 10 * p2 +theta = 1 / points +vtheta = 1 / vdivs +theta_2_PI = 2 * pi * theta + +V = arange(vdivs) +I = arange(points) +T = theta_2_PI * I + +Tx = tile(T, V.size) +Vx = V.repeat(T.size) +P = pi * ((vtheta * Vx) - 0.5) + +X = (r1 * cos(Tx) * cos(P)) + (r2 * cos(Tx)) +Y = (r1 * sin(Tx) * cos(P)) + (r2 * sin(Tx)) +Z = r1 * sin(P) + +v_points = vstack([X, Y, Z]).T.tolist() +verts_out.append(v_points) diff --git a/node_scripts/SNLite_templates/demo/numpy_sphere_fib.py b/node_scripts/SNLite_templates/demo/numpy_sphere_fib.py new file mode 100644 index 0000000000000000000000000000000000000000..b34c487ddbc3a89f4da2e0b864ece0fb185c9ff1 --- /dev/null +++ b/node_scripts/SNLite_templates/demo/numpy_sphere_fib.py @@ -0,0 +1,26 @@ +""" +in samples s d=400 n=2 +in rseed s d=4 n=2 +in mult s d=1.0 n=2 +out verts_out v +""" +import numpy as np +import math, random + +def fibonacci_sphere_np(samples, rseed): + indices = np.arange(samples) + rnd = 1. + random.seed(rseed) + rnd = random.random() * samples + offset = 2./samples + increment = math.pi * (3. - math.sqrt(5.)) + + y = ((indices * offset) - 1) + (offset / 2) + r = np.sqrt(1 - pow(y, 2)) + phi = ((indices + rnd) % samples) * increment + x = np.cos(phi) * r + z = np.sin(phi) * r + return (np.vstack([x,y,z])*mult).T.tolist() + +p = fibonacci_sphere_np(samples, rseed) +verts_out.extend([p]) diff --git a/node_scripts/SNLite_templates/demo/numpy_spiral_fib.py b/node_scripts/SNLite_templates/demo/numpy_spiral_fib.py new file mode 100644 index 0000000000000000000000000000000000000000..3610f434837b8e2a8cb33d684f9b136dad6d3688 --- /dev/null +++ b/node_scripts/SNLite_templates/demo/numpy_spiral_fib.py @@ -0,0 +1,18 @@ +""" +in num_points s d=100 n=2 +in dist_cen s d=22 n=2 +in scale_factor s d=0.13 n=2 +out verts v +""" +import numpy as np +from math import radians + +i = np.arange(dist_cen, num_points) +theta = i * radians(137.5) +r = np.sqrt(i) * scale_factor +X = np.cos(theta) * r +Y = np.sin(theta) * r +Z = np.zeros(i.size) +fverts = np.vstack([X, Y, Z]).T.tolist() + +verts.append(fverts) diff --git a/node_scripts/SNLite_templates/demo/recursive_subdivision.py b/node_scripts/SNLite_templates/demo/recursive_subdivision.py new file mode 100644 index 0000000000000000000000000000000000000000..e110d8285592b49b3a9049fdf6f9ad8c38931610 --- /dev/null +++ b/node_scripts/SNLite_templates/demo/recursive_subdivision.py @@ -0,0 +1,61 @@ +""" +in quad_verts v +in quad_faces s +in seed s d=1 n=2 +in random_factor s d=0.1 n=2 +in iterations s d=1 n=2 +out verts v +out faces s +""" + +from sverchok.utils.modules.geom_utils import interp_v3_v3v3 as lerp +from sverchok.utils.sv_mesh_utils import mesh_join +from sverchok.nodes.modifier_change.remove_doubles import remove_doubles +import random + +# loosly based on https://www.youtube.com/watch?v=GhquYJ9m1Oc + +sort = lambda vex, pox: [vex[i] for i in pox] + +def random_subdiv_mesh(verts_m, pols_m, iteration): + + verts, faces =[],[] + for pol in pols_m: + verts_out, faces_out = [], [] + new_quad = faces_out.append + + pts = sort(verts_m, pol) + X = 0.5 +(random.random() - 0.5) * random_factor + Y = 0.5 +(random.random() - 0.5) * random_factor + pos_a = lerp(pts[0], pts[1], Y) + pos_b = lerp(pts[1], pts[2], X) + pos_c = lerp(pts[3], pts[2], 1-Y) + pos_d = lerp(pts[0], pts[3], X) + pos_e = lerp(pos_d, pos_b, Y) + pos_f = lerp(pos_d, pos_b, 1-Y) + + # indices = 0, 1, 2, 3 + verts_out.extend(pts) + + # indices = 4, 5, 6, 7, 8, 9 + verts_out.extend([pos_a, pos_b, pos_c, pos_d, pos_e, pos_f]) + + new_quad([0, 4, 8, 7]) + new_quad([4, 1, 5, 8]) + new_quad([5, 2, 6, 9]) + new_quad([7, 9, 6, 3]) + faces.append(faces_out) + verts.append(verts_out) + + verts, _, faces = mesh_join(verts, [],faces) + if iteration <2 : + return verts,faces + else: + return random_subdiv_mesh(verts, faces, iteration - 1) + +if quad_verts and quad_faces: + random.seed(seed) + verts, faces = random_subdiv_mesh(quad_verts[0], quad_faces[0], iterations) + verts, _, faces, _, _ = remove_doubles(verts, faces, 1e-5, False) + verts = [verts] + faces = [faces]