Skip to content

Instantly share code, notes, and snippets.

Forked from anonymous/
Last active August 29, 2015 14:02
Show Gist options
  • Save zeffii/93e6a8e001678f2fcba3 to your computer and use it in GitHub Desktop.
Save zeffii/93e6a8e001678f2fcba3 to your computer and use it in GitHub Desktop.
import bpy
import bmesh
import mathutils
from bmesh.ops import spin
from bpy.props import BoolProperty, FloatProperty, FloatVectorProperty
import math
from math import pi, radians
from node_s import *
from util import *
import sv_bmesh_utils
from sv_bmesh_utils import bmesh_from_pydata
def get_lathed_geometry(node, verts, edges, cent, axis, dvec, angle, steps):
bm = bmesh_from_pydata(verts, edges, [])
geom = bm.verts[:] + bm.edges[:]
bm, geom=geom, cent=cent, axis=axis,
dvec=dvec, angle=angle, steps=steps, use_duplicate=False)
if node.remove_doubles:
bmesh.ops.remove_doubles(bm, verts=bm.verts[:], dist=node.dist)
v = [[:] for v in bm.verts]
p = [[i.index for i in p.verts] for p in bm.faces[:]]
return v, p
class SvLatheNode(Node, SverchCustomTreeNode):
bl_idname = 'SvLatheNode'
bl_label = 'Sv Lathe Node'
remove_doubles = BoolProperty(
name='merge', description='Remove doubles', update=updateNode)
dist = FloatProperty(name="merge distance", default=0.0001, update=updateNode)
Degrees = FloatProperty(name="Degrees", default=360.0, update=updateNode)
Steps = IntProperty(name="Steps", default=20, update=updateNode)
cent = FloatVectorProperty(name='cent', size=3, update=updateNode)
dvec = FloatVectorProperty(name='dvec', size=3, update=updateNode)
axis = FloatVectorProperty(
name='axis', size=3, update=updateNode, default=(0, 0, 1))
def init(self, context):
# so many inputs!!'VerticesSocket', 'Verts', 'Verts')'StringsSocket', 'Edges', 'Edges')
# these have default props'VerticesSocket', 'cent', 'cent').prop_name = 'cent''VerticesSocket', 'axis', 'axis').prop_name = 'axis''VerticesSocket', 'dvec', 'dvec').prop_name = 'dvec''StringsSocket', 'Degrees', 'Degrees').prop_name = 'Degrees''StringsSocket', 'Steps', 'Steps').prop_name = 'Steps'
# outputs, sparse!'VerticesSocket', 'Verts', 'Verts')'StringsSocket', 'Poly', 'Poly')
def draw_buttons(self, context, layout):
row = layout.row(align=True)
row.prop(self, "remove_doubles", text="merge")
def nothing_to_process(self):
if not ('Poly' in self.outputs):
return True
if not (self.inputs['Verts'].links and self.outputs['Verts'].links):
return True
def update(self):
if self.nothing_to_process():
inputs = self.inputs
def get_socket(x, default):
links = inputs[x].links
if links:
r = SvGetSocketAnyType(self, inputs[x])
r = {'found': dataCorrect(r)}
r = {'generated': default}
return r
mverts = get_socket('Verts', [])
if 'generated' in mverts:
# not sure it ever reaches here
medges = get_socket('Edges', [])
mcent = get_socket('cent', [0, 0, 0])
maxis = get_socket('axis', [0, 0, 1])
mdvec = get_socket('dvec', [0, 0, 0])
mDegrees = get_socket('Degrees', 360.0)
mSteps = get_socket('Steps', 20)
verts_out, faces_out = [], []
for idx, Verts in enumerate(mverts['found']):
if not Verts:
final_values = {'verts': Verts}
if 'found' in medges:
final_values['edges'] = lastrepeat(...)
ceter = lastrepeat(...) if 'found' in mcent else mcent['generated']
final_values['cent'] = center
axis = lastrepeat(...) if 'found' in maxis else maxis['generated']
final_values['axis'] = axis
dvec = lastrepeat(...) if 'found' in mdvec else mdvec['generated']
final_values['dvec'] = dvec
angle = lastrepeat(...) if 'found' in mDegrees else mDegrees['generated']
final_values['angle'] = radians(angle)
steps = lastrepeat(...) if 'found' in mSteps else mSteps['generated']
final_values['steps'] = steps
v, p = get_lathed_geometry(self, **final_values)
SvSetSocketAnyType(self, 'Verts', verts_out)
SvSetSocketAnyType(self, 'Poly', faces_out)
def update_socket(self, context):
def register():
def unregister():
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment