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

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(size_t 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(size_t 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(size_t 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(size_t 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(size_t 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(size_t 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(size_t 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(size_t 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 recursivly 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, NULL);
	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);
	}
	for(uint32_t i(0); i< _animations.size(); i++){// get all the animation names so I can reference them by name and get the correct id
		_animationNameToId.insert(Unordered_map<std::string, uint32_t>::value_type(_animations[i]._name, i));
	}
	if(_animations.size() >0) _currentAnimIndex =0;// set it to the first animation if there are any
	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;
		Unordered_map<std::string, 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(size_t i(0); i< _animations.size(); i++){// pre calculate the animations
		SetAnimIndex(i);
		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(dt);
			_animations[i]._transforms.push_back(vectorImpl<mat4<F32> >());
			vectorImpl<mat4<F32> >& trans = _animations[i]._transforms.back();
			for( size_t a = 0; a < _transforms.size(); ++a){
				AnimUtils::TransformMatrix(rotationmat, aiMatrix4x4(_bones[a]->_globalTransform *  _bones[a]->_offsetMatrix));
				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());
	file.write(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of chars
	file.write(parent->_name.c_str(), nsize);// the name of the bone
	file.write(reinterpret_cast<char*>(&parent->_offsetMatrix), sizeof(parent->_offsetMatrix));// the bone offsets
	file.write(reinterpret_cast<char*>(&parent->_originalLocalTransform), sizeof(parent->_originalLocalTransform));// original bind pose
	nsize = static_cast<uint32_t>(parent->_children.size());// number of children
	file.write(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of children
	for( vectorImpl<Bone*>::iterator it = parent->_children.begin(); it != parent->_children.end(); ++it)// continue for all children
		SaveSkeleton(file, *it);
}

Bone* SceneAnimator::LoadSkeleton(std::ifstream& file, Bone* parent){
	Bone* internalNode = 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
	file.read(reinterpret_cast<char*>(&internalNode->_offsetMatrix), sizeof(internalNode->_offsetMatrix));// the bone offsets
	file.read(reinterpret_cast<char*>(&internalNode->_originalLocalTransform), sizeof(internalNode->_originalLocalTransform));// original bind pose

	internalNode->_localTransform = internalNode->_originalLocalTransform;// a copy saved
	CalculateBoneToWorldTransform(internalNode);

	file.read(reinterpret_cast<char*>(&nsize), sizeof(uint32_t));// the number of children

	// continue for all child nodes and assign the created internal nodes as our children
	for( U32 a = 0; a < nsize && file; a++){// recursivly call this function on all children
		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
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 Diff Diff 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]]

146 Diff Diff k1ngp1n picture k1ngp1n Wed 10 Apr, 2013 13:20:15 +0000

[Ionut] [[BR]]
*Final LightBranch updates 2/3 : Main trunk merge and build test (VC90, VC100, gDebugger) [[BR]]
-Merged light branch with trunk [[BR]]
-Deleted light branch [[BR]]

122 Diff Diff k1ngp1n picture k1ngp1n Mon 11 Jun, 2012 14:39:08 +0000

[Ionut] [[BR]]
-Restructured “Hardware” folder to match the rest of the projects header-separation pattern [[BR]]

121 Diff Diff k1ngp1n picture k1ngp1n Sun 10 Jun, 2012 16:40:45 +0000

[Ionut] [[BR]]
-Added basic localization support [[BR]]
-Added cross-platform INI parsing [[BR]]
-Moved ReCast+Detour to LIBS folder [[BR]]

111 k1ngp1n picture k1ngp1n Tue 08 May, 2012 21:49:31 +0000

[Ionut] [[BR]]
-Added animation support based on Scott Lee’s animation loader library added a few revision’s back [[BR]]
--Added cached skeleton rendering to the library [[BR]]
--Added cached AABB transformations based on current animation frame [[BR]]
--Scene animators are added per submesh and only processed if said submesh is visible and only in the rendering stage: FINAL_STAGE [[BR]]
[[BR]]
-Added support for shader-based VBO data upload (glVertexAttribPointer) with full backwards compatibility to old method (glTexCoordPointer)[[BR]]
-Added support for Index Buffer Object (improper name) indice upload for VBO’s with full backwards compatibility to old method [[BR]]
-Reworked coordination class to better handle AIEntity teams [[BR]]
-Added “updateSceneState(currentTime)” callback that is called once per frame (used for animation update)[[BR]]
-Added “initializeAI/deinitializeAI” scene callbacks for AI creation/destruction [[BR]]
-Templatized the Quaternion class [[BR]]
-Added a “drawLines” subroutine to the rendering api[[BR]]
-Disabled tree loading in MainScene as current ASSIMP implementation is slow. Will be restored after backing and loading models to own format is added in next revision [[BR]]
-Other various small performance tweaks [[BR]]