9
from math import cos, sin, pi
11
def add_torus(PREF_MAJOR_RAD, PREF_MINOR_RAD, PREF_MAJOR_SEG, PREF_MINOR_SEG):
12
Vector = Blender.Mathutils.Vector
13
RotationMatrix = Blender.Mathutils.RotationMatrix
17
tot_verts = PREF_MAJOR_SEG * PREF_MINOR_SEG
18
for major_index in xrange(PREF_MAJOR_SEG):
20
mtx = RotationMatrix( 360 * float(major_index)/PREF_MAJOR_SEG, 3, 'z' )
22
for minor_index in xrange(PREF_MINOR_SEG):
23
angle = 2*pi*minor_index/PREF_MINOR_SEG
25
verts.append( Vector(PREF_MAJOR_RAD+(cos(angle)*PREF_MINOR_RAD), 0, (sin(angle)*PREF_MINOR_RAD)) * mtx )
26
if minor_index+1==PREF_MINOR_SEG:
27
i2 = (major_index)*PREF_MINOR_SEG
28
i3 = i1 + PREF_MINOR_SEG
29
i4 = i2 + PREF_MINOR_SEG
33
i3 = i1 + PREF_MINOR_SEG
36
if i2>=tot_verts: i2 = i2-tot_verts
37
if i3>=tot_verts: i3 = i3-tot_verts
38
if i4>=tot_verts: i4 = i4-tot_verts
40
faces.append( (i3,i4,i2,i1) )
47
PREF_MAJOR_RAD = Draw.Create(1.0)
48
PREF_MINOR_RAD = Draw.Create(0.25)
49
PREF_MAJOR_SEG = Draw.Create(48)
50
PREF_MINOR_SEG = Draw.Create(16)
52
if not Draw.PupBlock('Add Torus', [\
53
('Major Radius:', PREF_MAJOR_RAD, 0.01, 100, 'Radius for the main ring of the torus'),\
54
('Minor Radius:', PREF_MINOR_RAD, 0.01, 100, 'Radius for the minor ring of the torus setting the thickness of the ring.'),\
55
('Major Segments:', PREF_MAJOR_SEG, 3, 256, 'Radius for the main ring of the torus'),\
56
('Minor Segments:', PREF_MINOR_SEG, 3, 256, 'Radius for the minor ring of the torus setting the thickness of the ring.'),\
60
verts, faces = add_torus(PREF_MAJOR_RAD.val, PREF_MINOR_RAD.val, PREF_MAJOR_SEG.val, PREF_MINOR_SEG.val)
62
BPyAddMesh.add_mesh_simple('Torus', verts, [], faces)
b'\\ No newline at end of file'