Help to get Access to Bezier Keyframe Interpolation Settings

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
Rai López
Posts: 2228
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Help to get Access to Bezier Keyframe Interpolation Settings

Post by Rai López »

Hi everyone, maybe only devs could say but, having the info we have at the moment by the Scripting Interface documents, is someone (with more technical/structural knowledge) capable to easily figure out how to deal with the new functions concerning keyframe Bezier interpolation data? In SI docs we find something like this:
  • Code: Select all

    class InterpSetting {
    	real BezierOutAngle(int32 component);
    	void SetBezierOutAngle(int32 component, real angle);
    	
    	real BezierOutPercentage(int32 component);
    	void SetBezierOutPercentage(int32 component, real percent);
    
    	int32	interpMode;
    	...
    };
  • Code: Select all

    class AnimChannel {
    	void SetKeyInterp(int32 when, InterpSetting &interp);
    	void SetKeyInterpByID(int32 id, InterpSetting &interp);
    	void GetKeyInterp(int32 when, InterpSetting &interp);
    	void GetKeyInterpByID(int32 id, InterpSetting &interp);
    
    	...
    };

So we count now with a new class called "InterpSetting" with some functions on it that seems designed to work in conjunction with the old "AnimChannel" ones (?), but I'm simply not able to figure out the way to combine them to simply get, for example, the "BezierOutAngle" of certain Bezier key. My logic says me that the new class should be "child" or intended to communicate with keyframes themselves, but it's like if there be something different on this or some elements/arguments that I don't get to place or even understand. And yeah, I'm afraid it will be like an embarrassing trifle once revealed, but I've been trial & erroring during hours and (although I kinda like that) I think it's already driving me (more) crazy, so any help on this would be greatly appreciated. Plus... well, it's for a good cause :)

Greetings & thanks in advance,
Ramón López.
...
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Re: Help to get Access to Bezier Keyframe Interpolation Sett

Post by Genete »

Hi Ramón,
I'll try to write a code to use those functions.
I'm a bit rusted with lua and I'm not testing the code I write here but you can fix it (read it as pseudocode):

Code: Select all

/* Code to get the bezier out angle */
/*Define a AnimChannel*/
AnimChannel mychan;
/* Grab the layer's channel*/
mychan=...
/*Grab the Interpolation settings at a certain frame (frame1)*/
/*Or by a certain ID*/
InterpSetting mysetting;
mychan.GetKeyInterp(frame1, mysetting);
/* Notice that we put the variable 'mysetting' but it is passed in fact by reference */
*/ so it can be modified in the called function*/

/* Check if the channel is bezier type/*
if(mysetting.interpMode==INTERP_BEZIER) 
{
    return (mysetting.BezierOutAngle(mycomponent);
}
else
{
/* bye bye*/ return nil; /* or do whatever */
}
And the question is: What does 'component' mean? The only way to know what does it mean is to use the SetBezierOutAngle functions with different component values and observe the result on the keyframe.

About percentage I think it is a way to evaluate the tangent's length. So tangent length should be something like:


tan(angle)=distance*percentage/length
so
length=distance*percentage/tan(angle)

where:
angle is the tangent angle (be careful with the angle's zero and relative angle counting)
distance is the number of frames between the previous(next) frame to the current one.
percentage is a [0,1) value that scales down the tangent length. This way the tangent's horizontal projection never would be larger than the distance to the previous(next) keyframe.

This makes me think that 'component' could be something to convert the 'distance' to a real value in order to correctly build the bezier curve. But it is weird that it is a int32 ... :shock:

I hope it gives you some more clues. :D
Cheers
-G
User avatar
Rai López
Posts: 2228
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: Help to get Access to Bezier Keyframe Interpolation Sett

Post by Rai López »

Genete, first of all thank you very much for take the time to help, unfortunately I think I still have the same problem as before, which basically is... I'm simply not able to get access to ANY of the "InterpSetting" class functions in any way that I can think :(

I've been using a Layer Script for quick testing which, at this point, looks as follows:

Code: Select all

-- Bezier functions access Layer Script test (perform an UNDO for a quick RELOAD if you make any change here)

function LayerScript(moho)
	local frame = moho.frame
	local layer = moho.layer
	local animChan = layer.fTranslation
	local keyID = animChan:GetClosestKeyID(frame)
	local keyIntMode = animChan:GetKeyInterpMode(frame)

	---[[Ensure key is Bezier (just fot quick testing)
	if moho.layer.fTranslation:HasKey(frame) and keyIntMode ~= MOHO.INTERP_BEZIER then
		animChan:SetKeyInterp(frame, MOHO.INTERP_BEZIER, 0, 0)
	end
	--]]

	if keyIntMode == MOHO.INTERP_BEZIER then
		local mySetting = animChan:BezierOutAngle(1) -- try to access from AnimChannel doesn't work.
		--local mySetting = layer:BezierOutAngle(1)  -- try to access from moho.layer doesn't work (which has sense...)
		--local mySetting = LM.InterpSetting:new_local() -- Any other stupid try neither worked...
		--local mySetting = ???

		local keyInt = animChan:GetKeyInterp(frame, mySetting)
		print(tostring(keyInt))
	end

	--[[Other referencies...
		local m = animVal:GetKeyInterpMode(j)
		local v1, v2 = 0, 0
		local m, v1, v2 = animVal:GetKeyInterp(j, m, v1, v2) --print (v1, v2) --WEIRD?! But seems to work...
	--]]
end

I was/am very intrigued too about the "int 32 component" argument, but if I could access to that functions at least, maybe some trial and error (as you suggested) would through some light on it. Really... I'm totally lost with this "silly thing" and the worst thing is (contrary as I'm in real life) I'm totally unable to move to other tasks unless I find a solution to any unsolved (more if they intrigues me so much) problem/s...

So summarizing, and assuming you'll always have a better understanding of this kind of "structure" issues than me for sure, any idea of how this precise part of your pseudocode could be addressed to can really play with it?

Code: Select all

/*Grab the Interpolation settings at a certain frame (frame1)*/
/*Or by a certain ID*/
InterpSetting mysetting;
mychan.GetKeyInterp(frame1, mysetting);

Cause if I feed the "GetKeyInterp" function's second argument with a nil variable, table or whatever (expecting it be filled with "InterpSetting" stuff for example) I only get Lua Console errors and program crashes.

BTW, I'm sure the tangents/angles info will be very useful one this bad patch goes pass :)


Well, thanks again and greetings,
Ramón López.
...
User avatar
Lost Marble
Site Admin
Posts: 2347
Joined: Tue Aug 03, 2004 6:02 pm
Location: Scotts Valley, California, USA
Contact:

Re: Help to get Access to Bezier Keyframe Interpolation Sett

Post by Lost Marble »

I'm sorry we're so lacking in the scripting documentation department. It's something we intend to address, but it's been pushed back repeatedly in favor of other features and bug fixes. Anyway, the "component" refers to X, Y, or Z. Obviously, this only applies to vector channels like layer translation (X, Y, or Z) or bone translation (then only X or Y). If you're working with a channel with just a single value, there's only one component - for example, bone rotation.

So for the component, pass in either 0, 1, or 2, corresponding to X, Y, or Z. And for single value channels, always pass 0.
Genete
Posts: 3483
Joined: Tue Oct 17, 2006 3:27 pm
Location: España / Spain

Re: Help to get Access to Bezier Keyframe Interpolation Sett

Post by Genete »

Lost Marble wrote:I'm sorry we're so lacking in the scripting documentation department. It's something we intend to address, but it's been pushed back repeatedly in favor of other features and bug fixes. Anyway, the "component" refers to X, Y, or Z. Obviously, this only applies to vector channels like layer translation (X, Y, or Z) or bone translation (then only X or Y). If you're working with a channel with just a single value, there's only one component - for example, bone rotation.

