Skip to content
Snippets Groups Projects
createMesh.py 63.5 KiB
Newer Older
  • Learn to ignore specific revisions
  • Brendon Murphy's avatar
    Brendon Murphy committed
        Head_Verts = []
        Head_Faces= []
        Head_Height = 0.0
        #sc = context.scene
    
        ReSized_Allen_Bit_Flat_Distance = props.bf_Allen_Bit_Flat_Distance   # set default  
       
        
        Head_Height = props.bf_Hex_Head_Height # 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):
                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) 
     
        #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)
        
        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)
       
            
        #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)
    
        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))
    
        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)
    
        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)
    
    
        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))
    #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))
    
    Brendon Murphy's avatar
    Brendon Murphy committed
    
        Face_Start = len(verts)
        verts.extend(Move_Verts_Up_Z(Bit_Verts,Head_Height))
        faces.extend(Copy_Faces(Bit_Faces,Face_Start))
    
        Face_Start = len(verts)
        verts.extend(Move_Verts_Up_Z(Head_Verts,Head_Height))
        faces.extend(Copy_Faces(Head_Faces,Face_Start))
    
        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_Crest_Percent,props.bf_Root_Percent)
    
        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
    
    
    def Create_New_Mesh(props, context, align_matrix):
    
        verts = []
        faces = []
        sMeshName =''
        sObjName =''
            
        if props.bf_Model_Type == 'bf_Model_Bolt':
            #print('Create Bolt')
            verts, faces = Bolt_Mesh(props, context)
            sMeshName = 'Bolt'
            sObjName = 'Bolt'
        
        if props.bf_Model_Type == 'bf_Model_Nut':
            #print('Create Nut')
            verts, faces = Nut_Mesh(props, context)
            sMeshName = 'Nut'
            sObjName = 'Nut'
    
        
        verts, faces = RemoveDoubles(verts, faces)
        
        verts = Scale_Mesh_Verts(verts,GLOBAL_SCALE)
        
        
        mesh = bpy.data.meshes.new(sMeshName)
        
    
        mesh.vertices.add(len(verts))
        mesh.faces.add(len(faces))
    
    
        mesh.vertices.foreach_set("co", unpack_list(verts))
        mesh.faces.foreach_set("vertices_raw", unpack_face_list(faces))
    
    Brendon Murphy's avatar
    Brendon Murphy committed
    
    
        scene = context.scene
    
        bpy.ops.object.select_all(action='DESELECT')
    
        mesh.update()
        ob_new = bpy.data.objects.new(sObjName, mesh)
        scene.objects.link(ob_new)
        ob_new.select = True
        scene.objects.active = ob_new
    
        #ob_new.location = scene.cursor_location
        ob_new.matrix_world = align_matrix
    
        #print("Created_Object")
        return