Coverage Report

Created: 2026-08-31 06:41

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
        OgreAssert(data, "VertexData must not be null");
225
0
        VertexAnimationTrack* ret = createVertexTrack(handle, animType);
226
227
0
        ret->setAssociatedVertexData(data);
228
229
0
        return ret;
230
0
    }
231
    //---------------------------------------------------------------------
232
    unsigned short Animation::getNumVertexTracks(void) const
233
0
    {
234
0
        return (unsigned short)mVertexTrackList.size();
235
0
    }
236
    //---------------------------------------------------------------------
237
    bool Animation::hasVertexTrack(unsigned short handle) const
238
0
    {
239
0
        return (mVertexTrackList.find(handle) != mVertexTrackList.end());
240
0
    }
241
    //---------------------------------------------------------------------
242
    VertexAnimationTrack* Animation::getVertexTrack(unsigned short handle) const
243
0
    {
244
0
        VertexTrackList::const_iterator i = mVertexTrackList.find(handle);
245
246
0
        if (i == mVertexTrackList.end())
247
0
        {
248
0
            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
249
0
                "Cannot find vertex track with the specified handle " +
250
0
                StringConverter::toString(handle),
251
0
                "Animation::getVertexTrack");
252
0
        }
253
254
0
        return i->second;
255
256
0
    }
257
    //---------------------------------------------------------------------
258
    void Animation::destroyVertexTrack(unsigned short handle)
259
0
    {
260
0
        VertexTrackList::iterator i = mVertexTrackList.find(handle);
261
262
0
        if (i != mVertexTrackList.end())
263
0
        {
264
0
            OGRE_DELETE  i->second;
265
0
            mVertexTrackList.erase(i);
266
0
            _keyFrameListChanged();
267
0
        }
268
0
    }
269
    //---------------------------------------------------------------------
270
    void Animation::destroyAllVertexTracks(void)
271
0
    {
272
0
        for (auto& v : mVertexTrackList)
273
0
        {
274
0
            OGRE_DELETE  v.second;
275
0
        }
276
0
        mVertexTrackList.clear();
277
0
        _keyFrameListChanged();
278
0
    }
279
    //---------------------------------------------------------------------
280
    void Animation::destroyAllTracks(void)
281
0
    {
282
0
        destroyAllNodeTracks();
283
0
        destroyAllNumericTracks();
284
0
        destroyAllVertexTracks();
285
0
    }
286
    //---------------------------------------------------------------------
287
    const String& Animation::getName(void) const
288
0
    {
289
0
        return mName;
290
0
    }
291
    //---------------------------------------------------------------------
292
    void Animation::apply(Real timePos, Real weight, Real scale)
293
0
    {
294
0
        _applyBaseKeyFrame();
295
296
        // Calculate time index for fast keyframe search
297
0
        TimeIndex timeIndex = _getTimeIndex(timePos);
298
299
0
        for (auto& i : mNodeTrackList)
300
0
        {
301
0
            i.second->apply(timeIndex, weight, scale);
302
0
        }
303
0
        for (auto& j : mNumericTrackList)
304
0
        {
305
0
            j.second->apply(timeIndex, weight, scale);
306
0
        }
307
0
        for (auto& k : mVertexTrackList)
308
0
        {
309
0
            k.second->apply(timeIndex, weight, scale);
310
0
        }
311
0
    }
312
    //---------------------------------------------------------------------
313
    void Animation::applyToNode(Node* node, Real timePos, Real weight, Real scale)
314
0
    {
315
0
        _applyBaseKeyFrame();
316
317
        // Calculate time index for fast keyframe search
318
0
        TimeIndex timeIndex = _getTimeIndex(timePos);
319
320
0
        for (auto& t : mNodeTrackList)
321
0
        {
322
0
            t.second->applyToNode(node, timeIndex, weight, scale);
323
0
        }
324
0
    }
325
    //---------------------------------------------------------------------
326
    void Animation::apply(Skeleton* skel, Real timePos, Real weight,
327
        Real scale)
