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
#include "Headers/SceneAnimator.h"
#include "Platform/Headers/ByteBuffer.h"
#include "Platform/Video/Headers/GFXDevice.h"

#include "Core/Headers/Console.h"
#include "Utility/Headers/Localization.h"

namespace Divide {

void AnimEvaluator::save(const AnimEvaluator& evaluator, ByteBuffer& dataOut) {
    // The animation name;
    dataOut << evaluator._name;
    // the duration
    dataOut << evaluator._duration;
    // the number of ticks per second
    dataOut << evaluator._ticksPerSecond;
    // number of animation channels,
    dataOut << static_cast<uint32_t>(evaluator._channels.size());  
    // for each channel
    for (vectorAlg::vecSize j(0); j < evaluator._channels.size(); j++) {  
        // the channel name
        dataOut << evaluator._channels[j]._name;
        dataOut << evaluator._channels[j]._nameKey;
        // the number of position keys
        uint32_t nsize = static_cast<uint32_t>(evaluator._channels[j]._positionKeys.size());
        dataOut << nsize;
        // for each position key;
        for (vectorAlg::vecSize i(0); i < nsize; i++) {  
            // position key
            dataOut << evaluator._channels[j]._positionKeys[i].mTime;
            // position key
            dataOut << evaluator._channels[j]._positionKeys[i].mValue.x;
            dataOut << evaluator._channels[j]._positionKeys[i].mValue.y;
            dataOut << evaluator._channels[j]._positionKeys[i].mValue.z;
        }

        nsize = static_cast<uint32_t>(evaluator._channels[j]._rotationKeys.size());
        // the number of rotation keys
        dataOut << nsize;
        // for each channel
        for (vectorAlg::vecSize i(0); i < nsize; i++) {
            // rotation key
            dataOut << evaluator._channels[j]._rotationKeys[i].mTime;
            // rotation key
            dataOut << evaluator._channels[j]._rotationKeys[i].mValue.x;
            dataOut << evaluator._channels[j]._rotationKeys[i].mValue.y;
            dataOut << evaluator._channels[j]._rotationKeys[i].mValue.z;
            dataOut << evaluator._channels[j]._rotationKeys[i].mValue.w;
        }

        nsize = static_cast<uint32_t>(evaluator._channels[j]._scalingKeys.size());
        // the number of scaling keys
        dataOut << nsize;
        // for each channel
        for (vectorAlg::vecSize i(0); i < nsize; i++) {  
            // scale key
            dataOut << evaluator._channels[j]._scalingKeys[i].mTime;
            // scale key
            dataOut << evaluator._channels[j]._scalingKeys[i].mValue.x;
            dataOut << evaluator._channels[j]._scalingKeys[i].mValue.y;
            dataOut << evaluator._channels[j]._scalingKeys[i].mValue.z;
        }
    }
}

void AnimEvaluator::load(AnimEvaluator& evaluator, ByteBuffer& dataIn) {
    Console::d_printfn(Locale::get(_ID("CREATE_ANIMATION_BEGIN")), evaluator._name.c_str());
    // the animation name
    dataIn >> evaluator._name;
    // the duration
    dataIn >> evaluator._duration;
    // the number of ticks per second
    dataIn >> evaluator._ticksPerSecond;
    // the number animation channels
    uint32_t nsize = 0;
    dataIn >> nsize;
    evaluator._channels.resize(nsize);
    evaluator._lastPositions.resize(nsize, vec3<U32>());
    // for each channel
    for (vectorAlg::vecSize j(0); j < evaluator._channels.size(); j++) {  
        AnimationChannel& channel = evaluator._channels[j];
        //the channel name
        dataIn >> channel._name;
        dataIn >> channel._nameKey;
        // the number of position keys
        dataIn >> nsize;
        channel._positionKeys.resize(nsize);
        // for each position key
        for (vectorAlg::vecSize i(0); i < nsize; i++) {  
            aiVectorKey& pos = channel._positionKeys[i];
            // position key
            dataIn >> pos.mTime;
            // position key
            dataIn >> pos.mValue.x;
            dataIn >> pos.mValue.y;
            dataIn >> pos.mValue.z;
        }

        // the number of rotation keys
        dataIn >> nsize;
        channel._rotationKeys.resize(nsize);
        // for each rotation key
        for (vectorAlg::vecSize i(0); i < nsize; i++) {  
            aiQuatKey& rot = channel._rotationKeys[i];
            // rotation key
            dataIn >> rot.mTime;
            // rotation key
            dataIn >> rot.mValue.x;
            dataIn >> rot.mValue.y;
            dataIn >> rot.mValue.z;
            dataIn >> rot.mValue.w;
        }

        // the number of scaling keys
        dataIn >> nsize;
        channel._scalingKeys.resize(nsize);
        // for each skaling key
        for (vectorAlg::vecSize i(0); i < nsize; i++) { 
            aiVectorKey& scale = channel._scalingKeys[i]; 
            // scale key
            dataIn >> scale.mTime;
            // scale key
            dataIn >> scale.mValue.x;
            dataIn >> scale.mValue.y;
            dataIn >> scale.mValue.z;
        }
    }
    evaluator._lastPositions.resize(evaluator._channels.size(), vec3<U32>());
}

void SceneAnimator::save(PlatformContext& context, ByteBuffer& dataOut) const {
    ACKNOWLEDGE_UNUSED(context);

    // first recursively save the skeleton
    if (_skeleton) {
        saveSkeleton(dataOut, _skeleton);
    }

    dataOut << to_uint(_bones.size());
    for (Bone* bone : _bones) {
        dataOut << bone->name();
    }

    // the number of animations
    uint32_t nsize = static_cast<uint32_t>(_animations.size());
    dataOut << nsize;

    for (uint32_t i(0); i < nsize; i++) {
        AnimEvaluator::save(*_animations[i], dataOut);
    }
}

void SceneAnimator::load(PlatformContext& context, ByteBuffer& dataIn) {
    // make sure to clear this before writing new data
    release();

    _skeleton = loadSkeleton(dataIn, nullptr);

    stringImpl boneName;
    uint32_t nsize = 0;
    dataIn >> nsize;
    _bones.resize(nsize);
    for (uint32_t i(0); i < nsize; i++) {
        dataIn >> boneName;
        _bones[i] = _skeleton->find(boneName);
    }
    _skeletonDepthCache = nsize;
    // the number of animations
    dataIn >> nsize;
    _animations.resize(nsize);
    
    uint32_t idx = 0;
    for (std::shared_ptr<AnimEvaluator>& anim : _animations) {
        anim = std::make_unique<AnimEvaluator>();
        AnimEvaluator::load(*anim, dataIn);
        // get all the animation names so I can reference them by name and get the correct id
        hashAlg::emplace(_animationNameToID, _ID_RT(anim->name()), idx++);
    }
    
    init(context);
}

void SceneAnimator::saveSkeleton(ByteBuffer& dataOut, Bone* parent) const {
    // the name of the bone
    dataOut << parent->name();
    // the bone offsets
    for (U8 i = 0; i < 4; ++i) {
        for (U8 j = 0; j < 4; ++j) {
            dataOut << parent->_offsetMatrix[i][j];
        }
    }
    // original bind pose
    for (U8 i = 0; i < 4; ++i) {
        for (U8 j = 0; j < 4; ++j) {
            dataOut << parent->_originalLocalTransform[i][j];
        }
    }
    // number of children
    uint32_t nsize = static_cast<uint32_t>(parent->_children.size());
    dataOut << nsize;
    // continue for all children
    for (vectorImpl<Bone*>::iterator it = std::begin(parent->_children); it != std::end(parent->_children); ++it) {
        saveSkeleton(dataOut, *it);
    }
}

Bone* SceneAnimator::loadSkeleton(ByteBuffer& dataIn, Bone* parent) {
    stringImpl tempString;
    // create a node
    Bone* internalNode = MemoryManager_NEW Bone();
    // set the parent, in the case this is the root node, it will be null
    internalNode->_parent = parent;  
    // the name of the bone
    dataIn >> tempString;
    internalNode->name(tempString);
    // the bone offsets
    for (U8 i = 0; i < 4; ++i) {
        for (U8 j = 0; j < 4; ++j) {
            dataIn >> internalNode->_offsetMatrix[i][j];
        }
    }
    // original bind pose
    for (U8 i = 0; i < 4; ++i) {
        for (U8 j = 0; j < 4; ++j) {
            dataIn >> internalNode->_originalLocalTransform[i][j];
        }
    }

    // a copy saved
    internalNode->_localTransform = internalNode->_originalLocalTransform;
    calculateBoneToWorldTransform(internalNode);
    // the number of children
    U32 nsize = 0;
    dataIn >> nsize;

    // recursively call this function on all children
    // continue for all child nodes and assign the created internal nodes as our children
    for (U32 a = 0; a < nsize; a++) {
        internalNode->_children.push_back(loadSkeleton(dataIn, internalNode));
    }
    return internalNode;
}
};

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

