feat: multiple face rendering and geometry storing
This commit is contained in:
@@ -49,21 +49,31 @@ void enzo::nt::NetworkManager::setDisplayOp(OpId opId)
|
||||
std::vector<enzo::nt::OpId> dependencyGraph = getDependencyGraph(opId);
|
||||
enzo::geo::Geometry prevGeometry;
|
||||
|
||||
// ----
|
||||
// create geometry start
|
||||
// ----
|
||||
std::shared_ptr<ga::Attribute> PAttr = prevGeometry.getAttribByName(ga::AttrOwner::POINT, "P");
|
||||
ga::AttributeHandleVector3 PAttrHandle = ga::AttributeHandleVector3(PAttr);
|
||||
PAttrHandle.addValue(bt::Vector3(1.0f, -1.0f, 0.0f));
|
||||
PAttrHandle.addValue(bt::Vector3(-1.0f, -1.0f, 0.0f));
|
||||
PAttrHandle.addValue(bt::Vector3(-1.0f, 1.0f, 0.0f));
|
||||
PAttrHandle.addValue(bt::Vector3(0.0f, 2.0f, 0.0f));
|
||||
PAttrHandle.addValue(bt::Vector3(1.0f, 1.0f, 0.0f));
|
||||
ga::AttributeHandleVector3 PAttrHandle(PAttr);
|
||||
std::vector<bt::Vector3> pts={
|
||||
{-1,-1,-1},{1,-1,-1},{1,-1,1},{-1,-1,1},
|
||||
{-1,1,-1},{1,1,-1},{1,1,1},{-1,1,1},
|
||||
{0,2,-1},{0,2,1}
|
||||
};
|
||||
for(auto& p:pts) PAttrHandle.addValue(p);
|
||||
|
||||
std::shared_ptr<ga::Attribute> pointAttr = prevGeometry.getAttribByName(ga::AttrOwner::VERTEX, "point");
|
||||
ga::AttributeHandleInt pointAttrHandle = ga::AttributeHandleInt(pointAttr);
|
||||
pointAttrHandle.addValue(0);
|
||||
pointAttrHandle.addValue(1);
|
||||
pointAttrHandle.addValue(2);
|
||||
pointAttrHandle.addValue(3);
|
||||
pointAttrHandle.addValue(4);
|
||||
ga::AttributeHandleInt pointAttrHandle(pointAttr);
|
||||
std::vector<std::vector<int>> faces={
|
||||
{3,2,6,9,7},{0,1,5,8,4},{0,3,7,4},{1,2,6,5},
|
||||
{0,1,2,3},{4,7,9},{4,9,8},{5,6,9},{5,9,8}
|
||||
};
|
||||
for(auto& f:faces) for(int i:f) pointAttrHandle.addValue(i);
|
||||
|
||||
std::shared_ptr<ga::Attribute> vertexCountAttr = prevGeometry.getAttribByName(ga::AttrOwner::PRIMITIVE, "vertexCount");
|
||||
ga::AttributeHandleInt vertexCountHandle(vertexCountAttr);
|
||||
for(auto& f:faces) vertexCountHandle.addValue(f.size());
|
||||
|
||||
// --------
|
||||
|
||||
for(enzo::nt::OpId opId : dependencyGraph)
|
||||
{
|
||||
@@ -76,7 +86,9 @@ enzo::geo::Geometry enzo::nt::NetworkManager::cookOp(enzo::nt::OpId opId, enzo::
|
||||
{
|
||||
std::shared_ptr<ga::Attribute> PAttr = inputGeometry.getAttribByName(ga::AttrOwner::POINT, "P");
|
||||
ga::AttributeHandleVector3 PAttrHandle = ga::AttributeHandleVector3(PAttr);
|
||||
for(int i=0; i<5; ++i)
|
||||
|
||||
|
||||
for(int i=0; i<PAttrHandle.getAllValues().size(); ++i)
|
||||
{
|
||||
enzo::bt::Vector3 vector = PAttrHandle.getValue(i);
|
||||
vector.y()+=1;
|
||||
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
data_->push_back(value);
|
||||
}
|
||||
|
||||
std::vector<T> getData() const
|
||||
std::vector<T> getAllValues() const
|
||||
{
|
||||
return *data_;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ geo::Geometry::Geometry()
|
||||
{
|
||||
addVector3Attribute(ga::AttrOwner::POINT, "P");
|
||||
addIntAttribute(ga::AttrOwner::VERTEX, "point");
|
||||
addIntAttribute(ga::AttrOwner::PRIMITIVE, "vertexCount");
|
||||
}
|
||||
|
||||
ga::AttributeHandle<int> geo::Geometry::addIntAttribute(ga::AttributeOwner owner, std::string name)
|
||||
|
||||
@@ -61,18 +61,33 @@ void GLMesh::setPosBuffer(std::vector<enzo::bt::Vector3> data)
|
||||
unbind();
|
||||
}
|
||||
|
||||
void GLMesh::setIndexBuffer(std::vector<int> data)
|
||||
void GLMesh::setIndexBuffer(std::vector<int> pointIndices, std::vector<int> primVertexCounts)
|
||||
{
|
||||
bind();
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
|
||||
indexData.clear();
|
||||
std::cout << "index data\n-------\n";
|
||||
for(int i=1;i+1<data.size();++i)
|
||||
std::cout << "index pointIndices\n-------\n";
|
||||
size_t startIndex = 1;
|
||||
|
||||
// create triangle fan from potentially ngon inputs
|
||||
std::cout << "size: " << primVertexCounts.size() << "\n";
|
||||
for(size_t primNum=0; primNum<primVertexCounts.size(); ++primNum)
|
||||
{
|
||||
indexData.push_back(data.at(0));
|
||||
indexData.push_back(data.at(i));
|
||||
indexData.push_back(data.at(i+1));
|
||||
std::cout << data.at(0) << " " << data.at(i) << " " << data.at(i+1) << "\n";
|
||||
int primVertexCount = primVertexCounts[primNum];
|
||||
|
||||
std::cout << "startIndex: " << startIndex << "\n";
|
||||
std::cout << "prim vertex count: " << primVertexCount << "\n";
|
||||
|
||||
for(size_t pointIndex=startIndex; pointIndex+2<startIndex+primVertexCount; ++pointIndex)
|
||||
{
|
||||
indexData.push_back(pointIndices.at(startIndex-1));
|
||||
indexData.push_back(pointIndices.at(pointIndex));
|
||||
indexData.push_back(pointIndices.at(pointIndex+1));
|
||||
|
||||
std::cout << pointIndices.at(0) << " " << pointIndices.at(pointIndex) << " " << pointIndices.at(pointIndex+1) << "\n";
|
||||
}
|
||||
|
||||
startIndex += primVertexCount;
|
||||
}
|
||||
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexData.size()*sizeof(GLint), indexData.data(), GL_STATIC_DRAW);
|
||||
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
void init();
|
||||
void initBuffers();
|
||||
void setPosBuffer(std::vector<enzo::bt::Vector3> data);
|
||||
void setIndexBuffer(std::vector<int> data);
|
||||
void setIndexBuffer(std::vector<int> pointIndices, std::vector<int> primVertexCounts);
|
||||
void bind();
|
||||
void unbind();
|
||||
void draw();
|
||||
|
||||
@@ -156,7 +156,8 @@ std::unique_ptr<GLMesh> ViewportGLWidget::meshFromGeo(enzo::geo::Geometry& geome
|
||||
PAttrHandle.addValue(bt::Vector3(0.0f, 2.0f, 0.0f));
|
||||
PAttrHandle.addValue(bt::Vector3(1.0f, 1.0f, 0.0f));
|
||||
|
||||
mesh->setPosBuffer(PAttrHandle.getData());
|
||||
|
||||
mesh->setPosBuffer(PAttrHandle.getAllValues());
|
||||
|
||||
std::shared_ptr<ga::Attribute> pointAttr = geometry.getAttribByName(ga::AttrOwner::VERTEX, "point");
|
||||
ga::AttributeHandleInt pointAttrHandle = ga::AttributeHandleInt(pointAttr);
|
||||
@@ -165,7 +166,13 @@ std::unique_ptr<GLMesh> ViewportGLWidget::meshFromGeo(enzo::geo::Geometry& geome
|
||||
pointAttrHandle.addValue(2);
|
||||
pointAttrHandle.addValue(3);
|
||||
pointAttrHandle.addValue(4);
|
||||
mesh->setIndexBuffer(pointAttrHandle.getData());
|
||||
|
||||
std::shared_ptr<ga::Attribute> vertexCountAttr = geometry.getAttribByName(ga::AttrOwner::PRIMITIVE, "vertexCount");
|
||||
ga::AttributeHandleInt vertexCountHandle = ga::AttributeHandleInt(vertexCountAttr);
|
||||
vertexCountHandle.addValue(5);
|
||||
|
||||
mesh->setIndexBuffer(pointAttrHandle.getAllValues(), vertexCountHandle.getAllValues());
|
||||
|
||||
|
||||
|
||||
return mesh;
|
||||
@@ -177,10 +184,13 @@ void ViewportGLWidget::geometryChanged(enzo::geo::Geometry& geometry)
|
||||
std::shared_ptr<ga::Attribute> PAttr = geometry.getAttribByName(ga::AttrOwner::POINT, "P");
|
||||
ga::AttributeHandleVector3 PAttrHandle = ga::AttributeHandleVector3(PAttr);
|
||||
|
||||
triangleMesh_->setPosBuffer(PAttrHandle.getData());
|
||||
triangleMesh_->setPosBuffer(PAttrHandle.getAllValues());
|
||||
|
||||
std::shared_ptr<ga::Attribute> pointAttr = geometry.getAttribByName(ga::AttrOwner::VERTEX, "point");
|
||||
ga::AttributeHandleInt pointAttrHandle = ga::AttributeHandleInt(pointAttr);
|
||||
|
||||
triangleMesh_->setIndexBuffer(pointAttrHandle.getData());
|
||||
std::shared_ptr<ga::Attribute> vertexCountAttr = geometry.getAttribByName(ga::AttrOwner::PRIMITIVE, "vertexCount");
|
||||
ga::AttributeHandleInt vertexCountHandle = ga::AttributeHandleInt(vertexCountAttr);
|
||||
|
||||
triangleMesh_->setIndexBuffer(pointAttrHandle.getAllValues(), vertexCountHandle.getAllValues());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user