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