Skip to content

Commit

Permalink
Merge pull request #1618 from Autodesk/boudrey/MAYA-113148/ref-instea…
Browse files Browse the repository at this point in the history
…d-of-ptr

MAYA-113148 MayaUSD: Pass UsdMayaPrimReaderContext as reference inste…
  • Loading branch information
seando-adsk authored Aug 23, 2021
2 parents 8c07745 + 35ed7d6 commit 2779350
Show file tree
Hide file tree
Showing 34 changed files with 104 additions and 109 deletions.
6 changes: 3 additions & 3 deletions lib/mayaUsd/fileio/fallbackPrimReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ UsdMaya_FallbackPrimReader::UsdMaya_FallbackPrimReader(const UsdMayaPrimReaderAr
{
}

bool UsdMaya_FallbackPrimReader::Read(UsdMayaPrimReaderContext* context)
bool UsdMaya_FallbackPrimReader::Read(UsdMayaPrimReaderContext& context)
{
const UsdPrim& usdPrim = _GetArgs().GetUsdPrim();
if (usdPrim.HasAuthoredTypeName() && !usdPrim.IsA<UsdGeomImageable>()) {
Expand All @@ -35,7 +35,7 @@ bool UsdMaya_FallbackPrimReader::Read(UsdMayaPrimReaderContext* context)
return false;
}

MObject parentNode = context->GetMayaNode(usdPrim.GetPath().GetParentPath(), true);
MObject parentNode = context.GetMayaNode(usdPrim.GetPath().GetParentPath(), true);

MStatus status;
MObject mayaNode;
Expand All @@ -44,7 +44,7 @@ bool UsdMaya_FallbackPrimReader::Read(UsdMayaPrimReaderContext* context)
parentNode,
/*importTypeName*/ false,
_GetArgs(),
context,
&context,
&status,
&mayaNode);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/fallbackPrimReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class UsdMaya_FallbackPrimReader : public UsdMayaPrimReader
public:
UsdMaya_FallbackPrimReader(const UsdMayaPrimReaderArgs& args);

virtual bool Read(UsdMayaPrimReaderContext* context);
bool Read(UsdMayaPrimReaderContext& context) override;

static UsdMayaPrimReaderRegistry::ReaderFactoryFn CreateFactory();
};
Expand Down
3 changes: 1 addition & 2 deletions lib/mayaUsd/fileio/functorPrimReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ UsdMaya_FunctorPrimReader::UsdMaya_FunctorPrimReader(
{
}

bool UsdMaya_FunctorPrimReader::Read(UsdMayaPrimReaderContext* context)
bool UsdMaya_FunctorPrimReader::Read(UsdMayaPrimReaderContext& context)
{
TF_VERIFY(context);
return _readerFn(_GetArgs(), context);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/functorPrimReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class UsdMaya_FunctorPrimReader final : public UsdMayaPrimReader
public:
UsdMaya_FunctorPrimReader(const UsdMayaPrimReaderArgs&, UsdMayaPrimReaderRegistry::ReaderFn);

bool Read(UsdMayaPrimReaderContext* context) override;
bool Read(UsdMayaPrimReaderContext& context) override;

static UsdMayaPrimReaderSharedPtr
Create(const UsdMayaPrimReaderArgs&, UsdMayaPrimReaderRegistry::ReaderFn readerFn);
Expand Down
4 changes: 2 additions & 2 deletions lib/mayaUsd/fileio/jobs/readJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ void UsdMaya_ReadJob::_DoImportPrimIt(
// specified one.
auto primReaderIt = primReaderMap.find(prim.GetPath());
if (primReaderIt != primReaderMap.end()) {
primReaderIt->second->PostReadSubtree(&readCtx);
primReaderIt->second->PostReadSubtree(readCtx);
}
} else {
// This is the normal Read step (pre-visit).
Expand All @@ -374,7 +374,7 @@ void UsdMaya_ReadJob::_DoImportPrimIt(
= UsdMayaPrimReaderRegistry::FindOrFallback(typeName)) {
UsdMayaPrimReaderSharedPtr primReader = factoryFn(args);
if (primReader) {
primReader->Read(&readCtx);
primReader->Read(readCtx);
if (primReader->HasPostReadSubtree()) {
primReaderMap[prim.GetPath()] = primReader;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/primReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ UsdMayaPrimReader::UsdMayaPrimReader(const UsdMayaPrimReaderArgs& args)

bool UsdMayaPrimReader::HasPostReadSubtree() const { return false; }

void UsdMayaPrimReader::PostReadSubtree(UsdMayaPrimReaderContext*) { }
void UsdMayaPrimReader::PostReadSubtree(UsdMayaPrimReaderContext&) { }

const UsdMayaPrimReaderArgs& UsdMayaPrimReader::_GetArgs() { return _args; }

Expand Down
6 changes: 2 additions & 4 deletions lib/mayaUsd/fileio/primReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,22 @@ class UsdMayaPrimReader

/// Reads the USD prim given by the prim reader args into a Maya shape,
/// modifying the prim reader context as a result.
/// Callers must ensure \p context is non-null.
/// Returns true if successful.
MAYAUSD_CORE_PUBLIC
virtual bool Read(UsdMayaPrimReaderContext* context) = 0;
virtual bool Read(UsdMayaPrimReaderContext& context) = 0;

/// Whether this prim reader specifies a PostReadSubtree step.
MAYAUSD_CORE_PUBLIC
virtual bool HasPostReadSubtree() const;

/// An additional import step that runs after all descendants of this prim
/// have been processed.
/// Callers must ensure \p context is non-null.
/// For example, if we have prims /A, /A/B, and /C, then the import steps
/// are run in the order:
/// (1) Read A (2) Read B (3) PostReadSubtree B (4) PostReadSubtree A,
/// (5) Read C (6) PostReadSubtree C
MAYAUSD_CORE_PUBLIC
virtual void PostReadSubtree(UsdMayaPrimReaderContext* context);
virtual void PostReadSubtree(UsdMayaPrimReaderContext& context);

protected:
/// Input arguments. Read data about the input USD prim from here.
Expand Down
6 changes: 3 additions & 3 deletions lib/mayaUsd/fileio/primReaderRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct UsdMayaPrimReaderRegistry
/// Reader function, i.e. a function that reads a prim. This is the
/// signature of the function declared in the PXRUSDMAYA_DEFINE_READER
/// macro.
typedef std::function<bool(const UsdMayaPrimReaderArgs&, UsdMayaPrimReaderContext*)> ReaderFn;
typedef std::function<bool(const UsdMayaPrimReaderArgs&, UsdMayaPrimReaderContext&)> ReaderFn;

/// \brief Register \p fn as a reader provider for \p type.
MAYAUSD_CORE_PUBLIC
Expand Down Expand Up @@ -122,13 +122,13 @@ struct UsdMayaPrimReaderRegistry
};

#define PXRUSDMAYA_DEFINE_READER(T, argsVarName, ctxVarName) \
static bool UsdMaya_PrimReader_##T(const UsdMayaPrimReaderArgs&, UsdMayaPrimReaderContext*); \
static bool UsdMaya_PrimReader_##T(const UsdMayaPrimReaderArgs&, UsdMayaPrimReaderContext&); \
TF_REGISTRY_FUNCTION_WITH_TAG(UsdMayaPrimReaderRegistry, T) \
{ \
UsdMayaPrimReaderRegistry::RegisterRaw<T>(UsdMaya_PrimReader_##T); \
} \
bool UsdMaya_PrimReader_##T( \
const UsdMayaPrimReaderArgs& argsVarName, UsdMayaPrimReaderContext* ctxVarName)
const UsdMayaPrimReaderArgs& argsVarName, UsdMayaPrimReaderContext& ctxVarName)

PXR_NAMESPACE_CLOSE_SCOPE

Expand Down
3 changes: 2 additions & 1 deletion lib/mayaUsd/fileio/shading/shadingModeUseRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,8 @@ class UseRegistryShadingModeImporter
{
// UsdMayaPrimReader::Read is a function that works by indirect effect. It will return
// "true" on success, and the resulting changes will be found in the _context object.
if (!shaderReader.Read(_context->GetPrimReaderContext())) {
UsdMayaPrimReaderContext* context = _context->GetPrimReaderContext();
if (context == nullptr || !shaderReader.Read(*context)) {
return MObject();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/mayaUsd/fileio/shading/symmetricShaderReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ UsdMayaSymmetricShaderReader::UsdMayaSymmetricShaderReader(
}

/* override */
bool UsdMayaSymmetricShaderReader::Read(UsdMayaPrimReaderContext* context)
bool UsdMayaSymmetricShaderReader::Read(UsdMayaPrimReaderContext& context)
{
const UsdPrim& prim = _GetArgs().GetUsdPrim();
const UsdShadeShader shaderSchema = UsdShadeShader(prim);
Expand Down Expand Up @@ -175,7 +175,7 @@ bool UsdMayaSymmetricShaderReader::Read(UsdMayaPrimReaderContext* context)
return false;
}

context->RegisterNewMayaNode(prim.GetPath().GetString(), mayaObject);
context.RegisterNewMayaNode(prim.GetPath().GetString(), mayaObject);

for (const UsdShadeInput& input : shaderSchema.GetInputs()) {
const UsdAttribute& usdAttr = input.GetAttr();
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/shading/symmetricShaderReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class UsdMayaSymmetricShaderReader : public UsdMayaShaderReader
const TfToken& mayaNodeTypeName);

MAYAUSD_CORE_PUBLIC
bool Read(UsdMayaPrimReaderContext* context) override;
bool Read(UsdMayaPrimReaderContext& context) override;

MAYAUSD_CORE_PUBLIC
TfToken GetMayaNameForUsdAttrName(const TfToken& usdAttrName) const override;
Expand Down
36 changes: 18 additions & 18 deletions lib/mayaUsd/fileio/translators/translatorLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static bool _ReadLightAttrs(
const UsdLuxLight& lightSchema,
MFnDependencyNode& depFn,
const UsdMayaPrimReaderArgs& args,
UsdMayaPrimReaderContext* context)
UsdMayaPrimReaderContext& context)
{
MStatus status;
bool success = true;
Expand All @@ -155,10 +155,10 @@ static bool _ReadLightAttrs(

// ReadUsdAttribute will read a Usd attribute, accounting for eventual animations
success &= UsdMayaReadUtil::ReadUsdAttribute(
lightSchema.GetIntensityAttr(), depFn, _tokens->IntensityPlugName, args, context);
lightSchema.GetIntensityAttr(), depFn, _tokens->IntensityPlugName, args, &context);

success &= UsdMayaReadUtil::ReadUsdAttribute(
lightSchema.GetColorAttr(), depFn, _tokens->ColorPlugName, args, context);
lightSchema.GetColorAttr(), depFn, _tokens->ColorPlugName, args, &context);

// For diffuse & specular, the USD value is a [0,1] float, but it's a boolean in Maya.
// We can't really import this properly, but at least we're enabling the maya attibute
Expand Down Expand Up @@ -191,9 +191,9 @@ static bool _ReadLightAttrs(
depFn,
_tokens->UseRayTraceShadowsPlugName,
args,
context);
&context);
success &= UsdMayaReadUtil::ReadUsdAttribute(
shadowAPI.GetShadowColorAttr(), depFn, _tokens->ShadowColorPlugName, args, context);
shadowAPI.GetShadowColorAttr(), depFn, _tokens->ShadowColorPlugName, args, &context);
}
return success;
}
Expand All @@ -220,7 +220,7 @@ static bool _ReadDirectionalLight(
const UsdLuxLight& lightSchema,
MFnDependencyNode& depFn,
const UsdMayaPrimReaderArgs& args,
UsdMayaPrimReaderContext* context)
UsdMayaPrimReaderContext& context)
{
MStatus status;
bool success = true;
Expand All @@ -230,7 +230,7 @@ static bool _ReadDirectionalLight(
return false;
}
success &= UsdMayaReadUtil::ReadUsdAttribute(
distantLight.GetAngleAttr(), depFn, _tokens->LightAnglePlugName, args, context);
distantLight.GetAngleAttr(), depFn, _tokens->LightAnglePlugName, args, &context);
return success;
}

