Skip to content

Commit

Permalink
add vertex attributes for cone, curve, and cylinder geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffamstutz committed Jan 20, 2023
1 parent 3cd34f1 commit fa7d337
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 4 deletions.
24 changes: 24 additions & 0 deletions libs/helide/scene/surface/geometry/Cone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ void Cone::commit()
m_index = getParamObject<Array1D>("primitive.index");
m_vertexPosition = getParamObject<Array1D>("vertex.position");
m_vertexRadius = getParamObject<Array1D>("vertex.radius");
m_vertexAttributes[0] = getParamObject<Array1D>("vertex.attribute0");
m_vertexAttributes[1] = getParamObject<Array1D>("vertex.attribute1");
m_vertexAttributes[2] = getParamObject<Array1D>("vertex.attribute2");
m_vertexAttributes[3] = getParamObject<Array1D>("vertex.attribute3");
m_vertexAttributes[4] = getParamObject<Array1D>("vertex.color");

if (!m_vertexPosition) {
reportMessage(ANARI_SEVERITY_WARNING,
Expand Down Expand Up @@ -82,6 +87,25 @@ void Cone::commit()
rtcCommitGeometry(embreeGeometry());
}

float4 Cone::getAttributeValueAt(
const Attribute &attr, const Ray &ray) const
{
if (attr == Attribute::NONE)
return DEFAULT_ATTRIBUTE_VALUE;

auto attrIdx = static_cast<int>(attr);
auto *attributeArray = m_vertexAttributes[attrIdx].ptr;
if (!attributeArray)
return Geometry::getAttributeValueAt(attr, ray);

auto idx = m_index ? *(m_index->dataAs<uint32_t>() + ray.primID) : ray.primID;

auto a = readAttributeArrayAt(attributeArray, idx + 0);
auto b = readAttributeArrayAt(attributeArray, idx + 1);

return a + (b - a) * ray.u;
}

void Cone::cleanup()
{
if (m_index)
Expand Down
4 changes: 4 additions & 0 deletions libs/helide/scene/surface/geometry/Cone.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ struct Cone : public Geometry

void commit() override;

float4 getAttributeValueAt(
const Attribute &attr, const Ray &ray) const override;

private:
void cleanup();

helium::IntrusivePtr<Array1D> m_index;
helium::IntrusivePtr<Array1D> m_vertexPosition;
helium::IntrusivePtr<Array1D> m_vertexRadius;
std::array<helium::IntrusivePtr<Array1D>, 5> m_vertexAttributes;
float m_globalRadius{0.f};
};

Expand Down
24 changes: 24 additions & 0 deletions libs/helide/scene/surface/geometry/Curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ void Curve::commit()
m_index = getParamObject<Array1D>("primitive.index");
m_vertexPosition = getParamObject<Array1D>("vertex.position");
m_vertexRadius = getParamObject<Array1D>("vertex.radius");
m_vertexAttributes[0] = getParamObject<Array1D>("vertex.attribute0");
m_vertexAttributes[1] = getParamObject<Array1D>("vertex.attribute1");
m_vertexAttributes[2] = getParamObject<Array1D>("vertex.attribute2");
m_vertexAttributes[3] = getParamObject<Array1D>("vertex.attribute3");
m_vertexAttributes[4] = getParamObject<Array1D>("vertex.color");

if (!m_vertexPosition) {
reportMessage(ANARI_SEVERITY_WARNING,
Expand Down Expand Up @@ -78,6 +83,25 @@ void Curve::commit()
rtcCommitGeometry(embreeGeometry());
}

float4 Curve::getAttributeValueAt(
const Attribute &attr, const Ray &ray) const
{
if (attr == Attribute::NONE)
return DEFAULT_ATTRIBUTE_VALUE;

auto attrIdx = static_cast<int>(attr);
auto *attributeArray = m_vertexAttributes[attrIdx].ptr;
if (!attributeArray)
return Geometry::getAttributeValueAt(attr, ray);

auto idx = m_index ? *(m_index->dataAs<uint32_t>() + ray.primID) : ray.primID;

auto a = readAttributeArrayAt(attributeArray, idx + 0);
auto b = readAttributeArrayAt(attributeArray, idx + 1);

return a + (b - a) * ray.u;
}

void Curve::cleanup()
{
if (m_index)
Expand Down
6 changes: 4 additions & 2 deletions libs/helide/scene/surface/geometry/Curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#pragma once

#include "Geometry.h"
// anari
#include "anari/backend/utilities/Optional.h"

namespace helide {

Expand All @@ -15,12 +13,16 @@ struct Curve : public Geometry

void commit() override;

float4 getAttributeValueAt(
const Attribute &attr, const Ray &ray) const override;

private:
void cleanup();

helium::IntrusivePtr<Array1D> m_index;
helium::IntrusivePtr<Array1D> m_vertexPosition;
helium::IntrusivePtr<Array1D> m_vertexRadius;
std::array<helium::IntrusivePtr<Array1D>, 5> m_vertexAttributes;
float m_globalRadius{0.f};
};

Expand Down
24 changes: 24 additions & 0 deletions libs/helide/scene/surface/geometry/Cylinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ void Cylinder::commit()
m_index = getParamObject<Array1D>("primitive.index");
m_radius = getParamObject<Array1D>("primitive.radius");
m_vertexPosition = getParamObject<Array1D>("vertex.position");
m_vertexAttributes[0] = getParamObject<Array1D>("vertex.attribute0");
m_vertexAttributes[1] = getParamObject<Array1D>("vertex.attribute1");
m_vertexAttributes[2] = getParamObject<Array1D>("vertex.attribute2");
m_vertexAttributes[3] = getParamObject<Array1D>("vertex.attribute3");
m_vertexAttributes[4] = getParamObject<Array1D>("vertex.color");

if (!m_vertexPosition) {
reportMessage(ANARI_SEVERITY_WARNING,
Expand Down Expand Up @@ -83,6 +88,25 @@ void Cylinder::commit()
rtcCommitGeometry(embreeGeometry());
}

float4 Cylinder::getAttributeValueAt(
const Attribute &attr, const Ray &ray) const
{
if (attr == Attribute::NONE)
return DEFAULT_ATTRIBUTE_VALUE;

auto attrIdx = static_cast<int>(attr);
auto *attributeArray = m_vertexAttributes[attrIdx].ptr;
if (!attributeArray)
return Geometry::getAttributeValueAt(attr, ray);

auto idx = m_index ? *(m_index->dataAs<uint32_t>() + ray.primID) : ray.primID;

auto a = readAttributeArrayAt(attributeArray, idx + 0);
auto b = readAttributeArrayAt(attributeArray, idx + 1);

return a + (b - a) * ray.u;
}

void Cylinder::cleanup()
{
if (m_index)
Expand Down
6 changes: 4 additions & 2 deletions libs/helide/scene/surface/geometry/Cylinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#pragma once

#include "Geometry.h"
// anari
#include "anari/backend/utilities/Optional.h"

namespace helide {

Expand All @@ -15,12 +13,16 @@ struct Cylinder : public Geometry

void commit() override;

float4 getAttributeValueAt(
const Attribute &attr, const Ray &ray) const override;

private:
void cleanup();

helium::IntrusivePtr<Array1D> m_index;
helium::IntrusivePtr<Array1D> m_radius;
helium::IntrusivePtr<Array1D> m_vertexPosition;
std::array<helium::IntrusivePtr<Array1D>, 5> m_vertexAttributes;
float m_globalRadius{0.f};
};

Expand Down

0 comments on commit fa7d337

Please sign in to comment.