Fix: USD Export: Calculate extents properly for lights #113910

Closed
Charles Wardlaw wants to merge 1 commits from CharlesWardlaw/blender:bugfix/light_bounds into blender-v4.0-release

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
1 changed files with 14 additions and 0 deletions

View File

@ -26,6 +26,18 @@ bool USDLightWriter::is_supported(const HierarchyContext * /*context*/) const
return true;
}
static void set_light_extents(const pxr::UsdPrim &prim, const pxr::UsdTimeCode time)
{
if (auto boundable = pxr::UsdGeomBoundable(prim)) {
pxr::VtArray<pxr::GfVec3f> extent;
pxr::UsdGeomBoundable::ComputeExtentFromPlugins(boundable, time, &extent);
boundable.CreateExtentAttr().Set(extent, time);
}
/* We're intentionally not erroring on non-boundable lights,
* because the error spam can be annoying. */
}
void USDLightWriter::do_write(HierarchyContext &context)
{
pxr::UsdStageRefPtr stage = usd_export_context_.stage;
@ -115,6 +127,8 @@ void USDLightWriter::do_write(HierarchyContext &context)
usd_light_api.CreateDiffuseAttr().Set(light->diff_fac, timecode);
usd_light_api.CreateSpecularAttr().Set(light->spec_fac, timecode);
usd_light_api.CreateNormalizeAttr().Set(true, timecode);
set_light_extents(usd_light_api.GetPrim(), timecode);
}
} // namespace blender::io::usd