Diff revisions: vs.
Revision Author Commited Message
832 Diff Diff IonutCava picture IonutCava Thu 26 Jan, 2017 17:23:11 +0000

[IonutCava]
- More path related work
- Initial code to centralize file I/O (does not compile yet)

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)
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

674 Diff Diff IonutCava picture IonutCava Mon 11 Apr, 2016 16:17:10 +0000

[IonutCava]
- Some profile guided optimizations:
— Remove the task state hashmap and replace with flat array
— Allow PhysX to load collision meshes from a RAM cache first -> then file -> then recompute
- Improve memory logger output

623 Diff Diff IonutCava picture IonutCava Fri 15 Jan, 2016 17:23:31 +0000

[IonutCava]
- Some particle system optimizations (splitting tasks in async workloads)
- Faster colour conversion systems
- Faster bone lookup by name
- Some DEBUG build changes to improve interactivity:
— Debug heap can be re-enabled on demand to track down Heisenbugs if they show up
- GLIM buffer orphaning

591 Diff Diff IonutCava picture IonutCava Wed 02 Dec, 2015 17:17:23 +0000

[IonutCava]
- More work on the ForwardPlus renderer
- Singleton cleanup
- First steps for reducing scope of GFXDevice class

577 Diff Diff IonutCava picture IonutCava Fri 20 Nov, 2015 15:59:10 +0000

