Thanks chrrox, I'm gonna try it right away and report back!
In the meantime, dumb question, why does your script have two matrices? I guess the second one is not really necessary since it's not used anyway..^^"
...
EDIT: I'm sorry, but I'm still getting mixed results. The overall shape of the skeleton looks right, but hierarchy looks kinda messed up. In this specific example file, the root index is already 0 (and oddly enough, it seems there are more than just one root?), but I don't see what's the problem:
Model File:
http://www.mediafire.com/download/98xb6 ... enaPSP.dat
This is a quick script I made to read the mesh (I invert Y/Z so the model stands up in MAX, Note that it is a very small model):
Code: Select all
clearListener()
fname = getOpenFileName \
caption:"3D Model" \
types:"3D Model (*.*)|*.*" \
historyCategory:"3D Model"
f = fopen fname "rb"
fn readMesh f vertexOffset vertexNum =
(
Vertices = #()
Normals = #()
TexCoords = #()
Faces = #()
fseek f vertexOffset #seek_set
for i = 1 to vertexNum do
(
w1 = readbyte f
w2 = readbyte f
w3 = readbyte f
w4 = readbyte f
w5 = readbyte f
w6 = readbyte f
w7 = readbyte f
w8 = readbyte f
u = (((readshort f #unsigned) as float) / 0x8000)
v = (((readshort f #unsigned) as float) / 0x8000) * (-1)
texcoord = point3 u v 0
--print texcoord
TexCoords[i] = texcoord
nx = ((readbyte f) as float) / 0x80
nz = ((readbyte f) as float) / 0x80
ny = ((readbyte f) as float) / 0x80
nw = ((readbyte f) as float) / 0x80
normal = point3 nx ny nz
Normals[i] = normal
x = readfloat f
z = readfloat f
y = readfloat f
vertex = point3 x y z
Vertices[i] = vertex
)
for i = 1 to (vertexNum - 2) by 1 do
(
x = i
if(mod i 2 == 0) then
(
y = i + 1
z = i + 2
)
else
(
y = i + 2
z = i + 1
)
face = point3 x y z
append Faces face
)
msh = mesh vertices:Vertices faces:Faces tverts:TexCoords
mmesh = msh.mesh
buildTVFaces mmesh
for i = 1 to mmesh.numfaces do
(setTVFace mmesh i (getFace mmesh i)
)
)
readMesh f 0x330a 0x5e2
readMesh f 0xd964 0x162
readMesh f 0x101be 0xb1
readMesh f 0x116bc 0x89
readMesh f 0x1275a 0xb7
readMesh f 0x13d00 0x139
fclose f
And this is the code I'm using to import the skeleton (so far with mixed results :/)
Code: Select all
clearListener()
struct Bone_Table_Data
(
BoneName,BoneParentID,BoneID
)
fn readFixedString bstream fixedLen =
(
local str = ""
for i = 1 to fixedLen do
(
str0 = ReadByte bstream #unsigned
if str0==0x0A do str+="\r\n"
if str0!=0xFD AND str0!=0xFC do str+= bit.intAsChar str0
)
str
)
fname = getOpenFileName \
caption:"3D Model" \
types:"3D Model (*.*)|*.*" \
historyCategory:"3D Model"
f = fopen fname "rb"
boneStart = 0x266a
BoneCount = 0x1f
fseek f boneStart #seek_set
BNArr = #()
for i = 1 to BoneCount Do (
boneSize0 = readlong f
boneSize1 = readlong f
nameSize = readbyte f
boneName = readFixedString f nameSize
print boneName
BoneParentID = readlong f
print BoneParentID
BoneParentID = BoneParentID
m11 = readfloat f; m12 = readfloat f; m13 = readfloat f; ignore = readfloat f
m21 = readfloat f; m22 = readfloat f; m23 = readfloat f; ignore = readfloat f
m31 = readfloat f; m32 = readfloat f; m33 = readfloat f; ignore = readfloat f
m41 = readfloat f; m42 = readfloat f; m43 = readfloat f; ignore = readfloat f
tfm = matrix3 [m11,m12,m13] [m21,m22,m23] [m31,m32,m33] [m41,m42,m43]
tfm = inverse tfm
ignore = readfloat f
tfm2 = matrix3 [m11,m12,m13] [m21,m22,m23] [m31,m32,m33] [m41,m42,m43]
newBone = bonesys.createbone \
tfm.row4 \
(tfm.row4 + 0.01 * (normalize tfm.row1)) \
(normalize tfm.row3)
newBone.name = BoneName
newBone.width = 0.1
newBone.height = 0.1
newBone.wirecolor = yellow
newbone.showlinks = true
newBone.setBoneEnable false 0
newBone.pos.controller = TCB_position ()
newBone.rotation.controller = TCB_rotation ()
append BNArr newBone
if (BoneParentID != 0) then
newBone.parent = BNArr[BoneParentID]
)
Thank you very much again:
~Sky