-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFacialAnimation.h
213 lines (201 loc) · 5.55 KB
/
FacialAnimation.h
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
#pragma once
#include <Ogre.h>
#include "tinyxml.h"
using namespace Ogre;
using namespace std;
#define SI_COUNT 9
#define PROCESS_ANIM 0.2f
class MorphState
{
public:
MorphState(){mPatch=0;};
~MorphState(){};
void init(Real second, String key)
{
mKey=key;
mSecond=second;
}
void init(Real second,String key,bool patch)
{
mKey=key;
mSecond=second;
mPatch=patch;
if (mPatch)
{
LogManager::getSingleton().logMessage("Experimental facial patch");
}
}
inline Real getSecond(){return mSecond;}
inline String getKey(){return mKey;}
int getIndex()
{
//int pc = (mPatch+1);
int pc=1;
if (mKey=="A")
return 2*pc;
if (mKey=="E")
return 3*pc;
if (mKey=="O")
return 4*pc;
if (mKey=="U")
return 5*pc;
if (mKey=="I")
return 6*pc;
if (mKey=="B")
return 7*pc;
if (mKey=="C")
return 8*pc;
if (mKey=="D")
return 7*pc;
if (mKey=="F")
return 8*pc;
if (mKey=="G")
return 7*pc;
if (mKey=="H")
return 8*pc;
if (mKey=="J")
return 7*pc;
if (mKey=="K")
return 8*pc;
if (mKey=="L")
return -1;
if (mKey=="M")
return -1;
if (mKey=="N")
return 7*pc;
if (mKey=="P")
return -1;
if (mKey=="Q")
return 8*pc;
if (mKey=="R")
return 7*pc;
if (mKey=="S")
return 7*pc;
if (mKey=="T")
return 7*pc;
if (mKey=="V")
return 8*pc;
if (mKey=="W")
return 7*pc;
if (mKey=="X")
return 8*pc;
if (mKey=="Y")
return 7*pc;
if (mKey=="Z")
return 8*pc;
return 8*pc;
}
bool isPatched(){return mPatch>0;}
private:
int mPatch;
Real mSecond;
String mKey;
};
class FacialAnimation
{
public:
FacialAnimation();
~FacialAnimation();
Entity* preInit(String meshFile,String name);
void init(String xmlFile);
void animate(Vector3 pos);
void upd(Real tm);
void setSubtitle(String subt)
{
subtitle=subt;
}
void destroy()
{
}
void updatePose(int index, float weight){
//get the pose list
PoseList poseList = mesh->getPoseList();
int curPoseIndex = index;
//loop through each submesh
int numSubMeshes = mesh->getNumSubMeshes();
//skip submesh 0 since it is the shared geometry, and we have no poses on that
for(int curSubMesh = 1; curSubMesh <= numSubMeshes; curSubMesh++)
{
try
{
if (mPatched)
{
//LogManager::getSingleton().logMessage("INDEXes"+StringConverter::toString(curPoseIndex*numSubMeshes+curSubMesh-1));
vertexPoseKeyFrameMap[curSubMesh]->updatePoseReference(curPoseIndex*numSubMeshes+curSubMesh-1, weight);
// Dirty animation state since we're fudging this manually
//If we don't notify dirty, Ogre doesn't know to update this state
//and nothing happens
head->getAnimationState("manl"+head->getName())->getParent()->_notifyDirty();
}
else
{
//LogManager::getSingleton().logMessage("INDEX"+StringConverter::toString(index));
vertexPoseKeyFrameMap[curSubMesh]->updatePoseReference(curPoseIndex, weight);
// Dirty animation state since we're fudging this manually
//If we don't notify dirty, Ogre doesn't know to update this state
//and nothing happens
head->getAnimationState("manl"+head->getName())->getParent()->_notifyDirty();
}
}
catch(...)
{
}
}
}
void updatePose(int index, float weight,bool patch){
//get the pose list
PoseList poseList = mesh->getPoseList();
int curPoseIndex = index;
//loop through each submesh
int numSubMeshes = mesh->getNumSubMeshes();
//skip submesh 0 since it is the shared geometry, and we have no poses on that
for(int curSubMesh = 1; curSubMesh <= numSubMeshes; curSubMesh++)
{
try
{
if (patch)
{
//LogManager::getSingleton().logMessage("INDEXes"+StringConverter::toString(curPoseIndex+curSubMesh-1));
vertexPoseKeyFrameMap[curSubMesh]->updatePoseReference(curPoseIndex+curSubMesh-1, weight);
// Dirty animation state since we're fudging this manually
//If we don't notify dirty, Ogre doesn't know to update this state
//and nothing happens
head->getAnimationState("manl"+head->getName())->getParent()->_notifyDirty();
}
else
{
//LogManager::getSingleton().logMessage("INDEX"+StringConverter::toString(index));
vertexPoseKeyFrameMap[curSubMesh]->updatePoseReference(curPoseIndex, weight);
// Dirty animation state since we're fudging this manually
//If we don't notify dirty, Ogre doesn't know to update this state
//and nothing happens
head->getAnimationState("manl"+head->getName())->getParent()->_notifyDirty();
}
}
catch(...)
{
}
}
}
String getAttrib(TiXmlElement *XMLNode, const String ¶meter, const String &defaultValue = "");
Real getAttribReal(TiXmlElement *XMLNode, const String ¶meter, Real defaultValue = 0);
bool getAttribBool(TiXmlElement *XMLNode, const String ¶meter, bool defaultValue = false);
private:
bool mPatched;
String subtitle;
bool mAnimate;
long curstate;
Real duration;
map<int, Ogre::VertexPoseKeyFrame*> vertexPoseKeyFrameMap;
MorphState curMState;
AnimationState* manualAnimState;
VertexPoseKeyFrame* manualKeyFrame;
String soundFile;
Vector3 mPos;
Ogre::Entity* head;
MeshPtr mesh;
Real endAnim,timeAnim;
vector<MorphState> letters;
TiXmlDocument *SequenceDoc;
TiXmlElement *SequenceRoot;
};