Newer
Older
vec1 = Vector([x, y, 0.0])
verts.append([x, y, -Flat_Height - Undercut_Height])
x = sin(radians(60 / 6)) * Half_Flat
y = cos(radians(60 / 6)) * Half_Flat
vec2 = Vector([x, y, 0.0])
verts.append([x, y, -Flat_Height - Undercut_Height])
x = sin(radians(60 / 3)) * Half_Flat
y = cos(radians(60 / 3)) * Half_Flat
vec3 = Vector([x, y, 0.0])
verts.append([x, y, -Flat_Height - Undercut_Height])
x = sin(radians(60 / 2)) * Half_Flat
y = cos(radians(60 / 2)) * Half_Flat
vec3 = Vector([x, y, 0.0])
verts.append([x, y, -Flat_Height - Undercut_Height])
Campbell Barton
committed
# Under cut to Shank BEVEL
x = sin(radians(0)) * (SHANK_RADIUS + Shank_Bevel)
y = cos(radians(0)) * (SHANK_RADIUS + Shank_Bevel)
vec1 = Vector([x, y, 0.0])
verts.append([x, y, -Flat_Height - Undercut_Height])
x = sin(radians(60 / 6)) * (SHANK_RADIUS + Shank_Bevel)
y = cos(radians(60 / 6)) * (SHANK_RADIUS + Shank_Bevel)
vec2 = Vector([x, y, 0.0])
verts.append([x, y, -Flat_Height - Undercut_Height])
x = sin(radians(60 / 3)) * (SHANK_RADIUS + Shank_Bevel)
y = cos(radians(60 / 3)) * (SHANK_RADIUS + Shank_Bevel)
vec3 = Vector([x, y, 0.0])
verts.append([x, y, -Flat_Height - Undercut_Height])
x = sin(radians(60 / 2)) * (SHANK_RADIUS + Shank_Bevel)
y = cos(radians(60 / 2)) * (SHANK_RADIUS + Shank_Bevel)
vec3 = Vector([x, y, 0.0])
verts.append([x, y, -Flat_Height - Undercut_Height])
Campbell Barton
committed
# Under cut to Shank BEVEL
x = sin(radians(0)) * SHANK_RADIUS
y = cos(radians(0)) * SHANK_RADIUS
vec1 = Vector([x, y, 0.0])
verts.append([x, y, -Flat_Height - Undercut_Height - Shank_Bevel])
x = sin(radians(60 / 6)) * SHANK_RADIUS
y = cos(radians(60 / 6)) * SHANK_RADIUS
vec2 = Vector([x, y, 0.0])
verts.append([x, y, -Flat_Height - Undercut_Height - Shank_Bevel])
x = sin(radians(60 / 3)) * SHANK_RADIUS
y = cos(radians(60 / 3)) * SHANK_RADIUS
vec3 = Vector([x, y, 0.0])
verts.append([x, y, -Flat_Height - Undercut_Height - Shank_Bevel])
x = sin(radians(60 / 2)) * SHANK_RADIUS
y = cos(radians(60 / 2)) * SHANK_RADIUS
vec3 = Vector([x, y, 0.0])
verts.append([x, y, -Flat_Height - Undercut_Height - Shank_Bevel])
Campbell Barton
committed
faces.extend(Build_Face_List_Quads(FaceStart, 3, Row - 1))
Campbell Barton
committed
Mirror_Verts, Mirror_Faces = Mirror_Verts_Faces(verts, faces, 'y')
verts.extend(Mirror_Verts)
faces.extend(Mirror_Faces)
Campbell Barton
committed
Spin_Verts, Spin_Faces = SpinDup(verts, faces, 360, 6, 'z')
Campbell Barton
committed
return Spin_Verts, Spin_Faces, 0 - (-HEIGHT)
Campbell Barton
committed
# ####################################################################
# Create External Thread
# ####################################################################
def Thread_Start3(verts, INNER_RADIUS, OUTTER_RADIUS, PITCH, DIV_COUNT,
CREST_PERCENT, ROOT_PERCENT, Height_Offset):
Campbell Barton
committed
Height_Step = float(PITCH) / float(DIV_COUNT)
Deg_Step = 360.0 / float(DIV_COUNT)
Campbell Barton
committed
Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100)
Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100)
Root_to_Crest_Height = Crest_to_Root_Height = \
(float(PITCH) - (Crest_Height + Root_Height)) / 2.0
Campbell Barton
committed
# thread start
Rank = float(OUTTER_RADIUS - INNER_RADIUS) / float(DIV_COUNT)
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
verts.append([x, y, z])
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
Campbell Barton
committed
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
verts.append([x, y, z])
Height_Offset -= Crest_to_Root_Height
Ret_Row += 1
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
Campbell Barton
committed
x = sin(radians(i * Deg_Step)) * INNER_RADIUS
y = cos(radians(i * Deg_Step)) * INNER_RADIUS
x = sin(radians(i * Deg_Step)) * (OUTTER_RADIUS - (i * Rank))
y = cos(radians(i * Deg_Step)) * (OUTTER_RADIUS - (i * Rank))
verts.append([x, y, z])
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
Campbell Barton
committed
x = sin(radians(i * Deg_Step)) * INNER_RADIUS
y = cos(radians(i * Deg_Step)) * INNER_RADIUS
x = sin(radians(i * Deg_Step)) * (OUTTER_RADIUS - (i * Rank))
y = cos(radians(i * Deg_Step)) * (OUTTER_RADIUS - (i * Rank))
verts.append([x, y, z])
Height_Offset -= Root_to_Crest_Height
Ret_Row += 1
Campbell Barton
committed
def Create_Shank_Verts(START_DIA, OUTTER_DIA, LENGTH, Z_LOCATION, DIV_COUNT):
Campbell Barton
committed
START_RADIUS = START_DIA / 2
OUTTER_RADIUS = OUTTER_DIA / 2
Campbell Barton
committed
Taper_Lentgh = Opp / tan(radians(31))
Campbell Barton
committed
Campbell Barton
committed
Campbell Barton
committed
Deg_Step = 360.0 / float(DIV_COUNT)
Campbell Barton
committed
Campbell Barton
committed
Campbell Barton
committed
# Ring
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * START_RADIUS
y = cos(radians(i * Deg_Step)) * START_RADIUS
z = Height_Offset - 0
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Height_Offset -= Stright_Length
Row += 1
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * START_RADIUS
y = cos(radians(i * Deg_Step)) * START_RADIUS
z = Height_Offset - 0
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
return verts, Row, Height_Offset
def Create_Thread_Start_Verts(INNER_DIA, OUTTER_DIA, PITCH, CREST_PERCENT,
ROOT_PERCENT, Z_LOCATION, DIV_COUNT):
Campbell Barton
committed
INNER_RADIUS = INNER_DIA / 2
OUTTER_RADIUS = OUTTER_DIA / 2
Campbell Barton
committed
Deg_Step = 360.0 / float(DIV_COUNT)
Height_Step = float(PITCH) / float(DIV_COUNT)
Campbell Barton
committed
Campbell Barton
committed
Campbell Barton
committed
Height_Start = Height_Offset
Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100)
Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100)
Root_to_Crest_Height = Crest_to_Root_Height = \
(float(PITCH) - (Crest_Height + Root_Height)) / 2.0
Rank = float(OUTTER_RADIUS - INNER_RADIUS) / float(DIV_COUNT)
Campbell Barton
committed
Height_Offset = Z_LOCATION + PITCH
Campbell Barton
committed
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
z = Height_Offset - (Height_Step * i)
if z > Cut_off:
z = Cut_off
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
z = Height_Offset - (Height_Step * i)
if z > Cut_off:
z = Cut_off
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Height_Offset -= Crest_to_Root_Height
Row += 1
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
z = Height_Offset - (Height_Step * i)
if z > Cut_off:
z = Cut_off
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
z = Height_Offset - (Height_Step * i)
if z > Cut_off:
z = Cut_off
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Height_Offset -= Root_to_Crest_Height
Row += 1
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
Campbell Barton
committed
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Height_Offset -= Crest_to_Root_Height
Row += 1
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
Campbell Barton
committed
x = sin(radians(i * Deg_Step)) * INNER_RADIUS
y = cos(radians(i * Deg_Step)) * INNER_RADIUS
x = sin(radians(i * Deg_Step)) * (OUTTER_RADIUS - (i * Rank))
y = cos(radians(i * Deg_Step)) * (OUTTER_RADIUS - (i * Rank))
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
Campbell Barton
committed
x = sin(radians(i * Deg_Step)) * INNER_RADIUS
y = cos(radians(i * Deg_Step)) * INNER_RADIUS
x = sin(radians(i * Deg_Step)) * (OUTTER_RADIUS - (i * Rank))
y = cos(radians(i * Deg_Step)) * (OUTTER_RADIUS - (i * Rank))
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Height_Offset -= Root_to_Crest_Height
Row += 1
Campbell Barton
committed
return verts, Row, Height_Offset
def Create_Thread_Verts(INNER_DIA, OUTTER_DIA, PITCH, HEIGHT,
CREST_PERCENT, ROOT_PERCENT, Z_LOCATION, DIV_COUNT):
Campbell Barton
committed
INNER_RADIUS = INNER_DIA / 2
OUTTER_RADIUS = OUTTER_DIA / 2
Campbell Barton
committed
Deg_Step = 360.0 / float(DIV_COUNT)
Height_Step = float(PITCH) / float(DIV_COUNT)
NUM_OF_START_THREADS = 4.0
NUM_OF_END_THREADS = 3.0
Num = int((HEIGHT - ((NUM_OF_START_THREADS * PITCH) + (NUM_OF_END_THREADS * PITCH))) / PITCH)
Campbell Barton
committed
Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100)
Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100)
Root_to_Crest_Height = Crest_to_Root_Height = \
(float(PITCH) - (Crest_Height + Root_Height)) / 2.0
Campbell Barton
committed
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
z = Height_Offset - (Height_Step * i)
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
z = Height_Offset - (Height_Step * i)
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Height_Offset -= Crest_to_Root_Height
Row += 1
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * INNER_RADIUS
y = cos(radians(i * Deg_Step)) * INNER_RADIUS
z = Height_Offset - (Height_Step * i)
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * INNER_RADIUS
y = cos(radians(i * Deg_Step)) * INNER_RADIUS
z = Height_Offset - (Height_Step * i)
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Height_Offset -= Root_to_Crest_Height
Row += 1
Campbell Barton
committed
return verts, Row, Height_Offset
def Create_Thread_End_Verts(INNER_DIA, OUTTER_DIA, PITCH, CREST_PERCENT,
ROOT_PERCENT, Z_LOCATION, DIV_COUNT):
Campbell Barton
committed
INNER_RADIUS = INNER_DIA / 2
OUTTER_RADIUS = OUTTER_DIA / 2
Campbell Barton
committed
Deg_Step = 360.0 / float(DIV_COUNT)
Height_Step = float(PITCH) / float(DIV_COUNT)
Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100)
Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100)
Root_to_Crest_Height = Crest_to_Root_Height = \
(float(PITCH) - (Crest_Height + Root_Height)) / 2.0
Campbell Barton
committed
Campbell Barton
committed
Height_Offset = Z_LOCATION
Tapper_Height_Start = Height_Offset - PITCH - PITCH
Max_Height = Tapper_Height_Start - PITCH
Campbell Barton
committed
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
z = max(z, Max_Height)
Tapper_Radius = OUTTER_RADIUS
if z < Tapper_Height_Start:
Tapper_Radius = OUTTER_RADIUS - (Tapper_Height_Start - z)
x = sin(radians(i * Deg_Step)) * (Tapper_Radius)
y = cos(radians(i * Deg_Step)) * (Tapper_Radius)
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
z = max(z, Max_Height)
Tapper_Radius = OUTTER_RADIUS
if z < Tapper_Height_Start:
Tapper_Radius = OUTTER_RADIUS - (Tapper_Height_Start - z)
x = sin(radians(i * Deg_Step)) * (Tapper_Radius)
y = cos(radians(i * Deg_Step)) * (Tapper_Radius)
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Height_Offset -= Crest_to_Root_Height
Row += 1
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
z = max(z, Max_Height)
Tapper_Radius = OUTTER_RADIUS - (Tapper_Height_Start - z)
if Tapper_Radius > INNER_RADIUS:
Campbell Barton
committed
Tapper_Radius = INNER_RADIUS
Campbell Barton
committed
x = sin(radians(i * Deg_Step)) * (Tapper_Radius)
y = cos(radians(i * Deg_Step)) * (Tapper_Radius)
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
z = max(z, Max_Height)
Tapper_Radius = OUTTER_RADIUS - (Tapper_Height_Start - z)
if Tapper_Radius > INNER_RADIUS:
Campbell Barton
committed
Tapper_Radius = INNER_RADIUS
Campbell Barton
committed
x = sin(radians(i * Deg_Step)) * (Tapper_Radius)
y = cos(radians(i * Deg_Step)) * (Tapper_Radius)
verts.append([x, y, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Height_Offset -= Root_to_Crest_Height
Row += 1
Campbell Barton
committed
return verts, Row, Height_Offset, Lowest_Z_Vert
def Create_External_Thread(SHANK_DIA, SHANK_LENGTH, INNER_DIA, OUTTER_DIA,
PITCH, LENGTH, CREST_PERCENT, ROOT_PERCENT, DIV_COUNT):
Campbell Barton
committed
verts = []
faces = []
Total_Row = 0
Campbell Barton
committed
Campbell Barton
committed
Shank_Verts, Shank_Row, Offset = Create_Shank_Verts(
SHANK_DIA, OUTTER_DIA, SHANK_LENGTH,
Offset, DIV_COUNT
)
Thread_Start_Verts, Thread_Start_Row, Offset = Create_Thread_Start_Verts(
INNER_DIA, OUTTER_DIA, PITCH, CREST_PERCENT,
ROOT_PERCENT, Offset, DIV_COUNT
)
Campbell Barton
committed
Thread_Verts, Thread_Row, Offset = Create_Thread_Verts(
INNER_DIA, OUTTER_DIA, PITCH, LENGTH,
CREST_PERCENT, ROOT_PERCENT, Offset, DIV_COUNT
)
Campbell Barton
committed
Thread_End_Verts, Thread_End_Row, Offset, Lowest_Z_Vert = Create_Thread_End_Verts(
INNER_DIA, OUTTER_DIA, PITCH, CREST_PERCENT,
ROOT_PERCENT, Offset, DIV_COUNT
)
Campbell Barton
committed
Total_Row += Thread_End_Row
verts.extend(Shank_Verts)
verts.extend(Thread_Start_Verts)
verts.extend(Thread_Verts)
verts.extend(Thread_End_Verts)
Campbell Barton
committed
faces.extend(Build_Face_List_Quads(Face_Start, DIV_COUNT, Total_Row - 1, 0))
faces.extend(Fill_Ring_Face(len(verts) - DIV_COUNT, DIV_COUNT, 1))
Campbell Barton
committed
return verts, faces, 0.0 - Lowest_Z_Vert
Campbell Barton
committed
# ####################################################################
# Create Nut
# ####################################################################
def add_Hex_Nut(FLAT, HOLE_DIA, HEIGHT):
global Global_Head_Height
global Global_NutRad
Campbell Barton
committed
verts = []
faces = []
HOLE_RADIUS = HOLE_DIA * 0.5
Half_Flat = FLAT / 2
Half_Height = HEIGHT / 2
Campbell Barton
committed
Row = 0
Lowest_Z_Vert = 0.0
Campbell Barton
committed
Campbell Barton
committed
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
# inner hole
x = sin(radians(0)) * HOLE_RADIUS
y = cos(radians(0)) * HOLE_RADIUS
# print ("rad 0 x;", x, "y:" ,y )
verts.append([x, y, 0.0])
x = sin(radians(60 / 6)) * HOLE_RADIUS
y = cos(radians(60 / 6)) * HOLE_RADIUS
# print ("rad 60/6x;", x, "y:" ,y )
verts.append([x, y, 0.0])
x = sin(radians(60 / 3)) * HOLE_RADIUS
y = cos(radians(60 / 3)) * HOLE_RADIUS
# print ("rad 60/3x;", x, "y:" ,y )
verts.append([x, y, 0.0])
x = sin(radians(60 / 2)) * HOLE_RADIUS
y = cos(radians(60 / 2)) * HOLE_RADIUS
# print ("rad 60/2x;", x, "y:" ,y )
verts.append([x, y, 0.0])
Campbell Barton
committed
Campbell Barton
committed
x = sin(radians(0)) * TopBevelRadius
y = cos(radians(0)) * TopBevelRadius
vec1 = Vector([x, y, 0.0])
verts.append([x, y, 0.0])
Campbell Barton
committed
x = sin(radians(60 / 6)) * TopBevelRadius
y = cos(radians(60 / 6)) * TopBevelRadius
vec2 = Vector([x, y, 0.0])
verts.append([x, y, 0.0])
Campbell Barton
committed
x = sin(radians(60 / 3)) * TopBevelRadius
y = cos(radians(60 / 3)) * TopBevelRadius
vec3 = Vector([x, y, 0.0])
verts.append([x, y, 0.0])
Campbell Barton
committed
x = sin(radians(60 / 2)) * TopBevelRadius
y = cos(radians(60 / 2)) * TopBevelRadius
vec4 = Vector([x, y, 0.0])
verts.append([x, y, 0.0])
Campbell Barton
committed
# Flats
x = tan(radians(0)) * Half_Flat
dvec = vec1 - Vector([x, Half_Flat, 0.0])
verts.append([x, Half_Flat, -dvec.length])
Lowest_Z_Vert = min(Lowest_Z_Vert, -dvec.length)
Campbell Barton
committed
x = tan(radians(60 / 6)) * Half_Flat
dvec = vec2 - Vector([x, Half_Flat, 0.0])
verts.append([x, Half_Flat, -dvec.length])
Lowest_Z_Vert = min(Lowest_Z_Vert, -dvec.length)
Campbell Barton
committed
x = tan(radians(60 / 3)) * Half_Flat
dvec = vec3 - Vector([x, Half_Flat, 0.0])
verts.append([x, Half_Flat, -dvec.length])
Lowest_Z_Vert = min(Lowest_Z_Vert, -dvec.length)
x = tan(radians(60 / 2)) * Half_Flat
dvec = vec4 - Vector([x, Half_Flat, 0.0])
verts.append([x, Half_Flat, -dvec.length])
Lowest_Z_Vert = min(Lowest_Z_Vert, -dvec.length)
Campbell Barton
committed
# down Bits Tri
x = tan(radians(0)) * Half_Flat
verts.append([x, Half_Flat, Lowest_Point])
Campbell Barton
committed
x = tan(radians(60 / 6)) * Half_Flat
verts.append([x, Half_Flat, Lowest_Point])
x = tan(radians(60 / 3)) * Half_Flat
verts.append([x, Half_Flat, Lowest_Point])
Campbell Barton
committed
x = tan(radians(60 / 2)) * Half_Flat
verts.append([x, Half_Flat, Lowest_Point])
Lowest_Z_Vert = min(Lowest_Z_Vert, Lowest_Point)
Campbell Barton
committed
x = tan(radians(0)) * Half_Flat
verts.append([x, Half_Flat, -Half_Height])
Campbell Barton
committed
x = tan(radians(60 / 6)) * Half_Flat
verts.append([x, Half_Flat, -Half_Height])
x = tan(radians(60 / 3)) * Half_Flat
verts.append([x, Half_Flat, -Half_Height])
Campbell Barton
committed
x = tan(radians(60 / 2)) * Half_Flat
verts.append([x, Half_Flat, -Half_Height])
Lowest_Z_Vert = min(Lowest_Z_Vert, -Half_Height)
Campbell Barton
committed
faces.extend(Build_Face_List_Quads(FaceStart, 3, Row - 1))
Campbell Barton
committed
Tvert, tface = Mirror_Verts_Faces(verts, faces, 'z', Lowest_Z_Vert)
Campbell Barton
committed
Tvert, tface = Mirror_Verts_Faces(verts, faces, 'y')
Campbell Barton
committed
S_verts, S_faces = SpinDup(verts, faces, 360, 6, 'z')
# return verts, faces, TopBevelRadius
return S_verts, S_faces, TopBevelRadius
def add_Nylon_Head(OUTSIDE_RADIUS, Z_LOCATION, DIV_COUNT):
INNER_HOLE = OUTSIDE_RADIUS - (OUTSIDE_RADIUS * (1.25 / 4.75))
EDGE_THICKNESS = (OUTSIDE_RADIUS * (0.4 / 4.75))
RAD1 = (OUTSIDE_RADIUS * (0.5 / 4.75))
OVER_ALL_HEIGHT = (OUTSIDE_RADIUS * (2.0 / 4.75))
Campbell Barton
committed
Height_Offset = Z_LOCATION
Lowest_Z_Vert = 0
Campbell Barton
committed
z = (Height_Offset - OVER_ALL_HEIGHT) + EDGE_THICKNESS
verts.append([x, 0.0, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
z = (Height_Offset - OVER_ALL_HEIGHT)
verts.append([x, 0.0, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
for i in range(180, 80, -10):
x = sin(radians(i)) * RAD1
z = cos(radians(i)) * RAD1
verts.append([(OUTSIDE_RADIUS - RAD1) + x, 0.0, ((Height_Offset - OVER_ALL_HEIGHT) + RAD1) + z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
Campbell Barton
committed
z = Height_Offset
verts.append([x, 0.0, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
sVerts, sFaces = SpinDup(verts, faces, 360, DIV_COUNT, 'z')
sVerts.extend(verts) # add the start verts to the Spin verts to complete the loop
Campbell Barton
committed
faces.extend(Build_Face_List_Quads(FaceStart, Row - 1, DIV_COUNT,1))
return Move_Verts_Up_Z(sVerts, 0), faces, Lowest_Z_Vert
def add_Nylon_Part(OUTSIDE_RADIUS, Z_LOCATION, DIV_COUNT):
INNER_HOLE = OUTSIDE_RADIUS - (OUTSIDE_RADIUS * (1.5 / 4.75))
EDGE_THICKNESS = (OUTSIDE_RADIUS * (0.4 / 4.75))
OVER_ALL_HEIGHT = (OUTSIDE_RADIUS * (2.0 / 4.75))
PART_THICKNESS = OVER_ALL_HEIGHT - EDGE_THICKNESS
PART_INNER_HOLE = (OUTSIDE_RADIUS * (2.5 / 4.75))
Campbell Barton
committed
FaceStart = len(verts)
Height_Offset = Z_LOCATION
Lowest_Z_Vert = 0
Campbell Barton
committed
Campbell Barton
committed
z = Height_Offset
verts.append([x, 0.0, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
verts.append([x, 0.0, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
x = PART_INNER_HOLE
z = Height_Offset - PART_THICKNESS
verts.append([x, 0.0, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
Campbell Barton
committed
x = INNER_HOLE + EDGE_THICKNESS
z = Height_Offset - PART_THICKNESS
verts.append([x, 0.0, z])
Lowest_Z_Vert = min(Lowest_Z_Vert, z)
sVerts, sFaces = SpinDup(verts, faces, 360, DIV_COUNT, 'z')
sVerts.extend(verts) # add the start verts to the Spin verts to complete the loop
faces.extend(Build_Face_List_Quads(FaceStart, Row - 1, DIV_COUNT, 1))
return sVerts, faces, 0 - Lowest_Z_Vert
# ####################################################################
# Create Internal Thread
# ####################################################################
def Create_Internal_Thread_Start_Verts(verts, INNER_RADIUS, OUTTER_RADIUS, PITCH, DIV,
CREST_PERCENT, ROOT_PERCENT, Height_Offset):
Ret_Row = 0
# Move the offset up so that the verts start at
# at the correct place (Height_Start)
Height_Offset = Height_Offset + PITCH
Campbell Barton
committed
Height_Start = Height_Offset - PITCH
Height_Step = float(PITCH) / float(DIV)
Deg_Step = 360.0 / float(DIV)
Campbell Barton
committed
Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100)
Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100)
Root_to_Crest_Height = Crest_to_Root_Height = \
(float(PITCH) - (Crest_Height + Root_Height)) / 2.0
Campbell Barton
committed
Rank = float(OUTTER_RADIUS - INNER_RADIUS) / float(DIV)
for i in range(DIV + 1):
z = Height_Offset - (Height_Step * i)
if z > Height_Start:
z = Height_Start
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
Campbell Barton
committed
verts.append([x, y, z])
Height_Offset -= Crest_Height
Ret_Row += 1
Campbell Barton
committed
for i in range(DIV + 1):
z = Height_Offset - (Height_Step * i)
if z > Height_Start:
z = Height_Start
Campbell Barton
committed
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
Campbell Barton
committed
verts.append([x, y, z])
Height_Offset -= Crest_to_Root_Height
Ret_Row += 1
Campbell Barton
committed
for i in range(DIV + 1):
z = Height_Offset - (Height_Step * i)
if z > Height_Start:
z = Height_Start
Campbell Barton
committed
x = sin(radians(i * Deg_Step)) * INNER_RADIUS
y = cos(radians(i * Deg_Step)) * INNER_RADIUS
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
x = sin(radians(i * Deg_Step)) * (OUTTER_RADIUS - (i * Rank))
y = cos(radians(i * Deg_Step)) * (OUTTER_RADIUS - (i * Rank))
verts.append([x, y, z])
Height_Offset -= Root_Height
Ret_Row += 1
for i in range(DIV + 1):
z = Height_Offset - (Height_Step * i)
if z > Height_Start:
z = Height_Start
x = sin(radians(i * Deg_Step)) * INNER_RADIUS
y = cos(radians(i * Deg_Step)) * INNER_RADIUS
x = sin(radians(i * Deg_Step)) * (OUTTER_RADIUS - (i * Rank))
y = cos(radians(i * Deg_Step)) * (OUTTER_RADIUS - (i * Rank))
verts.append([x, y, z])
Height_Offset -= Root_to_Crest_Height
Ret_Row += 1
Campbell Barton
committed
def Create_Internal_Thread_End_Verts(verts, INNER_RADIUS, OUTTER_RADIUS, PITCH,
CREST_PERCENT, ROOT_PERCENT, Height_Offset,
DIV_COUNT):
Campbell Barton
committed
Height_End = Height_Offset - PITCH
Height_Step = float(PITCH) / float(DIV_COUNT)
Deg_Step = 360.0 / float(DIV_COUNT)
Campbell Barton
committed
Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100)
Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100)
Root_to_Crest_Height = Crest_to_Root_Height = \
(float(PITCH) - (Crest_Height + Root_Height)) / 2.0
Rank = float(OUTTER_RADIUS - INNER_RADIUS) / float(DIV_COUNT)
Campbell Barton
committed
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
verts.append([x, y, z])
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
Campbell Barton
committed
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
verts.append([x, y, z])
Height_Offset -= Crest_to_Root_Height
Ret_Row += 1
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
Campbell Barton
committed
x = sin(radians(i * Deg_Step)) * INNER_RADIUS
y = cos(radians(i * Deg_Step)) * INNER_RADIUS
# Fix T51338 - seems that the placing a small random offset makes the mesh valid
rand_offset = triangular(0.0001, 0.009)
x = sin(radians(i * Deg_Step)) * (INNER_RADIUS + (i * Rank + rand_offset))
y = cos(radians(i * Deg_Step)) * (INNER_RADIUS + (i * Rank + rand_offset))
x = sin(radians(i * Deg_Step)) * (OUTTER_RADIUS)
y = cos(radians(i * Deg_Step)) * (OUTTER_RADIUS)
Campbell Barton
committed
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
z = Height_Offset - (Height_Step * i)
Campbell Barton
committed
x = sin(radians(i * Deg_Step)) * INNER_RADIUS
y = cos(radians(i * Deg_Step)) * INNER_RADIUS
x = sin(radians(i * Deg_Step)) * (INNER_RADIUS + (i * Rank))
y = cos(radians(i * Deg_Step)) * (INNER_RADIUS + (i * Rank))
x = sin(radians(i * Deg_Step)) * (OUTTER_RADIUS)
y = cos(radians(i * Deg_Step)) * (OUTTER_RADIUS)
Campbell Barton
committed
Height_Offset -= Root_to_Crest_Height
Ret_Row += 1
return Ret_Row, Height_End # send back Height End as this is the lowest point
Campbell Barton
committed
def Create_Internal_Thread(INNER_DIA, OUTTER_DIA, PITCH, HEIGHT,
CREST_PERCENT, ROOT_PERCENT, INTERNAL, DIV_COUNT):
Campbell Barton
committed
INNER_RADIUS = INNER_DIA / 2
OUTTER_RADIUS = OUTTER_DIA / 2
Campbell Barton
committed
Deg_Step = 360.0 / float(DIV_COUNT)
Height_Step = float(PITCH) / float(DIV_COUNT)
Campbell Barton
committed
# less one pitch for the start and end that is 1/2 pitch high
Num = int(round((HEIGHT - PITCH) / PITCH))
Campbell Barton
committed
Campbell Barton
committed
Crest_Height = float(PITCH) * float(CREST_PERCENT) / float(100)
Root_Height = float(PITCH) * float(ROOT_PERCENT) / float(100)
Root_to_Crest_Height = Crest_to_Root_Height = \
(float(PITCH) - (Crest_Height + Root_Height)) / 2.0
Campbell Barton
committed
Campbell Barton
committed
Row_Inc, Height_Offset = Create_Internal_Thread_Start_Verts(
verts, INNER_RADIUS, OUTTER_RADIUS, PITCH,
DIV_COUNT, CREST_PERCENT, ROOT_PERCENT,
Height_Offset
)
Campbell Barton
committed
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
verts.append([x, y, Height_Offset - (Height_Step * i)])
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * OUTTER_RADIUS
y = cos(radians(i * Deg_Step)) * OUTTER_RADIUS
verts.append([x, y, Height_Offset - (Height_Step * i)])
Height_Offset -= Crest_to_Root_Height
Row += 1
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * INNER_RADIUS
y = cos(radians(i * Deg_Step)) * INNER_RADIUS
verts.append([x, y, Height_Offset - (Height_Step * i)])
Campbell Barton
committed
for i in range(DIV_COUNT + 1):
x = sin(radians(i * Deg_Step)) * INNER_RADIUS
y = cos(radians(i * Deg_Step)) * INNER_RADIUS
verts.append([x, y, Height_Offset - (Height_Step * i)])
Height_Offset -= Root_to_Crest_Height
Row += 1
Campbell Barton
committed
Row_Inc, Height_Offset = Create_Internal_Thread_End_Verts(
verts, INNER_RADIUS, OUTTER_RADIUS,
PITCH, CREST_PERCENT,
ROOT_PERCENT, Height_Offset, DIV_COUNT
Campbell Barton
committed
Row += Row_Inc
faces.extend(Build_Face_List_Quads(FaceStart, DIV_COUNT, Row - 1, FLIP=1))
Campbell Barton
committed
return verts, faces, 0 - Height_Offset