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
/*
   Copyright (c) 2014 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 ANIMATION_CONTROLLER_H_
#define ANIMATION_CONTROLLER_H_

#include <fstream>
#include "AnimationEvaluator.h"

struct aiNode;
struct aiScene;

namespace Divide {

class SceneAnimator{
public:
    typedef hashMapImpl<I32/*frameIndex*/, vectorAlg::vecSize/*vectorIntex*/> LineMap;
    typedef hashMapImpl<I32/*animationId*/, LineMap> LineCollection;

    SceneAnimator(): _skeleton(0)
    {
    }

    ~SceneAnimator()
    {
        Release(); 
    }

    /// This must be called to fill the SceneAnimator with valid data
    bool Init(const aiScene* pScene, U8 meshPointer);
    /// Frees all memory and initializes everything to a default state
    void Release();
    void Save(std::ofstream& file);
    void Load(std::ifstream& file);
    /// Lets the caller know if there is a skeleton present
    inline bool HasSkeleton() const { return !_bones.empty(); }
    /// 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 D32 percent) {
        _animations[animationIndex]._ticksPerSecond *= percent / 100.0f; 
    }
    /// This will set the animation speed
    inline void AdjustAnimationSpeedTo(I32 animationIndex, const D32 tickspersecond) { 
        _animations[animationIndex]._ticksPerSecond = tickspersecond; 
    }
    /// Get the animationspeed... in ticks per second
    inline F32 GetAnimationSpeed(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 vectorImpl<mat4<F32> >& GetTransforms(I32 animationIndex, const D32 dt) { 
        return _animations[animationIndex].GetTransforms(dt); 
    }
    inline vectorImpl<mat4<F32> >& GetTransformsByIndex(I32 animationIndex, U32 index) { 
        return _animations[animationIndex]._transforms[index]; 
    }
    inline I32 GetFrameIndex(I32 animationIndex) const { 
        return _animations[animationIndex].GetFrameIndex(); 
    }
    inline U32 GetFrameCount(I32 animationIndex) const { 
        return _animations[animationIndex].GetFrameCount(); 
    }
    inline const vectorImpl<AnimEvaluator>& GetAnimations() const { 
        return _animations; 
    }
    inline const stringImpl& GetAnimationName(I32 animationIndex) const { 
        return _animations[animationIndex]._name; 
    }
    inline bool GetAnimationID(const stringImpl& animationName, U32& id){
        hashMapImpl<stringImpl, U32>::iterator itr = _animationNameToId.find(animationName);
        if (itr != _animationNameToId.end()) {
            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>& GetBoneTransform(I32 animationIndex, const D32 dt, const stringImpl& bname) { 
        I32 bindex = GetBoneIndex(bname);
        if (bindex == -1) 
            return _cacheIdentity;
        return _animations[animationIndex].GetTransforms(dt)[bindex]; 
    }

    /// Same as above, except takes the index
    inline const mat4<F32>& GetBoneTransform(I32 animationIndex, const D32 dt, U32 bindex) { 
        return _animations[animationIndex].GetTransforms(dt)[bindex]; 
    }
	/// Get the bone's global transform
	inline const mat4<F32>& GetBoneOffsetTransform(const stringImpl& bname) {
		I32 bindex=GetBoneIndex(bname);
		if(bindex != -1) {
			AnimUtils::TransformMatrix(_bonesByName[bname]->_offsetMatrix, _cacheIdentity);
		}
		return _cacheIdentity;
	}

    /// A vector that holds each animation
    vectorImpl<AnimEvaluator> _animations;
    Bone* GetBoneByName(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 GetBoneIndex(const stringImpl& bname) const;
    const vectorImpl<Line >& getSkeletonLines(I32 animationIndex, const D32 dt);

    size_t GetBoneCount() const { return _bones.size(); }

private:

    ///I/O operations
    void SaveSkeleton(std::ofstream& file, Bone* pNode);
    Bone* LoadSkeleton(std::ifstream& file, Bone* pNode);

    void UpdateTransforms(Bone* pNode);
    void Calculate(I32 animationIndex, const D32 pTime);
    void CalcBoneMatrices();
    /// Calculates the global transformation matrix for the given internal node
    void CalculateBoneToWorldTransform(Bone* pInternalNode);
    void ExtractAnimations(const aiScene* pScene);
    /// Recursively creates an internal node structure matching the current scene and animation.
    Bone* CreateBoneTree( aiNode* pNode, Bone* parent);

    I32 CreateSkeleton(Bone* piNode, const aiMatrix4x4& parent, vectorImpl<Line >& lines);

private:
    Bone* _skeleton;/** Root node of the internal scene structure */

    hashMapImpl<stringImpl, Bone*> _bonesByName;/** Name to node map to quickly find nodes by their name */
    hashMapImpl<stringImpl, U32>   _bonesToIndex;/** Name to node map to quickly find nodes by their name */
    hashMapImpl<stringImpl, U32>   _animationNameToId;// find animations quickly

    vectorImpl<Bone*> _bones;// DO NOT DELETE THESE when the destructor runs... THEY ARE JUST REFERENCES!!
    vectorImpl<aiMatrix4x4 > _transforms;// temp array of transforms

    mat4<F32>      _cacheIdentity;
    LineCollection _skeletonLines;
    vectorImpl<vectorImpl<Line >> _skeletonLinesContainer;

};

}; //namespace Divide

#endif

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

Diff revisions: vs.
Revision Author Commited Message
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

322 Diff Diff IonutCava picture IonutCava Sat 06 Sep, 2014 20:33:47 +0000

[Ionut]
- Refactored most of Boost related code to be C++11 based
— Boost is only used for ThreadPool, Mutex handling, XML parsing and networking (ASIO)
— Function binds, threads, regex, NonCopyable base, Hashing algorithms and more are now using C++11 libraries
- Replaced all FOR_EACH calls with standard, range, “for” calls

321 Diff Diff IonutCava picture IonutCava Wed 03 Sep, 2014 22:05:15 +0000

[Ionut]
- Added support (and enabled by default) for the EASTL library (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html / https://github.com/paulhodge/EASTL)
— Strings, vectors and hash_maps can be combined from EASTL, STL and Boost (not all combinations work. e.g. EASTL strings with STL/Boost containers due to the lack of a proper hash function)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

304 Diff Diff IonutCava picture IonutCava Sun 10 Aug, 2014 21:10:54 +0000

[Ionut]
- Redesigned the WorldEditor (dummy functions added for every button/option)
- Improved debug rendering performance by using static IMPrimitives for axis gizmo rendering
- Simplified skeleton rendering

286 Diff Diff IonutCava picture IonutCava Fri 18 Jul, 2014 16:32:03 +0000

[Ionut] [[BR]]

    • very buggy commit ** [[BR]]

- New rendering pipeline: [[BR]]
— Bumped OpenGL version to 4.4 [[BR]]
— Command based rendering. GFXDevice dispatches rendering commands to their respective buffers [[BR]]
— State changing is exclusively controlled by the GFXDevice class [[BR]]
— Material properties and transform matrices are stored in shader storage buffers that are updated after culling and uploaded once per RenderPass. Objects use drawIDs to index data in shaders [[BR]]
— Removed all custom matrices and other, per shader, bind data [[BR]]
— Removed per node light data. Light culling and shader buffers will replace the old light management system [[BR]]
— Framebuffers now use the Texture class for attachments [[BR]]
— Sampler objects now work like RenderStateBlocks. GL_API handles them and stores them in a hash indexed map [[BR]]
— Removed “prepareMaterial” calls. Pre-draw material setup is now only limited to texture binding [[BR]]
— Moved immediate mode emulation and primitive rendering from API level to GFXDevice level [[BR]]
— Framebuffer rendering must be completed with a call to end() to ensure proper MSAA resolve (asserts, otherwise) [[BR]]
- Fixed hash code generation for RenderStateBlock (and now, glSamplerObject) using boost::hash_combine [[BR]]
- Temporarily disabled XML caching for materials [[BR]]

274 Diff Diff IonutCava picture IonutCava Fri 13 Jun, 2014 12:56:03 +0000

[Ionut] [[BR]]
- Simplified buffer based rendering (VertexBuffer & GenericVertexData are now exclusively command based) [[BR]]
- Update bone buffer to persistent mapped-SSBO system with double-buffering [[BR]]
- Simplified sky rendering and (finally) reduced the sun’s radius [[BR]]

273 Diff Diff IonutCava picture IonutCava Wed 11 Jun, 2014 20:34:00 +0000

[Ionut] [[BR]]
- Improved batching part2: [[BR]]
— Moved all bone transformation matrices upload from uniform functions in SceneNode to Shader Storage Buffers in AnimationController class with updates controlled by SceneGraphNode’s AnimationComponent [[BR]]
-— No double-buffering or efficient mapping of data yet. Just raw buffer updates [[BR]]
— Replaced all RenderStateBlock* pointers with I64 hash values [[BR]]
-— Will be used later in draw commands as per-shader state hash [[BR]]
— Moved getShaderProgram from Material to Material::ShaderInfo [[BR]]
-— Improved redundant uniform checks [[BR]]
— Improved texture unit changing in case of redundant texture bind case (i.e. skip changing the texture unit) [[BR]]
[[BR]]
- Improved float and double comparison functions using algorithms described in http://randomascii.wordpress.com/2012/02/13/dont-store-that-in-a-float/ [[BR]]
- Added a new utility function, DIVIDE_ASSERT, to more easily bind an assert check with a specific message [[BR]]
- Added missing files from Forward+ renderer’s initial code [[BR]]

270 Diff Diff IonutCava picture IonutCava Thu 05 Jun, 2014 19:08:07 +0000

[Ionut][[BR]]
- SubMeshes now use a single vertex buffer (owned by the parent mesh) with proper offsetting and querying [[BR]]
— Implementation not optimal yet [[BR]]
- Cleaned up VertexBuffer related classes [[BR]]

253 k1ngp1n picture k1ngp1n Wed 09 Apr, 2014 11:30:54 +0000

[Ionut] [[BR]]
- Split SceneAnimator in global and per-instance data (SceneAnimator and AnimatorComponent) respectively [[BR]]
— Each SceneNode, sharing the same skinned mesh can have different animations with different timings now [[BR]]
- Fixed particle systems' billboarding issues [[BR]]
- More cleaning up of the Material class [[BR]]