From 1886b82f382dfb20c5ab4ac0e830d494b39bdcd5 Mon Sep 17 00:00:00 2001 From: John Phan <darkneter@gmail.com> Date: Tue, 15 Feb 2011 16:39:35 +0000 Subject: [PATCH] few update. export check log. --- io_export_unreal_psk_psa.py | 99 ++++++++++++++++++++++++++++++++++- io_import_scene_unreal_psk.py | 46 +++++++++++----- 2 files changed, 129 insertions(+), 16 deletions(-) diff --git a/io_export_unreal_psk_psa.py b/io_export_unreal_psk_psa.py index b7b828794..87a5e87c4 100644 --- a/io_export_unreal_psk_psa.py +++ b/io_export_unreal_psk_psa.py @@ -19,7 +19,7 @@ bl_info = { "name": "Export Skeleletal Mesh/Animation Data", "author": "Darknet/Optimus_P-Fat/Active_Trash/Sinsoft", "version": (2, 0), - "blender": (2, 5, 3), + "blender": (2, 5, 6), "api": 31847, "location": "File > Export > Skeletal Mesh/Animation Data (.psk/.psa)", "description": "Export Unreal Engine (.psk)", @@ -879,7 +879,10 @@ def parse_meshes(blender_meshes, psk_file): print (" -- Dumping Mesh Points -- LEN:",len(points.dict)) for point in points.items(): psk_file.AddPoint(point) + if len(points.dict) > 32767: + raise RuntimeError("Vertex point reach max limited 32767 in pack data. Your",len(points.dict)) print (" -- Dumping Mesh Wedge -- LEN:",len(wedges.dict)) + for wedge in wedges.items(): psk_file.AddWedge(wedge) @@ -1062,6 +1065,19 @@ def parse_armature(blender_armature, psk_file, psa_file): bones = [x for x in current_armature.bones if not x.parent is None] #will ingore this part of the ocde """ + if len(current_armature.bones) == 0: + raise RuntimeError("Warning add two bones else it will crash the unreal editor.") + if len(current_armature.bones) == 1: + raise RuntimeError("Warning add one more bone else it will crash the unreal editor.") + + mainbonecount = 0; + for current_bone in current_armature.bones: #list the bone. #note this will list all the bones. + if(current_bone.parent is None): + mainbonecount += 1 + print("Main Bone",mainbonecount) + if mainbonecount > 1: + #print("Warning there no main bone.") + raise RuntimeError("There too many Main bones. Number main bones:",mainbonecount) for current_bone in current_armature.bones: #list the bone. #note this will list all the bones. if(current_bone.parent is None): parse_bone(current_bone, psk_file, psa_file, 0, 0, current_obj.matrix_local, None) @@ -1524,14 +1540,50 @@ def fs_callback(filename, context): print(" - Too Armature Meshes!") print(" - Select One Armature Object Only!") barmature = False + bMeshScale = True + bMeshCenter = True + if blender_meshes[0] !=None: + if blender_meshes[0].scale.x == 1 and blender_meshes[0].scale.y == 1 and blender_meshes[0].scale.z == 1: + #print("Okay") + bMeshScale = True + else: + print("Error, Mesh Object not scale right should be (1,1,1).") + bMeshScale = False + if blender_meshes[0].location.x == 0 and blender_meshes[0].location.y == 0 and blender_meshes[0].location.z == 0: + #print("Okay") + bMeshCenter = True + else: + print("Error, Mesh Object not center.") + bMeshCenter = False + bArmatureScale = True + bArmatureCenter = True + if blender_armature[0] !=None: + if blender_armature[0].scale.x == 1 and blender_armature[0].scale.y == 1 and blender_armature[0].scale.z == 1: + #print("Okay") + bArmatureScale = True + else: + print("Error, Armature Object not scale right should be (1,1,1).") + bArmatureScale = False + if blender_armature[0].location.x == 0 and blender_armature[0].location.y == 0 and blender_armature[0].location.z == 0: + #print("Okay") + bArmatureCenter = True + else: + print("Error, Armature Object not center.") + bArmatureCenter = False + + + + #print("location:",blender_armature[0].location.x) - if (bmesh == False) or (barmature == False): + if (bmesh == False) or (barmature == False) or (bArmatureCenter == False) or (bArmatureScale == False)or (bMeshScale == False) or (bMeshCenter == False): exportmessage = "Export Fail! Check Log." print("=================================") print("= Export Fail! =") print("=================================") else: exportmessage = "Export Finish!" + #print("blender_armature:",dir(blender_armature[0])) + #print(blender_armature[0].scale) #need to build a temp bone index for mesh group vertex BoneIndexArmature(blender_armature) @@ -1649,6 +1701,11 @@ bpy.types.Scene.unrealtriangulatebool = BoolProperty( bpy.types.Scene.unrealactionexportall = BoolProperty( name="All Actions", description="This let you export all the actions from current armature that matches bone name in action groups names.", + default=False) + +bpy.types.Scene.unrealdisplayactionsets = BoolProperty( + name="Show Action Set(s)", + description="Display Action Sets Information.", default=False) bpy.types.Scene.unrealexportpsk = BoolProperty( @@ -1727,6 +1784,44 @@ class VIEW3D_PT_unrealtools_objectmode(bpy.types.Panel): layout.prop(rd.render, "fps") layout.prop(rd, "unrealactionexportall") + layout.prop(rd, "unrealdisplayactionsets") + #print("unrealdisplayactionsets:",rd.unrealdisplayactionsets) + if rd.unrealdisplayactionsets: + layout.label(text="Total Action Set(s):" + str(len(bpy.data.actions))) + #armature data + amatureobject = None + bonenames = [] #bone name of the armature bones list + #layout.label(text="object(s):" + str(len(bpy.data.objects))) + + for obj in bpy.data.objects: + if obj.type == 'ARMATURE' and obj.select == True: + #print(dir(obj)) + amatureobject = obj + break + elif obj.type == 'ARMATURE': + amatureobject = obj + + if amatureobject != None: + layout.label(text="Armature: " + amatureobject.name) + #print("Armature:",amatureobject.name) + boxactionset = layout.box() + for bone in amatureobject.pose.bones: + bonenames.append(bone.name) + actionsetmatchcount = 0 + for ActionNLA in bpy.data.actions: + nobone = 0 + for group in ActionNLA.groups: + for abone in bonenames: + #print("name:>>",abone) + if abone == group.name: + nobone += 1 + break + if (len(ActionNLA.groups) == len(bonenames)) and (nobone == len(ActionNLA.groups)): + actionsetmatchcount += 1 + #print("Action Set match: Pass") + boxactionset.label(text="Action Name: " + ActionNLA.name) + layout.label(text="Match Found: " + str(actionsetmatchcount)) + #row = layout.row() #row.label(text="Action Set(s)(not build)") #for action in bpy.data.actions: diff --git a/io_import_scene_unreal_psk.py b/io_import_scene_unreal_psk.py index a504bc3d7..6ef9e6403 100644 --- a/io_import_scene_unreal_psk.py +++ b/io_import_scene_unreal_psk.py @@ -361,6 +361,30 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK): break if bfound == False: + ''' + armdata = bpy.data.armatures.new(objectname) + ob_new = bpy.data.objects.new(meshname, armdata) + #ob_new = bpy.data.objects.new(meshname, 'ARMATURE') + #ob_new.data = armdata + bpy.context.scene.objects.link(ob_new) + #bpy.ops.object.mode_set(mode='OBJECT') + for i in bpy.context.scene.objects: i.select = False #deselect all objects + ob_new.select = True + #set current armature to edit the bone + bpy.context.scene.objects.active = ob_new + #set mode to able to edit the bone + bpy.ops.object.mode_set(mode='EDIT') + + #newbone = ob_new.data.edit_bones.new('test') + #newbone.tail.y = 1 + print("creating bone(s)") + for bone in md5_bones: + #print(dir(bone)) + bpy.ops.object.mode_set(mode='EDIT') + newbone = ob_new.data.edit_bones.new(bone.name) + ''' + + armdata = bpy.data.armatures.new(objectname) ob_new = bpy.data.objects.new(meshname, armdata) #ob_new = bpy.data.objects.new(meshname, 'ARMATURE') @@ -396,8 +420,8 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK): newbone.parent = parentbone rotmatrix = bone.bindmat.to_matrix().to_4x4().to_3x3() # XXX, redundant matrix conversion? - #parent_head = parentbone.head * parentbone.matrix.to_quaternion().inverted() - #parent_tail = parentbone.tail * parentbone.matrix.to_quaternion().inverted() + #parent_head = parentbone.head * parentbone.matrix.to_quaternion().inverse() + #parent_tail = parentbone.tail * parentbone.matrix.to_quaternion().inverse() #location=Vector(pos_x,pos_y,pos_z) #set_position = (parent_tail - parent_head) + location #print("tmp head:",set_position) @@ -414,9 +438,10 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK): newbone.tail.y = parentbone.head.y + (pos_y + bonesize * rotmatrix[1][1]) newbone.tail.z = parentbone.head.z + (pos_z + bonesize * rotmatrix[1][2]) else: - #print("rotmatrix:",dir(bone.bindmat.to_matrix().resize_4x4())) + print("rotmatrix:",dir(bone.bindmat.to_matrix().resize_4x4())) #rotmatrix = bone.bindmat.to_matrix().resize_4x4().to_3x3() # XXX, redundant matrix conversion? - rotmatrix = bone.bindmat.to_matrix().to_3x3() + rotmatrix = bone.bindmat.to_matrix().to_3x3() # XXX, redundant matrix conversion? + newbone.head.x = bone.bindpos[0] newbone.head.y = bone.bindpos[1] @@ -467,7 +492,7 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK): #RWghts fields = PntIdx|BoneIdx|Weight RWghts.sort() printlog( "len(RWghts)=" + str(len(RWghts)) + "\n") - #Tmsh.update() + #Tmsh.update_tag() #set the Vertex Colors of the faces #face.v[n] = RWghts[0] @@ -503,7 +528,7 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK): me_ob.faces.foreach_set("vertices_raw", faces) me_ob.faces.foreach_set("use_smooth", [False] * len(me_ob.faces)) - me_ob.update() + me_ob.update_tag() #=================================================================================================== #UV Setup @@ -552,16 +577,13 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK): #=================================================================================================== # #=================================================================================================== - #print("me_ob",dir(me_ob)) - #this update the render in the 3d scene. - me_ob.update(); obmesh = bpy.data.objects.new(objName,me_ob) #check if there is a material to set to if len(materials) > 0: obmesh.active_material = materials[0] #material setup tmp bpy.context.scene.objects.link(obmesh) - #print("obmesh",dir(obmesh)) + bpy.context.scene.update() print ("PSK2Blender completed") @@ -602,13 +624,9 @@ def menu_func(self, context): self.layout.operator(IMPORT_OT_psk.bl_idname, text="Skeleton Mesh (.psk)") def register(): - bpy.utils.register_module(__name__) - bpy.types.INFO_MT_file_import.append(menu_func) def unregister(): - bpy.utils.unregister_module(__name__) - bpy.types.INFO_MT_file_import.remove(menu_func) if __name__ == "__main__": -- GitLab