Skip to content
Snippets Groups Projects
createMesh.py 67.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • Aaron Keith's avatar
    Aaron Keith committed
        # Create new mesh
        mesh = bpy.data.meshes.new(name)
    
        # Make a mesh from a list of verts/edges/faces.
        mesh.from_pydata(verts, edges, faces)
    
        # Update mesh geometry after adding stuff.
    
        # Deselect all objects when in object mode
        if bpy.ops.object.select_all.poll():
            bpy.ops.object.select_all(action='DESELECT')
    
    Aaron Keith's avatar
    Aaron Keith committed
    
        if edit:
            # Replace geometry of existing object
    
            # Use the active obj and select it.
            ob_new = obj_act
            ob_new.select = True
    
            if obj_act.mode == 'OBJECT':
                # Get existing mesh datablock.
                old_mesh = ob_new.data
    
                # Set object data to nothing
                ob_new.data = None
    
                # Clear users of existing mesh datablock.
                old_mesh.user_clear()
    
                # Remove old mesh datablock if no users are left.
                if (old_mesh.users == 0):
                    bpy.data.meshes.remove(old_mesh)
    
                # Assign new mesh datablock.
                ob_new.data = mesh
        else:
            # Create new object
            ob_new = bpy.data.objects.new(name, mesh)
    
            # Link new object to the given scene and select it.
            scene.objects.link(ob_new)
            ob_new.select = True
    
            # Place the object at the 3D cursor location.
            # apply viewRotaion
            ob_new.matrix_world = align_matrix
    
        if obj_act and obj_act.mode == 'EDIT':
            if not edit:
                # We are in EditMode, switch to ObjectMode.
                bpy.ops.object.mode_set(mode='OBJECT')
    
                # Select the active object as well.
                obj_act.select = True
    
                # Apply location of new object.
                scene.update()
    
                # Join new object into the active.
                bpy.ops.object.join()
    
                # Switching back to EditMode.
                bpy.ops.object.mode_set(mode='EDIT')
    
                ob_new = obj_act
    
        else:
            # We are in ObjectMode.
            # Make the new object the active one.
            scene.objects.active = ob_new
    
        return ob_new
    
    
    Brendon Murphy's avatar
    Brendon Murphy committed
    
    def Create_New_Mesh(props, context, align_matrix):
    
        verts = []
        faces = []
    
    Campbell Barton's avatar
    Campbell Barton committed
        # sMeshName =''  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        if props.bf_Model_Type == 'bf_Model_Bolt':
    
            # print('Create Bolt')
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            verts, faces = Bolt_Mesh(props, context)
    
    Campbell Barton's avatar
    Campbell Barton committed
            # sMeshName = 'Bolt'  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            sObjName = 'Bolt'
    
    Brendon Murphy's avatar
    Brendon Murphy committed
        if props.bf_Model_Type == 'bf_Model_Nut':
    
            # print('Create Nut')
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            verts, faces = Nut_Mesh(props, context)
    
    Campbell Barton's avatar
    Campbell Barton committed
            # sMeshName = 'Nut'  # UNUSED
    
    Brendon Murphy's avatar
    Brendon Murphy committed
            sObjName = 'Nut'
    
        verts, faces = RemoveDoubles(verts, faces)
    
        verts = Scale_Mesh_Verts(verts, GLOBAL_SCALE)
    
        obj = create_mesh_object(context, verts, [], faces, sObjName,
                                 props.edit, align_matrix)
    
    Campbell Barton's avatar
    Campbell Barton committed
        return obj