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-1625 - Certain USD light shapes disappear if user try to edit as maya data. #4007

Closed
Closed
Show file tree
Hide file tree
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
180 changes: 180 additions & 0 deletions lib/mayaUsd/fileio/translators/translatorLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include <pxr/usd/sdf/path.h>
#include <pxr/usd/usd/prim.h>
#include <pxr/usd/usd/stage.h>
#include <pxr/usd/usdLux/cylinderLight.h>
#include <pxr/usd/usdLux/diskLight.h>
#include <pxr/usd/usdLux/distantLight.h>
#include <pxr/usd/usdLux/lightAPI.h>
#include <pxr/usd/usdLux/rectLight.h>
Expand Down Expand Up @@ -62,6 +64,9 @@ TF_DEFINE_PRIVATE_TOKENS(
((DirectionalLightMayaTypeName, "directionalLight"))
((PointLightMayaTypeName, "pointLight"))
((AreaLightMayaTypeName, "areaLight"))
((CylinderLightMayaTypeName, "volumeLight"))
((DiskLightMayaTypeName, "volumeLight"))
((DomeLightMayaTypeName, "volumeLight"))
((normalizeAttrName, "normalize"))
// Maya light plug names.
((IntensityPlugName, "intensity"))
Expand All @@ -76,6 +81,7 @@ TF_DEFINE_PRIVATE_TOKENS(
((PenumbraAnglePlugName, "penumbraAngle"))
((ConeAnglePlugName, "coneAngle"))
((LightRadiusPlugName, "lightRadius"))
((LightLengthPlugName, "lightHeight"))
);
// clang-format on

Expand Down Expand Up @@ -424,6 +430,169 @@ static bool _ReadAreaLight(
return success;
}

// Export the specialized MFnVolumeLight attributes
bool UsdMayaTranslatorLight::WriteCylinderLightAttrs(
const UsdTimeCode& usdTime,
const UsdLuxCylinderLight& usdLight,
MFnVolumeLight& mayaLight,
FlexibleSparseValueWriter* valueWriter)
{
MStatus status;

MPlug lightRadiusPlug
= mayaLight.findPlug(_tokens->LightRadiusPlugName.GetText(), true, &status);
CHECK_MSTATUS_AND_RETURN(status, false);
float lightRadius = lightRadiusPlug.asFloat();

MPlug lightLengthPlug
= mayaLight.findPlug(_tokens->LightLengthPlugName.GetText(), true, &status);
CHECK_MSTATUS_AND_RETURN(status, false);
float lightLength = lightLengthPlug.asFloat();

UsdMayaWriteUtil::SetAttribute(usdLight.GetRadiusAttr(), lightRadius, usdTime, valueWriter);
UsdMayaWriteUtil::SetAttribute(usdLight.GetLengthAttr(), lightLength, usdTime, valueWriter);

UsdPrim prim = usdLight.GetPrim();
UsdLuxShapingAPI shapingAPI = UsdLuxShapingAPI::Apply(prim);

return true;
}

bool UsdMayaTranslatorLight::WriteDiskLightAttrs(
const UsdTimeCode& usdTime,
const UsdLuxDiskLight& usdLight,
MFnVolumeLight& mayaLight,
FlexibleSparseValueWriter* valueWriter)
{
MStatus status;

MPlug lightRadiusPlug
= mayaLight.findPlug(_tokens->LightRadiusPlugName.GetText(), true, &status);
CHECK_MSTATUS_AND_RETURN(status, false);
float lightRadius = lightRadiusPlug.asFloat();

UsdMayaWriteUtil::SetAttribute(usdLight.GetRadiusAttr(), lightRadius, usdTime, valueWriter);

UsdPrim prim = usdLight.GetPrim();
UsdLuxShapingAPI shapingAPI = UsdLuxShapingAPI::Apply(prim);

return true;
}

bool UsdMayaTranslatorLight::WriteDomeLightAttrs(
const UsdTimeCode& usdTime,
const UsdLuxDomeLight& usdLight,
MFnVolumeLight& mayaLight,
FlexibleSparseValueWriter* valueWriter)
{
MStatus status;

MPlug lightRadiusPlug
= mayaLight.findPlug(_tokens->LightRadiusPlugName.GetText(), true, &status);
CHECK_MSTATUS_AND_RETURN(status, false);
float lightRadius = lightRadiusPlug.asFloat();

UsdMayaWriteUtil::SetAttribute(
usdLight.CreateGuideRadiusAttr(), lightRadius, usdTime, valueWriter);

UsdPrim prim = usdLight.GetPrim();
UsdLuxShapingAPI shapingAPI = UsdLuxShapingAPI::Apply(prim);

return true;
}

static bool _ReadVolumeLight(
const UsdLuxLightAPI& lightSchema,
MFnDependencyNode& depFn,
const UsdMayaPrimReaderArgs& args,
UsdMayaPrimReaderContext& context)
{
// Both Cylinder light and disk light will be mapped to volume light in Maya

MStatus status;
bool success = true;
UsdPrim prim = lightSchema.GetPrim();

if (prim.IsA<UsdLuxCylinderLight>()) {
UsdLuxCylinderLight cylinderLight(prim);
MPlug plug = depFn.findPlug("lightShape", true, &status);
CHECK_MSTATUS_AND_RETURN(status, false);

success &= UsdMayaReadUtil::SetMayaAttr(plug, VtValue(2), false);

MPlug plug2 = depFn.findPlug("faceAxis", true, &status);
CHECK_MSTATUS_AND_RETURN(status, false);

success &= UsdMayaReadUtil::SetMayaAttr(plug2, VtValue(0), false);

success &= UsdMayaReadUtil::ReadUsdAttribute(
cylinderLight.GetRadiusAttr(), depFn, _tokens->LightRadiusPlugName, args, &context);

UsdLuxShapingAPI shapingAPI(prim);
if (!shapingAPI) {
return false;
}

// We need to specify a time when getting an attribute, otherwise we can get invalid data
// for single time-samples
UsdTimeCode timeCode(args.GetTimeInterval().GetMin());
// We need some magic conversions between maya dropOff, coneAngle, penumbraAngle,
// and Usd shapingFocus, shapingConeAngle, shapingConeSoftness
success &= UsdMayaReadUtil::ReadUsdAttribute(
cylinderLight.GetLengthAttr(), depFn, _tokens->LightLengthPlugName, args, &context);

return success;

} else if (prim.IsA<UsdLuxDiskLight>()) {
UsdLuxDiskLight diskLight(prim);
if (!diskLight) {
return false;
}

MPlug plug = depFn.findPlug("lightShape", true, &status);
CHECK_MSTATUS_AND_RETURN(status, false);

success &= UsdMayaReadUtil::SetMayaAttr(plug, VtValue(2), false);

MPlug plug2 = depFn.findPlug("faceAxis", true, &status);
CHECK_MSTATUS_AND_RETURN(status, false);

success &= UsdMayaReadUtil::SetMayaAttr(plug2, VtValue(2), false);

success &= UsdMayaReadUtil::ReadUsdAttribute(
diskLight.GetRadiusAttr(), depFn, _tokens->LightRadiusPlugName, args, &context);

UsdLuxShapingAPI shapingAPI(prim);
if (!shapingAPI) {
return false;
}

return success;
} else if (prim.IsA<UsdLuxDomeLight>()) {
UsdLuxDomeLight domeLight(prim);
if (!domeLight) {
return false;
}

MPlug plug = depFn.findPlug("lightShape", true, &status);
CHECK_MSTATUS_AND_RETURN(status, false);

success &= UsdMayaReadUtil::SetMayaAttr(plug, VtValue(1), false);

success &= UsdMayaReadUtil::ReadUsdAttribute(
domeLight.GetGuideRadiusAttr(), depFn, _tokens->LightRadiusPlugName, args, &context);

UsdLuxShapingAPI shapingAPI(prim);
if (!shapingAPI) {
return false;
}

return success;
} else {
return false;
}
}

/* static */
bool UsdMayaTranslatorLight::Read(
const UsdMayaPrimReaderArgs& args,
Expand Down Expand Up @@ -456,6 +625,15 @@ bool UsdMayaTranslatorLight::Read(
UsdLuxShapingAPI shapingAPI(lightSchema);
mayaLightTypeToken
= (shapingAPI) ? _tokens->SpotLightMayaTypeName : _tokens->PointLightMayaTypeName;
} else if (usdPrim.IsA<UsdLuxCylinderLight>()) {
// USD Cylinder Light => Maya Volume Light
mayaLightTypeToken = _tokens->CylinderLightMayaTypeName;
} else if (usdPrim.IsA<UsdLuxDiskLight>()) {
// USD Disk Light => Maya Volume Light
mayaLightTypeToken = _tokens->DiskLightMayaTypeName;
} else if (usdPrim.IsA<UsdLuxDomeLight>()) {
// USD Dome Light => Maya Dome Light
mayaLightTypeToken = _tokens->DomeLightMayaTypeName;
}
if (mayaLightTypeToken.IsEmpty()) {
TF_RUNTIME_ERROR(
Expand Down Expand Up @@ -513,6 +691,8 @@ bool UsdMayaTranslatorLight::Read(
_ReadSpotLight(lightSchema, depFn, args, context);
} else if (mayaLightTypeToken == _tokens->AreaLightMayaTypeName) {
_ReadAreaLight(lightSchema, depFn, args, context);
} else if (mayaLightTypeToken == _tokens->CylinderLightMayaTypeName) {
_ReadVolumeLight(lightSchema, depFn, args, context);
}
return true;
}
Expand Down
28 changes: 28 additions & 0 deletions lib/mayaUsd/fileio/translators/translatorLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
#include <mayaUsd/fileio/utils/writeUtil.h>

#include <pxr/pxr.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/rectLight.h>
#include <pxr/usd/usdLux/sphereLight.h>
Expand All @@ -33,6 +36,7 @@
#include <maya/MFnDirectionalLight.h>
#include <maya/MFnPointLight.h>
#include <maya/MFnSpotLight.h>
#include <maya/MFnVolumeLight.h>

PXR_NAMESPACE_OPEN_SCOPE

Expand Down Expand Up @@ -81,6 +85,30 @@ struct UsdMayaTranslatorLight
MFnAreaLight& mayaLight,
FlexibleSparseValueWriter* valueWriter = nullptr);

/// Exports Maya's area light attributes using UsdLuxCylinderLight schema
MAYAUSD_CORE_PUBLIC
static bool WriteCylinderLightAttrs(
const UsdTimeCode& usdTime,
const UsdLuxCylinderLight& usdLight,
MFnVolumeLight& mayaLight,
FlexibleSparseValueWriter* valueWriter = nullptr);

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

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

/// Import a UsdLuxLightAPI schema as a corresponding Maya light.
/// Return true if the maya light was properly created and imported
MAYAUSD_CORE_PUBLIC
Expand Down
7 changes: 7 additions & 0 deletions lib/usd/translators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ if(CMAKE_UFE_V3_FEATURES_AVAILABLE)
)
endif()

if (UFE_VOLUME_LIGHTS_SUPPORT)
target_compile_definitions(${TARGET_NAME}
PRIVATE
UFE_VOLUME_LIGHTS_SUPPORT=1
)
endif()

add_subdirectory(shading)

# -----------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions lib/usd/translators/lightReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,23 @@ PXRUSDMAYA_DEFINE_READER(UsdLuxCylinderLight, args, context)
if (TfGetEnvSetting(MAYAUSD_IMPORT_RFM_LIGHTS)) {
return UsdMayaTranslatorRfMLight::Read(args, context);
}
#ifdef UFE_VOLUME_LIGHTS_SUPPORT
return UsdMayaTranslatorLight::Read(args, context);
#else
return false;
#endif
}

PXRUSDMAYA_DEFINE_READER(UsdLuxDiskLight, args, context)
{
if (TfGetEnvSetting(MAYAUSD_IMPORT_RFM_LIGHTS)) {
return UsdMayaTranslatorRfMLight::Read(args, context);
}
#ifdef UFE_VOLUME_LIGHTS_SUPPORT
return UsdMayaTranslatorLight::Read(args, context);
#else
return false;
#endif
}

PXRUSDMAYA_DEFINE_READER(UsdLuxDistantLight, args, context)
Expand All @@ -55,7 +63,11 @@ PXRUSDMAYA_DEFINE_READER(UsdLuxDomeLight, args, context)
if (TfGetEnvSetting(MAYAUSD_IMPORT_RFM_LIGHTS)) {
return UsdMayaTranslatorRfMLight::Read(args, context);
}
#ifdef UFE_VOLUME_LIGHTS_SUPPORT
return UsdMayaTranslatorLight::Read(args, context);
#else
return false;
#endif
}

PXRUSDMAYA_DEFINE_READER(UsdLuxGeometryLight, args, context)
Expand Down
Loading
Loading