08-10-2011, 03:43 PM
(This post was last modified: 08-10-2011, 03:43 PM by Lugana Rysniq.)
Code:
fseek f 0x28 #seek_set --
BoneCount = ReadBElong f
BoneTableOffset = ReadBElong f + 0x18
BoneTableOffset2 = ReadBElong f + 0x18
BoneTableOffset3 = ReadBElong f + 0x18
UnkCountt = ReadBElong f
MeshCount = ReadBElong f
fseek f BoneTableOffset#seek_set
struct BoneOffset (
BoneTOffset
)
Bone_Offset_array = #()
for i = 1 to BoneCount Do (
BoneTOffset = ReadBElong f + 0x18
append Bone_Offset_array (BoneOffset BoneTOffset:BoneTOffset)
)
print Bone_Offset_array
struct BoneData (
BoneID, BoneNameOffset, BoneName, BoneParentID
)
Bone_Data_array = #()
BoneID = -1
for k in Bone_Offset_array Do (
fseek f k.BoneTOffset#seek_set
BoneID += 1
BoneParentID = ReadBElong f
BoneNameOffset = ReadBElong f
BoneName = readstring f
append Bone_Data_array ( BoneData BoneID:BoneID BoneNameOffset:BoneNameOffset BoneName:BoneName BoneParentID:BoneParentID )
)F$?-\$vW&qiH
print Bone_Data_array
BNArr = #()
for i = 1 to BoneCount Do (
m11 = ReadBEfloat f; m12 = ReadBEfloat f; m13 = ReadBEfloat f; m14 = ReadBEfloat f
m21 = ReadBEfloat f; m22 = ReadBEfloat f; m23 = ReadBEfloat f; m24 = ReadBEfloat f
m31 = ReadBEfloat f; m32 = ReadBEfloat f; m33 = ReadBEfloat f; m34 = ReadBEfloat f
m41 = ReadBEfloat f; m42 = ReadBEfloat f; m43 = ReadBEfloat f; m44 = ReadBEfloat f
tfm = 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 = Bone_Data_array[i].BoneName
newBone.width = 0.01
newBone.height = 0.01
pos = [m14,m24,m34]
pos = pos * tfm
newBone.pos.x = (-1)*pos.x
newBone.pos.y = (-1)*pos.y
newBone.pos.z = (-1)*pos.z
newBone.setBoneEnable false 0
newBone.pos.controller = TCB_position ()
newBone.rotation.controller = TCB_rotation ()
if (Bone_Data_array[i].BoneParentID != -1) then
newBone.parent = BNArr[Bone_Data_array[i].BoneParentID+1]
BNArr[i] = newBone
)
fseek f 0x68#seek_set
for c = 1 to MeshCount Do (
Vert_array = #() --define arrays for verts, normals, UV and Faces
Normal_array = #()
UV_array = #()
Face_array = #()
offsetstart = (ReadBElong f) + 0x18
tablestart = ftell f
fseek f offsetstart#seek_set
Count1 = ReadBElong f
FaceCount = ReadBElong f
Count3 = ReadBElong f
VertCount = ReadBElong f
VertSize = ReadBElong f
Count6 = ReadBElong f
Count7 = ReadBElong f
Count8 = ReadBElong f
Count9 = ReadBElong f
Count10 = ReadBElong f
Count11 = ReadBElong f
FaceStart = ftell f
VerStart = (FaceCount * 2) + FaceStart
StartDirection = -1
f1 = (ReadBEword f) + 1
f2 = (ReadBEword f) + 1
FaceDirection = StartDirection
Do (
f3 = (ReadBEword f)
if (f3==0xFFFF) then (
f1 = (ReadBEword f) + 1
f2 = (ReadBEword f) + 1
FaceDirection = StartDirection
) else (
f3 += 1
FaceDirection *= -1
if (f1!=f2)AND(f2!=f3)AND(f3!=f1) then (
if FaceDirection > 0 then append Face_array [f1,f2,f3]
else append Face_array [f1,f3,f2]
)
f1 = f2
f2 = f3
)
) while ((ftell f) != (VerStart + 2))
fseek f VerStart#seek_set
deleteitem Face_array Face_array.count
test = readshort f
if test != 0x0000 Do (
fseek f -2 #seek_cur
)
for v = 1 to VertCount Do (
vx = ReadBEfloat f --read xyz coordinates
vy = ReadBEfloat f
vz = ReadBEfloat f
fseek f 0x8 #seek_cur
nx = ReadBElong f --read Normal ??
ny = ReadBElong f
nz = ReadBElong f
tu = ReadBEHalfFloat f --read UV float value
tv = ReadBEHalfFloat f * -1
fseek f 0x8 #seek_cur
append Vert_array [vx,vy,vz] --save verts to Vert_array
append Normal_array [nx,ny,nz] --save normals to Normal_array
append UV_array [tu,tv,0] --save UVs to UV_array
)
fseek f tablestart#seek_set
msh = mesh vertices:Vert_array faces:Face_array --build mesh
msh.numTVerts = UV_array.count
buildTVFaces msh
for j = 1 to UV_array.count do setTVert msh j UV_array[j]
for j = 1 to Face_array.count do setTVFace msh j Face_array[j]
for j = 1 to Normal_array.count do setNormal msh j Normal_array[j]
)
I Get this but i jsut an unexpeced End-of-file when i try to run it in max