mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-22 04:45:31 +00:00
(Mostly) updated verve implementation.
This commit is contained in:
parent
e0627973fb
commit
5a7f0f0b23
538 changed files with 68727 additions and 49 deletions
154
Engine/source/Verve/Extension/Animation/VShapeAnimationEvent.cpp
Normal file
154
Engine/source/Verve/Extension/Animation/VShapeAnimationEvent.cpp
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "Verve/Extension/Animation/VShapeAnimationEvent.h"
|
||||
#include "Verve/Extension/Animation/VShapeAnimationTrack.h"
|
||||
|
||||
#include "console/consoleTypes.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_CONOBJECT( VShapeAnimationEvent );
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
VShapeAnimationEvent::VShapeAnimationEvent( void ) :
|
||||
mAnimationData( String::EmptyString ),
|
||||
mAutoDuration( true )
|
||||
{
|
||||
setLabel( "AnimationEvent" );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void VShapeAnimationEvent::initPersistFields( void )
|
||||
{
|
||||
Parent::initPersistFields();
|
||||
|
||||
addField( "AnimationData", TypeRealString, Offset( mAnimationData, VShapeAnimationEvent ), "The name of the Animation Sequence to play upon triggering." );
|
||||
addField( "AutoDuration", TypeBool, Offset( mAutoDuration, VShapeAnimationEvent ), "Force the Event's Duration to match the length of the Animation." );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Callback Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VShapeAnimationEvent::onTrigger( pTime, pDelta );
|
||||
//
|
||||
// Play the desired animation. Also account for any offet in playtime, and
|
||||
// timescale.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VShapeAnimationEvent::onTrigger( const S32 &pTime, const S32 &pDelta )
|
||||
{
|
||||
Parent::onTrigger( pTime, pDelta );
|
||||
|
||||
VTorque::SceneObjectType *object = getSceneObject();
|
||||
VShapeAnimationTrack *track;
|
||||
if ( !object || !getTrack( track ) )
|
||||
{
|
||||
// Sanity!
|
||||
return;
|
||||
}
|
||||
|
||||
// Play Animation.
|
||||
VTorque::playAnimation( object, track->getThreadIndex(), mAnimationData );
|
||||
|
||||
// Set Position.
|
||||
VTorque::setAnimationPosition( object, track->getThreadIndex(), getAnimationPosition( pTime + pDelta ) );
|
||||
|
||||
// Set Time Scale.
|
||||
VTorque::setAnimationTimeScale( object, track->getThreadIndex(), ( ( pDelta > 0 ) ? 1.f : -1.f ) );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VShapeAnimationEvent::onComplete( pTime, pDelta );
|
||||
//
|
||||
// If the animation is cyclic, then it needs to be paused once the event has
|
||||
// finished playing.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VShapeAnimationEvent::onComplete( const S32 &pTime, const S32 &pDelta )
|
||||
{
|
||||
// Fetch Object.
|
||||
VTorque::SceneObjectType *object = getSceneObject();
|
||||
VShapeAnimationTrack *track;
|
||||
if ( object && VTorque::isAnimationLooping( object, mAnimationData ) && getTrack( track ) )
|
||||
{
|
||||
// Pause Animation.
|
||||
VTorque::pauseAnimation( object, track->getThreadIndex() );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Property Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VShapeAnimationEvent::getAnimationPosition( pTime );
|
||||
//
|
||||
// Returns the time that the animation should be positioned at, at the given
|
||||
// time. This method considers whether the animation is cyclic or not and will
|
||||
// return the appropriate time regardless. Time is expressed in seconds and not
|
||||
// milliseconds.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
F32 VShapeAnimationEvent::getAnimationPosition( const S32 &pTime )
|
||||
{
|
||||
// Fetch Object.
|
||||
VSceneObjectTrack *track;
|
||||
VTorque::SceneObjectType *object = getSceneObject();
|
||||
if ( !getTrack( track ) || !object )
|
||||
{
|
||||
// Null.
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
// Fetch Interp.
|
||||
F32 interp = track->calculateInterp( pTime );
|
||||
if ( !isControllerPlayingForward() )
|
||||
{
|
||||
// Flip.
|
||||
interp = ( 1.f - interp );
|
||||
}
|
||||
|
||||
// Not Looping?
|
||||
if ( !VTorque::isAnimationLooping( object, mAnimationData ) )
|
||||
{
|
||||
// Return Interp.
|
||||
return interp;
|
||||
}
|
||||
|
||||
// Fetch Sequence Duration.
|
||||
const S32 duration = ( S32 )( 1000 * VTorque::getAnimationDuration( object, mAnimationData ) );
|
||||
|
||||
// Fetch Loop Interp.
|
||||
const S32 loopInterp = S32( mDuration * interp ) % duration;
|
||||
|
||||
return ( F32 )loopInterp / ( F32 )duration;
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _VT_VSHAPEANIMATIONEVENT_H_
|
||||
#define _VT_VSHAPEANIMATIONEVENT_H_
|
||||
|
||||
#ifndef _VT_VSCENEOBJECTEVENT_H_
|
||||
#include "Verve/Extension/SceneObject/VSceneObjectEvent.h"
|
||||
#endif
|
||||
|
||||
#ifndef _VT_TORQUE_ANIMATION_H_
|
||||
#include "Verve/Torque/TAnimation.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class VShapeAnimationEvent : public VSceneObjectEvent
|
||||
{
|
||||
typedef VSceneObjectEvent Parent;
|
||||
|
||||
public:
|
||||
|
||||
bool mAutoDuration;
|
||||
String mAnimationData;
|
||||
|
||||
public:
|
||||
|
||||
VShapeAnimationEvent( void );
|
||||
|
||||
static void initPersistFields( void );
|
||||
|
||||
// Callback Methods.
|
||||
|
||||
virtual void onTrigger( const S32 &pTime, const S32 &pDelta );
|
||||
virtual void onComplete( const S32 &pTime, const S32 &pDelta );
|
||||
|
||||
// Console Declaration.
|
||||
|
||||
DECLARE_CONOBJECT( VShapeAnimationEvent );
|
||||
|
||||
public:
|
||||
|
||||
// Property Methods.
|
||||
|
||||
F32 getAnimationPosition( const S32 &pTime );
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // _VT_VSHAPEANIMATIONEVENT_H_
|
||||
185
Engine/source/Verve/Extension/Animation/VShapeAnimationTrack.cpp
Normal file
185
Engine/source/Verve/Extension/Animation/VShapeAnimationTrack.cpp
Normal file
|
|
@ -0,0 +1,185 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "Verve/Extension/Animation/VShapeAnimationTrack.h"
|
||||
#include "Verve/Extension/Animation/VShapeAnimationEvent.h"
|
||||
#include "Verve/Core/VGroup.h"
|
||||
|
||||
#include "console/consoleTypes.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
IMPLEMENT_CONOBJECT( VShapeAnimationTrack );
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
VShapeAnimationTrack::VShapeAnimationTrack( void ) :
|
||||
mThreadIndex( 0 )
|
||||
{
|
||||
setLabel( "AnimationTrack" );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void VShapeAnimationTrack::initPersistFields( void )
|
||||
{
|
||||
Parent::initPersistFields();
|
||||
|
||||
addField( "ThreadIndex", TypeS32, Offset( mThreadIndex, VShapeAnimationTrack ), "The index of the Animation Thread to play." );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Controller Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VShapeAnimationTrack::onControllerEvent( pEvent );
|
||||
//
|
||||
// When the controller's state changes, this method is called. If the
|
||||
// controller is paused, or stops playing, then the animation will cease to
|
||||
// play. If the controller resumes play, the animation will continue.
|
||||
//
|
||||
// For a full list of possible events, see the 'eControllerEventType'
|
||||
// declaration in VController.h.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
bool VShapeAnimationTrack::onControllerEvent( VController::eControllerEventType pEvent )
|
||||
{
|
||||
if ( !Parent::onControllerEvent( pEvent ) )
|
||||
{
|
||||
// Skip.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enabled?
|
||||
if ( !isEnabled() )
|
||||
{
|
||||
// Continue Processing Events.
|
||||
return true;
|
||||
}
|
||||
|
||||
switch ( pEvent )
|
||||
{
|
||||
case VController::k_EventPlay :
|
||||
{
|
||||
|
||||
// Play Animation.
|
||||
VTorque::setAnimationTimeScale( getSceneObject(), mThreadIndex, ( ( isControllerPlayingForward() ) ? 1.f : -1.f ) );
|
||||
|
||||
} break;
|
||||
|
||||
case VController::k_EventPause :
|
||||
case VController::k_EventStop :
|
||||
{
|
||||
|
||||
// Stop Animation.
|
||||
VTorque::setAnimationTimeScale( getSceneObject(), mThreadIndex, 0.f );
|
||||
|
||||
} break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// VShapeAnimationTrack::onControllerReset( pTime, pForward );
|
||||
//
|
||||
// Reset the animation state of the target object. If there is a Next Event,
|
||||
// then the animation is positioned accordingly.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void VShapeAnimationTrack::onControllerReset( const S32 &pTime, const bool &pForward )
|
||||
{
|
||||
VTorque::SceneObjectType *object = getSceneObject();
|
||||
if ( !object )
|
||||
{
|
||||
// Parent Call.
|
||||
Parent::onControllerReset( pTime, pForward );
|
||||
return;
|
||||
}
|
||||
|
||||
VShapeAnimationEvent *event;
|
||||
if ( getCurrentEvent( event ) )
|
||||
{
|
||||
// Stop Animation.
|
||||
VTorque::stopAnimation( object, mThreadIndex );
|
||||
}
|
||||
|
||||
// Parent Call.
|
||||
Parent::onControllerReset( pTime, pForward );
|
||||
|
||||
if ( getCurrentEvent( event ) )
|
||||
{
|
||||
// Play Animation.
|
||||
VTorque::playAnimation( object, mThreadIndex, event->mAnimationData );
|
||||
|
||||
// Set Position.
|
||||
VTorque::setAnimationPosition( object, mThreadIndex, event->getAnimationPosition( pTime ) );
|
||||
|
||||
// Stop Animation.
|
||||
VTorque::setAnimationTimeScale( object, mThreadIndex, 0.f );
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VT_EDITOR
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Debug Methods.
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
DefineEngineMethod( VShapeAnimationTrack, updateTrack, void, (),, "( void ) - Update the Track.\n"
|
||||
"@return No return value." )
|
||||
{
|
||||
for ( ITreeNode *node = object->mChildNode; node != NULL; node = node->mSiblingNextNode )
|
||||
{
|
||||
VShapeAnimationEvent *currEvent = ( VShapeAnimationEvent* )node;
|
||||
VShapeAnimationEvent *nextEvent = ( VShapeAnimationEvent* )node->mSiblingNextNode;
|
||||
if ( !currEvent->mAutoDuration )
|
||||
{
|
||||
// Skip.
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( VTorque::isAnimationLooping( object->getSceneObject(), currEvent->mAnimationData ) )
|
||||
{
|
||||
if ( !nextEvent )
|
||||
{
|
||||
// Update Duration.
|
||||
currEvent->setDuration( object->getControllerDuration() - currEvent->getTriggerTime() );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update Duration.
|
||||
currEvent->setDuration( mAbs( nextEvent->getTriggerTime() - currEvent->getTriggerTime() ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update Duration.
|
||||
currEvent->setDuration( ( S32 )( 1000 * VTorque::getAnimationDuration( object->getSceneObject(), currEvent->mAnimationData ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Verve
|
||||
// Copyright (C) 2014 - Violent Tulip
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to
|
||||
// deal in the Software without restriction, including without limitation the
|
||||
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
// sell copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
// IN THE SOFTWARE.
|
||||
//-----------------------------------------------------------------------------
|
||||
#ifndef _VT_VSHAPEANIMATIONTRACK_H_
|
||||
#define _VT_VSHAPEANIMATIONTRACK_H_
|
||||
|
||||
#ifndef _VT_VSCENEOBJECTTRACK_H_
|
||||
#include "Verve/Extension/SceneObject/VSceneObjectTrack.h"
|
||||
#endif
|
||||
|
||||
#ifndef _VT_TORQUE_ANIMATION_H_
|
||||
#include "Verve/Torque/TAnimation.h"
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
class VShapeAnimationTrack : public VSceneObjectTrack
|
||||
{
|
||||
typedef VSceneObjectTrack Parent;
|
||||
|
||||
U32 mThreadIndex;
|
||||
|
||||
public:
|
||||
|
||||
VShapeAnimationTrack( void );
|
||||
|
||||
static void initPersistFields( void );
|
||||
|
||||
// Controller Methods.
|
||||
|
||||
virtual bool onControllerEvent( VController::eControllerEventType pEvent );
|
||||
virtual void onControllerReset( const S32 &pTime, const bool &pForward );
|
||||
|
||||
// Console Declaration.
|
||||
|
||||
DECLARE_CONOBJECT( VShapeAnimationTrack );
|
||||
|
||||
public:
|
||||
|
||||
inline U32 &getThreadIndex( void ) { return mThreadIndex; };
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#endif // _VT_VSHAPEANIMATIONTRACK_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue