Coverage Report

Created: 2025-11-11 06:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ogre/OgreMain/src/OgreAnimation.cpp
Line
Count
Source
1
/*
2
-----------------------------------------------------------------------------
3
This source file is part of OGRE
4
    (Object-oriented Graphics Rendering Engine)
5
For the latest info, see http://www.ogre3d.org/
6
7
Copyright (c) 2000-2014 Torus Knot Software Ltd
8
9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
of this software and associated documentation files (the "Software"), to deal
11
in the Software without restriction, including without limitation the rights
12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
copies of the Software, and to permit persons to whom the Software is
14
furnished to do so, subject to the following conditions:
15
16
The above copyright notice and this permission notice shall be included in
17
all copies or substantial portions of the Software.
18
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
THE SOFTWARE.
26
-----------------------------------------------------------------------------
27
*/
28
#include "OgreStableHeaders.h"
29
#include "OgreAnimation.h"
30
#include "OgreKeyFrame.h"
31
32
namespace Ogre {
33
34
    Animation::InterpolationMode Animation::msDefaultInterpolationMode = Animation::IM_LINEAR;
35
    Animation::RotationInterpolationMode
36
        Animation::msDefaultRotationInterpolationMode = Animation::RIM_LINEAR;
37
    //---------------------------------------------------------------------
38
    Animation::Animation(const String& name, Real length)
39
0
        : mName(name)
40
0
        , mLength(length)
41
0
        , mInterpolationMode(msDefaultInterpolationMode)
42
0
        , mRotationInterpolationMode(msDefaultRotationInterpolationMode)
43
0
        , mKeyFrameTimesDirty(false)
44
0
        , mUseBaseKeyFrame(false)
45
0
        , mBaseKeyFrameTime(0.0f)
46
0
        , mBaseKeyFrameAnimationName(BLANKSTRING)
47
0
        , mContainer(0)
48
0
    {
49
0
    }
50
    //---------------------------------------------------------------------
51
    Animation::~Animation()
52
0
    {
53
0
        destroyAllTracks();
54
0
    }
55
    //---------------------------------------------------------------------
56
    Real Animation::getLength(void) const
57
0
    {
58
0
        return mLength;
59
0
    }
60
    //---------------------------------------------------------------------
61
    void Animation::setLength(Real len)
62
0
    {
63
0
        mLength = len;
64
0
    }
65
    //---------------------------------------------------------------------
66
    NodeAnimationTrack* Animation::createNodeTrack(unsigned short handle)
67
0
    {
68
0
        if (hasNodeTrack(handle))
69
0
        {
70
0
            OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
71
0
                "Node track with the specified handle " +
72
0
                StringConverter::toString(handle) + " already exists",
73
0
                "Animation::createNodeTrack");
74
0
        }
75
76
0
        NodeAnimationTrack* ret = OGRE_NEW NodeAnimationTrack(this, handle);
77
78
0
        mNodeTrackList[handle] = ret;
79
0
        return ret;
80
0
    }
81
    //---------------------------------------------------------------------
82
    NodeAnimationTrack* Animation::createNodeTrack(unsigned short handle, Node* node)
83
0
    {
84
0
        NodeAnimationTrack* ret = createNodeTrack(handle);
85
86
0
        ret->setAssociatedNode(node);
87
88
0
        return ret;
89
0
    }
90
    //---------------------------------------------------------------------
91
    unsigned short Animation::getNumNodeTracks(void) const
92
0
    {
93
0
        return (unsigned short)mNodeTrackList.size();
94
0
    }
95
    //---------------------------------------------------------------------
96
    bool Animation::hasNodeTrack(unsigned short handle) const
97
0
    {
98
0
        return (mNodeTrackList.find(handle) != mNodeTrackList.end());
99
0
    }
100
    //---------------------------------------------------------------------
101
    NodeAnimationTrack* Animation::getNodeTrack(unsigned short handle) const
102
0
    {
103
0
        NodeTrackList::const_iterator i = mNodeTrackList.find(handle);
104
105
0
        if (i == mNodeTrackList.end())
106
0
        {
107
0
            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
108
0
                "Cannot find node track with the specified handle " +
109
0
                StringConverter::toString(handle),
110
0
                "Animation::getNodeTrack");
111
0
        }