328
0
    {
329
0
        _applyBaseKeyFrame();
330
331
        // Calculate time index for fast keyframe search
332
0
        TimeIndex timeIndex = _getTimeIndex(timePos);
333
334
0
        for (auto& t : mNodeTrackList)
335
0
        {
336
            // get bone to apply to
337
0
            Bone* b = skel->getBone(t.first);
338
0
            t.second->applyToNode(b, timeIndex, weight, scale);
339
0
        }
340
341
342
0
    }
343
    //---------------------------------------------------------------------
344
    void Animation::apply(Skeleton* skel, Real timePos, float weight,
345
      const AnimationState::BoneBlendMask* blendMask, Real scale)
346
0
    {
347
0
        _applyBaseKeyFrame();
348
349
        // Calculate time index for fast keyframe search
350
0
        TimeIndex timeIndex = _getTimeIndex(timePos);
351
352
0
        for (auto& t : mNodeTrackList)
353
0
        {
354
0
            Bone* b = skel->getBone(t.first);
355
0
            t.second->applyToNode(b, timeIndex, (*blendMask)[b->getHandle()] * weight, scale);
356
0
        }
357
0
    }
358
    //---------------------------------------------------------------------
359
    void Animation::apply(Entity* entity, Real timePos, Real weight,
360
        bool software, bool hardware)
361
0
    {
362
0
        _applyBaseKeyFrame();
363
364
        // Calculate time index for fast keyframe search
365
0
        TimeIndex timeIndex = _getTimeIndex(timePos);
366
367
0
        VertexTrackList::iterator i;
368
0
        for (auto& t : mVertexTrackList)
369
0
        {
370
0
            unsigned short handle = t.first;
371
0
            VertexAnimationTrack* track = t.second;
372
373
0
            VertexData* swVertexData;
374
0
            VertexData* hwVertexData;
375
0
            if (handle == 0)
376
0
            {
377
                // shared vertex data
378
0
                swVertexData = entity->_getSoftwareVertexAnimVertexData();
379
0
                hwVertexData = entity->_getHardwareVertexAnimVertexData();
380
0
                entity->_markBuffersUsedForAnimation();
381
0
            }
382
0
            else
383
0
            {
384
                // sub entity vertex data (-1)
385
0
                SubEntity* s = entity->getSubEntity(handle - 1);
386
                // Skip this track if subentity is not visible
387
0
                if (!s->isVisible())
388
0
                    continue;
389
0
                swVertexData = s->_getSoftwareVertexAnimVertexData();
390
0
                hwVertexData = s->_getHardwareVertexAnimVertexData();
391
0
                s->_markBuffersUsedForAnimation();
392
0
            }
393
            // Apply to both hardware and software, if requested
394
0
            if (software)
395
0
            {
396
0
                track->setTargetMode(VertexAnimationTrack::TM_SOFTWARE);
397
0
                track->applyToVertexData(swVertexData, timeIndex, weight,
398
0
                    &(entity->getMesh()->getPoseList()));
399
0
            }
400
0
            if (hardware)
401
0
            {
402
0
                track->setTargetMode(VertexAnimationTrack::TM_HARDWARE);
403
0
                track->applyToVertexData(hwVertexData, timeIndex, weight,
404
0
                    &(entity->getMesh()->getPoseList()));
405
0
            }
406
0
        }
407
408
0
    }
409
    //---------------------------------------------------------------------
410
    void Animation::applyToAnimable(const AnimableValuePtr& anim, Real timePos, Real weight, Real scale)
411
0
    {
412
0
        _applyBaseKeyFrame();
413
414
        // Calculate time index for fast keyframe search
415
0
        _getTimeIndex(timePos);
416
417
0
        for (auto& j : mNumericTrackList)
418
0
        {
419
0
            j.second->applyToAnimable(anim, timePos, weight, scale);
420
0
        }
421
0
   }
422
    //---------------------------------------------------------------------
423
    void Animation::applyToVertexData(VertexData* data, Real timePos, float weight)
424
0
    {
425
0
        _applyBaseKeyFrame();
426
427
        // Calculate time index for fast keyframe search
428
0
        TimeIndex timeIndex = _getTimeIndex(timePos);
429
430
0
        for (auto& k : mVertexTrackList)
431
0
        {
432
0
            k.second->applyToVertexData(data, timeIndex, weight);
433
0
        }
434
0
    }
