Guest User

Untitled

a guest
Oct 16th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18.  
  19. import bpy
  20. import mathutils
  21.  
  22. # from bpy.props import FloatProperty, BoolProperty
  23. from mathutils import Vector
  24. from mathutils.geometry import interpolate_bezier
  25.  
  26. from sverchok.node_tree import SverchCustomTreeNode
  27. from sverchok.data_structure import updateNode
  28.  
  29.  
  30. def get_points_bezier(spline, clean=True):
  31.  
  32. knots = spline.bezier_points
  33. if len(knots) < 2:
  34. return
  35.  
  36. # verts per segment
  37. r = spline.resolution_u + 1
  38.  
  39. # segments in spline
  40. segments = len(knots)
  41.  
  42. if not spline.use_cyclic_u:
  43. segments -= 1
  44.  
  45. master_point_list = []
  46. for i in range(segments):
  47. inext = (i + 1) % len(knots)
  48.  
  49. knot1 = knots[i].co
  50. handle1 = knots[i].handle_right
  51. handle2 = knots[inext].handle_left
  52. knot2 = knots[inext].co
  53.  
  54. bezier = knot1, handle1, handle2, knot2, r
  55. points = interpolate_bezier(*bezier)
  56. master_point_list.extend(points)
  57.  
  58. # some clean up to remove consecutive doubles, this could be smarter...
  59. if clean:
  60. old = master_point_list
  61. good = [v for i, v in enumerate(old[:-1]) if not old[i] == old[i + 1]]
  62. good.append(old[-1])
  63. return good
  64.  
  65. # makes edge keys, ensure cyclic
  66. Edges = [[i, i + 1] for i in range(n_verts - 1)]
  67. if spline.use_cyclic_u:
  68. Edges.append([i, 0])
  69.  
  70. return master_point_list, Edges
  71.  
  72.  
  73.  
  74. class SvCurveInputNode(bpy.types.Node, SverchCustomTreeNode):
  75. ''' Curve data in '''
  76. bl_idname = 'SvCurveInputNode'
  77. bl_label = 'Curve Input'
  78. bl_icon = 'CURVE'
  79.  
  80. def sv_init(self, context):
  81. ...
  82.  
  83. def draw_buttons(self, context, layout):
  84. ...
  85.  
  86. def process(self):
  87.  
  88. objects_in = self.objects.get()
  89. for obj in objects:
  90. # end early!
  91. if not obj.type == 'CURVE':
  92. return
  93.  
  94. for obj in objects:
  95.  
  96. m = obj.matrix_world
  97. mtrx.append(m[:])
  98. # spline = bpy.data.curves[0].splines[0]
  99. # points = get_points_bezier(spline)
  100.  
  101. for spline in obj.data.splines:
  102. verts, edges = get_points(spline, clean=True)
  103. edgs_out.append(edges)
  104. vers_out.append(verts)
  105. mtrx_out.append(obj.matrix_world[:])
  106.  
  107. continue
  108.  
  109.  
  110. def register():
  111. bpy.utils.register_class(SvCurveInputNode)
  112.  
  113.  
  114. def unregister():
  115. bpy.utils.unregister_class(SvCurveInputNode)
Add Comment
Please, Sign In to add comment