Skip to content

Commit

Permalink
Merge pull request #3896 from Autodesk/samuelliu-adsk/EMSUSD-172/more…
Browse files Browse the repository at this point in the history
…_light_support

EMSUSD-172 - Add more light shapes supports in the viewport
  • Loading branch information
seando-adsk authored Sep 12, 2024
2 parents bcf8289 + 25cac6d commit cdf562b
Show file tree
Hide file tree
Showing 7 changed files with 339 additions and 33 deletions.
7 changes: 7 additions & 0 deletions cmake/modules/FindUFE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ set(UFE_LIGHTS_SUPPORT FALSE CACHE INTERNAL "ufeLights")
if (UFE_INCLUDE_DIR AND EXISTS "${UFE_INCLUDE_DIR}/ufe/lightHandler.h")
set(UFE_LIGHTS_SUPPORT TRUE CACHE INTERNAL "ufeLights")
message(STATUS "Maya has UFE lights API")

set(UFE_VOLUME_LIGHTS_SUPPORT FALSE CACHE INTERNAL "ufeVolumeLights")
file(STRINGS ${UFE_INCLUDE_DIR}/ufe/light.h UFE_HAS_API REGEX "VolumeProps")
if(UFE_HAS_API)
set(UFE_VOLUME_LIGHTS_SUPPORT TRUE CACHE INTERNAL "ufeVolumeLights")
message(STATUS "Maya has UFE VolumeLights API")
endif()
endif()

set(UFE_MATERIALS_SUPPORT FALSE CACHE INTERNAL "ufeMaterials")
Expand Down
6 changes: 6 additions & 0 deletions lib/mayaUsd/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ if (UFE_LIGHTS_SUPPORT)
PRIVATE
UFE_LIGHTS_SUPPORT=1
)
if (UFE_VOLUME_LIGHTS_SUPPORT)
target_compile_definitions(${PROJECT_NAME}
PRIVATE
UFE_VOLUME_LIGHTS_SUPPORT=1
)
endif()
endif()

if (UFE_MATERIALS_SUPPORT)
Expand Down
146 changes: 143 additions & 3 deletions lib/mayaUsd/ufe/UsdLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@

#include <usdUfe/ufe/UsdUndoableCommand.h>

#include <pxr/usd/usdLux/cylinderLight.h>
#include <pxr/usd/usdLux/diskLight.h>
#include <pxr/usd/usdLux/distantLight.h>
#include <pxr/usd/usdLux/domeLight.h>
#include <pxr/usd/usdLux/lightAPI.h>
#include <pxr/usd/usdLux/portalLight.h>
#include <pxr/usd/usdLux/rectLight.h>
#include <pxr/usd/usdLux/shadowAPI.h>
#include <pxr/usd/usdLux/shapingAPI.h>
Expand Down Expand Up @@ -70,7 +74,7 @@ class SetValueUndoableCommandImpl
MAYAUSD_VERIFY_CLASS_SETUP(Ufe::Light, UsdLight);

UsdLight::UsdLight(const UsdUfe::UsdSceneItem::Ptr& item)
: Light()
: UFE_LIGHT_BASE()
, _item(item)
{
}
Expand All @@ -94,14 +98,32 @@ Ufe::Light::Type UsdLight::type() const

if (usdPrim.IsA<UsdLuxDistantLight>()) {
return Ufe::Light::Directional;
} else if (usdPrim.IsA<UsdLuxRectLight>()) {
} else if (
usdPrim.IsA<UsdLuxRectLight>()
#ifdef UFE_VOLUME_LIGHTS_SUPPORT
|| usdPrim.IsA<UsdLuxPortalLight>()) {
#else
) {
#endif
return Ufe::Light::Area;
} else if (usdPrim.IsA<UsdLuxSphereLight>()) {
const UsdLuxShapingAPI shapingAPI(usdPrim);
return shapingAPI.GetShapingConeAngleAttr().IsValid() ? Ufe::Light::Spot
#ifdef UFE_VOLUME_LIGHTS_SUPPORT
: Ufe::Light::Sphere;
#else
: Ufe::Light::Point;
#endif

#ifdef UFE_VOLUME_LIGHTS_SUPPORT
} else if (usdPrim.IsA<UsdLuxCylinderLight>()) {
return Ufe::Light::Cylinder;
} else if (usdPrim.IsA<UsdLuxDiskLight>()) {
return Ufe::Light::Disk;
} else if (usdPrim.IsA<UsdLuxDomeLight>()) {
return Ufe::Light::Dome;
#endif
}

// In case of unknown light type, fallback to point light
return Ufe::Light::Point;
}
Expand Down Expand Up @@ -365,6 +387,9 @@ UsdSphereInterface::spherePropsCmd(float radius, bool asPoint)

