Implementation class of animationgraph programming C ++ in cryengine3
The animationgraph code consists of two parts:
Static part (class = canimationgraph =)
Dynamic part (class = canimationgraphstate =)
The static part represents the graph structure and attributes of each part. Each loaded animation graph file has an instance. All of these belong to an animationgraph Manager (= canimationgraphmanager = ).
The dynamic part represents the current status of a role entity instance in the level. Animationgraph is an animation role (= canimatedcharacter = ).
If a role uses two animationgraphs, they are two animations. They are encapsulated into a packaging class and act as a single canimationgraphstate class with the same behavior. The canimatedcharacter class has its own packaging class and the packaging class has these two animationgraph sections.
Set input value
The value entered by animationgraph can be modified by any module of the engine or by a Lua script.
Use C ++ code
The ianimationgraphstate pointer object of a role (the interface of the dynamic part of the animation graph) is required. Some of these methods will be called.
Bool setinput (inputid, float, tanimationgraphqueryid * pqueryid = 0 );
Bool setinput (inputid, Int, tanimationgraphqueryid * pqueryid = 0 );
Bool setinput (inputid, const char *, tanimationgraphqueryid * pqueryid = 0 );
The first parameter is the input ID. The second value is converted to the matching input type. The third parameter is optional and is used to obtain a query number. More operations are required when additional feedback information is added. (For example, when an animation matches an input value ).
If the operation is successful, the return value is true.
The following is the same, but it does not input the default value if no value exists. Therefore, this may be useful when you only want to change the upper body without affecting the full body animation.
Bool setinputoptional (inputid, const char *, tanimationgraphqueryid * pqueryid = 0 );
The input can be determined by their names rather than IDs. Use this method:
Template <class T> inline bool setinput (const char * Name, T value, tanimationgraphqueryid * pqueryid = 0 );
Use a string to query the ID. Therefore, the preferred method parameter input is to store the variable ID for future application. How to convert an input name to an input ID:
Inputid getinputid (const char * input) = 0;
Use Lua script
It is not recommended to change the input value of the animationgraph in the script, but it is still possible to do so. For this reason, the Lua script function will be applied:
Entitiy. Actor: setanimationinput (name, value)
Entity is the entity in the script list. Its name is the input name of input, and value is the value to be set.
Implement a new node type
For each node type of the animationgraph factory, you must register it in the animationgraph manager. This can be done through the canimationgraphmanger: registerfactories function.
The system needs to store any node type and initialize the instance through attribute combinations. To differentiate the combinations of unique attributes and sort created instances, the key is to use the node factory method virtual bool! Islessthan (ianimationstatenodefactory * pfactory. This method should return the result of comparing the data members directly stored by all nodes with the property values of the derived values. The Preprocessing macro can be used to simplify the execution. For example, the C ++ class like cagfacial takes the following example:
virtual bool IsLessThan( IAnimationStateNodeFactory * pFactory )
{
Ag_lt_begin_factory (cagfacial );
Ag_lt_elem (m_expressionnameidle );
Ag_lt_elem (m_expressionnamealerted );
Ag_lt_elem (m_expressionnamecombat );
Ag_lt_end ();
}
The new node is created by calling the CREATE () method of the factory. A new instance of the corresponding node class needs to be created and returned to the caller. In some cases, when a node is executed in one way, it does not need to store any dynamic data (so it is a node that can be shared ), the factory instance can also be a node instance at the same time. In this case, this function can be simply implemented as follows:
IAnimationStateNode * CAGSomeFactoryAndNodeClass::Create()
{
return this;
}
Some nodes depend on their types or sometimes their attribute values. Each frame needs to be updated (only when the node is in the current State ). If so, it initializes the sign of easnf_update for the nose of the node after playing. After each frame is activated, its virtual void Update (! The sanimationstatedata & Data function will be called.
Nodes provide some virtual methods to overwrite
Virtual void enterstate (sanimationstatedata & Data, bool duetorollback );
Virtual ehasenteredstate hasenteredstate (sanimationstatedata & data );
Virtual void enteredstate (sanimationstatedata & Data ){}
Virtual bool canleavestate (sanimationstatedata & data );
Virtual void leavestate (sanimationstatedata & data );
Virtual void leftstate (sanimationstatedata & Data, bool wasentered ){}
If the transition from the current state to another State requires the current state, you can call the canleavestate function to query the transition from the current state to the next state. Each node has a conversion veto. Conversion starts only once all nodes return treue.
At the beginning of one transition to another, the leavestate method is the first called method for each node in the current state. Then, the enterstate method is called for each node in the next state. These nodes are cleared and initialized using these methods. These methods are called before the animation actually starts. Most nodes won't do anything here except the animationlayerx node that pushes their animations into the animation queue.
Next, the system constantly queries each node in the next state by calling the hasenteredstate function. This function will be returned by the following columns;
Ehes_instant -- if this node does not affect access
Ehes_wating -- if the node is affected and the entry is still in progress
Ehes_entered -- if the node notifies the system that the work has been completed
For example, if the instance's animationlayerx node is monitoring the animation queue, ehes_waiting is returned and ehes_entered is returned only when their animation starts playing. This is used for animation synchronization of other nodes. Once ehes_entered is returned for a few points, the transition between animation States ends (note that the transition between animations is not completed at this time ). The nodes in the current status are notified to call their leftstate method, and the nodes in the next status start to call the enteredstate method.
Most nodes return ehes_instant when calling hasenteredstate, because they only provide functions related to animation playback. If ehes_instant is returned for all nodes in the next state, it means that the graph is in an empty state. When the conversion is complete and the next state is in the current state, since it is empty and no animation is played, all leftstate and enteredstate methods will not be called. However, the leftstate Method for nodes in the previous state will be called after entering other non-empty states.
Author: Wuhua wujiu Source: wine.