Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2012-12-28 14:06:57 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2012-12-28 14:06:57 +0400
commit108f7a74b973a11b42aed2a64e2e09f9151a7e00 (patch)
tree096c4900502e75e6d08b11b9e455bbab039caf7f /io_import_scene_unreal_psa_psk.py
parentd4ca9c16298a2ae8f9666c0c2643b56c50139636 (diff)
Updated to use UI_UL_list as template_list (also a bunch of style cleanup, still some work to do here!).
Diffstat (limited to 'io_import_scene_unreal_psa_psk.py')
-rw-r--r--io_import_scene_unreal_psa_psk.py739
1 files changed, 377 insertions, 362 deletions
diff --git a/io_import_scene_unreal_psa_psk.py b/io_import_scene_unreal_psa_psk.py
index 408e1fb1..6825511d 100644
--- a/io_import_scene_unreal_psa_psk.py
+++ b/io_import_scene_unreal_psa_psk.py
@@ -47,6 +47,7 @@ Imports a *psk file to a new mesh
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 @@ 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)
+ default=1, min=0.001, max=1000
+)
#output log in to txt file
DEBUGLOG = False
@@ -68,33 +70,35 @@ 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=[]
+ 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 @@ class md5_bone:
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 @@ def gettailpos(pbone,bones):
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 @@ def gettailpos(pbone,bones):
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 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
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 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
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]])
+
+ #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)]
+ ##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:
SGlist.append(indata[5])
- print("smooth:",indata[5])
+ print("smooth:", indata[5])
#assign a material index to the face
#Tmsh.faces[-1].materialIndex = SGlist.index(indata[5])
- printlog( "Using Materials to represent PSK Smoothing Groups...\n")
+ printlog("Using Materials to represent PSK Smoothing Groups...\n")
#==========
# skip something...
#==========
-
+
#==================================================================================================
# Material
#==================================================================================================
##
#read the MATT0000 header
- indata = unpack('20s3i',pskfile.read(32))
+ indata = unpack('20s3i', pskfile.read(32))
recCount = indata[3]
printlog("Nbr of MATT0000 records: " + str(recCount) + "\n" )
printlog(" - Not importing any material data now. PSKs are texture wrapped! \n")
@@ -298,25 +302,24 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
materialcount = 0
while counter < recCount:
counter = counter + 1
- indata = unpack('64s6i',pskfile.read(88))
+ indata = unpack('64s6i', pskfile.read(88))
materialcount += 1
- print("Material",counter)
- print("Mat name %s",indata[0])
+ print("Material", counter)
+ print("Mat name %s", indata[0])
##
-
#==================================================================================================
# Bones (Armature)
#==================================================================================================
#read the REFSKEL0 header
- indata = unpack('20s3i',pskfile.read(32))
+ 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 = []
-
+
md5_bones = []
bni_dict = {}
#==================================================================================================
@@ -326,11 +329,11 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
print ("---PRASE--BONES---")
printlog("Name|Flgs|NumChld|PrntIdx|Qx|Qy|Qz|Qw|LocX|LocY|LocZ|Lngth|XSize|YSize|ZSize\n")
while counter < recCount:
- indata = unpack('64s3i11f',pskfile.read(120))
+ indata = unpack('64s3i11f', pskfile.read(120))
#print( "DATA",str(indata))
-
+
bone.append(indata)
-
+
createbone = md5_bone()
#temp_name = indata[0][:30]
temp_name = indata[0]
@@ -339,7 +342,10 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
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")
+ 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")
createbone.name = temp_name
createbone.bone_index = counter
createbone.parent_index = indata[3]
@@ -349,42 +355,42 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
createbone.scale[0] = indata[12]
createbone.scale[1] = indata[13]
createbone.scale[2] = indata[14]
-
+
bni_dict[createbone.name] = createbone.bone_index
-
+
#w,x,y,z
if (counter == 0):#main parent
- createbone.bindmat = mathutils.Quaternion((indata[7],-indata[4],-indata[5],-indata[6])).to_matrix()
- createbone.origmat = mathutils.Quaternion((indata[7],-indata[4],-indata[5],-indata[6])).to_matrix()
+ createbone.bindmat = mathutils.Quaternion((indata[7], -indata[4], -indata[5], -indata[6])).to_matrix()
+ createbone.origmat = mathutils.Quaternion((indata[7], -indata[4], -indata[5], -indata[6])).to_matrix()
else:
- createbone.bindmat = mathutils.Quaternion((indata[7],-indata[4],-indata[5],-indata[6])).to_matrix()
- createbone.origmat = mathutils.Quaternion((indata[7],-indata[4],-indata[5],-indata[6])).to_matrix()
+ createbone.bindmat = mathutils.Quaternion((indata[7], -indata[4], -indata[5], -indata[6])).to_matrix()
+ createbone.origmat = mathutils.Quaternion((indata[7], -indata[4], -indata[5], -indata[6])).to_matrix()
- createbone.bindmat = mathutils.Matrix.Translation(mathutils.Vector((indata[8],indata[9],indata[10]))) * createbone.bindmat.to_4x4()
+ createbone.bindmat = mathutils.Matrix.Translation(mathutils.Vector((indata[8], indata[9], indata[10]))) * \
+ createbone.bindmat.to_4x4()
-
md5_bones.append(createbone)
counter = counter + 1
bnstr = (str(indata[0]))
Bns.append(bnstr)
-
+
for pbone in md5_bones:
- pbone.parent = md5_bones[pbone.parent_index]
+ pbone.parent = md5_bones[pbone.parent_index]
for pbone in md5_bones:
if pbone.name != pbone.parent.name:
- pbone.bindmat = pbone.parent.bindmat * pbone.bindmat
+ pbone.bindmat = pbone.parent.bindmat * pbone.bindmat
#print(pbone.name)
#print(pbone.bindmat)
#print("end")
else:
pbone.bindmat = pbone.bindmat
-
+
for pbone in md5_bones:
- pbone.head = getheadpos(pbone,md5_bones)
-
+ pbone.head = getheadpos(pbone, md5_bones)
+
for pbone in md5_bones:
- pbone.tail = gettailpos(pbone,md5_bones)
+ pbone.tail = gettailpos(pbone, md5_bones)
for pbone in md5_bones:
pbone.parent = md5_bones[pbone.parent_index].name
@@ -392,15 +398,15 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
bonecount = 0
for armbone in bone:
temp_name = armbone[0][:30]
- #print ("BONE NAME: ",len(temp_name))
+ #print ("BONE NAME: ", len(temp_name))
temp_name=str((temp_name))
#temp_name = temp_name[1]
- #print ("BONE NAME: ",temp_name)
- bonecount +=1
+ #print ("BONE NAME: ", temp_name)
+ bonecount += 1
print ("-------------------------")
print ("----Creating--Armature---")
print ("-------------------------")
-
+
#================================================================================================
#Check armature if exist if so create or update or remove all and addnew bone
#================================================================================================
@@ -419,7 +425,8 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
#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
+ 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
@@ -436,7 +443,7 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
bpy.ops.object.mode_set(mode='EDIT')#Go to edit mode for the bones
newbone = ob_new.data.edit_bones.new(bone.name)
#parent the bone
- #print("DRI:",dir(newbone))
+ #print("DRI:", dir(newbone))
parentbone = None
#note bone location is set in the real space or global not local
bonesize = bpy.types.Scene.unrealbonesize
@@ -444,7 +451,7 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
pos_x = bone.bindpos[0]
pos_y = bone.bindpos[1]
pos_z = bone.bindpos[2]
- #print( "LINKING:" , bone.parent ,"j")
+ #print("LINKING:" , bone.parent ,"j")
parentbone = ob_new.data.edit_bones[bone.parent]
newbone.parent = parentbone
rotmatrix = bone.bindmat
@@ -480,53 +487,59 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
newbone.roll = math.radians(-90.0)
"""
bpy.context.scene.update()
-
+
#==================================================================================================
#END BONE DATA BUILD
#==================================================================================================
VtxCol = []
for x in range(len(Bns)):
#change the overall darkness of each material in a range between 0.1 and 0.9
- tmpVal = ((float(x)+1.0)/(len(Bns))*0.7)+0.1
+ tmpVal = ((float(x) + 1.0) / (len(Bns)) * 0.7) + 0.1
tmpVal = int(tmpVal * 256)
- tmpCol = [tmpVal,tmpVal,tmpVal,0]
+ tmpCol = [tmpVal, tmpVal, tmpVal, 0]
#Change the color of each material slightly
if x % 3 == 0:
- if tmpCol[0] < 128: tmpCol[0] += 60
- else: tmpCol[0] -= 60
+ if tmpCol[0] < 128:
+ tmpCol[0] += 60
+ else:
+ tmpCol[0] -= 60
if x % 3 == 1:
- if tmpCol[1] < 128: tmpCol[1] += 60
- else: tmpCol[1] -= 60
+ if tmpCol[1] < 128:
+ tmpCol[1] += 60
+ else:
+ tmpCol[1] -= 60
if x % 3 == 2:
- if tmpCol[2] < 128: tmpCol[2] += 60
- else: tmpCol[2] -= 60
+ if tmpCol[2] < 128:
+ tmpCol[2] += 60
+ else:
+ tmpCol[2] -= 60
#Add the material to the mesh
VtxCol.append(tmpCol)
-
+
#==================================================================================================
# Bone Weight
#==================================================================================================
#read the RAWW0000 header
- indata = unpack('20s3i',pskfile.read(32))
+ indata = unpack('20s3i', pskfile.read(32))
recCount = indata[3]
- printlog( "Nbr of RAWW0000 records: " + str(recCount) +"\n")
+ printlog("Nbr of RAWW0000 records: " + str(recCount) +"\n")
#RAWW0000 fields: Weight|PntIdx|BoneIdx
RWghts = []
counter = 0
while counter < recCount:
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]])
+ 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( "Vertex point and groups count =" + 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")
-
+ printlog(str(vg[0]) + "|" + str(vg[1]) + "|" + str(vg[2]) + "\n")
+
#Tmsh.update_tag()
-
+
#set the Vertex Colors of the faces
#face.v[n] = RWghts[0]
#RWghts[1] = index of VtxCol
@@ -540,37 +553,36 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
n = n + 1
TmpCol = VtxCol[RWghts[n][1]]
#check if a vertex has more than one influence
- if n != len(RWghts)-1:
- if RWghts[n][0] == RWghts[n+1][0]:
+ if n != len(RWghts) - 1:
+ if RWghts[n][0] == RWghts[n + 1][0]:
#if there is more than one influence, use the one with the greater influence
#for simplicity only 2 influences are checked, 2nd and 3rd influences are usually very small
- if RWghts[n][2] < RWghts[n+1][2]:
- TmpCol = VtxCol[RWghts[n+1][1]]
- Tmsh.faces[x].col.append(NMesh.Col(TmpCol[0],TmpCol[1],TmpCol[2],0))
+ if RWghts[n][2] < RWghts[n + 1][2]:
+ TmpCol = VtxCol[RWghts[n + 1][1]]
+ Tmsh.faces[x].col.append(NMesh.Col(TmpCol[0], TmpCol[1], TmpCol[2], 0))
"""
if (DEBUGLOG):
logf.close()
#==================================================================================================
#Building Mesh
#==================================================================================================
- print("vertex:",len(verts),"faces:",len(faces))
- print("vertex2:",len(verts2))
+ print("vertex:", len(verts), "faces:", len(faces))
+ print("vertex2:", len(verts2))
me_ob.vertices.add(len(verts2))
me_ob.tessfaces.add(len(faces))
me_ob.vertices.foreach_set("co", unpack_list(verts2))
- me_ob.tessfaces.foreach_set("vertices_raw",unpack_list( faces))
-
+ me_ob.tessfaces.foreach_set("vertices_raw", unpack_list( faces))
+
for face in me_ob.tessfaces:
- face.use_smooth = facesmooth[face.index]
-
+ face.use_smooth = facesmooth[face.index]
+
"""
Material setup coding.
First the mesh has to be create first to get the uv texture setup working.
-Create material(s) list in the psk pack data from the list.(to do list)
-Append the material to the from create the mesh object.
-Create Texture(s)
- -fae loop for uv assign and assign material index
-
+ -face loop for uv assign and assign material index
"""
bpy.ops.object.mode_set(mode='OBJECT')
#===================================================================================================
@@ -591,9 +603,9 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
#print(dir(mtex))
#print(dir(matdata))
#for texno in range(len( bpy.data.textures)):
- #print((bpy.data.textures[texno].name))
+ #print((bpy.data.textures[texno].name))
#print(dir(bpy.data.textures[texno]))
- #matdata.active_texture = bpy.data.textures[matcount-1]
+ #matdata.active_texture = bpy.data.textures[matcount - 1]
#matdata.texture_coords = 'UV'
#matdata.active_texture = texturedata
materials.append(matdata)
@@ -611,13 +623,13 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
# texturename = "text1" # UNUSED
countm = 0
for countm in range(materialcount):
- psktexname="psk" + str(countm)
+ psktexname = "psk" + str(countm)
me_ob.uv_textures.new(name=psktexname)
countm += 1
print("INIT UV TEXTURE...")
_matcount = 0
#for mattexcount in materials:
- #print("MATERAIL ID:",_matcount)
+ #print("MATERAIL ID:", _matcount)
_textcount = 0
for uv in me_ob.tessface_uv_textures: # uv texture
print("UV TEXTURE ID:",_textcount)
@@ -627,25 +639,25 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
if faceuv[face.index][1] == _textcount: #if face index and texture index matches assign it
mfaceuv = faceuv[face.index] #face index
_uv1 = mfaceuv[0][0] #(0,0)
- uv.data[face.index].uv1 = mathutils.Vector((_uv1[0],_uv1[1])) #set them
+ uv.data[face.index].uv1 = mathutils.Vector((_uv1[0], _uv1[1])) #set them
_uv2 = mfaceuv[0][1] #(0,0)
- uv.data[face.index].uv2 = mathutils.Vector((_uv2[0],_uv2[1])) #set them
+ uv.data[face.index].uv2 = mathutils.Vector((_uv2[0], _uv2[1])) #set them
_uv3 = mfaceuv[0][2] #(0,0)
- uv.data[face.index].uv3 = mathutils.Vector((_uv3[0],_uv3[1])) #set them
+ uv.data[face.index].uv3 = mathutils.Vector((_uv3[0], _uv3[1])) #set them
else: #if not match zero them
- uv.data[face.index].uv1 = mathutils.Vector((0,0)) #zero them
- uv.data[face.index].uv2 = mathutils.Vector((0,0)) #zero them
- uv.data[face.index].uv3 = mathutils.Vector((0,0)) #zero them
+ uv.data[face.index].uv1 = mathutils.Vector((0, 0)) #zero them
+ uv.data[face.index].uv2 = mathutils.Vector((0, 0)) #zero them
+ uv.data[face.index].uv3 = mathutils.Vector((0, 0)) #zero them
_textcount += 1
#_matcount += 1
#print(matcount)
print("END UV TEXTURE...")
- print("UV TEXTURE LEN:",len(texture))
+ print("UV TEXTURE LEN:", len(texture))
#for tex in me_ob.uv_textures:
- #print("mesh tex:",dir(tex))
+ #print("mesh tex:", dir(tex))
#print((tex.name))
-
+
#for face in me_ob.faces:
#print(dir(face))
@@ -660,15 +672,14 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
#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)
+ #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)
+ #print(vgroup.name, ":", vgroup.index)
for vgp in RWghts:
#bone index
-
if vgp[1] == bni_dict[vgroup.name]:
#print(vgp)
#[vertex id],weight
@@ -678,7 +689,7 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
if len(materials) > 0:
obmesh.active_material = materials[0] #material setup tmp
print("---- adding mesh to the scene ----")
-
+
bpy.ops.object.mode_set(mode='OBJECT')
#bpy.ops.object.select_pattern(extend=True, pattern=obmesh.name, case_sensitive=True)
#bpy.ops.object.select_pattern(extend=True, pattern=ob_new.name, case_sensitive=True)
@@ -694,26 +705,26 @@ def pskimport(infile,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
obmesh.select = True
ob_new.select = True
bpy.ops.object.parent_set(type="ARMATURE")
-
+
print ("PSK2Blender completed")
#End of def pskimport#########################
-def getInputFilenamepsk(self,filename,importmesh,importbone,bDebugLogPSK,importmultiuvtextures):
+def getInputFilenamepsk(self, filename, importmesh, importbone, bDebugLogPSK, importmultiuvtextures):
checktype = filename.split('\\')[-1].split('.')[1]
print ("------------",filename)
if checktype.lower() != 'psk':
- print (" Selected file = ",filename)
+ print (" Selected file = ", filename)
raise (IOError, "The selected input file is not a *.psk file")
#self.report({'INFO'}, ("Selected file:"+ filename))
else:
- pskimport(filename,importmesh,importbone,bDebugLogPSK,importmultiuvtextures)
-
-def getInputFilenamepsa(self,filename,context):
+ pskimport(filename, importmesh, importbone, bDebugLogPSK, importmultiuvtextures)
+
+def getInputFilenamepsa(self, filename, context):
checktype = filename.split('\\')[-1].split('.')[1]
if checktype.lower() != 'psa':
- print (" Selected file = ",filename)
+ print (" Selected file = ", filename)
raise (IOError, "The selected input file is not a *.psa file")
- #self.report({'INFO'}, ("Selected file:"+ filename))
+ #self.report({'INFO'}, ("Selected file:" + filename))
else:
psaimport(filename,context)
@@ -751,7 +762,7 @@ class IMPORT_OT_psk(bpy.types.Operator):
)
bDebugLogPSK = BoolProperty(
name="Debug Log.txt",
- description="Log the output of raw format. It will save in " \
+ description="Log the output of raw format. It will save in "
"current file dir. Note this just for testing",
default=False,
)
@@ -765,13 +776,14 @@ class IMPORT_OT_psk(bpy.types.Operator):
def execute(self, context):
bpy.types.Scene.unrealbonesize = self.unrealbonesize
- getInputFilenamepsk(self,self.filepath,self.importmesh,self.importbone,self.bDebugLogPSK,self.importmultiuvtextures)
+ getInputFilenamepsk(self, self.filepath, self.importmesh, self.importbone, self.bDebugLogPSK,
+ self.importmultiuvtextures)
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
- return {'RUNNING_MODAL'}
+ return {'RUNNING_MODAL'}
class psa_bone:
name=""
@@ -781,7 +793,7 @@ class psa_bone:
self.name=""
self.Transform=None
self.parent=None
-
+
def psaimport(filename,context):
print ("--------------------------------------------------")
print ("---------SCRIPT EXECUTING PYTHON IMPORTER---------")
@@ -791,33 +803,33 @@ def psaimport(filename,context):
debug = True
if (debug):
logpath = filename.replace(".psa", ".txt")
- print("logpath:",logpath)
- logf = open(logpath,'w')
+ print("logpath:", logpath)
+ logf = open(logpath, 'w')
def printlog(strdata):
if (debug):
logf.write(strdata)
- def printlogplus(name,data):
+ def printlogplus(name, data):
if (debug):
- logf.write(str(name)+'\n')
- if isinstance(data,bytes):
+ logf.write(str(name) + '\n')
+ if isinstance(data, bytes):
logf.write(str(bytes.decode(data).strip(bytes.decode(b'\x00'))))
else:
logf.write(str(data))
logf.write('\n')
-
+
printlog('-----------Log File------------\n')
#General Header
- indata = unpack('20s3i',psafile.read(32))
- printlogplus('ChunkID',indata[0])
- printlogplus('TypeFlag',indata[1])
- printlogplus('DataSize',indata[2])
- printlogplus('DataCount',indata[3])
+ indata = unpack('20s3i', psafile.read(32))
+ printlogplus('ChunkID', indata[0])
+ printlogplus('TypeFlag', indata[1])
+ printlogplus('DataSize', indata[2])
+ printlogplus('DataCount', indata[3])
#Bones Header
- indata = unpack('20s3i',psafile.read(32))
- printlogplus('ChunkID',indata[0])
- printlogplus('TypeFlag',indata[1])
- printlogplus('DataSize',indata[2])
- printlogplus('DataCount',indata[3])
+ indata = unpack('20s3i', psafile.read(32))
+ printlogplus('ChunkID', indata[0])
+ printlogplus('TypeFlag', indata[1])
+ printlogplus('DataSize', indata[2])
+ printlogplus('DataCount', indata[3])
#Bones Data
BoneIndex2NamePairMap = {}
BoneNotFoundList = []
@@ -826,56 +838,56 @@ def psaimport(filename,context):
counter = 0
nobonematch = True
while counter < recCount:
- indata = unpack('64s3i11f',psafile.read(120))
- #printlogplus('bone',indata[0])
+ indata = unpack('64s3i11f', psafile.read(120))
+ #printlogplus('bone', indata[0])
bonename = str(bytes.decode(indata[0]).strip(bytes.decode(b'\x00')))
if bonename in bpy.data.armatures['armaturedata'].bones.keys():
BoneIndex2NamePairMap[counter] = bonename
- print('find bone',bonename)
+ print('find bone', bonename)
nobonematch = False
else:
- print('can not find the bone:',bonename)
+ print('can not find the bone:', bonename)
BoneNotFoundList.append(counter)
counter += 1
-
+
if nobonematch:
print('no bone was match so skip import!')
return
-
+
#Animations Header
- indata = unpack('20s3i',psafile.read(32))
- printlogplus('ChunkID',indata[0])
- printlogplus('TypeFlag',indata[1])
- printlogplus('DataSize',indata[2])
- printlogplus('DataCount',indata[3])
+ indata = unpack('20s3i', psafile.read(32))
+ printlogplus('ChunkID', indata[0])
+ printlogplus('TypeFlag', indata[1])
+ printlogplus('DataSize', indata[2])
+ printlogplus('DataCount', indata[3])
#Animations Data
recCount = indata[3]
counter = 0
Raw_Key_Nums = 0
Action_List = []
while counter < recCount:
- indata = unpack('64s64s4i3f3i',psafile.read(64+64+4*4+3*4+3*4))
- printlogplus('Name',indata[0])
- printlogplus('Group',indata[1])
- printlogplus('totalbones',indata[2])
- printlogplus('NumRawFrames',indata[-1])
+ indata = unpack('64s64s4i3f3i', psafile.read(64 + 64 + 4 * 4 + 3 * 4 + 3 * 4))
+ printlogplus('Name', indata[0])
+ printlogplus('Group', indata[1])
+ printlogplus('totalbones', indata[2])
+ printlogplus('NumRawFrames', indata[-1])
Name = str(bytes.decode(indata[0]).strip(bytes.decode(b'\x00')))
Group = str(bytes.decode(indata[1]).strip(bytes.decode(b'\x00')))
totalbones = indata[2]
NumRawFrames = indata[-1]
-
+
Raw_Key_Nums += indata[2] * indata[-1]
Action_List.append((Name,Group,totalbones,NumRawFrames))
-
+
counter += 1
-
+
#Raw keys Header
Raw_Key_List = []
- indata = unpack('20s3i',psafile.read(32))
- printlogplus('ChunkID',indata[0])
- printlogplus('TypeFlag',indata[1])
- printlogplus('DataSize',indata[2])
- printlogplus('DataCount',indata[3])
+ indata = unpack('20s3i', psafile.read(32))
+ printlogplus('ChunkID', indata[0])
+ printlogplus('TypeFlag', indata[1])
+ printlogplus('DataSize', indata[2])
+ printlogplus('DataCount', indata[3])
if(Raw_Key_Nums != indata[3]):
print('error! Raw_Key_Nums Inconsistent')
return
@@ -883,39 +895,39 @@ def psaimport(filename,context):
recCount = Raw_Key_Nums
counter = 0
while counter < recCount:
- indata = unpack('3f4f1f',psafile.read(3*4+4*4+4))
+ indata = unpack('3f4f1f', psafile.read(3 * 4 + 4 * 4 + 4))
pos = mathutils.Vector((indata[0], indata[1], indata[2]))
quat = mathutils.Quaternion((indata[6], indata[3], indata[4], indata[5]))
time = indata[7]
- Raw_Key_List.append((pos,quat,time))
+ Raw_Key_List.append((pos, quat, time))
counter += 1
#Scale keys Header,Scale keys Data,Curve keys Header,Curve keys Data
curFilePos = psafile.tell()
- psafile.seek(0,2)
+ psafile.seek(0, 2)
endFilePos = psafile.tell()
if curFilePos == endFilePos:
print('no Scale keys,Curve keys')
-
+
#build the animation line
if bpy.ops.object.mode_set.poll():
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
-
+
NeededBoneMatrix = {}
ARMATURE_OBJ = 'ArmObject'
ARMATURE_DATA = 'armaturedata'
if bpy.context.scene.udk_importarmatureselect:
if len(bpy.context.scene.udkas_list) > 0:
print("CHECKING ARMATURE...")
- #for bone in bpy.data.objects[ARMATURE_OBJ].pose.bones:
+ #for bone in bpy.data.objects[ARMATURE_OBJ].pose.bones:
#for objd in bpy.data.objects:
- #print("NAME:",objd.name," TYPE:",objd.type)
+ #print("NAME:", objd.name, " TYPE:", objd.type)
#if objd.type == 'ARMARURE':
#print(dir(objd))
armature_list = bpy.context.scene.udkas_list #armature list array
armature_idx = bpy.context.scene.udkimportarmature_list_idx #armature index selected
ARMATURE_OBJ = bpy.data.objects[armature_list[armature_idx]].name #object armature
ARMATURE_DATA = bpy.data.objects[armature_list[armature_idx]].data.name #object data
-
+
for bone in bpy.data.armatures[ARMATURE_DATA].bones:
name = bone.name
ori_matrix = bone.matrix
@@ -928,7 +940,7 @@ def psaimport(filename,context):
bone_rest_matrix_inv.resize_4x4()
bone_rest_matrix.resize_4x4()
NeededBoneMatrix[name] = (bone_rest_matrix,bone_rest_matrix_inv,ori_matrix)
-
+
#build tmp pose bone tree
psa_bones = {}
for bone in bpy.data.objects[ARMATURE_OBJ].pose.bones:
@@ -940,29 +952,29 @@ def psaimport(filename,context):
else:
_psa_bone.parent = None
psa_bones[bone.name] = _psa_bone
-
+
raw_key_index = 0
for raw_action in Action_List:
- Name = raw_action[0]
- Group = raw_action[1]
- Totalbones = raw_action[2]
- NumRawFrames = raw_action[3]
+ Name = raw_action[0]
+ Group = raw_action[1]
+ Totalbones = raw_action[2]
+ NumRawFrames = raw_action[3]
context.scene.update()
object = bpy.data.objects['ArmObject']
object.animation_data_create()
- action = bpy.data.actions.new(name=Name)
+ action = bpy.data.actions.new(name=Name)
object.animation_data.action = action
for i in range(NumRawFrames):
- context.scene.frame_set(i+1)
+ context.scene.frame_set(i + 1)
pose_bones = object.pose.bones
for j in range(Totalbones):
if j not in BoneNotFoundList:
bName = BoneIndex2NamePairMap[j]
- pbone = psa_bones[bName]
+ pbone = psa_bones[bName]
pos = Raw_Key_List[raw_key_index][0]
quat = Raw_Key_List[raw_key_index][1]
-
+
mat = Matrix()
if pbone.parent != None:
quat = quat.conjugated()
@@ -978,7 +990,7 @@ def psaimport(filename,context):
raw_key_index += 1
#bpy.data.meshes[1]
- for bone in pose_bones:
+ for bone in pose_bones:
bone.matrix = psa_bones[bone.name].Transform
bone.keyframe_insert("rotation_quaternion")
bone.keyframe_insert("location")
@@ -986,16 +998,16 @@ def psaimport(filename,context):
def whirlSingleBone(pose_bone,quat):
bpy.context.scene.update()
#record child's matrix and origin rotate
- hymat = Quaternion((0.707,-0.707,0,0)).inverted().to_matrix().to_4x4()
+ hymat = Quaternion((0.707, -0.707, 0, 0)).inverted().to_matrix().to_4x4()
children_infos = {}
childrens = pose_bone.children
for child in childrens:
- armmat = bpy.data.armatures['armaturedata'].bones[child.name].matrix.copy().to_4x4()
+ armmat = bpy.data.armatures['armaturedata'].bones[child.name].matrix.copy().to_4x4()
cmat = child.matrix.copy() * armmat.inverted() * hymat.inverted()
pos = cmat.to_translation()
rotmat = cmat.to_3x3()
- children_infos[child] = (armmat,pos,rotmat)
-
+ children_infos[child] = (armmat, pos, rotmat)
+
#whirl this bone by quat
pose_bone.matrix *= quat.to_matrix().to_4x4()
pose_bone.keyframe_insert("location")
@@ -1003,7 +1015,7 @@ def psaimport(filename,context):
bpy.context.scene.update()
#set back children bon to original position
#reverse whirl child bone by quat.inverse()
-
+
for child in childrens:
armmat = children_infos[child][0]
pos = children_infos[child][1]
@@ -1015,17 +1027,17 @@ def psaimport(filename,context):
for bone in pose_bones:
if bone.parent != None:
- whirlSingleBone(bone,Quaternion((0.707,0,0,-0.707)))
+ whirlSingleBone(bone,Quaternion((0.707, 0, 0, -0.707)))
else:
- bone.rotation_quaternion *= Quaternion((0.707,-0.707,0,0))*Quaternion((0.707,0,0,-0.707))
+ bone.rotation_quaternion *= Quaternion((0.707, -0.707, 0, 0)) * Quaternion((0.707, 0, 0, -0.707))
bone.keyframe_insert("rotation_quaternion")
-
+
break
-
+
context.scene.frame_set(0)
if(debug):
logf.close()
-
+
class IMPORT_OT_psa(bpy.types.Operator):
'''Load a skeleton anim psa File'''
bl_idname = "import_scene.psa"
@@ -1048,7 +1060,7 @@ class IMPORT_OT_psa(bpy.types.Operator):
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
- return {'RUNNING_MODAL'}
+ return {'RUNNING_MODAL'}
class IMPORT_OT_psa(bpy.types.Operator):
'''Load a skeleton anim psa File'''
@@ -1072,50 +1084,50 @@ class IMPORT_OT_psa(bpy.types.Operator):
def invoke(self, context, event):
wm = context.window_manager
wm.fileselect_add(self)
- return {'RUNNING_MODAL'}
+ return {'RUNNING_MODAL'}
bpy.types.Scene.udk_importpsk = StringProperty(
- name = "Import .psk",
- description = "Skeleton mesh file path for psk",
- default = "")
+ name = "Import .psk",
+ description = "Skeleton mesh file path for psk",
+ default = "")
bpy.types.Scene.udk_importpsa = StringProperty(
- name = "Import .psa",
- description = "Animation Data to Action Set(s) file path for psa",
- default = "")
+ name = "Import .psa",
+ description = "Animation Data to Action Set(s) file path for psa",
+ default = "")
bpy.types.Scene.udk_importarmatureselect = BoolProperty(
- name = "Armature Selected",
- description = "Select Armature to Import psa animation data.",
- default = False)
-
-class Panel_UDKImport( bpy.types.Panel ):
-
- bl_label = "UDK Import"
- bl_idname = "OBJECT_PT_udk_import"
- bl_space_type = "VIEW_3D"
- bl_region_type = "TOOLS"
-
- filepath = StringProperty(
+ name = "Armature Selected",
+ description = "Select Armature to Import psa animation data",
+ default = False)
+
+class Panel_UDKImport(bpy.types.Panel):
+ bl_label = "UDK Import"
+ bl_idname = "OBJECT_PT_udk_import"
+ bl_space_type = "VIEW_3D"
+ bl_region_type = "TOOLS"
+
+ filepath = StringProperty(
subtype='FILE_PATH',
)
-
- #@classmethod
- #def poll(cls, context):
- # return context.active_object
-
- def draw(self, context):
- layout = self.layout
- layout.operator(OBJECT_OT_PSKPath.bl_idname)
-
- layout.prop(context.scene, "udk_importarmatureselect")
- if bpy.context.scene.udk_importarmatureselect:
- layout.operator(OBJECT_OT_UDKImportArmature.bl_idname)
- layout.template_list(context.scene, "udkimportarmature_list", context.scene, "udkimportarmature_list_idx",prop_list="template_list_controls", rows=5)
- layout.operator(OBJECT_OT_PSAPath.bl_idname)
-
+
+ #@classmethod
+ #def poll(cls, context):
+ # return context.active_object
+
+ def draw(self, context):
+ layout = self.layout
+ layout.operator(OBJECT_OT_PSKPath.bl_idname)
+
+ layout.prop(context.scene, "udk_importarmatureselect")
+ if bpy.context.scene.udk_importarmatureselect:
+ layout.operator(OBJECT_OT_UDKImportArmature.bl_idname)
+ layout.template_list("UI_UL_list", "", context.scene, "udkimportarmature_list",
+ context.scene, "udkimportarmature_list_idx", rows=5)
+ layout.operator(OBJECT_OT_PSAPath.bl_idname)
+
class OBJECT_OT_PSKPath(bpy.types.Operator):
+ """Select .psk file path to import for skeleton mesh"""
bl_idname = "object.pskpath"
bl_label = "Import PSK Path"
- __doc__ = " Select .psk file path to import for skeleton mesh."
filepath = StringProperty(
subtype='FILE_PATH',
@@ -1152,107 +1164,110 @@ class OBJECT_OT_PSKPath(bpy.types.Operator):
min=0.001,
max=1000,
)
-
+
def execute(self, context):
#context.scene.importpskpath = self.properties.filepath
bpy.types.Scene.unrealbonesize = self.unrealbonesize
- getInputFilenamepsk(self,self.filepath,self.importmesh,self.importbone,self.bDebugLogPSK,self.importmultiuvtextures)
+ getInputFilenamepsk(self, self.filepath, self.importmesh, self.importbone, self.bDebugLogPSK,
+ self.importmultiuvtextures)
return {'FINISHED'}
-
+
def invoke(self, context, event):
#bpy.context.window_manager.fileselect_add(self)
wm = context.window_manager
wm.fileselect_add(self)
return {'RUNNING_MODAL'}
-
+
class UDKImportArmaturePG(bpy.types.PropertyGroup):
- bool = BoolProperty(default=False)
- string = StringProperty()
- bexport = BoolProperty(default=False,name="Export", options={"HIDDEN"},description = "This will be ignore when exported")
- bselect = BoolProperty(default=False,name="Select", options={"HIDDEN"},description = "This will be ignore when exported")
- otype = StringProperty(name="Type",description = "This will be ignore when exported")
- template_list_controls = StringProperty(default="", options={"HIDDEN"})
+ #boolean = BoolProperty(default=False)
+ string = StringProperty()
+ bexport = BoolProperty(default=False, name="Export", options={"HIDDEN"},
+ description = "This will be ignore when exported")
+ bselect = BoolProperty(default=False, name="Select", options={"HIDDEN"},
+ description = "This will be ignore when exported")
+ otype = StringProperty(name="Type",description = "This will be ignore when exported")
bpy.utils.register_class(UDKImportArmaturePG)
bpy.types.Scene.udkimportarmature_list = CollectionProperty(type=UDKImportArmaturePG)
bpy.types.Scene.udkimportarmature_list_idx = IntProperty()
class OBJECT_OT_PSAPath(bpy.types.Operator):
- bl_idname = "object.psapath"
- bl_label = "Import PSA Path"
- __doc__ = " Select .psa file path to import for animation data."
+ """Select .psa file path to import for animation data"""
+ bl_idname = "object.psapath"
+ bl_label = "Import PSA Path"
- filepath = StringProperty(name="PSA File Path", description="Filepath used for importing the PSA file", maxlen= 1024, default= "")
- filter_glob = StringProperty(
+ filepath = StringProperty(name="PSA File Path", description="Filepath used for importing the PSA file",
+ maxlen=1024, default="")
+ filter_glob = StringProperty(
default="*.psa",
options={'HIDDEN'},
)
-
- def execute(self, context):
- #context.scene.importpsapath = self.properties.filepath
- getInputFilenamepsa(self,self.filepath,context)
- return {'FINISHED'}
-
- def invoke(self, context, event):
- bpy.context.window_manager.fileselect_add(self)
- return {'RUNNING_MODAL'}
-
+
+ def execute(self, context):
+ #context.scene.importpsapath = self.properties.filepath
+ getInputFilenamepsa(self,self.filepath,context)
+ return {'FINISHED'}
+
+ def invoke(self, context, event):
+ bpy.context.window_manager.fileselect_add(self)
+ return {'RUNNING_MODAL'}
+
class OBJECT_OT_UDKImportArmature(bpy.types.Operator):
- bl_idname = "object.udkimportarmature"
- bl_label = "Update Armature"
- __doc__ = "This will update the filter of the mesh and armature."
-
- def execute(self, context):
- my_objlist = bpy.context.scene.udkimportarmature_list
- objectl = []
- for objarm in bpy.context.scene.objects:#list and filter only mesh and armature
- if objarm.type == 'ARMATURE':
- objectl.append(objarm)
- for _objd in objectl:#check if list has in udk list
- bfound_obj = False
- for _obj in my_objlist:
- if _obj.name == _objd.name and _obj.otype == _objd.type:
- _obj.bselect = _objd.select
- bfound_obj = True
- break
- if bfound_obj == False:
- #print("ADD ARMATURE...")
- my_item = my_objlist.add()
- my_item.name = _objd.name
- my_item.bselect = _objd.select
- my_item.otype = _objd.type
- removeobject = []
- for _udkobj in my_objlist:
- bfound_objv = False
- for _objd in bpy.context.scene.objects: #check if there no existing object from sense to remove it
- if _udkobj.name == _objd.name and _udkobj.otype == _objd.type:
- bfound_objv = True
- break
- if bfound_objv == False:
- removeobject.append(_udkobj)
- #print("remove check...")
- for _item in removeobject: #loop remove object from udk list object
- count = 0
- for _obj in my_objlist:
- if _obj.name == _item.name and _obj.otype == _item.otype:
- my_objlist.remove(count)
- break
- count += 1
- return{'FINISHED'}
-
+ """This will update the filter of the mesh and armature"""
+ bl_idname = "object.udkimportarmature"
+ bl_label = "Update Armature"
+
+ def execute(self, context):
+ my_objlist = bpy.context.scene.udkimportarmature_list
+ objectl = []
+ for objarm in bpy.context.scene.objects:#list and filter only mesh and armature
+ if objarm.type == 'ARMATURE':
+ objectl.append(objarm)
+ for _objd in objectl:#check if list has in udk list
+ bfound_obj = False
+ for _obj in my_objlist:
+ if _obj.name == _objd.name and _obj.otype == _objd.type:
+ _obj.bselect = _objd.select
+ bfound_obj = True
+ break
+ if bfound_obj == False:
+ #print("ADD ARMATURE...")
+ my_item = my_objlist.add()
+ my_item.name = _objd.name
+ my_item.bselect = _objd.select
+ my_item.otype = _objd.type
+ removeobject = []
+ for _udkobj in my_objlist:
+ bfound_objv = False
+ for _objd in bpy.context.scene.objects: #check if there no existing object from sense to remove it
+ if _udkobj.name == _objd.name and _udkobj.otype == _objd.type:
+ bfound_objv = True
+ break
+ if bfound_objv == False:
+ removeobject.append(_udkobj)
+ #print("remove check...")
+ for _item in removeobject: #loop remove object from udk list object
+ count = 0
+ for _obj in my_objlist:
+ if _obj.name == _item.name and _obj.otype == _item.otype:
+ my_objlist.remove(count)
+ break
+ count += 1
+ return{'FINISHED'}
+
class OBJECT_OT_UDKImportA(bpy.types.Operator):
- bl_idname = "object.udkimporta"
- bl_label = "Update Armature"
- __doc__ = "This will update the filter of the mesh and armature."
-
- def execute(self, context):
- for objd in bpy.data.objects:
- print("NAME:",objd.name," TYPE:",objd.type)
- if objd.type == "ARMATURE":
- print(dir(objd))
- print((objd.data.name))
- return{'FINISHED'}
-
+ """This will update the filter of the mesh and armature"""
+ bl_idname = "object.udkimporta"
+ bl_label = "Update Armature"
+
+ def execute(self, context):
+ for objd in bpy.data.objects:
+ print("NAME:",objd.name," TYPE:",objd.type)
+ if objd.type == "ARMATURE":
+ print(dir(objd))
+ print((objd.data.name))
+ return{'FINISHED'}
+
def menu_func(self, context):
self.layout.operator(IMPORT_OT_psk.bl_idname, text="Skeleton Mesh (.psk)")
self.layout.operator(IMPORT_OT_psa.bl_idname, text="Skeleton Anim (.psa)")
@@ -1260,7 +1275,7 @@ def menu_func(self, context):
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)
@@ -1270,4 +1285,4 @@ if __name__ == "__main__":
#note this only read the data and will not be place in the scene
#getInputFilename('C:\\blenderfiles\\BotA.psk')
-#getInputFilename('C:\\blenderfiles\\AA.PSK') \ No newline at end of file
+#getInputFilename('C:\\blenderfiles\\AA.PSK')