112
113
0
        return i->second;
114
115
0
    }
116
    //---------------------------------------------------------------------
117
    void Animation::destroyNodeTrack(unsigned short handle)
118
0
    {
119
0
        NodeTrackList::iterator i = mNodeTrackList.find(handle);
120
121
0
        if (i != mNodeTrackList.end())
122
0
        {
123
0
            OGRE_DELETE i->second;
124
0
            mNodeTrackList.erase(i);
125
0
            _keyFrameListChanged();
126
0
        }
127
0
    }
128
    //---------------------------------------------------------------------
129
    void Animation::destroyAllNodeTracks(void)
130
0
    {
131
0
        for (auto& t : mNodeTrackList)
132
0
        {
133
0
            OGRE_DELETE t.second;
134
0
        }
135
0
        mNodeTrackList.clear();
136
0
        _keyFrameListChanged();
137
0
    }
138
    //---------------------------------------------------------------------
139
    NumericAnimationTrack* Animation::createNumericTrack(unsigned short handle, const AnimableValuePtr& anim)
140
0
    {
141
0
        if (hasNumericTrack(handle))
142
0
        {
143
0
            OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
144
0
                "Numeric track with the specified handle " +
145
0
                StringConverter::toString(handle) + " already exists",
146
0
                "Animation::createNumericTrack");
147
0
        }
148
149
0
        NumericAnimationTrack* ret = OGRE_NEW NumericAnimationTrack(this, handle, anim);
150
151
0
        mNumericTrackList[handle] = ret;
152
0
        return ret;
153
0
    }
154
    //---------------------------------------------------------------------
155
    unsigned short Animation::getNumNumericTracks(void) const
156
0
    {
157
0
        return (unsigned short)mNumericTrackList.size();
158
0
    }
159
    //---------------------------------------------------------------------
160
    bool Animation::hasNumericTrack(unsigned short handle) const
161
0
    {
162
0
        return (mNumericTrackList.find(handle) != mNumericTrackList.end());
163
0
    }
164
    //---------------------------------------------------------------------
165
    NumericAnimationTrack* Animation::getNumericTrack(unsigned short handle) const
166
0
    {
167
0
        NumericTrackList::const_iterator i = mNumericTrackList.find(handle);
168
169
0
        if (i == mNumericTrackList.end())
170
0
        {
171
0
            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
172
0
                "Cannot find numeric track with the specified handle " +
173
0
                StringConverter::toString(handle),
174
0
                "Animation::getNumericTrack");
175
0
        }
176
177
0
        return i->second;
178
179
0
    }
180
    //---------------------------------------------------------------------
181
    void Animation::destroyNumericTrack(unsigned short handle)
182
0
    {
183
0
        NumericTrackList::iterator i = mNumericTrackList.find(handle);
184
185
0
        if (i != mNumericTrackList.end())
186
0
        {
187
0
            OGRE_DELETE i->second;
188
0
            mNumericTrackList.erase(i);
189
0
            _keyFrameListChanged();
190
0
        }
191
0
    }
192
    //---------------------------------------------------------------------
193
    void Animation::destroyAllNumericTracks(void)
194
0
    {
195
0
        for (auto& t : mNumericTrackList)
196
0
        {
197
0
            OGRE_DELETE t.second;
198
0
        }
199
0
        mNumericTrackList.clear();
200
0
        _keyFrameListChanged();
201
0
    }
202
    //---------------------------------------------------------------------
203
    VertexAnimationTrack* Animation::createVertexTrack(unsigned short handle,
204
        VertexAnimationType animType)
205
0
    {
206
0
        if (hasVertexTrack(handle))
207
0
        {
208
0
            OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
209
0
                "Vertex track with the specified handle " +
210
0
                StringConverter::toString(handle) + " already exists",
211
0
                "Animation::createVertexTrack");
212
0
        }
213
214
0
        VertexAnimationTrack* ret = OGRE_NEW VertexAnimationTrack(this, handle, animType);
215
216
0
        mVertexTrackList[handle] = ret;
217
0
        return ret;
218
219
0
    }
220
    //---------------------------------------------------------------------
