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
#include "Headers/AnimationController.h"
#include "Hardware/Video/Headers/GFXDevice.h"
#include "Headers/AnimationUtils.h"

#include <assimp/scene.h>

using namespace boost;

void SceneAnimator::Release(){// this should clean everything up
    FOR_EACH(LineCollection::value_type& it, _skeletonLines){
        FOR_EACH(LineMap::value_type& it2, it.second){
            it2.second.clear();
        }
    }
    _skeletonLines.clear();
    _animations.clear();// clear all animations
    _bonesByName.clear();
    _bonesToIndex.clear();
    _animationNameToId.clear();
    _transforms.clear();
    // This node will delete all children recursivly
    SAFE_DELETE(_skeleton);
}

bool SceneAnimator::Init(const aiScene* pScene, U8 meshPointer){// this will build the skeleton based on the scene passed to it and CLEAR EVERYTHING
    if(!pScene->HasAnimations()) return false;
    Release();

    _skeleton = CreateBoneTree( pScene->mRootNode, nullptr);
    ExtractAnimations(pScene);

    const aiMesh* mesh = pScene->mMeshes[meshPointer];

    for (U32 n = 0; n < mesh->mNumBones;++n){
        const aiBone* bone = mesh->mBones[n];
        Unordered_map<std::string, Bone*>::iterator found = _bonesByName.find(bone->mName.data);
        if(found != _bonesByName.end()){// FOUND IT!!! woohoo, make sure its not already in the bone list
            bool skip = false;
            for(size_t j(0); j< _bones.size(); j++){
                std::string bname = bone->mName.data;
                if(_bones[j]->_name == bname) {
                    skip = true;// already inserted, skip this so as not to insert the same bone multiple times
                    break;
                }
            }
            if(!skip){// only insert the bone if it has not already been inserted
                std::string tes = found->second->_name;
                found->second->_offsetMatrix =  bone->mOffsetMatrix;
                _bones.push_back(found->second);
                _bonesToIndex[found->first] = (U32)_bones.size()-1;
            }
        }
    }

    _transforms.resize( _bones.size());
    D32 timestep = 1.0/ANIMATION_TICKS_PER_SECOND;// ANIMATION_TICKS_PER_SECOND
    mat4<F32> rotationmat;
    vectorImpl<mat4<F32> > vec;
    for(size_t i(0); i< _animations.size(); i++){// pre calculate the animations
        D32 dt = 0;
        for(D32 ticks = 0; ticks < _animations[i]._duration; ticks += _animations[i]._ticksPerSecond/ANIMATION_TICKS_PER_SECOND){
            dt +=timestep;
            Calculate((I32)i, dt);
            _animations[i]._transforms.push_back(vec);
            vectorImpl<mat4<F32> >& trans = _animations[i]._transforms.back();
            if(GFX_DEVICE.getApi() == Direct3D){
                for( size_t a = 0; a < _transforms.size(); ++a){
                    AnimUtils::TransformMatrix(rotationmat, _bones[a]->_offsetMatrix * _bones[a]->_globalTransform);
                    trans.push_back(rotationmat);
                }
            }else{
                for( size_t a = 0; a < _transforms.size(); ++a){
                    AnimUtils::TransformMatrix(rotationmat, _bones[a]->_globalTransform * _bones[a]->_offsetMatrix);
                    trans.push_back(rotationmat);
                }
            }
        }
    }

    D_PRINT_FN(Locale::get("LOAD_ANIMATIONS_END"), _bones.size());
    return !_transforms.empty();
}

void SceneAnimator::ExtractAnimations(const aiScene* pScene){
    D_PRINT_FN(Locale::get("LOAD_ANIMATIONS_BEGIN"));
    for(size_t i(0); i< pScene->mNumAnimations; i++){
        if(pScene->mAnimations[i]->mDuration > 0.0f){
            _animations.push_back(AnimEvaluator(pScene->mAnimations[i]) );// add the animations
        }
    }
    // get all the animation names so I can reference them by name and get the correct id
    U16 i = 0;
    for(AnimEvaluator& animation : _animations){
        _animationNameToId.insert(Unordered_map<std::string, U32>::value_type(animation._name, i++));
    }
}

