Add eye direction in model

Adds eye direction support in the model system and in the 'test' model.
This commit is contained in:
Epicalert 2021-06-08 10:53:59 +08:00
parent 26c11c414f
commit 09c60db8c1
No known key found for this signature in database
GPG key ID: CAA46F858D0979BD
7 changed files with 34 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

BIN
models/test/face-iris.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

View file

@ -17,6 +17,14 @@ bind = "head"
follow = "face"
factor = 0.85
[[part]]
texture = "face-iris.png"
bind = "head"
follow = "face"
factor = 0.85
offset_bind = "offset-eyes"
offset_factor = 0.03
[[part]]
bind = "head"
follow = "face"

View file

@ -137,6 +137,7 @@ void cvFrame() {
landmarks[biggestFace][30].x * 2 / (float)frame.cols - 1,
landmarks[biggestFace][30].y * 2 / (float)frame.rows - 1
);
faceData.positions[OFFSET_EYES] = eyeVector;
faceData.triggers[TRIGGER_NULL] = false;
faceData.triggers[TRIGGER_MOUTH_OPEN] =

View file

@ -122,6 +122,7 @@ Model::Model(const char* path) {
// rotation and scale factor
auto rotFacResult = partsVec[i].getDouble("rot_factor");
auto scaleFacResult = partsVec[i].getDouble("scale_factor");
auto offsetFacResult = partsVec[i].getDouble("offset_factor");
if (rotFacResult.first) {
newPart.rotFactor = (float)rotFacResult.second;
@ -129,6 +130,10 @@ Model::Model(const char* path) {
if (scaleFacResult.first) {
newPart.scaleFactor = (float)scaleFacResult.second;
}
if (offsetFacResult.first) {
newPart.offsetFactor = (float)offsetFacResult.second;
}
// origin
auto originArray = partsVec[i].getArray("origin");
@ -154,6 +159,13 @@ Model::Model(const char* path) {
newPart.scaleOffset = glm::vec2((float)offsetVec[0], (float)offsetVec[1]);
}
// offset bind
auto offsetBindResult = partsVec[i].getString("offset_bind");
if (offsetBindResult.first) {
newPart.setOffsetBind(offsetBindResult.second);
}
// texture
auto textureSingle = partsVec[i].getString("texture");

View file

@ -11,6 +11,7 @@ std::map<std::string, int> bindStringToNum {
{"null", BIND_NULL},
{"head", BIND_HEAD},
{"face", BIND_FACE},
{"offset-eyes", OFFSET_EYES},
};
std::map<std::string, bool> triggerStringToNum {
@ -40,6 +41,10 @@ void ModelPart::setFollowTarget(std::string followTarget) {
follow = bindStringToNum[followTarget];
}
void ModelPart::setOffsetBind(std::string bindName) {
offsetBind = bindStringToNum[bindName];
}
void ModelPart::smoothTransform(glm::vec2 position, float rotation, float scale) {
histPositions[histI] = position;
histRotations[histI] = rotation;
@ -78,7 +83,8 @@ void ModelPart::processFaceData(struct FaceData faceData) {
glm::vec2 bindPosition = faceData.positions[bind];
glm::vec2 followPosition = faceData.positions[follow];
glm::vec2 followDirection = followPosition - bindPosition;
glm::vec2 newPosition = bindPosition + (followDirection * factor);
glm::vec2 offset = faceData.positions[offsetBind] * offsetFactor;
glm::vec2 newPosition = bindPosition + offset + (followDirection * factor);
smoothTransform(newPosition, faceData.headRotation, faceData.scale);

View file

@ -11,6 +11,9 @@
#define BIND_HEAD 0x01
#define BIND_FACE 0x02
#define OFFSET_EYES 0x10
#define TRIGGER_NULL 0x00
#define TRIGGER_MOUTH_OPEN 0x01
@ -38,6 +41,8 @@ class ModelPart {
int bind = BIND_NULL;
int follow = BIND_NULL;
float factor = 0.0f; //default factor of 0 so part will not follow a null by default
int offsetBind = BIND_NULL;
float offsetFactor = 0.0f;
float rotFactor = 1.0f;
float scaleFactor = 1.0f;
@ -54,6 +59,7 @@ class ModelPart {
void setBind(std::string bindName);
void setFollowTarget(std::string followTarget);
void setOffsetBind(std::string bindName);
void smoothTransform(glm::vec2 position, float rotation, float scale);
void setTransform(glm::vec2 position, float rotation, float scale);