[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1870] trunk/py/scripts/addons: added weight when import into blender and filter out the ext.

John Phan darkneter at gmail.com
Mon Apr 25 20:24:43 CEST 2011


Revision: 1870
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1870
Author:   darknet
Date:     2011-04-25 18:24:42 +0000 (Mon, 25 Apr 2011)
Log Message:
-----------
added weight when import into blender and filter out the ext.

Modified Paths:
--------------
    trunk/py/scripts/addons/io_export_unreal_psk_psa.py
    trunk/py/scripts/addons/io_import_scene_unreal_psk.py

Modified: trunk/py/scripts/addons/io_export_unreal_psk_psa.py
===================================================================
--- trunk/py/scripts/addons/io_export_unreal_psk_psa.py	2011-04-25 16:29:27 UTC (rev 1869)
+++ trunk/py/scripts/addons/io_export_unreal_psk_psa.py	2011-04-25 18:24:42 UTC (rev 1870)
@@ -1756,13 +1756,6 @@
 
 from bpy.props import *
 
-exporttypedata = []
-
-# [index,text field,0] #or something like that
-exporttypedata.append(("0","PSK","Export PSK"))
-exporttypedata.append(("1","PSA","Export PSA"))
-exporttypedata.append(("2","ALL","Export ALL"))
-
 bpy.types.Scene.unrealfpsrate = IntProperty(
     name="fps rate",
     description="Set the frame per second (fps) for unreal.",
@@ -1771,7 +1764,7 @@
 bpy.types.Scene.unrealexport_settings = EnumProperty(
     name="Export:",
     description="Select a export settings (psk/psa/all)...",
-    items = exporttypedata, default = '0')
+    items = [("0","PSK","Export PSK"),("1","PSA","Export PSA"),("2","ALL","Export ALL")], default = '0')
 	
 bpy.types.Scene.UEActionSetSettings = EnumProperty(
     name="Action Set(s) Export Type",
@@ -1878,6 +1871,7 @@
     # to the class instance from the operator settings before calling.
 
     filepath = StringProperty(name="File Path", description="Filepath used for exporting the PSA file", maxlen= 1024, default= "", subtype='FILE_PATH')
+    filter_glob = StringProperty(default="*.psk;*.psa", options={'HIDDEN'})
     pskexportbool = BoolProperty(name="Export PSK", description="Export Skeletal Mesh", default= True)
     psaexportbool = BoolProperty(name="Export PSA", description="Export Action Set (Animation Data)", default= True)
     actionexportall = BoolProperty(name="All Actions", description="This will export all the actions that matches the current armature.", default=False)

Modified: trunk/py/scripts/addons/io_import_scene_unreal_psk.py
===================================================================
--- trunk/py/scripts/addons/io_import_scene_unreal_psk.py	2011-04-25 16:29:27 UTC (rev 1869)
+++ trunk/py/scripts/addons/io_import_scene_unreal_psk.py	2011-04-25 18:24:42 UTC (rev 1870)
@@ -188,6 +188,7 @@
         indata = unpack('3f',pskfile.read(12))
         #print(indata[0],indata[1],indata[2])
         verts.extend([(indata[0],indata[1],indata[2])])
+        printlog(str(indata[0]) + "|" +str(indata[1]) + "|" +str(indata[2]) + "\n")
         #Tmsh.vertices.append(NMesh.Vert(indata[0],indata[1],indata[2]))
         
     #================================================================================================== 
@@ -200,10 +201,12 @@
     counter = 0
     UVCoords = []
     #UVCoords record format = [index to PNTS, U coord, v coord]
+    printlog("[index to PNTS, U coord, v coord]\n");
     while counter < recCount:
         counter = counter + 1
         indata = unpack('hhffhh',pskfile.read(16))
         UVCoords.append([indata[0],indata[2],indata[3]])
+        printlog(str(indata[0]) + "|" +str(indata[2]) + "|" +str(indata[3])+"\n")
         #print([indata[0],indata[2],indata[3]])
         #print([indata[1],indata[2],indata[3]])
         
@@ -220,10 +223,12 @@
     counter = 0
     faces = []
     faceuv = []
+    #the psk values are: nWdgIdx1|WdgIdx2|WdgIdx3|MatIdx|AuxMatIdx|SmthGrp
+    printlog("nWdgIdx1|WdgIdx2|WdgIdx3|MatIdx|AuxMatIdx|SmthGrp \n")
     while counter < recCount:
         counter = counter + 1
-        indata = unpack('hhhbbi',pskfile.read(12))
-        #the psk values are: nWdgIdx1|WdgIdx2|WdgIdx3|MatIdx|AuxMatIdx|SmthGrp
+        indata = unpack('hhhbbi',pskfile.read(12))        
+        printlog(str(indata[0]) + "|" +str(indata[1]) + "|" +str(indata[2])+ "|" +str(indata[3])+ "|" +str(indata[4])+ "|" +str(indata[5]) + "\n")
         #indata[0] = index of UVCoords
         #UVCoords[indata[0]]=[index to PNTS, U coord, v coord]
         #UVCoords[indata[0]][0] = index to PNTS
@@ -244,6 +249,7 @@
         v2 = UVCoords[indata[2]][2]
         uv.append([u2,v2])
         faceuv.append([uv,indata[3],indata[4],indata[5]])
+        
         #print("material:",indata[3])
         #print("UV: ",u0,v0)
         #update the uv var of the last item in the Tmsh.faces list
@@ -286,6 +292,8 @@
     indata = unpack('20s3i',pskfile.read(32))
     recCount = indata[3]
     printlog( "Nbr of REFSKEL0 records: " + str(recCount) + "\n")
+    #REFSKEL0 fields - Name|Flgs|NumChld|PrntIdx|Qw|Qx|Qy|Qz|LocX|LocY|LocZ|Lngth|XSize|YSize|ZSize
+    
     Bns = []
     bone = []
     nobone = 0
@@ -294,9 +302,11 @@
     #==================================================================================================
     counter = 0
     print ("---PRASE--BONES---")
+    printlog("Name|Flgs|NumChld|PrntIdx|Qw|Qx|Qy|Qz|LocX|LocY|LocZ|Lngth|XSize|YSize|ZSize\n")
     while counter < recCount:
         indata = unpack('64s3i11f',pskfile.read(120))
         #print( "DATA",str(indata))
+        
         bone.append(indata)
         
         createbone = md5_bone()
@@ -308,6 +318,7 @@
         temp_name = temp_name.rstrip(" ")
         temp_name = temp_name.strip()
         temp_name = temp_name.strip( bytes.decode(b'\x00'))
+        printlog(temp_name + "|" +str(indata[1]) + "|" +str(indata[2])+ "|" +str(indata[3])+ "|" +str(indata[4])+ "|" +str(indata[5]) +str(indata[6]) + "|" +str(indata[7]) + "|" +str(indata[8])+ "|" +str(indata[9])+ "|" +str(indata[10])+ "|" +str(indata[11]) +str(indata[12]) + "|" +str(indata[13]) + "|" +str(indata[14])+ "\n")
         print ("temp_name:", temp_name, "||")
         createbone.name = temp_name
         createbone.bone_index = counter
@@ -445,8 +456,6 @@
                     #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()  # XXX, redundant matrix conversion?
-					
-                    
                     newbone.head.x = bone.bindpos[0]
                     newbone.head.y = bone.bindpos[1]
                     newbone.head.z = bone.bindpos[2]
@@ -493,9 +502,14 @@
         counter = counter + 1
         indata = unpack('fii',pskfile.read(12))
         RWghts.append([indata[1],indata[2],indata[0]])
+        #print("weight:",[indata[1],indata[2],indata[0]])
     #RWghts fields = PntIdx|BoneIdx|Weight
     RWghts.sort()
-    printlog( "len(RWghts)=" + str(len(RWghts)) + "\n")
+    printlog( "Vertex point and groups count =" + str(len(RWghts)) + "\n")
+    printlog("PntIdx|BoneIdx|Weight")
+    for vg in RWghts:
+        printlog( str(vg[0]) + "|" + str(vg[1]) + "|" + str(vg[2]) + "\n")
+        
     #Tmsh.update_tag()
     
     #set the Vertex Colors of the faces
@@ -554,7 +568,6 @@
     materials = []
 	
     for matcount in range(materialcount):
-        
         #if texturedata != None:
         matdata = bpy.data.materials.new(materialname + str(matcount))
         #mtex = matdata.texture_slots.new()
@@ -686,24 +699,44 @@
     #
     #===================================================================================================
     obmesh = bpy.data.objects.new(objName,me_ob)
+    #===================================================================================================
+    #Mesh Vertex Group bone weight
+    #===================================================================================================
+    print("---- building bone weight mesh ----")
+    #print(dir(ob_new.data.bones))
+    #create bone vertex group #deal with bone id for index number
+    for bone in ob_new.data.bones:
+        #print("names:",bone.name,":",dir(bone))
+        #print("names:",bone.name)
+        group = obmesh.vertex_groups.new(bone.name)
+    for vgroup in obmesh.vertex_groups:
+        #print(vgroup.name,":",vgroup.index)
+        for vgp in RWghts:
+            #bone index
+            if vgp[1] == vgroup.index:
+                #print(vgp)
+                #[vertex id],weight
+                vgroup.add([vgp[0]], vgp[2], 'ADD')
+				
     #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("---- adding mesh to the scene ----")    
+    bpy.context.scene.objects.link(obmesh)    
     bpy.context.scene.update()
     
     print ("PSK2Blender completed")
 #End of def pskimport#########################
 
-def getInputFilename(filename,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
+def getInputFilename(self,filename,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
     checktype = filename.split('\\')[-1].split('.')[1]
     print ("------------",filename)
-    if checktype.upper() != 'PSK':
+    if checktype.lower() != 'psk':
         print ("  Selected file = ",filename)
         raise (IOError, "The selected input file is not a *.psk file")
-    pskimport(filename,importmesh,importbone,bDebugLogPSK,importmultiuvtextures)
+        #self.report({'INFO'}, ("Selected file:"+ filename))
+    else:
+        pskimport(filename,importmesh,importbone,bDebugLogPSK,importmultiuvtextures)
 
 from bpy.props import *
 
@@ -716,14 +749,15 @@
 	
     # List of operator properties, the attributes will be assigned
     # to the class instance from the operator settings before calling.
-    filepath = StringProperty(name="File Path", description="Filepath used for importing the OBJ file", maxlen= 1024, default= "")
+    filepath = StringProperty(name="File Path", description="Filepath used for importing the psk file", maxlen= 1024, subtype='FILE_PATH')
+    filter_glob = StringProperty(default="*.psk", options={'HIDDEN'})
     importmesh = BoolProperty(name="Mesh", description="Import mesh only. (not yet build.)", default=True)
     importbone = BoolProperty(name="Bones", description="Import bones only. Current not working yet.", default=True)
     importmultiuvtextures = BoolProperty(name="Single UV Texture(s)", description="Single or Multi uv textures.", default=True)
     bDebugLogPSK = BoolProperty(name="Debug Log.txt", description="Log the output of raw format. It will save in current file dir. Note this just for testing.", default=False)
 
     def execute(self, context):
-        getInputFilename(self.filepath,self.importmesh,self.importbone,self.bDebugLogPSK,self.importmultiuvtextures)

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list