Expand Down Expand Up @@ -261,7 +261,7 @@ static bool _ReadPointLight(
const UsdLuxLight& lightSchema,
MFnDependencyNode& depFn,
const UsdMayaPrimReaderArgs& args,
UsdMayaPrimReaderContext* context)
UsdMayaPrimReaderContext& context)
{
MStatus status;
bool success = true;
Expand All @@ -271,7 +271,7 @@ static bool _ReadPointLight(
return false;
}
success &= UsdMayaReadUtil::ReadUsdAttribute(
sphereLight.GetRadiusAttr(), depFn, _tokens->LightRadiusPlugName, args, context);
sphereLight.GetRadiusAttr(), depFn, _tokens->LightRadiusPlugName, args, &context);
return success;
}

Expand Down Expand Up @@ -329,7 +329,7 @@ static bool _ReadSpotLight(
const UsdLuxLight& lightSchema,
MFnDependencyNode& depFn,
const UsdMayaPrimReaderArgs& args,
UsdMayaPrimReaderContext* context)
UsdMayaPrimReaderContext& context)
{

MStatus status;
Expand All @@ -340,7 +340,7 @@ static bool _ReadSpotLight(
return false;
}
success &= UsdMayaReadUtil::ReadUsdAttribute(
sphereLight.GetRadiusAttr(), depFn, _tokens->LightRadiusPlugName, args, context);
sphereLight.GetRadiusAttr(), depFn, _tokens->LightRadiusPlugName, args, &context);

