[Bf-extensions-cvs] [83bdf81] master: curve extra objects: bounce spline, spirofit, catenary update
meta-androcto
noreply at git.blender.org
Tue Apr 25 12:55:19 CEST 2017
Commit: 83bdf81f5fda9d33960280d322207f361b74fe87
Author: meta-androcto
Date: Tue Apr 25 20:54:55 2017 +1000
Branches: master
https://developer.blender.org/rBA83bdf81f5fda9d33960280d322207f361b74fe87
curve extra objects: bounce spline, spirofit, catenary update
===================================================================
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 7be535a..f40c768 100644
--- a/add_curve_extra_objects/add_curve_spirofit_bouncespline.py
+++ b/add_curve_extra_objects/add_curve_spirofit_bouncespline.py
@@ -18,12 +18,12 @@
bl_info = {
- "name": "SpiroFit and BounceSpline",
+ "name": "SpiroFit, BounceSpline and Catenary",
"author": "Antonio Osprite, Liero, Atom, Jimmy Hazevoet",
"version": (0, 2, 0),
"blender": (2, 78, 0),
- "location": "Toolshelf > Misc Tab",
- "description": "SpiroFit and BounceSpline adds splines to Mesh",
+ "location": "Toolshelf > Create Tab",
+ "description": "SpiroFit and BounceSpline adds splines to selected mesh",
"warning": "",
"wiki_url": "",
"category": "Object",
@@ -37,6 +37,7 @@ from bpy.props import (
FloatProperty,
IntProperty,
)
+from bpy.types import Operator
from mathutils import (
Matrix,
Vector,
@@ -44,14 +45,14 @@ from mathutils import (
from math import (
sin,
cos,
- pi
+ pi,
+ sqrt,
+ pow
)
-from bpy.types import Operator
import random as r
-
# ------------------------------------------------------------
-#
+
def use_random_seed(seed):
r.seed(seed)
return
@@ -60,18 +61,26 @@ def use_random_seed(seed):
# Generate new curve object from given points
# ------------------------------------------------------------
-def add_curve_object(verts, matrix,
- x_ray=False,
- spline_type='BEZIER',
- spline_resolution=12,
- bevel=0.0,
- bevel_resolution=0,
- spline_random_radius=0.0):
-
- curve = bpy.data.curves.new('Spline','CURVE')
+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')
curve.dimensions = '3D'
spline = curve.splines.new(spline_type)
- cur = bpy.data.objects.new('Curve',curve)
+ cur = bpy.data.objects.new(spline_name,curve)
if spline_type == 'BEZIER':
spline.bezier_points.add(int(len(verts)-1))
@@ -80,6 +89,7 @@ def add_curve_object(verts, matrix,
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
else:
spline.points.add(int(len(verts)-1))
for i in range(len(verts)):
@@ -91,16 +101,44 @@ def add_curve_object(verts, matrix,
cur.data.fill_mode = 'FULL'
cur.data.bevel_depth = bevel
cur.data.bevel_resolution = bevel_resolution
- cur.matrix_world = matrix
- if x_ray:
+ 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
+ if x_ray is True:
cur.show_x_ray = x_ray
return
+#------------------------------------------------------------
+def draw_spline_settings(self, context):
+ layout = self.layout
+ col = layout.column(align=True)
+ col.prop(self, 'spline_type')
+ col.separator()
+ col.prop(self, 'resolution_u')
+ col.prop(self, 'bevel')
+ col.prop(self, 'bevel_res')
+ if self.spline_type == 'BEZIER':
+ col.prop(self, 'random_radius')
+ col.prop(self, 'extrude')
+ col.separator()
+ col.prop(self, 'twist_mode')
+ col.separator()
+ if self.twist_mode == 'TANGENT':
+ col.prop(self, 'twist_smooth')
+ col.prop(self, 'tilt')
+
# ------------------------------------------------------------
# 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
@@ -114,26 +152,16 @@ def spiral_point(step, radius, z_coord, spires, waves, wave_height, rndm):
return [x, y, z]
-# ray cast
def object_mapping_ray_cast(obj, vert, center, offset):
- intersections = []
ray = Vector(vert)
orig = Vector(center)
direction = ray - orig
poly = obj.data.polygons
- for f in poly:
- foo, hit, nor, index = obj.ray_cast(orig, direction)
- if hit:
- intersections.append(hit + offset * nor)
-
- if len(intersections) > 0:
- mapped = min([(distance(i, vert), i) for i in intersections])[1]
- else:
- mapped = orig
+ foo, hit, nor, index = obj.ray_cast(orig, direction)
+ mapped = hit + offset * nor
return [mapped[0], mapped[1], mapped[2]]
-# closest point
def object_mapping_closest_point(obj, vert, offset):
cpom = obj.closest_point_on_mesh(vert)
mapped = cpom[1] + cpom[2] * offset
@@ -141,15 +169,15 @@ def object_mapping_closest_point(obj, vert, offset):
def spirofit_spline(obj,
- spires=4,
spire_resolution=4,
+ spires=4,
+ offset=0.0,
waves=0,
wave_height=0.0,
rndm_spire=0.0,
- offset=0.0,
+ direction=False,
map_method='RAYCAST'):
- points = []
bb = obj.bound_box
bb_xmin = min([ v[0] for v in bb ])
bb_ymin = min([ v[1] for v in bb ])
@@ -163,20 +191,16 @@ def spirofit_spline(obj,
cx = (bb_xmax + bb_xmin) / 2.0
cy = (bb_ymax + bb_ymin) / 2.0
center = [cx, cy, bb_zmin]
-
- cp = spiral_point(bb_zmin, radius, bb_zmin, spires, waves, wave_height, 0)
- if map_method == 'RAYCAST':
- cp = object_mapping_ray_cast(obj, cp, center, offset)
- elif map_method == 'CLOSESTPOINT':
- cp = object_mapping_closest_point(obj, cp, offset)
+ points = []
steps = spires * spire_resolution
- for i in range(1, steps + 1):
+ for i in range(steps + 1):
t = bb_zmin + (2 * pi / steps) * i
z = bb_zmin + (float(height) / steps) * i
center = [cx, cy, z]
-
- cp = spiral_point(t, radius, z, spires, waves, wave_height, rndm_spire)
+ if direction is True:
+ t = -t
+ cp = spiral_point(-t, radius, z, spires, waves, wave_height, rndm_spire)
if map_method == 'RAYCAST':
cp = object_mapping_ray_cast(obj, cp, center, offset)
elif map_method == 'CLOSESTPOINT':
@@ -185,7 +209,6 @@ def spirofit_spline(obj,
points.append(cp)
return points
-
# ------------------------------------------------------------
class SpiroFitSpline(bpy.types.Operator):
@@ -195,107 +218,148 @@ class SpiroFitSpline(bpy.types.Operator):
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
map_method = bpy.props.EnumProperty(
- name="Mapping Method",
- default='CLOSESTPOINT',
- description="Mapping method",
- items=[('RAYCAST', 'Ray cast', 'Ray cast'),
- ('CLOSESTPOINT', 'Closest point', 'Closest point')]
- )
-
+ 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
+ )
spire_resolution = bpy.props.IntProperty(
- name="Spire Resolution",
- default=8,
- min=3,
- max=256,
- soft_max=128,
- description="Spire resolution 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 spire 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"
+ )
waves = bpy.props.IntProperty(
- name="Waves",
- default=0,
- min=0,
- description="Waves amount"
- )
+ name="Waves",
+ default=0,
+ min=0,
+ description="Waves amount"
+ )
wave_height = bpy.props.FloatProperty(
- name="Wave intensity",
- default=0.1,
- min=0.0,
- description="Wave intensity scale"
- )
+ name="Wave Intensity",
+ default=0.25,
+ min=0.0,
+ precision=3,
+ description="Wave intensity scale"
+ )
rndm_spire = bpy.props.FloatProperty(
- name="Randomize",
- default=0.0,
- min=0.0,
- description="Randomize spire"
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list