Build Better Software. Faster.
Visit our company site at: www.techsoft3d.com
 

White Papers Index

Animations - Gettings Things Moving
Guido

Predefined animations have a multitude of different applications in the engineering realm. They can be found in a part catalogs that show various objects interacting, a 3d tutorial that walks the user through a step by step assembly process, or the visualization of precalculated result data. In each of these cases, animations provide a means to move beyond the static 3d image. While it has always been relatively easy to manually “animate” things in HOOPS by changing the modelling matrix of a particular object; HOOPS 9.0 has introduced a well defined and flexible API that deals with all the various facets of animation and transparently handles serialization of the animation data.

The new classes are part of HOOPS/MVO and can be easily identified by the “HBhv” prefix in the class name. As usual all the animation related code is available in readable source code to all HOOPS license holders. The amount of new code that deals with animation can be a bit overwhelming at first so this article tries to give you a few pointers and hints on where to go after you have read through the animation specifications and the info provided in the documentation.

When new functionality is introduced to HOOPS there is almost always some kind of sample code showcasing the new features. With the animation classes this showcase comes in the form of the “Keyframe Editor” - an interactive tool in our MFC based PartViewers that allow an end-user to add animations to an existing HSF file without writing one line of code. For a developer that wants to access the animation functionality programmatically, the source code of the Keyframe Editor can serve as a good real-world example on how to use the animation related classes. KeyframeEditor.cpp/h contains the bulk of the functionality. It is comprised of code that creates a new keyframe from scratch, inserts a keyframe at a specific position in the timeline, deletes a keyframe from an animation and various other functions. It can deal with anything from camera animations to attribute switches.

By stepping through the source, much of the fundamental animation concepts will become clear. For example, HSOpMoveHandle.cpp/h uses the geometry handles to create new keyframes very intuitively by dragging objects across the screen. This is a good example on how to use the MVO Operator concept of "geometry handles" and the animation classes in conjunction.

Finally, HBhvUtility::ConvertHsfToSegSwitch() contains code that takes a number of “frames” stored as named segments, each having its individual set of geometry, and creates the required animation data from it.

The “normal” way of defining an animation is to create new animation related objects and add them one by one to the "Behavior Manager". However, this can be a somewhat tedious process; especially in the beginning stages when a clear understanding of how the animation classes interact with each other is not yet understood. In these cases, it can be more convenient to take another route and use/manipulate the "XML Definition" directly. In order to display XML Data for a particular dataset, simply bring up the Keyframe Editor and press the “Edit XML” button. The "XML Defintion" can not only be displayed but it can also be manipulated with the changes taking effect immediately after pressing the "OK" button. A developer can take advantage of this feature by creating an animation definition simply by using the XML Definition and then processing it via HBvBeahviorManager::ProcessXMLData(). In this case all the necessary classes are created automatically and only knowledge of the "XML Specification" is necessary.

Tutorial: A Simple Animation

In this short tutorial we create a simple animation using the "Keyframe Editor":

1) Open bnc.hsf (from the demo/common/hsf/cad directory) and activate the keyframe editor (Tools-Keyframe Editor). It is also a good idea to choose a frontal view of the object

2) In order to drag objects around the screen we need to switch to the “Manipulator” Operator. After we have done that we can activate any geometry piece on the screen by simply clicking on it. At that point we are ready to define our first keyframe which should be at the current position of the object. To create that keyframe, simply click on any of the positional geometry handles. A new keyframe should appear in the keyframe editor.

3) After we have created the first keyframe for the animation we need to decide where to position the next keyframe by clicking an appropriate distance to the right from the first one. Each keyframe represents a fixed amount of time. Now by dragging the selected object across the screen the new object position is tied to the current keyframe.

4) We create a final third keyframe for the selected object. Again, we choose a new keyframe, first in the keyframe editor, then we drag the object to the desired position. To view the entire animation, just click on the play button in the animation toolbar. Alternatively, you can also click any keyframe box in the keyframe editor to jump to the desired position.

5) Finally, we want to add an additional rotation component to the animation. Again, the process is initiated by clicking on the first keyframe in the "Keyframe Editor". Next, we click one of the rotational handles of the selected object which will then create the second timeline.

6) We choose the final keyframe of the positional timeline as our end-keyframe for the rotation. By dragging and holding the mouse over the rotational handle the third keyframe is created. By clicking on “Edit XML” we can view the "XML Definition"of the animation we have just created.

 
 

 

 

 

 

©2004-06 Tech Soft 3D All Rights Reserved. Privacy | Legal