feat: render open and closed faces/lines

This commit is contained in:
parker
2025-08-04 13:47:08 +01:00
parent 3130d91f39
commit 065e5f73ac
11 changed files with 117 additions and 66 deletions

View File

@@ -14,16 +14,19 @@ ga::Attribute::Attribute(std::string name, ga::AttributeType type)
switch(type_)
{
case(AttrType::intT):
intStore_=std::make_shared<std::vector<int>>();
intStore_=std::make_shared<std::vector<bt::intT>>();
break;
case(AttrType::floatT):
floatStore_=std::make_shared<std::vector<float>>();
floatStore_=std::make_shared<std::vector<bt::floatT>>();
break;
case(AttrType::vectorT):
vector3Store_=std::make_shared<std::vector<enzo::bt::Vector3>>();
break;
case(AttrType::boolT):
boolStore_=std::make_shared<std::vector<enzo::bt::boolT>>();
break;
default:
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for");
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for in Attribute constructor");
}
@@ -40,16 +43,19 @@ ga::Attribute::Attribute(const Attribute& other)
switch(type_)
{
case(AttrType::intT):
intStore_=std::make_shared<std::vector<int>>(*other.intStore_);
intStore_=std::make_shared<std::vector<bt::intT>>(*other.intStore_);
break;
case(AttrType::floatT):
floatStore_=std::make_shared<std::vector<float>>(*other.floatStore_);
floatStore_=std::make_shared<std::vector<bt::floatT>>(*other.floatStore_);
break;
case(AttrType::vectorT):
vector3Store_=std::make_shared<std::vector<enzo::bt::Vector3>>(*other.vector3Store_);
break;
case(AttrType::boolT):
boolStore_=std::make_shared<std::vector<enzo::bt::boolT>>(*other.boolStore_);
break;
default:
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for");
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for in Attribute copy constructor");
}
}

View File

@@ -46,9 +46,10 @@ namespace enzo{
// void* data_;
// data stores
std::shared_ptr<StoreContainer<int>> intStore_;
std::shared_ptr<StoreContainer<float>> floatStore_;
std::shared_ptr<StoreContainer<bt::intT>> intStore_;
std::shared_ptr<StoreContainer<bt::floatT>> floatStore_;
std::shared_ptr<StoreContainer<enzo::bt::Vector3>> vector3Store_;
std::shared_ptr<StoreContainer<enzo::bt::boolT>> boolStore_;
};

View File

@@ -27,13 +27,13 @@ public:
// TODO: add the other types
// int
if constexpr (std::is_same<int, T>::value)
if constexpr (std::is_same<bt::intT, T>::value)
{
data_=attribute->intStore_;
}
// float
else if constexpr (std::is_same<float, T>::value)
else if constexpr (std::is_same<bt::floatT, T>::value)
{
data_=attribute->floatStore_;
}
@@ -43,9 +43,13 @@ public:
{
data_=attribute->vector3Store_;
}
else if constexpr (std::is_same<enzo::bt::boolT, T>::value)
{
data_=attribute->boolStore_;
}
else
{
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for");
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for in AttributeHandle constructor");
}
}
@@ -109,8 +113,9 @@ private:
};
using AttributeHandleInt = AttributeHandle<int>;
using AttributeHandleFloat = AttributeHandle<float>;
using AttributeHandleInt = AttributeHandle<bt::intT>;
using AttributeHandleFloat = AttributeHandle<bt::floatT>;
using AttributeHandleVector3 = AttributeHandle<enzo::bt::Vector3>;
using AttributeHandleBool = AttributeHandle<enzo::bt::boolT>;
}

View File

