add_mesh_torus now passes the pep8 test

This commit is contained in:
Campbell Barton 2009-11-01 18:07:35 +00:00
parent 29aea786cb
commit 2cf22b53bc
3 changed files with 113 additions and 89 deletions

@ -4,112 +4,136 @@
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation, # along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
# ##### END GPL LICENSE BLOCK ##### # ##### END GPL LICENSE BLOCK #####
import bpy, Mathutils # <pep8-80 compliant>
from math import cos, sin, pi, radians import bpy
import Mathutils
from math import cos, sin, pi
def add_torus(PREF_MAJOR_RAD, PREF_MINOR_RAD, PREF_MAJOR_SEG, PREF_MINOR_SEG): def add_torus(major_rad, minor_rad, major_seg, minor_seg):
Vector = Mathutils.Vector Vector = Mathutils.Vector
Quaternion = Mathutils.Quaternion Quaternion = Mathutils.Quaternion
PI_2= pi*2
Z_AXIS = 0,0,1
verts = []
faces = []
i1 = 0
tot_verts = PREF_MAJOR_SEG * PREF_MINOR_SEG
for major_index in range(PREF_MAJOR_SEG):
verts_tmp = []
quat = Quaternion( Z_AXIS, (major_index/PREF_MAJOR_SEG)*PI_2)
for minor_index in range(PREF_MINOR_SEG): PI_2 = pi * 2
angle = 2*pi*minor_index/PREF_MINOR_SEG z_axis = (0, 0, 1)
vec = Vector(PREF_MAJOR_RAD+(cos(angle)*PREF_MINOR_RAD), 0, (sin(angle)*PREF_MINOR_RAD)) * quat verts = []
verts.extend([vec.x, vec.y, vec.z]) faces = []
i1 = 0
if minor_index+1==PREF_MINOR_SEG: tot_verts = major_seg * minor_seg
i2 = (major_index)*PREF_MINOR_SEG for major_index in range(major_seg):
i3 = i1 + PREF_MINOR_SEG quat = Quaternion(z_axis, (major_index / major_seg) * PI_2)
i4 = i2 + PREF_MINOR_SEG
for minor_index in range(minor_seg):
else: angle = 2 * pi * minor_index / minor_seg
i2 = i1 + 1
i3 = i1 + PREF_MINOR_SEG vec = Vector(major_rad + (cos(angle) * minor_rad), 0.0,
i4 = i3 + 1 (sin(angle) * minor_rad)) * quat
if i2>=tot_verts: i2 = i2-tot_verts verts.extend([vec.x, vec.y, vec.z])
if i3>=tot_verts: i3 = i3-tot_verts
if i4>=tot_verts: i4 = i4-tot_verts if minor_index + 1 == minor_seg:
i2 = (major_index) * minor_seg
# stupid eekadoodle i3 = i1 + minor_seg
if i2: faces.extend( [i1,i3,i4,i2] ) i4 = i2 + minor_seg
else: faces.extend( [i2,i1,i3,i4] )
else:
i1+=1 i2 = i1 + 1
i3 = i1 + minor_seg
return verts, faces i4 = i3 + 1
if i2 >= tot_verts:
i2 = i2 - tot_verts
if i3 >= tot_verts:
i3 = i3 - tot_verts
if i4 >= tot_verts:
i4 = i4 - tot_verts
# stupid eekadoodle
if i2:
faces.extend([i1, i3, i4, i2])
else:
faces.extend([i2, i1, i3, i4])
i1 += 1
return verts, faces
from bpy.props import * from bpy.props import *
class MESH_OT_primitive_torus_add(bpy.types.Operator):
'''Add a torus mesh.''' class AddTorusPrimitive(bpy.types.Operator):
bl_idname = "mesh.primitive_torus_add" '''Add a torus mesh.'''
bl_label = "Add Torus" bl_idname = "mesh.primitive_torus_add"
bl_register = True bl_label = "Add Torus"
bl_undo = True bl_register = True
bl_undo = True
major_radius = FloatProperty(name="Major Radius", description="Number of segments for the main ring of the torus", default= 1.0, min= 0.01, max= 100.0)
minor_radius = FloatProperty(name="Minor Radius", description="Number of segments for the minor ring of the torus", default= 0.25, min= 0.01, max= 100.0) major_radius = FloatProperty(name="Major Radius",
major_segments = IntProperty(name="Major Segments", description="Number of segments for the main ring of the torus", default= 48, min= 3, max= 256) description="Number of segments for the main ring of the torus",
minor_segments = IntProperty(name="Minor Segments", description="Number of segments for the minor ring of the torus", default= 16, min= 3, max= 256) default=1.0, min=0.01, max=100.0)
minor_radius = FloatProperty(name="Minor Radius",
def execute(self, context): description="Number of segments for the minor ring of the torus",
verts_loc, faces = add_torus(self.major_radius, self.minor_radius, self.major_segments, self.minor_segments) default=0.25, min=0.01, max=100.0)
major_segments = IntProperty(name="Major Segments",
me= bpy.data.add_mesh("Torus") description="Number of segments for the main ring of the torus",
default=48, min=3, max=256)
me.add_geometry(int(len(verts_loc)/3), 0, int(len(faces)/4)) minor_segments = IntProperty(name="Minor Segments",
me.verts.foreach_set("co", verts_loc) description="Number of segments for the minor ring of the torus",
me.faces.foreach_set("verts_raw", faces) default=16, min=3, max=256)
sce = context.scene def execute(self, context):
# ugh verts_loc, faces = add_torus(self.major_radius,
for ob in sce.objects: self.minor_radius,
ob.selected = False self.major_segments,
self.minor_segments)
me.update()
ob= bpy.data.add_object('MESH', "Torus") mesh = bpy.data.add_mesh("Torus")
ob.data= me
context.scene.add_object(ob) mesh.add_geometry(int(len(verts_loc) / 3), 0, int(len(faces) / 4))
context.scene.active_object = ob mesh.verts.foreach_set("co", verts_loc)
ob.selected = True mesh.faces.foreach_set("verts_raw", faces)
ob.location = tuple(context.scene.cursor_location) scene = context.scene
return ('FINISHED',) # ugh
for ob in scene.objects:
ob.selected = False
mesh.update()
ob_new = bpy.data.add_object('MESH', "Torus")
ob_new.data = mesh
scene.add_object(ob_new)
scene.active_object = ob_new
ob_new.selected = True
ob_new.location = tuple(context.scene.cursor_location)
return ('FINISHED',)
# Register the operator # Register the operator
bpy.ops.add(MESH_OT_primitive_torus_add) bpy.ops.add(AddTorusPrimitive)
# Add to a menu # Add to a menu
import dynamic_menu import dynamic_menu
import space_info
menu_item = dynamic_menu.add(bpy.types.INFO_MT_mesh_add, (lambda self, context: self.layout.itemO("mesh.primitive_torus_add", text="Torus", icon='ICON_MESH_DONUT')) ) menu_func = (lambda self, context: self.layout.itemO("mesh.primitive_torus_add",
text="Torus", icon='ICON_MESH_DONUT'))
menu_item = dynamic_menu.add(bpy.types.INFO_MT_mesh_add, menu_func)
if __name__ == "__main__": if __name__ == "__main__":
bpy.ops.mesh.primitive_torus_add() bpy.ops.mesh.primitive_torus_add()

@ -594,10 +594,10 @@ class ConstraintButtonsPanel(bpy.types.Panel):
row = layout.row() row = layout.row()
row.itemL(text="To:") row.itemL(text="To:")
row.itemR(con, "track", expand=True) row.itemR(con, "track", expand=True)
def SPLINE_IK(self, context, layout, con): def SPLINE_IK(self, context, layout, con):
self.target_template(layout, con) self.target_template(layout, con)
row = layout.row() row = layout.row()
row.itemR(con, "chain_length") row.itemR(con, "chain_length")
# TODO: add the various options this constraint has... # TODO: add the various options this constraint has...

@ -643,7 +643,7 @@ class PARTICLE_PT_render(ParticleButtonsPanel):
subsub.itemR(part, "adaptive_pix") subsub.itemR(part, "adaptive_pix")
sub.itemR(part, "hair_bspline") sub.itemR(part, "hair_bspline")
sub.itemR(part, "render_step", text="Steps") sub.itemR(part, "render_step", text="Steps")
sub = split.column() sub = split.column()
sub.itemL(text="Timing:") sub.itemL(text="Timing:")
sub.itemR(part, "abs_path_time") sub.itemR(part, "abs_path_time")