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

@@ -59,6 +59,11 @@ public:
return *data_;
}
size_t getSize()
{
return data_->size();
}
T getValue(size_t pos) const
{
// TODO:protect against invalid positions

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);

View File

@@ -1,12 +1,13 @@
#pragma once
#include "Engine/Operator/Geometry.h"
#include "Engine/Types.h"
namespace enzo::nt
{
class GeometryOpDef
{
public:
GeometryOpDef();
GeometryOpDef(enzo::nt::OpId opId);
void cookOp();
geo::Geometry& getOutputGeo(unsigned outputIndex);
private:
@@ -15,10 +16,12 @@ private:
unsigned int maxInputs_;
unsigned int maxOutputs_;
protected:
enzo::nt::OpId opId_;
const enzo::geo::Geometry& getInputGeoView(unsigned int inputIndex);
enzo::geo::Geometry cloneInputGeo(unsigned int inputIndex);
bool outputRequested(unsigned int outputIndex);
// TODO: std::move geometry instead of copying
void setOutputGeometry(unsigned int outputIndex, enzo::geo::Geometry geometry);
};
}

View File

@@ -23,12 +23,13 @@ void enzo::nt::connectOperators(enzo::nt::OpId inputOpId, unsigned int inputInde
outputOp.addInputConnection(newConnection);
}
nt::GeometryOperator::GeometryOperator()
nt::GeometryOperator::GeometryOperator(enzo::nt::OpId opId)
: opId_{opId}
{
// TODO: drive by geometry definition
maxInputs_=4;
maxOutputs_=4;
opDef_ = new enzo::nt::GeometryOpDef();
opDef_ = new enzo::nt::GeometryOpDef(opId_);
}
void enzo::nt::GeometryOperator::cookOp()

View File

@@ -11,7 +11,7 @@ void connectOperators(enzo::nt::OpId inputOpId, unsigned int inputIndex, enzo::n
class GeometryOperator
{
public:
GeometryOperator();
GeometryOperator(enzo::nt::OpId opId);
// disable copying
GeometryOperator(const GeometryOperator&) = delete;
@@ -38,5 +38,6 @@ private:
unsigned int maxInputs_;
unsigned int maxOutputs_;
enzo::nt::GeometryOpDef* opDef_;
enzo::nt::OpId opId_;
};
}