void UsdSphereInterface::sphereProps(float radius, bool asPoint)
{
if (asPoint) {
radius = 0.0f;
}
setLightSphereProps(_item->prim(), Ufe::Light::SphereProps { radius, asPoint });
}

Expand Down Expand Up @@ -446,6 +471,104 @@ Ufe::Light::NormalizeUndoableCommand::Ptr UsdAreaInterface::normalizeCmd(bool nl
return pCmd;
}

#ifdef UFE_VOLUME_LIGHTS_SUPPORT

UFE_LIGHT_BASE::VolumeProps getLightCylinderVolumeProps(const UsdPrim& prim)
{
const UsdLuxCylinderLight lightSchema(prim);
const PXR_NS::UsdAttribute radiusAttribute = lightSchema.GetRadiusAttr();
const PXR_NS::UsdAttribute lengthAttribute = lightSchema.GetLengthAttr();

UFE_LIGHT_BASE::VolumeProps vp;
radiusAttribute.Get(&vp.radius);
lengthAttribute.Get(&vp.length);
return vp;
}

UFE_LIGHT_BASE::VolumeProps getLightDiskVolumeProps(const UsdPrim& prim)
{
const UsdLuxDiskLight lightSchema(prim);
const PXR_NS::UsdAttribute radiusAttribute = lightSchema.GetRadiusAttr();

UFE_LIGHT_BASE::VolumeProps vp;
radiusAttribute.Get(&vp.radius);
return vp;
}

UFE_LIGHT_BASE::VolumeProps getLightDomeVolumeProps(const UsdPrim& prim)
{
UFE_LIGHT_BASE::VolumeProps vp;
return vp;
}

void setLightVolumeProps(const UsdPrim& prim, const UFE_LIGHT_BASE::VolumeProps& attrVal)
{
const UsdLuxSphereLight lightSchema(prim);
const PXR_NS::UsdAttribute lightAttribute = lightSchema.GetRadiusAttr();

lightAttribute.Set(attrVal.radius);
}

void UsdCylinderInterface::volumeProps(float radius, float length)
{
setLightVolumeProps(_item->prim(), UFE_LIGHT_BASE::VolumeProps { radius, length });
}
void UsdDiskInterface::volumeProps(float radius)
{
setLightVolumeProps(_item->prim(), UFE_LIGHT_BASE::VolumeProps { radius });
}

void UsdDomeInterface::volumeProps(float radius)
{
setLightVolumeProps(_item->prim(), UFE_LIGHT_BASE::VolumeProps { radius });
}

// Cylinder Light
UFE_LIGHT_BASE::VolumeProps UsdCylinderInterface::volumeProps() const
{
return getLightCylinderVolumeProps(_item->prim());
}

UFE_LIGHT_BASE::VolumePropsUndoableCommand::Ptr
UsdCylinderInterface::volumePropsCmd(float radius, float length)
{
auto pCmd = std::make_shared<SetValueUndoableCommandImpl<const UFE_LIGHT_BASE::VolumeProps&>>(
_item->path(), setLightVolumeProps);
pCmd->set(UFE_LIGHT_BASE::VolumeProps { radius, length });
return pCmd;
}

// Disk Light
UFE_LIGHT_BASE::VolumeProps UsdDiskInterface::volumeProps() const
{
return getLightDiskVolumeProps(_item->prim());
}

UFE_LIGHT_BASE::VolumePropsUndoableCommand::Ptr UsdDiskInterface::volumePropsCmd(float radius)
{
auto pCmd = std::make_shared<SetValueUndoableCommandImpl<const UFE_LIGHT_BASE::VolumeProps&>>(
_item->path(), setLightVolumeProps);

pCmd->set(UFE_LIGHT_BASE::VolumeProps { radius, 0 });
return pCmd;
}

// Dome light
UFE_LIGHT_BASE::VolumeProps UsdDomeInterface::volumeProps() const
{
return getLightDomeVolumeProps(_item->prim());
}

UFE_LIGHT_BASE::VolumePropsUndoableCommand::Ptr UsdDomeInterface::volumePropsCmd(float radius)
{
auto pCmd = std::make_shared<SetValueUndoableCommandImpl<const UFE_LIGHT_BASE::VolumeProps&>>(
_item->path(), setLightVolumeProps);

pCmd->set(UFE_LIGHT_BASE::VolumeProps { radius, 0 });
return pCmd;
}
#endif

void UsdAreaInterface::normalize(bool ln) { setLightNormalize(_item->prim(), ln); }

bool UsdAreaInterface::normalize() const { return getLightNormalize(_item->prim()); }
Expand All @@ -470,5 +593,22 @@ std::shared_ptr<Ufe::Light::AreaInterface> UsdLight::areaInterfaceImpl()
return std::make_shared<UsdAreaInterface>(_item);
}

#ifdef UFE_VOLUME_LIGHTS_SUPPORT
std::shared_ptr<UFE_LIGHT_BASE::CylinderInterface> UsdLight::cylinderInterfaceImpl()
{
return std::make_shared<UsdCylinderInterface>(_item);
}

