diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-04-03 09:57:04 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-04-03 09:57:04 +0400 |
commit | 70869641df8e6e38e4a3e3a8cce542349e9f81ea (patch) | |
tree | 328c389efae4721dcf60aa68aec0b37d0f16bbd6 /release | |
parent | dab9f85485664a60976b72535224152bbc10fac3 (diff) |
Python Add Mesh Script, adds a Torus with radius and segment options.
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/add_mesh_torus.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/release/scripts/add_mesh_torus.py b/release/scripts/add_mesh_torus.py new file mode 100644 index 00000000000..7cc55815755 --- /dev/null +++ b/release/scripts/add_mesh_torus.py @@ -0,0 +1,64 @@ +#!BPY +""" +Name: 'Torus' +Blender: 243 +Group: 'AddMesh' +""" +import BPyAddMesh +import Blender +from math import cos, sin, pi + +def add_torus(PREF_MAJOR_RAD, PREF_MINOR_RAD, PREF_MAJOR_SEG, PREF_MINOR_SEG): + Vector = Blender.Mathutils.Vector + RotationMatrix = Blender.Mathutils.RotationMatrix + verts = [] + faces = [] + i1 = 0 + tot_verts = PREF_MAJOR_SEG * PREF_MINOR_SEG + for major_index in xrange(PREF_MAJOR_SEG): + verts_tmp = [] + mtx = RotationMatrix( 360 * float(major_index)/PREF_MAJOR_SEG, 3, 'z' ) + + for minor_index in xrange(PREF_MINOR_SEG): + angle = 2*pi*minor_index/PREF_MINOR_SEG + + verts.append( Vector(PREF_MAJOR_RAD+(cos(angle)*PREF_MINOR_RAD), 0, (sin(angle)*PREF_MINOR_RAD)) * mtx ) + if minor_index+1==PREF_MINOR_SEG: + i2 = (major_index)*PREF_MINOR_SEG + i3 = i1 + PREF_MINOR_SEG + i4 = i2 + PREF_MINOR_SEG + print i1,i2,i3,i4 + else: + i2 = i1 + 1 + i3 = i1 + PREF_MINOR_SEG + 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 + + faces.append( (i3,i4,i2,i1) ) + i1+=1 + + return verts, faces + +def main(): + Draw = Blender.Draw + PREF_MAJOR_RAD = Draw.Create(1.0) + PREF_MINOR_RAD = Draw.Create(0.25) + PREF_MAJOR_SEG = Draw.Create(48) + PREF_MINOR_SEG = Draw.Create(16) + + if not Draw.PupBlock('Add Torus', [\ + ('Major Radius:', PREF_MAJOR_RAD, 0.01, 100, 'Radius for the main ring of the torus'),\ + ('Minor Radius:', PREF_MINOR_RAD, 0.01, 100, 'Radius for the minor ring of the torus setting the thickness of the ring.'),\ + ('Major Segments:', PREF_MAJOR_SEG, 3, 256, 'Radius for the main ring of the torus'),\ + ('Minor Segments:', PREF_MINOR_SEG, 3, 256, 'Radius for the minor ring of the torus setting the thickness of the ring.'),\ + ]): + return + + verts, faces = add_torus(PREF_MAJOR_RAD.val, PREF_MINOR_RAD.val, PREF_MAJOR_SEG.val, PREF_MINOR_SEG.val) + + BPyAddMesh.add_mesh_simple('Torus', verts, [], faces) + +main()
\ No newline at end of file |