45 #pragma warning( disable: 4512 ) // assignment operator could not be generated
47 #include "display_frame.h"
51 #include "disti_assert.h"
52 #include "gls_resources.h"
59 #if GLS_VERSION_MAJOR < 4
60 # error GlsAnimation not tested with older versions of GL Studio. Use 4.x or higher.
71 , _propertyName( propertyName )
74 , _key( Detail::
g_nan )
75 , _doubleCurve( keyframeCurve )
76 , _baseCurve( keyframeCurve )
84 , _propertyName( propertyName )
87 , _key( Detail::
g_nan )
88 , _vectorCurve( keyframeCurve )
89 , _baseCurve( keyframeCurve )
97 , _propertyName( propertyName )
100 , _key( Detail::
g_nan )
101 , _quaternionCurve( keyframeCurve )
102 , _baseCurve( keyframeCurve )
110 , _propertyName( propertyName )
113 , _key( Detail::
g_nan )
114 , _stringCurve( keyframeCurve )
115 , _baseCurve( keyframeCurve )
123 , _propertyName( propertyName )
126 , _key( Detail::
g_nan )
127 , _colorCurve( keyframeCurve )
128 , _baseCurve( keyframeCurve )
136 , _propertyName( propertyName )
139 , _key( Detail::
g_nan )
140 , _doubleCurve( keyframeCurve )
141 , _baseCurve( keyframeCurve.get() )
149 , _propertyName( propertyName )
152 , _key( Detail::
g_nan )
153 , _vectorCurve( keyframeCurve )
154 , _baseCurve( keyframeCurve.get() )
162 , _propertyName( propertyName )
165 , _key( Detail::
g_nan )
166 , _quaternionCurve( keyframeCurve )
167 , _baseCurve( keyframeCurve.get() )
175 , _propertyName( propertyName )
178 , _key( Detail::
g_nan )
179 , _stringCurve( keyframeCurve )
180 , _baseCurve( keyframeCurve.get() )
188 , _propertyName( propertyName )
191 , _key( Detail::
g_nan )
192 , _colorCurve( keyframeCurve )
193 , _baseCurve( keyframeCurve.get() )
201 , _propertyName( propertyName )
204 , _key( Detail::
g_nan )
205 , _doubleCurve( keyframeCurve )
206 , _baseCurve( keyframeCurve.get() )
214 , _propertyName( propertyName )
217 , _key( Detail::
g_nan )
218 , _vectorCurve( keyframeCurve )
219 , _baseCurve( keyframeCurve.get() )
227 , _propertyName( propertyName )
230 , _key( Detail::
g_nan )
231 , _quaternionCurve( keyframeCurve )
232 , _baseCurve( keyframeCurve.get() )
240 , _propertyName( propertyName )
243 , _key( Detail::
g_nan )
244 , _stringCurve( keyframeCurve )
245 , _baseCurve( keyframeCurve.get() )
253 , _propertyName( propertyName )
256 , _key( Detail::
g_nan )
257 , _colorCurve( keyframeCurve )
258 , _baseCurve( keyframeCurve.get() )
267 return minMax.second - minMax.first;
288 std::cout <<
"Warning -- GlsKeyframeAnimation ('" << _propertyName <<
"'): DisplayFrame was not set or properties were not found. Ignoring call to SetKey().\n";
301 else if( _vectorCurve )
303 const Vector vec = _vectorCurve->
Interpolate( key );
304 #if GLS_VERSION_MAJOR == 4 && GLS_VERSION_MINOR < 5
308 if( _isDynamicTranslate )
310 _object->DynamicTranslate( vec );
314 _object->DynamicScale( vec );
318 #endif // GLS Version < 4.5
324 else if( _stringCurve )
328 else if( _colorCurve )
331 const glsColor color = _colorCurve->
Interpolate( key );
334 _object->SetFillColor( color );
357 return std::vector<std::string>( &_propertyName, &_propertyName + 1 );
363 if( propertyNames.size() > 0 )
365 _propertyName = propertyNames[ 0 ];
377 std::size_t startPos = 0;
378 while( (startPos = _propertyName.find(findStr, startPos) ) != std::string::npos )
380 _propertyName.replace(startPos, findStr.length(), replaceStr);
381 startPos += replaceStr.length();
396 bool GlsKeyframeAnimation::HandleSpecialCases( DisplayFrame*
const displayFrame )
402 const std::size_t lastDotPos = _propertyName.rfind(
'.');
403 if( lastDotPos != std::string::npos && lastDotPos != 0 && lastDotPos != _propertyName.size() - 1 )
405 const std::string prop = _propertyName.substr( lastDotPos + 1 );
406 if( prop ==
"FillColor" )
408 const std::string objName = _propertyName.substr( 0, lastDotPos );
410 _object = displayFrame->objects->FindByNameSameFrame( objName.c_str() );
413 _object = displayFrame->objects->FindByName( objName.c_str() );
418 std::cout <<
"Warning -- GlsKeyframeAnimation: '" << objName <<
"' was not found for FillColor pseudo-property. (Is the object name correct?)\n";
425 #if GLS_VERSION_MAJOR == 4 && GLS_VERSION_MINOR < 5
427 else if( _vectorCurve )
430 const std::size_t lastDotPos = _propertyName.rfind(
'.');
431 if( lastDotPos != std::string::npos && lastDotPos != 0 && lastDotPos != _propertyName.size() - 1 )
433 const std::string prop = _propertyName.substr( lastDotPos + 1 );
434 _isDynamicTranslate = (prop ==
"DynamicTranslate");
435 if( _isDynamicTranslate || prop ==
"DynamicScale" )
437 const std::string objName = _propertyName.substr( 0, lastDotPos );
438 _object = displayFrame->objects->FindByNameSameFrame( objName.c_str() );
441 _object = displayFrame->objects->FindByName( objName.c_str() );
446 std::cout <<
"Warning -- GlsKeyframeAnimation: '" << objName <<
"' was not found for " << prop <<
" property. (Is the object name correct?)\n";
450 if( dynamic_cast<Group*>( _object ) )
458 #endif // GLS Version < 4.5
465 DistiAssert( displayFrame );
467 if( HandleSpecialCases( displayFrame ) )
473 _attr = &displayFrame->Resource( _propertyName.c_str() );
476 if( dynamic_cast<DistiEmptyAttribute*>( _attr ) )
479 std::cout <<
"Warning -- GlsKeyframeAnimation: '" << _propertyName <<
"' was not found. (Does the property exist? Do you need to enable Runtime Attributes in the GL Studio Resources window?)\n";
491 return _attr || _object;
503 , _key( Detail::
g_nan )
504 , _minKey( std::numeric_limits<
Key>::infinity() )
505 , _maxKey( -std::numeric_limits<
Key>::infinity() )
516 , _key( Detail::
g_nan )
517 , _minKey( std::numeric_limits<
Key>::infinity() )
518 , _maxKey( -std::numeric_limits<
Key>::infinity() )
520 DistiAssert( animation );
534 DistiAssert( animation );
536 DistiAssert(
Detail::IsNaN( _key ) &&
"This animation has already been started. Cannot add to it now." );
539 _animationList.push_back( animation );
542 const KeyPair minMax = animation->GetMinMaxKeys();
543 _minKey = (std::min)( _minKey, minMax.first );
544 _maxKey = (std::max)( _maxKey, minMax.second );
550 if( _animationList.empty() )
554 return _maxKey - _minKey;
560 if( _animationList.empty() )
564 return KeyPair( _minKey, _maxKey );
571 DistiAssert( displayFrame );
572 bool allPropsFound =
true;
574 for( AnimationIter it = _animationList.begin(), end = _animationList.end(); it != end; ++it )
576 const bool thisPropFound = (*it)->SetDisplayFrame( displayFrame );
577 allPropsFound = allPropsFound && thisPropFound;
579 return allPropsFound;
585 if( _animationList.empty() )
590 for( AnimationIter it = _animationList.begin(), end = _animationList.end(); it != end; ++it )
592 if( !(*it)->IsReadyToAnimate() )
605 for( AnimationIter it = _animationList.begin(), end = _animationList.end(); it != end; ++it )
607 (*it)->SetKey( key );
630 for( AnimationIter it = _animationList.begin(), end = _animationList.end(); it != end; ++it )
639 std::vector<std::string> nameList;
640 nameList.reserve( _animationList.size() );
641 for( AnimationIter it = _animationList.begin(), end = _animationList.end(); it != end; ++it )
643 const std::vector<std::string> childNames = (*it)->GetPropertyNames();
644 nameList.insert( nameList.end(), childNames.begin(), childNames.end() );
653 for( AnimationIter it = _animationList.begin(), end = _animationList.end(); it != end; ++it )
655 if( i < propertyNames.size() )
657 std::vector<std::string> collectedNames;
659 for(j = 0; j < (*it)->CountPropertyNames(); ++j)
661 collectedNames.push_back(propertyNames[ i ]);
665 (*it)->RetargetPropertyNames(collectedNames);
670 std::cout <<
"Warning -- GlsKeyframeAnimation: More objects than names. \n";
675 if( i < propertyNames.size() )
678 std::cout <<
"Warning -- GlsKeyframeAnimation: More names than objects. \n";
686 for( AnimationIter it = _animationList.begin(), end = _animationList.end(); it != end; ++it )
688 (*it)->RetargetPropertyNames( findStr, replaceStr );
697 for( AnimationIter it = _animationList.begin(), end = _animationList.end(); it != end; ++it )
699 sum += (*it)->CountPropertyNames();
708 for( AnimationIter it = _animationList.begin(), end = _animationList.end(); it != end; ++it )
710 clone->Add( (*it)->Clone() );
718 Group*
const parentsGroup = parent->ParentGroup();
719 Group*
const childsGroup = child->ParentGroup();
721 int pos = parentsGroup->Position( parent );
723 parentsGroup->DeleteObject( parent );
724 childsGroup->DeleteObject( child );
726 const std::string name = parent->InstanceName();
727 parent->InstanceName( (name +
"_Parent").c_str() );
729 Group* group =
new Group();
730 group->InstanceName( name.c_str() );
731 group->InsertObject( parent );
732 group->InsertObject( child );
733 group->SetAvailableAttributes(
unsigned( DisplayObject::GLS_ATTRIBUTES_ALL ) );
734 parentsGroup->InsertObject( group,
true,
true, pos );
735 group->WorldRotationPoint( parent->WorldRotationPoint() );
741 DistiAssert( displayFrame );
742 GlsResourceFilter filter;
743 filter.NamesOnly(
true );
744 filter.GroupLevelsDown( -1 );
745 displayFrame->GetResources( stream, &filter );
static const KeyPair s_nanPair
Default value for remapping constructor parameter.
Size CountPropertyNames() const
Override from GlsAnimation.
stdortr1::shared_ptr< GlsAnimationCollection > Ptr
Alias for easier reading.
std::vector< std::string > GetPropertyNames() const
Override from GlsAnimation.
GlsKeyframeCurveBase::Key Key
Alias for easier reading.
void SetKey(const Key &key)
Override from GlsAnimation.
bool IsReadyToAnimate() const
Override from GlsAnimation.
GlsAnimation::Ptr Clone() const
Override from GlsAnimation.
GlsKeyframeCurveBase::Key Key
Alias for easier reading.
void Reset()
Override from GlsAnimation.
GlsAnimationCollection(const std::string &name, GlsAnimation *animation=0)
bool IsReadyToAnimate() const
Override from GlsAnimation.
KeyPair GetMinMaxKeys() const
Override from GlsAnimation.
stdortr1::shared_ptr< GlsAnimation > Ptr
Alias for easier reading.
GlsKeyframeCurveBase::Size Size
Alias for easier reading.
GlsKeyframeAnimation(const std::string &name, const std::string &propertyName, const GlsKeyframeCurve< double > *keyframeCurve)
void SetGlsAnimationParentChildRelationship(DisplayObject *const parent, DisplayObject *const child)
Establishes a parent-child relationship like that in Adobe After Effects that does not exist in the G...
bool SetDisplayFrame(DisplayFrame *displayFrame)
GlsKeyframeCurveBase::KeyPair KeyPair
Alias for easier reading.
void DumpResourceNames(DisplayFrame *const displayFrame, std::ostream &stream)
void RetargetPropertyNames(const std::vector< std::string > &propertyNames)
Override from GlsAnimation.
Key GetKeyRange() const
Override from GlsAnimation.
bool SetDisplayFrame(DisplayFrame *displayFrame)
GlsAnimation::Ptr Clone() const
Override from GlsAnimation.
void SetKey(const Key &key)
Override from GlsAnimation.
DisplayFrame * _displayFrame
The display frame used for retargeting.
GlsKeyframeCurveBase::KeyPair KeyPair
Alias for easier reading.
Base class for all animations.
Key GetKeyRange() const
Override from GlsAnimation.
void RetargetPropertyNames(const std::vector< std::string > &propertyNames)
Override from GlsAnimation.
const GlsKeyframeCurveBase::Key g_nan
Constant for not-a-number (NaN) for easier reading.
KeyPair GetMinMaxKeys() const
Override from GlsAnimation.
void Reset()
Override from GlsAnimation.
The GL Studio animation classes.
Value Interpolate(const Key &key) const
void Add(GlsAnimation *animation)
const std::string & GetName() const
Returns the given name of this animation sequence.
Key GetKey() const
Override from GlsAnimation.
Size GetKeyframeCount() const
Override from GlsKeyframeCurveBase.
Size CountPropertyNames() const
Override from GlsAnimation.
bool IsNaN(const double d)
Detects not-a-number (NaN)
virtual KeyPair GetMinMaxKeys() const =0
std::vector< std::string > GetPropertyNames() const
Override from GlsAnimation.