Fix for #6: Incorrect bolt lengths #13

Open
sw-tya wants to merge 2 commits from sw-tya/add_mesh_BoltFactory:swtya_BoltLength into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Showing only changes of commit 4718b93051 - Show all commits

View File

@ -705,6 +705,7 @@ def Create_Pan_Head(HOLE_DIA, HEAD_DIA, SHANK_DIA, HEIGHT, RAD1, RAD2, FACE_OFFS
verts.append([SHANK_RADIUS, 0.0, (0.0 - HEIGHT)])
Row += 1
washer_face_z = Start_Height - HEIGHT
verts.append([SHANK_RADIUS, 0.0, (0.0 - HEIGHT) - Start_Height])
Row += 1
@ -716,7 +717,7 @@ def Create_Pan_Head(HOLE_DIA, HEAD_DIA, SHANK_DIA, HEIGHT, RAD1, RAD2, FACE_OFFS
# Global_Head_Height = HEIGHT # UNUSED
return Move_Verts_Up_Z(sVerts, Start_Height), faces, HEIGHT
return Move_Verts_Up_Z(sVerts, Start_Height), faces, HEIGHT, washer_face_z
def Create_Dome_Head(HOLE_DIA, HEAD_DIA, SHANK_DIA, HEIGHT, RAD1, RAD2, FACE_OFFSET, DIV_COUNT):
@ -843,6 +844,8 @@ def Create_Cap_Head(HOLE_DIA, HEAD_DIA, SHANK_DIA, HEIGHT, RAD1, RAD2, DIV_COUNT
verts.append([HEAD_RADIUS - BEVEL, 0.0, 0.0 - HEIGHT])
Row += 1
washer_face_z = -HEIGHT
# rad2
for i in range(0, 100, 10):
x = sin(radians(i)) * RAD2
@ -855,7 +858,7 @@ def Create_Cap_Head(HOLE_DIA, HEAD_DIA, SHANK_DIA, HEIGHT, RAD1, RAD2, DIV_COUNT
faces.extend(Build_Face_List_Quads(FaceStart, Row - 1, DIV_COUNT))
return sVerts, faces, HEIGHT + RAD2
return sVerts, faces, HEIGHT + RAD2, washer_face_z
def Create_Hex_Head(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT):
@ -868,6 +871,7 @@ def Create_Hex_Head(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT):
Undercut_Height = (Half_Flat * (0.05 / 8))
Shank_Bevel = (Half_Flat * (0.05 / 8))
Flat_Height = HEIGHT - Undercut_Height - Shank_Bevel
washer_face_z = -HEIGHT + Undercut_Height
# Undercut_Height = 5
SHANK_RADIUS = SHANK_DIA / 2
Row = 0
@ -927,7 +931,6 @@ def Create_Hex_Head(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT):
x = tan(radians(60 / 3)) * Half_Flat
dvec = vec3 - Vector([x, Half_Flat, 0.0])
Lowest_Point = -dvec.length
verts.append([x, Half_Flat, -dvec.length])
x = tan(radians(60 / 2)) * Half_Flat
@ -1061,7 +1064,7 @@ def Create_Hex_Head(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT):
Spin_Verts, Spin_Faces = SpinDup(verts, faces, 360, 6, 'z')
return Spin_Verts, Spin_Faces, 0 - (-HEIGHT)
return Spin_Verts, Spin_Faces, 0 - (-HEIGHT), washer_face_z
def Create_12_Point(FLAT, HOLE_DIA, SHANK_DIA, HEIGHT, FLANGE_DIA):
@ -2385,13 +2388,16 @@ def Bolt_Mesh(props, context):
props.bf_Philips_Bit_Dia / GLOBAL_SCALE * (0.5 / 1.82),
props.bf_Phillips_Bit_Depth / GLOBAL_SCALE
)
# Head Mesh
# Define the washer face of the bolt, i.e. the underside. Some bolts have a bevel or radius to the shank included
# Their head height causes an incorrect shank/thread length determination.
washer_face_z = 0 # z-axis height, some Heads return a variable that overwrites this
if props.bf_Head_Type == 'bf_Head_Hex':
Head_Verts, Head_Faces, Head_Height = Create_Hex_Head(
Head_Verts, Head_Faces, Head_Height, washer_face_z = Create_Hex_Head(
props.bf_Hex_Head_Flat_Distance / GLOBAL_SCALE, Bit_Dia,
props.bf_Shank_Dia / GLOBAL_SCALE, props.bf_Hex_Head_Height / GLOBAL_SCALE
)
elif props.bf_Head_Type == 'bf_Head_12Pnt':
Head_Verts, Head_Faces, Head_Height = Create_12_Point_Head(
props.bf_12_Point_Head_Flat_Distance / GLOBAL_SCALE, Bit_Dia,
@ -2400,7 +2406,7 @@ def Bolt_Mesh(props, context):
max(props.bf_12_Point_Head_Flange_Dia / GLOBAL_SCALE, props.bf_12_Point_Head_Flat_Distance / GLOBAL_SCALE)
)
elif props.bf_Head_Type == 'bf_Head_Cap':
Head_Verts, Head_Faces, Head_Height = Create_Cap_Head(
Head_Verts, Head_Faces, Head_Height, washer_face_z = Create_Cap_Head(
Bit_Dia, props.bf_Cap_Head_Dia / GLOBAL_SCALE,
props.bf_Shank_Dia / GLOBAL_SCALE, props.bf_Cap_Head_Height / GLOBAL_SCALE,
props.bf_Cap_Head_Dia / GLOBAL_SCALE * (1.0 / 19.0),
@ -2413,9 +2419,8 @@ def Bolt_Mesh(props, context):
props.bf_Shank_Dia / GLOBAL_SCALE, props.bf_Hex_Head_Height / GLOBAL_SCALE,
1, 1, 0, props.bf_Div_Count
)
elif props.bf_Head_Type == 'bf_Head_Pan':
Head_Verts, Head_Faces, Head_Height = Create_Pan_Head(
Head_Verts, Head_Faces, Head_Height, washer_face_z = Create_Pan_Head(
Bit_Dia, props.bf_Pan_Head_Dia / GLOBAL_SCALE,
props.bf_Shank_Dia / GLOBAL_SCALE,
props.bf_Hex_Head_Height / GLOBAL_SCALE, 1, 1, 0,
@ -2437,11 +2442,24 @@ def Bolt_Mesh(props, context):
verts.extend(Move_Verts_Up_Z(Head_Verts, Head_Height))
faces.extend(Copy_Faces(Head_Faces, Face_Start))
make_shank = (props.bf_Shank_Length / GLOBAL_SCALE)
make_thread = (props.bf_Thread_Length / GLOBAL_SCALE)
if washer_face_z != 0:
# At this point the mesh is back at z=zero. The washer face may be randomly above this depending on
# the head choice. Optional returned variable is used to shorten up the shank/thread.
# If the Head function modified the washer_face-z we are here to make a length correction.
washer_face = washer_face_z + Head_Height
make_shank = (props.bf_Shank_Length / GLOBAL_SCALE) - washer_face
if make_shank < 0:
# If all the shank length is used up then take it off the thread length
make_thread = (props.bf_Thread_Length / GLOBAL_SCALE) + make_shank
make_shank = 0
Face_Start = len(verts)
Thread_Verts, Thread_Faces, Thread_Height = Create_External_Thread(
props.bf_Shank_Dia / GLOBAL_SCALE, props.bf_Shank_Length / GLOBAL_SCALE,
props.bf_Shank_Dia / GLOBAL_SCALE, make_shank,
props.bf_Minor_Dia / GLOBAL_SCALE, props.bf_Major_Dia / GLOBAL_SCALE,
props.bf_Pitch / GLOBAL_SCALE, props.bf_Thread_Length / GLOBAL_SCALE,
props.bf_Pitch / GLOBAL_SCALE, make_thread,
props.bf_Crest_Percent,
props.bf_Root_Percent, props.bf_Div_Count
)