Skip to content

Commit 63cdca6

Browse files
author
devsh
committed
if it works, its not stupid
1 parent ae6d573 commit 63cdca6

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

22.RaytracedAO/main.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class RaytracerExampleEventReceiver : public nbl::IEventReceiver
6060
case ReloadKey:
6161
reloadKeyPressed = true;
6262
break;
63+
case OverloadCameraKey:
64+
overloadCameraKeyPressed = true;
65+
break;
6366
case QuitKey:
6467
running = false;
6568
return true;
@@ -89,6 +92,8 @@ class RaytracerExampleEventReceiver : public nbl::IEventReceiver
8992

9093
inline bool isReloadKeyPressed() const { return reloadKeyPressed; }
9194

95+
inline bool isOverloadCameraKeyPressed() const { return overloadCameraKeyPressed; }
96+
9297
inline void resetKeys()
9398
{
9499
skipKeyPressed = false;
@@ -98,6 +103,7 @@ class RaytracerExampleEventReceiver : public nbl::IEventReceiver
98103
screenshotKeyPressed = false;
99104
logProgressKeyPressed = false;
100105
reloadKeyPressed = false;
106+
overloadCameraKeyPressed = false;
101107
}
102108

103109
private:
@@ -110,6 +116,7 @@ class RaytracerExampleEventReceiver : public nbl::IEventReceiver
110116
static constexpr nbl::EKEY_CODE LogProgressKey = nbl::KEY_KEY_L;
111117
static constexpr nbl::EKEY_CODE BeautyKey = nbl::KEY_KEY_B;
112118
static constexpr nbl::EKEY_CODE ReloadKey = nbl::KEY_F5;
119+
static constexpr nbl::EKEY_CODE OverloadCameraKey = nbl::KEY_KEY_C;
113120

114121
bool running;
115122
bool renderingBeauty;
@@ -121,6 +128,7 @@ class RaytracerExampleEventReceiver : public nbl::IEventReceiver
121128
bool screenshotKeyPressed;
122129
bool logProgressKeyPressed;
123130
bool reloadKeyPressed;
131+
bool overloadCameraKeyPressed;
124132
};
125133

126134
struct PersistentState
@@ -1243,12 +1251,39 @@ int main(int argc, char** argv)
12431251
sensors[activeSensor].resetInteractiveCamera();
12441252
std::cout << "Interactive Camera Position and Target has been Reset." << std::endl;
12451253
}
1246-
if(receiver.isNextPressed())
1254+
else if(receiver.isOverloadCameraKeyPressed())
1255+
{
1256+
pfd::open_file file("Choose XML file to overload camera with (only first sensor overrides)", "../../media/mitsuba", { "XML files (.xml)", "*.xml" });
1257+
if (!file.result().empty())
1258+
{
1259+
const auto filePath = file.result()[0];
1260+
using namespace nbl::asset;
1261+
smart_refctd_ptr<const ext::MitsubaLoader::CMitsubaMetadata> mitsubaMetadata;
1262+
{
1263+
static const IAssetLoader::SAssetLoadParams mitsubaLoaderParams = { 0, nullptr, IAssetLoader::ECF_DONT_CACHE_REFERENCES, nullptr, IAssetLoader::ELPF_LOAD_METADATA_ONLY };
1264+
auto meshes_bundle = device->getAssetManager()->getAsset(filePath.data(),mitsubaLoaderParams);
1265+
if (!meshes_bundle.getContents().empty())
1266+
mitsubaMetadata = smart_refctd_ptr<const ext::MitsubaLoader::CMitsubaMetadata>(static_cast<const ext::MitsubaLoader::CMitsubaMetadata*>(meshes_bundle.getMetadata()));
1267+
}
1268+
if (!mitsubaMetadata || mitsubaMetadata->m_global.m_sensors.empty())
1269+
os::Printer::log("ERROR (" + std::to_string(__LINE__) + " line): The xml file is invalid/cannot be loaded! File path: " + filePath, ELL_ERROR);
1270+
else
1271+
{
1272+
const uint32_t originalSensorCount = sensors.size();
1273+
uint32_t idx = originalSensorCount;
1274+
for (const auto& sensor : mitsubaMetadata->m_global.m_sensors)
1275+
extractAndAddToSensorData(sensor,idx++);
1276+
setActiveSensor(originalSensorCount);
1277+
}
1278+
writeLastRunState = true;
1279+
}
1280+
}
1281+
else if(receiver.isNextPressed())
12471282
{
12481283
setActiveSensor(activeSensor + 1);
12491284
writeLastRunState = true;
12501285
}
1251-
if(receiver.isPreviousPressed())
1286+
else if(receiver.isPreviousPressed())
12521287
{
12531288
setActiveSensor(activeSensor - 1);
12541289
writeLastRunState = true;

0 commit comments

Comments
 (0)