Skip to content

Commit

Permalink
icosphere recursived (#3993)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicdoval authored Mar 28, 2021
1 parent e71650a commit efc6c32
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 29 deletions.
63 changes: 36 additions & 27 deletions nodes/generator/icosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@

from math import pi, sqrt
import bpy
from bpy.props import IntProperty, FloatProperty, BoolVectorProperty
import bmesh
from bpy.props import IntProperty, FloatProperty, EnumProperty
from mathutils import Matrix, Vector

from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode, list_match_modes, list_match_func
from sverchok.utils.sv_bmesh_utils import bmesh_from_pydata, pydata_from_bmesh
from sverchok.data_structure import updateNode
from sverchok.utils.sv_bmesh_utils import numpy_data_from_bmesh
from sverchok.utils.math import from_cylindrical
from sverchok.utils.nodes_mixins.recursive_nodes import SvRecursiveNode


def icosahedron_cylindrical(r):

Expand Down Expand Up @@ -78,7 +80,7 @@ def icosahedron(r):
vertices = [from_cylindrical(rho, phi, z, 'radians') for rho, phi, z in vertices]
return vertices, edges, faces

class SvIcosphereNode(bpy.types.Node, SverchCustomTreeNode):
class SvIcosphereNode(bpy.types.Node, SverchCustomTreeNode, SvRecursiveNode):
"IcoSphere primitive"

bl_idname = 'SvIcosphereNode'
Expand Down Expand Up @@ -113,13 +115,18 @@ def get_subdivisions(self):
name = "Radius",
default=1.0, min=0.0,
update=updateNode)

list_match: EnumProperty(
name="List Match",
description="Behavior on different list lengths, object level",
items=list_match_modes, default="REPEAT",
update=updateNode)


# list_match: EnumProperty(
# name="List Match",
# description="Behavior on different list lengths, object level",
# items=list_match_modes, default="REPEAT",
# update=updateNode)
out_np: BoolVectorProperty(
name="Ouput Numpy",
description="Output NumPy arrays slows this node but may improve performance of nodes it is connected to",
default=(False, False, False),
size=3, update=updateNode)

def sv_init(self, context):
self['subdivisions'] = 2

Expand All @@ -133,22 +140,23 @@ def sv_init(self, context):
def draw_buttons_ext(self, context, layout):
layout.prop(self, "subdivisions_max")
layout.prop(self, "list_match")
layout.label(text="Ouput Numpy:")
r = layout.row(align=True)
for i in range(3):
r.prop(self, "out_np", index=i, text=self.outputs[i].name, toggle=True)

def process(self):
# return if no outputs are connected
if not any(s.is_linked for s in self.outputs):
return

subdivisions_s = self.inputs['Subdivisions'].sv_get()[0]
radius_s = self.inputs['Radius'].sv_get()[0]
def pre_setup(self):
for s in self.inputs:
s.nesting_level = 1
s.pre_processing = 'ONE_ITEM'

def process_data(self, params):
out_verts = []
out_edges = []
out_faces = []

objects = list_match_func[self.list_match]([subdivisions_s, radius_s])

for subdivisions, radius in zip(*objects):
for subdivisions, radius in zip(*params):
if subdivisions == 0:
# In this case we just return the icosahedron
verts, edges, faces = icosahedron(radius)
Expand All @@ -161,19 +169,20 @@ def process(self):
subdivisions = self.subdivisions_max

bm = bmesh.new()
bmesh.ops.create_icosphere(bm,
subdivisions = subdivisions,
diameter = radius)
verts, edges, faces = pydata_from_bmesh(bm)
bmesh.ops.create_icosphere(
bm,
subdivisions=subdivisions,
diameter=radius)

This comment has been minimized.

Copy link
@nortikin

nortikin Sep 21, 2021

Owner

radius

This comment has been minimized.

Copy link
@Durman

Durman Sep 22, 2021

Collaborator

We should support both API for a while.

This comment has been minimized.

Copy link
@nortikin

nortikin Sep 22, 2021

Owner

are there changes in 3,0,0? Sorry, in 3,0,0 it not radius, not works.

This comment has been minimized.

Copy link
@Durman

Durman Sep 22, 2021

Collaborator

Yes it is changes of Blender 3.0 API, not a bug.


verts, edges, faces, _ = numpy_data_from_bmesh(bm, self.out_np)
bm.free()

out_verts.append(verts)
out_edges.append(edges)
out_faces.append(faces)

self.outputs['Vertices'].sv_set(out_verts)
self.outputs['Edges'].sv_set(out_edges)
self.outputs['Faces'].sv_set(out_faces)
return out_verts, out_edges, out_faces


def register():
bpy.utils.register_class(SvIcosphereNode)
Expand Down
2 changes: 2 additions & 0 deletions nodes/modifier_change/subdivide_mk2.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ def process(self):
face_data_matched = numpy_full_list(face_data, len(faces)).tolist()
else:
face_data_matched = repeat_last_for_length(face_data, len(faces))
else:
face_data_matched =[]

bm = bmesh_from_pydata(
vertices, edges, faces,
Expand Down
3 changes: 1 addition & 2 deletions utils/sv_bmesh_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def add_mesh_to_bmesh(bm, verts, edges=None, faces=None, sv_index_name=None, upd

def numpy_data_from_bmesh(bm, out_np, face_data=None):
if out_np[0]:
verts = np.array([v.co[:] for v in bm.verts])
verts = np.array([v.co for v in bm.verts])
else:
verts = [v.co[:] for v in bm.verts]
if out_np[1]:
Expand Down Expand Up @@ -850,4 +850,3 @@ def recalc_normals(verts, edges, faces, loop=False):
verts, edges, faces = pydata_from_bmesh(bm)
bm.free()
return verts, edges, faces

0 comments on commit efc6c32

Please sign in to comment.