refactor: cleanup setPosBuffer funciton, add getters for geometry

This commit is contained in:
parker
2025-08-03 03:22:52 +01:00
parent 48ad8909cc
commit 488ff9ff72
6 changed files with 139 additions and 65 deletions

View File

@@ -10,22 +10,67 @@
#include "icecream.hpp"
using namespace enzo;
geo::Geometry::Geometry()
geo::Geometry::Geometry() :
vertexCountHandlePrim_{addIntAttribute(ga::AttrOwner::PRIMITIVE, "vertexCount")},
pointOffsetHandleVert_{addIntAttribute(ga::AttrOwner::VERTEX, "point")},
posHandlePoint_{addVector3Attribute(ga::AttrOwner::POINT, "P")}
{
addVector3Attribute(ga::AttrOwner::POINT, "P");
addIntAttribute(ga::AttrOwner::VERTEX, "point");
addIntAttribute(ga::AttrOwner::PRIMITIVE, "vertexCount");
}
geo::Geometry::Geometry(const Geometry& other)
geo::Geometry::Geometry(const Geometry& other):
pointAttributes_{deepCopyAttributes(other.pointAttributes_)},
vertexAttributes_{deepCopyAttributes(other.vertexAttributes_)},
primitiveAttributes_{deepCopyAttributes(other.primitiveAttributes_)},
globalAttributes_{deepCopyAttributes(other.globalAttributes_)},
vertexCountHandlePrim_{enzo::ga::AttributeHandleInt(getAttribByName(ga::AttrOwner::PRIMITIVE, "vertexCount"))},
pointOffsetHandleVert_{enzo::ga::AttributeHandleInt(getAttribByName(ga::AttrOwner::VERTEX, "point"))},
posHandlePoint_{enzo::ga::AttributeHandleVector3(getAttribByName(ga::AttrOwner::POINT, "P"))}
{
pointAttributes_ = deepCopyAttributes(other.pointAttributes_);
vertexAttributes_ = deepCopyAttributes(other.vertexAttributes_);
primitiveAttributes_ = deepCopyAttributes(other.primitiveAttributes_);
globalAttributes_ = deepCopyAttributes(other.globalAttributes_);
}
void geo::Geometry::addFace(std::initializer_list<ga::Offset> pointOffsets)
{
for(ga::Offset pointOffset : pointOffsets)
{
pointOffsetHandleVert_.addValue(pointOffset);
}
vertexCountHandlePrim_.addValue(pointOffsets.size());
}
bt::Vector3 geo::Geometry::getPosFromVert(ga::Offset vertexOffset) const
{
// get point offset
const ga::Offset pointOffset = pointOffsetHandleVert_.getValue(vertexOffset);
// get value at point offset
return posHandlePoint_.getValue(pointOffset);
}
bt::Vector3 geo::Geometry::getPointPos(ga::Offset pointOffset) const
{
return posHandlePoint_.getValue(pointOffset);
}
unsigned int geo::Geometry::getPrimVertCount(ga::Offset primOffset) const
{
return vertexCountHandlePrim_.getValue(primOffset);
}
ga::Offset geo::Geometry::getNumPrims() const
{
return vertexCountHandlePrim_.getSize();
}
ga::Offset geo::Geometry::getNumVerts() const
{
return pointOffsetHandleVert_.getSize();
}
geo::Geometry::attribVector geo::Geometry::deepCopyAttributes(attribVector originalVector)
{
geo::Geometry::attribVector copied;
@@ -125,6 +170,25 @@ enzo::geo::HeMesh geo::Geometry::computeHalfEdgeMesh()
return heMesh;
}
unsigned int geo::Geometry::getPrimStartVertex(ga::Offset primOffset)
{
const ga::Offset handleSize = vertexCountHandlePrim_.getSize();
// TODO: add smarter system to recompute primStarts_, also move to separate function
// if size changed, recompute
if(handleSize!=primStarts_.size())
{
bt::intT primStart = 0;
for(size_t i=0; i<handleSize; ++i)
{
primStarts_.push_back(primStart);
primStart += vertexCountHandlePrim_.getValue(i);
}
}
return primStarts_[primOffset];
}
ga::AttributeHandle<int> geo::Geometry::addIntAttribute(ga::AttributeOwner owner, std::string name)
{