feat: basic geometry pass between operators

This commit is contained in:
parker
2025-07-08 19:13:15 +01:00
parent 0520d35b2c
commit 6f2a1ce532
7 changed files with 54 additions and 29 deletions

View File

@@ -1,6 +1,8 @@
#include "Engine/Operator/GeometryOpDef.h"
#include <stdexcept>
#include <iostream>
#include "Engine/Network/NetworkManager.h"
#include "Engine/Operator/GeometryOperator.h"
#include "Engine/Types.h"
#include "Engine/Operator/AttributeHandle.h"
@@ -20,7 +22,16 @@ const enzo::geo::Geometry& enzo::nt::GeometryOpDef::getInputGeoView(unsigned int
enzo::geo::Geometry enzo::nt::GeometryOpDef::cloneInputGeo(unsigned int inputIndex)
{
// TODO: implement
return enzo::geo::Geometry();
enzo::nt::NetworkManager* nm = nt::NetworkManager::getInstance();
enzo::nt::GeometryOperator& selfOp = nm->getGeoOperator(opId_);
std::vector<std::shared_ptr<const nt::GeometryConnection>> inputConnections = selfOp.getInputConnections();
if(inputConnections.size()==0)
{
std::cout << "no input\n";
return enzo::geo::Geometry();
}
std::shared_ptr<const nt::GeometryConnection> inputConnection = inputConnections.at(inputIndex);
return nm->getGeoOperator(inputConnection->getInputOpId()).getOutputGeo(inputConnection->getInputIndex());
}
void enzo::nt::GeometryOpDef::setOutputGeometry(unsigned int outputIndex, enzo::geo::Geometry geometry)
@@ -32,7 +43,8 @@ void enzo::nt::GeometryOpDef::setOutputGeometry(unsigned int outputIndex, enzo::
outputGeometry_[outputIndex] = geometry;
}
enzo::nt::GeometryOpDef::GeometryOpDef()
enzo::nt::GeometryOpDef::GeometryOpDef(enzo::nt::OpId opId)
: opId_{opId}
{
minInputs_=1;
maxInputs_=4;
@@ -63,29 +75,37 @@ void enzo::nt::GeometryOpDef::cookOp()
// ----
// create geometry start
// ----
std::shared_ptr<ga::Attribute> PAttr = geo.getAttribByName(ga::AttrOwner::POINT, "P");
auto PAttr = geo.getAttribByName(ga::AttrOwner::POINT, "P");
ga::AttributeHandleVector3 PAttrHandle(PAttr);
std::vector<bt::Vector3> pts={
int startPt = PAttrHandle.getSize();
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);
for (auto& p : pts) PAttrHandle.addValue(p);
std::shared_ptr<ga::Attribute> pointAttr = geo.getAttribByName(ga::AttrOwner::VERTEX, "point");
auto pointAttr = geo.getAttribByName(ga::AttrOwner::VERTEX, "point");
ga::AttributeHandleInt pointAttrHandle(pointAttr);
std::vector<std::vector<int>> faces={
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);
for (auto& f : faces) for (int i : f) pointAttrHandle.addValue(startPt + i);
std::shared_ptr<ga::Attribute> vertexCountAttr = geo.getAttribByName(ga::AttrOwner::PRIMITIVE, "vertexCount");
auto vertexCountAttr = geo.getAttribByName(ga::AttrOwner::PRIMITIVE, "vertexCount");
ga::AttributeHandleInt vertexCountHandle(vertexCountAttr);
for(auto& f:faces) vertexCountHandle.addValue(f.size());
for (auto& f : faces) vertexCountHandle.addValue(f.size());
// --------
for(int i=0; i<PAttrHandle.getAllValues().size(); ++i)
{
enzo::bt::Vector3 vector = PAttrHandle.getValue(i);
vector.x()+=2.5;
PAttrHandle.setValue(i, vector);
}
// set output geometry
setOutputGeometry(0, geo);