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:
authorlijenstina <lijenstina@gmail.com>2017-06-03 14:37:35 +0300
committerlijenstina <lijenstina@gmail.com>2017-06-03 14:37:35 +0300
commit9c045fdd8808b8745d0af66ce7dda1e0da592332 (patch)
tree20ac5b516277df002f4977c5c1437b0891889f26 /add_curve_extra_objects/add_curve_spirals.py
parent77a836a2455bac9f56d6b3ae65bb37a64dea1b1c (diff)
Add Curve Extra Objects: Cleanup, refactor some code
Bumped version to 0.1.2 Pep8 cleanup Consistent property definitions Remove star imports Some small UI fixes Reorder the submenu items types Alphabetically Add Curve braid: merge in the bpybraid and braid scripts since they are relatively small Add Simple Curve - use a property group for scene props Add list of Menus and Panels available in the User Preferences
Diffstat (limited to 'add_curve_extra_objects/add_curve_spirals.py')
-rw-r--r--add_curve_extra_objects/add_curve_spirals.py339
1 files changed, 214 insertions, 125 deletions
diff --git a/add_curve_extra_objects/add_curve_spirals.py b/add_curve_extra_objects/add_curve_spirals.py
index f8b12ae1..522f6379 100644
--- a/add_curve_extra_objects/add_curve_spirals.py
+++ b/add_curve_extra_objects/add_curve_spirals.py
@@ -1,19 +1,24 @@
-'''bl_info = {
+# gpl: author Alejandro Omar Chocano Vasquez
+
+"""
+bl_info = {
"name": "Spirals",
"description": "Make spirals",
"author": "Alejandro Omar Chocano Vasquez",
- "version": (1, 2),
+ "version": (1, 2, 1),
"blender": (2, 62, 0),
"location": "View3D > Add > Curve",
- "warning": "", # used for warning icon and text in addons panel
- "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.4/Py/"
+ "warning": "",
+ "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.4/Py/"
"Scripts/Object/Spirals",
"tracker_url": "http://alexvaqp.googlepages.com?"
"func=detail&aid=<number>",
"category": "Add Curve",
}
-'''
-import bpy, time
+"""
+
+import bpy
+import time
from bpy.props import (
EnumProperty,
BoolProperty,
@@ -21,62 +26,59 @@ from bpy.props import (
IntProperty,
)
from math import (
- sin,
- cos,
- pi,
- exp
+ sin, cos, pi
+ )
+from bpy_extras.object_utils import object_data_add
+from bpy.types import (
+ Operator,
+ Menu,
)
-from bpy_extras.object_utils import AddObjectHelper, object_data_add
-from bpy.types import Operator, Menu
from bl_operators.presets import AddPresetBase
# make normal spiral
# ----------------------------------------------------------------------------
+
def make_spiral(props, context):
- # archemedian and logarithmic can be plottet in zylindrical coordinates
- # if props.spiral_type != 1 and props.spiral_type != 2:
- # return None
+ # archemedian and logarithmic can be plotted in cylindrical coordinates
# INPUT: turns->degree->max_phi, steps, direction
# Initialise Polar Coordinate Enviroment
- # -------------------------------
- props.degree = 360*props.turns # If you want to make the slider for degree
- steps = props.steps * props.turns # props.steps[per turn] -> steps[for the whole spiral]
+ props.degree = 360 * props.turns # If you want to make the slider for degree
+ steps = props.steps * props.turns # props.steps[per turn] -> steps[for the whole spiral]
props.z_scale = props.dif_z * props.turns
- max_phi = pi*props.degree/180 # max angle in radian
- step_phi = max_phi/steps # angle in radians between two vertices
+ max_phi = pi * props.degree / 180 # max angle in radian
+ step_phi = max_phi / steps # angle in radians between two vertices
+
if props.spiral_direction == 'CLOCKWISE':
step_phi *= -1 # flip direction
max_phi *= -1
- step_z = props.z_scale/(steps-1) # z increase in one step
+
+ step_z = props.z_scale / (steps - 1) # z increase in one step
verts = []
verts.extend([props.radius, 0, 0, 1])
cur_phi = 0
cur_z = 0
-# ------------------------------
-# Archemedean: dif_radius, radius
+ # Archemedean: dif_radius, radius
cur_rad = props.radius
- step_rad = props.dif_radius/(steps * 360/props.degree)
-# radius increase per angle for archemedean spiral| (steps * 360/props.degree)...Steps needed for 360 deg
-# Logarithmic: radius, B_force, ang_div, dif_z
+ step_rad = props.dif_radius / (steps * 360 / props.degree)
+ # radius increase per angle for archemedean spiral|
+ # (steps * 360/props.degree)...Steps needed for 360 deg
+ # Logarithmic: radius, B_force, ang_div, dif_z
-# print("max_phi:",max_phi,"step_phi:",step_phi,"step_rad:",step_rad,"step_z:",step_z)
while abs(cur_phi) <= abs(max_phi):
cur_phi += step_phi
cur_z += step_z
-# ------------------------------
if props.spiral_type == 'ARCH':
cur_rad += step_rad
if props.spiral_type == 'LOG':
# r = a*e^{|theta| * b}
cur_rad = props.radius * pow(props.B_force, abs(cur_phi))
-# ------------------------------
px = cur_rad * cos(cur_phi)
py = cur_rad * sin(cur_phi)
@@ -87,26 +89,25 @@ def make_spiral(props, context):
# make Spheric spiral
# ----------------------------------------------------------------------------
+
def make_spiral_spheric(props, context):
# INPUT: turns, steps[per turn], radius
# use spherical Coordinates
- step_phi = (2*pi) / props.steps # Step of angle in radians for one turn
+ step_phi = (2 * pi) / props.steps # Step of angle in radians for one turn
steps = props.steps * props.turns # props.steps[per turn] -> steps[for the whole spiral]
- max_phi = 2*pi*props.turns # max angle in radian
- step_phi = max_phi/steps # angle in radians between two vertices
+ max_phi = 2 * pi * props.turns # max angle in radian
+ step_phi = max_phi / steps # angle in radians between two vertices
if props.spiral_direction == 'CLOCKWISE': # flip direction
step_phi *= -1
max_phi *= -1
- step_theta = pi / (steps-1) # theta increase in one step (pi == 180 deg)
+ step_theta = pi / (steps - 1) # theta increase in one step (pi == 180 deg)
verts = []
verts.extend([0, 0, -props.radius, 1]) # First vertex at south pole
-#cur_rad = props.radius = CONST
-
cur_phi = 0
- cur_theta = -pi/2 # Beginning at south pole
+ cur_theta = -pi / 2 # Beginning at south pole
while abs(cur_phi) <= abs(max_phi):
# Coordinate Transformation sphere->rect
@@ -120,17 +121,21 @@ def make_spiral_spheric(props, context):
return verts
+
# make torus spiral
# ----------------------------------------------------------------------------
def make_spiral_torus(props, context):
- # INPUT: turns, steps, inner_radius, curves_number, mul_height, dif_inner_radius, cycles
- max_phi = 2*pi*props.turns * props.cycles # max angle in radian
- step_phi = 2*pi/props.steps # Step of angle in radians between two vertices
+ # INPUT: turns, steps, inner_radius, curves_number,
+ # mul_height, dif_inner_radius, cycles
+ max_phi = 2 * pi * props.turns * props.cycles # max angle in radian
+ step_phi = 2 * pi / props.steps # Step of angle in radians between two vertices
+
if props.spiral_direction == 'CLOCKWISE': # flip direction
step_phi *= -1
max_phi *= -1
- step_theta = (2*pi / props.turns) / props.steps
+
+ step_theta = (2 * pi / props.turns) / props.steps
step_rad = props.dif_radius / (props.steps * props.turns)
step_inner_rad = props.dif_inner_radius / props.steps
step_z = props.dif_z / (props.steps * props.turns)
@@ -146,14 +151,17 @@ def make_spiral_torus(props, context):
while abs(cur_phi) <= abs(max_phi):
# Torus Coordinates -> Rect
- px = (cur_rad + cur_inner_rad * cos(cur_phi)) * cos(props.curves_number * cur_theta)
- py = (cur_rad + cur_inner_rad * cos(cur_phi)) * sin(props.curves_number * cur_theta)
+ px = (cur_rad + cur_inner_rad * cos(cur_phi)) * \
+ cos(props.curves_number * cur_theta)
+ py = (cur_rad + cur_inner_rad * cos(cur_phi)) * \
+ sin(props.curves_number * cur_theta)
pz = cur_inner_rad * sin(cur_phi) + cur_z
verts.extend([px, py, pz, 1])
- if props.touch and cur_phi >= n_cycle * 2*pi:
- step_z = ((n_cycle+1) * props.dif_inner_radius + props.inner_radius) * 2 / (props.steps * props.turns)
+ if props.touch and cur_phi >= n_cycle * 2 * pi:
+ step_z = ((n_cycle + 1) * props.dif_inner_radius +
+ props.inner_radius) * 2 / (props.steps * props.turns)
n_cycle += 1
cur_theta += step_theta
@@ -163,7 +171,7 @@ def make_spiral_torus(props, context):
cur_z += step_z
return verts
-# ----------------------------------------------------------------------------
+
def draw_curve(props, context):
if props.spiral_type == 'ARCH':
@@ -179,132 +187,203 @@ def draw_curve(props, context):
curve_data.dimensions = '3D'
spline = curve_data.splines.new(type=props.curve_type)
- '''
+ """
if props.curve_type == 0:
spline = curve_data.splines.new(type='POLY')
elif props.curve_type == 1:
spline = curve_data.splines.new(type='NURBS')
- '''
- spline.points.add(len(verts)*0.25-1)
-# Add only one quarter of points as elements in verts, because verts looks like: "x,y,z,?,x,y,z,?,x,..."
+ """
+ spline.points.add(len(verts) * 0.25 - 1)
+ # Add only one quarter of points as elements in verts,
+ # because verts looks like: "x,y,z,?,x,y,z,?,x,..."
spline.points.foreach_set('co', verts)
new_obj = object_data_add(context, curve_data)
+
class CURVE_OT_spirals(Operator):
bl_idname = "curve.spirals"
- bl_label = "Add Curve: Spirals"
+ bl_label = "Curve Spirals"
+ bl_description = "Create different types of spirals"
bl_options = {'REGISTER', 'UNDO'}
-# UNDO needed for operator redo and therefore also to let the addobjecthelp appear!!!
- bl_description = "Create different types of spirals"
- spiral_type = EnumProperty(items=[('ARCH', "Archemedian", "Archemedian"),
- ("LOG", "Logarithmic", "Logarithmic"),
- ("SPHERE", "Spheric", "Spheric"),
- ("TORUS", "Torus", "Torus")],
- default='ARCH',
- name="Spiral Type",
- description="Type of spiral to add")
-
- curve_type = EnumProperty(items=[('POLY', "Poly", "PolyLine"),
- ("NURBS", "NURBS", "NURBS")],
- default='POLY',
- name="Curve Type",
- description="Type of spline to use")
-
- spiral_direction = EnumProperty(items=[('COUNTER_CLOCKWISE', "Counter Clockwise", "Wind in a counter clockwise direction"),
- ("CLOCKWISE", "Clockwise", "Wind in a clockwise direction")],
- default='COUNTER_CLOCKWISE',
- name="Spiral Direction",
- description="Direction of winding")
-
- turns = IntProperty(default=1, min=1, max=1000, description="Length of Spiral in 360 deg")
- steps = IntProperty(default=24, min=2, max=1000, description="Number of Vertices per turn")
-
- radius = FloatProperty(default=1.00, min=0.00, max=100.00, description="radius for first turn")
- dif_z = FloatProperty(default=0, min=-10.00, max=100.00, description="increase in z axis per turn")
-# needed for 1 and 2 spiral_type
-# ARCHMEDEAN variables
- dif_radius = FloatProperty(default=0.00, min=-50.00, max=50.00, description="radius increment in each turn")
-# step between turns(one turn equals 360 deg)
-# LOG variables
- B_force = FloatProperty(default=1.00, min=0.00, max=30.00, description="factor of exponent")
-# TORUS variables
- inner_radius = FloatProperty(default=0.20, min=0.00, max=100, description="Inner Radius of Torus")
- dif_inner_radius = FloatProperty(default=0, min=-10, max=100, description="Increase of inner Radius per Cycle")
- dif_radius = FloatProperty(default=0, min=-10, max=100, description="Increase of Torus Radius per Cycle")
- cycles = FloatProperty(default=1, min=0.00, max=1000, description="Number of Cycles")
- curves_number = IntProperty(default=1, min=1, max=400, description="Number of curves of spiral")
- touch = BoolProperty(default=False, description="No empty spaces between cycles")
+ spiral_type = EnumProperty(
+ items=[('ARCH', "Archemedian", "Archemedian"),
+ ("LOG", "Logarithmic", "Logarithmic"),
+ ("SPHERE", "Spheric", "Spheric"),
+ ("TORUS", "Torus", "Torus")],
+ default='ARCH',
+ name="Spiral Type",
+ description="Type of spiral to add"
+ )
+ curve_type = EnumProperty(
+ items=[('POLY', "Poly", "PolyLine"),
+ ("NURBS", "NURBS", "NURBS")],
+ default='POLY',
+ name="Curve Type",
+ description="Type of spline to use"
+ )
+ spiral_direction = EnumProperty(
+ items=[('COUNTER_CLOCKWISE', "Counter Clockwise",
+ "Wind in a counter clockwise direction"),
+ ("CLOCKWISE", "Clockwise",
+ "Wind in a clockwise direction")],
+ default='COUNTER_CLOCKWISE',
+ name="Spiral Direction",
+ description="Direction of winding"
+ )
+ turns = IntProperty(
+ default=1,
+ min=1, max=1000,
+ description="Length of Spiral in 360 deg"
+ )
+ steps = IntProperty(
+ default=24,
+ min=2, max=1000,
+ description="Number of Vertices per turn"
+ )
+ radius = FloatProperty(
+ default=1.00,
+ min=0.00, max=100.00,
+ description="Radius for first turn"
+ )
+ dif_z = FloatProperty(
+ default=0,
+ min=-10.00, max=100.00,
+ description="Increase in Z axis per turn"
+ )
+ # needed for 1 and 2 spiral_type
+ # Archemedian variables
+ dif_radius = FloatProperty(
+ default=0.00,
+ min=-50.00, max=50.00,
+ description="Radius increment in each turn"
+ )
+ # step between turns(one turn equals 360 deg)
+ # Log variables
+ B_force = FloatProperty(
+ default=1.00,
+ min=0.00, max=30.00,
+ description="Factor of exponent"
+ )
+ # Torus variables
+ inner_radius = FloatProperty(
+ default=0.20,
+ min=0.00, max=100,
+ description="Inner Radius of Torus"
+ )
+ dif_inner_radius = FloatProperty(
+ default=0,
+ min=-10, max=100,
+ description="Increase of inner Radius per Cycle"
+ )
+ dif_radius = FloatProperty(
+ default=0,
+ min=-10, max=100,
+ description="Increase of Torus Radius per Cycle"
+ )
+ cycles = FloatProperty(
+ default=1,
+ min=0.00, max=1000,
+ description="Number of Cycles"
+ )
+ curves_number = IntProperty(
+ default=1,
+ min=1, max=400,
+ description="Number of curves of spiral"
+ )
+ touch = BoolProperty(
+ default=False,
+ description="No empty spaces between cycles"
+ )
def draw(self, context):
layout = self.layout
col = layout.column_flow(align=True)
- col.label('Presets:')
+
+ col.label("Presets:")
+
row = col.row(align=True)
- row.menu("OBJECT_MT_spiral_curve_presets", text=bpy.types.OBJECT_MT_spiral_curve_presets.bl_label)
+ row.menu("OBJECT_MT_spiral_curve_presets",
+ text=bpy.types.OBJECT_MT_spiral_curve_presets.bl_label)
row.operator("curve_extras.spiral_presets", text="", icon='ZOOMIN')
- #op = row.operator("curve.spiral_presets", text="SAVE")
- #op.name = bpy.types.OBJECT_MT_spiral_curve_presets.bl_label
op = row.operator("curve_extras.spiral_presets", text="", icon='ZOOMOUT')
op.remove_active = True
- layout.prop(self, 'spiral_type')
- layout.prop(self, 'curve_type')
- layout.prop(self, 'spiral_direction')
+ layout.prop(self, "spiral_type")
+ layout.prop(self, "curve_type")
+ layout.prop(self, "spiral_direction")
- layout.label(text="Spiral Parameters:")
- layout.prop(self, 'turns', text="Turns")
- layout.prop(self, 'steps', text="Steps")
+ col = layout.column(align=True)
+ col.label(text="Spiral Parameters:")
+ col.prop(self, "turns", text="Turns")
+ col.prop(self, "steps", text="Steps")
box = layout.box()
if self.spiral_type == 'ARCH':
- box.prop(self, 'dif_radius', text="Radius Growth")
- box.prop(self, 'radius', text="Radius")
- box.prop(self, 'dif_z', text="Height")
+ box.label("Archemedian Settings:")
+ col = box.column(align=True)
+ col.prop(self, "dif_radius", text="Radius Growth")
+ col.prop(self, "radius", text="Radius")
+ col.prop(self, "dif_z", text="Height")
+
if self.spiral_type == 'LOG':
- box.prop(self, 'radius', text="Radius")
- box.prop(self, 'B_force', text="Expansion Force")
- box.prop(self, 'dif_z', text="Height")
+ box.label("Logarithmic Settings:")
+ col = box.column(align=True)
+ col.prop(self, "radius", text="Radius")
+ col.prop(self, "B_force", text="Expansion Force")
+ col.prop(self, "dif_z", text="Height")
+
if self.spiral_type == 'SPHERE':
- box.prop(self, 'radius', text="Radius")
+ box.label("Spheric Settings:")
+ box.prop(self, "radius", text="Radius")
+
if self.spiral_type == 'TORUS':
- box.prop(self, 'cycles', text="Number of Cycles")
+ box.label("Torus Settings:")
+ col = box.column(align=True)
+ col.prop(self, "cycles", text="Number of Cycles")
+
if self.dif_inner_radius == 0 and self.dif_z == 0:
self.cycles = 1
- box.prop(self, 'radius', text="Radius")
+ col.prop(self, "radius", text="Radius")
+
if self.dif_z == 0:
- box.prop(self, 'dif_z', text="Height per Cycle")
+ col.prop(self, "dif_z", text="Height per Cycle")
else:
box2 = box.box()
- box2.prop(self, 'dif_z', text="Height per Cycle")
- box2.prop(self, 'touch', text="Make Snail")
- box.prop(self, 'inner_radius', text="Inner Radius")
- box.prop(self, 'curves_number', text="Curves Number")
- box.prop(self, 'dif_radius', text="Increase of Torus Radius")
- box.prop(self, 'dif_inner_radius', text="Increase of Inner Radius")
+ col2 = box2.column(align=True)
+ col2.prop(self, "dif_z", text="Height per Cycle")
+ col2.prop(self, "touch", text="Make Snail")
+
+ col = box.column(align=True)
+ col.prop(self, "curves_number", text="Curves Number")
+ col.prop(self, "inner_radius", text="Inner Radius")
+ col.prop(self, "dif_radius", text="Increase of Torus Radius")
+ col.prop(self, "dif_inner_radius", text="Increase of Inner Radius")
@classmethod
def poll(cls, context):
- # method called by blender to check if the operator can be run
return context.scene is not None
def execute(self, context):
time_start = time.time()
draw_curve(self, context)
- print("Drawing Spiral Finished: %.4f sec" % (time.time() - time_start))
+
+ self.report({'INFO'},
+ "Drawing Spiral Finished: %.4f sec" % (time.time() - time_start))
+
return {'FINISHED'}
+
class CURVE_EXTRAS_OT_spirals_presets(AddPresetBase, Operator):
- '''Spirals Presets'''
bl_idname = "curve_extras.spiral_presets"
bl_label = "Spirals"
+ bl_description = "Spirals Presets"
preset_menu = "OBJECT_MT_spiral_curve_presets"
preset_subdir = "curve_extras/curve.spirals"
preset_defines = [
- "op = bpy.context.active_operator",
- ]
-
+ "op = bpy.context.active_operator",
+ ]
preset_values = [
"op.spiral_type",
"op.curve_type",
@@ -320,10 +399,11 @@ class CURVE_EXTRAS_OT_spirals_presets(AddPresetBase, Operator):
"op.cycles",
"op.curves_number",
"op.touch",
- ]
+ ]
+
class OBJECT_MT_spiral_curve_presets(Menu):
- '''Presets for curve.spiral.'''
+ '''Presets for curve.spiral'''
bl_label = "Spiral Curve Presets"
bl_idname = "OBJECT_MT_spiral_curve_presets"
preset_subdir = "curve_extras/curve.spirals"
@@ -331,5 +411,14 @@ class OBJECT_MT_spiral_curve_presets(Menu):
draw = bpy.types.Menu.draw_preset
-if __name__ == "__main__":
+
+def register():
bpy.utils.register_module(__name__)
+
+
+def unregister():
+ bpy.utils.unregister_module(__name__)
+
+
+if __name__ == "__main__":
+ register()