[Bf-extensions-cvs] [5911df5] master: Curve Extra Objects: update bounce splines by Jimmy Haze

meta-androcto noreply at git.blender.org
Sun May 7 11:51:47 CEST 2017


Commit: 5911df5ca356dc09a15aed29642f05296df09c84
Author: meta-androcto
Date:   Sun May 7 19:51:22 2017 +1000
Branches: master
https://developer.blender.org/rBA5911df5ca356dc09a15aed29642f05296df09c84

Curve Extra Objects: update bounce splines by Jimmy Haze

===================================================================

M	add_curve_extra_objects/add_curve_spirofit_bouncespline.py

===================================================================

diff --git a/add_curve_extra_objects/add_curve_spirofit_bouncespline.py b/add_curve_extra_objects/add_curve_spirofit_bouncespline.py
index f40c768..ad6c548 100644
--- a/add_curve_extra_objects/add_curve_spirofit_bouncespline.py
+++ b/add_curve_extra_objects/add_curve_spirofit_bouncespline.py
@@ -23,99 +23,108 @@ bl_info = {
     "version": (0, 2, 0),
     "blender": (2, 78, 0),
     "location": "Toolshelf > Create Tab",
-    "description": "SpiroFit and BounceSpline adds splines to selected mesh",
+    "description": "SpiroFit, BounceSpline and Catenary adds splines to selected mesh or objects",
     "warning": "",
     "wiki_url": "",
     "category": "Object",
-}
-
+    }
 
 import bpy
 from bpy.props import (
-        BoolProperty,
-        EnumProperty,
-        FloatProperty,
-        IntProperty,
-        )
+    BoolProperty,
+    EnumProperty,
+    FloatProperty,
+    IntProperty,
+    )
 from bpy.types import Operator
 from mathutils import (
-        Matrix,
-        Vector,
-        )
+    Matrix,
+    Vector,
+    )
 from math import (
-        sin,
-        cos,
-        pi,
-        sqrt,
-        pow
-        )
+    sin,
+    cos,
+    pi,
+    sqrt,
+    pow,
+    radians
+    )
 import random as r
 
-# ------------------------------------------------------------
-
-def use_random_seed(seed):
-    r.seed(seed)
-    return
 
 # ------------------------------------------------------------
-# Generate new curve object from given points
+# Generate curve object from given points
 # ------------------------------------------------------------
 
 def add_curve_object(
-                verts, 
-                matrix,
-                spline_name="Spline",
-                x_ray=False,
-                spline_type='BEZIER',
-                spline_resolution=12,
-                bevel=0.0,
-                bevel_resolution=0,
-                extrude=0.0,
-                spline_random_radius=0.0,
-                twist_mode='MINIMUM',
-                twist_smooth=0.0,
-                tilt=0.0
-                ):
-
-    curve = bpy.data.curves.new(spline_name,'CURVE')
+            verts,
+            matrix,
+            spline_name="Spline",
+            spline_type='BEZIER',
+            resolution_u=12,
+            bevel=0.0,
+            bevel_resolution=0,
+            extrude=0.0,
+            spline_radius=0.0,
+            twist_mode='MINIMUM',
+            twist_smooth=0.0,
+            tilt=0.0,
+            x_ray=False
+            ):
+
+    curve = bpy.data.curves.new(spline_name, 'CURVE')
     curve.dimensions = '3D'
     spline = curve.splines.new(spline_type)
-    cur = bpy.data.objects.new(spline_name,curve)
+    cur = bpy.data.objects.new(spline_name, curve)
+
+    spline.radius_interpolation = 'BSPLINE'
+    spline.tilt_interpolation = 'BSPLINE'
 
     if spline_type == 'BEZIER':
-        spline.bezier_points.add(int(len(verts)-1))
+        spline.bezier_points.add(int(len(verts) - 1))
         for i in range(len(verts)):
             spline.bezier_points[i].co = verts[i]
             spline.bezier_points[i].handle_right_type = 'AUTO'
             spline.bezier_points[i].handle_left_type = 'AUTO'
-            spline.bezier_points[i].radius += r.random() * spline_random_radius
-            spline.bezier_points[i].tilt = tilt 
+            spline.bezier_points[i].radius += spline_radius * r.random()
+            spline.bezier_points[i].tilt = radians(tilt)
     else:
-        spline.points.add(int(len(verts)-1))
+        spline.points.add(int(len(verts) - 1))
         for i in range(len(verts)):
             spline.points[i].co = verts[i][0], verts[i][1], verts[i][2], 1
 
     bpy.context.scene.objects.link(cur)
     cur.data.use_uv_as_generated = True
-    cur.data.resolution_u = spline_resolution
+    cur.data.resolution_u = resolution_u
     cur.data.fill_mode = 'FULL'
     cur.data.bevel_depth = bevel
     cur.data.bevel_resolution = bevel_resolution
     cur.data.extrude = extrude
     cur.data.twist_mode = twist_mode
     cur.data.twist_smooth = twist_smooth
-    if matrix is None:
-        cur.select = True
-        bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')
-        cur.select = False
-    else:
-        cur.matrix_world = matrix
+    cur.matrix_world = matrix
+    bpy.context.scene.objects.active = cur
+    cur.select = True
     if x_ray is True:
         cur.show_x_ray = x_ray
     return
 
-#------------------------------------------------------------
-def draw_spline_settings(self, context):
+
+def move_origin_to_start():
+    active = bpy.context.active_object
+    spline = active.data.splines[0]
+    if spline.type == 'BEZIER':
+        start = active.matrix_world * spline.bezier_points[0].co
+    else:
+        start = active.matrix_world * spline.points[0].co
+        start = start[:-1]
+    cursor = bpy.context.scene.cursor_location.copy()
+    bpy.context.scene.cursor_location = start
+    bpy.ops.object.origin_set(type='ORIGIN_CURSOR')
+    bpy.context.scene.cursor_location = cursor
+
+
+def draw_spline_settings(self):
     layout = self.layout
     col = layout.column(align=True)
     col.prop(self, 'spline_type')
