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>2016-08-10 19:05:58 +0300
committermeta-androcto <meta.androcto1@gmail.com>2016-08-10 19:05:58 +0300
commita36c5cd168d917da46b6a6e773153adfeacf0bf7 (patch)
treece59445a3034ffe53fb0ef107c6b6cd32b949e1a
parent69bda0309bbe6f63b08732955ad80ce51503cd4e (diff)
code cleanup: curve extra objects thanks @batfinger
-rw-r--r--add_curve_extra_objects/__init__.py126
-rw-r--r--add_curve_extra_objects/add_curve_aceous_galore.py346
-rw-r--r--add_curve_extra_objects/add_curve_spirals.py325
-rw-r--r--add_curve_extra_objects/add_curve_torus_knots.py175
-rw-r--r--add_curve_extra_objects/add_surface_plane_cone.py115
5 files changed, 640 insertions, 447 deletions
diff --git a/add_curve_extra_objects/__init__.py b/add_curve_extra_objects/__init__.py
index ec45c1c1..e24b770f 100644
--- a/add_curve_extra_objects/__init__.py
+++ b/add_curve_extra_objects/__init__.py
@@ -45,8 +45,91 @@ else:
from . import add_surface_plane_cone
import bpy
-from bpy.types import Menu
+from bpy.types import Menu, AddonPreferences
+from bpy.props import StringProperty, IntProperty, BoolProperty
+def convert_old_presets(data_path, msg_data_path, old_preset_subdir, new_preset_subdir, fixdic={}, ext=".py"):
+ ''' convert old presets '''
+
+ def convert_presets(self, context):
+ if not getattr(self, data_path, False):
+ return None
+ import os
+
+ target_path = os.path.join("presets", old_preset_subdir)
+ target_path = bpy.utils.user_resource('SCRIPTS',
+ target_path)
+
+ # created an anytype op to run against preset
+ op = type('', (), {})()
+
+ files = [f for f in os.listdir(target_path) if f.endswith(ext)]
+ if not files:
+ print("No old presets in %s" % target_path)
+ setattr(self, msg_data_path, "No old presets")
+ return None
+
+ new_target_path = os.path.join("presets", new_preset_subdir)
+ new_target_path = bpy.utils.user_resource('SCRIPTS',
+ new_target_path,
+ create=True)
+ for f in files:
+ file = open(os.path.join(target_path, f))
+ for line in file:
+ if line.startswith("op."):
+ exec(line)
+ file.close()
+ for key, items in fixdic.items():
+ if hasattr(op, key) and isinstance(getattr(op, key), int):
+ setattr(op, key, items[getattr(op, key)])
+ # create a new one
+ new_file_path = os.path.join(new_target_path, f)
+ if os.path.isfile(new_file_path):
+ # do nothing
+ print("Preset %s already exists, passing..." % f)
+ continue
+ file_preset = open(new_file_path, 'w')
+ file_preset.write("import bpy\n")
+ file_preset.write("op = bpy.context.active_operator\n")
+ for prop, value in vars(op).items():
+ file_preset.write("op.%s = %s\n" % (prop, str(value)))
+ file_preset.close()
+ print("Writing new preset to %s" % new_file_path)
+
+ setattr(self, msg_data_path, "Converted %d old presets" % len(files))
+ return None
+ return convert_presets
+
+
+class CurveExtraObjectsAddonPreferences(AddonPreferences):
+ bl_idname = __name__
+
+ spiral_fixdic = {"spiral_type": ['ARCH', 'ARCH', 'LOG', 'SPHERE', 'TORUS'],
+ "curve_type": ['POLY', 'NURB'],
+ "spiral_direction": ['COUNTER_CLOCKWISE', 'CLOCKWISE']
+ }
+ update_spriral_presets_msg = StringProperty(default="Nothing to do")
+ update_spiral_presets = BoolProperty(
+ name="Update Old Presets",
+ description="Update presets to reflect data changes",
+ default=False,
+ update=convert_old_presets("update_spiral_presets", # this props name
+ "update_spiral_presets_msg", # message prop
+ "operator/curve.spirals",
+ "curve_extras/curve.spirals",
+ fixdic=spiral_fixdic)
+ )
+
+ def draw(self, context):
+ layout = self.layout
+ layout.label(text="Spirals")
+ if self.update_spiral_presets:
+ layout.label(self.update_spriral_presets_msg, icon='FILE_TICK')
+ else:
+ layout.prop(self, "update_spiral_presets")
+
+
+# TODO check if this is even used.
class INFO_MT_curve_extras_add(Menu):
# Define the "Extras" menu
bl_idname = "curve_extra_objects_add"
@@ -55,31 +138,40 @@ class INFO_MT_curve_extras_add(Menu):
def draw(self, context):
layout = self.layout
layout.operator_context = 'INVOKE_REGION_WIN'
- layout.operator("mesh.curveaceous_galore",
- text="Curve Profiles")
- layout.operator("curve.spirals",
- text="Spirals")
+ layout.operator_menu_enum("mesh.curveaceous_galore",
+ "ProfileType",
+ )
+ layout.operator_menu_enum("curve.spirals",
+ "spiral_type",
+ icon='FORCE_VORTEX')
layout.operator("curve.torus_knot_plus",
text="Torus Knot Plus")
# Define "Extras" menus
def menu_func(self, context):
- self.layout.separator()
- self.layout.operator("mesh.curveaceous_galore",
- text="Curve Profiles")
- self.layout.operator("curve.torus_knot_plus",
- text="Torus Knot Plus")
- self.layout.operator("curve.spirals",
- text="Spirals")
+ if context.mode != 'OBJECT':
+ # fix in D2142 will allow to work in EDIT_CURVE
+ return None
+ layout = self.layout
+ layout.separator()
+ layout.operator_menu_enum("mesh.curveaceous_galore",
+ "ProfileType",
+ )
+ layout.operator_menu_enum("curve.spirals",
+ "spiral_type",
+ icon='FORCE_VORTEX')
+ layout.operator("curve.torus_knot_plus", text="Torus Knot Plus")
def menu_surface(self, context):
layout = self.layout
self.layout.separator()
- self.layout.operator("object.add_surface_wedge", text="Wedge", icon="MOD_CURVE")
- self.layout.operator("object.add_surface_cone", text="Cone", icon="MOD_CURVE")
- self.layout.operator("object.add_surface_star", text="Star", icon="MOD_CURVE")
- self.layout.operator("object.add_surface_plane", text="Plane", icon="MOD_CURVE")
- self.layout.operator("curve.smooth_x_times", text="Special Smooth", icon="MOD_CURVE")
+ if context.mode == 'EDIT_SURFACE':
+ self.layout.operator("curve.smooth_x_times", text="Special Smooth", icon="MOD_CURVE")
+ elif context.mode == 'OBJECT':
+ self.layout.operator("object.add_surface_wedge", text="Wedge", icon="MOD_CURVE")
+ self.layout.operator("object.add_surface_cone", text="Cone", icon="MOD_CURVE")
+ self.layout.operator("object.add_surface_star", text="Star", icon="MOD_CURVE")
+ self.layout.operator("object.add_surface_plane", text="Plane", icon="MOD_CURVE")
def register():
bpy.utils.register_module(__name__)
diff --git a/add_curve_extra_objects/add_curve_aceous_galore.py b/add_curve_extra_objects/add_curve_aceous_galore.py
index 41bf4587..259660fb 100644
--- a/add_curve_extra_objects/add_curve_aceous_galore.py
+++ b/add_curve_extra_objects/add_curve_aceous_galore.py
@@ -31,8 +31,8 @@ bl_info = {
'''
-##------------------------------------------------------------
-#### import modules
+# ------------------------------------------------------------
+# import modules
import bpy
from bpy.props import (
BoolProperty,
@@ -51,11 +51,11 @@ from math import (
)
import mathutils.noise as Noise
from bpy.types import Operator
-###------------------------------------------------------------
-#### Some functions to use with others:
-###------------------------------------------------------------
+# ------------------------------------------------------------
+# Some functions to use with others:
+# ------------------------------------------------------------
-#------------------------------------------------------------
+# ------------------------------------------------------------
# Generate random number:
def randnum(low=0.0, high=1.0, seed=0):
"""
@@ -82,9 +82,9 @@ def randnum(low=0.0, high=1.0, seed=0):
return rnum
-#------------------------------------------------------------
+# ------------------------------------------------------------
# Make some noise:
-def vTurbNoise(x,y,z, iScale=0.25, Size=1.0, Depth=6, Hard=0, Basis=0, Seed=0):
+def vTurbNoise(x, y, z, iScale=0.25, Size=1.0, Depth=6, Hard=0, Basis=0, Seed=0):
"""
vTurbNoise((x,y,z), iScale=0.25, Size=1.0, Depth=6, Hard=0, Basis=0, Seed=0 )
@@ -109,32 +109,34 @@ def vTurbNoise(x,y,z, iScale=0.25, Size=1.0, Depth=6, Hard=0, Basis=0, Seed=0):
the generated turbulence vector.
(type=3-float list)
"""
- rand = randnum(-100,100,Seed)
- if Basis == 9: Basis = 14
+ rand = randnum(-100, 100, Seed)
+ if Basis == 9:
+ Basis = 14
vTurb = Noise.turbulence_vector((x/Size+rand, y/Size+rand, z/Size+rand), Depth, Hard, Basis)
tx = vTurb[0]*iScale
ty = vTurb[1]*iScale
tz = vTurb[2]*iScale
- return tx,ty,tz
+ return tx, ty, tz
#------------------------------------------------------------
# Axis: ( used in 3DCurve Turbulence )
-def AxisFlip(x,y,z, x_axis=1, y_axis=1, z_axis=1, flip=0 ):
+def AxisFlip(x, y, z, x_axis=1, y_axis=1, z_axis=1, flip=0):
if flip != 0:
flip *= -1
- else: flip = 1
+ else:
+ flip = 1
x *= x_axis*flip
y *= y_axis*flip
z *= z_axis*flip
- return x,y,z
+ return x, y, z
-###-------------------------------------------------------------------
-#### 2D Curve shape functions:
-###-------------------------------------------------------------------
+# -------------------------------------------------------------------
+# 2D Curve shape functions:
+# -------------------------------------------------------------------
-##------------------------------------------------------------
+# ------------------------------------------------------------
# 2DCurve: Profile: L, H, T, U, Z
def ProfileCurve(type=0, a=0.25, b=0.25):
"""
@@ -155,42 +157,42 @@ def ProfileCurve(type=0, a=0.25, b=0.25):
"""
newpoints = []
- if type ==1:
- ## H:
- a*=0.5
- b*=0.5
- newpoints = [ [ -1.0, 1.0, 0.0 ], [ -1.0+a, 1.0, 0.0 ],
- [ -1.0+a, b, 0.0 ], [ 1.0-a, b, 0.0 ], [ 1.0-a, 1.0, 0.0 ],
- [ 1.0, 1.0, 0.0 ], [ 1.0, -1.0, 0.0 ], [ 1.0-a, -1.0, 0.0 ],
- [ 1.0-a, -b, 0.0 ], [ -1.0+a, -b, 0.0 ], [ -1.0+a, -1.0, 0.0 ],
- [ -1.0, -1.0, 0.0 ] ]
- elif type ==2:
- ## T:
- a*=0.5
- newpoints = [ [ -1.0, 1.0, 0.0 ], [ 1.0, 1.0, 0.0 ],
- [ 1.0, 1.0-b, 0.0 ], [ a, 1.0-b, 0.0 ], [ a, -1.0, 0.0 ],
- [ -a, -1.0, 0.0 ], [ -a, 1.0-b, 0.0 ], [ -1.0, 1.0-b, 0.0 ] ]
- elif type ==3:
- ## U:
- a*=0.5
- newpoints = [ [ -1.0, 1.0, 0.0 ], [ -1.0+a, 1.0, 0.0 ],
- [ -1.0+a, -1.0+b, 0.0 ], [ 1.0-a, -1.0+b, 0.0 ], [ 1.0-a, 1.0, 0.0 ],
- [ 1.0, 1.0, 0.0 ], [ 1.0, -1.0, 0.0 ], [ -1.0, -1.0, 0.0 ] ]
- elif type ==4:
- ## Z:
- a*=0.5
- newpoints = [ [ -0.5, 1.0, 0.0 ], [ a, 1.0, 0.0 ],
- [ a, -1.0+b, 0.0 ], [ 1.0, -1.0+b, 0.0 ], [ 1.0, -1.0, 0.0 ],
- [ -a, -1.0, 0.0 ], [ -a, 1.0-b, 0.0 ], [ -1.0, 1.0-b, 0.0 ],
- [ -1.0, 1.0, 0.0 ] ]
+ if type == 1:
+ # H:
+ a *= 0.5
+ b *= 0.5
+ newpoints = [[-1.0, 1.0, 0.0], [-1.0+a, 1.0, 0.0],
+ [-1.0+a, b, 0.0], [1.0-a, b, 0.0], [1.0-a, 1.0, 0.0],
+ [1.0, 1.0, 0.0], [1.0, -1.0, 0.0], [1.0-a, -1.0, 0.0],
+ [1.0-a, -b, 0.0], [-1.0+a, -b, 0.0], [-1.0+a, -1.0, 0.0],
+ [-1.0, -1.0, 0.0]]
+ elif type == 2:
+ # T:
+ a *= 0.5
+ newpoints = [[-1.0, 1.0, 0.0], [1.0, 1.0, 0.0],
+ [1.0, 1.0-b, 0.0], [a, 1.0-b, 0.0], [a, -1.0, 0.0],
+ [-a, -1.0, 0.0], [-a, 1.0-b, 0.0], [-1.0, 1.0-b, 0.0]]
+ elif type == 3:
+ # U:
+ a *= 0.5
+ newpoints = [[-1.0, 1.0, 0.0], [-1.0+a, 1.0, 0.0],
+ [-1.0+a, -1.0+b, 0.0], [1.0-a, -1.0+b, 0.0], [1.0-a, 1.0, 0.0],
+ [1.0, 1.0, 0.0], [1.0, -1.0, 0.0], [-1.0, -1.0, 0.0]]
+ elif type == 4:
+ # Z:
+ a *= 0.5
+ newpoints = [[-0.5, 1.0, 0.0], [a, 1.0, 0.0],
+ [a, -1.0+b, 0.0], [1.0, -1.0+b, 0.0], [1.0, -1.0, 0.0],
+ [-a, -1.0, 0.0], [-a, 1.0-b, 0.0], [-1.0, 1.0-b, 0.0],
+ [-1.0, 1.0, 0.0]]
else:
- ## L:
- newpoints = [ [ -1.0, 1.0, 0.0 ], [ -1.0+a, 1.0, 0.0 ],
- [ -1.0+a, -1.0+b, 0.0 ], [ 1.0, -1.0+b, 0.0 ],
- [ 1.0, -1.0, 0.0 ], [ -1.0, -1.0, 0.0 ] ]
+ # L:
+ newpoints = [[-1.0, 1.0, 0.0], [-1.0+a, 1.0, 0.0],
+ [-1.0+a, -1.0+b, 0.0], [1.0, -1.0+b, 0.0],
+ [1.0, -1.0, 0.0], [-1.0, -1.0, 0.0]]
return newpoints
-##------------------------------------------------------------
+# ------------------------------------------------------------
# 2DCurve: Miscellaneous.: Diamond, Arrow1, Arrow2, Square, ....
def MiscCurve(type=1, a=1.0, b=0.5, c=1.0):
"""
@@ -214,28 +216,28 @@ def MiscCurve(type=1, a=1.0, b=0.5, c=1.0):
"""
newpoints = []
- a*=0.5
- b*=0.5
+ a *= 0.5
+ b *= 0.5
if type == 1:
- ## diamond:
- newpoints = [ [ 0.0, b, 0.0 ], [ a, 0.0, 0.0 ], [ 0.0, -b, 0.0 ], [ -a, 0.0, 0.0 ] ]
+ # diamond:
+ newpoints = [[0.0, b, 0.0], [a, 0.0, 0.0], [0.0, -b, 0.0], [-a, 0.0, 0.0]]
elif type == 2:
- ## Arrow1:
- newpoints = [ [ -a, b, 0.0 ], [ a, 0.0, 0.0 ], [ -a, -b, 0.0 ], [ 0.0, 0.0, 0.0 ] ]
+ # Arrow1:
+ newpoints = [[-a, b, 0.0], [a, 0.0, 0.0], [-a, -b, 0.0], [0.0, 0.0, 0.0]]
elif type == 3:
- ## Arrow2:
- newpoints = [ [ -1.0, b, 0.0 ], [ -1.0+a, b, 0.0 ],
- [ -1.0+a, 1.0, 0.0 ], [ 1.0, 0.0, 0.0 ],
- [ -1.0+a, -1.0, 0.0 ], [ -1.0+a, -b, 0.0 ],
- [ -1.0, -b, 0.0 ] ]
+ # Arrow2:
+ newpoints = [[-1.0, b, 0.0], [-1.0+a, b, 0.0],
+ [-1.0+a, 1.0, 0.0], [1.0, 0.0, 0.0],
+ [-1.0+a, -1.0, 0.0], [-1.0+a, -b, 0.0],
+ [-1.0, -b, 0.0]]
elif type == 4:
- ## Rounded square:
- newpoints = [ [ -a, b-b*0.2, 0.0 ], [ -a+a*0.05, b-b*0.05, 0.0 ], [ -a+a*0.2, b, 0.0 ],
- [ a-a*0.2, b, 0.0 ], [ a-a*0.05, b-b*0.05, 0.0 ], [ a, b-b*0.2, 0.0 ],
- [ a, -b+b*0.2, 0.0 ], [ a-a*0.05, -b+b*0.05, 0.0 ], [ a-a*0.2, -b, 0.0 ],
- [ -a+a*0.2, -b, 0.0 ], [ -a+a*0.05, -b+b*0.05, 0.0 ], [ -a, -b+b*0.2, 0.0 ] ]
+ # Rounded square:
+ newpoints = [[-a, b-b*0.2, 0.0], [-a+a*0.05, b-b*0.05, 0.0], [-a+a*0.2, b, 0.0],
+ [a-a*0.2, b, 0.0], [a-a*0.05, b-b*0.05, 0.0], [a, b-b*0.2, 0.0],
+ [a, -b+b*0.2, 0.0], [a-a*0.05, -b+b*0.05, 0.0], [a-a*0.2, -b, 0.0],
+ [-a+a*0.2, -b, 0.0], [-a+a*0.05, -b+b*0.05, 0.0], [-a, -b+b*0.2, 0.0]]
elif type == 5:
- ## Rounded Rectangle II:
+ # Rounded Rectangle II:
newpoints = []
x = a / 2
y = b / 2
@@ -246,27 +248,27 @@ def MiscCurve(type=1, a=1.0, b=0.5, c=1.0):
if r > y:
r = y - 0.0001
- if r>0:
- newpoints.append([-x+r,y,0])
- newpoints.append([x-r,y,0])
- newpoints.append([x,y-r,0])
- newpoints.append([x,-y+r,0])
- newpoints.append([x-r,-y,0])
- newpoints.append([-x+r,-y,0])
- newpoints.append([-x,-y+r,0])
- newpoints.append([-x,y-r,0])
+ if r > 0:
+ newpoints.append([-x+r, y, 0])
+ newpoints.append([x-r, y, 0])
+ newpoints.append([x, y-r, 0])
+ newpoints.append([x, -y+r, 0])
+ newpoints.append([x-r, -y, 0])
+ newpoints.append([-x+r, -y, 0])
+ newpoints.append([-x, -y+r, 0])
+ newpoints.append([-x, y-r, 0])
else:
- newpoints.append([-x,y,0])
- newpoints.append([x,y,0])
- newpoints.append([x,-y,0])
- newpoints.append([-x,-y,0])
+ newpoints.append([-x, y, 0])
+ newpoints.append([x, y, 0])
+ newpoints.append([x, -y, 0])
+ newpoints.append([-x, -y, 0])
else:
- ## Square:
- newpoints = [ [ -a, b, 0.0 ], [ a, b, 0.0 ], [ a, -b, 0.0 ], [ -a, -b, 0.0 ] ]
+ # Square:
+ newpoints = [[-a, b, 0.0], [a, b, 0.0], [a, -b, 0.0], [-a, -b, 0.0]]
return newpoints
-##------------------------------------------------------------
+# ------------------------------------------------------------
# 2DCurve: Star:
def StarCurve(starpoints=8, innerradius=0.5, outerradius=1.0, twist=0.0):
"""
@@ -295,14 +297,14 @@ def StarCurve(starpoints=8, innerradius=0.5, outerradius=1.0, twist=0.0):
t = (i*step)
x1 = cos(t*pi)*outerradius
y1 = sin(t*pi)*outerradius
- newpoints.append([x1,y1,0])
+ newpoints.append([x1, y1, 0])
x2 = cos(t*pi+(pi/starpoints+twist))*innerradius
y2 = sin(t*pi+(pi/starpoints+twist))*innerradius
- newpoints.append([x2,y2,0])
- i+=1
+ newpoints.append([x2, y2, 0])
+ i += 1
return newpoints
-##------------------------------------------------------------
+# ------------------------------------------------------------
# 2DCurve: Flower:
def FlowerCurve(petals=8, innerradius=0.5, outerradius=1.0, petalwidth=2.0):
"""
@@ -332,17 +334,17 @@ def FlowerCurve(petals=8, innerradius=0.5, outerradius=1.0, petalwidth=2.0):
t = (i*step)
x1 = cos(t*pi-(pi/petals))*innerradius
y1 = sin(t*pi-(pi/petals))*innerradius
- newpoints.append([x1,y1,0])
+ newpoints.append([x1, y1, 0])
x2 = cos(t*pi-pet)*outerradius
y2 = sin(t*pi-pet)*outerradius
- newpoints.append([x2,y2,0])
+ newpoints.append([x2, y2, 0])
x3 = cos(t*pi+pet)*outerradius
y3 = sin(t*pi+pet)*outerradius
- newpoints.append([x3,y3,0])
- i+=1
+ newpoints.append([x3, y3, 0])
+ i += 1
return newpoints
-##------------------------------------------------------------
+# ------------------------------------------------------------
# 2DCurve: Arc,Sector,Segment,Ring:
def ArcCurve(sides=6, startangle=0.0, endangle=90.0, innerradius=0.5, outerradius=1.0, type=3):
"""
@@ -371,34 +373,34 @@ def ArcCurve(sides=6, startangle=0.0, endangle=90.0, innerradius=0.5, outerradiu
newpoints = []
sides += 1
angle = (2.0*(1.0/360.0))
- endangle-=startangle
+ endangle -= startangle
step = ((angle*endangle)/(sides-1))
i = 0
while i < sides:
t = (i*step) + angle*startangle
x1 = sin(t*pi)*outerradius
y1 = cos(t*pi)*outerradius
- newpoints.append([x1,y1,0])
- i+=1
+ newpoints.append([x1, y1, 0])
+ i += 1
- #if type ==0:
+ # if type ==0:
# Arc: turn cyclic curve flag off!
# Segment:
- if type ==2:
- newpoints.append([0,0,0])
+ if type == 2:
+ newpoints.append([0, 0, 0])
# Ring:
- elif type ==3:
- j=sides-1
+ elif type == 3:
+ j = sides-1
while j > -1:
t = (j*step) + angle*startangle
x2 = sin(t*pi)*innerradius
y2 = cos(t*pi)*innerradius
- newpoints.append([x2,y2,0])
- j-=1
+ newpoints.append([x2, y2, 0])
+ j -= 1
return newpoints
-##------------------------------------------------------------
+# ------------------------------------------------------------
# 2DCurve: Cog wheel:
def CogCurve(theeth=8, innerradius=0.8, middleradius=0.95, outerradius=1.0, bevel=0.5):
"""
@@ -431,26 +433,26 @@ def CogCurve(theeth=8, innerradius=0.8, middleradius=0.95, outerradius=1.0, beve
t = (i*step)
x1 = cos(t*pi-(pi/theeth)-pet)*innerradius
y1 = sin(t*pi-(pi/theeth)-pet)*innerradius
- newpoints.append([x1,y1,0])
+ newpoints.append([x1, y1, 0])
x2 = cos(t*pi-(pi/theeth)+pet)*innerradius
y2 = sin(t*pi-(pi/theeth)+pet)*innerradius
- newpoints.append([x2,y2,0])
+ newpoints.append([x2, y2, 0])
x3 = cos(t*pi-pet)*middleradius
y3 = sin(t*pi-pet)*middleradius
- newpoints.append([x3,y3,0])
+ newpoints.append([x3, y3, 0])
x4 = cos(t*pi-(pet*bevel))*outerradius
y4 = sin(t*pi-(pet*bevel))*outerradius
- newpoints.append([x4,y4,0])
+ newpoints.append([x4, y4, 0])
x5 = cos(t*pi+(pet*bevel))*outerradius
y5 = sin(t*pi+(pet*bevel))*outerradius
- newpoints.append([x5,y5,0])
+ newpoints.append([x5, y5, 0])
x6 = cos(t*pi+pet)*middleradius
y6 = sin(t*pi+pet)*middleradius
- newpoints.append([x6,y6,0])
- i+=1
+ newpoints.append([x6, y6, 0])
+ i += 1
return newpoints
-##------------------------------------------------------------
+# ------------------------------------------------------------
# 2DCurve: nSide:
def nSideCurve(sides=6, radius=1.0):
"""
@@ -475,12 +477,12 @@ def nSideCurve(sides=6, radius=1.0):
t = (i*step)
x = sin(t*pi)*radius
y = cos(t*pi)*radius
- newpoints.append([x,y,0])
- i+=1
+ newpoints.append([x, y, 0])
+ i += 1
return newpoints
-##------------------------------------------------------------
+# ------------------------------------------------------------
# 2DCurve: Splat:
def SplatCurve(sides=24, scale=1.0, seed=0, basis=0, radius=1.0):
"""
@@ -509,21 +511,21 @@ def SplatCurve(sides=24, scale=1.0, seed=0, basis=0, radius=1.0):
i = 0
while i < sides:
t = (i*step)
- turb = vTurbNoise(t,t,t, 1.0, scale, 6, 0, basis, seed )
+ turb = vTurbNoise(t, t, t, 1.0, scale, 6, 0, basis, seed)
turb = turb[2] * 0.5 + 0.5
x = sin(t*pi)*radius * turb
y = cos(t*pi)*radius * turb
- newpoints.append([x,y,0])
- i+=1
+ newpoints.append([x, y, 0])
+ i += 1
return newpoints
-###-----------------------------------------------------------
-#### 3D curve shape functions:
-###-----------------------------------------------------------
+# -----------------------------------------------------------
+# 3D curve shape functions:
+# -----------------------------------------------------------
-###------------------------------------------------------------
+# ------------------------------------------------------------
# 3DCurve: Helix:
-def HelixCurve( number=100, height=2.0, startangle=0.0, endangle=360.0, width=1.0, a=0.0, b=0.0 ):
+def HelixCurve(number=100, height=2.0, startangle=0.0, endangle=360.0, width=1.0, a=0.0, b=0.0):
"""
HelixCurve( number=100, height=2.0, startangle=0.0, endangle=360.0, width=1.0, a=0.0, b=0.0 )
@@ -554,20 +556,20 @@ def HelixCurve( number=100, height=2.0, startangle=0.0, endangle=360.0, width=1.
step = angle/(number-1)
h = height/angle
start = (startangle*2.0/360.0)
- a/=angle
+ a /= angle
i = 0
while i < number:
- t = ( i*step+start )
- x = sin( (t*pi) ) * ( 1.0 + cos( t * pi * a - ( b * pi ) ) ) * ( 0.25 * width )
- y = cos( (t*pi) ) * ( 1.0 + cos( t * pi * a - ( b * pi ) ) ) * ( 0.25 * width )
- z = ( t * h ) -h*start
- newpoints.append([x,y,z])
- i+=1
+ t = (i*step+start)
+ x = sin((t*pi)) * (1.0 + cos(t * pi * a - (b * pi))) * (0.25 * width)
+ y = cos((t*pi)) * (1.0 + cos(t * pi * a - (b * pi))) * (0.25 * width)
+ z = (t * h) - h*start
+ newpoints.append([x, y, z])
+ i += 1
return newpoints
-###------------------------------------------------------------ ?
+# ------------------------------------------------------------ ?
# 3DCurve: Cycloid: Cycloid, Epicycloid, Hypocycloid
-def CycloidCurve( number=24, length=2.0, type=0, a=1.0, b=1.0, startangle=0.0, endangle=360.0 ):
+def CycloidCurve(number=24, length=2.0, type=0, a=1.0, b=1.0, startangle=0.0, endangle=360.0):
"""
CycloidCurve( number=24, length=2.0, type=0, a=1.0, b=1.0, startangle=0.0, endangle=360.0 )
@@ -591,39 +593,39 @@ def CycloidCurve( number=24, length=2.0, type=0, a=1.0, b=1.0, startangle=0.0, e
#h = height/angle
d = length
start = (startangle*2.0/360.0)
- a/=angle
+ a /= angle
i = 0
- if type == 0: # Epitrochoid
+ if type == 0: # Epitrochoid
while i < number:
- t = ( i*step+start )
+ t = (i*step+start)
x = ((a + b) * cos(t*pi)) - (d * cos(((a+b)/b)*t*pi))
y = ((a + b) * sin(t*pi)) - (d * sin(((a+b)/b)*t*pi))
- z = 0 # ( t * h ) -h*start
- newpoints.append([x,y,z])
- i+=1
+ z = 0 # ( t * h ) -h*start
+ newpoints.append([x, y, z])
+ i += 1
else:
- newpoints = [[-1,-1,0], [-1,1,0], [1,1,0], [1,-1,0]]
+ newpoints = [[-1, -1, 0], [-1, 1, 0], [1, 1, 0], [1, -1, 0]]
return newpoints
-##------------------------------------------------------------
+# ------------------------------------------------------------
# calculates the matrix for the new object
# depending on user pref
def align_matrix(context):
loc = Matrix.Translation(context.scene.cursor_location)
obj_align = context.user_preferences.edit.object_align
if (context.space_data.type == 'VIEW_3D'
- and obj_align == 'VIEW'):
+ and obj_align == 'VIEW'):
rot = context.space_data.region_3d.view_matrix.to_3x3().inverted().to_4x4()
else:
rot = Matrix()
align_matrix = loc * rot
return align_matrix
-##------------------------------------------------------------
-#### Curve creation functions
+# ------------------------------------------------------------
+# Curve creation functions
# sets bezierhandles to auto
-def setBezierHandles(obj, mode = 'AUTOMATIC'):
+def setBezierHandles(obj, mode='AUTOMATIC'):
scene = bpy.context.scene
if obj.type != 'CURVE':
return
@@ -648,8 +650,8 @@ def vertsToPoints(Verts, splineType):
for v in Verts:
vertArray += v
if splineType == 'NURBS':
- vertArray.append(1) #for nurbs w=1
- else: #for poly w=0
+ vertArray.append(1) # for nurbs w=1
+ else: # for poly w=0
vertArray.append(0)
return vertArray
@@ -661,8 +663,8 @@ def createCurve(context, vertArray, self, align_matrix):
# create curve
scene = context.scene
- newCurve = bpy.data.curves.new(name, type = 'CURVE') # curvedatablock
- newSpline = newCurve.splines.new(type = splineType) # spline
+ newCurve = bpy.data.curves.new(name, type='CURVE') # curvedatablock
+ newSpline = newCurve.splines.new(type=splineType) # spline
# create spline from vertarray
if splineType == 'BEZIER':
@@ -680,11 +682,11 @@ def createCurve(context, vertArray, self, align_matrix):
newSpline.order_u = self.order_u
# create object with newCurve
- new_obj = bpy.data.objects.new(name, newCurve) # object
- scene.objects.link(new_obj) # place in active scene
- new_obj.select = True # set as selected
+ new_obj = bpy.data.objects.new(name, newCurve) # object
+ scene.objects.link(new_obj) # place in active scene
+ new_obj.select = True # set as selected
scene.objects.active = new_obj # set as active
- new_obj.matrix_world = align_matrix # apply matrix
+ new_obj.matrix_world = align_matrix # apply matrix
# set bezierhandles
if splineType == 'BEZIER':
@@ -692,7 +694,7 @@ def createCurve(context, vertArray, self, align_matrix):
return
-##------------------------------------------------------------
+# ------------------------------------------------------------
# Main Function
def main(context, self, align_matrix):
# deselect all objects
@@ -781,7 +783,7 @@ class Curveaceous_galore(Operator):
# align_matrix for the invoke
align_matrix = None
- #### general properties
+ # general properties
ProfileTypes = [
('Profile', 'Profile', 'Profile'),
('Miscellaneous', 'Miscellaneous', 'Miscellaneous'),
@@ -804,7 +806,7 @@ class Curveaceous_galore(Operator):
description="Type of splines to output",
items=SplineTypes)
- #### Curve Options
+ # Curve Options
shapeItems = [
('2D', '2D', '2D'),
('3D', '3D', '3D')]
@@ -829,7 +831,7 @@ class Curveaceous_galore(Operator):
description="bezier handles type",
items=bezHandles)
- #### ProfileCurve properties
+ # ProfileCurve properties
ProfileCurveType = IntProperty(name="Type",
min=1, soft_min=1,
max=5, soft_max=5,
@@ -842,7 +844,7 @@ class Curveaceous_galore(Operator):
default=0.25,
description="var2 of ProfileCurve")
- #### MiscCurve properties
+ # MiscCurve properties
MiscCurveType = IntProperty(name="Type",
min=1, soft_min=1,
max=6, soft_max=6,
@@ -859,7 +861,7 @@ class Curveaceous_galore(Operator):
min=0, soft_min=0,
description="var3 of MiscCurve")
- #### Common properties
+ # Common properties
innerRadius = FloatProperty(name="Inner radius",
default=0.5,
min=0, soft_min=0,
@@ -873,7 +875,7 @@ class Curveaceous_galore(Operator):
min=0, soft_min=0,
description="Outer radius")
- #### Flower properties
+ # Flower properties
petals = IntProperty(name="Petals",
default=8,
min=2, soft_min=2,
@@ -883,7 +885,7 @@ class Curveaceous_galore(Operator):
min=0.01, soft_min=0.01,
description="Petal width")
- #### Star properties
+ # Star properties
starPoints = IntProperty(name="Star points",
default=8,
min=2, soft_min=2,
@@ -892,7 +894,7 @@ class Curveaceous_galore(Operator):
default=0.0,
description="Twist")
- #### Arc properties
+ # Arc properties
arcSides = IntProperty(name="Arc sides",
default=6,
min=1, soft_min=1,
@@ -909,7 +911,7 @@ class Curveaceous_galore(Operator):
max=3, soft_max=3,
description="Sides of arc")
- #### Cogwheel properties
+ # Cogwheel properties
teeth = IntProperty(name="Teeth",
default=8,
min=2, soft_min=2,
@@ -920,13 +922,13 @@ class Curveaceous_galore(Operator):
max=1, soft_max=1,
description="Bevel")
- #### Nsided property
+ # Nsided property
Nsides = IntProperty(name="Sides",
default=8,
min=3, soft_min=3,
description="Number of sides")
- #### Splat properties
+ # Splat properties
splatSides = IntProperty(name="Splat sides",
default=24,
min=3, soft_min=3,
@@ -945,7 +947,7 @@ class Curveaceous_galore(Operator):
max=14, soft_max=14,
description="Basis")
- #### Helix properties
+ # Helix properties
helixPoints = IntProperty(name="resolution",
default=100,
min=3, soft_min=3,
@@ -970,7 +972,7 @@ class Curveaceous_galore(Operator):
default=0.0,
description="Helix var2")
- #### Cycloid properties
+ # Cycloid properties
cycloPoints = IntProperty(name="Resolution",
default=100,
min=3, soft_min=3,
@@ -1035,10 +1037,10 @@ class Curveaceous_galore(Operator):
elif self.ProfileType == 'Arc':
box.prop(self, 'arcSides')
- box.prop(self, 'arcType') # has only one Type?
+ box.prop(self, 'arcType') # has only one Type?
box.prop(self, 'startAngle')
box.prop(self, 'endAngle')
- box.prop(self, 'innerRadius') # doesn't seem to do anything
+ box.prop(self, 'innerRadius') # doesn't seem to do anything
box.prop(self, 'outerRadius')
elif self.ProfileType == 'Cogwheel':
@@ -1070,7 +1072,7 @@ class Curveaceous_galore(Operator):
elif self.ProfileType == 'Cycloid':
box.prop(self, 'cycloPoints')
- #box.prop(self, 'cycloType') # needs the other types first
+ # box.prop(self, 'cycloType') # needs the other types first
box.prop(self, 'cycloStart')
box.prop(self, 'cycloEnd')
box.prop(self, 'cyclo_a')
@@ -1102,7 +1104,7 @@ class Curveaceous_galore(Operator):
##### POLL #####
@classmethod
def poll(cls, context):
- return context.scene != None
+ return context.scene is not None
##### EXECUTE #####
def execute(self, context):
@@ -1113,8 +1115,8 @@ class Curveaceous_galore(Operator):
# deal with 2D - 3D curve differences
if self.ProfileType in ['Helix', 'Cycloid']:
self.shape = '3D'
- #else:
- #self.shape = '2D' # someone decide if we want this
+ # else:
+ # self.shape = '2D' # someone decide if we want this
if self.ProfileType in ['Helix']:
self.use_cyclic_u = False
diff --git a/add_curve_extra_objects/add_curve_spirals.py b/add_curve_extra_objects/add_curve_spirals.py
index 29a86870..f8b12ae1 100644
--- a/add_curve_extra_objects/add_curve_spirals.py
+++ b/add_curve_extra_objects/add_curve_spirals.py
@@ -15,116 +15,119 @@
'''
import bpy, time
from bpy.props import (
+ EnumProperty,
BoolProperty,
FloatProperty,
IntProperty,
)
from math import (
sin,
- cos,
- pi,
+ cos,
+ pi,
exp
)
from bpy_extras.object_utils import AddObjectHelper, object_data_add
-from bpy.types import Operator
+from bpy.types import Operator, Menu
+from bl_operators.presets import AddPresetBase
-#make normal spiral
-#-----------------------------------------------------------------------------
+
+# 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
-
-#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]
+ # archemedian and logarithmic can be plottet in zylindrical coordinates
+ # if props.spiral_type != 1 and props.spiral_type != 2:
+ # return None
+
+ # 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.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
- if props.spiral_direction == 1:
- step_phi *= -1 #flip direction
+
+ 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])
-
+ verts.extend([props.radius, 0, 0, 1])
+
cur_phi = 0
- cur_z = 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
-
-#print("max_phi:",max_phi,"step_phi:",step_phi,"step_rad:",step_rad,"step_z:",step_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 == 1:
+ cur_z += step_z
+
+# ------------------------------
+ if props.spiral_type == 'ARCH':
cur_rad += step_rad
- if props.spiral_type == 2:
-#r = a*e^{|theta| * b}
- cur_rad = props.radius * pow(props.B_force, abs(cur_phi))
-#-------------------------------
-
+ 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)
- verts.extend( [px,py,cur_z,1] )
+ verts.extend([px, py, cur_z, 1])
return verts
-#make Spheric spiral
-#-----------------------------------------------------------------------------
+# 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
- 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
- if props.spiral_direction == 1: #flip direction
+ # INPUT: turns, steps[per turn], radius
+ # use spherical Coordinates
+ 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
+ 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
+ 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
+ # Coordinate Transformation sphere->rect
px = props.radius * cos(cur_theta) * cos(cur_phi)
py = props.radius * cos(cur_theta) * sin(cur_phi)
pz = props.radius * sin(cur_theta)
- verts.extend([px,py,pz,1])
+ verts.extend([px, py, pz, 1])
cur_theta += step_theta
cur_phi += step_phi
return verts
-#make torus spiral
-#-----------------------------------------------------------------------------
+# 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
- if props.spiral_direction == 1: #flip direction
+ # 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
@@ -133,24 +136,24 @@ def make_spiral_torus(props, context):
step_z = props.dif_z / (props.steps * props.turns)
verts = []
-
- cur_phi = 0 #Inner Ring Radius Angle
- cur_theta = 0 #Ring Radius Angle
+
+ cur_phi = 0 # Inner Ring Radius Angle
+ cur_theta = 0 # Ring Radius Angle
cur_rad = props.radius
cur_inner_rad = props.inner_radius
cur_z = 0
n_cycle = 0
-
+
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)
+ # 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)
pz = cur_inner_rad * sin(cur_phi) + cur_z
- verts.extend([px,py,pz,1])
+ verts.extend([px, py, pz, 1])
- if props.touch == True 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
@@ -160,55 +163,72 @@ def make_spiral_torus(props, context):
cur_z += step_z
return verts
-#-----------------------------------------------------------------------------
+# ----------------------------------------------------------------------------
def draw_curve(props, context):
- if props.spiral_type == 1:
+ if props.spiral_type == 'ARCH':
verts = make_spiral(props, context)
- if props.spiral_type == 2:
+ if props.spiral_type == 'LOG':
verts = make_spiral(props, context)
- if props.spiral_type == 3:
+ if props.spiral_type == 'SPHERE':
verts = make_spiral_spheric(props, context)
- if props.spiral_type == 4:
+ if props.spiral_type == 'TORUS':
verts = make_spiral_torus(props, context)
-
+
curve_data = bpy.data.curves.new(name='Spiral', type='CURVE')
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 spirals(Operator):
+class CURVE_OT_spirals(Operator):
bl_idname = "curve.spirals"
- bl_label = "Spirals"
- bl_options = {'REGISTER','UNDO', 'PRESET'}
-#UNDO needed for operator redo and therefore also to let the addobjecthelp appear!!!
- bl_description = "adds different types of spirals"
-
- spiral_type = IntProperty(default=1, min=1, max=4, description="1:archemedian, 2:logarithmic, 3:spheric, 4:torus")
- curve_type = IntProperty(default=0, min=0, max=1, description="0:Poly, 1:Nurb")
- spiral_direction = IntProperty(default=0, min=0, max=1, description="0:counter-clockwise, 1:clockwise")
-
+ bl_label = "Add Curve: 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
+# 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
+# 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
+# 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")
@@ -218,47 +238,98 @@ class spirals(Operator):
def draw(self, context):
layout = self.layout
- layout.prop(self, 'spiral_type', text="Spiral Type")
- layout.prop(self, 'curve_type', text="Curve Type")
- layout.prop(self, 'spiral_direction', text="Spiral Direction")
-
+ col = layout.column_flow(align=True)
+ 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.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.label(text="Spiral Parameters:")
- layout.prop(self, 'turns', text = "Turns")
- layout.prop(self, 'steps', text = "Steps")
+ layout.prop(self, 'turns', text="Turns")
+ layout.prop(self, 'steps', text="Steps")
box = layout.box()
- if self.spiral_type == 1:
- box.prop(self, 'dif_radius', text = "Radius Growth")
- box.prop(self, 'radius', text = "Radius")
- box.prop(self, 'dif_z', text = "Height")
- if self.spiral_type == 2:
- box.prop(self, 'radius', text = "Radius")
- box.prop(self, 'B_force', text = "Expansion Force")
- box.prop(self, 'dif_z', text = "Height")
- if self.spiral_type == 3:
- box.prop(self, 'radius', text = "Radius")
- if self.spiral_type == 4:
- box.prop(self, 'cycles', text = "Number of Cycles")
+ 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")
+ 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")
+ if self.spiral_type == 'SPHERE':
+ box.prop(self, 'radius', text="Radius")
+ if self.spiral_type == 'TORUS':
+ box.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")
+ box.prop(self, 'radius', text="Radius")
if self.dif_z == 0:
- box.prop(self, 'dif_z', text = "Height per Cycle")
+ box.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")
+ 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")
@classmethod
def poll(cls, context):
-#method called by blender to check if the operator can be run
- return context.scene != None
+ # 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)
+ print("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"
+ preset_menu = "OBJECT_MT_spiral_curve_presets"
+ preset_subdir = "curve_extras/curve.spirals"
+
+ preset_defines = [
+ "op = bpy.context.active_operator",
+ ]
+
+ preset_values = [
+ "op.spiral_type",
+ "op.curve_type",
+ "op.spiral_direction",
+ "op.turns",
+ "op.steps",
+ "op.radius",
+ "op.dif_z",
+ "op.dif_radius",
+ "op.B_force",
+ "op.inner_radius",
+ "op.dif_inner_radius",
+ "op.cycles",
+ "op.curves_number",
+ "op.touch",
+ ]
+
+class OBJECT_MT_spiral_curve_presets(Menu):
+ '''Presets for curve.spiral.'''
+ bl_label = "Spiral Curve Presets"
+ bl_idname = "OBJECT_MT_spiral_curve_presets"
+ preset_subdir = "curve_extras/curve.spirals"
+ preset_operator = "script.execute_preset"
+
+ draw = bpy.types.Menu.draw_preset
+
+if __name__ == "__main__":
+ bpy.utils.register_module(__name__)
diff --git a/add_curve_extra_objects/add_curve_torus_knots.py b/add_curve_extra_objects/add_curve_torus_knots.py
index b43bd831..e6499de5 100644
--- a/add_curve_extra_objects/add_curve_torus_knots.py
+++ b/add_curve_extra_objects/add_curve_torus_knots.py
@@ -36,14 +36,14 @@ bl_info = {
import bpy
from bpy.props import (
BoolProperty,
- EnumProperty,
- FloatProperty,
+ EnumProperty,
+ FloatProperty,
IntProperty
)
from math import (
sin,
- cos,
- pi,
+ cos,
+ pi,
sqrt
)
from mathutils import *
@@ -65,28 +65,28 @@ def gcd(a, b):
####################### Knot Definitions ###############################
########################################################################
def Torus_Knot(self, linkIndex=0):
- p = self.torus_p # revolution count (around the torus center)
- q = self.torus_q # spin count (around the torus tube)
+ p = self.torus_p # revolution count (around the torus center)
+ q = self.torus_q # spin count (around the torus tube)
- N = self.torus_res # curve resolution (number of control points)
+ N = self.torus_res # curve resolution (number of control points)
# use plus options only when they are enabled
if self.options_plus:
- u = self.torus_u # p multiplier
- v = self.torus_v # q multiplier
- h = self.torus_h # height (scale along Z)
- s = self.torus_s # torus scale (radii scale factor)
- else: # don't use plus settings
+ u = self.torus_u # p multiplier
+ v = self.torus_v # q multiplier
+ h = self.torus_h # height (scale along Z)
+ s = self.torus_s # torus scale (radii scale factor)
+ else: # don't use plus settings
u = 1
v = 1
h = 1
s = 1
- R = self.torus_R * s # major radius (scaled)
- r = self.torus_r * s # minor radius (scaled)
+ R = self.torus_R * s # major radius (scaled)
+ r = self.torus_r * s # minor radius (scaled)
# number of decoupled links when (p,q) are NOT co-primes
- links = gcd(p,q) # = 1 when (p,q) are co-primes
+ links = gcd(p, q) # = 1 when (p,q) are co-primes
# parametrized angle increment (cached outside of the loop for performance)
# NOTE: the total angle is divided by number of decoupled links to ensure
@@ -95,17 +95,17 @@ def Torus_Knot(self, linkIndex=0):
# link phase : each decoupled link is phased equally around the torus center
# NOTE: linkIndex value is in [0, links-1]
- linkPhase = 2*pi/q * linkIndex # = 0 when there is just ONE link
+ linkPhase = 2*pi/q * linkIndex # = 0 when there is just ONE link
# user defined phasing
if self.options_plus:
- rPhase = self.torus_rP # user defined revolution phase
- sPhase = self.torus_sP # user defined spin phase
- else: # don't use plus settings
+ rPhase = self.torus_rP # user defined revolution phase
+ sPhase = self.torus_sP # user defined spin phase
+ else: # don't use plus settings
rPhase = 0
sPhase = 0
- rPhase += linkPhase # total revolution phase of the current link
+ rPhase += linkPhase # total revolution phase of the current link
if DEBUG:
print("")
@@ -117,16 +117,18 @@ def Torus_Knot(self, linkIndex=0):
print("link phase = %.2f rad" % linkPhase)
# flip directions ? NOTE: flipping both is equivalent to no flip
- if self.flip_p: p*=-1
- if self.flip_q: q*=-1
+ if self.flip_p:
+ p *= -1
+ if self.flip_q:
+ q *= -1
# create the 3D point array for the current link
newPoints = []
for n in range(N-1):
-# t = 2*pi / links * n/(N-1) with: da = 2*pi/links/(N-1) => t = n * da
+ # t = 2*pi / links * n/(N-1) with: da = 2*pi/links/(N-1) => t = n * da
t = n * da
- theta = p*t*u + rPhase # revolution angle
- phi = q*t*v + sPhase # spin angle
+ theta = p*t*u + rPhase # revolution angle
+ phi = q*t*v + sPhase # spin angle
x = (R + r*cos(phi)) * cos(theta)
y = (R + r*cos(phi)) * sin(theta)
@@ -134,7 +136,7 @@ def Torus_Knot(self, linkIndex=0):
# append 3D point
# NOTE : the array is adjusted later as needed to 4D for POLY and NURBS
- newPoints.append([x,y,z])
+ newPoints.append([x, y, z])
return newPoints
@@ -142,7 +144,7 @@ def Torus_Knot(self, linkIndex=0):
# Calculate the align matrix for the new object (based on user preferences)
def align_matrix(self, context):
if self.absolute_location:
- loc = Matrix.Translation(Vector((0,0,0)))
+ loc = Matrix.Translation(Vector((0, 0, 0)))
else:
loc = Matrix.Translation(context.scene.cursor_location)
@@ -161,7 +163,7 @@ def align_matrix(self, context):
# ------------------------------------------------------------------------------
# Set curve BEZIER handles to auto
-def setBezierHandles(obj, mode = 'AUTOMATIC'):
+def setBezierHandles(obj, mode='AUTOMATIC'):
scene = bpy.context.scene
if obj.type != 'CURVE':
return
@@ -174,7 +176,7 @@ def setBezierHandles(obj, mode = 'AUTOMATIC'):
# ------------------------------------------------------------------------------
# Convert array of vert coordinates to points according to spline type
def vertsToPoints(Verts, splineType):
-# main vars
+ # main vars
vertArray = []
# array for BEZIER spline output (V3)
@@ -187,8 +189,8 @@ def vertsToPoints(Verts, splineType):
for v in Verts:
vertArray += v
if splineType == 'NURBS':
- vertArray.append(1) # for NURBS w=1
- else: # for POLY w=0
+ vertArray.append(1) # for NURBS w=1
+ else: # for POLY w=0
vertArray.append(0)
return vertArray
@@ -196,7 +198,7 @@ def vertsToPoints(Verts, splineType):
# ------------------------------------------------------------------------------
# Create the Torus Knot curve and object and add it to the scene
def create_torus_knot(self, context):
-# pick a name based on (p,q) parameters
+ # pick a name based on (p,q) parameters
aName = "Torus Knot %i x %i" % (self.torus_p, self.torus_q)
# create curve
@@ -208,12 +210,12 @@ def create_torus_knot(self, context):
# create torus knot link(s)
if self.multiple_links:
- links = gcd(self.torus_p, self.torus_q);
+ links = gcd(self.torus_p, self.torus_q)
else:
- links = 1;
+ links = 1
for l in range(links):
-# get vertices for the current link
+ # get vertices for the current link
verts = Torus_Knot(self, l)
# output splineType 'POLY' 'NURBS' or 'BEZIER'
@@ -255,10 +257,10 @@ def create_torus_knot(self, context):
# set object in the scene
scene = bpy.context.scene
- scene.objects.link(new_obj) # place in active scene
- new_obj.select = True # set as selected
+ scene.objects.link(new_obj) # place in active scene
+ new_obj.select = True # set as selected
scene.objects.active = new_obj # set as active
- new_obj.matrix_world = self.align_matrix # apply matrix
+ new_obj.matrix_world = self.align_matrix # apply matrix
# set BEZIER handles
if splineType == 'BEZIER':
@@ -269,28 +271,28 @@ def create_torus_knot(self, context):
# ------------------------------------------------------------------------------
# Create materials to be assigned to each TK link
def addLinkColors(self, curveData):
-# some predefined colors for the torus knot links
+ # some predefined colors for the torus knot links
colors = []
- if self.colorSet == "1": # RGBish
- colors += [ [0.0, 0.0, 1.0] ]
- colors += [ [0.0, 1.0, 0.0] ]
- colors += [ [1.0, 0.0, 0.0] ]
- colors += [ [1.0, 1.0, 0.0] ]
- colors += [ [0.0, 1.0, 1.0] ]
- colors += [ [1.0, 0.0, 1.0] ]
- colors += [ [1.0, 0.5, 0.0] ]
- colors += [ [0.0, 1.0, 0.5] ]
- colors += [ [0.5, 0.0, 1.0] ]
- else: # RainBow
- colors += [ [0.0, 0.0, 1.0] ]
- colors += [ [0.0, 0.5, 1.0] ]
- colors += [ [0.0, 1.0, 1.0] ]
- colors += [ [0.0, 1.0, 0.5] ]
- colors += [ [0.0, 1.0, 0.0] ]
- colors += [ [0.5, 1.0, 0.0] ]
- colors += [ [1.0, 1.0, 0.0] ]
- colors += [ [1.0, 0.5, 0.0] ]
- colors += [ [1.0, 0.0, 0.0] ]
+ if self.colorSet == "1": # RGBish
+ colors += [[0.0, 0.0, 1.0]]
+ colors += [[0.0, 1.0, 0.0]]
+ colors += [[1.0, 0.0, 0.0]]
+ colors += [[1.0, 1.0, 0.0]]
+ colors += [[0.0, 1.0, 1.0]]
+ colors += [[1.0, 0.0, 1.0]]
+ colors += [[1.0, 0.5, 0.0]]
+ colors += [[0.0, 1.0, 0.5]]
+ colors += [[0.5, 0.0, 1.0]]
+ else: # RainBow
+ colors += [[0.0, 0.0, 1.0]]
+ colors += [[0.0, 0.5, 1.0]]
+ colors += [[0.0, 1.0, 1.0]]
+ colors += [[0.0, 1.0, 0.5]]
+ colors += [[0.0, 1.0, 0.0]]
+ colors += [[0.5, 1.0, 0.0]]
+ colors += [[1.0, 1.0, 0.0]]
+ colors += [[1.0, 0.5, 0.0]]
+ colors += [[1.0, 0.0, 0.0]]
me = curveData
mat_offset = len(me.materials)
@@ -301,17 +303,19 @@ def addLinkColors(self, curveData):
matListNames = bpy.data.materials.keys()
# create the material
if matName not in matListNames:
- if DEBUG: print("Creating new material : %s" % matName)
+ if DEBUG:
+ print("Creating new material : %s" % matName)
mat = bpy.data.materials.new(matName)
else:
- if DEBUG: print("Material %s already exists" % matName)
+ if DEBUG:
+ print("Material %s already exists" % matName)
mat = bpy.data.materials[matName]
# set material color
if self.options_plus and self.random_colors:
mat.diffuse_color = random(), random(), random()
else:
- cID = i % (len(colors)) # cycle through predefined colors
+ cID = i % (len(colors)) # cycle through predefined colors
mat.diffuse_color = colors[cID]
if self.options_plus:
@@ -332,7 +336,7 @@ class torus_knot_plus(Operator, AddObjectHelper):
bl_context = "object"
def mode_update_callback(self, context):
-# keep the equivalent radii sets (R,r)/(eR,iR) in sync
+ # keep the equivalent radii sets (R,r)/(eR,iR) in sync
if self.mode == 'EXT_INT':
self.torus_eR = self.torus_R + self.torus_r
self.torus_iR = self.torus_R - self.torus_r
@@ -340,19 +344,19 @@ class torus_knot_plus(Operator, AddObjectHelper):
# align_matrix for the invoke
align_matrix = None
-#### GENERAL options
+# GENERAL options
options_plus = BoolProperty(
name="Extra Options",
default=False,
description="Show more options (the plus part)",
)
absolute_location = BoolProperty(
- name= "Absolute Location",
+ name="Absolute Location",
default=False,
description="Set absolute location instead of relative to 3D cursor",
)
-#### COLOR options
+# COLOR options
use_colors = BoolProperty(
name="Use Colors",
default=False,
@@ -360,7 +364,7 @@ class torus_knot_plus(Operator, AddObjectHelper):
)
colorSet = EnumProperty(
name="Color Set",
- items= (('1', 'RGBish', 'RGBsish ordered colors'),
+ items=(('1', 'RGBish', 'RGBsish ordered colors'),
('2', 'Rainbow', 'Rainbow ordered colors')),
)
random_colors = BoolProperty(
@@ -375,7 +379,7 @@ class torus_knot_plus(Operator, AddObjectHelper):
description="Color saturation",
)
-#### SURFACE Options
+# SURFACE Options
geo_surface = BoolProperty(
name="Surface",
default=True,
@@ -407,7 +411,7 @@ class torus_knot_plus(Operator, AddObjectHelper):
description="Offset the surface relative to the curve"
)
-#### TORUS KNOT Options
+# TORUS KNOT Options
torus_p = IntProperty(
name="p",
default=2,
@@ -460,7 +464,7 @@ class torus_knot_plus(Operator, AddObjectHelper):
description="Phase spins by this radian amount"
)
-#### TORUS DIMENSIONS options
+# TORUS DIMENSIONS options
mode = EnumProperty(
name="Torus Dimensions",
items=(("MAJOR_MINOR", "Major/Minor",
@@ -514,7 +518,7 @@ class torus_knot_plus(Operator, AddObjectHelper):
description="Scale along the local Z axis"
)
-#### CURVE options
+# CURVE options
torus_res = IntProperty(
name="Curve Resolution",
default=100,
@@ -573,7 +577,8 @@ class torus_knot_plus(Operator, AddObjectHelper):
links = gcd(self.torus_p, self.torus_q)
info = "Multiple Links"
- if links > 1: info += " ( " + str(links) + " )"
+ if links > 1:
+ info += " ( " + str(links) + " )"
box.prop(self, 'multiple_links', text=info)
if self.options_plus:
@@ -596,7 +601,7 @@ class torus_knot_plus(Operator, AddObjectHelper):
col = box.column(align=True)
col.prop(self, "torus_r")
- else: # EXTERIOR-INTERIOR
+ else: # EXTERIOR-INTERIOR
col = box.column(align=True)
col.prop(self, "torus_eR")
@@ -617,7 +622,7 @@ class torus_knot_plus(Operator, AddObjectHelper):
col.label(text="Output Curve Type:")
col.row().prop(self, 'outputType', expand=True)
- depends=box.column()
+ depends = box.column()
depends.prop(self, 'torus_res')
# deactivate the "curve resolution" if "adaptive resolution" is enabled
depends.enabled = not self.adaptive_resolution
@@ -658,29 +663,31 @@ class torus_knot_plus(Operator, AddObjectHelper):
##### POLL #####
@classmethod
def poll(cls, context):
- if context.mode != "OBJECT": return False
- return context.scene != None
+ if context.mode != "OBJECT":
+ return False
+ return context.scene is not None
##### EXECUTE #####
def execute(self, context):
if self.mode == 'EXT_INT':
-# adjust the equivalent radii pair : (R,r) <=> (eR,iR)
+ # adjust the equivalent radii pair : (R,r) <=> (eR,iR)
self.torus_R = (self.torus_eR + self.torus_iR)*0.5
self.torus_r = (self.torus_eR - self.torus_iR)*0.5
if self.adaptive_resolution:
-# adjust curve resolution automatically based on (p,q,R,r) values
+ # adjust curve resolution automatically based on (p,q,R,r) values
p = self.torus_p
q = self.torus_q
R = self.torus_R
r = self.torus_r
- links = gcd(p,q)
+ links = gcd(p, q)
# get an approximate length of the whole TK curve
- maxTKLen = 2*pi*sqrt(p*p*(R+r)*(R+r) + q*q*r*r) # upper bound approximation
- minTKLen = 2*pi*sqrt(p*p*(R-r)*(R-r) + q*q*r*r) # lower bound approximation
- avgTKLen = (minTKLen + maxTKLen)/2 # average approximation
- if DEBUG: print("Approximate average TK length = %.2f" % avgTKLen)
- self.torus_res = max(3, avgTKLen/links * 8) # x N factor = control points per unit length
+ maxTKLen = 2*pi*sqrt(p*p*(R+r)*(R+r) + q*q*r*r) # upper bound approximation
+ minTKLen = 2*pi*sqrt(p*p*(R-r)*(R-r) + q*q*r*r) # lower bound approximation
+ avgTKLen = (minTKLen + maxTKLen)/2 # average approximation
+ if DEBUG:
+ print("Approximate average TK length = %.2f" % avgTKLen)
+ self.torus_res = max(3, avgTKLen/links * 8) # x N factor = control points per unit length
# update align matrix
self.align_matrix = align_matrix(self, context)
diff --git a/add_curve_extra_objects/add_surface_plane_cone.py b/add_curve_extra_objects/add_surface_plane_cone.py
index 4e0a1e4b..98369047 100644
--- a/add_curve_extra_objects/add_surface_plane_cone.py
+++ b/add_curve_extra_objects/add_surface_plane_cone.py
@@ -30,6 +30,7 @@ from bpy.props import (
)
from bpy.types import Operator
+from bpy.utils import register_class, unregister_class
class MakeSurfaceWedge(Operator):
@@ -58,6 +59,10 @@ class MakeSurfaceWedge(Operator):
min=1,
max=500)
+ @classmethod
+ def poll(cls, context):
+ return context.mode == 'OBJECT'
+
def execute(self, context):
# variables
size = self.size
@@ -66,7 +71,7 @@ class MakeSurfaceWedge(Operator):
# add a surface Plane
bpy.ops.object.add_surface_plane()
# save some time, by getting instant acces to those values.
- ao = bpy.context.active_object
+ ao = context.active_object
point = ao.data.splines[0].points
# rotate 90 degrees on the z axis
ao.rotation_euler[0] = 0.0
@@ -77,10 +82,10 @@ class MakeSurfaceWedge(Operator):
bpy.ops.curve.select_all(action='DESELECT')
# select points 0 and 1, and extrudde them
# declaring ao and point again seems necesary...
- ao = bpy.context.active_object
+ ao = context.active_object
point = ao.data.splines[0].points
point[0].select = True
- ao = bpy.context.active_object
+ ao = context.active_object
point = ao.data.splines[0].points
point[1].select = True
bpy.ops.curve.extrude()
@@ -102,14 +107,14 @@ class MakeSurfaceWedge(Operator):
# get origin to geometry.
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN')
# change name
- bpy.context.active_object.name = 'SurfaceWedge'
+ context.active_object.name = 'SurfaceWedge'
# get the wedge to the 3d cursor.
- bpy.context.active_object.location = bpy.context.scene.cursor_location
+ context.active_object.location = context.scene.cursor_location
bpy.ops.transform.resize(value=(size, size, size))
# adjust resolution in u and v direction
- bpy.context.active_object.data.resolution_u = res_u
- bpy.context.active_object.data.resolution_v = res_v
+ context.active_object.data.resolution_u = res_u
+ context.active_object.data.resolution_v = res_v
return{'FINISHED'}
@@ -141,6 +146,10 @@ class MakeSurfaceCone(Operator):
min=1,
max=500)
+ @classmethod
+ def poll(cls, context):
+ return context.mode == 'OBJECT'
+
def execute(self, context):
size = self.size
res_u = self.res_u
@@ -149,8 +158,8 @@ class MakeSurfaceCone(Operator):
# add basemesh, a nurbs torus
bpy.ops.surface.primitive_nurbs_surface_torus_add(location=(0, 0, 0))
# get active object and active object name
- ao = bpy.context.active_object
- aoname = bpy.context.active_object.name
+ ao = context.active_object
+ aoname = context.active_object.name
# go to edit mode
bpy.ops.object.mode_set(mode='EDIT')
# deselect all
@@ -181,18 +190,18 @@ class MakeSurfaceCone(Operator):
bpy.ops.object.editmode_toggle()
bpy.ops.object.editmode_toggle()
# change name
- bpy.context.active_object.name = 'SurfaceCone'
+ context.active_object.name = 'SurfaceCone'
# go back to object mode
bpy.ops.object.editmode_toggle()
# bring object to cursor
bpy.ops.object.mode_set(mode='OBJECT')
- bpy.context.active_object.location = bpy.context.scene.cursor_location
+ context.active_object.location = context.scene.cursor_location
# adjust size
bpy.ops.transform.resize(value=(size, size, size))
# adjust resolution in u and v direction
- bpy.context.active_object.data.resolution_u = res_u
- bpy.context.active_object.data.resolution_v = res_v
+ context.active_object.data.resolution_u = res_u
+ context.active_object.data.resolution_v = res_v
return{'FINISHED'}
@@ -222,6 +231,10 @@ class MakeSurfaceStar(Operator):
min=1,
max=500)
+ @classmethod
+ def poll(cls, context):
+ return context.mode == 'OBJECT'
+
def execute(self, context):
size = self.size
res_u = self.res_u
@@ -231,7 +244,7 @@ class MakeSurfaceStar(Operator):
bpy.ops.surface.primitive_nurbs_surface_circle_add(location=(0, 0, 0))
# we got 8 points, we need 40 points.
# get active object
- ao = bpy.context.active_object
+ ao = context.active_object
# enter edtimode
bpy.ops.object.mode_set(mode='EDIT')
# deselect all
@@ -261,7 +274,7 @@ class MakeSurfaceStar(Operator):
(0.1545085906982422, -0.4755282402038574, 0.25, 1.0),
(0.8090166449546814, -0.5877856612205505, 0.2499999850988388, 1.0)]
for i in range(0, 10):
- bpy.context.active_object.data.splines[0].points[i].co = ListOfCoords[i]
+ context.active_object.data.splines[0].points[i].co = ListOfCoords[i]
# now select all, and subdivide till 40 points is reached:
bpy.ops.curve.select_all(action='SELECT')
@@ -280,15 +293,15 @@ class MakeSurfaceStar(Operator):
# origin to geometry
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY', center='MEDIAN')
# get object to 3d cursor
- bpy.context.active_object.location = bpy.context.scene.cursor_location
+ context.active_object.location = context.scene.cursor_location
# change name
ao.name = 'SurfaceStar'
# adjust size
bpy.ops.transform.resize(value=(size, size, size))
# adjust resolution in u and v direction
- bpy.context.active_object.data.resolution_u = res_u
- bpy.context.active_object.data.resolution_v = res_v
+ context.active_object.data.resolution_u = res_u
+ context.active_object.data.resolution_v = res_v
return{'FINISHED'}
@@ -318,6 +331,10 @@ class MakeSurfacePlane(Operator):
min=1,
max=500)
+ @classmethod
+ def poll(cls, context):
+ return context.mode == 'OBJECT'
+
def execute(self, context):
size = self.size
res_u = self.res_u
@@ -326,34 +343,34 @@ class MakeSurfacePlane(Operator):
bpy.ops.surface.primitive_nurbs_surface_surface_add() # add the base mesh, a NURBS Surface
bpy.ops.transform.resize(value=(1, 1, 0.0001), constraint_axis=(False, False, True)) # make it flat
- ao = bpy.context.active_object.name # get the active object' s name
+ ao = context.active_object.name # get the active object' s name
# added surface has 16 points
# deleting points to get plane shape.
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.curve.select_all(action='DESELECT')
- bpy.context.active_object.data.splines[0].points[0].select = True
- bpy.context.active_object.data.splines[0].points[1].select = True
- bpy.context.active_object.data.splines[0].points[2].select = True
- bpy.context.active_object.data.splines[0].points[3].select = True
+ context.active_object.data.splines[0].points[0].select = True
+ context.active_object.data.splines[0].points[1].select = True
+ context.active_object.data.splines[0].points[2].select = True
+ context.active_object.data.splines[0].points[3].select = True
bpy.ops.curve.delete(type='VERT')
- bpy.context.active_object.data.splines[0].points[8].select = True
- bpy.context.active_object.data.splines[0].points[9].select = True
- bpy.context.active_object.data.splines[0].points[10].select = True
- bpy.context.active_object.data.splines[0].points[11].select = True
+ context.active_object.data.splines[0].points[8].select = True
+ context.active_object.data.splines[0].points[9].select = True
+ context.active_object.data.splines[0].points[10].select = True
+ context.active_object.data.splines[0].points[11].select = True
bpy.ops.curve.delete(type='VERT')
- bpy.context.active_object.data.splines[0].points[0].select = True
- bpy.context.active_object.data.splines[0].points[4].select = True
+ context.active_object.data.splines[0].points[0].select = True
+ context.active_object.data.splines[0].points[4].select = True
bpy.ops.curve.delete(type='VERT')
- bpy.context.active_object.data.splines[0].points[2].select = True
- bpy.context.active_object.data.splines[0].points[5].select = True
+ context.active_object.data.splines[0].points[2].select = True
+ context.active_object.data.splines[0].points[5].select = True
bpy.ops.curve.delete(type='VERT')
# assigning name
- bpy.context.active_object.name = 'SurfacePlane'
+ context.active_object.name = 'SurfacePlane'
# select all
bpy.ops.curve.select_all(action='SELECT')
# bringing origin to center:
@@ -363,12 +380,12 @@ class MakeSurfacePlane(Operator):
bpy.ops.object.transform_apply(scale=True)
# bring object to 3d cursor.
bpy.ops.object.mode_set(mode='OBJECT')
- bpy.context.active_object.location = bpy.context.scene.cursor_location
+ context.active_object.location = context.scene.cursor_location
bpy.ops.transform.resize(value=(size, size, size))
# adjust resolution in u and v direction
- bpy.context.active_object.data.resolution_u = res_u
- bpy.context.active_object.data.resolution_v = res_v
+ context.active_object.data.resolution_u = res_u
+ context.active_object.data.resolution_v = res_v
return{'FINISHED'}
@@ -391,6 +408,10 @@ class SmoothXtimes(Operator):
default=1,
description='amount of smooths')
+ @classmethod
+ def poll(cls, context):
+ return context.mode == 'EDIT_SURFACE'
+
def execute(self, context):
# smooth times time(s).
times = self.times
@@ -420,12 +441,12 @@ def SmoothXtimes_button(self, context):
def register():
- bpy.utils.register_class(UserInterface)
- bpy.utils.register_class(MakeSurfacePlane)
- bpy.utils.register_class(MakeSurfaceCone)
- bpy.utils.register_class(MakeSurfaceStar)
- bpy.utils.register_class(MakeSurfaceWedge)
- bpy.utils.register_class(SmoothXtimes)
+ register_class(UserInterface)
+ register_class(MakeSurfacePlane)
+ register_class(MakeSurfaceCone)
+ register_class(MakeSurfaceStar)
+ register_class(MakeSurfaceWedge)
+ register_class(SmoothXtimes)
bpy.types.INFO_MT_surface_add.append(Surface_plane_button)
bpy.types.INFO_MT_surface_add.append(Surface_cone_button)
bpy.types.INFO_MT_surface_add.append(Surface_star_button)
@@ -434,12 +455,12 @@ def register():
def unregister():
- bpy.utils.unregister_class(UserInterface)
- bpy.utils.unregister_class(MakeSurfacePlane)
- bpy.utils.unregister_class(MakeSurfaceCone)
- bpy.utils.unregister_class(MakeSurfaceStar)
- bpy.utils.unregister_class(MakeSurfaceWedge)
- bpy.utils.unregister_class(SmoothXtimes)
+ unregister_class(UserInterface)
+ unregister_class(MakeSurfacePlane)
+ unregister_class(MakeSurfaceCone)
+ unregister_class(MakeSurfaceStar)
+ unregister_class(MakeSurfaceWedge)
+ unregister_class(SmoothXtimes)
bpy.types.INFO_MT_surface_add.remove(Surface_plane_button)
bpy.types.INFO_MT_surface_add.remove(Surface_cone_button)
bpy.types.INFO_MT_surface_add.remove(Surface_star_button)