Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sverchok open subdiv #4590

Merged
merged 14 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ def draw_message(box, package, dependencies=None):
info(numba_d.message)
numba = None

pyOpenSubdiv_d = sv_dependencies["pyOpenSubdiv"] = SvDependency("pyOpenSubdiv","https://github.com/GeneralPancakeMSTR/pyOpenSubdivision")
pyOpenSubdiv_d.pip_installable = True
try:
import pyOpenSubdiv
pyOpenSubdiv_d.message = "pyOpenSubdiv package is available"
pyOpenSubdiv_d.module = pyOpenSubdiv
except ImportError:
pyOpenSubdiv_d.message = "sv: pyOpenSubdiv package is not available, Catmull-Clark subdivision will not be available"
info(pyOpenSubdiv_d.message)
pyOpenSubdiv = None

good_names = [d.package for d in sv_dependencies.values() if d.module is not None and d.package is not None]
if good_names:
info("sv: Dependencies available: %s.", ", ".join(good_names))
Expand Down
1 change: 1 addition & 0 deletions index.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@
## Modifier Make
LineConnectNodeMK2
---
SvOpenSubdivideNode
SvSubdivideNodeMK2
SvSubdivideToQuadsNode
SvOffsetLineNode
Expand Down
104 changes: 104 additions & 0 deletions nodes/modifier_change/opensubdivide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

import bpy
from bpy.props import IntProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode, match_long_repeat

# from sverchok.utils.modules.ctypes_pyOpenSubdiv import pyOpenSubdiv
# openSubdivide = pyOpenSubdiv

enable_module = False
try:
import pyOpenSubdiv
from pyOpenSubdiv.pysubdivision import pysubdivide
enable_module = True
except ModuleNotFoundError:
enable_module = False


from itertools import chain
import traceback
class SvOpenSubdivideNode(bpy.types.Node,SverchCustomTreeNode):
bl_idname = "SvOpenSubdivideNode"
bl_label = "OpenSubdiv"
bl_icon = 'OUTLINER_OB_EMPTY'
sv_icon = None

maxlevel : IntProperty(name='level',default=0,min=0,max=5,update=updateNode)

def sv_init(self,context):
self.inputs.new('SvStringsSocket', "Levels").prop_name='maxlevel'
self.inputs.new('SvVerticesSocket', "Vertices")
self.inputs.new('SvStringsSocket', "Faces")

self.outputs.new('SvVerticesSocket', "Vertices")
self.outputs.new('SvStringsSocket', "Edges")
self.outputs.new('SvStringsSocket', "Faces")
Durman marked this conversation as resolved.
Show resolved Hide resolved

def process(self):
if not enable_module:
raise Exception("The dependent library is not installed (pyOpenSubdiv).")

vert_sets = self.inputs['Vertices'].sv_get(default=[],deepcopy=False)
edges = []
face_sets = self.inputs['Faces'].sv_get(default=[],deepcopy=False)


if(vert_sets != [] and face_sets != []):
subdivision_levels = self.inputs["Levels"].sv_get()[0]

# This is definitely gonna crash.
# I think I'll take the "wait and see how" approach?
parameters = zip(*match_long_repeat([subdivision_levels,vert_sets,face_sets]))

new_meshes = {
'vertices':[],
'edges':[],
'faces':[]
}

for params in parameters:
subdivision_level = params[0]
vertices = params[1]
faces = params[2]
faceVerts = list(chain.from_iterable(faces))
vertsPerFace = [len(face) for face in faces]

new_mesh = pysubdivide(subdivision_level,vertices,faceVerts,vertsPerFace)

new_meshes['vertices'].append(new_mesh['vertices']) # ctypes implementation
new_meshes['edges'].append(new_mesh['edges'])
new_meshes['faces'].append(new_mesh['faces'])

self.outputs['Vertices'].sv_set(new_meshes['vertices'])
self.outputs['Edges'].sv_set(new_meshes['edges'])
self.outputs['Faces'].sv_set(new_meshes['faces'])

else:
self.outputs['Vertices'].sv_set(vertices)
self.outputs['Edges'].sv_set(edges)
self.outputs['Faces'].sv_set(faces)


def register():
bpy.utils.register_class(SvOpenSubdivideNode)

def unregister():
bpy.utils.unregister_class(SvOpenSubdivideNode)
1 change: 1 addition & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ def draw_freecad_ops():
draw_message(box, "circlify")
draw_message(box, "cython")
draw_message(box, "numba")
draw_message(box, "pyOpenSubdiv")

draw_freecad_ops()

Expand Down