Skip to content

Commit

Permalink
Merge pull request #1701 from dj-mcg/pr/Update_UsdLuxLight_to_use_Usd…
Browse files Browse the repository at this point in the history
…LuxLightAPI_schema_class

Use the API schema class UsdLuxLightAPI in place of USD typed class
  • Loading branch information
Krystian Ligenza authored Sep 22, 2021
2 parents f072bcb + 48af5ec commit 4fef906
Show file tree
Hide file tree
Showing 6 changed files with 262 additions and 30 deletions.
66 changes: 49 additions & 17 deletions lib/mayaUsd/fileio/translators/translatorLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
#include <pxr/usd/usd/prim.h>
#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usdLux/distantLight.h>
#if PXR_VERSION < 2111
#include <pxr/usd/usdLux/light.h>
#else
#include <pxr/usd/usdLux/lightAPI.h>
#endif
#include <pxr/usd/usdLux/rectLight.h>
#include <pxr/usd/usdLux/shadowAPI.h>
#include <pxr/usd/usdLux/shapingAPI.h>
Expand Down Expand Up @@ -79,10 +83,14 @@ TF_DEFINE_PRIVATE_TOKENS(
);
// clang-format on

// Export the "common" light attributes from MFnLights to UsdLuxLight
// Export the "common" light attributes from MFnLights to UsdLuxLightAPI
bool UsdMayaTranslatorLight::WriteLightAttrs(
const UsdTimeCode& usdTime,
UsdLuxLight& usdLight,
const UsdTimeCode& usdTime,
#if PXR_VERSION < 2111
const UsdLuxLight& usdLight,
#else
const UsdLuxLightAPI& usdLight,
#endif
MFnLight& mayaLight,
UsdUtilsSparseValueWriter* valueWriter)
{
Expand Down Expand Up @@ -119,7 +127,7 @@ bool UsdMayaTranslatorLight::WriteLightAttrs(
valueWriter);
}

// Some renderers have a float value for diffuse and specular just like UsdLuxLight does (it
// Some renderers have a float value for diffuse and specular just like UsdLuxLightAPI does (it
// defaults to 1) But Maya lights also have a checkbox to enable/disable diffuse and specular.
// We can just set it to 0 or 1 depending on this boolean
bool lightDiffuse = mayaLight.lightDiffuse(&status);
Expand All @@ -135,12 +143,16 @@ bool UsdMayaTranslatorLight::WriteLightAttrs(
return true;
}

