[Closed] Animation problems
Hello. I am new to the forums and pretty much new to using Maxscript so please be gentle.
I have a problem with getting the animation to work correctly. I am loading from a binary file into a struct I have created.
Struct ClsAnimationData (Name, ID, FrameCount, PerSLERP, BoneData, BoneFrame, BoneTM, Attribs, Events)
The data is read into this function
Function ReadANI FileName &ANI =
(
If FileName == Undefined Then Return False
Ani = ClsAnimationData()
Local FileHandle = 0
Local Version = 0
Local FrameCount = 0
Local BoneCount = 0
Local PathPresent = 0
Local EventCount = 0
Local I = 0
ANI.Name = GetFilenameFile FileName
FileHandle = FOpen FileName "rbS"
Version = ReadLong FileHandle #Unsigned
If Version != 10 Then
MessageBox "Invalid Version, attempting to continue anyway."
ANI.ID = ReadLong FileHandle #Unsigned
ANI.PerSLERP = ReadFloat FileHandle
FSeek FileHandle 32 #Seek_Cur
BoneCount = ReadLong FileHandle #Unsigned
FrameCount = ReadLong FileHandle #Unsigned
ANI.FrameCount = FrameCount
PathPresent = ReadLong FileHandle #Unsigned
If PathPresent != 0 Then FSeek FileHandle (12 * FrameCount) #Seek_Cur
ReadTM FileHandle &ANI BoneCount FrameCount
CreateArray &ANI.Attribs FrameCount
For I = 1 To FrameCount Do
(
ANI.Attribs[I] = ClsAttributes()
ANI.Attribs[I].Flags = ReadLong FileHandle #Unsigned
ANI.Attribs[I].SoundID = ReadLong FileHandle #Unsigned
ANI.Attribs[I].Frame = ReadFloat FileHandle
)
EventCount = ReadLong FileHandle #Unsigned
If EventCount != 0 Then
(
CreateArray &ANI.Events EventCount
For I = 1 To EventCount Do ANI.Events[I] = ReadVector3 FileHandle
)
)
Now here is where it goes awry. If a specific bone has animation for it, the TM will be undefined and it will cycle through the frames.
on btnAniImport pressed do
(
f = getOpenFileName caption: "Import Animation" types: "Animation (*.ani)|*.ani"
ReadANI f &Animation
For BoneID = 1 To Animation.BoneData.names.Count Do
(
obj = getnodebyname Animation.BoneData.names[BoneID]
if obj != undefined Then
(
If Animation.BoneTM[BoneID] == undefined Then
(
tm = Animation.BoneTM[BoneID]
For FrameID = 1 To Animation.FrameCount Do
(
rot = Animation.BoneFrame[BoneID][FrameID].Rotation
trans = Animation.BoneFrame[BoneID][FrameID].Translation
animate on
(
at time FrameID (obj.pos = trans; obj.rotation = rot)
)
)
)
else
(
if tm != undefined Then obj.transform = tm
)
)
)
)
The bones are loading exactly the way they should. Its when I load the animation that the bones get mangled and give weird results. Am I doing this right or is there an easier way to do this?
I’m having serious issues with the animations.
I have rotation and translations stored in an array for each frame. Some bones have parents and some do not. How do I animate this?
I’ve been stuck on this for weeks now. Please some one point me in the right direction.