Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightnet committed Apr 27, 2011
1 parent 23fc6a3 commit b39de23
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions io_import_scene_unreal_psk.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@
from string import *
from struct import *
from math import *

#from bpy.props import *

from bpy.props import *
import mathutils

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

Expand Down Expand Up @@ -333,11 +336,11 @@ def printlog(strdata):
#w,x,y,z
if (counter == 0):#main parent
print("no parent bone")
createbone.bindmat = mathutils.Quaternion((indata[7],indata[4],indata[5],indata[6]))
createbone.bindmat = mathutils.Quaternion((indata[7],indata[4],indata[5],indata[6]))#default
#createbone.bindmat = mathutils.Quaternion((indata[7],-indata[4],-indata[5],-indata[6]))
else:#parent
print("parent bone")
createbone.bindmat = mathutils.Quaternion((indata[7],-indata[4],-indata[5],-indata[6]))
createbone.bindmat = mathutils.Quaternion((indata[7],-indata[4],-indata[5],-indata[6]))#default
#createbone.bindmat = mathutils.Quaternion((indata[7],indata[4],indata[5],indata[6]))

md5_bones.append(createbone)
Expand Down Expand Up @@ -421,20 +424,23 @@ def printlog(strdata):
bpy.ops.object.mode_set(mode='EDIT')
newbone = ob_new.data.edit_bones.new(bone.name)
#parent the bone
print("DRI:",dir(newbone))
parentbone = None
print("bone name:",bone.name)
#note bone location is set in the real space or global not local
bonesize = bpy.types.Scene.unrealbonesize
if bone.name != bone.parent:

pos_x = bone.bindpos[0]
pos_y = bone.bindpos[1]
pos_z = bone.bindpos[2]
#print( "LINKING:" , bone.parent ,"j")
parentbone = ob_new.data.edit_bones[bone.parent]
newbone.parent = parentbone

rotmatrix = bone.bindmat.to_matrix().to_4x4().to_3x3() # XXX, redundant matrix conversion?
newbone.transform(bone.bindmat.to_matrix().to_4x4(),True,True)
#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)
Expand All @@ -444,24 +450,28 @@ def printlog(strdata):
#pos_x = set_position.x
#pos_y = set_position.y
#pos_z = set_position.z



newbone.head.x = parentbone.head.x + pos_x
newbone.head.y = parentbone.head.y + pos_y
newbone.head.z = parentbone.head.z + pos_z
#print("head:",newbone.head)
newbone.tail.x = parentbone.head.x + (pos_x + bonesize * rotmatrix[1][0])
newbone.tail.y = parentbone.head.y + (pos_y + bonesize * rotmatrix[1][1])
newbone.tail.z = parentbone.head.z + (pos_z + bonesize * rotmatrix[1][2])
#newbone.roll = fixRoll(newbone)
else:
#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.transform(bone.bindmat.to_matrix(),True,True)
newbone.head.x = bone.bindpos[0]
newbone.head.y = bone.bindpos[1]
newbone.head.z = bone.bindpos[2]
newbone.tail.x = bone.bindpos[0] + bonesize * rotmatrix[1][0]
newbone.tail.y = bone.bindpos[1] + bonesize * rotmatrix[1][1]
newbone.tail.z = bone.bindpos[2] + bonesize * rotmatrix[1][2]
#newbone.roll = fixRoll(newbone)
#print("no parent")

bpy.context.scene.update()
Expand Down Expand Up @@ -738,8 +748,6 @@ def getInputFilename(self,filename,importmesh,importbone,bDebugLogPSK,importmult
else:
pskimport(filename,importmesh,importbone,bDebugLogPSK,importmultiuvtextures)

from bpy.props import *

class IMPORT_OT_psk(bpy.types.Operator):
'''Load a skeleton mesh psk File'''
bl_idname = "import_scene.psk"
Expand All @@ -755,8 +763,10 @@ class IMPORT_OT_psk(bpy.types.Operator):
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)
unrealbonesize = FloatProperty( name="Bone Length", description="Bone Length from head to tail distance.", default=1,min=0.001,max=1000)

def execute(self, context):
bpy.types.Scene.unrealbonesize = self.unrealbonesize
getInputFilename(self,self.filepath,self.importmesh,self.importbone,self.bDebugLogPSK,self.importmultiuvtextures)
return {'FINISHED'}

Expand Down

0 comments on commit b39de23

Please sign in to comment.