ogre source code - action system animation

ogre's animation system is written in OgreMain.

Bone resource import

SkeletonManager is the creation and management of bones. There are two ways to create it. The first is to directly create a new Skeleton, and the second is to import it through resources.

When the resource is imported, execute Resource::prepare of OgreResource, and then execute prepareImpl, which is prepareImpl of OgreResource.h.

Then Skeleton inherits Resource, so Skeleton::prepareImpl is executed when importing.

First get the resource ResourceGroupManager::getSingleton().openResource. Get the pointer to the file, which is of type DataStream.

Then use the SkeletonSerializer's importSkeleton to import the resource content. SkeletonSerializer inherits Serializer, and Serializer is the serialized content after reading the resource.

There are several types of recognition for imported bones

 

OgreSkeletonInstance instanced bones

OgreSkeletonInstance is the identification of the skeleton file of the instantiated object. When initializing in OgreEntity, _initialise is executed. If there is a skeleton, the SkeletonInstance is created, and then the line is loaded. SkeletonInstance inherits Skeleton, so it also executes Skeleton's prepareImpl to perform content loading. deriveRootBone is to set the root node,

Execute createBone for each bone, set the parent and child of the bone,

In the scene management SceneManager, after executing _renderScene, it will update the animation and execute _applySceneAnimations(); in it, it will get all the AnimationStates, get the animation and then apply it. Execute to the apply function of OgreAnimation.

 

_applyBaseKeyFrame

Then execute Animation::_applyBaseKeyFrame() on mNodeTrackList and mVertexTrackList first.

Initialize Node and Vertex inside

 

 

Then apply apply to Node, Numeric, and Vertex respectively.

Execute to NodeAnimationTrack::applyToNode,

mNodeTrackList

NodeAnimationTrack is an AnimationTrack specially designed to handle node transformations.

If it is Node, execute to NodeAnimationTrack::getInterpolatedKeyFrame

Determine whether it is the first frame, if the first frame is directly assigned rotation zoom translation.

 

Otherwise, the blending of the two frames before and after is performed. There are two kinds of blending, linear and spline.

 

 

getInterpolatedKeyFrame gets the matrix data of the frame and sets it in the node

NumericAnimation:

NumericAnimationTrack is an AnimationTrack designed to handle generic animation values.

NumericAnimationTrack::applyToAnimable, get the influence weight through getInterpolatedKeyFrame, set it into a certain frame through VertexPoseKeyFrame::addPoseReference, and then anim->applyDeltaValue(val); set it into AnimableValue, and several types can be set

 

mVertexTrackList

VertexAnimationTrack is an AnimationTrack specially designed to handle changing vertex position information.

If the type is VAT_POSE, that is, the animation consists of a single triangle pose keyframe, execute VertexAnimationTrack::getInterpolatedKeyFrame, which mainly obtains the influence between frames and puts it in the KeyFrame.

Then according to the deformation, the animation of the pose performs a matrix change.

Skeleton Play Weights:

The BoneBlendMask in AnimationState is used for the mask of the bones, and the mask here finally affects the weight of the playback action of a node.

When OgreEntity_updateRenderQueue, it will perform rendering queue processing, and then execute setAnimationState through cacheBoneMatrices.

Then take out all the activated action state machines getEnabledAnimationStates from the animSet, get the action through the state machine, and then do it in two ways. The first one is if there is a blendMask, then execute the apply of the action with the blendMask, if not, it is not.

 

blendMask

If it is with blendMask, the action system of node will be executed,

 

Equivalent to bringing blendMask, only those with blendMask can perform actions.

Without blendMask

If there is no blendMask, execute applyToNode without blendMask, which is equivalent to the effect without mask.

Optimization of skeletal animation (only node optimization)

Skeleton::optimiseAllAnimations has optimizations for skeletal animation. It will remove the values ​​of zoom, translation, and rotation that are all 0, and execute it to Animation::optimise, which mainly optimizes Node and Vertex modes, but now only Made node.

Then into NodeAnimationTrack::optimise. Here mainly only middle keyframes are eliminated from sequences of 5+ identical keyframes, because we need to keep boundary keyframes in place, and we need to keep 2 keyframes at each end in order to preserve tangents for spline interpolation .

 

The processing of Animation in OgreMesh again

 

Guess you like

Origin blog.csdn.net/llsansun/article/details/123366856