UsdLuxShapingAPI shapingAPI(prim);
if (!shapingAPI) {
Expand All @@ -353,7 +353,7 @@ static bool _ReadSpotLight(
// We need some magic conversions between maya dropOff, coneAngle, penumbraAngle,
// and Usd shapingFocus, shapingConeAngle, shapingConeSoftness
success &= UsdMayaReadUtil::ReadUsdAttribute(
shapingAPI.GetShapingFocusAttr(), depFn, _tokens->DropoffPlugName, args, context);
shapingAPI.GetShapingFocusAttr(), depFn, _tokens->DropoffPlugName, args, &context);

float UsdConeAngle = 1.f;
shapingAPI.GetShapingConeAngleAttr().Get(&UsdConeAngle, timeCode);
Expand Down Expand Up @@ -408,7 +408,7 @@ static bool _ReadAreaLight(
const UsdLuxLight& lightSchema,
MFnDependencyNode& depFn,
const UsdMayaPrimReaderArgs& args,
UsdMayaPrimReaderContext* context)
UsdMayaPrimReaderContext& context)
{
MStatus status;
bool success = true;
Expand All @@ -419,15 +419,15 @@ static bool _ReadAreaLight(
}

success &= UsdMayaReadUtil::ReadUsdAttribute(
rectLight.GetNormalizeAttr(), depFn, _tokens->normalizeAttrName, args, context);
rectLight.GetNormalizeAttr(), depFn, _tokens->normalizeAttrName, args, &context);