221
    VertexAnimationTrack* Animation::createVertexTrack(unsigned short handle,
222
        VertexData* data, VertexAnimationType animType)
223
0
    {
224
0
        VertexAnimationTrack* ret = createVertexTrack(handle, animType);
225
226
0
        ret->setAssociatedVertexData(data);
227
228
0
        return ret;
229
0
    }
230
    //---------------------------------------------------------------------
231
    unsigned short Animation::getNumVertexTracks(void) const
232
0
    {
233
0
        return (unsigned short)mVertexTrackList.size();
234
0
    }
235
    //---------------------------------------------------------------------
236
    bool Animation::hasVertexTrack(unsigned short handle) const
237
0
    {
238
0
        return (mVertexTrackList.find(handle) != mVertexTrackList.end());
239
0
    }
240
    //---------------------------------------------------------------------
241
    VertexAnimationTrack* Animation::getVertexTrack(unsigned short handle) const
242
0
    {
243
0
        VertexTrackList::const_iterator i = mVertexTrackList.find(handle);
244
245
0
        if (i == mVertexTrackList.end())
246
0
        {
247
0
            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
248
0
                "Cannot find vertex track with the specified handle " +
249
0
                StringConverter::toString(handle),
250
0
                "Animation::getVertexTrack");
251
0
        }
252
253
0
        return i->second;
254
255
0
    }
256
    //---------------------------------------------------------------------
257
    void Animation::destroyVertexTrack(unsigned short handle)
258
0
    {
259
0
        VertexTrackList::iterator i = mVertexTrackList.find(handle);
260
261
0
        if (i != mVertexTrackList.end())
262
0
        {
263
0
            OGRE_DELETE  i->second;
264
0
            mVertexTrackList.erase(i);
265
0
            _keyFrameListChanged();
266
0
        }
267
0
    }
268
    //---------------------------------------------------------------------
269
    void Animation::destroyAllVertexTracks(void)
270
0
    {
271
0
        for (auto& v : mVertexTrackList)
272
0
        {
273
0
            OGRE_DELETE  v.second;
274
0
        }
275
0
        mVertexTrackList.clear();
276
0
        _keyFrameListChanged();
277
0
    }
278
    //---------------------------------------------------------------------
279
    void Animation::destroyAllTracks(void)
280
0
    {
281
0
        destroyAllNodeTracks();
282
0
        destroyAllNumericTracks();
283
0
        destroyAllVertexTracks();
284
0
    }
285
    //---------------------------------------------------------------------
286
    const String& Animation::getName(void) const
287
0
    {
288
0
        return mName;
289
0
    }
290
    //---------------------------------------------------------------------
291
    void Animation::apply(Real timePos, Real weight, Real scale)
292
0
    {
293
0
        _applyBaseKeyFrame();
294
295
        // Calculate time index for fast keyframe search
296
0
        TimeIndex timeIndex = _getTimeIndex(timePos);
297
298
0
        for (auto& i : mNodeTrackList)
299
0
        {
300
0
            i.second->apply(timeIndex, weight, scale);
301
0
        }
302
0
        for (auto& j : mNumericTrackList)
303
0
        {
304
0
            j.second->apply(timeIndex, weight, scale);
305
0
        }
306
0
        for (auto& k : mVertexTrackList)
307
0
        {
308
0
            k.second->apply(timeIndex, weight, scale);
309
0
        }
310
0
    }
311
    //---------------------------------------------------------------------
312
    void Animation::applyToNode(Node* node, Real timePos, Real weight, Real scale)
313
0
    {
314
0
        _applyBaseKeyFrame();
315
316
        // Calculate time index for fast keyframe search
317
0
        TimeIndex timeIndex = _getTimeIndex(timePos);
318
319
0
        for (auto& t : mNodeTrackList)
320
0
        {
321
0
            t.second->applyToNode(node, timeIndex, weight, scale);
322
0
        }
323
0
    }
324
    //---------------------------------------------------------------------
325
    void Animation::apply(Skeleton* skel, Real timePos, Real weight,
326
        Real scale)
