Fix #5: Scale factor issue #7

Merged
Nika Kutsniashvili merged 2 commits from linux_dr/add_mesh_BoltFactory:losborn_issue83322_fix into main 2024-07-17 13:24:00 +02:00
3 changed files with 99 additions and 95 deletions
Showing only changes of commit fd94ab3159 - Show all commits

View File

@ -26,7 +26,7 @@ class add_mesh_bolt(Operator, AddObjectHelper):
bl_options = {'REGISTER', 'UNDO', 'PRESET'}
bl_description = "Construct many types of Bolts"
MAX_INPUT_NUMBER = 50
MAX_INPUT_NUMBER = 50 # mm
Bolt: BoolProperty(name="Bolt",
default=True,
@ -82,39 +82,39 @@ class add_mesh_bolt(Operator, AddObjectHelper):
bf_Shank_Length: FloatProperty(
attr='bf_Shank_Length',
name='Shank Length', default=0,
min=0, soft_min=0, max=MAX_INPUT_NUMBER,
min=0, soft_min=0, max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Length of the unthreaded shank',
unit='LENGTH',
)
bf_Shank_Dia: FloatProperty(
attr='bf_Shank_Dia',
name='Shank Dia', default=3,
name='Shank Dia', default=3 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Diameter of the shank',
unit='LENGTH',
)
bf_Phillips_Bit_Depth: FloatProperty(
attr='bf_Phillips_Bit_Depth',
name='Bit Depth', default=1.1431535482406616,
name='Bit Depth', default=1.1431535482406616 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Depth of the Phillips Bit',
unit='LENGTH',
)
bf_Allen_Bit_Depth: FloatProperty(
attr='bf_Allen_Bit_Depth',
name='Bit Depth', default=1.5,
name='Bit Depth', default=1.5 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Depth of the Allen Bit',
unit='LENGTH',
)
bf_Allen_Bit_Flat_Distance: FloatProperty(
attr='bf_Allen_Bit_Flat_Distance',
name='Flat Dist', default=2.5,
name='Flat Dist', default=2.5 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Flat Distance of the Allen Bit',
unit='LENGTH',
)
@ -136,131 +136,131 @@ class add_mesh_bolt(Operator, AddObjectHelper):
)
bf_Torx_Bit_Depth: FloatProperty(
attr='bf_Torx_Bit_Depth',
name='Bit Depth', default=1.5,
name='Bit Depth', default=1.5 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Depth of the Torx Bit',
unit='LENGTH',
)
bf_Hex_Head_Height: FloatProperty(
attr='bf_Hex_Head_Height',
name='Head Height', default=2,
min=0, soft_min=0, max=MAX_INPUT_NUMBER,
name='Head Height', default=2 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0, max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Height of the Hex Head',
unit='LENGTH',
)
bf_Hex_Head_Flat_Distance: FloatProperty(
attr='bf_Hex_Head_Flat_Distance',
name='Flat Dist', default=5.5,
name='Flat Dist', default=5.5 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Flat Distance of the Hex Head',
unit='LENGTH',
)
bf_12_Point_Head_Height: FloatProperty(
attr='bf_12_Point_Head_Height',
name='Head Height', default=3.0,
min=0, soft_min=0, max=MAX_INPUT_NUMBER,
name='Head Height', default=3.0 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0, max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Height of the 12 Point Head',
unit='LENGTH',
)
bf_12_Point_Head_Flat_Distance: FloatProperty(
attr='bf_12_Point_Head_Flat_Distance',
name='Flat Dist', default=3.0,
min=0.001, soft_min=0, # limit to 0.001 to avoid calculation error
max=MAX_INPUT_NUMBER,
name='Flat Dist', default=3.0 * createMesh.GLOBAL_SCALE,
min=0.001 * createMesh.GLOBAL_SCALE, soft_min=0, # limit to 0.001*createMesh.GLOBAL_SCALE to avoid calculation error
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Flat Distance of the 12 Point Head',
unit='LENGTH',
)
bf_12_Point_Head_Flange_Dia: FloatProperty(
attr='bf_12_Point_Head_Flange_Dia',
name='12 Point Head Flange Dia', default=5.5,
name='12 Point Head Flange Dia', default=5.5 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Flange diameter of the 12 point Head',
unit='LENGTH',
)
bf_CounterSink_Head_Dia: FloatProperty(
attr='bf_CounterSink_Head_Dia',
name='Head Dia', default=6.300000190734863,
name='Head Dia', default=6.300000190734863 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Diameter of the Counter Sink Head',
unit='LENGTH',
)
bf_Cap_Head_Height: FloatProperty(
attr='bf_Cap_Head_Height',
name='Head Height', default=3,
name='Head Height', default=3 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Height of the Cap Head',
unit='LENGTH',
)
bf_Cap_Head_Dia: FloatProperty(
attr='bf_Cap_Head_Dia',
name='Head Dia', default=5.5,
name='Head Dia', default=5.5 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Diameter of the Cap Head',
unit='LENGTH',
)
bf_Dome_Head_Dia: FloatProperty(
attr='bf_Dome_Head_Dia',
name='Dome Head Dia', default=5.599999904632568,
name='Dome Head Dia', default=5.599999904632568 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Length of the unthreaded shank',
unit='LENGTH',
)
bf_Pan_Head_Dia: FloatProperty(
attr='bf_Pan_Head_Dia',
name='Pan Head Dia', default=5.599999904632568,
name='Pan Head Dia', default=5.599999904632568 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Diameter of the Pan Head',
unit='LENGTH',
)
bf_Philips_Bit_Dia: FloatProperty(
attr='bf_Philips_Bit_Dia',
name='Bit Dia', default=1.8199999332427979,
name='Bit Dia', default=1.8199999332427979 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Diameter of the Philips Bit',
unit='LENGTH',
)
bf_Thread_Length: FloatProperty(
attr='bf_Thread_Length',
name='Thread Length', default=6,
name='Thread Length', default=6 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Length of the Thread',
unit='LENGTH',
)
bf_Major_Dia: FloatProperty(
attr='bf_Major_Dia',
name='Major Dia', default=3,
name='Major Dia', default=3 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Outside diameter of the Thread',
unit='LENGTH',
)
bf_Pitch: FloatProperty(
attr='bf_Pitch',
name='Pitch', default=0.3499999940395355,
min=0.1, soft_min=0.1,
max=7.0,
name='Pitch', default=0.3499999940395355 * createMesh.GLOBAL_SCALE,
min=0.1 * createMesh.GLOBAL_SCALE, soft_min=0.1 * createMesh.GLOBAL_SCALE,
max=7.0 * createMesh.GLOBAL_SCALE,
description='Pitch if the thread',
unit='LENGTH',
)
bf_Minor_Dia: FloatProperty(
attr='bf_Minor_Dia',
name='Minor Dia', default=2.6211137771606445,
name='Minor Dia', default=2.6211137771606445 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Inside diameter of the Thread',
unit='LENGTH',
)
@ -287,42 +287,42 @@ class add_mesh_bolt(Operator, AddObjectHelper):
)
bf_Hex_Nut_Height: FloatProperty(
attr='bf_Hex_Nut_Height',
name='Hex Nut Height', default=2.4000000953674316,
name='Hex Nut Height', default=2.4000000953674316 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Height of the Hex Nut',
unit='LENGTH',
)
bf_Hex_Nut_Flat_Distance: FloatProperty(
attr='bf_Hex_Nut_Flat_Distance',
name='Hex Nut Flat Dist', default=5.5,
name='Hex Nut Flat Dist', default=5.5 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Flat distance of the Hex Nut',
unit='LENGTH',
)
bf_12_Point_Nut_Height: FloatProperty(
attr='bf_12_Point_Nut_Height',
name='12 Point Nut Height', default=2.4000000953674316,
name='12 Point Nut Height', default=2.4000000953674316 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Height of the 12 Point Nut',
unit='LENGTH',
)
bf_12_Point_Nut_Flat_Distance: FloatProperty(
attr='bf_12_Point_Nut_Flat_Distance',
name='12 Point Nut Flat Dist', default=3.0,
min=0.001, soft_min=0, # limit to 0.001 to avoid calculation error
max=MAX_INPUT_NUMBER,
name='12 Point Nut Flat Dist', default=3.0 * createMesh.GLOBAL_SCALE,
min=0.001 * createMesh.GLOBAL_SCALE, soft_min=0, # limit to 0.001 to avoid calculation error
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Flat distance of the 12 point Nut',
unit='LENGTH',
)
bf_12_Point_Nut_Flange_Dia: FloatProperty(
attr='bf_12_Point_Nut_Flange_Dia',
name='12 Point Nut Flange Dia', default=5.5,
name='12 Point Nut Flange Dia', default=5.5 * createMesh.GLOBAL_SCALE,
min=0, soft_min=0,
max=MAX_INPUT_NUMBER,
max=MAX_INPUT_NUMBER * createMesh.GLOBAL_SCALE,
description='Flange diameter of the 12 point Nut',
unit='LENGTH',
)

