Create & Control your animations: How-To Guide

Julien Moreau-Mathis
Community Play 3D
Published in
4 min readJul 30, 2014

--

Introduction

Community Play 3D provides tools to create and control your animations like FPS weapons, animated trees, characters, etc.

This tutorial will show you how to create quickly animations for the most common usage like weapons and all animated objects containing key-frames.

Add your animated object

First, add your animated object into the Objects list (these objects are automatically optimized by CP3D) and texture it (if not automatically done).

Note: when added, the animated objects are not automatically animated with the default animations.

Create and manage your animations

Once you configured your animated object, run the animations manager. You can find the manager in the global context menu Animators -> Manual Animation.

Animators -> Manual Animation

CP3D will open a window with a view port containing the animated object for a real-time preview, a list of actions and some tabs.

Actions Tab

An action is an object in memory (data) containing these following values:

  • Start frame
  • End frame
  • Action’s name
  • Animation speed
  • Skeleton for the current action

When developing your game or your 3D application, each animation is an Action. Then, in your C++ code you’ll be able to call an action directly form its name. The code will look like:

controller->setAnimationToNode(myNode, “actionName”);

Animations Tab

This tab contains a list of skeletons you’ll use in your Actions. If you want to separate the animations into different files, you can, and simply add them to the list. When configuring your actions, you’ll be able to load your different skeletons.

Details Tab

This tab contains the relative informations of the current skeleton you chose in your action. You’ll find the frame count, the start frame, the end frame and the joint count informations. If you want to preview the entire skeleton’s animation(s), you can directly use the preview button in the details tab.

Create an action

To create an action:

  • Add one by clicking on the “Add” button
  • Select the action in the actions list
  • Configure the action: start frame, speed, etc.
  • Click “Preview” to view the result in real-time.

Each action must be done to represent a particular animation like Fire, Reload, Stay, Run etc.

Save your actions

To save your actions. Go on the context menu of the tool and click File -> Save.

You can now close the Animations Manager.

Load your saved animations

To load your saved animation(s), edit your animated object (our weapon here) and go in the “Animated” tab.

  • Click the “Browse…” button to load our saved file
  • Select the .anc file
  • Open it
  • Select the animation for preview in the entire world using the combo box

Usage in C++

The usage in C++ is pretty simple. You have two methods:

  • Create a IAnimationEndCallback class
  • Use lambdas

For the example here, we are going to apply the “RELOAD” and “IDLE” animations to our weapon.

The animations controller is a class : cp3d::controllers::IAnimationController;

To get access to the animations controller of the CP3D API:

devices->getAnimationController(); // Returns the pointer

The available methods are:

/// Apply a saved animation to the scene node “node”.
/// animationNumber between 0-n, previously configured by the user in CP3D World Editor.
/// If animationNumber is false then the animation will no be ran
virtual void applyAnimationToModel(ISceneNode *node, u32 animationNumber) = 0;
/// Same as applyAnimationToModel but finds the animation by name
/// name : the name of the animation
virtual void applyAnimationFromNameToModel(ISceneNode *node, stringc name) = 0;
/// Returns the current animation number played by the node
/// Value from 0 to n, if unused, then returns -1
virtual s32 getCurrentAnimationIndiceOf(ISceneNode *node) = 0;
/// Set a custom callback stored into a lambda function
virtual void setCustomCallback(ISceneNode *node, std::function<void(IAnimatedMeshSceneNode *node)> callback) = 0;

Let start the application with the RELOAD animation for the weapon:

ISceneNode *mp5Node; /// Our weapon nodedevices->getAnimationController()
->applyAnimationFromNameToModel(mp5Node, “RELOAD”);

Create a IAnimationEndCallback class

class CMyCallback : public IAnimationEndCallBack {
public:
void OnAnimationEnd(IAnimatedMeshSceneNode* node) {
/// Your code here. Can be:
devices->getAnimationController()
->applyAnimationFromNameToModel(node, "IDLE");
}
};

Then in the code:

CMyCallback *cb = new CMyCallback();
mp5Node->setAnimationEndCallback(cb);

With this code, the weapon will reload. Once it is finished, the callback will be called and set the IDLE animation to the weapon.

Use lambdas functions

With the lambda functions, the method is more smart and more clean.

ISceneNode *mp5Node; /// Our weapon nodedevices->getAnimationController()
->applyAnimationFromNameToModel(mp5Node, “RELOAD”);
/// Apply callback with a lambda
devices->getAnimationController()->setCustomCallback(mp5Node, [=](IAnimatedMeshSceneNode *node)
{
devices->getAnimationController()
->applyAnimationFromNameToModel(mp5Node, “IDLE”);
});

With these 5 lines of code, the weapon will reload and return to the IDLE animation once the reload animation is finished.

--

--