327
0
    {
328
0
        _applyBaseKeyFrame();
329
330
        // Calculate time index for fast keyframe search
331
0
        TimeIndex timeIndex = _getTimeIndex(timePos);
332
333
0
        for (auto& t : mNodeTrackList)
334
0
        {
335
            // get bone to apply to
336
0
            Bone* b = skel->getBone(t.first);
337
0
            t.second->applyToNode(b, timeIndex, weight, scale);
338
0
        }
339
340
341
0
    }
342
    //---------------------------------------------------------------------
343
    void Animation::apply(Skeleton* skel, Real timePos, float weight,
344
      const AnimationState::BoneBlendMask* blendMask, Real scale)
345
0
    {
346
0
        _applyBaseKeyFrame();
347
348
        // Calculate time index for fast keyframe search
349
0
        TimeIndex timeIndex = _getTimeIndex(timePos);
350
351
0
        for (auto& t : mNodeTrackList)
352
0
        {
353
0
            Bone* b = skel->getBone(t.first);
354
0
            t.second->applyToNode(b, timeIndex, (*blendMask)[b->getHandle()] * weight, scale);
355
0
        }
356
0
    }
357
    //---------------------------------------------------------------------
358
    void Animation::apply(Entity* entity, Real timePos, Real weight,
359
        bool software, bool hardware)
360
0
    {
361
0
        _applyBaseKeyFrame();
362
363
        // Calculate time index for fast keyframe search
364
0
        TimeIndex timeIndex = _getTimeIndex(timePos);
365
366
0
        VertexTrackList::iterator i;
367
0
        for (auto& t : mVertexTrackList)
368
0
        {
369
0
            unsigned short handle = t.first;
370
0
            VertexAnimationTrack* track = t.second;
371
372
0
            VertexData* swVertexData;
373
0
            VertexData* hwVertexData;
374
0
            if (handle == 0)
375
0
            {
376
                // shared vertex data
377
0
                swVertexData = entity->_getSoftwareVertexAnimVertexData();
378
0
                hwVertexData = entity->_getHardwareVertexAnimVertexData();
379
0
                entity->_markBuffersUsedForAnimation();
380
0
            }
381
0
            else
382
0
            {
383
                // sub entity vertex data (-1)
384
0
                SubEntity* s = entity->getSubEntity(handle - 1);
385
                // Skip this track if subentity is not visible
386
0
                if (!s->isVisible())
387
0
                    continue;
388
0
                swVertexData = s->_getSoftwareVertexAnimVertexData();
389
0
                hwVertexData = s->_getHardwareVertexAnimVertexData();
390
0
                s->_markBuffersUsedForAnimation();
391
0
            }
392
            // Apply to both hardware and software, if requested
393
0
            if (software)
394
0
            {
395
0
                track->setTargetMode(VertexAnimationTrack::TM_SOFTWARE);
396
0
                track->applyToVertexData(swVertexData, timeIndex, weight,
397
0
                    &(entity->getMesh()->getPoseList()));
398
0
            }
399
0
            if (hardware)
400
0
            {
401
0
                track->setTargetMode(VertexAnimationTrack::TM_HARDWARE);
402
0
                track->applyToVertexData(hwVertexData, timeIndex, weight,
403
0
                    &(entity->getMesh()->getPoseList()));
404
0
            }
405
0
        }
406
407
0
    }
408
    //---------------------------------------------------------------------
409
    void Animation::applyToAnimable(const AnimableValuePtr& anim, Real timePos, Real weight, Real scale)
410
0
    {
411
0
        _applyBaseKeyFrame();
412
413
        // Calculate time index for fast keyframe search
414
0
        _getTimeIndex(timePos);
415
416
0
        for (auto& j : mNumericTrackList)
417
0
        {
418
0
            j.second->applyToAnimable(anim, timePos, weight, scale);
419
0
        }
420
0
   }
421
    //---------------------------------------------------------------------
422
    void Animation::applyToVertexData(VertexData* data, Real timePos, float weight)
423
0
    {
424
0
        _applyBaseKeyFrame();
425
426
        // Calculate time index for fast keyframe search
427
0
        TimeIndex timeIndex = _getTimeIndex(timePos);
428
429
0
        for (auto& k : mVertexTrackList)
430
0
        {
431
0
            k.second->applyToVertexData(data, timeIndex, weight);
432
0
        }
433
0
    }
