[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4110] trunk/py/scripts/addons/ io_import_scene_unreal_psa_psk.py: Updated to use UI_UL_list as template_list (also a bunch of style cleanup, still some work to do here!).

Bastien Montagne montagne29 at wanadoo.fr
Fri Dec 28 11:07:00 CET 2012


Revision: 4110
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4110
Author:   mont29
Date:     2012-12-28 10:06:57 +0000 (Fri, 28 Dec 2012)
Log Message:
-----------
Updated to use UI_UL_list as template_list (also a bunch of style cleanup, still some work to do here!).

Modified Paths:
--------------
    trunk/py/scripts/addons/io_import_scene_unreal_psa_psk.py

Modified: trunk/py/scripts/addons/io_import_scene_unreal_psa_psk.py
===================================================================
--- trunk/py/scripts/addons/io_import_scene_unreal_psa_psk.py	2012-12-28 04:26:59 UTC (rev 4109)
+++ trunk/py/scripts/addons/io_import_scene_unreal_psa_psk.py	2012-12-28 10:06:57 UTC (rev 4110)
@@ -47,6 +47,7 @@
 import bpy
 import mathutils
 import math
+# XXX Yuck! 'from foo import *' is really bad!
 from mathutils import *
 from math import *
 from bpy.props import *
@@ -58,7 +59,8 @@
 bpy.types.Scene.unrealbonesize = FloatProperty(
     name="Bone Length",
     description="Bone Length from head to tail distance",
-    default=1,min=0.001,max=1000)
+    default=1, min=0.001, max=1000
+)
 
 #output log in to txt file
 DEBUGLOG = False
@@ -68,33 +70,35 @@
 from bpy_extras.io_utils import unpack_list, unpack_face_list
 
 class md5_bone:
-    bone_index=0
-    name=""
-    bindpos=[]
-    bindmat=[]
-    origmat=[]
-    head=[]
-    tail=[]
+    bone_index = 0
+    name = ""
+    bindpos = []
+    bindmat = []
+    origmat = []
+    head = []
+    tail = []
     scale = []
-    parent=""
-    parent_index=0
-    blenderbone=None
-    roll=0
+    parent = ""
+    parent_index = 0
+    blenderbone = None
+    roll = 0
 
     def __init__(self):
-        self.bone_index=0
-        self.name=""
-        self.bindpos=[0.0]*3
-        self.scale=[0.0]*3
-        self.head=[0.0]*3
-        self.tail=[0.0]*3
-        self.bindmat=[None]*3  #is this how you initilize a 2d-array
-        for i in range(3): self.bindmat[i] = [0.0]*3
-        self.origmat=[None]*3  #is this how you initilize a 2d-array
-        for i in range(3): self.origmat[i] = [0.0]*3
-        self.parent=""
-        self.parent_index=0
-        self.blenderbone=None
+        self.bone_index = 0
+        self.name = ""
+        self.bindpos = [0.0] * 3
+        self.scale = [0.0] * 3
+        self.head = [0.0] * 3
+        self.tail = [0.0] * 3
+        self.bindmat = [None] * 3  # is this how you initilize a 2d-array
+        for i in range(3):
+            self.bindmat[i] = [0.0] * 3
+        self.origmat = [None] * 3  #is this how you initilize a 2d-array
+        for i in range(3):
+            self.origmat[i] = [0.0] * 3
+        self.parent = ""
+        self.parent_index = 0
+        self.blenderbone = None
 
     def dump(self):
         print ("bone index: ", self.bone_index)
@@ -104,28 +108,28 @@
         print ("parent: ", self.parent)
         print ("parent index: ", self.parent_index)
         print ("blenderbone: ", self.blenderbone)
-        
+
 def getheadpos(pbone,bones):
-    pos_head = [0.0]*3
+    pos_head = [0.0] * 3
 
     #pos = mathutils.Vector((x,y,z)) * pbone.origmat
     pos = pbone.bindmat.to_translation()
-    
+
     """
     tmp_bone = pbone
     while tmp_bone.name != tmp_bone.parent.name:
         pos = pos * tmp_bone.parent.bindmat
         tmp_bone = tmp_bone.parent
     """
-    
+
     pos_head[0] = pos.x
     pos_head[1] = pos.y
     pos_head[2] = pos.z
-    
+
     return pos_head
-	
+
 def gettailpos(pbone,bones):
-    pos_tail = [0.0]*3
+    pos_tail = [0.0] * 3
     ischildfound = False
     childbone = None
     childbonelist = []
@@ -136,7 +140,7 @@
             childbonelist.append(bone)
             
     if ischildfound:
-        tmp_head = [0.0]*3
+        tmp_head = [0.0] * 3
         for bone in childbonelist:
             tmp_head[0] += bone.head[0]
             tmp_head[1] += bone.head[1]
@@ -147,15 +151,14 @@
         return tmp_head
     else:
         tmp_len = 0.0
-        tmp_len += (pbone.head[0] - pbone.parent.head[0])**2
-        tmp_len += (pbone.head[1] - pbone.parent.head[1])**2
-        tmp_len += (pbone.head[2] - pbone.parent.head[2])**2
-        tmp_len = tmp_len**0.5 * 0.5
+        tmp_len += (pbone.head[0] - pbone.parent.head[0]) ** 2
+        tmp_len += (pbone.head[1] - pbone.parent.head[1]) ** 2
+        tmp_len += (pbone.head[2] - pbone.parent.head[2]) ** 2
+        tmp_len = tmp_len ** 0.5 * 0.5
         pos_tail[0] = pbone.head[0] + tmp_len * pbone.bindmat[0][0]
         pos_tail[1] = pbone.head[1] + tmp_len * pbone.bindmat[1][0]
         pos_tail[2] = pbone.head[2] + tmp_len * pbone.bindmat[2][0]
 
