If someone wants to help me figure out the weighting ill add it to the max script.
Code: Select all
if (heapSize < 20000000) then
heapSize = 200000000 -- allow ~ 40 MB instead of just 7.5 MB. Prevents "Runtime Error: Out of scripter memory"
fname = GetOpenFileName caption:"Open Granado Espada Model File" types:"Granado Espada Model File(*.lma)|*.lma"
f = fopen fname "rb" --open file in read only format
fn PrintOffset Var =
(
local Var = Var
print ("This is the offset 0x" + (bit.intAsHex Var) as string)
Var
)
fn PrintCount Var =
(
local Var = Var
print ("This is the Count 0x" + (bit.intAsHex Var) as string)
Var
)
fn Readword fstream = (
return readshort fstream #unsigned
)
fn ReadFixedString bstream fixedLen =
(
local str = ""
for i = 1 to fixedLen do
(
str += bit.intAsChar (ReadByte bstream #unsigned)
)
str
)
struct Mesh_Info_Struct
(
Mesh_Name,vertstart,vertend,vertcount,facecount
)
struct Offset_Info_Struct
(
Section_Start,Vert_Start,Face_Start,vertsize
)
total_size = getFileSize fname
print total_size
idstring = readlong f
id1 = readbyte f#unsigned
id2 = readbyte f#unsigned
id3 = readbyte f#unsigned
Type_0_offset_array =#()
Type_1_offset_array =#()
Type_2_offset_array =#()
Type_3_offset_array =#()
Type_3_2_offset_array =#()
Type_4_offset_array =#()
Type_5_offset_array =#()
Type_6_offset_array =#()
Type_7_offset_array =#()
Mesh_Name_array =#()
do (
type = readlong f
size = readlong f
type2 = readlong f
print type
print size
print type2
printoffset (ftell f)
if type == 0 do (
append Type_0_offset_array (ftell f)
)
if type == 1 do (
append Type_1_offset_array (ftell f)
)
if type == 2 do (
append Type_2_offset_array (ftell f)
)
if type == 3 do (
if type2 == 2 do (
append Type_3_offset_array (ftell f)
)
if type2 == 10000 do (
append Type_3_2_offset_array (ftell f)
)
)
if type == 4 do (
append Type_4_offset_array (ftell f)
)
if type == 5 do (
append Type_6_offset_array (ftell f)
)
if type == 6 do (
append Type_6_offset_array (ftell f)
)
if type == 7 do (
append Type_7_offset_array (ftell f)
)
fseek f size #seek_cur
)while (ftell f) != total_size
print Type_0_offset_array.count
print Type_1_offset_array.count
print Type_2_offset_array.count
print Type_3_offset_array.count
print Type_4_offset_array.count
print Type_5_offset_array.count
print Type_6_offset_array.count
print Type_7_offset_array.count
for a = 1 to Type_0_offset_array.count do (
fseek f Type_0_offset_array[a]#seek_set
bone_name = readstring f
print bone_name
if isvalidnode (getNodeByName bone_name) != true then (
fseek f (0x28 - (bone_name.count + 1))#seek_cur
bone_parent = readstring f
if bone_parent != "" do (
fseek f (0x28 - (bone_parent.count + 1))#seek_cur
)
if bone_parent == "" do (
fseek f 0x27 #seek_cur
)
print (getNodeByName bone_name)
if (getNodeByName bone_name) != "undefined" do (
fseek f 0x28#seek_cur
m11 = readfloat f; m12 = readfloat f; m13 = readfloat f; m14 = readfloat f
m21 = readfloat f; m22 = readfloat f; m23 = readfloat f; m24 = readfloat f
m31 = readfloat f; m32 = readfloat f; m33 = readfloat f; m34 = readfloat f
m41 = readfloat f; m42 = readfloat f; m43 = readfloat f; m44 = readfloat 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_name
newBone.width = 0.3
newBone.height = 0.3
newBone.transform = inverse tfm
newBone.wirecolor = yellow
newbone.showlinks = true
newBone.setBoneEnable false 0
newBone.pos.controller = TCB_position ()
newBone.rotation.controller = TCB_rotation ()
newBone.name = bone_name
newBone.width = 0.3
newBone.height = 0.3
newBone.setBoneEnable false 0
newBone.pos.controller = TCB_position ()
newBone.rotation.controller = TCB_rotation ()
if (bone_parent != "") then (
newBone.parent = getNodeByName bone_parent
)
)
)
)
for a = 1 to Type_7_offset_array.count do (
fseek f Type_7_offset_array[a]#seek_set
Mesh_name = readstring f
fseek f (0x28 - (Mesh_name.count + 1))#seek_cur
if Mesh_name != "env_normal" do (
append Mesh_Name_array Mesh_name
)
print Mesh_name
print "-----------------"
)
for a = 1 to Type_4_offset_array.count do (
fseek f Type_4_offset_array[a]#seek_set
fseek f -8#seek_cur
tsize = readlong f
t2 = readlong f
unk01 = readlong f
t4_count = (tsize / 9)
for b = 1 to t4_count do (
type = readbyte f#unsigned
bone_id = readlong f
weight = readfloat f
printoffset type
print bone_id
print weight
print "----------"
)
printoffset (ftell f)
)
for a = 1 to Type_3_offset_array.count do (
fseek f Type_3_offset_array[a]#seek_set
unk01 = readlong f
unk02 = readlong f
unk03 = readlong f
unk04 = readlong f
Mesh_Count = readlong f
unk06 = readlong f
for c = 1 to Mesh_Count do (
unk07 = readlong f
Vert_array = #() --define arrays for verts, normals, UV and Faces
Normal_array = #()
UV_array = #()
Face_array = #()
Fcount = (readlong f) / 3
Vcount = readlong f
for i = 1 to Vcount do ( --* number of verts count
vx = readfloat f --read xyz coordinates
vy = readfloat f
vz = readfloat f
append Vert_array [vx,vy,vz] --save verts to Vert_array
--since UV in Max are in point3 format, so we add 0 for z value
nx = readlong f --read Normal ??
ny = readlong f
nz = readlong f
--append Normal_array [nx,ny,nz] --save normals to Normal_array
tu = readfloat f --read UV float value
tv = (readfloat f) * -1
append UV_array [tu,tv,0] --save UVs to UV_array
b1 = readlong f
)
for k = 1 to Fcount do (
f1 = (readlong f) + 1 --read face indices, games are start form 0, but Max start from 1
f2 = (readlong f) + 1 --so we add 1 to each index
f3 = (readlong f) + 1
append Face_array [f1,f2,f3] --save faces to Face_array
)
msh = mesh vertices:Vert_array faces:Face_array --build mesh
msh.numTVerts = UV_array.count
buildTVFaces msh
msh.name = Mesh_Name_array[a]
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]
)
)
for a = 1 to Type_3_2_offset_array.count do (
fseek f Type_3_2_offset_array[a]#seek_set
Vert_array = #() --define arrays for verts, normals, UV and Faces
Normal_array = #()
UV_array = #()
Face_array = #()
unk01 = readlong f
unk02 = readlong f
unk03 = readlong f
unk04 = readlong f
unk05 = readlong f
unk06 = readbyte f
Mesh_Name = readstring f
fseek f (0x107 - (Mesh_name.count + 1))#seek_cur
Fcount = (readlong f) / 3
Vcount = readlong f
for i = 1 to Vcount do ( --* number of verts count
vx = readfloat f --read xyz coordinates
vy = readfloat f
vz = readfloat f
append Vert_array [vx,vy,vz] --save verts to Vert_array
--since UV in Max are in point3 format, so we add 0 for z value
nx = readlong f --read Normal ??
ny = readlong f
nz = readlong f
--append Normal_array [nx,ny,nz] --save normals to Normal_array
tu = readfloat f --read UV float value
tv = (readfloat f) * -1
append UV_array [tu,tv,0] --save UVs to UV_array
b1 = readfloat f
b2 = readfloat f
b3 = readfloat f
)
for k = 1 to Fcount do (
f1 = (readlong f) + 1 --read face indices, games are start form 0, but Max start from 1
f2 = (readlong f) + 1 --so we add 1 to each index
f3 = (readlong f) + 1
append Face_array [f1,f2,f3] --save faces to Face_array
)
msh = mesh vertices:Vert_array faces:Face_array --build mesh
msh.numTVerts = UV_array.count
buildTVFaces msh
msh.name = Mesh_Name
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]
)
fclose f


