multiple nodes for collect/drawing
This commit is contained in:
parent
01740f7635
commit
106db1462c
2 changed files with 55 additions and 65 deletions
|
@ -314,15 +314,13 @@ void MsdfLayer::setBoundingBox(const Layer::BoundingBox & boundingBox){
|
|||
this->boundingBox = boundingBox;
|
||||
}
|
||||
bool MsdfLayer::collectCharacter(const char character,
|
||||
const ofNode & node,
|
||||
vector <ofNode> & nodes,
|
||||
const ofCamera & camera,
|
||||
glm::vec4 color,
|
||||
ofxVariableLab::FontVariation fontVariation){
|
||||
|
||||
OFX_PROFILER_FUNCTION()
|
||||
const ofImage & atlasImage = atlas->getAtlasImage();
|
||||
ofNode n = node;
|
||||
n.setScale(n.getScale() * scaleFactor);
|
||||
int atlas_w = atlasImage.getWidth();
|
||||
int atlas_h = atlasImage.getHeight();
|
||||
|
||||
|
@ -355,17 +353,6 @@ bool MsdfLayer::collectCharacter(const char character,
|
|||
float w = glm::mix(float(w_a), float(w_b), mix);
|
||||
float h = glm::mix(float(h_a), float(h_b), mix);
|
||||
|
||||
glm::vec4 p0 = n.getGlobalTransformMatrix() * glm::vec4(0, 0, 0, 1);
|
||||
glm::vec4 p1 = n.getGlobalTransformMatrix() * glm::vec4(0, h, 0, 1);
|
||||
glm::vec4 p2 = n.getGlobalTransformMatrix() * glm::vec4(w, h, 0, 1);
|
||||
glm::vec4 p3 = n.getGlobalTransformMatrix() * glm::vec4(w, 0, 0, 1);
|
||||
|
||||
if(isInside(camera, p0)
|
||||
|| isInside(camera, p1)
|
||||
|| isInside(camera, p2)
|
||||
|| isInside(camera, p3)){
|
||||
OFX_PROFILER_SCOPE("prepare vertices / indices");
|
||||
|
||||
glm::vec2 translation_a = glm::vec2(float(x_a) / float(atlas_w),
|
||||
float(y_a) / float(atlas_h));
|
||||
glm::vec2 scale_a = glm::vec2(float(w_a) / float(atlas_w),
|
||||
|
@ -383,44 +370,47 @@ bool MsdfLayer::collectCharacter(const char character,
|
|||
glm::vec2 uv2_b = scale_b + translation_b;
|
||||
glm::vec2 uv3_a = glm::vec2(scale_a.x, 0) + translation_a;
|
||||
glm::vec2 uv3_b = glm::vec2(scale_b.x, 0) + translation_b;
|
||||
for(int i = 0; i < 1; i++){
|
||||
float distance = 200;
|
||||
|
||||
for(int i = 0; i < nodes.size(); i++){
|
||||
ofNode & node = nodes[i];
|
||||
glm::vec4 p0 = node.getGlobalTransformMatrix() * glm::vec4(0, 0, 0, 1);
|
||||
glm::vec4 p1 = node.getGlobalTransformMatrix() * glm::vec4(0, h, 0, 1);
|
||||
glm::vec4 p2 = node.getGlobalTransformMatrix() * glm::vec4(w, h, 0, 1);
|
||||
glm::vec4 p3 = node.getGlobalTransformMatrix() * glm::vec4(w, 0, 0, 1);
|
||||
|
||||
int32_t base = static_cast <int32_t>(vertices.size());
|
||||
vertices.push_back(BufferVertex{
|
||||
{p0.x, p0.y + i * distance, p0.z, p0.w},
|
||||
{p0.x, p0.y, p0.z, p0.w},
|
||||
{uv0_a.x, uv0_a.y},
|
||||
{uv0_b.x, uv0_b.y},
|
||||
{color.r, color.g, color.b, color.a},
|
||||
mix
|
||||
});
|
||||
vertices.push_back(BufferVertex{
|
||||
{p1.x, p1.y + i * distance, p1.z, p1.w},
|
||||
{p1.x, p1.y, p1.z, p1.w},
|
||||
{uv1_a.x, uv1_a.y},
|
||||
{uv1_b.x, uv1_b.y},
|
||||
{color.r, color.g, color.b, color.a},
|
||||
mix
|
||||
});
|
||||
vertices.push_back(BufferVertex{
|
||||
{p2.x, p2.y + i * distance, p2.z, p2.w},
|
||||
{p2.x, p2.y, p2.z, p2.w},
|
||||
{uv2_a.x, uv2_a.y},
|
||||
{uv2_b.x, uv2_b.y},
|
||||
{color.r, color.g, color.b, color.a},
|
||||
mix
|
||||
});
|
||||
vertices.push_back(BufferVertex{
|
||||
{p3.x, p3.y + i * distance, p3.z, p3.w},
|
||||
{p3.x, p3.y, p3.z, p3.w},
|
||||
{uv3_a.x, uv3_a.y},
|
||||
{uv3_b.x, uv3_b.y},
|
||||
{color.r, color.g, color.b, color.a},
|
||||
mix
|
||||
});
|
||||
indices.insert(indices.end(), {base, base + 1, base + 2, base + 2, base + 3, base});
|
||||
}
|
||||
nElements++;
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void MsdfLayer::setAtlas(shared_ptr <ofxMsdfgen::Atlas> _atlas){
|
||||
atlas = _atlas;
|
||||
|
|
|
@ -57,7 +57,7 @@ class MsdfLayer : public Layer {
|
|||
const Layer::BoundingBox & getBoundingBox() override;
|
||||
void setBoundingBox(const Layer::BoundingBox & boundingBox) override;
|
||||
bool collectCharacter(const char character,
|
||||
const ofNode & node,
|
||||
vector <ofNode> & nodes,
|
||||
const ofCamera & camera,
|
||||
glm::vec4 color = glm::vec4(1, 1, 1, 1),
|
||||
ofxVariableLab::FontVariation fontVariation = ofxVariableLab::FontVariation());
|
||||
|
|
Loading…
Reference in a new issue