So for the component, pass in either 0, 1, or 2, corresponding to X, Y, or Z. And for single value channels, always pass 0.
Does it mean that the other assumptions I did in my post are correct? (percentage, length & distance between keyframes)
-G
User avatar
Rai López
Posts: 2228
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: Help to get Access to Bezier Keyframe Interpolation Sett

Post by Rai López »

Mike, first of all... thank you very much! Although I'm afraid my major problem still remains unsolved, which is, basically, I simply can't figure out the way to access to the functions inside the "InterpSetting" class. This can seems very basic, but I think there must be something different in this precise case that prevents to me to access to any function, like (for example) this way: "animChan:BezierOutAngle(0)", which always returns me a nil value error no matter from where or how I try to invoke it, I assume I fail in the way to use the "GetKeyInterp(frame, InterpSetting???)" functions but no try to feed it with an "InterpSetting" function as a second argument in anyway have worked to me, so... sorry if I'm simply missing something really obvious here or over-complicating things, but really I've found a big rough patch here and any help on this still would be very welcomed...

Well, thanks again (of course, that info related to the "component" argument will be useful for sure) and greetings!
...
User avatar
Equalrights4animals
Posts: 58
Joined: Sat May 10, 2014 10:26 pm

Re: Help to get Access to Bezier Keyframe Interpolation Sett

Post by Equalrights4animals »

What is bezier interpolation? Can someone please tell me what the other types of interpolation do?
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Help to get Access to Bezier Keyframe Interpolation Sett

Post by hayasidist »

Ramón López wrote:... my major problem still remains unsolved, which is, basically, I simply can't figure out the way to access to the functions inside the "InterpSetting" class. ..!
I think what you're asking means that you need something like this:

local interp = MOHO.InterpSetting:new_local()
interp.interpMode = mode
interp.val1 = v1
interp.val2 = v2
interp.interval = interval
interp.hold = hold
interp.tags = tags
yourChannel:SetKeyInterp(frame, interp)

is that what you wanted?
User avatar
Rai López
Posts: 2228
Joined: Sun Aug 08, 2004 1:41 pm
Location: Spain
Contact:

Re: Help to get Access to Bezier Keyframe Interpolation Sett

Post by Rai López »

@hayasidist: Yes, this got solved time ago. There were a problem on trying to access to the "InterpSetting" class form the Lua interface if I remember well but it got fixed at some point. I should have make a note here long time ago informing about such fix, sorry about that... but well, there it is now, thanks :)
...
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Help to get Access to Bezier Keyframe Interpolation Sett

Post by hayasidist »

oh - yeah - :oops: should have read the date on your post ... sorry!
User avatar
hayasidist
Posts: 3492
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Help to get Access to Bezier Keyframe Interpolation Sett

Post by hayasidist »

@Equalrights4animals:

Imagine two points on a piece of paper. One is the starting point and the other is the end point.

Interpolation is how you get from one position to another, and the shape of the line between them defines the type of interpolation. You can draw a straight line between them or you can draw a curved line between them. There's the straight line (linear interpolation), (we can argue as to whether 'step' is or is not a curve as it has two linear segements); and then there curves, with lots of ways to draw a curve: ease-in, bounce, elastic etc ...

One method for drawing curves was pioneered by a French engineer called Pierre Bézier. He used established mathematical theories to define the shapes of curves. He did this by having an extra control point associated with the start point and another with the end point. You draw a smooth curve that starts from your starting point heading in the direction of its control point and smoothly and continuoulsy change direction so that you arrrive at your end point as though you'd come from its control point.

The choice of where you put the control points (i.e. where you drag the contol handles) changes the shape of the curve.

The best place to look for a description of the various interpolation modes is the ASP 10 manual page 285 onwards.

Then the next best thing to do is draw a shape and animate it with Bézier interpolation; open up the Motion Graph and experiment with the Bézier control handles to see how you can shape of the path that an animated point follows to get from its start to end position.

If you need more help just ask.
Post Reply