[Bf-extensions-cvs] [99da32df] master: curve extra objects: bounce sprofit catenary update thanks Jimmy Haze
meta-androcto
noreply at git.blender.org
Sat May 13 10:59:48 CEST 2017
Commit: 99da32df1a9500e8fe33360a40bd6e0cfbec1363
Author: meta-androcto
Date: Sat May 13 18:59:19 2017 +1000
Branches: master
https://developer.blender.org/rBA99da32df1a9500e8fe33360a40bd6e0cfbec1363
curve extra objects: bounce sprofit catenary update thanks 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 ad6c5485..b2895e72 100644
--- a/add_curve_extra_objects/add_curve_spirofit_bouncespline.py
+++ b/add_curve_extra_objects/add_curve_spirofit_bouncespline.py
@@ -35,6 +35,7 @@ from bpy.props import (
EnumProperty,
FloatProperty,
IntProperty,
+ StringProperty,
)
from bpy.types import Operator
from mathutils import (
@@ -53,98 +54,6 @@ import random as r
# ------------------------------------------------------------
-# Generate curve object from given points
-# ------------------------------------------------------------
-
-def add_curve_object(
- 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)
-
- spline.radius_interpolation = 'BSPLINE'
- spline.tilt_interpolation = 'BSPLINE'
-
- if spline_type == 'BEZIER':
- 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 += spline_radius * r.random()
- spline.bezier_points[i].tilt = radians(tilt)
- else:
- 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 = 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
- 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 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')
- 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')
- 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
@@ -154,39 +63,25 @@ def distance(v1, v2):
return d
-def spiral_point(step, radius, z_coord, spires, waves, wave_height, rndm):
+def spiral_point(step, radius, z_coord, spires, waves, wave_iscale, rndm):
x = radius * cos(spires * step) + (r.random() - 0.5) * rndm
y = radius * sin(spires * step) + (r.random() - 0.5) * rndm
- z = z_coord + (cos(waves * step * pi) * wave_height) + (r.random() - 0.5) * rndm
+ z = z_coord + (cos(waves * step * pi) * wave_iscale) + (r.random() - 0.5) * rndm
return [x, y, z]
-def object_mapping_ray_cast(obj, vert, center, offset):
- ray = Vector(vert)
- orig = Vector(center)
- direction = ray - orig
- foo, hit, nor, index = obj.ray_cast(orig, direction)
- mapped = hit + offset * nor
- return [mapped[0], mapped[1], mapped[2]]
-
-
-def object_mapping_closest_point(obj, vert, offset):
- cpom = obj.closest_point_on_mesh(vert)
- mapped = cpom[1] + cpom[2] * offset
- return [mapped[0], mapped[1], mapped[2]]
-
-
def spirofit_spline(obj,
spire_resolution=4,
spires=4,
offset=0.0,
waves=0,
- wave_height=0.0,
+ wave_iscale=0.0,
rndm_spire=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])
@@ -199,22 +94,25 @@ def spirofit_spline(obj,
height = bb_zmax - bb_zmin
cx = (bb_xmax + bb_xmin) / 2.0
cy = (bb_ymax + bb_ymin) / 2.0
- points = []
-
steps = spires * spire_resolution
+
for i in range(steps + 1):
t = bb_zmin + (2 * pi / steps) * i
z = bb_zmin + (float(height) / steps) * i
- center = [cx, cy, z]
- if direction is True:
+ if direction:
t = -t
- cp = spiral_point(-t, radius, z, spires, waves, wave_height, rndm_spire)
+ cp = spiral_point(t, radius, z, spires, waves, wave_iscale, rndm_spire)
+
if map_method == 'RAYCAST':
- cp = object_mapping_ray_cast(obj, cp, center, offset)
+ success, hit, nor, index = obj.ray_cast(Vector(cp), (Vector([cx, cy, z]) - Vector(cp)))
+ if success:
+ points.append((hit + offset * nor))
+
elif map_method == 'CLOSESTPOINT':
- cp = object_mapping_closest_point(obj, cp, offset)
+ success, hit, nor, index = obj.closest_point_on_mesh(cp)
+ if success:
+ points.append((hit + offset * nor))
- points.append(cp)
return points
@@ -224,54 +122,54 @@ class SpiroFitSpline(bpy.types.Operator):
bl_description = "Wrap selected mesh in a spiral"
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
- map_method = bpy.props.EnumProperty(
- name="Mapping Method",
+ map_method = EnumProperty(
+ name="Mapping",
default='RAYCAST',
description="Mapping method",
items=[('RAYCAST', 'Ray cast', 'Ray casting'),
('CLOSESTPOINT', 'Closest point', 'Closest point on mesh')]
)
- direction = bpy.props.BoolProperty(
+ direction = BoolProperty(
name="Direction",
description="Spire direction",
default=False
)
- spire_resolution = bpy.props.IntProperty(
+ spire_resolution = IntProperty(
name="Spire Resolution",
default=8,
min=3,
- max=256,
+ max=1024,
soft_max=128,
description="Number of steps for one turn"
)
- spires = bpy.props.IntProperty(
+ spires = IntProperty(
name="Spires",
default=4,
min=1,
- max=512,
- soft_max=256,
+ max=1024,
+ soft_max=128,
description="Number of turns"
)
- offset = bpy.props.FloatProperty(
+ offset = FloatProperty(
name="Offset",
default=0.0,
precision=3,
description="Use normal direction to offset spline"
)
- waves = bpy.props.IntProperty(
- name="Waves",
+ waves = IntProperty(
+ name="Wave",
default=0,
min=0,
- description="Waves amount"
+ description="Wave amount"
)
- wave_height = bpy.props.FloatProperty(
+ wave_iscale = FloatProperty(
name="Wave Intensity",
default=0.0,
min=0.0,
precision=3,
description="Wave intensity scale"
)
- rndm_spire = bpy.props.FloatProperty(
+ rndm_spire = FloatProperty(
name="Randomise",
default=0.0,
min=0.0,
@@ -279,53 +177,46 @@ class SpiroFitSpline(bpy.types.Operator):
description="Randomise spire"
)
- spline_name = bpy.props.StringProperty(
+ spline_name = StringProperty(
name="Name",
default="SpiroFit"
)
- spline_type = bpy.props.EnumProperty(
- name="Spline Type",
+ spline_type = EnumProperty(
+ name="Spline",
default='BEZIER',
description="Spline type",
items=[('POLY', 'Poly', 'Poly spline'),
('BEZIER', 'Bezier', 'Bezier spline')]
)
- resolution_u = bpy.props.IntProperty(
+ resolution_u = IntProperty(
name="Resolution U",
default=12,
min=0,
max=64,
description="Curve resolution u"
)
- bevel = bpy.props.FloatProperty(
+ bevel = FloatProperty(
name="Bevel Radius",
default=0.0,
min=0.0,
precision=3,
description="Bevel depth"
)
- bevel_res = bpy.props.IntProperty(
+ bevel_res =IntProperty(
name="Bevel Resolution",
default=0,
min=0,
max=32,
description="Bevel resolution"
)
- random_radius = bpy.props.FloatProperty(
- name="Randomise Radius",
- default=0.0,
- min=0.0,
- precision=3,
- description="Random radius amount"
- )
- extrude = bpy.props.FloatProperty(
+ extrude = FloatProperty(
name="Extrude",
default=0.0,
min=0.0,
precision=3,
description="Extrude amount"
)
- twist_mode = bpy.props.EnumProperty(
+ twist_mode = EnumProperty(
name="Twisting",
default='MINIMUM',
description="Twist method, type of
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list