Skip to content
Snippets Groups Projects
createMesh.py 63.4 KiB
Newer Older
  • Learn to ignore specific revisions
  • Brendon Murphy's avatar
    Brendon Murphy committed
                x = sin(radians(i*Deg_Step))*INNER_RADIUS
                y = cos(radians(i*Deg_Step))*INNER_RADIUS
                if j == 0:
                    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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                if z > Height_Start:
                    z = Height_Start
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                x = sin(radians(i*Deg_Step))*INNER_RADIUS
                y = cos(radians(i*Deg_Step))*INNER_RADIUS
    
                if j == 0:
                    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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        return Ret_Row,Height_Offset
    
    
    def Create_Shank_Verts(START_DIA,OUTTER_DIA,LENGTH,Z_LOCATION = 0):
    
        verts = []
        DIV = 36
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        START_RADIUS = START_DIA/2
        OUTTER_RADIUS = OUTTER_DIA/2
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Opp = abs(START_RADIUS - OUTTER_RADIUS)
        Taper_Lentgh = Opp/tan(radians(31));
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        if Taper_Lentgh > LENGTH:
            Taper_Lentgh = 0
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Stright_Length = LENGTH - Taper_Lentgh
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Deg_Step = 360.0 /float(DIV)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Row = 0
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Height_Offset = Z_LOCATION
    
    
            #ring
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            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
    
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            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 -= Taper_Lentgh
        Row += 1
    
    
        return verts,Row,Height_Offset
    
    
    def Create_Thread_Start_Verts(INNER_DIA,OUTTER_DIA,PITCH,CREST_PERCENT,ROOT_PERCENT,Z_LOCATION = 0):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        verts = []
        DIV = 36
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        INNER_RADIUS = INNER_DIA/2
        OUTTER_RADIUS = OUTTER_DIA/2
    
    Campbell Barton's avatar
    Campbell Barton committed
        # Half_Pitch = float(PITCH)/2  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Deg_Step = 360.0 /float(DIV)
        Height_Step = float(PITCH)/float(DIV)
    
        Row = 0
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Height_Offset = Z_LOCATION
    
    Brendon Murphy's avatar
    Brendon Murphy 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)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Cut_off = Z_LOCATION
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        for j in range(1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+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_Height
            Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
                x = sin(radians(i*Deg_Step))*OUTTER_RADIUS
                y = cos(radians(i*Deg_Step))*OUTTER_RADIUS
                z = Height_Offset - (Height_Step*i)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                verts.append([x,y,z])
                Lowest_Z_Vert = min(Lowest_Z_Vert,z)
            Height_Offset -= Root_Height
            Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
                x = sin(radians(i*Deg_Step))*OUTTER_RADIUS
                y = cos(radians(i*Deg_Step))*OUTTER_RADIUS
                z = Height_Offset - (Height_Step*i)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                verts.append([x,y,z])
                Lowest_Z_Vert = min(Lowest_Z_Vert,z)
            Height_Offset -= Root_to_Crest_Height
            Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        for j in range(2):
            for i in range(DIV+1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                if z > Height_Start:
                    z = Height_Start
                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_Height
            Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                if z > Height_Start:
                    z = Height_Start
    
    Brendon Murphy's avatar
    Brendon Murphy 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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                if z > Height_Start:
                    z = Height_Start
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                x = sin(radians(i*Deg_Step))*INNER_RADIUS
                y = cos(radians(i*Deg_Step))*INNER_RADIUS
                if j == 0:
                    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_Height
            Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                if z > Height_Start:
                    z = Height_Start
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                x = sin(radians(i*Deg_Step))*INNER_RADIUS
                y = cos(radians(i*Deg_Step))*INNER_RADIUS
    
                if j == 0:
                    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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        return verts,Row,Height_Offset
    
    
    
    def Create_Thread_Verts(INNER_DIA,OUTTER_DIA,PITCH,HEIGHT,CREST_PERCENT,ROOT_PERCENT,Z_LOCATION = 0):
        verts = []
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        DIV = 36
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        INNER_RADIUS = INNER_DIA/2
        OUTTER_RADIUS = OUTTER_DIA/2
    
    Campbell Barton's avatar
    Campbell Barton committed
        # Half_Pitch = float(PITCH)/2  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Deg_Step = 360.0 /float(DIV)
        Height_Step = float(PITCH)/float(DIV)
    
        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)
        Row = 0
    
    Brendon Murphy's avatar
    Brendon Murphy 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
    
    
        Height_Offset = Z_LOCATION
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Lowest_Z_Vert = 0;
    
    Campbell Barton's avatar
    Campbell Barton committed
    
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        for j in range(Num):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
                x = sin(radians(i*Deg_Step))*OUTTER_RADIUS
                y = cos(radians(i*Deg_Step))*OUTTER_RADIUS
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                verts.append([x,y,z])
                Lowest_Z_Vert = min(Lowest_Z_Vert,z)
            Height_Offset -= Crest_Height
            Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
                x = sin(radians(i*Deg_Step))*INNER_RADIUS
                y = cos(radians(i*Deg_Step))*INNER_RADIUS
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                verts.append([x,y,z])
                Lowest_Z_Vert = min(Lowest_Z_Vert,z)
            Height_Offset -= Root_Height
            Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
                x = sin(radians(i*Deg_Step))*INNER_RADIUS
                y = cos(radians(i*Deg_Step))*INNER_RADIUS
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                verts.append([x,y,z])
                Lowest_Z_Vert = min(Lowest_Z_Vert,z)
            Height_Offset -= Root_to_Crest_Height
            Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        return verts,Row,Height_Offset
    
    
    
    def Create_Thread_End_Verts(INNER_DIA,OUTTER_DIA,PITCH,CREST_PERCENT,ROOT_PERCENT,Z_LOCATION = 0):
        verts = []
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        DIV = 36
    
        INNER_RADIUS = INNER_DIA/2
        OUTTER_RADIUS = OUTTER_DIA/2
    
    Campbell Barton's avatar
    Campbell Barton committed
        # Half_Pitch = float(PITCH)/2  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Deg_Step = 360.0 /float(DIV)
        Height_Step = float(PITCH)/float(DIV)
    
        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's avatar
    Campbell Barton committed
        # Col = 0  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Row = 0
    
    
        Height_Offset = Z_LOCATION
    
        Tapper_Height_Start = Height_Offset - PITCH - PITCH
    
        Max_Height = Tapper_Height_Start - PITCH
    
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Lowest_Z_Vert = 0;
    
    Campbell Barton's avatar
    Campbell Barton committed
        # FaceStart = len(verts)  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        for j in range(4):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+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_Height
            Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+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:
    
    Brendon Murphy's avatar
    Brendon Murphy 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_Height
            Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+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:
    
    Brendon Murphy's avatar
    Brendon Murphy 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
    
    Brendon Murphy's avatar
    Brendon Murphy 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):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        verts = []
        faces = []
    
        DIV = 36
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Total_Row = 0
    
    Campbell Barton's avatar
    Campbell Barton committed
        # Thread_Len = 0  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Face_Start = len(verts)
        Offset = 0.0;
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Shank_Verts,Shank_Row,Offset = Create_Shank_Verts(SHANK_DIA,OUTTER_DIA,SHANK_LENGTH,Offset)
        Total_Row += Shank_Row
    
        Thread_Start_Verts,Thread_Start_Row,Offset = Create_Thread_Start_Verts(INNER_DIA,OUTTER_DIA,PITCH,CREST_PERCENT,ROOT_PERCENT,Offset)
        Total_Row += Thread_Start_Row
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Thread_Verts,Thread_Row,Offset = Create_Thread_Verts(INNER_DIA,OUTTER_DIA,PITCH,LENGTH,CREST_PERCENT,ROOT_PERCENT,Offset)
        Total_Row += Thread_Row
    
    Brendon Murphy's avatar
    Brendon Murphy 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 )
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        verts.extend(Shank_Verts)
        verts.extend(Thread_Start_Verts)
        verts.extend(Thread_Verts)
        verts.extend(Thread_End_Verts)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        faces.extend(Build_Face_List_Quads(Face_Start,DIV,Total_Row -1,0))
        faces.extend(Fill_Ring_Face(len(verts)-DIV,DIV,1))
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        return verts,faces,0.0 - Lowest_Z_Vert
    
    Brendon Murphy's avatar
    Brendon Murphy committed
    
    ##########################################################################################
    ##########################################################################################
    ##                    Create Nut
    ##########################################################################################
    ##########################################################################################
    
    def add_Hex_Nut(FLAT,HOLE_DIA,HEIGHT):
        global Global_Head_Height
        global Global_NutRad
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        verts = []
        faces = []
        HOLE_RADIUS = HOLE_DIA * 0.5
        Half_Flat = FLAT/2
        Half_Height = HEIGHT/2
        TopBevelRadius = Half_Flat - 0.05
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Global_NutRad =  TopBevelRadius
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Row = 0;
        Lowest_Z_Vert = 0.0;
    
        verts.append([0.0,0.0,0.0])
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        FaceStart = len(verts)
        #inner hole
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        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])
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        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])
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        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])
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        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])
        Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        #bevel
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = sin(radians(0))*TopBevelRadius
        y = cos(radians(0))*TopBevelRadius
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        verts.append([x,y,0.0])
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = sin(radians(60/6))*TopBevelRadius
        y = cos(radians(60/6))*TopBevelRadius
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        verts.append([x,y,0.0])
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = sin(radians(60/3))*TopBevelRadius
        y = cos(radians(60/3))*TopBevelRadius
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        verts.append([x,y,0.0])
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = sin(radians(60/2))*TopBevelRadius
        y = cos(radians(60/2))*TopBevelRadius
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        verts.append([x,y,0.0])
        Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        #Flats
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = tan(radians(0))*Half_Flat
    
        dvec = vec1 - mathutils.Vector([x,Half_Flat,0.0])
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        verts.append([x,Half_Flat,-dvec.length])
        Lowest_Z_Vert = min(Lowest_Z_Vert,-dvec.length)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = tan(radians(60/6))*Half_Flat
    
        dvec = vec2 - mathutils.Vector([x,Half_Flat,0.0])
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        verts.append([x,Half_Flat,-dvec.length])
        Lowest_Z_Vert = min(Lowest_Z_Vert,-dvec.length)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
    
        x = tan(radians(60/3))*Half_Flat
    
        dvec = vec3 - mathutils.Vector([x,Half_Flat,0.0])
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Lowest_Point = -dvec.length
        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 - mathutils.Vector([x,Half_Flat,0.0])
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Lowest_Point = -dvec.length
        verts.append([x,Half_Flat,-dvec.length])
        Lowest_Z_Vert = min(Lowest_Z_Vert,-dvec.length)
        Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        #down Bits Tri
        x = tan(radians(0))*Half_Flat
        verts.append([x,Half_Flat,Lowest_Point])
    
    Brendon Murphy's avatar
    Brendon Murphy 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])
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = tan(radians(60/2))*Half_Flat
        verts.append([x,Half_Flat,Lowest_Point])
        Lowest_Z_Vert = min(Lowest_Z_Vert,Lowest_Point)
        Row += 1
    
        #down Bits
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = tan(radians(0))*Half_Flat
        verts.append([x,Half_Flat,-Half_Height])
    
    Brendon Murphy's avatar
    Brendon Murphy 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])
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = tan(radians(60/2))*Half_Flat
        verts.append([x,Half_Flat,-Half_Height])
        Lowest_Z_Vert = min(Lowest_Z_Vert,-Half_Height)
        Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        faces.extend(Build_Face_List_Quads(FaceStart,3,Row - 1))
    
        Global_Head_Height = HEIGHT
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Tvert,tface = Mirror_Verts_Faces(verts,faces,'z',Lowest_Z_Vert)
        verts.extend(Tvert)
        faces.extend(tface)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Tvert,tface = Mirror_Verts_Faces(verts,faces,'y')
        verts.extend(Tvert)
        faces.extend(tface)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        S_verts,S_faces = SpinDup(verts,faces,360,6,'z')
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        #return verts,faces,TopBevelRadius
        return S_verts,S_faces,TopBevelRadius
    
    
    
    def add_Nylon_Head(OUTSIDE_RADIUS,Z_LOCATION = 0):
        DIV = 36
        verts = []
        faces = []
        Row = 0
    
        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_HEIGTH = (OUTSIDE_RADIUS * (2.0/4.75))
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        FaceStart = len(verts)
    
    
    Campbell Barton's avatar
    Campbell Barton committed
        # Start_Height = 0 - 3  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Height_Offset = Z_LOCATION
        Lowest_Z_Vert = 0
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = INNER_HOLE
        z = (Height_Offset - OVER_ALL_HEIGTH) + EDGE_THICKNESS
        verts.append([x,0.0,z])
        Lowest_Z_Vert = min(Lowest_Z_Vert,z)
        Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = INNER_HOLE
        z = (Height_Offset - OVER_ALL_HEIGTH)
        verts.append([x,0.0,z])
        Lowest_Z_Vert = min(Lowest_Z_Vert,z)
        Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy 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_HEIGTH)+RAD1)+z])
            Lowest_Z_Vert = min(Lowest_Z_Vert,z)
            Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = OUTSIDE_RADIUS - 0
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        verts.append([x,0.0,z])
        Lowest_Z_Vert = min(Lowest_Z_Vert,z)
        Row += 1
    
        sVerts,sFaces = SpinDup(verts,faces,360,DIV,'z')
        sVerts.extend(verts)        #add the start verts to the Spin verts to complete the loop
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        faces.extend(Build_Face_List_Quads(FaceStart,Row-1,DIV))
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        return Move_Verts_Up_Z(sVerts,0),faces,Lowest_Z_Vert
    
    
    
    def add_Nylon_Part(OUTSIDE_RADIUS,Z_LOCATION = 0):
        DIV = 36
        verts = []
        faces = []
        Row = 0
    
        INNER_HOLE = OUTSIDE_RADIUS - (OUTSIDE_RADIUS * (1.5/4.75))
        EDGE_THICKNESS = (OUTSIDE_RADIUS * (0.4/4.75))
    
    Campbell Barton's avatar
    Campbell Barton committed
        # RAD1 = (OUTSIDE_RADIUS * (0.5/4.75))  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        OVER_ALL_HEIGTH = (OUTSIDE_RADIUS * (2.0/4.75))
        PART_THICKNESS = OVER_ALL_HEIGTH - EDGE_THICKNESS
        PART_INNER_HOLE = (OUTSIDE_RADIUS * (2.5/4.75))
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        FaceStart = len(verts)
    
    
    Campbell Barton's avatar
    Campbell Barton committed
        # Start_Height = 0 - 3  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Height_Offset = Z_LOCATION
        Lowest_Z_Vert = 0
    
    Brendon Murphy's avatar
    Brendon Murphy committed
    
        x = INNER_HOLE + EDGE_THICKNESS
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        verts.append([x,0.0,z])
        Lowest_Z_Vert = min(Lowest_Z_Vert,z)
        Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = PART_INNER_HOLE
        z = Height_Offset
        verts.append([x,0.0,z])
        Lowest_Z_Vert = min(Lowest_Z_Vert,z)
        Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        x = PART_INNER_HOLE
        z = Height_Offset - PART_THICKNESS
        verts.append([x,0.0,z])
        Lowest_Z_Vert = min(Lowest_Z_Vert,z)
        Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy 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)
        Row += 1
    
    
        sVerts,sFaces = SpinDup(verts,faces,360,DIV,'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,1))
    
    Brendon Murphy's avatar
    Brendon Murphy committed
    
        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):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Ret_Row = 0;
    
    
        Height_Offset = Height_Offset + PITCH  #Move the offset up so that the verts start at
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                                               #at the correct place  (Height_Start)
    
    Campbell Barton's avatar
    Campbell Barton committed
        # Half_Pitch = float(PITCH)/2  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Height_Step = float(PITCH)/float(DIV)
        Deg_Step = 360.0 /float(DIV)
    
    Brendon Murphy's avatar
    Brendon Murphy 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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
    
        Rank = float(OUTTER_RADIUS - INNER_RADIUS)/float(DIV)
    
        for j in range(1):  #FIXME - for j in range(1) what?!
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                if z > Height_Start:
                    z = Height_Start
                x = sin(radians(i*Deg_Step))*OUTTER_RADIUS
                y = cos(radians(i*Deg_Step))*OUTTER_RADIUS
                verts.append([x,y,z])
            Height_Offset -= Crest_Height
            Ret_Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                if z > Height_Start:
                    z = Height_Start
    
    Brendon Murphy's avatar
    Brendon Murphy 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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                if z > Height_Start:
                    z = Height_Start
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                x = sin(radians(i*Deg_Step))*INNER_RADIUS
                y = cos(radians(i*Deg_Step))*INNER_RADIUS
                if j == 0:
                    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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                if z > Height_Start:
                    z = Height_Start
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                x = sin(radians(i*Deg_Step))*INNER_RADIUS
                y = cos(radians(i*Deg_Step))*INNER_RADIUS
    
                if j == 0:
                    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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        return Ret_Row,Height_Offset
    
    
    def Create_Internal_Thread_End_Verts(verts,INNER_RADIUS,OUTTER_RADIUS,PITCH,DIV,CREST_PERCENT,ROOT_PERCENT,Height_Offset):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Ret_Row = 0;
    
    Campbell Barton's avatar
    Campbell Barton committed
        # Half_Pitch = float(PITCH)/2  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        #Height_End = Height_Offset - PITCH - PITCH - PITCH- PITCH - PITCH- PITCH
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        #Height_End = -2.1
        Height_Step = float(PITCH)/float(DIV)
        Deg_Step = 360.0 /float(DIV)
    
    Brendon Murphy's avatar
    Brendon Murphy 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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
    
        Rank = float(OUTTER_RADIUS - INNER_RADIUS)/float(DIV)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Num = 0
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        for j in range(2):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                if z < Height_End:
                    z = Height_End
                x = sin(radians(i*Deg_Step))*OUTTER_RADIUS
                y = cos(radians(i*Deg_Step))*OUTTER_RADIUS
                verts.append([x,y,z])
            Height_Offset -= Crest_Height
            Ret_Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                if z < Height_End:
                    z = Height_End
    
    Brendon Murphy's avatar
    Brendon Murphy 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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                if z < Height_End:
                    z = Height_End
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                x = sin(radians(i*Deg_Step))*INNER_RADIUS
                y = cos(radians(i*Deg_Step))*INNER_RADIUS
                if j == Num:
                    x = sin(radians(i*Deg_Step))*(INNER_RADIUS + (i*Rank))
                    y = cos(radians(i*Deg_Step))*(INNER_RADIUS + (i*Rank))
                if j > Num:
                    x = sin(radians(i*Deg_Step))*(OUTTER_RADIUS)
                    y = cos(radians(i*Deg_Step))*(OUTTER_RADIUS )
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                verts.append([x,y,z ])
            Height_Offset -= Root_Height
            Ret_Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+1):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                if z < Height_End:
                    z = Height_End
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                x = sin(radians(i*Deg_Step))*INNER_RADIUS
                y = cos(radians(i*Deg_Step))*INNER_RADIUS
    
                if j == Num:
                    x = sin(radians(i*Deg_Step))*(INNER_RADIUS + (i*Rank))
                    y = cos(radians(i*Deg_Step))*(INNER_RADIUS + (i*Rank))
                if j > Num:
                    x = sin(radians(i*Deg_Step))*(OUTTER_RADIUS )
                    y = cos(radians(i*Deg_Step))*(OUTTER_RADIUS )
    
    Brendon Murphy's avatar
    Brendon Murphy committed
                verts.append([x,y,z ])
            Height_Offset -= Root_to_Crest_Height
            Ret_Row += 1
    
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        return Ret_Row,Height_End  # send back Height End as this is the lowest point
    
    
    def Create_Internal_Thread(INNER_DIA,OUTTER_DIA,PITCH,HEIGHT,CREST_PERCENT,ROOT_PERCENT,INTERNAL = 1):
        verts = []
        faces = []
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        DIV = 36
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        INNER_RADIUS = INNER_DIA/2
        OUTTER_RADIUS = OUTTER_DIA/2
    
    Campbell Barton's avatar
    Campbell Barton committed
        # Half_Pitch = float(PITCH)/2  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Deg_Step = 360.0 /float(DIV)
        Height_Step = float(PITCH)/float(DIV)
    
    
        Num = int(round((HEIGHT- PITCH)/PITCH))  # less one pitch for the start and end that is 1/2 pitch high
    
    
    Campbell Barton's avatar
    Campbell Barton committed
        # Col = 0  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Row = 0
    
    Brendon Murphy's avatar
    Brendon Murphy 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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Height_Offset = 0
        FaceStart = len(verts)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Row_Inc,Height_Offset = Create_Internal_Thread_Start_Verts(verts,INNER_RADIUS,OUTTER_RADIUS,PITCH,DIV,CREST_PERCENT,ROOT_PERCENT,Height_Offset)
        Row += Row_Inc
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        for j in range(Num):
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+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_Height
            Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+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_Height
            Row += 1
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            for i in range(DIV+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
    
    Brendon Murphy's avatar
    Brendon Murphy committed
    
        Row_Inc,Height_Offset = Create_Internal_Thread_End_Verts(verts,INNER_RADIUS,OUTTER_RADIUS,PITCH,DIV,CREST_PERCENT,ROOT_PERCENT,Height_Offset)
        Row += Row_Inc
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        faces.extend(Build_Face_List_Quads(FaceStart,DIV,Row -1,INTERNAL))
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        return verts,faces,0 - Height_Offset
    
    
    def Nut_Mesh(props, context):
    
        verts = []
        faces = []
        Head_Verts = []
        Head_Faces= []
        #sc = context.scene
    
        New_Nut_Height = 5
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Face_Start = len(verts)
        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)
        verts.extend(Thread_Verts)
        faces.extend(Copy_Faces(Thread_Faces,Face_Start))
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Face_Start = len(verts)
        Head_Verts,Head_Faces,Lock_Nut_Rad = add_Hex_Nut(props.bf_Hex_Nut_Flat_Distance,props.bf_Major_Dia,New_Nut_Height)
        verts.extend((Head_Verts))
        faces.extend(Copy_Faces(Head_Faces,Face_Start))
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        LowZ = 0 - New_Nut_Height
    
    Brendon Murphy's avatar
    Brendon Murphy 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)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            verts.extend((Nylon_Head_Verts))
            faces.extend(Copy_Faces(Nylon_Head_faces,Face_Start))
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            Face_Start = len(verts)
    
            Nylon_Verts,Nylon_faces,Temp_LowZ = add_Nylon_Part(Lock_Nut_Rad,0-New_Nut_Height)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            verts.extend((Nylon_Verts))
            faces.extend(Copy_Faces(Nylon_faces,Face_Start))
    
    Brendon Murphy's avatar
    Brendon Murphy committed
    
        return Move_Verts_Up_Z(verts,0 - LowZ),faces
    
    
    
    ##########################################################################################
    ##########################################################################################
    ##########################################################################################
    ##                    Create Bolt
    ##########################################################################################
    ##########################################################################################
    
    
    
    def Bolt_Mesh(props, context):
    
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        verts = []
        faces = []
        Bit_Verts = []
        Bit_Faces = []
        Bit_Dia = 0.001
        Head_Verts = []
        Head_Faces= []
        Head_Height = 0.0
        #sc = context.scene
    
    
        ReSized_Allen_Bit_Flat_Distance = props.bf_Allen_Bit_Flat_Distance   # set default
    
    
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        Head_Height = props.bf_Hex_Head_Height # will be changed by the Head Functions
    
    Brendon Murphy's avatar
    Brendon Murphy 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)) * 1.05
    
                #print ("Resized Allen Bit Flat Distance to ",ReSized_Allen_Bit_Flat_Distance)
    
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        #bit Mesh
        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)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        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)
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        #Head Mesh
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            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)
    
    
        elif props.bf_Head_Type == 'bf_Head_Cap':
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            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))