/src/assimp/code/Common/TargetAnimation.h
Line | Count | Source |
1 | | /* |
2 | | Open Asset Import Library (assimp) |
3 | | ---------------------------------------------------------------------- |
4 | | |
5 | | Copyright (c) 2006-2026, assimp team |
6 | | |
7 | | All rights reserved. |
8 | | |
9 | | Redistribution and use of this software in source and binary forms, |
10 | | with or without modification, are permitted provided that the |
11 | | following conditions are met: |
12 | | |
13 | | * Redistributions of source code must retain the above |
14 | | copyright notice, this list of conditions and the |
15 | | following disclaimer. |
16 | | |
17 | | * Redistributions in binary form must reproduce the above |
18 | | copyright notice, this list of conditions and the |
19 | | following disclaimer in the documentation and/or other |
20 | | materials provided with the distribution. |
21 | | |
22 | | * Neither the name of the assimp team, nor the names of its |
23 | | contributors may be used to endorse or promote products |
24 | | derived from this software without specific prior |
25 | | written permission of the assimp team. |
26 | | |
27 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
30 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
31 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
32 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
33 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
34 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
35 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
36 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
37 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | | |
39 | | ---------------------------------------------------------------------- |
40 | | */ |
41 | | |
42 | | /** @file Defines a helper class for the ASE and 3DS loaders to |
43 | | help them compute camera and spot light animation channels */ |
44 | | #ifndef AI_TARGET_ANIMATION_H_INC |
45 | | #define AI_TARGET_ANIMATION_H_INC |
46 | | |
47 | | #include <assimp/anim.h> |
48 | | #include <vector> |
49 | | |
50 | | namespace Assimp { |
51 | | |
52 | | // --------------------------------------------------------------------------- |
53 | | /** Helper class to iterate through all keys in an animation channel. |
54 | | * |
55 | | * Missing tracks are interpolated. This is a helper class for |
56 | | * TargetAnimationHelper, but it can be freely used for other purposes. |
57 | | */ |
58 | | class KeyIterator { |
59 | | public: |
60 | | // ------------------------------------------------------------------ |
61 | | /** Constructs a new key iterator |
62 | | * |
63 | | * @param _objPos Object position track. May be nullptr. |
64 | | * @param _targetObjPos Target object position track. May be nullptr. |
65 | | * @param defaultObjectPos Default object position to be used if |
66 | | * no animated track is available. May be nullptr. |
67 | | * @param defaultTargetPos Default target position to be used if |
68 | | * no animated track is available. May be nullptr. |
69 | | */ |
70 | | KeyIterator(const std::vector<aiVectorKey> *_objPos, |
71 | | const std::vector<aiVectorKey> *_targetObjPos, |
72 | | const aiVector3D *defaultObjectPos = nullptr, |
73 | | const aiVector3D *defaultTargetPos = nullptr); |
74 | | |
75 | | // ------------------------------------------------------------------ |
76 | | /** Returns true if all keys have been processed |
77 | | */ |
78 | 0 | bool Finished() const { return reachedEnd; } |
79 | | |
80 | | // ------------------------------------------------------------------ |
81 | | /** Increment the iterator |
82 | | */ |
83 | | void operator++(); |
84 | 0 | inline void operator++(int) { return ++(*this); } |
85 | | |
86 | | // ------------------------------------------------------------------ |
87 | | /** Getters to retrieve the current state of the iterator |
88 | | */ |
89 | 0 | inline const aiVector3D &GetCurPosition() const { return curPosition; } |
90 | | |
91 | 0 | inline const aiVector3D &GetCurTargetPosition() const { return curTargetPosition; } |
92 | | |
93 | 0 | inline double GetCurTime() const { return curTime; } |
94 | | |
95 | | private: |
96 | | //! Did we reach the end? |
97 | | bool reachedEnd; |
98 | | |
99 | | //! Represents the current position of the iterator |
100 | | aiVector3D curPosition, curTargetPosition; |
101 | | |
102 | | double curTime; |
103 | | |
104 | | //! Input tracks and the next key to process |
105 | | const std::vector<aiVectorKey> *objPos, *targetObjPos; |
106 | | |
107 | | unsigned int nextObjPos, nextTargetObjPos; |
108 | | std::vector<aiVectorKey> defaultObjPos, defaultTargetObjPos; |
109 | | }; |
110 | | |
111 | | // --------------------------------------------------------------------------- |
112 | | /** Helper class for the 3DS and ASE loaders to compute camera and spot light |
113 | | * animations. |
114 | | * |
115 | | * 3DS and ASE store the differently to Assimp - there is an animation |
116 | | * channel for the camera/spot light itself and a separate position |
117 | | * animation channels specifying the position of the camera/spot light |
118 | | * look-at target */ |
119 | | class TargetAnimationHelper { |
120 | | public: |
121 | | /// @brief The class constructor. |
122 | | TargetAnimationHelper() : |
123 | | targetPositions(nullptr), |
124 | 0 | objectPositions(nullptr) { |
125 | 0 | // empty |
126 | 0 | } |
127 | | |
128 | | /// @brief The class destructor. |
129 | | ~TargetAnimationHelper() = default; |
130 | | |
131 | | // ------------------------------------------------------------------ |
132 | | /** Sets the target animation channel |
133 | | * |
134 | | * This channel specifies the position of the camera/spot light |
135 | | * target at a specific position. |
136 | | * |
137 | | * @param targetPositions Translation channel*/ |
138 | | void SetTargetAnimationChannel(const std::vector<aiVectorKey> *targetPositions); |
139 | | |
140 | | // ------------------------------------------------------------------ |
141 | | /** Sets the main animation channel |
142 | | * |
143 | | * @param objectPositions Translation channel */ |
144 | | void SetMainAnimationChannel(const std::vector<aiVectorKey> *objectPositions); |
145 | | |
146 | | // ------------------------------------------------------------------ |
147 | | /** Sets the main animation channel to a fixed value |
148 | | * |
149 | | * @param fixed Fixed value for the main animation channel*/ |
150 | | void SetFixedMainAnimationChannel(const aiVector3D &fixed); |
151 | | |
152 | | // ------------------------------------------------------------------ |
153 | | /** Computes final animation channels |
154 | | * @param distanceTrack Receive camera translation keys ... != nullptr. */ |
155 | | void Process(std::vector<aiVectorKey> *distanceTrack); |
156 | | |
157 | | private: |
158 | | const std::vector<aiVectorKey> *targetPositions, *objectPositions; |
159 | | aiVector3D fixedMain; |
160 | | }; |
161 | | |
162 | | } // namespace Assimp |
163 | | |
164 | | #endif // include guard |