nodes per layer and transform origin fixes
This commit is contained in:
parent
53f3b92e70
commit
7d4786d418
7 changed files with 112 additions and 74 deletions
|
@ -6,6 +6,7 @@
|
||||||
#include "ofGraphics.h"
|
#include "ofGraphics.h"
|
||||||
#include "ofRectangle.h"
|
#include "ofRectangle.h"
|
||||||
#include "ofUtils.h"
|
#include "ofUtils.h"
|
||||||
|
#include "quaternion.hpp"
|
||||||
|
|
||||||
namespace ofxVariableLab {
|
namespace ofxVariableLab {
|
||||||
|
|
||||||
|
@ -224,80 +225,15 @@ void GPUFontAtlasLayerCombo::draw(){
|
||||||
font->collectBoundingBoxes(layer->getVariationText(),
|
font->collectBoundingBoxes(layer->getVariationText(),
|
||||||
bb, bbs, advanceY,
|
bb, bbs, advanceY,
|
||||||
true, layer->getProps().fontSize_px);
|
true, layer->getProps().fontSize_px);
|
||||||
ofNode momNode;
|
|
||||||
ofNode node;
|
|
||||||
node.setParent(momNode);
|
|
||||||
glm::vec4 transformOrigin;
|
glm::vec4 transformOrigin;
|
||||||
switch(layer->getProps().transformOrigin){
|
getAndApplyTransformOrigin(transformOrigin,
|
||||||
default:
|
layer->getOuterNode(),
|
||||||
case Layer::TransformOrigin::TOP_LEFT: {
|
layer->getInnerNode(),
|
||||||
node.move(glm::vec3(0,
|
bb,
|
||||||
ascender,
|
ascender,
|
||||||
0));
|
advanceY,
|
||||||
momNode.rotateDeg(layer->getProps().rotation, glm::vec3(0, 0, 1));
|
layer->getProps());
|
||||||
transformOrigin = glm::vec4(layer->getProps().x,
|
bb.multiply(layer->getInnerNode().getGlobalTransformMatrix());
|
||||||
layer->getProps().y - ascender,
|
|
||||||
0, 1);
|
|
||||||
momNode.move(transformOrigin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Layer::TransformOrigin::TOP_RIGHT: {
|
|
||||||
float moveX = bb.p1.x - bb.p0.x;
|
|
||||||
node.move(glm::vec3(-moveX,
|
|
||||||
ascender,
|
|
||||||
0));
|
|
||||||
momNode.rotateDeg(layer->getProps().rotation, glm::vec3(0, 0, 1));
|
|
||||||
transformOrigin = glm::vec4(layer->getProps().x + moveX,
|
|
||||||
layer->getProps().y - ascender,
|
|
||||||
0, 1);
|
|
||||||
momNode.move(transformOrigin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Layer::TransformOrigin::CENTER: {
|
|
||||||
float moveX = (bb.p2.x - bb.p0.x) * 0.5 + bb.p0.x;
|
|
||||||
float moveY = (bb.p2.y - bb.p0.y) * 0.5 - bb.p2.y;
|
|
||||||
node.move(glm::vec3(-moveX,
|
|
||||||
moveY,
|
|
||||||
0));
|
|
||||||
momNode.rotateDeg(layer->getProps().rotation, glm::vec3(0, 0, 1));
|
|
||||||
transformOrigin = glm::vec4(layer->getProps().x + moveX,
|
|
||||||
layer->getProps().y - moveY,
|
|
||||||
0, 1);
|
|
||||||
momNode.move(transformOrigin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Layer::TransformOrigin::BOTTOM_LEFT: {
|
|
||||||
float moveY = ascender - advanceY;
|
|
||||||
node.move(glm::vec3(0,
|
|
||||||
moveY,
|
|
||||||
0));
|
|
||||||
momNode.rotateDeg(layer->getProps().rotation, glm::vec3(0, 0, 1));
|
|
||||||
transformOrigin = glm::vec4(layer->getProps().x,
|
|
||||||
layer->getProps().y - moveY,
|
|
||||||
0, 1);
|
|
||||||
momNode.move(transformOrigin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case Layer::TransformOrigin::BOTTOM_RIGHT: {
|
|
||||||
float moveY = ascender - (advanceY);
|
|
||||||
float moveX = (bb.p2.x - bb.p0.x);
|
|
||||||
node.move(glm::vec3(-moveX,
|
|
||||||
moveY,
|
|
||||||
0));
|
|
||||||
momNode.rotateDeg(layer->getProps().rotation, glm::vec3(0, 0, 1));
|
|
||||||
transformOrigin = glm::vec4(layer->getProps().x + moveX,
|
|
||||||
layer->getProps().y - moveY,
|
|
||||||
0, 1);
|
|
||||||
momNode.move(transformOrigin);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
bb.multiply(node.getGlobalTransformMatrix());
|
|
||||||
ofVboMesh mesh;
|
ofVboMesh mesh;
|
||||||
mesh.addVertices({bb.p0, bb.p1, bb.p2, bb.p3,
|
mesh.addVertices({bb.p0, bb.p1, bb.p2, bb.p3,
|
||||||
glm::vec4(layer->getProps().x, layer->getProps().y, 0, 1),
|
glm::vec4(layer->getProps().x, layer->getProps().y, 0, 1),
|
||||||
|
@ -313,7 +249,7 @@ void GPUFontAtlasLayerCombo::draw(){
|
||||||
});
|
});
|
||||||
outerBoundingBoxes.push_back(mesh);
|
outerBoundingBoxes.push_back(mesh);
|
||||||
|
|
||||||
font->collectVerticesAndIndices(node,
|
font->collectVerticesAndIndices(layer->getInnerNode(),
|
||||||
bbs,
|
bbs,
|
||||||
vertices,
|
vertices,
|
||||||
indices,
|
indices,
|
||||||
|
@ -350,4 +286,74 @@ void GPUFontAtlasLayerCombo::draw(){
|
||||||
, 20, 20);
|
, 20, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GPUFontAtlasLayerCombo::getAndApplyTransformOrigin(glm::vec4 & transformOrigin,
|
||||||
|
ofNode & momNode,
|
||||||
|
ofNode & node,
|
||||||
|
const ofxGPUFont::Font::BoundingBox & bb,
|
||||||
|
const float ascender,
|
||||||
|
const float advanceY,
|
||||||
|
const Layer::Props & props){
|
||||||
|
switch(props.transformOrigin){
|
||||||
|
default:
|
||||||
|
case Layer::TransformOrigin::TOP_LEFT: {
|
||||||
|
node.setPosition(glm::vec3(0,
|
||||||
|
ascender,
|
||||||
|
0));
|
||||||
|
transformOrigin = glm::vec4(props.x,
|
||||||
|
props.y - ascender,
|
||||||
|
0, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Layer::TransformOrigin::TOP_RIGHT: {
|
||||||
|
float moveX = bb.p1.x - bb.p0.x;
|
||||||
|
node.setPosition(glm::vec3(-moveX,
|
||||||
|
ascender,
|
||||||
|
0));
|
||||||
|
transformOrigin = glm::vec4(props.x + moveX,
|
||||||
|
props.y - ascender,
|
||||||
|
0, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Layer::TransformOrigin::CENTER: {
|
||||||
|
float moveX = (bb.p2.x - bb.p0.x) * 0.5 + bb.p0.x;
|
||||||
|
float moveY = (bb.p2.y - bb.p0.y) * 0.5 - bb.p2.y;
|
||||||
|
node.setPosition(glm::vec3(-moveX,
|
||||||
|
moveY,
|
||||||
|
0));
|
||||||
|
transformOrigin = glm::vec4(props.x + moveX,
|
||||||
|
props.y - moveY,
|
||||||
|
0, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Layer::TransformOrigin::BOTTOM_LEFT: {
|
||||||
|
float moveY = ascender - advanceY;
|
||||||
|
node.setPosition(glm::vec3(0,
|
||||||
|
moveY,
|
||||||
|
0));
|
||||||
|
transformOrigin = glm::vec4(props.x,
|
||||||
|
props.y - moveY,
|
||||||
|
0, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case Layer::TransformOrigin::BOTTOM_RIGHT: {
|
||||||
|
float moveY = ascender - (advanceY);
|
||||||
|
float moveX = (bb.p2.x - bb.p0.x);
|
||||||
|
node.setPosition(glm::vec3(-moveX,
|
||||||
|
moveY,
|
||||||
|
0));
|
||||||
|
transformOrigin = glm::vec4(props.x + moveX,
|
||||||
|
props.y - moveY,
|
||||||
|
0, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
momNode.setOrientation(glm::quat(1, 0, 0, 0));
|
||||||
|
momNode.rotateDeg(props.rotation, glm::vec3(0, 0, 1));
|
||||||
|
momNode.setPosition(transformOrigin);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace ofxVariableLab {
|
namespace ofxVariableLab {
|
||||||
|
|
||||||
struct GPUFontAtlasLayerComboSettings : public AtlasLayerComboSettings {
|
struct GPUFontAtlasLayerComboSettings : public AtlasLayerComboSettings {
|
||||||
int gpuTextureOffset = 0;
|
int gpuTextureOffset = 0;
|
||||||
};
|
};
|
||||||
|
@ -55,6 +56,13 @@ class GPUFontAtlasLayerCombo : public AtlasLayerCombo {
|
||||||
return glm::lookAt(glm::vec3(0, 0, distance), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)) * glm::mat4(rotation) * translation;
|
return glm::lookAt(glm::vec3(0, 0, distance), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)) * glm::mat4(rotation) * translation;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
void getAndApplyTransformOrigin(glm::vec4 & transformOrigin,
|
||||||
|
ofNode & momNode,
|
||||||
|
ofNode & node,
|
||||||
|
const ofxGPUFont::Font::BoundingBox & bb,
|
||||||
|
const float ascender,
|
||||||
|
const float advanceY,
|
||||||
|
const Layer::Props & props);
|
||||||
public:
|
public:
|
||||||
void setup(const ComboIdentifier & identifier,
|
void setup(const ComboIdentifier & identifier,
|
||||||
AtlasLayerComboSettings settings = GPUFontAtlasLayerComboSettings()) override;
|
AtlasLayerComboSettings settings = GPUFontAtlasLayerComboSettings()) override;
|
||||||
|
|
|
@ -15,6 +15,7 @@ void GPUFontLayer::setup(const LayerSettings & settings){
|
||||||
id = "layer-" + ofToString(Layer::n_layers);
|
id = "layer-" + ofToString(Layer::n_layers);
|
||||||
n_layers++;
|
n_layers++;
|
||||||
}
|
}
|
||||||
|
innerNode.setParent(outerNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPUFontLayer::update(){
|
void GPUFontLayer::update(){
|
||||||
|
@ -99,6 +100,12 @@ const Layer::Props & GPUFontLayer::getProps() const {
|
||||||
const glm::vec4 & GPUFontLayer::getColor() const {
|
const glm::vec4 & GPUFontLayer::getColor() const {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
ofNode & GPUFontLayer::getOuterNode(){
|
||||||
|
return outerNode;
|
||||||
|
}
|
||||||
|
ofNode & GPUFontLayer::getInnerNode(){
|
||||||
|
return innerNode;
|
||||||
|
}
|
||||||
void GPUFontLayer::clearPropsBuffer(){
|
void GPUFontLayer::clearPropsBuffer(){
|
||||||
propsBuffer.clear();
|
propsBuffer.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,8 @@ class GPUFontLayer : public Layer {
|
||||||
void isWithNewMom() override;
|
void isWithNewMom() override;
|
||||||
const ComboIdentifier & getMomsComboIdentifier() const override;
|
const ComboIdentifier & getMomsComboIdentifier() const override;
|
||||||
void setMomsComboIdentifier(const ComboIdentifier & identifier) override;
|
void setMomsComboIdentifier(const ComboIdentifier & identifier) override;
|
||||||
|
ofNode & getOuterNode() override;
|
||||||
|
ofNode & getInnerNode() override;
|
||||||
|
|
||||||
const vector <ofxGPUFont::GlyphIdentity> & getVariationText();
|
const vector <ofxGPUFont::GlyphIdentity> & getVariationText();
|
||||||
|
|
||||||
|
@ -65,5 +67,7 @@ class GPUFontLayer : public Layer {
|
||||||
bool notHappyWithMom = false;
|
bool notHappyWithMom = false;
|
||||||
LayerType type = GPUFONT;
|
LayerType type = GPUFONT;
|
||||||
glm::vec4 color;
|
glm::vec4 color;
|
||||||
|
ofNode outerNode;
|
||||||
|
ofNode innerNode;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,8 @@ class Layer {
|
||||||
virtual void isWithNewMom() = 0;
|
virtual void isWithNewMom() = 0;
|
||||||
virtual const ComboIdentifier & getMomsComboIdentifier() const = 0;
|
virtual const ComboIdentifier & getMomsComboIdentifier() const = 0;
|
||||||
virtual void setMomsComboIdentifier(const ComboIdentifier & identifier) = 0;
|
virtual void setMomsComboIdentifier(const ComboIdentifier & identifier) = 0;
|
||||||
|
virtual ofNode & getOuterNode() = 0;
|
||||||
|
virtual ofNode & getInnerNode() = 0;
|
||||||
static int n_layers;
|
static int n_layers;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ void MsdfLayer::setup(const LayerSettings & settings){
|
||||||
id = "layer-" + ofToString(Layer::n_layers);
|
id = "layer-" + ofToString(Layer::n_layers);
|
||||||
n_layers++;
|
n_layers++;
|
||||||
}
|
}
|
||||||
|
innerNode.setParent(outerNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MsdfLayer::update(){
|
void MsdfLayer::update(){
|
||||||
|
@ -298,6 +299,12 @@ const ComboIdentifier & MsdfLayer::getMomsComboIdentifier() const {
|
||||||
void MsdfLayer::setMomsComboIdentifier(const ComboIdentifier & identifier){
|
void MsdfLayer::setMomsComboIdentifier(const ComboIdentifier & identifier){
|
||||||
momsComboIdentifier = identifier;
|
momsComboIdentifier = identifier;
|
||||||
}
|
}
|
||||||
|
ofNode & MsdfLayer::getOuterNode(){
|
||||||
|
return outerNode;
|
||||||
|
}
|
||||||
|
ofNode & MsdfLayer::getInnerNode(){
|
||||||
|
return innerNode;
|
||||||
|
}
|
||||||
void MsdfLayer::setAtlas(shared_ptr <ofxMsdfgen::Atlas> _atlas){
|
void MsdfLayer::setAtlas(shared_ptr <ofxMsdfgen::Atlas> _atlas){
|
||||||
atlas = _atlas;
|
atlas = _atlas;
|
||||||
// TODO: this does not seem proper
|
// TODO: this does not seem proper
|
||||||
|
|
|
@ -36,6 +36,8 @@ class MsdfLayer : public Layer {
|
||||||
void isWithNewMom() override;
|
void isWithNewMom() override;
|
||||||
const ComboIdentifier & getMomsComboIdentifier() const override;
|
const ComboIdentifier & getMomsComboIdentifier() const override;
|
||||||
void setMomsComboIdentifier(const ComboIdentifier & identifier) override;
|
void setMomsComboIdentifier(const ComboIdentifier & identifier) override;
|
||||||
|
ofNode & getOuterNode() override;
|
||||||
|
ofNode & getInnerNode() override;
|
||||||
|
|
||||||
void setAtlas(shared_ptr <ofxMsdfgen::Atlas> _atlas);
|
void setAtlas(shared_ptr <ofxMsdfgen::Atlas> _atlas);
|
||||||
shared_ptr <ofxMsdfgen::Atlas> getAtlas() const;
|
shared_ptr <ofxMsdfgen::Atlas> getAtlas() const;
|
||||||
|
@ -56,5 +58,7 @@ class MsdfLayer : public Layer {
|
||||||
ComboIdentifier momsComboIdentifier;
|
ComboIdentifier momsComboIdentifier;
|
||||||
LayerType type = MSDFGEN;
|
LayerType type = MSDFGEN;
|
||||||
glm::vec4 color;
|
glm::vec4 color;
|
||||||
|
ofNode outerNode;
|
||||||
|
ofNode innerNode;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue