@@ -79,12 +79,17 @@ bool Scene::processScene() {
79
79
80
80
if (mSrcScene ){
81
81
if ( mSrcScene ->getImportSettings ().importAnimations ) {
82
- mAnimations = mSrcScene ->getAnimations ();
82
+ mAnimations .clear ();
83
+ // mAnimations = mSrcScene->getAnimations();
84
+ auto & srcAnims = mSrcScene ->getAnimations ();
85
+ for ( auto & srcA : srcAnims ) {
86
+ auto nanim = std::make_shared<ofxAssimp::Animation>( srcA );
87
+ mAnimations .push_back (nanim);
88
+ }
83
89
if (mAnimations .size () > 0 ) {
84
- // add a default mixer
85
- mAnimMixer = std::make_shared<AnimationMixer>();
86
- mAnimMixer ->add ( AnimationClip ( mAnimations [0 ], 1 .0f ));
87
- mAnimMixer ->getAnimationClip (0 ).animation .play ();
90
+ mAnimationIndex = -1 ; // set to -1 so it will trigger playing
91
+ setCurrentAnimation (0 );
92
+ getCurrentAnimation ().play ();
88
93
}
89
94
}
90
95
@@ -354,6 +359,13 @@ void Scene::flagSceneDirty() {
354
359
mBSceneDirty = true ;
355
360
}
356
361
362
+ std::shared_ptr<AnimationMixer> Scene::_getAnimationMixer () {
363
+ if ( !mAnimMixer ) {
364
+ mAnimMixer = std::make_shared<AnimationMixer>();
365
+ }
366
+ return mAnimMixer ;
367
+ }
368
+
357
369
void Scene::updateAnimations () {
358
370
if ( mAnimMixer ) {
359
371
mAnimMixer ->update (ofGetElapsedTimef ());
@@ -480,7 +492,10 @@ ofxAssimp::Animation& Scene::getCurrentAnimation() {
480
492
return dummyAnimation;
481
493
}
482
494
if ( mAnimMixer && mAnimMixer ->getNumAnimationClips () > 0 ) {
483
- return mAnimMixer ->getAnimationClips ().back ().animation ;
495
+ // return mAnimMixer->getAnimationClips().back().animation;
496
+ if ( auto alock = mAnimMixer ->getAnimationClips ().back ().animationWeak .lock () ) {
497
+ return *alock;
498
+ }
484
499
}
485
500
ofLogWarning (" ofxAssimp::Scene::getCurrentAnimation" ) << " does not have current animation!" ;
486
501
return dummyAnimation;
@@ -495,10 +510,11 @@ bool Scene::setCurrentAnimation( int aindex ) {
495
510
ofLogWarning (" ofxAssimp::Scene::setAnimation" ) << " already have this as the index!" ;
496
511
return false ;
497
512
}
513
+ _getAnimationMixer ();
498
514
mAnimationIndex = ofClamp (aindex, 0 , mAnimations .size ()-1 );
499
515
mAnimMixer ->removeAll ();
500
516
mAnimMixer ->add ( AnimationClip ( mAnimations [mAnimationIndex ], 1 .0f ));
501
- mAnimMixer ->getAnimationClips ().back ().animation . reset ();
517
+ mAnimMixer ->getAnimationClips ().back ().resetAnimation ();
502
518
return true ;
503
519
}
504
520
@@ -516,10 +532,11 @@ bool Scene::transitionCurrentAnimation( int aTargetAnimIndex, float aduration )
516
532
ofLogWarning (" ofxAssimp::Scene::setAnimation" ) << " no animations!!" ;
517
533
return false ;
518
534
}
535
+ _getAnimationMixer ();
519
536
mAnimationIndex = ofClamp (aTargetAnimIndex, 0 , mAnimations .size ()-1 );
520
537
mAnimMixer ->add ( AnimationClip ( mAnimations [mAnimationIndex ], 1 .f -mAnimMixer ->getTotalClipWeights () ));
521
- mAnimMixer ->transition (mAnimations [mAnimationIndex ]. getName (), aduration );
522
- mAnimMixer ->getAnimationClips ().back ().animation . reset ();
538
+ mAnimMixer ->transition (mAnimations [mAnimationIndex ]-> getName (), aduration );
539
+ mAnimMixer ->getAnimationClips ().back ().resetAnimation ();
523
540
return true ;
524
541
}
525
542
@@ -539,7 +556,7 @@ bool Scene::hasAnimation( const std::string& aname ) {
539
556
int Scene::getAnimationIndex ( const std::string& aname ) {
540
557
int tindex = -1 ;
541
558
for ( int i = 0 ; i < (int )mAnimations .size (); i++ ) {
542
- if ( mAnimations [i]. getName () == aname ) {
559
+ if ( mAnimations [i] && mAnimations [i]-> getName () == aname ) {
543
560
tindex = i;
544
561
break ;
545
562
}
@@ -553,7 +570,7 @@ ofxAssimp::Animation& Scene::getAnimation(int aindex) {
553
570
return dummyAnimation;
554
571
}
555
572
aindex = ofClamp (aindex, 0 , mAnimations .size ()-1 );
556
- return mAnimations [aindex];
573
+ return * mAnimations [aindex];
557
574
}
558
575
559
576
ofxAssimp::Animation& Scene::getAnimation (const std::string& aname) {
@@ -579,10 +596,11 @@ bool Scene::addAnimation( int aSrcAnimIndex, const std::string& aNewAnimName, fl
579
596
return false ;
580
597
}
581
598
auto & canim = mAnimations [aSrcAnimIndex];
582
- ofxAssimp::Animation nanim = mAnimations [aSrcAnimIndex];
583
- nanim.setup (aStartTick, aEndTick);
584
- nanim.setName (aNewAnimName);
585
- nanim.setLoopType (aLoopType);
599
+ // ofxAssimp::Animation nanim = mAnimations[aSrcAnimIndex];
600
+ auto nanim = std::make_shared<ofxAssimp::Animation>( *mAnimations [aSrcAnimIndex] );
601
+ nanim->setup (aStartTick, aEndTick);
602
+ nanim->setName (aNewAnimName);
603
+ nanim->setLoopType (aLoopType);
586
604
mAnimations .push_back (nanim);
587
605
return true ;
588
606
}
0 commit comments