Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EMSUSD-77 - Newly created USD Lights can't cast shadows #3233

Merged
merged 4 commits into from
Jul 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions lib/mayaUsd/ufe/UsdLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,14 @@ Ufe::Color3f UsdLight::color() const { return getLightColor(prim()); }

bool getLightShadowEnable(const UsdPrim& prim)
{
const UsdLuxShadowAPI shadowAPI(prim);
const PXR_NS::UsdAttribute lightAttribute = shadowAPI.GetShadowEnableAttr();
const UsdLuxShadowAPI shadowAPI(prim);
PXR_NS::UsdAttribute lightAttribute = shadowAPI.GetShadowEnableAttr();

if (!lightAttribute) {
// If the shadow enable attribute is not created yet, create one here
lightAttribute = shadowAPI.CreateShadowEnableAttr(VtValue(true));
return true;
}

bool val = false;
lightAttribute.Get(&val);
Expand All @@ -185,7 +191,9 @@ void setLightShadowEnable(const UsdPrim& prim, bool attrVal)
const UsdLuxShadowAPI shadowAPI(prim);
const PXR_NS::UsdAttribute lightAttribute = shadowAPI.GetShadowEnableAttr();

lightAttribute.Set(attrVal);
if (lightAttribute) {
lightAttribute.Set(attrVal);
}
}

Ufe::Light::ShadowEnableUndoableCommand::Ptr UsdLight::shadowEnableCmd(bool se)
Expand All @@ -202,8 +210,13 @@ bool UsdLight::shadowEnable() const { return getLightShadowEnable(prim()); }

Ufe::Color3f getLightShadowColor(const UsdPrim& prim)
{
const UsdLuxShadowAPI shadowAPI(prim);
const PXR_NS::UsdAttribute lightAttribute = shadowAPI.GetShadowColorAttr();
const UsdLuxShadowAPI shadowAPI(prim);
PXR_NS::UsdAttribute lightAttribute = shadowAPI.GetShadowColorAttr();

if (!lightAttribute) {
// If the shadow color attribute is not created yet, create one here
lightAttribute = shadowAPI.CreateShadowColorAttr();
}

GfVec3f val(0.f, 0.f, 0.f);
lightAttribute.Get(&val);
Expand Down
Loading