View File

@ -1,7 +1,7 @@
schema_version = "1.0.0"
id = "boltfactory"
name = "BoltFactory"
version = "0.4.0"
version = "0.4.1"
tagline = "Add a bolt or nut"
maintainer = "Community"
type = "add-on"

View File

@ -18,7 +18,7 @@ from bpy_extras.object_utils import AddObjectHelper, object_data_add
NARROW_UI = 180
MAX_INPUT_NUMBER = 50
GLOBAL_SCALE = 1 # 1 blender unit = X mm
GLOBAL_SCALE = 0.001 # GLOBAL_SCALE blender unit = 1 mm
# next two utility functions are stolen from import_obj.py
@ -2276,13 +2276,13 @@ def Nut_Mesh(props, context):
Face_Start = len(verts)
if props.bf_Nut_Type == 'bf_Nut_12Pnt':
Nut_Height = props.bf_12_Point_Nut_Height
Nut_Height = props.bf_12_Point_Nut_Height / GLOBAL_SCALE
else:
Nut_Height = props.bf_Hex_Nut_Height
Nut_Height = props.bf_Hex_Nut_Height / GLOBAL_SCALE
Thread_Verts, Thread_Faces, New_Nut_Height = Create_Internal_Thread(
props.bf_Minor_Dia, props.bf_Major_Dia,
props.bf_Pitch, Nut_Height,
props.bf_Minor_Dia / GLOBAL_SCALE, props.bf_Major_Dia / GLOBAL_SCALE,
props.bf_Pitch / GLOBAL_SCALE, Nut_Height,
props.bf_Crest_Percent, props.bf_Root_Percent,
1, props.bf_Div_Count
)
@ -2293,15 +2293,15 @@ def Nut_Mesh(props, context):
if props.bf_Nut_Type == 'bf_Nut_12Pnt':
Head_Verts, Head_Faces, Lock_Nut_Rad = add_12_Point_Nut(
props.bf_12_Point_Nut_Flat_Distance,
props.bf_Major_Dia, New_Nut_Height,
props.bf_12_Point_Nut_Flat_Distance / GLOBAL_SCALE,
props.bf_Major_Dia / GLOBAL_SCALE, New_Nut_Height,
# Limit the size of the Flange to avoid calculation error
max(props.bf_12_Point_Nut_Flange_Dia, props.bf_12_Point_Nut_Flat_Distance)
max(props.bf_12_Point_Nut_Flange_Dia / GLOBAL_SCALE, props.bf_12_Point_Nut_Flat_Distance / GLOBAL_SCALE)
)
else:
Head_Verts, Head_Faces, Lock_Nut_Rad = add_Hex_Nut(
props.bf_Hex_Nut_Flat_Distance,
props.bf_Major_Dia, New_Nut_Height
props.bf_Hex_Nut_Flat_Distance / GLOBAL_SCALE,
props.bf_Major_Dia / GLOBAL_SCALE, New_Nut_Height
)
verts.extend((Head_Verts))
faces.extend(Copy_Faces(Head_Faces, Face_Start))
@ -2343,15 +2343,19 @@ def Bolt_Mesh(props, context):
Head_Faces = []
Head_Height = 0.0
ReSized_Allen_Bit_Flat_Distance = props.bf_Allen_Bit_Flat_Distance # set default
ReSized_Allen_Bit_Flat_Distance = props.bf_Allen_Bit_Flat_Distance / GLOBAL_SCALE # set default
Head_Height = props.bf_Hex_Head_Height # will be changed by the Head Functions
Head_Height = props.bf_Hex_Head_Height / GLOBAL_SCALE # will be changed by the Head Functions
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):
if Allen_Bit_Dia(
props.bf_Allen_Bit_Flat_Distance /
GLOBAL_SCALE) > Max_Pan_Bit_Dia(
props.bf_Pan_Head_Dia /
GLOBAL_SCALE):
ReSized_Allen_Bit_Flat_Distance = Allen_Bit_Dia_To_Flat(
Max_Pan_Bit_Dia(props.bf_Pan_Head_Dia)
Max_Pan_Bit_Dia(props.bf_Pan_Head_Dia / GLOBAL_SCALE)
)
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)
@ -2360,62 +2364,62 @@ def Bolt_Mesh(props, context):
if props.bf_Bit_Type == 'bf_Bit_Allen':
Bit_Verts, Bit_Faces, Bit_Dia = Create_Allen_Bit(
ReSized_Allen_Bit_Flat_Distance,
props.bf_Allen_Bit_Depth
props.bf_Allen_Bit_Depth / GLOBAL_SCALE
)
if props.bf_Bit_Type == 'bf_Bit_Torx':
Bit_Verts, Bit_Faces, Bit_Dia = Create_Torx_Bit(
Torx_Bit_Size_To_Point_Distance(props.bf_Torx_Size_Type),
props.bf_Torx_Bit_Depth
props.bf_Torx_Bit_Depth / GLOBAL_SCALE
)
if props.bf_Bit_Type == 'bf_Bit_Philips':
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
props.bf_Philips_Bit_Dia / GLOBAL_SCALE,
props.bf_Philips_Bit_Dia / GLOBAL_SCALE * (0.5 / 1.82),
props.bf_Phillips_Bit_Depth / GLOBAL_SCALE
)
# 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
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, Bit_Dia,
props.bf_Shank_Dia, props.bf_12_Point_Head_Height,
props.bf_12_Point_Head_Flat_Distance / GLOBAL_SCALE, Bit_Dia,
props.bf_Shank_Dia / GLOBAL_SCALE, props.bf_12_Point_Head_Height / GLOBAL_SCALE,
# Limit the size of the Flange to avoid calculation error
max(props.bf_12_Point_Head_Flange_Dia, props.bf_12_Point_Head_Flat_Distance)
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(
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),
Bit_Dia, props.bf_Cap_Head_Dia / GLOBAL_SCALE,
props.bf_Shank_Dia, props.bf_Cap_Head_Height / GLOBAL_SCALE,
props.bf_Cap_Head_Dia / GLOBAL_SCALE * (1.0 / 19.0),
props.bf_Cap_Head_Dia / GLOBAL_SCALE * (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,
Bit_Dia, props.bf_Dome_Head_Dia / GLOBAL_SCALE,
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(
Bit_Dia, props.bf_Pan_Head_Dia,
props.bf_Shank_Dia,
props.bf_Hex_Head_Height, 1, 1, 0,
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,
props.bf_Div_Count
)
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),
Bit_Dia, props.bf_CounterSink_Head_Dia / GLOBAL_SCALE,
props.bf_Shank_Dia, props.bf_CounterSink_Head_Dia / GLOBAL_SCALE,
props.bf_CounterSink_Head_Dia / GLOBAL_SCALE * (0.09 / 6.31),
props.bf_Div_Count
)
@ -2429,9 +2433,9 @@ def Bolt_Mesh(props, context):
Face_Start = len(verts)
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_Shank_Dia / GLOBAL_SCALE, props.bf_Shank_Length / GLOBAL_SCALE,
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_Crest_Percent,
props.bf_Root_Percent, props.bf_Div_Count
)