435
    //---------------------------------------------------------------------
436
    void Animation::setInterpolationMode(InterpolationMode im)
437
0
    {
438
0
        mInterpolationMode = im;
439
0
    }
440
    //---------------------------------------------------------------------
441
    Animation::InterpolationMode Animation::getInterpolationMode(void) const
442
0
    {
443
0
        return mInterpolationMode;
444
0
    }
445
    //---------------------------------------------------------------------
446
    void Animation::setDefaultInterpolationMode(InterpolationMode im)
447
0
    {
448
0
        msDefaultInterpolationMode = im;
449
0
    }
450
    //---------------------------------------------------------------------
451
    Animation::InterpolationMode Animation::getDefaultInterpolationMode(void)
452
0
    {
453
0
        return msDefaultInterpolationMode;
454
0
    }
455
    //---------------------------------------------------------------------
456
    const Animation::NodeTrackList& Animation::_getNodeTrackList(void) const
457
0
    {
458
0
        return mNodeTrackList;
459
460
0
    }
461
    //---------------------------------------------------------------------
462
    const Animation::NumericTrackList& Animation::_getNumericTrackList(void) const
463
0
    {
464
0
        return mNumericTrackList;
465
0
    }
466
    //---------------------------------------------------------------------
467
    const Animation::VertexTrackList& Animation::_getVertexTrackList(void) const
468
0
    {
469
0
        return mVertexTrackList;
470
0
    }
471
    //---------------------------------------------------------------------
472
    void Animation::setRotationInterpolationMode(RotationInterpolationMode im)
473
0
    {
474
0
        mRotationInterpolationMode = im;
475
0
    }
476
    //---------------------------------------------------------------------
477
    Animation::RotationInterpolationMode Animation::getRotationInterpolationMode(void) const
478
0
    {
479
0
        return mRotationInterpolationMode;
480
0
    }
481
    //---------------------------------------------------------------------
482
    void Animation::setDefaultRotationInterpolationMode(RotationInterpolationMode im)
483
0
    {
484
0
        msDefaultRotationInterpolationMode = im;
485
0
    }
486
    //---------------------------------------------------------------------
487
    Animation::RotationInterpolationMode Animation::getDefaultRotationInterpolationMode(void)
488
0
    {
489
0
        return msDefaultRotationInterpolationMode;
490
0
    }
491
    //---------------------------------------------------------------------
492
    void Animation::optimise(bool discardIdentityNodeTracks)
493
0
    {
494
0
        optimiseNodeTracks(discardIdentityNodeTracks);
495
0
        optimiseVertexTracks();
496
497
0
    }
498
    //-----------------------------------------------------------------------
499
    void Animation::_collectIdentityNodeTracks(TrackHandleList& tracks) const
500
0
    {
501
0
        for (auto& t : mNodeTrackList)
502
0
        {
503
0
            const NodeAnimationTrack* track = t.second;
504
0
            if (track->hasNonZeroKeyFrames())
505
0
            {
506
0
                tracks.erase(t.first);
507
0
            }
508
0
        }
509
0
    }
510
    //-----------------------------------------------------------------------
511
    void Animation::_destroyNodeTracks(const TrackHandleList& tracks)
512
0
    {
513
0
        for (auto t : tracks)
514
0
        {
515
0
            destroyNodeTrack(t);
516
0
        }
517
0
    }
518
    //-----------------------------------------------------------------------
519
    void Animation::optimiseNodeTracks(bool discardIdentityTracks)
520
0
    {
521
        // Iterate over the node tracks and identify those with no useful keyframes
522
0
        std::list<unsigned short> tracksToDestroy;
523
0
        for (auto& t : mNodeTrackList)
524
0
        {
525
0
            NodeAnimationTrack* track = t.second;
526
0
            if (discardIdentityTracks && !track->hasNonZeroKeyFrames())
527
0
            {
528
                // mark the entire track for destruction
529
0
                tracksToDestroy.push_back(t.first);
530
0
            }
531
0
            else
532
0
            {
533
0
                track->optimise();
534
0
            }
535
0
        }
536
537
        // Now destroy the tracks we marked for death
538
0
        for(unsigned short& h : tracksToDestroy)
539
0
        {
540
0
            destroyNodeTrack(h);
541
0
        }
542
0
    }