-        
     return pos_tail
 
 def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
@@ -166,72 +169,72 @@
     print ("--------------------------------------------------")
     print (" DEBUG Log:",bDebugLogPSK)
     print ("Importing file: ", infile)
-    
+
     pskfile = open(infile,'rb')
     if (DEBUGLOG):
         logpath = infile.replace(".psk", ".txt")
         print("logpath:",logpath)
         logf = open(logpath,'w')
-        
+
     def printlog(strdata):
         if (DEBUGLOG):
             logf.write(strdata)
-    
+
     objName = infile.split('\\')[-1].split('.')[0]
-    
+
     me_ob = bpy.data.meshes.new(objName)
     print("objName:",objName)
     printlog(("New Mesh = " + me_ob.name + "\n"))
     #read general header
-    indata = unpack('20s3i',pskfile.read(32))
+    indata = unpack('20s3i', pskfile.read(32))
     #not using the general header at this time
     #================================================================================================== 
     # vertex point
     #================================================================================================== 
     #read the PNTS0000 header
-    indata = unpack('20s3i',pskfile.read(32))
+    indata = unpack('20s3i', pskfile.read(32))
     recCount = indata[3]
-    printlog(( "Nbr of PNTS0000 records: " + str(recCount) + "\n"))
+    printlog(("Nbr of PNTS0000 records: " + str(recCount) + "\n"))
     counter = 0
     verts = []
     verts2 = []
     while counter < recCount:
         counter = counter + 1
-        indata = unpack('3f',pskfile.read(12))
-        #print(indata[0],indata[1],indata[2])
-        verts.extend([(indata[0],indata[1],indata[2])])
-        verts2.extend([(indata[0],indata[1],indata[2])])
-        #print([(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]))
-        
+        indata = unpack('3f', pskfile.read(12))
+        #print(indata[0], indata[1], indata[2])
+        verts.extend([(indata[0], indata[1], indata[2])])
+        verts2.extend([(indata[0], indata[1], indata[2])])
+        #print([(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]))
+
     #================================================================================================== 
     # UV
     #================================================================================================== 
     #read the VTXW0000 header
-    indata = unpack('20s3i',pskfile.read(32))
+    indata = unpack('20s3i', pskfile.read(32))
     recCount = indata[3]
-    printlog( "Nbr of VTXW0000 records: " + str(recCount)+ "\n")
+    printlog("Nbr of VTXW0000 records: " + str(recCount)+ "\n")
     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('mat index %i',indata(4))
-        #print([indata[0],indata[2],indata[3]])
-        #print([indata[1],indata[2],indata[3]])
-        
+        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('mat index %i', indata(4))
+        #print([indata[0], indata[2], indata[3]])
+        #print([indata[1], indata[2], indata[3]])
+
     #================================================================================================== 
     # Face
     #================================================================================================== 
     #read the FACE0000 header
-    indata = unpack('20s3i',pskfile.read(32))
+    indata = unpack('20s3i', pskfile.read(32))
     recCount = indata[3]
-    printlog( "Nbr of FACE0000 records: "+ str(recCount) + "\n")
+    printlog("Nbr of FACE0000 records: " + str(recCount) + "\n")
     #PSK FACE0000 fields: WdgIdx1|WdgIdx2|WdgIdx3|MatIdx|AuxMatIdx|SmthGrp
     #associate MatIdx to an image, associate SmthGrp to a material
     SGlist = []
@@ -243,54 +246,55 @@
     printlog("nWdgIdx1|WdgIdx2|WdgIdx3|MatIdx|AuxMatIdx|SmthGrp \n")
     while counter < recCount:
         counter = counter + 1
-        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 = 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
         PNTSA = UVCoords[indata[2]][0]
         PNTSB = UVCoords[indata[1]][0]
         PNTSC = UVCoords[indata[0]][0]
-        #print(PNTSA,PNTSB,PNTSC) #face id vertex
-        #faces.extend([0,1,2,0])
-        faces.extend([(PNTSA,PNTSB,PNTSC,0)])
+        #print(PNTSA, PNTSB, PNTSC) #face id vertex
+        #faces.extend([0, 1, 2, 0])
+        faces.extend([(PNTSA, PNTSB, PNTSC, 0)])
         uv = []
         u0 = UVCoords[indata[2]][1]
         v0 = UVCoords[indata[2]][2]
-        uv.append([u0,1.0 - v0])
+        uv.append([u0, 1.0 - v0])
         u1 = UVCoords[indata[1]][1]
         v1 = UVCoords[indata[1]][2]
-        uv.append([u1,1.0 - v1])
+        uv.append([u1, 1.0 - v1])
         u2 = UVCoords[indata[0]][1]
         v2 = UVCoords[indata[0]][2]
-        uv.append([u2,1.0 - v2])
-        faceuv.append([uv,indata[3],indata[4],indata[5]])
-        
-        #print("material:",indata[3])
-        #print("UV: ",u0,v0)
+        uv.append([u2, 1.0 - v2])
+        faceuv.append([uv, indata[3], indata[4], indata[5]])
+

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list