feat: connect geometry position to GLMesh
This commit is contained in:
@@ -53,13 +53,19 @@ public:
|
|||||||
// TODO:make this private (primitive friend classes only)
|
// TODO:make this private (primitive friend classes only)
|
||||||
data_->push_back(value);
|
data_->push_back(value);
|
||||||
}
|
}
|
||||||
T getValue(uint pos)
|
|
||||||
|
std::vector<T> getData() const
|
||||||
|
{
|
||||||
|
return *data_;
|
||||||
|
}
|
||||||
|
|
||||||
|
T getValue(uint pos) const
|
||||||
{
|
{
|
||||||
// TODO:protect against invalid positions
|
// TODO:protect against invalid positions
|
||||||
// TODO: cast types
|
// TODO: cast types
|
||||||
return data_->at(pos);
|
return data_->at(pos);
|
||||||
}
|
}
|
||||||
std::string getName()
|
std::string getName() const
|
||||||
{
|
{
|
||||||
return name_;
|
return name_;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,17 +8,24 @@
|
|||||||
using namespace enzo;
|
using namespace enzo;
|
||||||
geo::Geometry::Geometry()
|
geo::Geometry::Geometry()
|
||||||
{
|
{
|
||||||
|
addVector3Attribute(ga::AttrOwner::POINT, "P");
|
||||||
}
|
}
|
||||||
|
|
||||||
ga::AttributeHandle<int> geo::Geometry::addIntAttribute(ga::AttributeOwner owner, std::string name)
|
ga::AttributeHandle<int> geo::Geometry::addIntAttribute(ga::AttributeOwner owner, std::string name)
|
||||||
{
|
{
|
||||||
auto newAttribute = std::make_shared<ga::Attribute>(name, ga::AttrType::intT);
|
auto newAttribute = std::make_shared<ga::Attribute>(name, ga::AttrType::intT);
|
||||||
getOwnerVector(owner).push_back(newAttribute);
|
getAttributeStore(owner).push_back(newAttribute);
|
||||||
return ga::AttributeHandle<int>(newAttribute);
|
return ga::AttributeHandle<int>(newAttribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<ga::Attribute>>& geo::Geometry::getOwnerVector(ga::AttributeOwner& owner)
|
ga::AttributeHandle<bt::Vector3> geo::Geometry::addVector3Attribute(ga::AttributeOwner owner, std::string name)
|
||||||
|
{
|
||||||
|
auto newAttribute = std::make_shared<ga::Attribute>(name, ga::AttrType::vectorT);
|
||||||
|
getAttributeStore(owner).push_back(newAttribute);
|
||||||
|
return ga::AttributeHandle<bt::Vector3>(newAttribute);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<ga::Attribute>>& geo::Geometry::getAttributeStore(ga::AttributeOwner& owner)
|
||||||
{
|
{
|
||||||
switch(owner)
|
switch(owner)
|
||||||
{
|
{
|
||||||
@@ -42,7 +49,7 @@ std::vector<std::shared_ptr<ga::Attribute>>& geo::Geometry::getOwnerVector(ga::A
|
|||||||
|
|
||||||
std::shared_ptr<ga::Attribute> geo::Geometry::getAttribByName(ga::AttributeOwner owner, std::string name)
|
std::shared_ptr<ga::Attribute> geo::Geometry::getAttribByName(ga::AttributeOwner owner, std::string name)
|
||||||
{
|
{
|
||||||
auto& vector = getOwnerVector(owner);
|
auto& vector = getAttributeStore(owner);
|
||||||
for(auto it=vector.begin(); it!=vector.end(); ++it)
|
for(auto it=vector.begin(); it!=vector.end(); ++it)
|
||||||
{
|
{
|
||||||
if((*it)->getName()==name)
|
if((*it)->getName()==name)
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ class Geometry
|
|||||||
public:
|
public:
|
||||||
Geometry();
|
Geometry();
|
||||||
ga::AttributeHandle<int> addIntAttribute(ga::AttributeOwner owner, std::string name);
|
ga::AttributeHandle<int> addIntAttribute(ga::AttributeOwner owner, std::string name);
|
||||||
|
ga::AttributeHandle<bt::Vector3> addVector3Attribute(ga::AttributeOwner owner, std::string name);
|
||||||
std::shared_ptr<ga::Attribute> getAttribByName(ga::AttributeOwner owner, std::string name);
|
std::shared_ptr<ga::Attribute> getAttribByName(ga::AttributeOwner owner, std::string name);
|
||||||
private:
|
private:
|
||||||
using attribVector = std::vector<std::shared_ptr<ga::Attribute>>;
|
using attribVector = std::vector<std::shared_ptr<ga::Attribute>>;
|
||||||
attribVector& getOwnerVector(ga::AttributeOwner& owner);
|
attribVector& getAttributeStore(ga::AttributeOwner& owner);
|
||||||
attribVector pointAttributes_;
|
attribVector pointAttributes_;
|
||||||
attribVector vertexAttributes_;
|
attribVector vertexAttributes_;
|
||||||
attribVector primitiveAttributes_;
|
attribVector primitiveAttributes_;
|
||||||
|
|||||||
@@ -15,6 +15,17 @@ void GLMesh::init()
|
|||||||
|
|
||||||
initBuffers();
|
initBuffers();
|
||||||
|
|
||||||
|
vertexPosData = {
|
||||||
|
-0.5f, -0.5f, 0.0f,
|
||||||
|
0.5f, -0.5f, 0.0f,
|
||||||
|
0.0f, 0.5f, 0.0f,
|
||||||
|
0.5f, 0.5f, 0.0f
|
||||||
|
};
|
||||||
|
|
||||||
|
// store data in the buffer
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, vertexPosData.size()*sizeof(GLfloat), vertexPosData.data(), GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
|
||||||
// unbind vertex array
|
// unbind vertex array
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
@@ -22,12 +33,6 @@ void GLMesh::init()
|
|||||||
void GLMesh::initBuffers()
|
void GLMesh::initBuffers()
|
||||||
{
|
{
|
||||||
|
|
||||||
vertexPosData = {
|
|
||||||
-0.5f, -0.5f, 0.0f,
|
|
||||||
0.5f, -0.5f, 0.0f,
|
|
||||||
0.0f, 0.5f, 0.0f,
|
|
||||||
0.5f, 0.5f, 0.0f
|
|
||||||
};
|
|
||||||
|
|
||||||
indexData =
|
indexData =
|
||||||
{
|
{
|
||||||
@@ -38,8 +43,6 @@ void GLMesh::initBuffers()
|
|||||||
glGenBuffers(1, &vertexBuffer);
|
glGenBuffers(1, &vertexBuffer);
|
||||||
// set purpose
|
// set purpose
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
|
||||||
// store data in the buffer
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, vertexPosData.size()*sizeof(GLfloat), vertexPosData.data(), GL_STATIC_DRAW);
|
|
||||||
|
|
||||||
// gives the shader a way to read buffer data
|
// gives the shader a way to read buffer data
|
||||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), (void*)0);
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3*sizeof(GLfloat), (void*)0);
|
||||||
@@ -52,6 +55,20 @@ void GLMesh::initBuffers()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLMesh::setPosBuffer(std::vector<enzo::bt::Vector3> data)
|
||||||
|
{
|
||||||
|
vertexPosData.clear();
|
||||||
|
for(auto vector : data)
|
||||||
|
{
|
||||||
|
vertexPosData.push_back(vector.x());
|
||||||
|
vertexPosData.push_back(vector.y());
|
||||||
|
vertexPosData.push_back(vector.z());
|
||||||
|
}
|
||||||
|
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, vertexPosData.size()*sizeof(GLfloat), vertexPosData.data(), GL_STATIC_DRAW);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GLMesh::bind()
|
void GLMesh::bind()
|
||||||
{
|
{
|
||||||
glBindVertexArray(vao);
|
glBindVertexArray(vao);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Engine/Types.h"
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <QOpenGLFunctions_3_2_Core>
|
#include <QOpenGLFunctions_3_2_Core>
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ public:
|
|||||||
|
|
||||||
void init();
|
void init();
|
||||||
void initBuffers();
|
void initBuffers();
|
||||||
|
void setPosBuffer(std::vector<enzo::bt::Vector3> data);
|
||||||
void bind();
|
void bind();
|
||||||
void unbind();
|
void unbind();
|
||||||
void draw();
|
void draw();
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#include "gui/viewport/ViewportGLWidget.h"
|
#include "gui/viewport/ViewportGLWidget.h"
|
||||||
|
#include "Engine/Operator/AttributeHandle.h"
|
||||||
|
#include "Engine/Types.h"
|
||||||
#include "gui/viewport/GLMesh.h"
|
#include "gui/viewport/GLMesh.h"
|
||||||
#include <glm/mat4x4.hpp>
|
#include <glm/mat4x4.hpp>
|
||||||
#include <glm/ext/matrix_clip_space.hpp>
|
#include <glm/ext/matrix_clip_space.hpp>
|
||||||
@@ -141,7 +143,25 @@ void ViewportGLWidget::paintGL()
|
|||||||
|
|
||||||
std::unique_ptr<GLMesh> ViewportGLWidget::meshFromGeo(std::unique_ptr<enzo::geo::Geometry>& geometry)
|
std::unique_ptr<GLMesh> ViewportGLWidget::meshFromGeo(std::unique_ptr<enzo::geo::Geometry>& geometry)
|
||||||
{
|
{
|
||||||
|
using namespace enzo;
|
||||||
|
|
||||||
auto mesh = std::make_unique<GLMesh>();
|
auto mesh = std::make_unique<GLMesh>();
|
||||||
|
|
||||||
|
std::shared_ptr<ga::Attribute> PAttr = geometry->getAttribByName(ga::AttrOwner::POINT, "P");
|
||||||
|
ga::AttributeHandleVector3 PAttrHandle = ga::AttributeHandleVector3(PAttr);
|
||||||
|
PAttrHandle.addValue(bt::Vector3(-0.5f, -0.5f, 0.0f));
|
||||||
|
PAttrHandle.addValue(bt::Vector3(0.5f, -0.5f, 0.0f));
|
||||||
|
PAttrHandle.addValue(bt::Vector3(0.0f, 0.5f, 0.0f));
|
||||||
|
PAttrHandle.addValue(bt::Vector3(0.5f, 0.5f, 0.0f));
|
||||||
|
|
||||||
|
mesh->setPosBuffer(PAttrHandle.getData());
|
||||||
|
// mesh->setPosBuffer(std::vector<bt::Vector3>{
|
||||||
|
// bt::Vector3(-0.5f, -0.5f, 0.0f),
|
||||||
|
// bt::Vector3(0.5f, -0.5f, 0.0f),
|
||||||
|
// bt::Vector3(0.0f, 0.5f, 0.0f),
|
||||||
|
// bt::Vector3(0.5f, 0.5f, 0.0f),
|
||||||
|
// });
|
||||||
|
|
||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user