Jetboom Anim API problem



  • Hi people, I have a little problem with the Animations API made by Jetboom. I know it is an old API, but I got it from this GitHub:

    https://github.com/JetBoom/animationsapi

    That was updated the last November 6, so it’s not that old. I would ask for help in Facepunch forums, but most people there don’t have an idea of how this works, and Jetboom probably won’t see my question there. I saw these forums are pretty active so I decided to ask here.

    It’s not anything complex. I was experimenting a bit with the API, and managed to make it work (actually it’s pretty easy to use). However, all animations I make seem to ignore the Interpolation I set. They always play as INTERP_COSINE, and make that stop at the end of every frame. I can’t find a way to make them play at a constant speed without slowing down at start and end of the frame. Any idea of what could be happening? This is an example anim:

    RegisterLuaAnimation('Test1', {
    		FrameData = {
    			{
    				BoneInfo = {
    					['ValveBiped.Bip01_R_UpperArm'] = {
    						RU = 15.364600194339,
    						RR = 13.448000165481
    					},
    					['ValveBiped.Bip01_R_Forearm'] = {
    						RU = -26.037841757273,
    						RR = 10.651728069841
    					}
    				},
    				FrameRate = 2
    			},
    			--
    			-- More frames here
    			--
    		},
    		Type = TYPE_GESTURE,
    		Interpolation = INTERP_CUBIC
    	})
    


  • Hi people, I have a little problem with the Animations API made by Jetboom. I know it is an old API, but I got it from this GitHub:

    https://github.com/JetBoom/animationsapi

    That was updated the last November 6, so it’s not that old. I would ask for help in Facepunch forums, but most people there don’t have an idea of how this works, and Jetboom probably won’t see my question there. I saw these forums are pretty active so I decided to ask here.

    It’s not anything complex. I was experimenting a bit with the API, and managed to make it work (actually it’s pretty easy to use). However, all animations I make seem to ignore the Interpolation I set. They always play as INTERP_COSINE, and make that stop at the end of every frame. I can’t find a way to make them play at a constant speed without slowing down at start and end of the frame. Any idea of what could be happening? This is an example anim:

    RegisterLuaAnimation('Test1', {
    		FrameData = {
    			{
    				BoneInfo = {
    					['ValveBiped.Bip01_R_UpperArm'] = {
    						RU = 15.364600194339,
    						RR = 13.448000165481
    					},
    					['ValveBiped.Bip01_R_Forearm'] = {
    						RU = -26.037841757273,
    						RR = 10.651728069841
    					}
    				},
    				FrameRate = 2
    			},
    			--
    			-- More frames here
    			--
    		},
    		Type = TYPE_GESTURE,
    		Interpolation = INTERP_CUBIC
    	})
    

  • Administrators

    Cubic isn’t a linear interpolation. That would be INTERP_LINEAR.
    There’s also RestartFrame which lets you make loops. ex: RestartFrame = 2 would make it loop back to the start of frame 2 when the animation runs out of frames.



    • snip -

    Apparently, another addon was overriding the API (probably with an older version). I can force the script to execute all animations with INTERP_LINEAR or INTERP_CUBIC if I add a line in cl_boneanimlib. However, it doesn’t seem to be reading the interpolation from the table. No matter which one I set, it always run with INTERP_COSINE.

    Also, if I force the script to run in INTERP_LINEAR, it always interpolate from the first frame to the current frame (not between the current and the next). I’ll take a look at the rest of the file and see if I can fix it somehow.



  • I found the problem. In cl_boneanimlib, function “ResetLuaAnimation”, line 245:

    self.LuaAnimations[sAnimation] = {Frame = animtable.StartFrame or 1, FrameDelta = animtable.Type == TYPE_POSTURE and not animtable.TimeToArrive and 1 or 0, FrameData = animtable.FrameData,
    		TimeScale = fTimeScale or animtable.TimeScale or 1, Type = animtable.Type, RestartFrame = animtable.RestartFrame, TimeToArrive = animtable.TimeToArrive, Callback = animtable.Callback,
    		ShouldPlay = animtable.ShouldPlay, PreCallback = animtable.PreCallback, Power = fPower or animtable.Power or 1, DieTime = fDieTime or animtable.DieTime, Group = animtable.Group,
    		UseReferencePose = animtable.UseReferencePose}
    

    As you can see, when it copies the table from Animations[ ] to self.LuaAnimations[ ], it doesn’t copy the “Interpolation” field. That’s why when “DoCurrentFrame” is executed, tGestureTable.Interpolation is always “nil”. It can be easely fixed by adding “Interpolation = animtable.Interpolation” at the end of the table above.

    Theres another problem tho. As I said before, the Linear Interpolation doesn’t work well. It always uses the starting frame as the first frame of the interpolation. I’ll see if I can fix it.



  • Ok I fixed the Linear Interpolation. In cl_boneanimlib, DoCurrentFrame, line 128, replaced that block with this:

    if iInterp == INTERP_LINEAR or bNoInterp then
    				local bi1 = GetFrameBoneInfo(pl, tGestureTable, iCurFrame - 1, iBoneID)
    				mBoneMatrix:Translate(LinearInterpolation(bi1.MU * vUp + bi1.MR * vRight + bi1.MF * vForward, tBoneInfo.MU * vUp + tBoneInfo.MR * vRight + tBoneInfo.MF * vForward, fFrameDelta) * fPower)
    				mBoneMatrix:Rotate(LinearInterpolation(Angle(bi1.RR, bi1.RU, bi1.RF), Angle(tBoneInfo.RR, tBoneInfo.RU, tBoneInfo.RF), fFrameDelta) * fPower)
    

    This is the LinearInterpolation function. It’s just a simplified cosine.

    local function LinearInterpolation(y1,y2,mu)
       return(y1*(1-mu)+y2*mu)
    end
    

    Now everything seem to work fine. Perhaps someone find this useful. If you’re still updating the GitHub, perhaps you should take a look at these changes and and commit them if needed.


  • Administrators

    I’ve updated it on github.



  • Thanks. Sorry to bother you again but, in the same file, line 250, that table assignment should be replaced with this:

    self.LuaAnimations[sAnimation] = {Frame = animtable.StartFrame or 1, FrameDelta = animtable.Type == TYPE_POSTURE and not animtable.TimeToArrive and 1 or 0, FrameData = animtable.FrameData,
    		TimeScale = fTimeScale or animtable.TimeScale or 1, Type = animtable.Type, RestartFrame = animtable.RestartFrame, TimeToArrive = animtable.TimeToArrive, Callback = animtable.Callback,
    		ShouldPlay = animtable.ShouldPlay, PreCallback = animtable.PreCallback, Power = fPower or animtable.Power or 1, DieTime = fDieTime or animtable.DieTime, Group = animtable.Group,
    		UseReferencePose = animtable.UseReferencePose, Interpolation = animtable.Interpolation}
    

    With the “Interpolation = animtable.Interpolation” at the end. Otherwise, it will always execute animations with a COSINE interpolation.


Log in to reply
 

5
Online

10898
Users

15223
Topics

296916
Posts

Looks like your connection to NoXiousNet was lost, please wait while we try to reconnect.