543
    //-----------------------------------------------------------------------
544
    void Animation::optimiseVertexTracks(void)
545
0
    {
546
        // Iterate over the node tracks and identify those with no useful keyframes
547
0
        std::list<unsigned short> tracksToDestroy;
548
0
        for (auto& t : mVertexTrackList)
549
0
        {
550
0
            VertexAnimationTrack* track = t.second;
551
0
            if (!track->hasNonZeroKeyFrames())
552
0
            {
553
                // mark the entire track for destruction
554
0
                tracksToDestroy.push_back(t.first);
555
0
            }
556
0
            else
557
0
            {
558
0
                track->optimise();
559
0
            }
560
0
        }
561
562
        // Now destroy the tracks we marked for death
563
0
        for(unsigned short& h : tracksToDestroy)
564
0
        {
565
0
            destroyVertexTrack(h);
566
0
        }
567
0
    }
568
    //-----------------------------------------------------------------------
569
    Animation* Animation::clone(const String& newName) const
570
0
    {
571
0
        Animation* newAnim = OGRE_NEW Animation(newName, mLength);
572
0
        newAnim->mInterpolationMode = mInterpolationMode;
573
0
        newAnim->mRotationInterpolationMode = mRotationInterpolationMode;
574
575
        // Clone all tracks
576
0
        for (auto i : mNodeTrackList)
577
0
        {
578
0
            i.second->_clone(newAnim);
579
0
        }
580
0
        for (auto i : mNumericTrackList)
581
0
        {
582
0
            i.second->_clone(newAnim);
583
0
        }
584
0
        for (auto i : mVertexTrackList)
585
0
        {
586
0
            i.second->_clone(newAnim);
587
0
        }
588
589
0
        newAnim->_keyFrameListChanged();
590
0
        return newAnim;
591
592
0
    }
593
    //-----------------------------------------------------------------------
594
    TimeIndex Animation::_getTimeIndex(Real timePos) const
595
0
    {
596
        // Uncomment following statement for work as previous
597
        //return timePos;
598
599
        // Build keyframe time list on demand
600
0
        if (mKeyFrameTimesDirty)
601
0
        {
602
0
            buildKeyFrameTimeList();
603
0
        }
604
605
        // Wrap time
606
0
        Real totalAnimationLength = mLength;
607
608
0
        if( timePos > totalAnimationLength && totalAnimationLength > 0.0f )
609
0
            timePos = std::fmod( timePos, totalAnimationLength );
610
611
        // Not best practice, but prevent from crash
612
0
        if (mKeyFrameTimes.empty())
613
0
            return timePos;
614
615
        // Search for global index
616
0
        auto it = std::lower_bound(mKeyFrameTimes.begin(), mKeyFrameTimes.end() - 1, timePos);
617
0
        return TimeIndex(timePos, static_cast<uint>(std::distance(mKeyFrameTimes.begin(), it)));
618
0
    }
619
    //-----------------------------------------------------------------------
620
    void Animation::buildKeyFrameTimeList(void) const
621
0
    {
622
        // Clear old keyframe times
623
0
        mKeyFrameTimes.clear();
624
625
        // Collect all keyframe times from each track
626
0
        for (auto& i : mNodeTrackList)
627
0
        {
628
0
            i.second->_collectKeyFrameTimes(mKeyFrameTimes);
629
0
        }
630
0
        for (auto& j : mNumericTrackList)
631
0
        {
632
0
            j.second->_collectKeyFrameTimes(mKeyFrameTimes);
633
0
        }
634
0
        for (auto& k : mVertexTrackList)
635
0
        {
636
0
            k.second->_collectKeyFrameTimes(mKeyFrameTimes);
637
0
        }
638
639
        // Build global index to local index map for each track
640
0
        for (auto& i : mNodeTrackList)
641
0
        {
642
0
            i.second->_buildKeyFrameIndexMap(mKeyFrameTimes);
643
0
        }
644
0
        for (auto& j : mNumericTrackList)
645
0
        {
646
0
            j.second->_buildKeyFrameIndexMap(mKeyFrameTimes);
647
0
        }
648
0
        for (auto& k : mVertexTrackList)
649
0
        {
650
0
            k.second->_buildKeyFrameIndexMap(mKeyFrameTimes);
651
0
        }
652
653
        // Reset dirty flag
654
0
        mKeyFrameTimesDirty = false;
655
0
    }