434
    //---------------------------------------------------------------------
435
    void Animation::setInterpolationMode(InterpolationMode im)
436
0
    {
437
0
        mInterpolationMode = im;
438
0
    }
439
    //---------------------------------------------------------------------
440
    Animation::InterpolationMode Animation::getInterpolationMode(void) const
441
0
    {
442
0
        return mInterpolationMode;
443
0
    }
444
    //---------------------------------------------------------------------
445
    void Animation::setDefaultInterpolationMode(InterpolationMode im)
446
0
    {
447
0
        msDefaultInterpolationMode = im;
448
0
    }
449
    //---------------------------------------------------------------------
450
    Animation::InterpolationMode Animation::getDefaultInterpolationMode(void)
451
0
    {
452
0
        return msDefaultInterpolationMode;
453
0
    }
454
    //---------------------------------------------------------------------
455
    const Animation::NodeTrackList& Animation::_getNodeTrackList(void) const
456
0
    {
457
0
        return mNodeTrackList;
458
459
0
    }
460
    //---------------------------------------------------------------------
461
    const Animation::NumericTrackList& Animation::_getNumericTrackList(void) const
462
0
    {
463
0
        return mNumericTrackList;
464
0
    }
465
    //---------------------------------------------------------------------
466
    const Animation::VertexTrackList& Animation::_getVertexTrackList(void) const
467
0
    {
468
0
        return mVertexTrackList;
469
0
    }
470
    //---------------------------------------------------------------------
471
    void Animation::setRotationInterpolationMode(RotationInterpolationMode im)
472
0
    {
473
0
        mRotationInterpolationMode = im;
474
0
    }
475
    //---------------------------------------------------------------------
476
    Animation::RotationInterpolationMode Animation::getRotationInterpolationMode(void) const
477
0
    {
478
0
        return mRotationInterpolationMode;
479
0
    }
480
    //---------------------------------------------------------------------
481
    void Animation::setDefaultRotationInterpolationMode(RotationInterpolationMode im)
482
0
    {
483
0
        msDefaultRotationInterpolationMode = im;
484
0
    }
485
    //---------------------------------------------------------------------
486
    Animation::RotationInterpolationMode Animation::getDefaultRotationInterpolationMode(void)
487
0
    {
488
0
        return msDefaultRotationInterpolationMode;
489
0
    }
490
    //---------------------------------------------------------------------
491
    void Animation::optimise(bool discardIdentityNodeTracks)
492
0
    {
493
0
        optimiseNodeTracks(discardIdentityNodeTracks);
494
0
        optimiseVertexTracks();
495
496
0
    }
497
    //-----------------------------------------------------------------------
498
    void Animation::_collectIdentityNodeTracks(TrackHandleList& tracks) const
499
0
    {
500
0
        for (auto& t : mNodeTrackList)
501
0
        {
502
0
            const NodeAnimationTrack* track = t.second;
503
0
            if (track->hasNonZeroKeyFrames())
504
0
            {
505
0
                tracks.erase(t.first);
506
0
            }
507
0
        }
508
0
    }
509
    //-----------------------------------------------------------------------
510
    void Animation::_destroyNodeTracks(const TrackHandleList& tracks)
511
0
    {
512
0
        for (auto t : tracks)
513
0
        {
514
0
            destroyNodeTrack(t);
515
0
        }
516
0
    }
517
    //-----------------------------------------------------------------------
518
    void Animation::optimiseNodeTracks(bool discardIdentityTracks)
519
0
    {
520
        // Iterate over the node tracks and identify those with no useful keyframes
521
0
        std::list<unsigned short> tracksToDestroy;
522
0
        for (auto& t : mNodeTrackList)
523
0
        {
524
0
            NodeAnimationTrack* track = t.second;
525
0
            if (discardIdentityTracks && !track->hasNonZeroKeyFrames())
526
0
            {
527
                // mark the entire track for destruction
528
0
                tracksToDestroy.push_back(t.first);
529
0
            }
530
0
            else
531
0
            {
532
0
                track->optimise();
533
0
            }
534
0
        }
535
536
        // Now destroy the tracks we marked for death
537
0
        for(unsigned short& h : tracksToDestroy)
538
0
        {
539
0
            destroyNodeTrack(h);
540
0
        }
541
0
    }
