forked from Alfwich/CubicEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnimationContainer.cpp
161 lines (128 loc) · 3.55 KB
/
AnimationContainer.cpp
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
#include "AnimationContainer.h"
std::unordered_map<std::string,Animation*> AnimationContainer::animations;
Animation* AnimationContainer::lastAdded = NULL;
Animation* AnimationContainer::NewAnimation( std::string name )
{
if( name.length() == 0 )
return NULL;
if( HasAnimation( name ) )
return animations[name];
animations[name] = new Animation;
lastAdded = animations[name];
return animations[name];
}
bool AnimationContainer::AddFrameToAnimation( std::string name, Model* model, Size3D* size, Rotation3D* rotation, Point3D* position )
{
if( !HasAnimation( name ) )
return false;
animations[name]->SetFrame( model, size, rotation, position );
return true;
}
bool AnimationContainer::AddFrameToAnimation( Model* model, Size3D* size, Rotation3D* rotation, Point3D* position )
{
if( lastAdded == NULL )
return false;
int prevFrame = lastAdded->AmountOfFrames()-1;
if( model == NULL )
model = lastAdded->GetFrameModel( prevFrame );
if( size == NULL )
size = lastAdded->GetFrameSize( prevFrame );
if( rotation == NULL )
rotation = lastAdded->GetFrameRotation( prevFrame );
if( position == NULL )
position = lastAdded->GetFramePoint( prevFrame );
lastAdded->SetFrame( model, size, rotation, position );
return true;
}
bool AnimationContainer::DoubleFramesAndReverseTail( std::string name )
{
if( !HasAnimation( name ) )
return false;
animations[name]->DoubleFramesAndReverseTail();
return true;
}
bool AnimationContainer::DoubleFramesAndReverseTail()
{
if( lastAdded == NULL )
return false;
lastAdded->DoubleFramesAndReverseTail();
return true;
}
Animation* AnimationContainer::LoadBlenderAnimationSequence( std::string path, std::string name )
{
if( HasAnimation( name ) )
return animations[name];
NewAnimation( name );
int frame = 1;
std::string modelName = name;
// Remove the tailing blender formating if detected
StringFunctions::spliceOut( path, "_000001.obj" );
std::string modelString = path;
std::stringstream ss;
ss << modelString << "_000001.obj"; // First model in the sequence
std::stringstream ss2;
ss2 << modelName << frame;
// Keep going until there is a failed model load ( end of sequence )
while( ModelContainer::addModel( ss.str(), ss2.str(), true, false ) )
{
// Push the loaded model into the animation
AddFrameToAnimation( name, ModelContainer::getModel( ss2.str() ) );
frame++;
// Add the corrent amount of tail characters for the next model in the sequence
// - This only supports up to 999999 frames ... however; thats a freaking lot of frames. Would most
// likely run out of memory before frames
ss.str("");
if( frame < 10 )
{
ss << modelString << "_00000" << frame << ".obj";
}
else
if( frame < 100 )
{
ss << modelString << "_0000" << frame << ".obj";
}
else
if( frame < 1000 )
{
ss << modelString << "_000" << frame << ".obj";
}
else
if( frame < 10000 )
{
ss << modelString << "_00" << frame << ".obj";
}
else
if( frame < 100000 )
{
ss << modelString << "_0" << frame << ".obj";
}
else
{
ss << modelString << "_" << frame << ".obj";
}
// Set the next name
ss2.str("");
ss2 << modelName << frame;
}
if( frame == 1 )
{
delete animations[name];
return NULL;
}
return animations[name];
}
Animation* AnimationContainer::GetAnimation( std::string name )
{
if( !HasAnimation( name ) )
return NULL;
return animations[name];
}
bool AnimationContainer::HasAnimation( std::string name )
{
if( animations.find(name) == animations.end() )
return false;
return true;
}
void AnimationContainer::Clear( std::string compare )
{
}