std::shared_ptr<UFE_LIGHT_BASE::DiskInterface> UsdLight::diskInterfaceImpl()
{
return std::make_shared<UsdDiskInterface>(_item);
}

std::shared_ptr<UFE_LIGHT_BASE::DomeInterface> UsdLight::domeInterfaceImpl()
{
return std::make_shared<UsdDomeInterface>(_item);
}
#endif

} // namespace ufe
} // namespace MAYAUSD_NS_DEF
64 changes: 63 additions & 1 deletion lib/mayaUsd/ufe/UsdLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@
#include <ufe/light.h>
#include <ufe/path.h>

#if defined(UFE_VOLUME_LIGHTS_SUPPORT) && (UFE_MAJOR_VERSION == 5)
#define UFE_LIGHT_BASE Ufe::Light_v5_5
#else
#define UFE_LIGHT_BASE Ufe::Light
#endif

namespace MAYAUSD_NS_DEF {
namespace ufe {

//! \brief Interface to control lights through USD.
class MAYAUSD_CORE_PUBLIC UsdLight : public Ufe::Light
class MAYAUSD_CORE_PUBLIC UsdLight : public UFE_LIGHT_BASE
{
public:
typedef std::shared_ptr<UsdLight> Ptr;
Expand Down Expand Up @@ -86,6 +92,11 @@ class MAYAUSD_CORE_PUBLIC UsdLight : public Ufe::Light
std::shared_ptr<SphereInterface> sphereInterfaceImpl() override;
std::shared_ptr<ConeInterface> coneInterfaceImpl() override;
std::shared_ptr<AreaInterface> areaInterfaceImpl() override;
#ifdef UFE_VOLUME_LIGHTS_SUPPORT
std::shared_ptr<CylinderInterface> cylinderInterfaceImpl() override;
std::shared_ptr<DiskInterface> diskInterfaceImpl() override;
std::shared_ptr<DomeInterface> domeInterfaceImpl() override;
#endif

private:
UsdUfe::UsdSceneItem::Ptr _item;
Expand Down Expand Up @@ -156,6 +167,57 @@ class UsdAreaInterface : public Ufe::Light::AreaInterface
UsdUfe::UsdSceneItem::Ptr _item;
};

#ifdef UFE_VOLUME_LIGHTS_SUPPORT
class UsdCylinderInterface : public UFE_LIGHT_BASE::CylinderInterface
{
public:
UsdCylinderInterface(const UsdUfe::UsdSceneItem::Ptr& item)
: _item(item)
{
}

UFE_LIGHT_BASE::VolumePropsUndoableCommand::Ptr
volumePropsCmd(float radius, float length) override;
void volumeProps(float radius, float length) override;
UFE_LIGHT_BASE::VolumeProps volumeProps() const override;

private:
UsdUfe::UsdSceneItem::Ptr _item;
};

class UsdDiskInterface : public UFE_LIGHT_BASE::DiskInterface
{
public:
UsdDiskInterface(const UsdUfe::UsdSceneItem::Ptr& item)
: _item(item)
{
}

UFE_LIGHT_BASE::VolumePropsUndoableCommand::Ptr volumePropsCmd(float radius) override;
void volumeProps(float radius) override;
UFE_LIGHT_BASE::VolumeProps volumeProps() const override;

private:
UsdUfe::UsdSceneItem::Ptr _item;
};

class UsdDomeInterface : public UFE_LIGHT_BASE::DomeInterface
{
public:
UsdDomeInterface(const UsdUfe::UsdSceneItem::Ptr& item)
: _item(item)
{
}

UFE_LIGHT_BASE::VolumePropsUndoableCommand::Ptr volumePropsCmd(float radius) override;
void volumeProps(float radius) override;
UFE_LIGHT_BASE::VolumeProps volumeProps() const override;

private:
UsdUfe::UsdSceneItem::Ptr _item;
};
#endif

} // namespace ufe
} // namespace MAYAUSD_NS_DEF

Expand Down
1 change: 1 addition & 0 deletions test/lib/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ foreach(script ${TEST_SCRIPT_FILES})
"UFE_MATERIAL_HAS_HASMATERIAL=${UFE_MATERIAL_HAS_HASMATERIAL}"
"UFE_CAMERA_HAS_RENDERABLE=${UFE_CAMERA_HAS_RENDERABLE}"
"UFE_SCENE_SEGMENT_HANDLER_ROOT_PATH=${UFE_SCENE_SEGMENT_HANDLER_ROOT_PATH}"
"UFE_VOLUME_LIGHTS_SUPPORT=${UFE_VOLUME_LIGHTS_SUPPORT}"
)

# Add a ctest label to these tests for easy filtering.
Expand Down
Loading

0 comments on commit cdf562b

Please sign in to comment.