Message 1 of 3
Help with making a importer?

Not applicable
08-05-2021
06:58 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello i'm new to 3ds max more from blender, I was looking to take a old export code i have for a game and make a importer from it but i'm not really sure were to start. If someone can point me in the right way thats all i would need right now.
--------------------------------------------------------------------------------
-- FRM Exporter
--------------------------------------------------------------------------------
global g_object_bone_table = #()
global g_AnimBoneTable = #()
global g_BipedTable = #()
global g_DumpedBoneTable = #()
global g_GCBoneNameTable = #( "Pelvis", "L Thigh", "L Calf", "L Foot", "R Thigh", "R Calf", "R Foot", "Spine", "Head", "L UpperArm", "L Forearm", "L Hand", "R UpperArm", "R Forearm", "R Hand", "Bone01", "Bone02", "Bone03", "Bone04","Bone05","Bone06","Bone07" ,"Bone08" ,"Bone09" ,"Bone10" ,"Bone11" ,"Bone12" ,"Bone13" ,"Bone14" ,"Bone15" ,"Bone16" ,"Bone17" ,"Bone18" ,"Bone19" ,"Bone20" ,"Bone21" ,"Bone22" ,"Bone23" ,"Bone24" ,"Bone25","Bone26","Bone27","Bone28" )
struct MyAnimBone
(
name,
m_objectID,
m_BoneID,
m_matWorldRot,
m_ParentObjectID,
m_ParentBoneID
)
fn ConvertNewBoneIndex2OldBoneIndex new_id =
(
for i = 1 to g_BipedTable.count do
(
if ( findString g_BipedTable[i].name g_GCBoneNameTable[new_id] != undefined ) then
(
return i
)
)
return undefined
)
fn GetObjectsByClass cl =
(
varSetSameClass = #()
for o in objects do
(
if classOf o == cl then
(
append varSetSameClass o
)
)
varSetSameClass
)
fn FRM_InitBipedTable =
(
g_BipedTable = #()
for o in objects do
(
if classOf o == biped_object then
(
append g_BipedTable o
)
else if LowerCase (substring o.name 1 4) == "bone" then
(
append g_BipedTable o
)
)
)
fn FRM_InitObjBonTable =
(
g_object_bone_table = #()
id = 1
for o in objects do
(
if classOf o == biped_object then
(
append g_object_bone_table id
id += 1
)
else if LowerCase (substring o.name 1 4) == "bone" then
(
append g_object_bone_table id
id += 1
)
else
(
append g_object_bone_table undefined
)
)
)
fn FRM_GetBoneIndex o_id =
(
if o_id == undefined then
return undefined
return g_object_bone_table[o_id]
)
fn FRM_GetObjectIndex obj =
(
for i = 1 to objects.count do
(
if obj == objects[i] then
(
return i
)
)
return undefined
)
fn DumpObjects objclass =
(
origbiped = #()
snapset = #()
for i in g_BipedTable do
(
append origbiped i
b = snapshot i name:(i.name as string + "_snap")
b.parent = undefined
b.transform = i.transform
b.position.track = bezier_position()
b.rotation.track = bezier_rotation()
append snapset b
)
for i = 1 to snapset.count do
(
try
(
snapset[i].parent = execute ("$'" + origbiped[i].parent.name + "_snap'")
)
catch
(
-- empty
)
)
animate on
undo off
for t = animationRange.start to animationRange.end by 1 do at time t
(
for i = 1 to Snapset.count do
(
snapset[i].transform = origbiped[i].transform
)
)
return snapset
)
fn FRM_SetBoneInfo obj_idx bon_idx =
(
o_id = FRM_GetObjectIndex objects[obj_idx].parent
b_id = FRM_GetBoneIndex o_id
if b_id == undefined then
b_id = 0
if o_id == undefined then
o_id = 0
matWorldRot = objects[obj_idx].transform
matWorldRot.row4 = point3 0 0 0
return MyAnimBone objects[obj_idx].name obj_idx bon_idx matWorldRot o_id b_id
)
fn Track iFrame boneID =
(
p = point3 0 0 0
s = point3 0 0 0
matAni = matrix3 1
multQuat = quat 0 0 0 1
rotKey = g_DumpedBoneTable[boneID].rotation.controller.keys
multQuat = rotKey[iFrame].value * (inverse rotKey[1].value)
multQuat.x = -multQuat.x
multQuat.y = -multQuat.y
multQuat.z = -multQuat.z
rotate matAni multQuat
return matAni
)
fn GetAnimMatForNewFRM iFrame bone_idx parentWorldRot =
(
matFrm = matrix3 1
matWorldRot = g_DumpedBoneTable[bone_idx].transform
matWorldRot.row4 = point3 0 0 0
matWorldRotInv = inverse matWorldRot
matLocal = GetLocalTM g_DumpedBoneTable[bone_idx]
if ( bone_idx == undefined ) then
(
bone_idx = 1
)
matAni = Track iFrame bone_idx
matTM = matLocal * matAni
matTM.row4 = matAni.row4
matFrm = matWorldRotInv * matTM * parentWorldRot
matFrm.row4 = point3 0 0 0
return matFrm
)
fn GetRootPos iFrame =
(
return g_DumpedBoneTable[1].pos.keys[iFrame].value * AUTO_SIZE_SCALE
)
fn FRM_InitBoneTable =
(
g_AnimBoneTable = #()
o_index = 0
b_index = 0
for o in objects do
(
o_index = o_index + 1
if classOf o == biped_object then
(
b_index = b_index + 1
append g_AnimBoneTable (FRM_SetBoneInfo o_index b_index)
)
else if LowerCase (substring o.name 1 4) == "bone" then
(
b_index = b_index + 1
append g_AnimBoneTable (FRM_SetBoneInfo o_index b_index)
)
)
)
fn FRM_SaveNewFile strFileName =
(
fileStream = fopen strFilename "wb"
WriteString fileStream "Frm Ver 1.1"
WriteShort fileStream ((int)animationRange.end) -- Writes the number of animation frames.
WriteShort fileStream g_DumpedBoneTable.count -- Write the number of bones.
-- The first frame is for model reference, so one is excluded from the number.
PrevRootPos = GetRootPos 1
for iFrame = 2 to ((int)animationRange.end + 1) do
(
WriteByte fileStream 0
RootPos = GetRootPos iFrame
PlusX = (RootPos.x - PrevRootPos.x)
PosY = RootPos.z - (g_BipedTable[1].transform.row4.z * AUTO_SIZE_SCALE)
PrevRootPos = RootPos
WriteFloat fileStream PlusX -- Record the PlusX value.
WriteFloat fileStream PosY -- Record the PosY value.
for i = 1 to g_DumpedBoneTable.count do
(
parentBoneID = g_AnimBoneTable[i].m_ParentBoneID
if ( parentBoneID == 0 ) then
(
matWorldRot = matrix3 1
matFRM = GetAnimMatForNewFRM iFrame i matWorldRot
)
else
(
matFRM = GetAnimMatForNewFRM iFrame i (g_AnimBoneTable[parentBoneID].m_matWorldRot)
)
WriteFloat fileStream matFRM.row1.x
WriteFloat fileStream matFRM.row1.z
WriteFloat fileStream matFRM.row1.y
WriteFloat fileStream 0.0
WriteFloat fileStream matFRM.row3.x
WriteFloat fileStream matFRM.row3.z
WriteFloat fileStream matFRM.row3.y
WriteFloat fileStream 0.0
WriteFloat fileStream matFRM.row2.x
WriteFloat fileStream matFRM.row2.z
WriteFloat fileStream matFRM.row2.y
WriteFloat fileStream 0.0
WriteFloat fileStream matFRM.row4.x
WriteFloat fileStream matFRM.row4.z
WriteFloat fileStream matFRM.row4.y
WriteFloat fileStream 1.0
)
)
PrevRootPos = GetRootPos 1
for iFrame = 2 to ((int)animationRange.end + 1) do
(
RootPos = GetRootPos iFrame
posZ = (RootPos.y - PrevRootPos.y)
WriteFloat fileStream posZ
)
fclose fileStream
)
--------------------------------------------------------------------------------
-- Export functions
--------------------------------------------------------------------------------
fn ExportFRMNew =
(
if ( strFileName = getSaveFileName filename:"default.frm" types:"FRM(*.frm)|*.frm|All|*.*|" ) != undefined then
(
sliderTime = 0f -- Forces the slide's frame to move to the 0th position.
FRM_InitObjBonTable()
FRM_InitBipedTable()
FRM_InitBoneTable()
g_DumpedBoneTable = DumpObjects biped_object
FRM_SaveNewFile strFileName
delete g_DumpedBoneTable
messageBox "FRM (monster) creation complete."
return true
)
return false
)
--------------------------------------------------------------------------------
-- utility definition
--------------------------------------------------------------------------------
utility GCExporter "GC Exporter ver 1.6"
(
-- picture file
bitmap bmp fileName:"GCExporter.bmp"
-- button definition
button btnFRMNew "FRM (Monster)" align:#center width:120 tooltip:"Creates a FRM motion with a new model structure applied."
-- When the 'FRM (Monster)' button is pressed
on btnFRMNew pressed do
(
ExportFRMNew()
)
)