THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 16/11/2012 at 06:25, xxxxxxxx wrote:
Right, so it's code that needs to be called on a frame change. Let's say you have an ObjectData plugin, you could test the frame number in the Execute() function, which will always be called at least once per frame. The easiet way to do this is to have a class-level variable which holds the number of the most recent frame before a frame change occurred. The code might look something like this:
EXECUTIONRESULT MyPlugin::Execute(BaseObject *op, BaseDocument *doc, BaseThread *bt, LONG priority, EXECUTIONFLAGS flags)
{
LONG frame, startFrame, fps;
fps = doc->GetFps();
startFrame = doc->GetMinTime().GetFrame(fps); // find start frame
frame = doc->GetTime().GetFrame(fps); // get current frame
if(frame == startFrame)
{
oldFrame = startFrame; // <----- oldFrame is a class-level LONG
// now do whatever else might be needed in the first frame of the animation
// do stuff here...
}
// if the user has changed the frame in some way
if(frame != oldFrame)
{
// update whatever is needed following the frame change
// do stuff here...
// note that this won't be done in the first frame because there, frame == oldFrame
// now reset oldFrame so these actions aren't done again in this frame
oldFrame = frame;
}
return EXECUTIONRESULT_OK;
}
The code is therefore only carried out when the frame changes. At the start frame of the animation, you might need to do other stuff, like initialising data structures or something, so that frame is treated separately.