[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3951] trunk/py/scripts/addons: changed file name and update credits as the bones are working a bit.

John Phan darkneter at gmail.com
Sun Nov 11 00:00:40 CET 2012


Revision: 3951
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3951
Author:   darknet
Date:     2012-11-10 23:00:38 +0000 (Sat, 10 Nov 2012)
Log Message:
-----------
changed file name and update credits as the bones are working a bit.

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

Removed Paths:
-------------
    trunk/py/scripts/addons/io_import_scene_unreal_psk.py

Added: trunk/py/scripts/addons/io_import_scene_unreal_psa_psk.py
===================================================================
--- trunk/py/scripts/addons/io_import_scene_unreal_psa_psk.py	                        (rev 0)
+++ trunk/py/scripts/addons/io_import_scene_unreal_psa_psk.py	2012-11-10 23:00:38 UTC (rev 3951)
@@ -0,0 +1,1089 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+bl_info = {
+    "name": "Import Unreal Skeleton Mesh (.psk)/Animation Set (psa)",
+    "author": "Darknet, flufy3d, camg188",
+    "version": (2, 1),
+    "blender": (2, 6, 4),
+    "location": "File > Import > Skeleton Mesh (.psk)/Animation Set (psa)",
+    "description": "Import Skeleleton Mesh/Animation Data",
+    "warning": "",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"
+        "Scripts/Import-Export/Unreal_psk_psa",
+    "tracker_url": "https://projects.blender.org/tracker/index.php?"\
+        "func=detail&aid=21366",
+    "category": "Import-Export"}
+
+"""
+Version': '2.0' ported by Darknet
+
+Unreal Tournament PSK file to Blender mesh converter V1.0
+Author: D.M. Sturgeon (camg188 at the elYsium forum), ported by Darknet
+Imports a *psk file to a new mesh
+
+-No UV Texutre
+-No Weight
+-No Armature Bones
+-No Material ID
+-Export Text Log From Current Location File (Bool )
+"""
+
+import bpy
+import mathutils
+import math
+from mathutils import *
+from math import *
+from bpy.props import *
+from string import *
+from struct import *
+from math import *
+from bpy.props import *
+
+bpy.types.Scene.unrealbonesize = FloatProperty(
+    name="Bone Length",
+    description="Bone Length from head to tail distance",
+    default=1,min=0.001,max=1000)
+
+#output log in to txt file
+DEBUGLOG = False
+
+scale = 1.0
+bonesize = 1.0
+from bpy_extras.io_utils import unpack_list, unpack_face_list
+
+class md5_bone:
+    bone_index=0
+    name=""
+    bindpos=[]
+    bindmat=[]
+    origmat=[]
+    head=[]
+    tail=[]
+    scale = []
+    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
+
+    def dump(self):
+        print ("bone index: ", self.bone_index)
+        print ("name: ", self.name)
+        print ("bind position: ", self.bindpos)
+        print ("bind translation matrix: ", self.bindmat)
+        print ("parent: ", self.parent)
+        print ("parent index: ", self.parent_index)
+        print ("blenderbone: ", self.blenderbone)
+        
+def getheadpos(pbone,bones):
+    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
+    ischildfound = False
+    childbone = None
+    childbonelist = []
+    for bone in bones:
+        if bone.parent.name == pbone.name:
+            ischildfound = True
+            childbone = bone
+            childbonelist.append(bone)
+            
+    if ischildfound:
+        tmp_head = [0.0]*3
+        for bone in childbonelist:
+            tmp_head[0] += bone.head[0]
+            tmp_head[1] += bone.head[1]
+            tmp_head[2] += bone.head[2]
+        tmp_head[0] /= len(childbonelist)
+        tmp_head[1] /= len(childbonelist)
+        tmp_head[2] /= len(childbonelist)
+        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
+        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):
+    global DEBUGLOG
+    DEBUGLOG = bDebugLogPSK
+    print ("--------------------------------------------------")
+    print ("---------SCRIPT EXECUTING PYTHON IMPORTER---------")
+    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))
+    #not using the general header at this time
+    #================================================================================================== 
+    # vertex point
+    #================================================================================================== 
+    #read the PNTS0000 header
+    indata = unpack('20s3i',pskfile.read(32))
+    recCount = indata[3]
+    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]))
+        
+    #================================================================================================== 
+    # UV
+    #================================================================================================== 
+    #read the VTXW0000 header
+    indata = unpack('20s3i',pskfile.read(32))
+    recCount = indata[3]
+    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]])
+        
+    #================================================================================================== 
+    # Face
+    #================================================================================================== 
+    #read the FACE0000 header
+    indata = unpack('20s3i',pskfile.read(32))
+    recCount = indata[3]
+    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 = []
+    counter = 0
+    faces = []
+    faceuv = []
+    facesmooth = []
+    #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))        
+        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)])
+        uv = []
+        u0 = UVCoords[indata[2]][1]
+        v0 = UVCoords[indata[2]][2]
+        uv.append([u0,1.0 - v0])
+        u1 = UVCoords[indata[1]][1]
+        v1 = UVCoords[indata[1]][2]
+        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)
+        #update the uv var of the last item in the Tmsh.faces list
+        # which is the face just added above
+        ##Tmsh.faces[-1].uv = [(u0,v0),(u1,v1),(u2,v2)]
+        #print("smooth:",indata[5])
+        #collect a list of the smoothing groups
+        facesmooth.append(indata[5])
+        #print(indata[5])
+        if SGlist.count(indata[5]) == 0:

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list