Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion OgreMain/include/OgreAnimationTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,18 @@ namespace Ogre
NodeAnimationTrack* _clone(Animation* newParent) const;

void _applyBaseKeyFrame(const KeyFrame* base) override;


/** Sets the transform of the current node to be the 'initial state' ie that
position / orientation / scale to be used as a basis for delta values used
in keyframe animation.

If you never call this method, the initial state is the identity transform, ie do nothing.
*/
void setInitialState(void);

/** Resets the position / orientation / scale of the node to it's initial state, see setInitialState for more info. */
void resetToInitialState(void) const;

private:
/// Specialised keyframe creation
KeyFrame* createKeyFrameImpl(Real time) override;
Expand All @@ -386,6 +397,13 @@ namespace Ogre
Node* mTargetNode;
// Prebuilt splines, must be mutable since lazy-update in const method
mutable Splines* mSplines;

/// The position to use as a base for keyframe animation
Vector3 mInitialPosition;
/// The orientation to use as a base for keyframe animation
Quaternion mInitialOrientation;
/// The scale to use as a base for keyframe animation
Vector3 mInitialScale;
};

/** Type of vertex animation.
Expand Down
27 changes: 27 additions & 0 deletions OgreMain/include/OgreBone.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ namespace Ogre
*/
void reset(void);

/** Sets the current transform of this Bone to be the 'initial state' ie that
position / orientation / scale to be used as a basis for delta values used
in keyframe animation.

If you never call this method, the initial state is the identity transform, ie do nothing.
*/
void setInitialState(void);

/** Gets the initial position of this Bone, see setInitialState for more info.

Also resets the cumulative animation weight used for blending.
*/
const Vector3& getInitialPosition(void) const { return mInitialPosition; }

/** Gets the initial orientation of this Bone, see setInitialState for more info. */
const Quaternion& getInitialOrientation(void) const { return mInitialOrientation; }

/** Gets the initial position of this Bone, see setInitialState for more info. */
const Vector3& getInitialScale(void) const { return mInitialScale; }

/** Sets whether or not this bone is manually controlled.

Manually controlled bones can be altered by the application at runtime,
Expand Down Expand Up @@ -136,6 +156,13 @@ namespace Ogre
/// Pointer back to creator, for child creation (not smart ptr so child does not preserve parent)
Skeleton* mCreator;

/// The position to use as a base for keyframe animation
Vector3 mInitialPosition;
/// The orientation to use as a base for keyframe animation
Quaternion mInitialOrientation;
/// The scale to use as a base for keyframe animation
Vector3 mInitialScale;

/// The inversed derived scale of the bone in the binding pose
Vector3 mBindDerivedInverseScale;
/// The inversed derived orientation of the bone in the binding pose
Expand Down
35 changes: 0 additions & 35 deletions OgreMain/include/OgreNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,6 @@ namespace Ogre {
*/
virtual void updateFromParentImpl(void) const;
private:
/// The position to use as a base for keyframe animation
Vector3 mInitialPosition;
/// The orientation to use as a base for keyframe animation
Quaternion mInitialOrientation;
/// The scale to use as a base for keyframe animation
Vector3 mInitialScale;

/** Node listener - only one allowed (no list) for size & performance reasons. */
Listener* mListener;

