~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to release/scripts/add_mesh_torus.py

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!BPY
 
2
"""
 
3
Name: 'Torus'
 
4
Blender: 243
 
5
Group: 'AddMesh'
 
6
"""
 
7
import BPyAddMesh
 
8
import Blender
 
9
from math import cos, sin, pi
 
10
 
 
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
 
14
        verts = []
 
15
        faces = []
 
16
        i1 = 0
 
17
        tot_verts = PREF_MAJOR_SEG * PREF_MINOR_SEG
 
18
        for major_index in xrange(PREF_MAJOR_SEG):
 
19
                verts_tmp = []
 
20
                mtx = RotationMatrix( 360 * float(major_index)/PREF_MAJOR_SEG, 3, 'z' )
 
21
                
 
22
                for minor_index in xrange(PREF_MINOR_SEG):
 
23
                        angle = 2*pi*minor_index/PREF_MINOR_SEG
 
24
                        
 
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
 
30
                                
 
31
                        else:
 
32
                                i2 = i1 + 1
 
33
                                i3 = i1 + PREF_MINOR_SEG
 
34
                                i4 = i3 + 1
 
35
                        
 
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
 
39
                        
 
40
                        faces.append( (i3,i4,i2,i1) )
 
41
                        i1+=1
 
42
        
 
43
        return verts, faces
 
44
 
 
45
def main():
 
46
        Draw = Blender.Draw
 
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)
 
51
 
 
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.'),\
 
57
        ]):
 
58
                return
 
59
        
 
60
        verts, faces = add_torus(PREF_MAJOR_RAD.val, PREF_MINOR_RAD.val, PREF_MAJOR_SEG.val, PREF_MINOR_SEG.val)
 
61
        
 
62
        BPyAddMesh.add_mesh_simple('Torus', verts, [], faces)
 
63
 
 
64
main()
 
 
b'\\ No newline at end of file'