Skip to content

Commit 8ba1860

Browse files
committed
support visible parameter on volume and surface objects
1 parent 6bec2eb commit 8ba1860

File tree

5 files changed

+38
-15
lines changed

5 files changed

+38
-15
lines changed

src/devices/helide/surface/Surface.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ void Surface::commitParameters()
1313
m_id = getParam<uint32_t>("id", ~0u);
1414
m_geometry = getParamObject<Geometry>("geometry");
1515
m_material = getParamObject<Material>("material");
16+
m_visible = getParam<bool>("visible", true);
1617
}
1718

1819
void Surface::finalize()
@@ -43,6 +44,11 @@ bool Surface::isValid() const
4344
}
4445
}
4546

47+
bool Surface::isVisible() const
48+
{
49+
return m_visible;
50+
}
51+
4652
const Geometry *Surface::geometry() const
4753
{
4854
return m_geometry.ptr;

src/devices/helide/surface/Surface.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct Surface : public Object
1919
void finalize() override;
2020
void markFinalized() override;
2121
bool isValid() const override;
22+
bool isVisible() const;
2223

2324
uint32_t id() const;
2425
const Geometry *geometry() const;
@@ -33,6 +34,7 @@ struct Surface : public Object
3334

3435
private:
3536
uint32_t m_id{~0u};
37+
bool m_visible{true};
3638
helium::IntrusivePtr<Geometry> m_geometry;
3739
helium::IntrusivePtr<Material> m_material;
3840
};

src/devices/helide/volume/Volume.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ Volume *Volume::createInstance(std::string_view subtype, HelideGlobalState *s)
2020
void Volume::commitParameters()
2121
{
2222
m_id = getParam<uint32_t>("id", ~0u);
23+
m_visible = getParam<bool>("visible", true);
24+
}
25+
26+
bool Volume::isVisible() const
27+
{
28+
return m_visible;
2329
}
2430

2531
} // namespace helide

src/devices/helide/volume/Volume.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct Volume : public Object
1414
static Volume *createInstance(std::string_view subtype, HelideGlobalState *d);
1515

1616
void commitParameters() override;
17+
bool isVisible() const;
1718

1819
uint32_t id() const;
1920

@@ -26,6 +27,7 @@ struct Volume : public Object
2627

2728
private:
2829
uint32_t m_id{~0u};
30+
bool m_visible{true};
2931
};
3032

3133
// Inlined definitions ////////////////////////////////////////////////////////

src/devices/helide/world/Group.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ Group::~Group()
1616
cleanup();
1717
}
1818

19-
bool Group::getProperty(
20-
const std::string_view &name, ANARIDataType type, void *ptr, uint64_t size, uint32_t flags)
19+
bool Group::getProperty(const std::string_view &name,
20+
ANARIDataType type,
21+
void *ptr,
22+
uint64_t size,
23+
uint32_t flags)
2124
{
2225
if (name == "bounds" && type == ANARI_FLOAT32_BOX3) {
2326
if (flags & ANARI_WAIT) {
@@ -26,7 +29,7 @@ bool Group::getProperty(
2629
}
2730
auto bounds = getEmbreeSceneBounds(m_embreeScene);
2831
for (auto *v : volumes()) {
29-
if (v->isValid())
32+
if (v && v->isValid() && v->isVisible())
3033
bounds.extend(v->bounds());
3134
}
3235
std::memcpy(ptr, &bounds, sizeof(bounds));
@@ -76,7 +79,7 @@ void Group::intersectVolumes(VolumeRay &ray, const mat4 &invMat) const
7679
box1 t = ray.t;
7780

7881
for (auto *v : volumes()) {
79-
if (!v->isValid())
82+
if (!v || !v->isValid() || !v->isVisible())
8083
continue;
8184
const float3 org = xfmPoint(invMat, ray.org);
8285
const float3 dir = xfmVec(invMat, ray.dir);
@@ -118,29 +121,33 @@ void Group::embreeSceneConstruct()
118121
rtcReleaseScene(m_embreeScene);
119122
m_embreeScene = rtcNewScene(deviceState()->embreeDevice);
120123

124+
m_surfaces.clear();
125+
121126
if (m_surfaceData) {
122127
uint32_t id = 0;
123128
std::for_each(m_surfaceData->handlesBegin(),
124129
m_surfaceData->handlesEnd(),
125130
[&](auto *o) {
126131
auto *s = (Surface *)o;
127-
if (s && s->isValid()) {
132+
if (s && s->isValid() && s->isVisible()) {
128133
m_surfaces.push_back(s);
129134
rtcAttachGeometryByID(
130135
m_embreeScene, s->geometry()->embreeGeometry(), id++);
131-
} else {
136+
} else if (!s || !s->isValid()) {
132137
reportMessage(ANARI_SEVERITY_DEBUG,
133138
"helide::Group rejecting invalid surface(%p) in building BLS",
134139
s);
135-
auto *g = s->geometry();
136-
if (!g || !g->isValid()) {
137-
reportMessage(
138-
ANARI_SEVERITY_DEBUG, " helide::Geometry is invalid");
139-
}
140-
auto *m = s->material();
141-
if (!m || !m->isValid()) {
142-
reportMessage(
143-
ANARI_SEVERITY_DEBUG, " helide::Material is invalid");
140+
if (s) {
141+
auto *g = s->geometry();
142+
if (!g || !g->isValid()) {
143+
reportMessage(
144+
ANARI_SEVERITY_DEBUG, " helide::Geometry is invalid");
145+
}
146+
auto *m = s->material();
147+
if (!m || !m->isValid()) {
148+
reportMessage(
149+
ANARI_SEVERITY_DEBUG, " helide::Material is invalid");
150+
}
144151
}
145152
}
146153
});

0 commit comments

Comments
 (0)