Skip to content

Commit cd125c9

Browse files
USD Viewer: check if the stage has dome light
1 parent 7690523 commit cd125c9

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

Samples/USDViewer/src/USDViewer.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,16 @@ static float4x4 GetUpAxisTransform(const pxr::TfToken UpAxis)
255255
}
256256
}
257257

258+
static bool HasDomeLight(pxr::UsdStage& Stage)
259+
{
260+
for (const auto& Prim : Stage.Traverse())
261+
{
262+
if (Prim.IsA<pxr::UsdLuxDomeLight>())
263+
return true;
264+
}
265+
return false;
266+
}
267+
258268
void USDViewer::LoadStage()
259269
{
260270
{
@@ -348,6 +358,7 @@ void USDViewer::LoadStage()
348358
AddDirectionalLight("_HnDirectionalLight3_", 5000.f, pxr::GfRotation{pxr::GfVec3d{1, 0.0, 0.5}, -40}, 1024);
349359

350360
// Environment map
361+
if (!HasDomeLight(*m_Stage.Stage))
351362
{
352363
m_Stage.DomeLightId = SceneDelegateId.AppendChild(pxr::TfToken{"_HnDomeLight_"});
353364
pxr::UsdLuxDomeLight DomeLight = pxr::UsdLuxDomeLight::Define(m_Stage.Stage, m_Stage.DomeLightId);
@@ -657,14 +668,17 @@ void USDViewer::UpdateUI()
657668
}
658669
}
659670

660-
if (ImGui::Button("Load Environment Map"))
671+
if (!m_Stage.DomeLightId.IsEmpty())
661672
{
662-
FileDialogAttribs OpenDialogAttribs{FILE_DIALOG_TYPE_OPEN};
663-
OpenDialogAttribs.Title = "Select HDR file";
664-
OpenDialogAttribs.Filter = "HDR files (*.hdr)\0*.hdr;\0All files\0*.*\0\0";
665-
auto FileName = FileSystem::FileDialog(OpenDialogAttribs);
666-
if (!FileName.empty())
667-
LoadEnvironmentMap(FileName.data());
673+
if (ImGui::Button("Load Environment Map"))
674+
{
675+
FileDialogAttribs OpenDialogAttribs{FILE_DIALOG_TYPE_OPEN};
676+
OpenDialogAttribs.Title = "Select HDR file";
677+
OpenDialogAttribs.Filter = "HDR files (*.hdr)\0*.hdr;\0All files\0*.*\0\0";
678+
auto FileName = FileSystem::FileDialog(OpenDialogAttribs);
679+
if (!FileName.empty())
680+
LoadEnvironmentMap(FileName.data());
681+
}
668682
}
669683

670684
if (ImGui::Button("Open directory"))

0 commit comments

Comments
 (0)