~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to release/scripts/addons_contrib/oscurart_mesh_thread.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-05-12 20:02:22 UTC
  • mfrom: (14.2.16 sid)
  • Revision ID: package-import@ubuntu.com-20120512200222-lznjs2cxzaq96wua
Tags: 2.63a-1
* New upstream bugfix release
  + debian/patches/: re-worked since source code changed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# ##### BEGIN GPL LICENSE BLOCK #####
2
 
#
3
 
#  This program is free software; you can redistribute it and/or
4
 
#  modify it under the terms of the GNU General Public License
5
 
#  as published by the Free Software Foundation; either version 2
6
 
#  of the License, or (at your option) any later version.
7
 
#
8
 
#  This program is distributed in the hope that it will be useful,
9
 
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
#  GNU General Public License for more details.
12
 
#
13
 
#  You should have received a copy of the GNU General Public License
14
 
#  along with this program; if not, write to the Free Software Foundation,
15
 
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
 
#
17
 
# ##### END GPL LICENSE BLOCK #####
18
 
 
19
 
bl_info = {
20
 
    "name": "Make Thread Mesh",
21
 
    "author": "Oscurart",
22
 
    "version": (1,0),
23
 
    "blender": (2, 5, 9),
24
 
    "api": 4000,
25
 
    "location": "Add > Mesh > Thread",
26
 
    "description": "Make a thread.",
27
 
    "warning": "",
28
 
    "wiki_url": "oscurart.blogspot.com",
29
 
    "tracker_url": "",
30
 
    "category": "Object"}
31
 
 
32
 
 
33
 
 
34
 
import math
35
 
import bpy
36
 
 
37
 
 
38
 
def func_osc_screw(self, STRETCH,TURNS,DIAMETER,RESOLUTION):
39
 
    # DATA PARA EL MESH
40
 
    me = bpy.data.meshes.new("threadData")
41
 
    obj = bpy.data.objects.new("Thread", me)     
42
 
    bpy.context.scene.objects.link(obj)  
43
 
      
44
 
    # VARIABLES
45
 
    vertexlist=[]
46
 
    facelist=[]
47
 
    facereset=0     
48
 
    CANTDIV=360/RESOLUTION
49
 
    ESPACIODIV=STRETCH/(TURNS+2+RESOLUTION)
50
 
 
51
 
    # PARA CADA VERTICE EN EL RANGO DESDE CERO A LENGTH 
52
 
    for vertice in range(0,TURNS+2+RESOLUTION):        
53
 
        # SUMA EN LA LISTA UN VERTICE       
54
 
        vertexlist.append((math.sin(math.radians(vertice*CANTDIV))*DIAMETER,vertice*ESPACIODIV,math.cos(math.radians(vertice*CANTDIV))*DIAMETER))
55
 
        if vertice > RESOLUTION:
56
 
            facelist.append((vertice-(RESOLUTION),vertice-((RESOLUTION)+1),vertice-1,vertice))    
57
 
 
58
 
    # CONECTO OBJETO    
59
 
    me.from_pydata(vertexlist,[],facelist)
60
 
    me.update()
61
 
    
62
 
 
63
 
 
64
 
class oscMakeScrew (bpy.types.Operator):
65
 
 
66
 
    bl_idname = "mesh.primitive_thread_oscurart"
67
 
    bl_label = "Add Mesh Thread"
68
 
    bl_description = "Create a Thread"
69
 
    bl_options = {'REGISTER', 'UNDO'}
70
 
 
71
 
    resolution = bpy.props.IntProperty (name="Resolution",default=10,min=3,max=1000)
72
 
    stretch = bpy.props.FloatProperty (name="Stretch",default=1,min=0.000001,max=1000)
73
 
    turns = bpy.props.IntProperty (name="Turns Steps",default=19,min=0)
74
 
    diameter = bpy.props.FloatProperty (name="Diameter",default=1,min=0,max=1000)
75
 
  
76
 
    
77
 
    
78
 
    def execute(self, context):
79
 
        func_osc_screw(self, self.stretch,self.turns,self.diameter,self.resolution)
80
 
        return {'FINISHED'}
81
 
 
82
 
 
83
 
# Registration
84
 
 
85
 
def add_screw_list(self, context):
86
 
    self.layout.operator(
87
 
        "mesh.primitive_thread_oscurart",
88
 
        text="Thread",
89
 
        icon="PLUGIN")
90
 
 
91
 
def register():
92
 
    bpy.types.INFO_MT_mesh_add.append(add_screw_list)
93
 
    bpy.utils.register_class(oscMakeScrew)
94
 
 
95
 
 
96
 
def unregister():
97
 
    bpy.types.INFO_MT_mesh_add.remove(add_screw_list)
98
 
    bpy.utils.unregister_class(oscMakeScrew)
99
 
 
100
 
 
101
 
if __name__ == '__main__':
102
 
    register()
103