@@ -12,6 +12,7 @@
using namespace enzo;
geo::Geometry::Geometry() :
vertexCountHandlePrim_{addIntAttribute(ga::AttrOwner::PRIMITIVE, "vertexCount")},
closedHandlePrim_{addBoolAttribute(ga::AttrOwner::PRIMITIVE, "closed")},
pointOffsetHandleVert_{addIntAttribute(ga::AttrOwner::VERTEX, "point")},
posHandlePoint_{addVector3Attribute(ga::AttrOwner::POINT, "P")}
{
@@ -19,27 +20,39 @@ geo::Geometry::Geometry() :
}
geo::Geometry::Geometry(const Geometry& other):
// attributes
pointAttributes_{deepCopyAttributes(other.pointAttributes_)},
vertexAttributes_{deepCopyAttributes(other.vertexAttributes_)},
primitiveAttributes_{deepCopyAttributes(other.primitiveAttributes_)},
globalAttributes_{deepCopyAttributes(other.globalAttributes_)},
// handles
vertexCountHandlePrim_{enzo::ga::AttributeHandleInt(getAttribByName(ga::AttrOwner::PRIMITIVE, "vertexCount"))},
closedHandlePrim_{enzo::ga::AttributeHandleBool(getAttribByName(ga::AttrOwner::PRIMITIVE, "closed"))},
pointOffsetHandleVert_{enzo::ga::AttributeHandleInt(getAttribByName(ga::AttrOwner::VERTEX, "point"))},
posHandlePoint_{enzo::ga::AttributeHandleVector3(getAttribByName(ga::AttrOwner::POINT, "P"))}
{
}
void geo::Geometry::addFace(std::initializer_list<ga::Offset> pointOffsets)
void geo::Geometry::addFace(std::vector<ga::Offset> pointOffsets, bool closed)
{
for(ga::Offset pointOffset : pointOffsets)
{
pointOffsetHandleVert_.addValue(pointOffset);
}
vertexCountHandlePrim_.addValue(pointOffsets.size());
closedHandlePrim_.addValue(closed);
}
void geo::Geometry::addPoint(const bt::Vector3& pos)
{
posHandlePoint_.addValue(pos);
}
bt::Vector3 geo::Geometry::getPosFromVert(ga::Offset vertexOffset) const
{
// get point offset
@@ -53,6 +66,12 @@ bt::Vector3 geo::Geometry::getPointPos(ga::Offset pointOffset) const
return posHandlePoint_.getValue(pointOffset);
}
void geo::Geometry::setPointPos(const ga::Offset offset, const bt::Vector3& pos)
{
posHandlePoint_.setValue(offset, pos);
}
unsigned int geo::Geometry::getPrimVertCount(ga::Offset primOffset) const
{
return vertexCountHandlePrim_.getValue(primOffset);
@@ -68,6 +87,11 @@ ga::Offset geo::Geometry::getNumVerts() const
return pointOffsetHandleVert_.getSize();
}
ga::Offset geo::Geometry::getNumPoints() const
{
return posHandlePoint_.getSize();
}
@@ -191,13 +215,26 @@ void geo::Geometry::computePrimStartVertices()
ga::AttributeHandle<int> geo::Geometry::addIntAttribute(ga::AttributeOwner owner, std::string name)
ga::AttributeHandleInt geo::Geometry::addIntAttribute(ga::AttributeOwner owner, std::string name)
{
auto newAttribute = std::make_shared<ga::Attribute>(name, ga::AttrType::intT);
getAttributeStore(owner).push_back(newAttribute);
return ga::AttributeHandle<int>(newAttribute);
return ga::AttributeHandleInt(newAttribute);
}
ga::AttributeHandleBool geo::Geometry::addBoolAttribute(ga::AttributeOwner owner, std::string name)
{
auto newAttribute = std::make_shared<ga::Attribute>(name, ga::AttrType::boolT);
getAttributeStore(owner).push_back(newAttribute);
return ga::AttributeHandleBool(newAttribute);
}
bt::boolT geo::Geometry::isClosed(ga::Offset primOffset) const
{
return closedHandlePrim_.getValue(primOffset);
}
ga::AttributeHandle<bt::Vector3> geo::Geometry::addVector3Attribute(ga::AttributeOwner owner, std::string name)
{
auto newAttribute = std::make_shared<ga::Attribute>(name, ga::AttrType::vectorT);

View File

@@ -24,21 +24,28 @@ class Geometry
public:
Geometry();
Geometry(const Geometry& other);
ga::AttributeHandle<int> addIntAttribute(ga::AttributeOwner owner, std::string name);
ga::AttributeHandle<bt::intT> addIntAttribute(ga::AttributeOwner owner, std::string name);
ga::AttributeHandleBool addBoolAttribute(ga::AttributeOwner owner, std::string name);
ga::AttributeHandle<bt::Vector3> addVector3Attribute(ga::AttributeOwner owner, std::string name);
// TODO: return weak ptr
std::shared_ptr<ga::Attribute> getAttribByName(ga::AttributeOwner owner, std::string name);
std::vector<bt::Vector3> derivePointNormals();
HeMesh computeHalfEdgeMesh();
// returns the first vertex of the primitive
void addFace(std::initializer_list<ga::Offset> pointOffsets);
void addFace(std::vector<ga::Offset> pointOffsets, bool closed=true);
void addPoint(const bt::Vector3& pos);
ga::Offset getPrimStartVertex(ga::Offset primOffset) const;
void setPointPos(const ga::Offset offset, const bt::Vector3& pos);
ga::Offset getPrimStartVertex(ga::Offset primOffset) const; // returns the first vertex of the primitive
bt::Vector3 getPosFromVert(ga::Offset vertexOffset) const;
bt::Vector3 getPointPos(ga::Offset pointOffset) const;
unsigned int getPrimVertCount(ga::Offset primOffset) const;
ga::Offset getNumPrims() const;
ga::Offset getNumVerts() const;
ga::Offset getNumPoints() const;
bt::boolT isClosed(ga::Offset primOffset) const;
void computePrimStartVertices();
private:
using attribVector = std::vector<std::shared_ptr<ga::Attribute>>;
@@ -55,6 +62,7 @@ private:
// handles
enzo::ga::AttributeHandleInt vertexCountHandlePrim_;
enzo::ga::AttributeHandleBool closedHandlePrim_;
enzo::ga::AttributeHandleInt pointOffsetHandleVert_;
enzo::ga::AttributeHandleVector3 posHandlePoint_;
};