Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
   Copyright (c) 2018 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

/*Code references:
    http://nolimitsdesigns.com/game-design/open-asset-import-library-animation-loader/
*/

#ifndef SCENE_ANIMATOR_H_
#define SCENE_ANIMATOR_H_

#include "AnimationEvaluator.h"
#include "Core/Math/Headers/Line.h"

struct aiMesh;
struct aiNode;
struct aiScene;

namespace Divide {

namespace Attorney {
    class SceneAnimatorMeshImporter;
};

/// Calculates the global transformation matrix for the given internal node
void calculateBoneToWorldTransform(Bone* pInternalNode);
class ByteBuffer;
class MeshImporter;
class PlatformContext;
class SceneAnimator {
    friend class Attorney::SceneAnimatorMeshImporter;
   public:
    // index = frameIndex; entry = vectorIndex;
    typedef vectorImpl<I32> LineMap;
    // index = animationID;
    typedef vectorImpl<LineMap> LineCollection;

    SceneAnimator();
    ~SceneAnimator();

    /// This must be called to fill the SceneAnimator with valid data
    bool init(PlatformContext& context, Bone* skeleton, const vectorImpl<Bone*>& bones);
    /// Frees all memory and initializes everything to a default state
    void release(bool releaseAnimations = true);
    void save(PlatformContext& context, ByteBuffer& dataOut) const;
    void load(PlatformContext& context, ByteBuffer& dataIn);
    /// Lets the caller know if there is a skeleton present
    inline bool hasSkeleton() const { return _skeleton != nullptr; }
    /// The next two functions are good if you want to change the direction of
    /// the current animation.
    /// You could use a forward walking animation and reverse it to get a
    /// walking backwards
    inline void playAnimationForward(I32 animationIndex) {
        _animations[animationIndex]->playAnimationForward(true);
    }
    inline void playAnimationBackward(I32 animationIndex) {
        _animations[animationIndex]->playAnimationForward(false);
    }
    /// This function will adjust the current animations speed by a percentage.
    /// So, passing 100, would do nothing, passing 50, would decrease the speed
    /// by half, and 150 increase it by 50%
    inline void adjustAnimationSpeedBy(I32 animationIndex, const D64 percent) {
        std::shared_ptr<AnimEvaluator>& animation = _animations.at(animationIndex);
        animation->ticksPerSecond(animation->ticksPerSecond() * (percent / 100.0));
    }
    /// This will set the animation speed
    inline void adjustAnimationSpeedTo(I32 animationIndex,
                                       const D64 tickspersecond) {
        _animations[animationIndex]->ticksPerSecond(tickspersecond);
    }
    /// Get the animationspeed... in ticks per second
    inline D64 animationSpeed(I32 animationIndex) const {
        return _animations[animationIndex]->ticksPerSecond();
    }

    /// Get the transforms needed to pass to the vertex shader.
    /// This will wrap the dt value passed, so it is safe to pass 50000000 as a
    /// valid number
    inline I32 frameIndexForTimeStamp(I32 animationIndex, const D64 dt) const {
        return _animations[animationIndex]->frameIndexAt(dt);
    }

    inline const vectorImplBest<mat4<F32>>& transforms(I32 animationIndex, U32 index) const {
        return _animations[animationIndex]->transforms(index);
    }

    inline const AnimEvaluator& animationByIndex(I32 animationIndex) const {
        assert(IS_IN_RANGE_INCLUSIVE(animationIndex, 0, to_I32(_animations.size()) - 1));
        const std::shared_ptr<AnimEvaluator>& animation = _animations.at(animationIndex);
        assert(animation != nullptr);
        return *animation;
    }

    inline AnimEvaluator& animationByIndex(I32 animationIndex) {
        assert(IS_IN_RANGE_INCLUSIVE(animationIndex, 0, to_I32(_animations.size()) - 1));
        const std::shared_ptr<AnimEvaluator>& animation = _animations.at(animationIndex);
        assert(animation != nullptr);
        return *animation;
    }

    inline U32 frameCount(I32 animationIndex) const {
        return _animations[animationIndex]->frameCount();
    }

    inline const vectorImpl<std::shared_ptr<AnimEvaluator>>& animations() const {
        return _animations;
    }

    inline const stringImpl& animationName(I32 animationIndex) const {
        return _animations[animationIndex]->name();
    }

    inline bool animationID(const stringImpl& animationName, U32& ID) {
        hashMapImpl<U64, U32>::iterator itr =
            _animationNameToID.find(_ID_RT(animationName));
        if (itr != std::end(_animationNameToID)) {
            ID = itr->second;
            return true;
        }
        return false;
    }
    /// GetBoneTransform will return the matrix of the bone given its name and
    /// the time.
    /// Be careful with this to make sure and send the correct dt. If the dt is
    /// different from what the model is currently at,
    /// the transform will be off
    inline const mat4<F32>& boneTransform(I32 animationIndex, const D64 dt,
                                          const stringImpl& bname) {
        I32 boneID = boneIndex(bname);
        if (boneID != -1) {
            return boneTransform(animationIndex, dt, boneID);
        }

        _boneTransformCache.identity();
        return _boneTransformCache;
    }

    /// Same as above, except takes the index
    inline const mat4<F32>& boneTransform(I32 animationIndex, const D64 dt,
                                          I32 bindex) {
        if (bindex != -1) {
            return _animations[animationIndex]->transforms(dt).at(bindex);
        }

        _boneTransformCache.identity();
        return _boneTransformCache;
    }

