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

namespace Divide {

void AnimEvaluator::Save(std::ofstream& file){
	uint32_t nsize = static_cast<uint32_t>(_name.size());
	file.write(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the size of the animation name
	file.write(_name.c_str(), nsize);// the size of the animation name
	file.write(reinterpret_cast<char*>(&_duration), sizeof(_duration));// the duration
	file.write(reinterpret_cast<char*>(&_ticksPerSecond), sizeof(_ticksPerSecond));// the number of ticks per second
	nsize = static_cast<uint32_t>(_channels.size());// number of animation channels,
	file.write(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number animation channels
	for(vectorAlg::vecSize j(0); j< _channels.size(); j++){// for each channel
		nsize =static_cast<uint32_t>(_channels[j]._name.size());
		file.write(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the size of the name
		file.write(_channels[j]._name.c_str(), nsize);// the size of the animation name

		nsize =static_cast<uint32_t>(_channels[j]._positionKeys.size());
		file.write(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of position keys
		for(vectorAlg::vecSize i(0); i< nsize; i++){// for each channel
			file.write(reinterpret_cast<char*>(&_channels[j]._positionKeys[i].mTime), 
                       sizeof(_channels[j]._positionKeys[i].mTime));// pos key
			file.write(reinterpret_cast<char*>(&_channels[j]._positionKeys[i].mValue), 
                       sizeof(_channels[j]._positionKeys[i].mValue));// pos key
		}

		nsize =static_cast<uint32_t>(_channels[j]._rotationKeys.size());
		file.write(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of position keys
		for(vectorAlg::vecSize i(0); i< nsize; i++){// for each channel
			file.write(reinterpret_cast<char*>(&_channels[j]._rotationKeys[i].mTime), 
                       sizeof(_channels[j]._rotationKeys[i].mTime));// rot key
			file.write(reinterpret_cast<char*>(&_channels[j]._rotationKeys[i].mValue), 
                       sizeof(_channels[j]._rotationKeys[i].mValue));// rot key
		}

		nsize =static_cast<uint32_t>(_channels[j]._scalingKeys.size());
		file.write(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of position keys
		for(vectorAlg::vecSize i(0); i< nsize; i++){// for each channel
			file.write(reinterpret_cast<char*>(&_channels[j]._scalingKeys[i].mTime), 
                       sizeof(_channels[j]._scalingKeys[i].mTime));// rot key
			file.write(reinterpret_cast<char*>(&_channels[j]._scalingKeys[i].mValue),
                       sizeof(_channels[j]._scalingKeys[i].mValue));// rot key
		}
	}
}

void AnimEvaluator::Load(std::ifstream& file){
	uint32_t nsize = 0;
	file.read(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the size of the animation name
	char temp[250];
	file.read(temp, nsize);// the size of the animation name
	temp[nsize]=0;// null char
	_name=temp;
	D_PRINT_FN(Locale::get("CREATE_ANIMATION_BEGIN"),_name.c_str());
	file.read(reinterpret_cast<char*>(&_duration), sizeof(_duration));// the duration
	file.read(reinterpret_cast<char*>(&_ticksPerSecond), sizeof(_ticksPerSecond));// the number of ticks per second
	file.read(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number animation channels
	_channels.resize(nsize);
	for(vectorAlg::vecSize j(0); j< _channels.size(); j++){// for each channel
		nsize =0;
		file.read(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the size of the name
		file.read(temp, nsize);// the size of the animation name
		temp[nsize]=0;// null char
		_channels[j]._name=temp;

		nsize =static_cast<uint32_t>(_channels[j]._positionKeys.size());
		file.read(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of position keys
		_channels[j]._positionKeys.resize(nsize);
		for(vectorAlg::vecSize i(0); i< nsize; i++){// for each channel
			file.read(reinterpret_cast<char*>(&_channels[j]._positionKeys[i].mTime), 
                      sizeof(_channels[j]._positionKeys[i].mTime));// pos key
			file.read(reinterpret_cast<char*>(&_channels[j]._positionKeys[i].mValue), 
                      sizeof(_channels[j]._positionKeys[i].mValue));// pos key
		}

		nsize =static_cast<uint32_t>(_channels[j]._rotationKeys.size());
		file.read(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of position keys
		_channels[j]._rotationKeys.resize(nsize);
		for(vectorAlg::vecSize i(0); i< nsize; i++){// for each channel
			file.read(reinterpret_cast<char*>(&_channels[j]._rotationKeys[i].mTime), 
                      sizeof(_channels[j]._rotationKeys[i].mTime));// pos key
			file.read(reinterpret_cast<char*>(&_channels[j]._rotationKeys[i].mValue), 
                      sizeof(_channels[j]._rotationKeys[i].mValue));// pos key
		}

		nsize =static_cast<uint32_t>(_channels[j]._scalingKeys.size());
		file.read(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of position keys
		_channels[j]._scalingKeys.resize(nsize);
		for(vectorAlg::vecSize i(0); i< nsize; i++){// for each channel
			file.read(reinterpret_cast<char*>(&_channels[j]._scalingKeys[i].mTime), 
                      sizeof(_channels[j]._scalingKeys[i].mTime));// pos key
			file.read(reinterpret_cast<char*>(&_channels[j]._scalingKeys[i].mValue),
                      sizeof(_channels[j]._scalingKeys[i].mValue));// pos key
		}
	}
	_lastPositions.resize( _channels.size(), vec3<U32>());
}

void SceneAnimator::Save(std::ofstream& file){
	// first recursively save the skeleton
	if(_skeleton)
		SaveSkeleton(file, _skeleton);

	uint32_t nsize = static_cast<uint32_t>(_animations.size());
	file.write(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of animations
	for(uint32_t i(0); i< nsize; i++){
		_animations[i].Save(file);
	}

	nsize = static_cast<uint32_t>(_bones.size());
	file.write(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of bones

	for(uint32_t i(0); i< _bones.size(); i++){
		nsize = static_cast<uint32_t>(_bones[i]->_name.size());
		file.write(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the size of the bone name
		file.write(_bones[i]->_name.c_str(), nsize);// the name of the bone
	}
}

void SceneAnimator::Load(std::ifstream& file){
	Release();// make sure to clear this before writing new data
	_skeleton = LoadSkeleton(file, nullptr);
	uint32_t nsize = 0;
	file.read(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of animations
	_animations.resize(nsize);
	D_PRINT_FN(Locale::get("LOAD_ANIMATIONS_BEGIN"));
	for(uint32_t i(0); i< nsize; i++){
		_animations[i].Load(file);
	}
    // get all the animation names so I can reference them by name and get the correct id
	for(uint32_t i(0); i< _animations.size(); i++){
		_animationNameToId.insert(hashMapImpl<stringImpl, uint32_t>::value_type(_animations[i]._name, i));
	}

	char bname[250];
	file.read(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of bones
	_bones.resize(nsize);

	for(uint32_t i(0); i< _bones.size(); i++){
		file.read(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the size of the bone name
		file.read(bname, nsize);// the size of the bone name
		bname[nsize]=0;
		hashMapImpl<stringImpl, Bone*>::iterator found = _bonesByName.find(bname);
		Bone* tep = found->second;
		_bonesToIndex[found->first] = i;
		_bones[i]=tep;
	}

	_transforms.resize( _bones.size());
	F32 timestep = 1.0f/(F32)ANIMATION_TICKS_PER_SECOND;// 25.0f per second
	for(vectorAlg::vecSize i(0); i< _animations.size(); i++){// pre calculate the animations
		F32 dt = 0;
		mat4<F32> rotationmat;
		for(F32 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(vectorImpl<mat4<F32> >());
			vectorImpl<mat4<F32> >& trans = _animations[i]._transforms.back();
			for( vectorAlg::vecSize a = 0; a < _transforms.size(); ++a){
				AnimUtils::TransformMatrix(aiMatrix4x4(_bones[a]->_globalTransform *  _bones[a]->_offsetMatrix), rotationmat);
				trans.push_back(rotationmat);
			}
		}
	}
	D_PRINT_FN(Locale::get("LOAD_ANIMATIONS_END"), _bones.size());
}

void SceneAnimator::SaveSkeleton(std::ofstream& file, Bone* parent) {
	uint32_t nsize = static_cast<uint32_t>(parent->_name.size());
    // the number of chars
	file.write(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));
    // the name of the bone
	file.write(parent->_name.c_str(), nsize);
    // the bone offsets
	file.write(reinterpret_cast<char*>(&parent->_offsetMatrix), sizeof(parent->_offsetMatrix));
    // original bind pose
	file.write(reinterpret_cast<char*>(&parent->_originalLocalTransform), sizeof(parent->_originalLocalTransform));
    // number of children
	nsize = static_cast<uint32_t>(parent->_children.size());
    // the number of children
	file.write(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));
    // continue for all children
    for (vectorImpl<Bone*>::iterator it = parent->_children.begin(); it != parent->_children.end(); ++it) {
		SaveSkeleton(file, *it);
    }
}

Bone* SceneAnimator::LoadSkeleton(std::ifstream& file, Bone* parent){
    Bone* internalNode = MemoryManager_NEW Bone();// create a node
	internalNode->_parent = parent; //set the parent, in the case this is theroot node, it will be null
	uint32_t nsize=0;
	file.read(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of chars
	char temp[250];
	file.read(temp, nsize);// the name of the bone
	temp[nsize]=0;
	internalNode->_name = temp;
	_bonesByName[internalNode->_name] = internalNode;// use the name as a key
    // the bone offsets
	file.read(reinterpret_cast<char*>(&internalNode->_offsetMatrix), sizeof(internalNode->_offsetMatrix));
    // original bind pose
	file.read(reinterpret_cast<char*>(&internalNode->_originalLocalTransform), sizeof(internalNode->_originalLocalTransform));
    // a copy saved
	internalNode->_localTransform = internalNode->_originalLocalTransform;
	CalculateBoneToWorldTransform(internalNode);
    // the number of children
	file.read(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));

    // recursivly 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 && file; a++) {
		internalNode->_children.push_back(LoadSkeleton(file, internalNode));
	}
	return internalNode;
}

};

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

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)

324 Diff Diff IonutCava picture IonutCava Sun 14 Sep, 2014 14:01:39 +0000

[Ionut]
- New memory management system (no custom allocators in this commit)
— Memory tracer to detect memory leaks on shutdown (from: https://www.relisoft.com/book/tech/9new.html)
— SAFE_DELETE_XYZ are now inline template functions not macros
— ASSERTION system now supports logging and message boxes and continue on error configurable for each build type
— Fixed a lot of memory leaks detected by the new system (some still remain)

- Added SRGB support (part 1)
— Albedo textures are loaded as SRGB (make sure resources are SRGB)
— Shaders output gamma corrected colors
— Moved terrain textures back to 2 array system (albedo and normal maps, albedo maps using a SRGB sampler)

- Sky is now loaded via the ResourceCache system
- Added include safeguards in shader atoms

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

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

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

168 Diff Diff k1ngp1n picture k1ngp1n Sat 26 Oct, 2013 19:03:21 +0000

- Reworked the Camera class[[BR]]
— Now fully quaternion based [[BR]]
— Basic camera types added but not used yet (third person, first person, orbit) [[BR]]
- Cleaned up Material and Texture handling [[BR]]
- Added clipping plane support [[BR]]
— Similar to OpenGL fixed-function clip planes but fully shader driven [[BR]]
— Added a new class, “Plane”, that helps define clip planes [[BR]]
- Optimized the Singleton class to allow faster “getInstance” calls without performance penalties [[BR]]
-- “createInstance” must be called for each singleton class before usage. Or “gerOrCreateInstance” can be used, which is basically the former “getInstance” implementation [[BR]]
- Improved console logging by changing some heap allocations to stack and removing dependencies on the std::string class [[BR]]
- Added a lot of performance optimizations related to coding standards and redundant calculations [[BR]]
— e.g. Frustum AABB check didn’t need to recompute the AABB points as they were calculated already [[BR]]
— e.g. A vector did not need to be set to 0 on initialization as that is already it’s default state on creation [[BR]]
— e.g. Faster Framerate and Timing calculations by using less member variables that are not needed outsied of calling functions [[BR]]
- The SceneState now contains the SceneRenderState and is passed on to the SceneGraph’s update calls [[BR]]
- Better material export/import to/from XML format [[BR]]
- More bug fixes and cleanups [[BR]]

152 k1ngp1n picture k1ngp1n Thu 20 Jun, 2013 14:23:31 +0000

[Ionut] [[BR]]
- New rendering pipeline (experimental and unstable): [[BR]]
— OpenGL 3.x clean context (glLight commands are still used for now, but UBO support is there, but not used yet) [[BR]]
— Custom matrix stacks and UBO based shader data (UBOs cause some link errors on some nVidia cards)[[BR]]
— Multi-threaded texture loading and shader compilation (mt shader compilation disabled for now. needs more tests) [[BR]]
— VAO rendering is self contained (no more enable/disable calls before a draw request) [[BR]]
— Render instance class used for rendering information [[BR]]
[[BR]]
- New unique ID generation base class: GUIDWrapper. Each class that derives from this, gets an application wide unique id on construction [[BR]]
- Added base code for an in-game editor using CEGUI [[BR]]
- Replaced some mutex locks with lockless data structures or atomic data [[BR]]
- CEGUI 0.8.2, FTGL-GL3 and GLIM 0.4 modified to support GLEW_MX if defined [[BR]]
- Dropped VS2008 support [[BR]]
- Networking library, server framework and ReCast files are now projects inside the Divide Framework solution [[BR]]
- New console command “setFov” that modifies the horizontal FoV value in realtime [[BR]]
- New console command “recompileShader” that reparses shader files, recompiles shaders and relinks shader programs who’s names match or contain the argument string [[BR]]
- New debug utility: axis angle drawn in corner of the screen if needed [[BR]]
- More ‘const’-s pasted around the code, more loop performance tweaks (allocations before a loop, tighter loops, etc), more utility member functions added to various classes [[BR]]