problems with simple node animation [SOLVED]

MrPixel

22-10-2010 01:29:39

I'm having trouble getting a very simple animation working. Out first animation test worked fine because the animation was centered at the origin of the scene. The second test had a single entity animated (rotation only) away from the origin. The entity translation and rotation is getting properly exported, but the base entity translation and rotation is also coming through in the animation keyframe data. Which results in a double translation and a double rotation. I've tried various settings in the animation export options and I can't get the keyframe data in "local" coordinates. In the osm snippet below, I would expect the first frame of the animation to have zero translation and zero rotation - but it mirrors the entity translation/rotation. What am I doing wrong?


<entity name="arm_00" hidden="false" filename="arm_00.mesh" CastShadows="yes" ReceiveShadows="yes">
<position x="-260" y="20" z="8.7422779e-007" />
<rotation x="-0" y="0.70710683" z="0" w="-0.70710677" />
<scale x="1" y="1" z="1" />
<animations>
<animation name="000" loop="false" length="4">
<keyframe time="0">
<position x="-260" y="20" z="8.74228e-007" />
<rotation w="-0.707107" x="-0" y="0.707107" z="0" />
<scale x="1" y="1" z="1" />
</keyframe>
<keyframe time="0.133333">
<position x="-260" y="20" z="8.74228e-007" />
<rotation w="-0.714147" x="-0" y="0.699996" z="0" />
<scale x="1" y="1" z="1" />
</keyframe>
...

Lioric

27-10-2010 03:32:46

How is the pivot of the animated objects? is it at the objects center (or in the correct position wrt the object, for that matter)

MrPixel

27-10-2010 23:05:55

I've looked at the pivots in Max and they look correct to me - but I'm not a Max pro. I'll look into it with the artist tomorrow.

I found a tutorial on creating node animations (link below) that provides a Max file with the pivots preset (all except one). I followed the tutorial and everything looks correct in Max and the the oFusion preview. But when I export, I get exactly the same problem (the entity pos/rot/scale is identical to the first frame of animation). I've exported with "In Place" checked and not - same result. I've Reset Transform on each part - same result. I tried to Collapse Stack but can't figure out how to do it without destroying the hierarchy.

Robot Arm Tutorial:
http://www.designnewz.com/tutorials/3d-studio-max-tutorials/animation/robotic-arm-p6

I traced through the Ogre animation code and for each frame it: resets to initial pos/rot/scale, then applies a delta from the initial pos/rot based on the interpolated keyframe data (scale is just replaced). So having the same pos/rot/scale as the first keyframe is clearly wrong but no matter what I do in Max and with export options, I can't get anything but that.

Lioric

28-10-2010 01:52:02

If the oFusion viewport produces the correct results, then your scene is setup correctly

Its just the animation updater code in your application that might be producing this issue, search this forum for threads with sample of how to correctly animate the produced scene

The first keyframe position is correct, as the nodes, when added to the scene, if no manually setting its initial state then it is 0, 0, 0 (and unit scale and rot), the animation updater, while updating it, will reset to 0,0,0 pos and then apply the first keyframe, and that will be the correct position for the animation start

MrPixel

28-10-2010 02:38:57

The animation code in our application is straight out of the latest oSceneLoader_demo_dragon (Pro) and I've verified that we are using the latest LoaderLib. We have our own app animation code but I temporarily replaced it with the oSceneLoader animation code for debugging this problem.

What you say about the animation updater resetting to 0,0,0 pos makes sense, but that's not what the sample loader code does. The application animation code (lifted straight from the demo loader) has

track->getAssociatedNode()->resetToInitialState();

Which sets the pos/rot/scale to the enitiy pos/rot/scale from the osm. Then when tracing "animation->apply(currentTime);", is doesn't reset the node pos/rot to anything, it simply applies node->translate(animTranslate) and node->rotate(animRotate). Which effectively "adds" the animation translation/rotation to the entity base pos/rot. Which is why I'm seeing the double translation and rotation.

So I guess I could fix the problem by replacing "track->getAssociatedNode()->resetToInitialState();" with setting the node position and rotation to zero. Does this mean that the sample loader code is incorrect?

Lioric

28-10-2010 02:47:54

The resetToInitialState method should set the node position to 0, 0, 0 world coords (the default pos of all nodes if you don't modiyf it manually), that is why the first keyframe position is needed

The oSceneLoader animation code has been used in several projects over the years succesfully

I will review with the scene you posted earlier

Lioric

28-10-2010 03:09:28

Have you downloaded the groupAnimationDemo? if not get it from:

www.ofusiontechnologies.com/support/pre ... onDemo.zip

and its source:

www.ofusiontechnologies.com/support/pre ... Source.zip

This is a demo sample of grouped animation, and shows how to with control the active group animation and its loop state

See if there is any hint in there that might help in your issue

MrPixel

29-10-2010 03:09:56

Your comment that the initial values should be zero "if you don't modify it manually" made me look more closely at our scene loader. I found a little chunk of code that another programmer slipped in after a scene was loaded...

for(int i=0;i<(int)mEntityList.size();i++)
{
SceneNode* node = mEntityList[i]->getParentSceneNode();
if(node)
node->setInitialState();
}


D'oh. This is why the initial state was getting set to the base entity position. I guess he's using this to "reset" a scene after entities have potentially been moved around. I replaced the resetToInitialState() in the per-frame animation controller with setPosition(Vector3::ZERO) and setOrientation(Quaternion::IDENTITY) and all works nicely now. Thanks much for the assistance!