Newer
Older
def Nut_Mesh(props, context):
verts = []
faces = []
Head_Verts = []
Campbell Barton
committed
Thread_Verts, Thread_Faces, New_Nut_Height = Create_Internal_Thread(
props.bf_Minor_Dia, props.bf_Major_Dia,
props.bf_Pitch, props.bf_Hex_Nut_Height,
props.bf_Crest_Percent, props.bf_Root_Percent,
1, props.bf_Div_Count
)
faces.extend(Copy_Faces(Thread_Faces, Face_Start))
Campbell Barton
committed
Head_Verts, Head_Faces, Lock_Nut_Rad = add_Hex_Nut(
props.bf_Hex_Nut_Flat_Distance,
props.bf_Major_Dia, New_Nut_Height
)
faces.extend(Copy_Faces(Head_Faces, Face_Start))
Campbell Barton
committed
Campbell Barton
committed
if props.bf_Nut_Type == 'bf_Nut_Lock':
Face_Start = len(verts)
Nylon_Head_Verts, Nylon_Head_faces, LowZ = add_Nylon_Head(
Lock_Nut_Rad, 0 - New_Nut_Height,
props.bf_Div_Count
)
faces.extend(Copy_Faces(Nylon_Head_faces, Face_Start))
Campbell Barton
committed
Nylon_Verts, Nylon_faces, Temp_LowZ = add_Nylon_Part(
Lock_Nut_Rad, 0 - New_Nut_Height,
props.bf_Div_Count
)
faces.extend(Copy_Faces(Nylon_faces, Face_Start))
Campbell Barton
committed
return Move_Verts_Up_Z(verts, 0 - LowZ), faces
# ####################################################################
# Create Bolt
# ####################################################################
def Bolt_Mesh(props, context):
verts = []
faces = []
Bit_Verts = []
Bit_Faces = []
Bit_Dia = 0.001
Head_Verts = []
ReSized_Allen_Bit_Flat_Distance = props.bf_Allen_Bit_Flat_Distance # set default
Campbell Barton
committed
Head_Height = props.bf_Hex_Head_Height # will be changed by the Head Functions
Campbell Barton
committed
if props.bf_Bit_Type == 'bf_Bit_Allen' and props.bf_Head_Type == 'bf_Head_Pan':
# need to size Allen bit if it is too big.
if Allen_Bit_Dia(props.bf_Allen_Bit_Flat_Distance) > Max_Pan_Bit_Dia(props.bf_Pan_Head_Dia):
ReSized_Allen_Bit_Flat_Distance = Allen_Bit_Dia_To_Flat(
Max_Pan_Bit_Dia(props.bf_Pan_Head_Dia)
)
ReSized_Allen_Bit_Flat_Distance -= ReSized_Allen_Bit_Flat_Distance * 0.05 # It looks better if it is just a bit smaller
# print ("Resized Allen Bit Flat Distance to ",ReSized_Allen_Bit_Flat_Distance)
# Bit Mesh
Bit_Verts, Bit_Faces, Bit_Dia = Create_Allen_Bit(
ReSized_Allen_Bit_Flat_Distance,
props.bf_Allen_Bit_Depth
)
Campbell Barton
committed
Bit_Verts, Bit_Faces, Bit_Dia = Create_Phillips_Bit(
props.bf_Philips_Bit_Dia,
props.bf_Philips_Bit_Dia * (0.5 / 1.82),
props.bf_Phillips_Bit_Depth
)
# Head Mesh
if props.bf_Head_Type == 'bf_Head_Hex':
Head_Verts, Head_Faces, Head_Height = Create_Hex_Head(
props.bf_Hex_Head_Flat_Distance, Bit_Dia,
props.bf_Shank_Dia, props.bf_Hex_Head_Height
)
Campbell Barton
committed
elif props.bf_Head_Type == 'bf_Head_Cap':
Head_Verts, Head_Faces, Head_Height = Create_Cap_Head(
Bit_Dia, props.bf_Cap_Head_Dia,
props.bf_Shank_Dia, props.bf_Cap_Head_Height,
props.bf_Cap_Head_Dia * (1.0 / 19.0),
props.bf_Cap_Head_Dia * (1.0 / 19.0),
props.bf_Div_Count
)
elif props.bf_Head_Type == 'bf_Head_Dome':
Head_Verts, Head_Faces, Head_Height = Create_Dome_Head(
Bit_Dia, props.bf_Dome_Head_Dia,
props.bf_Shank_Dia, props.bf_Hex_Head_Height,
1, 1, 0, props.bf_Div_Count
)
Campbell Barton
committed
elif props.bf_Head_Type == 'bf_Head_Pan':
Head_Verts, Head_Faces, Head_Height = Create_Pan_Head(
Bit_Dia, props.bf_Pan_Head_Dia,
props.bf_Shank_Dia,
props.bf_Hex_Head_Height, 1, 1, 0,
props.bf_Div_Count
)
Campbell Barton
committed
elif props.bf_Head_Type == 'bf_Head_CounterSink':
Head_Verts, Head_Faces, Head_Height = Create_CounterSink_Head(
Bit_Dia, props.bf_CounterSink_Head_Dia,
props.bf_Shank_Dia, props.bf_CounterSink_Head_Dia,
props.bf_CounterSink_Head_Dia * (0.09 / 6.31),
props.bf_Div_Count
)
"""
Head_Verts, Head_Faces, Head_Height = Create_CounterSink_Head(
Bit_Dia, props.bf_CounterSink_Head_Dia,
props.bf_Shank_Dia,
props.bf_CounterSink_Head_Dia,
props.bf_CounterSink_Head_Dia * (1.0 / 19.0)
)
"""
verts.extend(Move_Verts_Up_Z(Bit_Verts, Head_Height))
faces.extend(Copy_Faces(Bit_Faces, Face_Start))
verts.extend(Move_Verts_Up_Z(Head_Verts, Head_Height))
faces.extend(Copy_Faces(Head_Faces, Face_Start))
Thread_Verts, Thread_Faces, Thread_Height = Create_External_Thread(
props.bf_Shank_Dia, props.bf_Shank_Length,
props.bf_Minor_Dia, props.bf_Major_Dia,
props.bf_Pitch, props.bf_Thread_Length,
props.bf_Crest_Percent,
props.bf_Root_Percent, props.bf_Div_Count
)
verts.extend(Move_Verts_Up_Z(Thread_Verts, 00))
faces.extend(Copy_Faces(Thread_Faces, Face_Start))
return Move_Verts_Up_Z(verts, Thread_Height), faces
Campbell Barton
committed
Campbell Barton
committed
verts, faces = Bolt_Mesh(props, context)
sObjName = 'Bolt'
Campbell Barton
committed
verts, faces = Nut_Mesh(props, context)
sObjName = 'Nut'
verts, faces = RemoveDoubles(verts, faces)
Campbell Barton
committed
verts = Scale_Mesh_Verts(verts, GLOBAL_SCALE)
Campbell Barton
committed
mesh = bpy.data.meshes.new(name=sObjName)
mesh.from_pydata(verts, edges, faces)
# useful for development when the mesh may be invalid.
# Fix T51338 : Validate the mesh (the internal thread generator for the Nut
# should be more reliable now, however there could be other possible errors)
is_not_mesh_valid = mesh.validate()
if is_not_mesh_valid:
props.report({'INFO'}, "Mesh is not Valid, correcting")
return mesh