    /// Get the bone's global transform
    inline const mat4<F32>& boneOffsetTransform(const stringImpl& bname) {
        Bone* bone = boneByName(bname);
        if (bone != nullptr) {
            AnimUtils::TransformMatrix(bone->_offsetMatrix, _boneTransformCache);
        }
        return _boneTransformCache;
    }

    Bone* boneByName(const stringImpl& name) const;
    /// GetBoneIndex will return the index of the bone given its name.
    /// The index can be used to index directly into the vector returned from
    /// GetTransform
    I32 boneIndex(const stringImpl& bname) const;
    const vectorImpl<Line>& skeletonLines(I32 animationIndex, const D64 dt);

    /// Returns the frame count of the longest registered animation
    inline U32 getMaxAnimationFrames() const {
        return _maximumAnimationFrames;
    }

    inline size_t boneCount() const {
        return _skeletonDepthCache;
    }

   private:
    bool init(PlatformContext& context);
    /// I/O operations
    void saveSkeleton(ByteBuffer& dataOut, Bone* pNode) const;
    Bone* loadSkeleton(ByteBuffer& dataIn, Bone* pNode);

    void updateTransforms(Bone* pNode);
    void calculate(I32 animationIndex, const D64 pTime);
    I32 createSkeleton(Bone* piNode,
                       const aiMatrix4x4& parent,
                       vectorImpl<Line>& lines,
                       bool rowMajor = false);

   private:
    /// Frame count of the longest registered animation
    U32 _maximumAnimationFrames;
    /// Root node of the internal scene structure
    Bone* _skeleton;
    I32   _skeletonDepthCache;
    vectorImpl<Bone*> _bones;
    /// A vector that holds each animation
    vectorImpl<std::shared_ptr<AnimEvaluator>> _animations;
    /// find animations quickly
    hashMapImpl<U64, U32> _animationNameToID;
    /// temp array of transforms
    vectorImpl<aiMatrix4x4> _transforms;
    mat4<F32> _boneTransformCache;
    LineCollection _skeletonLines;
    vectorImpl<vectorImpl<Line>> _skeletonLinesContainer;
};

namespace Attorney {
    class SceneAnimatorMeshImporter {
        private:
        static void registerAnimations(SceneAnimator& animator, const vectorImpl<std::shared_ptr<AnimEvaluator>>& animations) {
            size_t animationCount = animations.size();
            animator._animations.reserve(animationCount);
            for (size_t i = 0; i < animationCount; ++i) {
                animator._animations.push_back(animations[i]);
                hashAlg::insert(animator._animationNameToID, _ID_RT(animator._animations[i]->name()), to_U32(i));
            }
        }

        friend class Divide::MeshImporter;
    };
};

};  // namespace Divide

#endif // SCENE_ANIMATOR_H_

Commits for Divide-Framework/trunk/Source Code/Geometry/Animations/Headers/SceneAnimator.h

Diff revisions: vs.
Revision Author Commited Message
1029 Diff Diff IonutCava picture IonutCava Tue 30 Jan, 2018 17:28:39 +0000

[Ionut]
- Update copyright notices

923 Diff Diff IonutCava picture IonutCava Tue 01 Aug, 2017 22:23:24 +0000

[Ionut]
- Add (hack) new GL 4.6 KHR_NO_ERROR flag for non-GPU validated builds
- Disable GPU debug messages by default. Re-enabled only via a command line argument: “--enableGPUMessageGroups”.
- Cleanup GL texture and sampler binding
- Rework hash map insert and emplace
- Update SDL to 2.0.5

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

833 Diff Diff IonutCava picture IonutCava Thu 26 Jan, 2017 22:04:33 +0000

[IonutCava]
- Fix most build errors. Divide-Server does not build for now.

804 Diff Diff IonutCava picture IonutCava Thu 01 Dec, 2016 17:20:59 +0000

[IonutCava]
- Singleton elimination update Part I: get it to compile
— The following classes are no longer Singletons: GFXDevice, GL_API, DX_API, SFXWrapper, FmodWrapper, SDLWrapper, ALWrapper, PXDevice, InputInterface, RenderPassManager, SceneManager and ResourceManager;
— Refactor system to a Context / Component based implementation (Pass relevant context to objects: e.g. GFXDevice object to Textures, GUI to GUIElements, etc)
— Make devices and managers components of the kernel
— Allow multiple Resource caches to co-exist. This may prove useful for later when a more fragmented memory model is need (per frame / per scene / global caches / etc)

  • next steps: part II – cleanup/refactor new code, part III – optimise code, part IV – remove remaining Singletons (e.g. Application, ParamHandler, FrameListenerManager, Recast, PostFX and DebugInterface)
795 Diff Diff IonutCava picture IonutCava Wed 23 Nov, 2016 17:14:33 +0000

[IonutCava]
- Remove ULL. Use U64 instead
- Various small bug fixes and typos.

780 Diff Diff IonutCava picture IonutCava Tue 11 Oct, 2016 16:15:24 +0000

[IonutCava]
- AtomicCounter in glUniformBuffer is now based on a glGenericBuffer implementation
- GFXDevice <-> Camera relation cleaned up a bit
- Added a readback system for glGenericBuffer
- Fixed a bug with Z_PRE_PASS stage culling

750 Diff Diff IonutCava picture IonutCava Thu 07 Jul, 2016 16:02:03 +0000

[IonutCava]
- Static analysis based fixes and improvements

684 IonutCava picture IonutCava Wed 20 Apr, 2016 16:27:05 +0000

[IonutCava]
- More math template code cleanup