// Import the common light attributes from UsdLuxLight.
// Import the common light attributes from UsdLuxLightAPI.
// As opposed to the writer, we can't rely on the MFnLight attribute
// accessors, as we need to support animations. Instead we're getting
// the Maya plugs from MFnDependencyNode
static bool _ReadLightAttrs(
const UsdLuxLight& lightSchema,
#if PXR_VERSION < 2111
const UsdLuxLight& lightSchema,
#else
const UsdLuxLightAPI& lightSchema,
#endif
MFnDependencyNode& depFn,
const UsdMayaPrimReaderArgs& args,
UsdMayaPrimReaderContext& context)
Expand Down Expand Up @@ -201,7 +213,7 @@ static bool _ReadLightAttrs(
// Export the specialized MFnDirectionalLight attributes
bool UsdMayaTranslatorLight::WriteDirectionalLightAttrs(
const UsdTimeCode& usdTime,
UsdLuxDistantLight& usdLight,
const UsdLuxDistantLight& usdLight,
MFnDirectionalLight& mayaLight,
UsdUtilsSparseValueWriter* valueWriter)
{
Expand All @@ -217,7 +229,11 @@ bool UsdMayaTranslatorLight::WriteDirectionalLightAttrs(

// Import the specialized MFnDirectionalLight attributes
static bool _ReadDirectionalLight(
const UsdLuxLight& lightSchema,
#if PXR_VERSION < 2111
const UsdLuxLight& lightSchema,
#else
const UsdLuxLightAPI& lightSchema,
#endif
MFnDependencyNode& depFn,
const UsdMayaPrimReaderArgs& args,
UsdMayaPrimReaderContext& context)
Expand All @@ -237,7 +253,7 @@ static bool _ReadDirectionalLight(
// Export the specialized MFnPointLight attributes
bool UsdMayaTranslatorLight::WritePointLightAttrs(
const UsdTimeCode& usdTime,
UsdLuxSphereLight& usdLight,
const UsdLuxSphereLight& usdLight,
MFnPointLight& mayaLight,
UsdUtilsSparseValueWriter* valueWriter)
{
Expand All @@ -258,7 +274,11 @@ bool UsdMayaTranslatorLight::WritePointLightAttrs(

// Import the specialized MFnPointLight attributes
static bool _ReadPointLight(
const UsdLuxLight& lightSchema,
#if PXR_VERSION < 2111
const UsdLuxLight& lightSchema,
#else
const UsdLuxLightAPI& lightSchema,
#endif
MFnDependencyNode& depFn,
const UsdMayaPrimReaderArgs& args,
UsdMayaPrimReaderContext& context)
Expand All @@ -278,7 +298,7 @@ static bool _ReadPointLight(
// Export the specialized MFnSpotLight attributes
bool UsdMayaTranslatorLight::WriteSpotLightAttrs(
const UsdTimeCode& usdTime,
UsdLuxSphereLight& usdLight,
const UsdLuxSphereLight& usdLight,
MFnSpotLight& mayaLight,
UsdUtilsSparseValueWriter* valueWriter)
{
Expand Down Expand Up @@ -326,7 +346,11 @@ bool UsdMayaTranslatorLight::WriteSpotLightAttrs(

// Import the specialized MFnSpotLight attributes
static bool _ReadSpotLight(
const UsdLuxLight& lightSchema,
#if PXR_VERSION < 2111
const UsdLuxLight& lightSchema,
#else
const UsdLuxLightAPI& lightSchema,
#endif
MFnDependencyNode& depFn,
const UsdMayaPrimReaderArgs& args,
UsdMayaPrimReaderContext& context)
Expand Down Expand Up @@ -386,7 +410,7 @@ static bool _ReadSpotLight(
// Export the specialized MFnAreaLight attributes
bool UsdMayaTranslatorLight::WriteAreaLightAttrs(
const UsdTimeCode& usdTime,
UsdLuxRectLight& usdLight,
const UsdLuxRectLight& usdLight,
MFnAreaLight& mayaLight,
UsdUtilsSparseValueWriter* valueWriter)
{
Expand All @@ -405,7 +429,11 @@ bool UsdMayaTranslatorLight::WriteAreaLightAttrs(

/// Read the parameters from UsdLuxRectLight into a Maya area light
static bool _ReadAreaLight(
const UsdLuxLight& lightSchema,
#if PXR_VERSION < 2111
const UsdLuxLight& lightSchema,
#else
const UsdLuxLightAPI& lightSchema,
#endif
MFnDependencyNode& depFn,
const UsdMayaPrimReaderArgs& args,
UsdMayaPrimReaderContext& context)
Expand Down Expand Up @@ -434,10 +462,14 @@ bool UsdMayaTranslatorLight::Read(
if (!usdPrim) {
return false;
}
#if PXR_VERSION < 2111
const UsdLuxLight lightSchema(usdPrim);
#else
const UsdLuxLightAPI lightSchema(usdPrim);
#endif
if (!lightSchema) {
TF_RUNTIME_ERROR(
"Failed to read UsdLuxLight prim for light %s", usdPrim.GetPath().GetText());
"Failed to read UsdLuxLightAPI prim for light %s", usdPrim.GetPath().GetText());
return false;
}
// Find the corresponding maya light type depending on
Expand All @@ -459,7 +491,7 @@ bool UsdMayaTranslatorLight::Read(
}
if (mayaLightTypeToken.IsEmpty()) {
TF_RUNTIME_ERROR(
"Could not determine Maya light type for UsdLuxLight prim %s",
"Could not determine Maya light type for UsdLuxLightAPI prim %s",
usdPrim.GetPath().GetText());
return false;
}
Expand Down Expand Up @@ -502,7 +534,7 @@ bool UsdMayaTranslatorLight::Read(
return false;
}

// Whatever the light type is, we always want to read the "common" UsdLuxLight attributes
// Whatever the light type is, we always want to read the "common" UsdLuxLightAPI attributes
_ReadLightAttrs(lightSchema, depFn, args, context);
// Read the specialized light attributes depending on the maya light type
if (mayaLightTypeToken == _tokens->DirectionalLightMayaTypeName) {
Expand Down
24 changes: 16 additions & 8 deletions lib/mayaUsd/fileio/translators/translatorLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@

#include <pxr/pxr.h>
#include <pxr/usd/usdLux/distantLight.h>
#if PXR_VERSION < 2111
#include <pxr/usd/usdLux/light.h>
#else
#include <pxr/usd/usdLux/lightAPI.h>
#endif
#include <pxr/usd/usdLux/rectLight.h>
#include <pxr/usd/usdLux/sphereLight.h>

Expand All @@ -39,49 +43,53 @@ PXR_NAMESPACE_OPEN_SCOPE
/// \brief Provides helper functions for translating to/from UsdLux
struct UsdMayaTranslatorLight
{
/// Exports the UsdLuxLight schema attributes from a generic Maya MFnLight.
/// Exports the UsdLuxLightAPI schema attributes from a generic Maya MFnLight.
/// This function should be called when exporting to any of the specialized light schemas.
/// Return true if all the parameters were exported properly.
MAYAUSD_CORE_PUBLIC
static bool WriteLightAttrs(
const UsdTimeCode& usdTime,
UsdLuxLight& usdLight,
const UsdTimeCode& usdTime,
#if PXR_VERSION < 2111
const UsdLuxLight& usdLight,
#else
const UsdLuxLightAPI& usdLight,
#endif
MFnLight& mayaLight,
UsdUtilsSparseValueWriter* valueWriter = nullptr);

/// Exports Maya's directional light attributes using UsdLuxDistantLight schema
MAYAUSD_CORE_PUBLIC
static bool WriteDirectionalLightAttrs(
const UsdTimeCode& usdTime,
UsdLuxDistantLight& usdLight,
const UsdLuxDistantLight& usdLight,
MFnDirectionalLight& mayaLight,
UsdUtilsSparseValueWriter* valueWriter = nullptr);

/// Exports Maya's point light attributes using UsdLuxSphereLight schema
MAYAUSD_CORE_PUBLIC
static bool WritePointLightAttrs(
const UsdTimeCode& usdTime,
UsdLuxSphereLight& usdLight,
const UsdLuxSphereLight& usdLight,
MFnPointLight& mayaLight,
UsdUtilsSparseValueWriter* valueWriter = nullptr);

/// Exports Maya's spot light attributes using UsdLuxSphereLight and UsdLuxShapingAPI schemas
MAYAUSD_CORE_PUBLIC
static bool WriteSpotLightAttrs(
const UsdTimeCode& usdTime,
UsdLuxSphereLight& usdLight,
const UsdLuxSphereLight& usdLight,
MFnSpotLight& mayaLight,
UsdUtilsSparseValueWriter* valueWriter = nullptr);

/// Exports Maya's area light attributes using UsdLuxRectLight schema
MAYAUSD_CORE_PUBLIC
static bool WriteAreaLightAttrs(
const UsdTimeCode& usdTime,
UsdLuxRectLight& usdLight,
const UsdLuxRectLight& usdLight,
MFnAreaLight& mayaLight,
UsdUtilsSparseValueWriter* valueWriter = nullptr);

/// Import a UsdLuxLight schema as a corresponding Maya light.
/// Import a UsdLuxLightAPI schema as a corresponding Maya light.
/// Return true if the maya light was properly created and imported
MAYAUSD_CORE_PUBLIC
static bool Read(const UsdMayaPrimReaderArgs& args, UsdMayaPrimReaderContext& context);
Expand Down
Loading

0 comments on commit 4fef906

Please sign in to comment.