656
    //-----------------------------------------------------------------------
657
    void Animation::setUseBaseKeyFrame(bool useBaseKeyFrame, Real keyframeTime, const String& baseAnimName)
658
0
    {
659
0
        if (useBaseKeyFrame != mUseBaseKeyFrame ||
660
0
            keyframeTime != mBaseKeyFrameTime ||
661
0
            baseAnimName != mBaseKeyFrameAnimationName)
662
0
        {
663
0
            mUseBaseKeyFrame = useBaseKeyFrame;
664
0
            mBaseKeyFrameTime = keyframeTime;
665
0
            mBaseKeyFrameAnimationName = baseAnimName;
666
0
        }
667
0
    }
668
    //-----------------------------------------------------------------------
669
    bool Animation::getUseBaseKeyFrame() const
670
0
    {
671
0
        return mUseBaseKeyFrame;
672
0
    }
673
    //-----------------------------------------------------------------------
674
    Real Animation::getBaseKeyFrameTime() const
675
0
    {
676
0
        return mBaseKeyFrameTime;
677
0
    }
678
    //-----------------------------------------------------------------------
679
    const String& Animation::getBaseKeyFrameAnimationName() const
680
0
    {
681
0
        return mBaseKeyFrameAnimationName;
682
0
    }
683
    //-----------------------------------------------------------------------
684
    void Animation::_applyBaseKeyFrame()
685
0
    {
686
0
        if (mUseBaseKeyFrame)
687
0
        {
688
0
            Animation* baseAnim = this;
689
0
            if (!mBaseKeyFrameAnimationName.empty() && mContainer)
690
0
                baseAnim = mContainer->getAnimation(mBaseKeyFrameAnimationName);
691
692
0
            if (baseAnim)
693
0
            {
694
0
                for (auto& i : mNodeTrackList)
695
0
                {
696
0
                    NodeAnimationTrack* track = i.second;
697
698
0
                    NodeAnimationTrack* baseTrack;
699
0
                    if (baseAnim == this)
700
0
                        baseTrack = track;
701
0
                    else
702
0
                        baseTrack = baseAnim->getNodeTrack(track->getHandle());
703
704
0
                    TransformKeyFrame kf(baseTrack, mBaseKeyFrameTime);
705
0
                    baseTrack->getInterpolatedKeyFrame(baseAnim->_getTimeIndex(mBaseKeyFrameTime), &kf);
706
0
                    track->_applyBaseKeyFrame(&kf);
707
0
                }
708
709
0
                for (auto& i : mVertexTrackList)
710
0
                {
711
0
                    VertexAnimationTrack* track = i.second;
712
713
0
                    if (track->getAnimationType() == VAT_POSE)
714
0
                    {
715
0
                        VertexAnimationTrack* baseTrack;
716
0
                        if (baseAnim == this)
717
0
                            baseTrack = track;
718
0
                        else
719
0
                            baseTrack = baseAnim->getVertexTrack(track->getHandle());
720
721
0
                        VertexPoseKeyFrame kf(baseTrack, mBaseKeyFrameTime);
722
0
                        baseTrack->getInterpolatedKeyFrame(baseAnim->_getTimeIndex(mBaseKeyFrameTime), &kf);
723
0
                        track->_applyBaseKeyFrame(&kf);
724
725
0
                    }
726
0
                }
727
728
0
            }
729
730
            // Re-base has been done, this is a one-way translation
731
0
            mUseBaseKeyFrame = false;
732
0
        }
733
734
0
    }
735
    //-----------------------------------------------------------------------
736
    void Animation::_notifyContainer(AnimationContainer* c)
737
0
    {
738
0
        mContainer = c;
739
0
    }
740
    //-----------------------------------------------------------------------
741
    AnimationContainer* Animation::getContainer()
742
0
    {
743
0
        return mContainer;
744
0
    }
745
}
746
747