Expand Down Expand Up @@ -560,28 +553,6 @@ namespace Ogre {
*/
Listener* getListener(void) const { return mListener; }


/** Sets the current transform of this node to be the 'initial state' ie that
position / orientation / scale to be used as a basis for delta values used
in keyframe animation.

You never need to call this method unless you plan to animate this node. If you do
plan to animate it, call this method once you've loaded the node with it's base state,
ie the state on which all keyframes are based.
@par
If you never call this method, the initial state is the identity transform, ie do nothing.
*/
void setInitialState(void);

/** Resets the position / orientation / scale of this node to it's initial state, see setInitialState for more info. */
void resetToInitialState(void);

/** Gets the initial position of this node, see setInitialState for more info.

Also resets the cumulative animation weight used for blending.
*/
const Vector3& getInitialPosition(void) const { return mInitialPosition; }

/** Gets the local position, relative to this node, of the given world-space position */
Vector3 convertWorldToLocalPosition( const Vector3 &worldPos );

Expand All @@ -603,12 +574,6 @@ namespace Ogre {
useful for simple transforms that don't require a child node.*/
Quaternion convertLocalToWorldOrientation( const Quaternion &localOrientation );

/** Gets the initial orientation of this node, see setInitialState for more info. */
const Quaternion& getInitialOrientation(void) const { return mInitialOrientation; }

/** Gets the initial position of this node, see setInitialState for more info. */
const Vector3& getInitialScale(void) const { return mInitialScale; }

/** Helper function, get the squared view depth. */
Real getSquaredViewDepth(const Camera* cam) const;

Expand Down
8 changes: 4 additions & 4 deletions OgreMain/include/OgreSceneManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,7 @@ namespace Ogre {
You can create Animation objects for animating SceneNode obejcts using the
createAnimation method. However, in order to actually apply those animations
you have to call methods on Node and Animation in a particular order (namely
Node::resetToInitialState and Animation::apply). To make this easier and to
@ref NodeAnimationTrack::resetToInitialState and @ref Animation::apply). To make this easier and to
help track the current time position of animations, the AnimationState object
is provided.
So if you don't want to control animation application manually, call this method,
Expand All @@ -2260,14 +2260,14 @@ namespace Ogre {
@par
Note that any SceneNode affected by this automatic animation will have it's state
reset to it's initial position before application of the animation. Unless specifically
modified using Node::setInitialState the Node assumes it's initial state is at the
modified using @ref NodeAnimationTrack::setInitialState the Node assumes it's initial state is at the
origin. If you want the base state of the SceneNode to be elsewhere, make your changes
to the node using the standard transform methods, then call setInitialState to
'bake' this reference position into the node.
'bake' this reference position into the NodeAnimationTrack.
@par
If the target of your animation is to be a generic AnimableValue, you
should ensure that it has a base value set (unlike nodes this has no
default). @see AnimableValue::setAsBaseValue.
default). @ref AnimableValue::setCurrentStateAsBaseValue
@param animName The name of an animation created already with createAnimation.
*/
AnimationState* createAnimationState(const String& animName);
Expand Down
21 changes: 19 additions & 2 deletions OgreMain/src/OgreAnimationTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ namespace Ogre {
//---------------------------------------------------------------------
NodeAnimationTrack::NodeAnimationTrack(Animation* parent, unsigned short handle, Node* targetNode)
: AnimationTrack(parent, handle), mSplineBuildNeeded(false), mUseShortestRotationPath(true),
mTargetNode(targetNode), mSplines(0)

mTargetNode(targetNode), mSplines(0), mInitialPosition(Vector3::ZERO),
mInitialOrientation(Quaternion::IDENTITY), mInitialScale(Vector3::UNIT_SCALE)
{
}
//---------------------------------------------------------------------
Expand Down Expand Up @@ -681,6 +681,23 @@ namespace Ogre {
}

}
void NodeAnimationTrack::setInitialState(void)
{
OgreAssert(mTargetNode, "Target node must be set before calling setInitialState");
mInitialPosition = mTargetNode->getPosition();
mInitialOrientation = mTargetNode->getOrientation();
mInitialScale = mTargetNode->getScale();
}
//-----------------------------------------------------------------------
void NodeAnimationTrack::resetToInitialState(void) const
{
if (!mTargetNode)
return;

mTargetNode->setPosition(mInitialPosition);
mTargetNode->setOrientation(mInitialOrientation);
mTargetNode->setScale(mInitialScale);
}
//--------------------------------------------------------------------------
VertexAnimationTrack::VertexAnimationTrack(Animation* parent,
unsigned short handle, VertexAnimationType animType)
Expand Down
17 changes: 15 additions & 2 deletions OgreMain/src/OgreBone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ namespace Ogre {
Bone::Bone(unsigned short handle, Skeleton* creator)
: Node(), mCreator(creator), mHandle(handle), mManuallyControlled(false)
{
setInitialState();
}
//---------------------------------------------------------------------
Bone::Bone(const String& name, unsigned short handle, Skeleton* creator)
: Node(name), mCreator(creator), mHandle(handle), mManuallyControlled(false)
{
setInitialState();
}
//---------------------------------------------------------------------
Bone::~Bone()
Expand Down Expand Up @@ -73,10 +75,21 @@ namespace Ogre {
mBindDerivedInverseScale = Vector3::UNIT_SCALE / _getDerivedScale();
mBindDerivedInverseOrientation = _getDerivedOrientation().Inverse();
}
//---------------------------------------------------------------------
//-----------------------------------------------------------------------
void Bone::setInitialState(void)
{
mInitialPosition = mPosition;
mInitialOrientation = mOrientation;
mInitialScale = mScale;
}
//-----------------------------------------------------------------------
void Bone::reset(void)
{
resetToInitialState();
mPosition = mInitialPosition;
mOrientation = mInitialOrientation;
mScale = mInitialScale;

needUpdate();
}
//---------------------------------------------------------------------
void Bone::setManuallyControlled(bool manuallyControlled)
Expand Down
19 changes: 0 additions & 19 deletions OgreMain/src/OgreNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ namespace Ogre {
mDerivedOrientation(Quaternion::IDENTITY),
mDerivedPosition(Vector3::ZERO),
mDerivedScale(Vector3::UNIT_SCALE),
mInitialPosition(Vector3::ZERO),
mInitialOrientation(Quaternion::IDENTITY),
mInitialScale(Vector3::UNIT_SCALE),
mListener(0)
{
needUpdate();
Expand Down Expand Up @@ -591,22 +588,6 @@ namespace Ogre {

}
//-----------------------------------------------------------------------
void Node::setInitialState(void)
{
mInitialPosition = mPosition;
mInitialOrientation = mOrientation;
mInitialScale = mScale;
}
//-----------------------------------------------------------------------
void Node::resetToInitialState(void)
{
mPosition = mInitialPosition;
mOrientation = mInitialOrientation;
mScale = mInitialScale;

needUpdate();
}
//-----------------------------------------------------------------------
struct NodeNameExists {
const String& name;
bool operator()(const Node* mo) {
Expand Down
3 changes: 1 addition & 2 deletions OgreMain/src/OgreSceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2198,8 +2198,7 @@ void SceneManager::_applySceneAnimations(void)
// Reset any nodes involved
for (const auto& it : anim->_getNodeTrackList())
{
if (Node* nd = it.second->getAssociatedNode())
nd->resetToInitialState();
it.second->resetToInitialState();
}

for (const auto& it : anim->_getNumericTrackList())
Expand Down
2 changes: 1 addition & 1 deletion PlugIns/DotScene/src/DotSceneLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ void DotSceneLoader::processNodeAnimation(pugi::xml_node& XMLNode, SceneNode* pP

// create a track to animate the camera's node
NodeAnimationTrack* track = anim->createNodeTrack(0, pParent);
pParent->setInitialState();
track->setInitialState();

// Process keyframes (*)
for (auto pElement : XMLNode.children("keyframe"))
Expand Down