Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormeta-androcto <meta.androcto1@gmail.com>2017-05-13 11:59:19 +0300
committermeta-androcto <meta.androcto1@gmail.com>2017-05-13 11:59:19 +0300
commit99da32df1a9500e8fe33360a40bd6e0cfbec1363 (patch)
tree662c277875641f832334de48b194e838db65388d /add_curve_extra_objects
parent8d5a642f0bd56124d567f56921eb9d4b39de0bfc (diff)
curve extra objects: bounce sprofit catenary update thanks Jimmy Haze
Diffstat (limited to 'add_curve_extra_objects')
-rw-r--r--add_curve_extra_objects/add_curve_spirofit_bouncespline.py480
1 files changed, 228 insertions, 252 deletions
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 tilt calculation",
@@ -333,41 +224,48 @@ class SpiroFitSpline(bpy.types.Operator):
('MINIMUM', "Minimum", 'Minimum'),
('TANGENT', "Tangent", 'Tangent')]
)
- twist_smooth = bpy.props.FloatProperty(
+ twist_smooth = FloatProperty(
name="Smooth",
default=0.0,
min=0.0,
precision=3,
description="Twist smoothing amount for tangents"
)
- tilt = bpy.props.FloatProperty(
+ tilt = FloatProperty(
name="Tilt",
default=0.0,
precision=3,
description="Spline handle tilt"
)
- x_ray = bpy.props.BoolProperty(
+ random_radius = FloatProperty(
+ name="Randomise",
+ default=0.0,
+ min=0.0,
+ precision=3,
+ description="Randomise radius of spline controlpoints"
+ )
+ x_ray = BoolProperty(
name="X-Ray",
- default=True,
- description="Make the object draw in front of others"
+ default=False,
+ description="X-Ray - make the object draw in front of others"
)
- random_seed = bpy.props.IntProperty(
+ random_seed = IntProperty(
name="Random Seed",
default=1,
min=0,
description="Random seed number"
)
- origin_to_start = bpy.props.BoolProperty(
+ origin_to_start = BoolProperty(
name="Origin at Start",
description="Set origin at first point of spline",
default=False
)
- refresh = bpy.props.BoolProperty(
+ refresh = BoolProperty(
name="Refresh",
description="Refresh spline",
default=False
)
- auto_refresh = bpy.props.BoolProperty(
+ auto_refresh = BoolProperty(
name="Auto",
description="Auto refresh spline",
default=True
@@ -377,18 +275,15 @@ class SpiroFitSpline(bpy.types.Operator):
layout = self.layout
col = layout.column(align=True)
row = col.row(align=True)
- row.prop(self, 'x_ray', toggle=True)
- row.separator()
if self.auto_refresh is False:
self.refresh = False
elif self.auto_refresh is True:
self.refresh = True
- row.prop(self, 'auto_refresh', toggle=True, icon='AUTO', text="")
- row.prop(self, 'refresh', toggle=True, icon='FILE_REFRESH', text="")
- row.separator()
- row.prop(self, 'origin_to_start', toggle=True, icon='MANIPUL', text="")
- row.separator()
- row.operator('object.add_spirofit_spline', text="Add New")
+ row.prop(self, 'auto_refresh', toggle=True, icon='AUTO', icon_only=True)
+ row.prop(self, 'refresh', toggle=True, icon='FILE_REFRESH', icon_only=True)
+ row.operator('object.add_spirofit_spline', text="Add")
+ row.prop(self, 'x_ray', toggle=True, icon_only=True, icon='RESTRICT_VIEW_OFF')
+ row.prop(self, 'origin_to_start', toggle=True, icon='CURVE_DATA', icon_only=True)
col = layout.column(align=True)
col.prop(self, 'spline_name')
@@ -401,10 +296,9 @@ class SpiroFitSpline(bpy.types.Operator):
row.prop(self, 'direction', toggle=True, text="", icon='ARROW_LEFTRIGHT')
col.prop(self, 'offset')
col.prop(self, 'waves')
- col.prop(self, 'wave_height')
+ col.prop(self, 'wave_iscale')
col.prop(self, 'rndm_spire')
col.prop(self, 'random_seed')
-
draw_spline_settings(self)
@@ -441,7 +335,7 @@ class SpiroFitSpline(bpy.types.Operator):
self.spires,
self.offset,
self.waves,
- self.wave_height,
+ self.wave_iscale,
self.rndm_spire,
self.direction,
self.map_method
@@ -512,7 +406,7 @@ def bounce_spline(obj,
for ray in range(extra + 1):
end += noise(ang_noise)
try:
- foo, hit, nor, index = obj.ray_cast(start, end * dist)
+ hit, nor, index = obj.ray_cast(start, end * dist)[-3:]
except:
index = -1
if index != -1:
@@ -531,89 +425,80 @@ class BounceSpline(bpy.types.Operator):
bl_description = "Fill selected mesh with a spline"
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
- bounce_number = bpy.props.IntProperty(
+ bounce_number = IntProperty(
name="Bounces",
- default=500,
+ default=1000,
min=1,
- max=99999,
- soft_max=9999,
+ max=100000,
+ soft_max=10000,
description="Number of bounces"
)
- ang_noise = bpy.props.FloatProperty(
+ ang_noise = FloatProperty(
name="Angular Noise",
default=0.25,
min=0.0,
precision=3,
description="Add some noise to ray direction"
)
- offset = bpy.props.FloatProperty(
+ offset = FloatProperty(
name="Offset",
default=0.0,
precision=3,
description="Use normal direction to offset spline"
)
- extra = bpy.props.IntProperty(
+ extra = IntProperty(
name="Extra",
default=50,
min=0,
max=1000,
- soft_min=0,
- soft_max=500,
description="Number of extra tries if it fails to hit mesh"
)
- active_face = bpy.props.BoolProperty(
+ active_face = BoolProperty(
name="Active Face",
default=False,
description="Starts from active face or a random one"
)
- spline_name = bpy.props.StringProperty(
+ spline_name = StringProperty(
name="Name",
default="BounceSpline"
)
- 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 tilt calculation",
@@ -621,63 +506,66 @@ class BounceSpline(bpy.types.Operator):
('MINIMUM', "Minimum", 'Minimum'),
('TANGENT', "Tangent", 'Tangent')]
)
- twist_smooth = bpy.props.FloatProperty(
+ twist_smooth = FloatProperty(
name="Smooth",
default=0.0,
min=0.0,
precision=3,
description="Twist smoothing amount for tangents"
)
- tilt = bpy.props.FloatProperty(
+ tilt = FloatProperty(
name="Tilt",
default=0.0,
precision=3,
description="Spline handle tilt"
)
- x_ray = bpy.props.BoolProperty(
+ random_radius = FloatProperty(
+ name="Randomise",
+ default=0.0,
+ min=0.0,
+ precision=3,
+ description="Randomise radius of spline controlpoints"
+ )
+ x_ray = BoolProperty(
name="X-Ray",
- default=True,
- description="Make the object draw in front of others"
+ default=False,
+ description="X-Ray - make the object draw in front of others"
)
- random_seed = bpy.props.IntProperty(
+ random_seed = IntProperty(
name="Random Seed",
default=1,
min=0,
description="Random seed number"
)
- origin_to_start = bpy.props.BoolProperty(
+ origin_to_start = BoolProperty(
name="Origin at Start",
description="Set origin at first point of spline",
default=False
)
- refresh = bpy.props.BoolProperty(
+ refresh = BoolProperty(
name="Refresh",
description="Refresh spline",
default=False
)
- auto_refresh = bpy.props.BoolProperty(
+ auto_refresh = BoolProperty(
name="Auto",
description="Auto refresh spline",
default=True
)
-
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
row = col.row(align=True)
- row.prop(self, 'x_ray', toggle=True)
- row.separator()
if self.auto_refresh is False:
self.refresh = False
elif self.auto_refresh is True:
self.refresh = True
- row.prop(self, 'auto_refresh', toggle=True, icon='AUTO', text="")
- row.prop(self, 'refresh', toggle=True, icon='FILE_REFRESH', text="")
- row.separator()
- row.prop(self, 'origin_to_start', toggle=True, icon='MANIPUL', text="")
- row.separator()
- row.operator('object.add_bounce_spline', text="Add New")
+ row.prop(self, 'auto_refresh', toggle=True, icon='AUTO', icon_only=True)
+ row.prop(self, 'refresh', toggle=True, icon='FILE_REFRESH', icon_only=True)
+ row.operator('object.add_bounce_spline', text="Add")
+ row.prop(self, 'x_ray', toggle=True, icon_only=True, icon='RESTRICT_VIEW_OFF')
+ row.prop(self, 'origin_to_start', toggle=True, icon='CURVE_DATA', icon_only=True)
col = layout.column(align=True)
col.prop(self, 'spline_name')
@@ -685,11 +573,10 @@ class BounceSpline(bpy.types.Operator):
col.prop(self, 'bounce_number')
row = col.row(align=True).split(0.9, align=True)
row.prop(self, 'ang_noise')
- row.prop(self, 'active_face', toggle=True, text="", icon='FACESEL')
+ row.prop(self, 'active_face', toggle=True, text="", icon='SNAP_FACE')
col.prop(self, 'offset')
col.prop(self, 'extra')
col.prop(self, 'random_seed')
-
draw_spline_settings(self)
@@ -790,70 +677,62 @@ class CatenaryCurve(bpy.types.Operator):
bl_description = "Hang a curve between two selected objects"
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
- steps = bpy.props.IntProperty(
+ steps = IntProperty(
name="Steps",
description="Resolution of the curve",
default=24,
min=2,
- max=256,
+ max=1024,
)
- var_a = bpy.props.FloatProperty(
+ var_a = FloatProperty(
name="a",
description="Catenary variable a",
precision=3,
default=2.0,
- min=0.0,
- soft_min=0.01,
+ min=0.01,
max=100.0
)
- spline_name = bpy.props.StringProperty(
+ spline_name = StringProperty(
name="Name",
default="Catenary"
)
- 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 tilt calculation",
@@ -861,63 +740,66 @@ class CatenaryCurve(bpy.types.Operator):
('MINIMUM', "Minimum", 'Minimum'),
('TANGENT', "Tangent", 'Tangent')]
)
- twist_smooth = bpy.props.FloatProperty(
+ twist_smooth = FloatProperty(
name="Smooth",
default=0.0,
min=0.0,
precision=3,
description="Twist smoothing amount for tangents"
)
- tilt = bpy.props.FloatProperty(
+ tilt = FloatProperty(
name="Tilt",
default=0.0,
precision=3,
description="Spline handle tilt"
)
- x_ray = bpy.props.BoolProperty(
+ random_radius = FloatProperty(
+ name="Randomise",
+ default=0.0,
+ min=0.0,
+ precision=3,
+ description="Randomise radius of spline controlpoints"
+ )
+ x_ray = BoolProperty(
name="X-Ray",
default=False,
- description="Make the object draw in front of others"
+ description="X-Ray - make the object draw in front of others"
)
- random_seed = bpy.props.IntProperty(
+ random_seed = IntProperty(
name="Random Seed",
default=1,
min=0,
description="Random seed number"
)
- origin_to_start = bpy.props.BoolProperty(
+ origin_to_start = BoolProperty(
name="Origin at Start",
description="Set origin at first point of spline",
default=False
)
- refresh = bpy.props.BoolProperty(
+ refresh = BoolProperty(
name="Refresh",
description="Refresh spline",
default=False
)
- auto_refresh = bpy.props.BoolProperty(
+ auto_refresh = BoolProperty(
name="Auto",
description="Auto refresh spline",
default=True
)
-
def draw(self, context):
layout = self.layout
col = layout.column(align=True)
row = col.row(align=True)
- row.prop(self, 'x_ray', toggle=True)
- row.separator()
if self.auto_refresh is False:
self.refresh = False
elif self.auto_refresh is True:
self.refresh = True
- row.prop(self, 'auto_refresh', toggle=True, icon='AUTO', text="")
- row.prop(self, 'refresh', toggle=True, icon='FILE_REFRESH', text="")
- row.separator()
- row.prop(self, 'origin_to_start', toggle=True, icon='MANIPUL', text="")
- row.separator()
- row.operator('object.add_catenary_curve', text="Add New")
+ row.prop(self, 'auto_refresh', toggle=True, icon='AUTO', icon_only=True)
+ row.prop(self, 'refresh', toggle=True, icon='FILE_REFRESH', icon_only=True)
+ row.operator('object.add_catenary_curve', text="Add")
+ row.prop(self, 'x_ray', toggle=True, icon_only=True, icon='RESTRICT_VIEW_OFF')
+ row.prop(self, 'origin_to_start', toggle=True, icon='CURVE_DATA', icon_only=True)
col = layout.column(align=True)
col.prop(self, 'spline_name')
@@ -951,7 +833,8 @@ class CatenaryCurve(bpy.types.Operator):
ob2 = bpy.context.selected_objects[0]
start = ob1.location
end = ob2.location
- if start[0] == end[0] and start[1] == end[1]:
+ if (start[0] == end[0]) and (start[1] == end[1]):
+ self.report({"WARNING"}, "Objects have the same x y location. Operation cancelled")
return {'CANCELLED'}
except:
return {'CANCELLED'}
@@ -989,7 +872,7 @@ class CatenaryCurve(bpy.types.Operator):
if self.origin_to_start is True:
move_origin_to_start()
else:
- bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')
+ bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
if self.auto_refresh is False:
self.refresh = False
@@ -999,6 +882,99 @@ class CatenaryCurve(bpy.types.Operator):
# ------------------------------------------------------------
+# 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')
+ col.prop(self, 'extrude')
+ if self.spline_type == 'BEZIER':
+ col.prop(self, 'random_radius')
+ 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')
+
+
+
+
+# ------------------------------------------------------------
# Tools Panel > Create
# ------------------------------------------------------------
class SplinePanel(bpy.types.Panel):