542
    //-----------------------------------------------------------------------
543
    void Animation::optimiseVertexTracks(void)
544
0
    {
545
        // Iterate over the node tracks and identify those with no useful keyframes
546
0
        std::list<unsigned short> tracksToDestroy;
547
0
        for (auto& t : mVertexTrackList)
548
0
        {
549
0
            VertexAnimationTrack* track = t.second;
550
0
            if (!track->hasNonZeroKeyFrames())
551
0
            {
552
                // mark the entire track for destruction
553
0
                tracksToDestroy.push_back(t.first);
554
0
            }
555
0
            else
556
0
            {
557
0
                track->optimise();
558
0
            }
559
0
        }
560
561
        // Now destroy the tracks we marked for death
562
0
        for(unsigned short& h : tracksToDestroy)
563
0
        {
564
0
            destroyVertexTrack(h);
565
0
        }
566
0
    }
567
    //-----------------------------------------------------------------------
568
    Animation* Animation::clone(const String& newName) const
569
0
    {
570
0
        Animation* newAnim = OGRE_NEW Animation(newName, mLength);
571
0
        newAnim->mInterpolationMode = mInterpolationMode;
572
0
        newAnim->mRotationInterpolationMode = mRotationInterpolationMode;
573
574
        // Clone all tracks
575
0
        for (auto i : mNodeTrackList)
576
0
        {
577
0
            i.second->_clone(newAnim);
578
0
        }
579
0
        for (auto i : mNumericTrackList)
580
0
        {
581
0
            i.second->_clone(newAnim);
582
0
        }
583
0
        for (auto i : mVertexTrackList)
584
0
        {
585
0
            i.second->_clone(newAnim);
586
0
        }
587
588
0
        newAnim->_keyFrameListChanged();
589
0
        return newAnim;
590
591
0
    }
592
    //-----------------------------------------------------------------------
593
    TimeIndex Animation::_getTimeIndex(Real timePos) const
594
0
    {
595
        // Uncomment following statement for work as previous
596
        //return timePos;
597
598
        // Build keyframe time list on demand
599
0
        if (mKeyFrameTimesDirty)
600
0
        {
601
0
            buildKeyFrameTimeList();
602
0
        }
603
604
        // Wrap time
605
0
        Real totalAnimationLength = mLength;
606
607
0
        if( timePos > totalAnimationLength && totalAnimationLength > 0.0f )
608
0
            timePos = std::fmod( timePos, totalAnimationLength );
609
610
        // Not best practice, but prevent from crash
611
0
        if (mKeyFrameTimes.empty())
612
0
            return timePos;
613
614
        // Search for global index
615
0
        auto it = std::lower_bound(mKeyFrameTimes.begin(), mKeyFrameTimes.end() - 1, timePos);
616
0
        return TimeIndex(timePos, static_cast<uint>(std::distance(mKeyFrameTimes.begin(), it)));
617
0
    }
618
    //-----------------------------------------------------------------------
619
    void Animation::buildKeyFrameTimeList(void) const
620
0
    {
621
        // Clear old keyframe times
622
0
        mKeyFrameTimes.clear();
623
624
        // Collect all keyframe times from each track
625
0
        for (auto& i : mNodeTrackList)
626
0
        {
627
0
            i.second->_collectKeyFrameTimes(mKeyFrameTimes);
628
0
        }
629
0
        for (auto& j : mNumericTrackList)
630
0
        {
631
0
            j.second->_collectKeyFrameTimes(mKeyFrameTimes);
632
0
        }
633
0
        for (auto& k : mVertexTrackList)
634
0
        {
635
0
            k.second->_collectKeyFrameTimes(mKeyFrameTimes);
636
0
        }
637
638
        // Build global index to local index map for each track
639
0
        for (auto& i : mNodeTrackList)
640
0
        {
641
0
            i.second->_buildKeyFrameIndexMap(mKeyFrameTimes);
642
0
        }
643
0
        for (auto& j : mNumericTrackList)
644
0
        {
645
0
            j.second->_buildKeyFrameIndexMap(mKeyFrameTimes);
646
0
        }
647
0
        for (auto& k : mVertexTrackList)
648
0
        {
649
0
            k.second->_buildKeyFrameIndexMap(mKeyFrameTimes);
650
0
        }
651
652
        // Reset dirty flag
653
0
        mKeyFrameTimesDirty = false;
654
0
    }
