Add origin and offsets
Origin point for a model part can be set with `origin` in model.toml; position and scale offsets can be set with `pos_offset` and `scale_offset` respectively.
This commit is contained in:
parent
4bb1c17ce4
commit
941c2043cd
13
TODO.md
13
TODO.md
|
@ -1,8 +1,11 @@
|
|||
# Before 1.0
|
||||
|
||||
## model
|
||||
- scale offset
|
||||
- position offset (or origin)
|
||||
|
||||
## graphics
|
||||
- prevent stretching from windows aspect ratio
|
||||
- prevent stretching from window aspect ratio
|
||||
- smoothing
|
||||
|
||||
## docs
|
||||
- model format documentation
|
||||
|
||||
## vision
|
||||
- fix worse facemark on dnn mode (maybe due to non-square roi?)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <vector>
|
||||
#include <zip.h>
|
||||
#include <fmt/core.h>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <tomlcpp.hpp> //dynamically link tomlcpp if it becomes common in repositories
|
||||
#include <model.hpp>
|
||||
#include <config.hpp>
|
||||
|
@ -11,7 +12,7 @@
|
|||
#define BUFFER_SIZE_TEXTURE 16777220 // 16 MiB
|
||||
|
||||
#define SUPPORTED_MODEL_MAJOR 0
|
||||
#define SUPPORTED_MODEL_MINOR 2
|
||||
#define SUPPORTED_MODEL_MINOR 3
|
||||
|
||||
void textureFromArchive(zip_t* archive, const char* path, ModelPart* part, size_t slot, std::string triggerName) {
|
||||
zip_file_t* textureFile = zip_fopen(archive, path, 0);
|
||||
|
@ -112,9 +113,9 @@ Model::Model(const char* path) {
|
|||
newPart.setFollowTarget(parentResult.second);
|
||||
|
||||
if (factorResult.first) {
|
||||
newPart.setFollowFactor((float)factorResult.second);
|
||||
newPart.factor = (float)factorResult.second;
|
||||
} else {
|
||||
newPart.setFollowFactor(1.0f);
|
||||
newPart.factor = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -123,10 +124,35 @@ Model::Model(const char* path) {
|
|||
auto scaleFacResult = partsVec[i].getDouble("scale_factor");
|
||||
|
||||
if (rotFacResult.first) {
|
||||
newPart.setRotationFactor((float)rotFacResult.second);
|
||||
newPart.rotFactor = (float)rotFacResult.second;
|
||||
}
|
||||
if (scaleFacResult.first) {
|
||||
newPart.setScaleFactor((float)scaleFacResult.second);
|
||||
newPart.scaleFactor = (float)scaleFacResult.second;
|
||||
}
|
||||
|
||||
// origin
|
||||
auto originArray = partsVec[i].getArray("origin");
|
||||
|
||||
if (originArray) {
|
||||
auto originVec = *originArray->getDoubleVector();
|
||||
|
||||
newPart.origin = glm::vec2((float)originVec[0], (float)originVec[1]);
|
||||
}
|
||||
|
||||
// offsets
|
||||
|
||||
auto posOffsetArray = partsVec[i].getArray("pos_offset");
|
||||
if (posOffsetArray) {
|
||||
auto offsetVec = *posOffsetArray->getDoubleVector();
|
||||
|
||||
newPart.posOffset = glm::vec2((float)offsetVec[0], (float)offsetVec[1]);
|
||||
}
|
||||
|
||||
auto scaleOffsetArray = partsVec[i].getArray("scale_offset");
|
||||
if (scaleOffsetArray) {
|
||||
auto offsetVec = *scaleOffsetArray->getDoubleVector();
|
||||
|
||||
newPart.scaleOffset = glm::vec2((float)offsetVec[0], (float)offsetVec[1]);
|
||||
}
|
||||
|
||||
// texture
|
||||
|
|
|
@ -33,29 +33,18 @@ void ModelPart::bindAndDraw() {
|
|||
}
|
||||
|
||||
void ModelPart::setBind(std::string bindName) {
|
||||
bind = bindStringToNum[bindName];
|
||||
bind = bindStringToNum[bindName];
|
||||
}
|
||||
|
||||
void ModelPart::setFollowTarget(std::string followTarget) {
|
||||
follow = bindStringToNum[followTarget];
|
||||
}
|
||||
|
||||
void ModelPart::setFollowFactor(float followFactor) {
|
||||
factor = followFactor;
|
||||
}
|
||||
|
||||
void ModelPart::setRotationFactor(float rotationFactor) {
|
||||
rotFactor = rotationFactor;
|
||||
}
|
||||
|
||||
void ModelPart::setScaleFactor(float scaleFac) {
|
||||
scaleFactor = scaleFac;
|
||||
follow = bindStringToNum[followTarget];
|
||||
}
|
||||
|
||||
void ModelPart::setTransform(glm::vec2 position, float rotation, float scale) {
|
||||
transMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(position.x, -position.y, 0.0f));
|
||||
transMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(position.x, -position.y, 0.0f) + glm::vec3(posOffset, 0.0f));
|
||||
transMatrix = glm::rotate(transMatrix, rotation * rotFactor, glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
transMatrix = glm::scale(transMatrix, glm::vec3(1,1,1) + (scale - 1) * scaleFactor);
|
||||
transMatrix = glm::scale(transMatrix, glm::vec3(1,1,1) + (scale - 1 + glm::vec3(scaleOffset, 0.0f)) * scaleFactor);
|
||||
transMatrix = glm::translate(transMatrix, glm::vec3(-origin, 0.0f));
|
||||
}
|
||||
|
||||
void ModelPart::processFaceData(struct FaceData faceData) {
|
||||
|
|
|
@ -24,26 +24,28 @@ class ModelPart {
|
|||
|
||||
glm::mat4 transMatrix = glm::mat4(1.0f);
|
||||
|
||||
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
|
||||
|
||||
float rotFactor = 1.0f;
|
||||
float scaleFactor = 1.0f;
|
||||
|
||||
bool empty = true;
|
||||
|
||||
public:
|
||||
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
|
||||
|
||||
float rotFactor = 1.0f;
|
||||
float scaleFactor = 1.0f;
|
||||
|
||||
glm::vec2 posOffset = glm::vec2(0,0);
|
||||
glm::vec2 scaleOffset = glm::vec2(0,0);
|
||||
|
||||
glm::vec2 origin = glm::vec2(0,0);
|
||||
|
||||
|
||||
ModelPart();
|
||||
|
||||
void bindAndDraw();
|
||||
|
||||
void setBind(std::string bindString);
|
||||
void setFollowTarget(std::string followString);
|
||||
void setFollowFactor(float followFactor);
|
||||
|
||||
void setRotationFactor(float rotationFactor);
|
||||
void setScaleFactor(float scaleFactor);
|
||||
void setBind(std::string bindName);
|
||||
void setFollowTarget(std::string followTarget);
|
||||
|
||||
void setTransform(glm::vec2 position, float rotation, float scale);
|
||||
|
||||
|
|
Loading…
Reference in a new issue