Skip to content

Commit 0e82051

Browse files
committed
Fix scene bugging when responding to Blender 'hide'
1 parent ba433a2 commit 0e82051

File tree

15 files changed

+73
-31
lines changed

15 files changed

+73
-31
lines changed

include/luxrays/core/namedobjectvector.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,27 @@ class NamedObjectVector {
109109
const std::string &GetName(NamedObjectConstRef o) const;
110110

111111
u_int GetSize()const;
112-
auto GetNames() const {
112+
113+
auto ViewNames() const {
113114
// Returns a view of references to the object names
114115
return objs | std::views::transform([](const auto& obj) -> const std::string & {
115116
return obj->GetName();
116117
});
117118
}
118-
//void GetNames(std::vector<std::string> &names) const;
119-
auto GetObjs() {
119+
auto GetNames() const {
120+
auto view = ViewNames();
121+
return std::vector<std::string>(view.begin(), view.end());
122+
}
123+
auto ViewObjs() {
120124
// Returns a view of references to the objects
121125
return objs | std::views::transform([](const auto& obj) -> NamedObjectRef {
122126
return *obj;
123127
});
124128
}
129+
auto GetObjs() {
130+
auto view = ViewObjs();
131+
return std::vector<std::reference_wrapper<NamedObject>>(view.begin(), view.end());
132+
}
125133

126134
void DeleteObj(const std::string &name);
127135
void DeleteObjs(const std::vector<std::string> &names);

include/luxrays/utils/observer_ptr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class observer_ptr {
9696
constexpr T* operator->() const noexcept { return ptr; }
9797

9898
// Conversion to bool (for boolean context)
99-
explicit constexpr operator bool() const noexcept { return ptr != nullptr; }
99+
explicit operator bool() const noexcept { return ptr != nullptr; }
100100

101101
// Get the raw pointer
102102
constexpr T* get() const noexcept { return ptr; }

include/slg/imagemap/imagemapcache.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ class ImageMapCache {
6060

6161
void GetImageMaps(std::vector<std::reference_wrapper<const ImageMap>> &ims) const;
6262

63-
auto GetImageMaps() const {
63+
auto ViewImageMaps() const {
6464
// Create and return a view of references to the values
6565
return maps | std::views::transform([](const auto& ptr) -> const ImageMap&
6666
{ return *ptr; });
6767
}
68+
auto GetImageMaps() const {
69+
auto view = ViewImageMaps();
70+
return std::vector<std::reference_wrapper<const ImageMap>>(view.begin(), view.end());
71+
}
6872

6973

7074
u_int GetSize()const { return static_cast<u_int>(mapByKey.size()); }

include/slg/lights/lightsourcedefs.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifndef _SLG_LIGHTSOURCEDEFINITIONS_H
2020
#define _SLG_LIGHTSOURCEDEFINITIONS_H
2121

22+
#include <functional>
2223
#include <robin_hood.h>
2324

2425
#include "luxrays/utils/properties.h"
@@ -76,27 +77,37 @@ class LightSourceDefinitions {
7677
return std::addressof(lights[n].get());
7778
}
7879

79-
auto GetEnvLightSources() {
80+
auto ViewEnvLightSources() {
8081
// Returns a view of references to the objects
8182
return envLightSources |
8283
std::views::transform([](const auto& obj) -> EnvLightSourceRef {
8384
return obj.get();
8485
});
8586
}
86-
auto GetEnvLightSources() const {
87+
auto ViewEnvLightSources() const {
8788
// Returns a view of references to the objects
8889
return envLightSources |
8990
std::views::transform([](const auto& obj) -> const EnvLightSourceRef {
9091
return obj.get();
9192
});
9293
}
93-
auto GetIntersectableLightSources() const {
94+
auto GetEnvLightSources() const {
95+
auto view = ViewEnvLightSources();
96+
return std::vector<std::reference_wrapper<EnvLightSource>>(view.begin(), view.end());
97+
}
98+
99+
auto ViewIntersectableLightSources() const {
94100
// Returns a view of references to the objects
95101
return intersectableLightSources |
96102
std::views::transform([](const auto& obj) -> const TriangleLightRef {
97103
return obj.get();
98104
});
99105
}
106+
auto GetIntersectableLightSources() const {
107+
auto view = ViewIntersectableLightSources();
108+
return std::vector<std::reference_wrapper<IntersectableLightSource>>(view.begin(), view.end());
109+
}
110+
100111
const std::vector<u_int> &GetLightIndexOffsetByMeshIndex() const {
101112
return lightIndexOffsetByMeshIndex;
102113
}

include/slg/materials/material.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class Material : public luxrays::NamedObject
9595
virtual BSDFEvent GetEventTypes() const = 0;
9696

9797
virtual bool IsLightSource() const {
98-
return bool(emittedTex);
98+
return static_cast<bool>(emittedTex);
9999
}
100100

101101
void SetPhotonGIEnabled(const bool v) { isPhotonGIEnabled = v; }

include/slg/volumes/volume.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "slg/textures/texture.h"
2626
#include "slg/usings.h"
2727
#include <functional>
28+
#include <typeinfo>
2829

2930
namespace slg {
3031

@@ -123,12 +124,18 @@ void updvol(T volume, const MaterialConstRef oldMat, MaterialRef newMat);
123124

124125
template<>
125126
inline void updvol(VolumeConstPtr volume, MaterialConstRef oldMat, MaterialRef newMat) {
126-
auto& oldVol = dynamic_cast<const Volume &>(oldMat);
127-
auto& newVol = dynamic_cast<Volume &>(newMat);
128127

129-
if (volume == &oldVol) {
130-
volume = &newVol;
128+
// Check
129+
try {
130+
auto& oldVol = dynamic_cast<const Volume &>(oldMat);
131+
if (volume != &oldVol) return; // Old material was not this volume
132+
} catch (std::bad_cast&) {
133+
return; // Old material was not a volume
131134
}
135+
136+
// Replace
137+
auto& newVol = dynamic_cast<Volume &>(newMat);
138+
volume = &newVol;
132139
}
133140

134141
template<>

src/slg/engines/bidircpu/bidircputhread.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "slg/engines/bidircpu/bidircpu.h"
2929
#include "slg/cameras/camera.h"
30+
#include "slg/lights/light.h"
3031

3132
using namespace std;
3233
using namespace luxrays;
@@ -577,7 +578,7 @@ void BiDirCPURenderThread::DirectHitLight(
577578
BiDirCPURenderEngine *engine = (BiDirCPURenderEngine *)renderEngine;
578579
auto& scene = engine->renderConfig.GetScene();
579580

580-
for(auto& el: scene.GetLightSources().GetEnvLightSources()) {
581+
for(EnvLightSource& el: scene.GetLightSources().GetEnvLightSources()) {
581582
const Spectrum lightRadiance = el.GetRadiance(scene,
582583
(eyeVertex.depth == 1) ? nullptr : &eyeVertex.bsdf,
583584
eyeVertex.bsdf.hitPoint.fixedDir, &directPdfA, &emissionPdfW);

src/slg/engines/pathtracer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919

2020
#include "luxrays/utils/properties.h"
21+
#include "slg/lights/light.h"
2122
#include "slg/usings.h"
2223
#include "slg/engines/pathtracer.h"
2324
#include "slg/engines/caches/photongi/photongicache.h"
@@ -323,7 +324,7 @@ void PathTracer::DirectHitInfiniteLight(SceneConstRef scene,
323324
if (bsdf && bsdf->hitPoint.throughShadowTransparency)
324325
return;
325326

326-
for(auto& envLight: scene.GetLightSources().GetEnvLightSources()) {
327+
for(EnvLightSource& envLight: scene.GetLightSources().GetEnvLightSources()) {
327328
// Check if the light source is visible according the settings
328329
if (!CheckDirectHitVisibilityFlags(envLight, pathInfo.depth, pathInfo.lastBSDFEvent))
329330
continue;

src/slg/lights/lightsourcedefs.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <boost/algorithm/string/predicate.hpp>
2222

23+
#include "slg/lights/light.h"
2324
#include "slg/scene/scene.h"
2425
#include "slg/lights/trianglelight.h"
2526
#include "slg/lights/strategies/logpower.h"
@@ -259,6 +260,8 @@ void LightSourceDefinitions::Preprocess(SceneConstRef scene, const bool useRTMod
259260
const u_int meshCount = scene.GetObjects().GetSize();
260261
for (u_int meshIndex = 0; meshIndex < meshCount; ++meshIndex) {
261262
auto& so = scene.GetObjects().GetSceneObject(meshIndex);
263+
auto& mat = so.GetMaterial();
264+
bool isLightSource = mat.IsLightSource();
262265

263266
if (so.GetMaterial().IsLightSource()) {
264267
lightIndexOffsetByMeshIndex[meshIndex] = lightIndexByTriIndex.size();
@@ -346,7 +349,7 @@ void LightSourceDefinitions::Preprocess(SceneConstRef scene, const bool useRTMod
346349

347350
void LightSourceDefinitions::UpdateVisibilityMaps(SceneConstRef scene, const bool useRTMode) {
348351
// Build visibility maps for Env. lights
349-
for (auto& envLight : GetEnvLightSources())
352+
for (EnvLightSource& envLight : GetEnvLightSources())
350353
envLight.UpdateVisibilityMap(scene, useRTMode);
351354
}
352355
// vim: autoindent noexpandtab tabstop=4 shiftwidth=4

src/slg/materials/materialdefs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ MaterialDefinitions::DefineMaterial(MaterialUPtr&& mat) {
4141
if (oldMatPtr) { // An object was replaced
4242
auto& oldMatRef = *oldMatPtr;
4343
// Update all references
44-
for(auto& o: mats.GetObjs()) {
44+
for(NamedObjectRef o: mats.ViewObjs()) {
4545
// Update all references in material/volume (note: volume is also a material)
4646
auto& m = dynamic_cast<MaterialRef>(o);
4747
m.UpdateMaterialReferences(oldMatRef, newMatRef);
@@ -53,7 +53,7 @@ MaterialDefinitions::DefineMaterial(MaterialUPtr&& mat) {
5353

5454
void MaterialDefinitions::UpdateTextureReferences(
5555
TextureConstRef oldTex, TextureRef newTex) {
56-
for(auto& mat: mats.GetObjs())
56+
for(NamedObjectRef mat: mats.GetObjs())
5757
dynamic_cast<MaterialRef>(mat).UpdateTextureReferences(oldTex, newTex);
5858
}
5959

0 commit comments

Comments
 (0)