655
    //-----------------------------------------------------------------------
656
    void Animation::setUseBaseKeyFrame(bool useBaseKeyFrame, Real keyframeTime, const String& baseAnimName)
657
0
    {
658
0
        if (useBaseKeyFrame != mUseBaseKeyFrame ||
659
0
            keyframeTime != mBaseKeyFrameTime ||
660
0
            baseAnimName != mBaseKeyFrameAnimationName)
661
0
        {
662
0
            mUseBaseKeyFrame = useBaseKeyFrame;
663
0
            mBaseKeyFrameTime = keyframeTime;
664
0
            mBaseKeyFrameAnimationName = baseAnimName;
665
0
        }
666
0
    }
667
    //-----------------------------------------------------------------------
668
    bool Animation::getUseBaseKeyFrame() const
669
0
    {
670
0
        return mUseBaseKeyFrame;
671
0
    }
672
    //-----------------------------------------------------------------------
673
    Real Animation::getBaseKeyFrameTime() const
674
0
    {
675
0
        return mBaseKeyFrameTime;
676
0
    }
677
    //-----------------------------------------------------------------------
678
    const String& Animation::getBaseKeyFrameAnimationName() const
679
0
    {
680
0
        return mBaseKeyFrameAnimationName;
681
0
    }
682
    //-----------------------------------------------------------------------
683
    void Animation::_applyBaseKeyFrame()
684
0
    {
685
0
        if (mUseBaseKeyFrame)
686
0
        {
687
0
            Animation* baseAnim = this;
688
0
            if (!mBaseKeyFrameAnimationName.empty() && mContainer)
689
0
                baseAnim = mContainer->getAnimation(mBaseKeyFrameAnimationName);
690
691
0
            if (baseAnim)
692
0
            {
693
0
                for (auto& i : mNodeTrackList)
694
0
                {
695
0
                    NodeAnimationTrack* track = i.second;
696
697
0
                    NodeAnimationTrack* baseTrack;
698
0
                    if (baseAnim == this)
699
0
                        baseTrack = track;
700
0
                    else
701
0
                        baseTrack = baseAnim->getNodeTrack(track->getHandle());
702
703
0
                    TransformKeyFrame kf(baseTrack, mBaseKeyFrameTime);
704
0
                    baseTrack->getInterpolatedKeyFrame(baseAnim->_getTimeIndex(mBaseKeyFrameTime), &kf);
705
0
                    track->_applyBaseKeyFrame(&kf);
706
0
                }
707
708
0
                for (auto& i : mVertexTrackList)
709
0
                {
710
0
                    VertexAnimationTrack* track = i.second;
711
712
0
                    if (track->getAnimationType() == VAT_POSE)
713
0
                    {
714
0
                        VertexAnimationTrack* baseTrack;
715
0
                        if (baseAnim == this)
716
0
                            baseTrack = track;
717
0
                        else
718
0
                            baseTrack = baseAnim->getVertexTrack(track->getHandle());
719
720
0
                        VertexPoseKeyFrame kf(baseTrack, mBaseKeyFrameTime);
721
0
                        baseTrack->getInterpolatedKeyFrame(baseAnim->_getTimeIndex(mBaseKeyFrameTime), &kf);
722
0
                        track->_applyBaseKeyFrame(&kf);
723
724
0
                    }
725
0
                }
726
727
0
            }
728
729
            // Re-base has been done, this is a one-way translation
730
0
            mUseBaseKeyFrame = false;
731
0
        }
732
733
0
    }
734
    //-----------------------------------------------------------------------
735
    void Animation::_notifyContainer(AnimationContainer* c)
736
0
    {
737
0
        mContainer = c;
738
0
    }
739
    //-----------------------------------------------------------------------
740
    AnimationContainer* Animation::getContainer()
741
0
    {
742
0
        return mContainer;
743
0
    }
744
}
745
746