feat(engine): add geometry class

This commit is contained in:
parker
2025-06-29 20:49:30 +01:00
parent deb237e481
commit 7db66aedeb
9 changed files with 118 additions and 69 deletions

View File

@@ -20,7 +20,7 @@ ga::Attribute::Attribute(std::string name, ga::AttributeType type)
floatStore_=std::make_shared<std::vector<float>>();
break;
default:
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not accounted for");
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for");
}
@@ -31,4 +31,8 @@ ga::AttributeType ga::Attribute::getType()
return type_;
}
std::string ga::Attribute::getName()
{
return name_;
}

View File

@@ -1,6 +1,7 @@
#pragma once
#include <string>
#include <optional>
#include <string_view>
#include <vector>
#include "Engine/Types.h"
#include <memory>
@@ -17,6 +18,7 @@ namespace enzo{
public:
Attribute(std::string name, ga::AttributeType type);
AttributeType getType();
std::string getName();

View File

@@ -1,4 +1,5 @@
#pragma once
#include <memory>
#include <stdexcept>
#include <string>
#include <optional>
@@ -16,40 +17,24 @@ class AttributeHandle
public:
ga::AttributeType type_;
AttributeHandle(Attribute& attribute)
AttributeHandle(std::shared_ptr<Attribute> attribute)
{
type_ = attribute.getType();
type_ = attribute->getType();
// get attribute data pointer
// TODO: check types match
// TODO: add the other types
if constexpr (std::is_same<int, T>::value)
{
data_=attribute.intStore_;
data_=attribute->intStore_;
}
else if constexpr (std::is_same<float, T>::value)
{
data_=attribute.floatStore_;
data_=attribute->floatStore_;
}
else
{
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not accounted for");
throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not properly accounted for");
}
// switch(type_)
// {
// case(AttrType::intT):
// {
// data_=attribute.intStore_;
// break;
// }
// case(AttrType::floatT):
// {
// data_=attribute.floatStore_;
// break;
// }
// default:
// throw std::runtime_error("Type " + std::to_string(static_cast<int>(type_)) + " was not accounted for");
// }
}
void addValue(T value)

View File

@@ -0,0 +1,55 @@
#include "Engine/Operator/Geometry.h"
#include "Engine/Operator/Attribute.h"
#include "Engine/Operator/AttributeHandle.h"
#include "Engine/Types.h"
#include <memory>
#include <stdexcept>
using namespace enzo;
geo::Geometry::Geometry()
{
}
ga::AttributeHandle<int> geo::Geometry::addIntAttribute(ga::AttributeOwner owner, std::string name)
{
auto newAttribute = std::make_shared<ga::Attribute>(name, ga::AttrType::intT);
getOwnerVector(owner).push_back(newAttribute);
return ga::AttributeHandle<int>(newAttribute);
}
std::vector<std::shared_ptr<ga::Attribute>>& geo::Geometry::getOwnerVector(ga::AttributeOwner& owner)
{
switch(owner)
{
case ga::AttributeOwner::POINT:
return pointAttributes_;
break;
case ga::AttributeOwner::VERTEX:
return vertexAttributes_;
break;
case ga::AttributeOwner::PRIMITIVE:
return primitiveAttributes_;
break;
case ga::AttributeOwner::GLOBAL:
return globalAttributes_;
break;
default:
throw std::runtime_error("Unexpected, owner could not be found");
}
}
std::shared_ptr<ga::Attribute> geo::Geometry::getAttribByName(ga::AttributeOwner owner, std::string name)
{
auto& vector = getOwnerVector(owner);
for(auto it=vector.begin(); it!=vector.end(); ++it)
{
if((*it)->getName()==name)
{
return (*it);
}
}
return nullptr;
}

View File

@@ -0,0 +1,22 @@
#pragma once
#include "Engine/Operator/Attribute.h"
#include "Engine/Types.h"
#include <variant>
namespace enzo::geo
{
class Geometry
{
public:
Geometry();
ga::AttributeHandle<int> addIntAttribute(ga::AttributeOwner owner, std::string name);
std::shared_ptr<ga::Attribute> getAttribByName(ga::AttributeOwner owner, std::string name);
private:
using attribVector = std::vector<std::shared_ptr<ga::Attribute>>;
attribVector& getOwnerVector(ga::AttributeOwner& owner);
attribVector pointAttributes_;
attribVector vertexAttributes_;
attribVector primitiveAttributes_;
attribVector globalAttributes_;
};
}

View File

@@ -1,24 +0,0 @@
#include "Engine/Operator/Primitive.h"
#include "Engine/Operator/Attribute.h"
#include "Engine/Types.h"
enzo::Primitive::Primitive()
{
}
bool enzo::Primitive::addIntAttrib(AttributeOwner owner, AttributeInt attribute)
{
bool status = true;
switch(owner)
{
case enzo::AttributeOwner::POINT:
pointAttribs_.push_back(attribute);
break;
}
pointAttribs_.push_back(attribute);
return status;
}

View File

@@ -1,20 +0,0 @@
#pragma once
#include "Engine/Operator/Attribute.h"
#include "Engine/Types.h"
#include <variant>
namespace enzo
{
class Primitive
{
public:
Primitive();
bool addIntAttrib(AttributeOwner owner, AttributeInt attribute);
AttributeInt findAttribByName(AttributeOwner owner, std::string name);
private:
std::vector<std::variant<
AttributeInt,
AttributeFloat
>> pointAttribs_;
};
}