@@ -131,15 +140,15 @@ def draw_spline_settings(self, context):
     col.separator()
     if self.twist_mode == 'TANGENT':
         col.prop(self, 'twist_smooth')
-    col.prop(self, 'tilt')
+    if self.spline_type == 'BEZIER':
+        col.prop(self, 'tilt')
 
 
 # ------------------------------------------------------------
+# "Build a spiral that fit the active object"
 # Spirofit, original blender 2.45 script by: Antonio Osprite
 # http://www.kino3d.com/forum/viewtopic.php?t=5374
 # ------------------------------------------------------------
-# Build a spiral that fit the active object
-
 def distance(v1, v2):
     d = (Vector(v1) - Vector(v2)).length
     return d
@@ -156,7 +165,6 @@ def object_mapping_ray_cast(obj, vert, center, offset):
     ray = Vector(vert)
     orig = Vector(center)
     direction = ray - orig
-    poly = obj.data.polygons
     foo, hit, nor, index = obj.ray_cast(orig, direction)
     mapped = hit + offset * nor
     return [mapped[0], mapped[1], mapped[2]]
@@ -169,28 +177,28 @@ def object_mapping_closest_point(obj, vert, offset):
 
 
 def spirofit_spline(obj,
-                    spire_resolution=4,
-                    spires=4,
-                    offset=0.0,
-                    waves=0,
-                    wave_height=0.0,
-                    rndm_spire=0.0,
-                    direction=False,
-                    map_method='RAYCAST'):
+            spire_resolution=4,
+            spires=4,
+            offset=0.0,
+            waves=0,
+            wave_height=0.0,
+            rndm_spire=0.0,
+            direction=False,
+            map_method='RAYCAST'
+            ):
 
     bb = obj.bound_box
-    bb_xmin = min([ v[0] for v in bb ])
-    bb_ymin = min([ v[1] for v in bb ])
-    bb_zmin = min([ v[2] for v in bb ])
-    bb_xmax = max([ v[0] for v in bb ])
-    bb_ymax = max([ v[1] for v in bb ])
-    bb_zmax = max([ v[2] for v in bb ])
+    bb_xmin = min([v[0] for v in bb])
+    bb_ymin = min([v[1] for v in bb])
+    bb_zmin = min([v[2] for v in bb])
+    bb_xmax = max([v[0] for v in bb])
+    bb_ymax = max([v[1] for v in bb])
+    bb_zmax = max([v[2] for v in bb])
 
     radius = distance([bb_xmax, bb_ymax, bb_zmin], [bb_xmin, bb_ymin, bb_zmin]) / 2.0
     height = bb_zmax - bb_zmin
     cx = (bb_xmax + bb_xmin) / 2.0
     cy = (bb_ymax + bb_ymin) / 2.0
-    center = [cx, cy, bb_zmin]
     points = []
 
     steps = spires * spire_resolution
@@ -209,164 +217,201 @@ def spirofit_spline(obj,
         points.append(cp)
     return points
 
-# ------------------------------------------------------------
 
 class SpiroFitSpline(bpy.types.Operator):
     bl_idname = "object.add_spirofit_spline"
     bl_label = "SpiroFit"
-    bl_description="Wrap selected mesh in a spiral"
+    bl_description = "Wrap selected mesh in a spiral"
     bl_options = {'REGISTER', 'UNDO', 'PRESET'}
 
     map_method = bpy.props.EnumProperty(
-            name="Mapping Method",
-            default='RAYCAST',
-            description="Mapping method",
-            items=[('RAYCAST', 'Ray cast', 'Ray casting'),
-                    ('CLOSESTPOINT', 'Closest point', 'Closest point on mesh')]
-            )
+        name="Mapping Method",
+        default='RAYCAST',
+        description="Mapping method",
+        items=[('RAYCAST', 'Ray cast', 'Ray casting'),
+               ('CLOSESTPOINT', 'Closest point', 'Closest point on mesh')]
+        )
     direction = bpy.props.BoolProperty(
-            name="Direction",
-            description="Spire direction",
-            default=False
-            )
+        name="Direction",
+        description="Spire direction",
+        default=False
+        )
     spire_resolution = bpy.props.IntProperty(
-            name="Spire Resolution",
-            default=8,
-            min=3,
-            max=256,
-            soft_max=128,
-            description="Number of steps for one turn"
-            )
+        name="Spire Resolution",
+        default=8,
+        min=3,
+        max=256,
+        soft_max=128,
+        description="Number of steps for one turn"
+        )
     spires = bpy.props.IntProperty(
-            name="Spires",
-            default=4,
-            min=1,
-            max=512,
-            soft_max=256,
-            description="Number of turns"
-            )
+        name="Spires",
+        default=4,
+        min=1,
+        max=512,
+        soft_max=256,
+        description="Number of turns"
+        )
     offset = bpy.props.FloatProperty(
-            name="Offset",
-            default=0.0,
-            precision=3,
-            description="Use normal direction to offset spline"
-            )
+        name="Offset",
+        default=0.0,
+        precision=3,
+        description="Use normal direction to offset spline"
+        )
     waves = bpy.props.IntProperty(
-            name="Waves",
-            default=0,
-            min=0,
-            description="Waves amount"
-            )
+        name="Waves",
+        default=0,
+        min=0,
+        description="Waves amount"
+     

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list