return success;
}

/* static */
bool UsdMayaTranslatorLight::Read(
const UsdMayaPrimReaderArgs& args,
UsdMayaPrimReaderContext* context)
UsdMayaPrimReaderContext& context)
{
// Get the Usd primitive we're reading
const UsdPrim& usdPrim = args.GetUsdPrim();
Expand Down Expand Up @@ -465,12 +465,12 @@ bool UsdMayaTranslatorLight::Read(
}

// Find which maya node needs to be our light's parent
MObject parentNode = context->GetMayaNode(lightSchema.GetPath().GetParentPath(), false);
MObject parentNode = context.GetMayaNode(lightSchema.GetPath().GetParentPath(), false);
MStatus status;
MObject mayaNodeTransformObj;
// First create the transform node
if (!UsdMayaTranslatorUtil::CreateTransformNode(
usdPrim, parentNode, args, context, &status, &mayaNodeTransformObj)) {
usdPrim, parentNode, args, &context, &status, &mayaNodeTransformObj)) {
TF_RUNTIME_ERROR("Failed to create transform node for %s", lightSchema.GetPath().GetText());
return false;
}
Expand All @@ -494,7 +494,7 @@ bool UsdMayaTranslatorLight::Read(

const std::string nodePath
= lightSchema.GetPath().AppendChild(TfToken(nodeName.asChar())).GetString();
context->RegisterNewMayaNode(nodePath, lightObj);
context.RegisterNewMayaNode(nodePath, lightObj);

MFnDependencyNode depFn(lightObj, &status);
if (status != MS::kSuccess) {
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/translators/translatorLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct UsdMayaTranslatorLight
/// Import a UsdLuxLight 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);
static bool Read(const UsdMayaPrimReaderArgs& args, UsdMayaPrimReaderContext& context);
};

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down
4 changes: 2 additions & 2 deletions lib/usd/pxrUsdPreviewSurface/usdPreviewSurfaceReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ PxrMayaUsdPreviewSurface_Reader::PxrMayaUsdPreviewSurface_Reader(
}

/* virtual */
bool PxrMayaUsdPreviewSurface_Reader::Read(UsdMayaPrimReaderContext* context)
bool PxrMayaUsdPreviewSurface_Reader::Read(UsdMayaPrimReaderContext& context)
{
const UsdPrim& prim = _GetArgs().GetUsdPrim();
UsdShadeShader shaderSchema = UsdShadeShader(prim);
Expand All @@ -85,7 +85,7 @@ bool PxrMayaUsdPreviewSurface_Reader::Read(UsdMayaPrimReaderContext* context)
return false;
}

context->RegisterNewMayaNode(prim.GetPath().GetString(), mayaObject);
context.RegisterNewMayaNode(prim.GetPath().GetString(), mayaObject);

for (const UsdShadeInput& input : shaderSchema.GetInputs()) {
TfToken baseName = GetMayaNameForUsdAttrName(input.GetFullName());
Expand Down
2 changes: 1 addition & 1 deletion lib/usd/pxrUsdPreviewSurface/usdPreviewSurfaceReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PxrMayaUsdPreviewSurface_Reader : public UsdMayaShaderReader
public:
PxrMayaUsdPreviewSurface_Reader(const UsdMayaPrimReaderArgs&, const TfToken& mayaTypeName);

bool Read(UsdMayaPrimReaderContext* context) override;
bool Read(UsdMayaPrimReaderContext& context) override;

TfToken GetMayaNameForUsdAttrName(const TfToken& usdAttrName) const override;
};
Expand Down
4 changes: 2 additions & 2 deletions lib/usd/translators/cameraReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ PXR_NAMESPACE_OPEN_SCOPE
PXRUSDMAYA_DEFINE_READER(UsdGeomCamera, args, context)
{
const UsdPrim& usdPrim = args.GetUsdPrim();
MObject parentNode = context->GetMayaNode(usdPrim.GetPath().GetParentPath(), true);
return UsdMayaTranslatorCamera::Read(UsdGeomCamera(usdPrim), parentNode, args, context);
MObject parentNode = context.GetMayaNode(usdPrim.GetPath().GetParentPath(), true);
return UsdMayaTranslatorCamera::Read(UsdGeomCamera(usdPrim), parentNode, args, &context);
}

PXR_NAMESPACE_CLOSE_SCOPE
4 changes: 2 additions & 2 deletions lib/usd/translators/lightRfMReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ PXRUSDMAYA_DEFINE_READER(UsdLuxSphereLight, args, context)

PXRUSDMAYA_DEFINE_READER(UsdRiPxrAovLight, args, context)
{
return UsdMayaTranslatorRfMLight::Read(args, context);
return UsdMayaTranslatorRfMLight::Read(args, &context);
}

PXRUSDMAYA_DEFINE_READER(UsdRiPxrEnvDayLight, args, context)
{
return UsdMayaTranslatorRfMLight::Read(args, context);
return UsdMayaTranslatorRfMLight::Read(args, &context);
}

PXR_NAMESPACE_CLOSE_SCOPE
4 changes: 2 additions & 2 deletions lib/usd/translators/materialReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ PXRUSDMAYA_DEFINE_READER(UsdShadeMaterial, args, context)
if (importUnboundShaders) {
const UsdPrim& usdPrim = args.GetUsdPrim();
UsdMayaTranslatorMaterial::Read(
args.GetJobArguments(), UsdShadeMaterial(usdPrim), UsdGeomGprim(), context);
args.GetJobArguments(), UsdShadeMaterial(usdPrim), UsdGeomGprim(), &context);
}
// Always prune materials' namespace descendants - assume that it's just
// part of the material's shading network.
context->SetPruneChildren(true);
context.SetPruneChildren(true);
return true;
}

Expand Down
Loading

0 comments on commit 2779350

Please sign in to comment.