// ------------------------------------------------------------------------------------------------
// Calculates the node transformations for the scene.
void SceneAnimator::Calculate(I32 animationIndex, const D32 pTime){
    if ((animationIndex < 0) || (animationIndex >= (I32)_animations.size())) return;// invalid animation
    _animations[animationIndex].Evaluate(pTime, _bonesByName);
    UpdateTransforms(_skeleton);
}

// ------------------------------------------------------------------------------------------------
// Recursively creates an internal node structure matching the current scene and animation.
Bone* SceneAnimator::CreateBoneTree( aiNode* pNode, Bone* parent){
    Bone* internalNode = new Bone(pNode->mName.data);// create a node
    internalNode->_parent = parent; //set the parent, in the case this is theroot node, it will be null
    _bonesByName[internalNode->_name] = internalNode;// use the name as a key
    internalNode->_localTransform =  pNode->mTransformation;
    if(GFX_DEVICE.getApi() == Direct3D){
        internalNode->_localTransform.Transpose();
    }
    internalNode->_originalLocalTransform = internalNode->_localTransform;// a copy saved
    CalculateBoneToWorldTransform(internalNode);

    // continue for all child nodes and assign the created internal nodes as our children
    // recursively call this function on all children
    for(uint32_t i = 0; i < pNode->mNumChildren; i++){
        Bone* childNode = CreateBoneTree(pNode->mChildren[i], internalNode);
        internalNode->_children.push_back(childNode);
    }
    return internalNode;
}

/// ------------------------------------------------------------------------------------------------
/// Recursively updates the internal node transformations from the given matrix array
void SceneAnimator::UpdateTransforms(Bone* pNode) {
    CalculateBoneToWorldTransform( pNode);// update global transform as well
    /// continue for all children
    for(Bone* bone : pNode->_children){
        UpdateTransforms( bone );
    }
}

Bone* SceneAnimator::GetBoneByName(const std::string& bname) const {
    Unordered_map<std::string, Bone*>::const_iterator found = _bonesByName.find(bname);
	if(found != _bonesByName.end()) 
		return found->second; 
	else 
		return nullptr;
}

I32 SceneAnimator::GetBoneIndex(const std::string& bname) const {
	Unordered_map<std::string, U32>::const_iterator found = _bonesToIndex.find(bname);
	if(found != _bonesToIndex.end()) 
		return found->second; 
	else 
		return -1;
}

/// ------------------------------------------------------------------------------------------------
/// Calculates the global transformation matrix for the given internal node
void SceneAnimator::CalculateBoneToWorldTransform(Bone* child){
    child->_globalTransform = child->_localTransform;
    Bone* parent = child->_parent;
    // this will climb the nodes up along through the parents concatenating all the matrices to get the Object to World transform, or in this case, the Bone To World transform
    if(GFX_DEVICE.getApi() == Direct3D){
        while( parent ){
            child->_globalTransform *= parent->_localTransform;
            parent  = parent->_parent;// get the parent of the bone we are working on
        }
    }else{
        while( parent) {
            child->_globalTransform = parent->_localTransform * child->_globalTransform;
            parent  = parent->_parent;// get the parent of the bone we are working on
        }
    }
}

///Renders the current skeleton pose at time index dt
I32 SceneAnimator::RenderSkeleton(I32 animationIndex, const D32 dt){
    I32 frameIndex = _animations[animationIndex].GetFrameIndexAt(dt);

    if (_skeletonLines.find(animationIndex) == _skeletonLines.end())
        _skeletonLines.insert(std::make_pair(animationIndex, LineMap()));
    
    if (_skeletonLines[animationIndex][frameIndex].empty()){
        // create all the needed points
        vectorImpl<Line >& lines = _skeletonLines[animationIndex][frameIndex];
        lines.reserve(_bones.size());
        // Construct skeleton
        Calculate(animationIndex, dt);
        // Prepare global transform
        aiMatrix4x4 rootTransform;
        AnimUtils::TransformMatrix(rootTransform,_rootTransformRender);
        CreateSkeleton(_skeleton, rootTransform, lines);
    }
    // Submit skeleton to gpu
    GFX_DEVICE.drawLines(_skeletonLines[animationIndex][frameIndex], _rootTransformRender, vec4<I32>(), false, true);
    return 1;
}