[IonutCava]
- Replace all string indexed maps with unsigned long long indexed maps and add both compile time and runtime hashing functions to convert strings to the proper indices
— Balancing the calls between _ID and _ID_RT can reduce map lookup overhead, especially with ParamHandler and Locale::get

518 Diff Diff IonutCava picture IonutCava Sun 04 Oct, 2015 20:08:56 +0000

[IonutCava]
- New asset loading system and new asset formats (DVDGeom – geometry and material data. DVDAnim – animation data):
— Separate ASSIMP importing process (including animations) from Mesh/SubMesh/Material creation:
— Interface ASSIMP with the rest of the framework via a “ImportData” structure.
— Allow saving/loading from file of the entire ImportData and animation data entries via serialization.
— Allow serialization of VertexBuffers and update animation system’s serialization structure as well
— Base all serialization/deserialization processes on the ByteBuffer class with support for loading/saving to files
— If DVDGeom and DVDAnim files are not found, fall back to ASSIMP to load the data and save them for later use
-— Loading times reduce in half if data is already present.
-— Multi-threaded asset loading is now possible.
-— Other (non-ASSIMP) importing libraries can now be used.
-— DVDGeom and DVDAnim files can be shared/moved but not edited (they hold binary data for smaller memory usage)
- OpenGL/Direct3D usage is a compile time toggle (for now) for performance reasons.

444 Diff Diff IonutCava picture IonutCava Thu 21 May, 2015 16:06:53 +0000

[Ionut]
- More platform independent code cleanup:
— Moved platform specific defines to their respective header files (e.g. THREAD_LOCAL)
— Moved most preprocessor defines from the VisualC++ projects into source code
— Removed compiler specific code (e.g. warning disables) and fixed most warning resulting from this

422 IonutCava picture IonutCava Tue 05 May, 2015 20:33:47 +0000

[Ionut]
- Bug fixes for the previous commit
- Replace most static_cast<U32/I32> with to_int / to_uint