Skip to content
Snippets Groups Projects
io_export_unreal_psk_psa.py 84.8 KiB
Newer Older
  • Learn to ignore specific revisions
  •         
            return{'FINISHED'}
    
    		
    class OBJECT_OT_UTRebuildArmature(bpy.types.Operator):
        bl_idname = "object.utrebuildarmature"  # XXX, name???
        bl_label = "Rebuild Armature"
    
    John Phan's avatar
    John Phan committed
        __doc__ = "If mesh is deform when importing to unreal engine try this. It rebuild the bones one at the time by select one armature object scrape to raw setup build."
    
    John Phan's avatar
    John Phan committed
            currentbone = [] #select armature for roll copy
    
            for obj in bpy.data.objects:
                if obj.type == 'ARMATURE' and obj.select == True:
                    print("Armature Name:",obj.name)
    
    John Phan's avatar
    John Phan committed
                    objectname = "ArmatureDataPSK"
                    meshname ="ArmatureObjectPSK"
    
                    armdata = bpy.data.armatures.new(objectname)
                    ob_new = bpy.data.objects.new(meshname, armdata)
                    bpy.context.scene.objects.link(ob_new)
    
    John Phan's avatar
    John Phan committed
                    bpy.ops.object.mode_set(mode='OBJECT')
    
                    for i in bpy.context.scene.objects: i.select = False #deselect all objects
                    ob_new.select = True
    
    John Phan's avatar
    John Phan committed
                    bpy.context.scene.objects.active = obj
                    
                    bpy.ops.object.mode_set(mode='EDIT')
                    #print("number of bones:",len(obj.data.edit_bones))
                    for bone in obj.data.edit_bones:
                        #print(dir(bone))
                        #print("roll",(bone.roll))
                        if bone.parent != None:
                            #print([bone.name,bone.roll,bone.roll,None])
                            currentbone.append([bone.name,bone.roll])
                        else:
                            currentbone.append([bone.name,bone.roll])
    
                    bpy.ops.object.mode_set(mode='OBJECT')
    
    John Phan's avatar
    John Phan committed
                    for i in bpy.context.scene.objects: i.select = False #deselect all objects
                    bpy.context.scene.objects.active = ob_new
    
                    bpy.ops.object.mode_set(mode='EDIT')
    
    John Phan's avatar
    John Phan committed
                    
    
    John Phan's avatar
    John Phan committed
                        #print("bone name:",bone.name)
    
                        bpy.ops.object.mode_set(mode='EDIT')
                        newbone = ob_new.data.edit_bones.new(bone.name)
                        newbone.head = bone.head_local
                        newbone.tail = bone.tail_local
    
    John Phan's avatar
    John Phan committed
                        for bonelist in currentbone:
                            if bone.name == bonelist[0]:
                                #print("found",bonelist[1])
                                newbone.roll = bonelist[1]
                                break
                        if bone.parent != None:
                            parentbone = ob_new.data.edit_bones[bone.parent.name]
                            newbone.parent = parentbone
                    print("Rebuild Armture Finish:",ob_new.name)
    
    John Phan's avatar
    John Phan committed
            self.report({'INFO'}, "Rebuild Armature Finish!")
    
    John Phan's avatar
    John Phan committed
    		
    
    def menu_func(self, context):
    
    Luca Bonavita's avatar
    Luca Bonavita committed
        #bpy.context.scene.unrealexportpsk = True
        #bpy.context.scene.unrealexportpsa = True
        default_path = os.path.splitext(bpy.data.filepath)[0] + ".psk"
    
        self.layout.operator(ExportUDKAnimData.bl_idname, text="Skeleton Mesh / Animation Data (.psk/.psa)").filepath = default_path
    
    Luca Bonavita's avatar
    Luca Bonavita committed
        bpy.types.INFO_MT_file_export.append(menu_func)
    
    Luca Bonavita's avatar
    Luca Bonavita committed
        bpy.types.INFO_MT_file_export.remove(menu_func)
    
    Luca Bonavita's avatar
    Luca Bonavita committed
        register()