Views
Frame information
From Odwiki
Contents |
[edit] Retrieve frame information with HDK and Houdini 8.2.238
This is very similar to the Keyframe_information, but instead of just gaining access to the keyframes you have set in Houdini yourself, this will explain how you can access all available frames and get its information
[edit] Set context to the right frame
First of all, you need to set the context handle, so it is pointing to the right frame. This frame could be any frame you desire, ranging from 1 - n.
Where do you get the context handle from, you ask? It should be a inparameter atleast in your "cookmySop" function.
Here is the function:
OP_Context::setFrame(long Frame);
Here you put in a long variable (the frame you want to work with). Now you have set the context to the right frame. Now you just need to lock it, so nothing can change the inparameters while you are working with the data:
SOP_Node::lockInputs(OP_Context &context);
Now its locked, and safe to use until you decide to unlock the context handle again.
[edit] Access the current Frame's data
So now when the context is locked, you can freely access the data. You need to access the Parameter data in order to get the information. Each Parameter owns a list of components, and these components can own channels. The channels are the ones that stores the information we want to access.
The most common parameters that you might want to use is; Translate, Rotation and Scale. Their internal Parameter names are as follows:
t = translate r = rotate s = scale
Each of these parameters have 3 component indices (x,y, z). So what you need to do now, is to evaluate each parameter, and get out the values you want.
So first of all, we need to make sure we are looking in the right node!
OP_Node *pCurrNode = OP_Node::getInput(unsigned int idx);
You might recognize this function, and you probably already have already called this one before. If you have, you can use that pointer instead of calling it once more. The important thing you have the pointer and its pointing to the current node you want to use.
So now you need to call the evaluation function using the current node:
OP_Node::evalFloat(const char *pn, int vi, float t)
The inparameters you use are:
- const char *pn = Parameter Name, as described above (t = translate etc)
- int vi = Index number, as said above each has 3 indices (x, y, z) so use 0 for x, 1 for y and 2 for z
- float t = current FrameTime.
You can get the current frametime easiest by using the context time variable:
OP_Context::context.myTime
This variable changes from frame to frame. Since animation is time dependent, it is the actual time variable that finds the specific value that you want to retrieve.
[edit] Putting it all together
Below I have posted a simple pseudo-code that shows how you can loop through a specific number of frames and get the information. In this example I will take out the Translate information.
// Start and stop frames
int StartFrame = 0;
int StopFrame = 10;
for(int CurrFrame = StartFrame; CurrFrame <= StopFrame; CurrFrame++)
{
// For each loop I set the context to that specific frame
context.setFrame((long)CurrFrame);
// Lock the context
lockInputs(context);
// Get the current node, if I havent already done that. I use 0 since I only working with one object
OP_Node *pCurrNode = getInput(0);
// Get the X-axis
float TranslateX = pCurrNode->evalFloat("t", 0, context.myTime);
// Get the Y-axis
float TranslateY= pCurrNode->evalFloat("t", 1, context.myTime);
// Get the Z-axis
float TranslateZ = pCurrNode->evalFloat("t", 2, context.myTime);
// Unlock the context so we can change the frame
unlockInputs();
}
[edit] Also see
Keyframe_information - Howto access specific keyframe information