/// Create animation skeleton
I32 SceneAnimator::CreateSkeleton(Bone* piNode, const aiMatrix4x4& parent, vectorImpl<Line >& lines){

    aiMatrix4x4 me = piNode->_globalTransform;
    if(GFX_DEVICE.getApi() == Direct3D){
        me.Transpose();
    }

    if (piNode->_parent) {
        lines.push_back(Line(vec3<F32>(parent.a4, parent.b4, parent.c4),
                             vec3<F32>(me.a4, me.b4, me.c4),
                             vec4<U8>(255,0,0,255)));
    }

    // render all child nodes
    for(Bone* bone : piNode->_children){
        CreateSkeleton(bone, me, lines);
    }

    return 1;
}

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

Diff revisions: vs.
Revision Author Commited Message
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]]

260 Diff Diff k1ngp1n picture k1ngp1n Sat 03 May, 2014 19:33:41 +0000

[Ionut] [[BR]]
- More work on CSM. Reverted back to VSM to allow easier blurring and filtering [[BR]]
- Rewrote FrameBuffer classes to fix MSAA and memory leaks that occurred on resize (double creation of textures) [[BR]]
— Removed FBType. FrameBuffer types depend only on attachment types and if it’s MSAA enabled or not [[BR]]
- Rewrote RenderState classes to be API agnostic [[BR]]
- Bug fixes in math classes [[BR]]
- Changed “resolution change” logic [[BR]]
- Simplified some options in config.xml [[BR]]
- Improved per-light shadow options [[BR]]

259 Diff Diff k1ngp1n picture k1ngp1n Sun 27 Apr, 2014 18:24:52 +0000

[Ionut][[BR]]
- Implemented Exponential Stable Cascaded Shadow Maps for directional lights (still buggy, but basically working) [[BR]]
— CSM settings (resolution, number of splits, etc) are part of the scene render state [[BR]]
- SGN can skip rendering for the current frame if they are not ready (e.g. OnDraw can now return false or materials can fail to bind) [[BR]]
- Frustum class is now using the Plane class [[BR]]
- Removed Math SIMD implementation as the compiler generated code will always be faster and safer [[BR]]
- Added a “STUBBED” macro for outputing to the error stream of important messages (instead of using #pragma message) [[BR]]
- Added “freeze time” logic to pause/resume updates with or without freezing the GUI too [[BR]]
- Added “processGUI” method the every Scene class to separate time-sensitive GUI updates from game logic loop [[BR]]
- GLSL <-> Vertex Buffer bind locations are automatically set for every vertex shader [[BR]]
- Added basic support for compute shaders [[BR]]
- Removed most OS define checks to make porting to a new platform easier [[BR]]
- Texture transparency check per-pixel is now using OpenMP [[BR]]
- Texture samplers can now set a border color for CLAMP_TO_BORDER wrap mode [[BR]]
- Removed “Object” suffix from GFX Classes (pixel buffer, vertex buffer, frame buffer, etc) [[BR]]
- Stop processing scene input when application looses focus [[BR]]
- SceneGraphNode class is now responsible for updating SGNComponents on draw and calling its _node’s OnDraw method [[BR]]
- UBOs can now list all of the active uniforms inside a block with info such as type and offset [[BR]]
- Removed deprecated ‘GLCheck’ macro [[BR]]
- A lot of bug fixes and performance improvements in various places [[BR]]

253 Diff Diff 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]]

251 Diff Diff k1ngp1n picture k1ngp1n Wed 02 Apr, 2014 20:38:18 +0000

[Ionut] [[BR]]

  • Divide is now a 64bit statically linked application * [[BR]]

- Updated to a Visual Studio 2013 solution for better C++11 support [[BR]]
— Recompiled all projects with platform toolset v120 [[BR]]
- Recompiled all projects as x64 – MT / MTd (from x86 – MD / MDd) [[BR]]
- Updated PhysX to 3.3 [[BR]]
- Updated GLFW to 3.0.4 [[BR]]

250 Diff Diff k1ngp1n picture k1ngp1n Wed 02 Apr, 2014 12:36:36 +0000

[Ionut] [[BR]]
- More C++11 work [[BR]]
- Renamed “for_each” macro to “FOR_EACH” to avoid name conflicts with the C++11 function [[BR]]

249 k1ngp1n picture k1ngp1n Mon 31 Mar, 2014 20:42:31 +0000

[Ionut] [[BR]]
- Migrated to platform toolset v100 [[BR]]
- Updated boost to 1.55 [[BR]]
- Moved from “NULL” to “nullptr” [[BR]]
- DevIL is now linked dynamically [[BR]]