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

MAYA-110155: consistent namespace across the project - Part 2 #1231

Merged
Merged
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
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/shading/shadingModeDisplayColor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ DEFINE_SHADING_MODE_IMPORTER_WITH_JOB_ARGUMENTS(
return MObject();
}

const GfVec3f displayColor = UsdMayaColorSpace::ConvertLinearToMaya(linearDisplayColor);
const GfVec3f displayColor = MayaUsd::utils::ConvertLinearToMaya(linearDisplayColor);

// We default to lambert if no conversion was requested:
const TfToken& preferredMaterial
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/utils/meshReadUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ bool assignColorSetPrimvarToMesh(
}

if (isDisplayColor) {
colorValue = UsdMayaColorSpace::ConvertLinearToMaya(colorValue);
colorValue = MayaUsd::utils::ConvertLinearToMaya(colorValue);
}

MColor mColor(colorValue[0], colorValue[1], colorValue[2], colorValue[3]);
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/utils/meshWriteUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ GfVec3f LinearColorFromColorSet(const MColor& mayaColor, bool shouldConvertToLin
// need to convert it to linear.
GfVec3f c(mayaColor[0], mayaColor[1], mayaColor[2]);
if (shouldConvertToLinear) {
return UsdMayaColorSpace::ConvertMayaToLinear(c);
return MayaUsd::utils::ConvertMayaToLinear(c);
}
return c;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/utils/readUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ MObject UsdMayaReadUtil::FindOrCreateMayaAttr(
template <typename T> T _ConvertVec(const MPlug& plug, const T& val)
{
if (MFnAttribute(plug.attribute()).isUsedAsColor()) {
return UsdMayaColorSpace::ConvertLinearToMaya(val);
return MayaUsd::utils::ConvertLinearToMaya(val);
} else {
return val;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/utils/writeUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static VtValue _ConvertVec(const T& val, const TfToken& role, const bool lineari
{
return VtValue(
((role == SdfValueRoleNames->Color) && linearizeColors)
? UsdMayaColorSpace::ConvertMayaToLinear(val)
? MayaUsd::utils::ConvertMayaToLinear(val)
: val);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/nodes/hdImagingShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ MObject PxrMayaHdImagingShape::GetOrCreateInstance()
// We never intend for the imaging shape to get saved out to the Maya scene
// file, so make sure that we preserve the scene modification status from
// before we create the shape.
const UsdMayaBlockSceneModificationContext blockModContext;
const MayaUsd::utils::BlockSceneModificationContext blockModContext;

// Create a transform node for the shape.
MObject hdImagingTransformObj;
Expand Down
10 changes: 3 additions & 7 deletions lib/mayaUsd/python/wrapBlockSceneModificationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,25 @@
//
#include <mayaUsd/utils/blockSceneModificationContext.h>

#include <pxr/pxr.h>

#include <boost/python.hpp>

#include <memory>

using namespace boost::python;

PXR_NAMESPACE_USING_DIRECTIVE;

namespace {

// This exposes UsdMayaBlockSceneModificationContext as a Python "context
// This exposes BlockSceneModificationContext as a Python "context
// manager" object that can be used with the "with" statement.
class _PyBlockSceneModificationContext
{
public:
void __enter__() { _context.reset(new UsdMayaBlockSceneModificationContext()); }
void __enter__() { _context.reset(new MayaUsd::utils::BlockSceneModificationContext()); }

void __exit__(object, object, object) { _context.reset(); }

private:
std::shared_ptr<UsdMayaBlockSceneModificationContext> _context;
std::shared_ptr<MayaUsd::utils::BlockSceneModificationContext> _context;
};

} // anonymous namespace
Expand Down
16 changes: 8 additions & 8 deletions lib/mayaUsd/python/wrapColorSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ PXR_NAMESPACE_USING_DIRECTIVE

void wrapColorSpace()
{
def("ConvertLinearToMaya", UsdMayaColorSpace::ConvertLinearToMaya<GfVec3f>);
def("ConvertLinearToMaya", UsdMayaColorSpace::ConvertLinearToMaya<GfVec3d>);
def("ConvertLinearToMaya", UsdMayaColorSpace::ConvertLinearToMaya<GfVec4f>);
def("ConvertLinearToMaya", UsdMayaColorSpace::ConvertLinearToMaya<GfVec4d>);
def("ConvertMayaToLinear", UsdMayaColorSpace::ConvertMayaToLinear<GfVec3f>);
def("ConvertMayaToLinear", UsdMayaColorSpace::ConvertMayaToLinear<GfVec3d>);
def("ConvertMayaToLinear", UsdMayaColorSpace::ConvertMayaToLinear<GfVec4f>);
def("ConvertMayaToLinear", UsdMayaColorSpace::ConvertMayaToLinear<GfVec4d>);
def("ConvertLinearToMaya", MayaUsd::utils::ConvertLinearToMaya<GfVec3f>);
def("ConvertLinearToMaya", MayaUsd::utils::ConvertLinearToMaya<GfVec3d>);
def("ConvertLinearToMaya", MayaUsd::utils::ConvertLinearToMaya<GfVec4f>);
def("ConvertLinearToMaya", MayaUsd::utils::ConvertLinearToMaya<GfVec4d>);
def("ConvertMayaToLinear", MayaUsd::utils::ConvertMayaToLinear<GfVec3f>);
def("ConvertMayaToLinear", MayaUsd::utils::ConvertMayaToLinear<GfVec3d>);
def("ConvertMayaToLinear", MayaUsd::utils::ConvertMayaToLinear<GfVec4f>);
def("ConvertMayaToLinear", MayaUsd::utils::ConvertMayaToLinear<GfVec4d>);
}
2 changes: 1 addition & 1 deletion lib/mayaUsd/render/vp2RenderDelegate/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ void HdVP2Mesh::_UpdateDrawItem(
|| colorInterp == HdInterpolationInstance)
&& (alphaInterp == HdInterpolationConstant
|| alphaInterp == HdInterpolationInstance)) {
const GfVec3f& clr3f = UsdMayaColorSpace::ConvertLinearToMaya(colorArray[0]);
const GfVec3f& clr3f = MayaUsd::utils::ConvertLinearToMaya(colorArray[0]);
const MColor color(clr3f[0], clr3f[1], clr3f[2], alphaArray[0]);
shader = _delegate->GetFallbackShader(color);
// The color of the fallback shader is ignored when the interpolation is
Expand Down
13 changes: 7 additions & 6 deletions lib/mayaUsd/utils/blockSceneModificationContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
#include "blockSceneModificationContext.h"

#include <pxr/base/tf/stringUtils.h>
#include <pxr/pxr.h>

#include <maya/MGlobal.h>
#include <maya/MStatus.h>
#include <maya/MString.h>

PXR_NAMESPACE_OPEN_SCOPE
namespace MAYAUSD_NS_DEF {
namespace utils {

UsdMayaBlockSceneModificationContext::UsdMayaBlockSceneModificationContext()
BlockSceneModificationContext::BlockSceneModificationContext()
{
const MString fileModifiedCmd("file -query -modified");
int cmdResult = 0;
Expand All @@ -35,13 +35,14 @@ UsdMayaBlockSceneModificationContext::UsdMayaBlockSceneModificationContext()
}

/* virtual */
UsdMayaBlockSceneModificationContext::~UsdMayaBlockSceneModificationContext()
BlockSceneModificationContext::~BlockSceneModificationContext()
{
const MString setFileModifiedCmd(
TfStringPrintf("file -modified %d", _sceneWasModified ? 1 : 0).c_str());
PXR_NS::TfStringPrintf("file -modified %d", _sceneWasModified ? 1 : 0).c_str());

MStatus status = MGlobal::executeCommand(setFileModifiedCmd);
CHECK_MSTATUS(status);
}

PXR_NAMESPACE_CLOSE_SCOPE
} // namespace utils
} // namespace MAYAUSD_NS_DEF
25 changes: 12 additions & 13 deletions lib/mayaUsd/utils/blockSceneModificationContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,34 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef PXRUSDMAYA_BLOCK_SCENE_MODIFICATION_CONTEXT_H
#define PXRUSDMAYA_BLOCK_SCENE_MODIFICATION_CONTEXT_H
#ifndef MAYAUSD_UTILS_BLOCK_SCENE_MODIFICATION_CONTEXT_H
#define MAYAUSD_UTILS_BLOCK_SCENE_MODIFICATION_CONTEXT_H

#include <mayaUsd/base/api.h>

#include <pxr/pxr.h>

PXR_NAMESPACE_OPEN_SCOPE
namespace MAYAUSD_NS_DEF {
namespace utils {

/// Utility class for wrapping a scope of Maya operations such that the
/// modification status of the Maya scene is preserved.
class UsdMayaBlockSceneModificationContext
class BlockSceneModificationContext
{
public:
MAYAUSD_CORE_PUBLIC
UsdMayaBlockSceneModificationContext();
BlockSceneModificationContext();

MAYAUSD_CORE_PUBLIC
virtual ~UsdMayaBlockSceneModificationContext();
virtual ~BlockSceneModificationContext();

private:
/// Modification status of the scene when the context was created.
bool _sceneWasModified;

UsdMayaBlockSceneModificationContext(const UsdMayaBlockSceneModificationContext&) = delete;
UsdMayaBlockSceneModificationContext& operator=(const UsdMayaBlockSceneModificationContext&)
= delete;
BlockSceneModificationContext(const BlockSceneModificationContext&) = delete;
BlockSceneModificationContext& operator=(const BlockSceneModificationContext&) = delete;
};

PXR_NAMESPACE_CLOSE_SCOPE
} // namespace utils
} // namespace MAYAUSD_NS_DEF

#endif
#endif // MAYAUSD_UTILS_BLOCK_SCENE_MODIFICATION_CONTEXT_H
8 changes: 7 additions & 1 deletion lib/mayaUsd/utils/colorSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@

PXR_NAMESPACE_USING_DIRECTIVE
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forced to keep this here because of "PIXMAYA_LINEAR_COLORS"


namespace MAYAUSD_NS_DEF {
namespace utils {

TF_DEFINE_ENV_SETTING(
PIXMAYA_LINEAR_COLORS,
false,
"If colors from maya should be treated as linear. "
"When false, colors are assumed to be gamma-corrected.");

bool UsdMayaColorSpace::IsColorManaged()
bool IsColorManaged()
{
// in theory this could vary per scene, but we think mixing that within any
// given pipeline is likely confusing. Also, we want to avoid this function
// calling out to mel.
return TfGetEnvSetting(PIXMAYA_LINEAR_COLORS);
}

} // namespace utils
} // namespace MAYAUSD_NS_DEF
17 changes: 7 additions & 10 deletions lib/mayaUsd/utils/colorSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef PXRUSDMAYA_COLORSPACE_H
#define PXRUSDMAYA_COLORSPACE_H
#ifndef MAYAUSD_UTILS_COLORSPACE_H
#define MAYAUSD_UTILS_COLORSPACE_H

#include <mayaUsd/base/api.h>

#include <pxr/base/gf/gamma.h>
#include <pxr/pxr.h>

PXR_NAMESPACE_OPEN_SCOPE

/// Helper functions for dealing with colors stored in Maya.
///
/// Technically, this doesn't need to be tied to Usd.
namespace UsdMayaColorSpace {
namespace MAYAUSD_NS_DEF {
namespace utils {

/// Returns true if we treat colors from Maya as linear colors.
///
Expand Down Expand Up @@ -62,8 +60,7 @@ template <typename T> T ConvertMayaToLinear(const T& mayaColor)
return IsColorManaged() ? mayaColor : GfConvertDisplayToLinear(mayaColor);
}

}; // namespace UsdMayaColorSpace

PXR_NAMESPACE_CLOSE_SCOPE
} // namespace utils
} // namespace MAYAUSD_NS_DEF

#endif
#endif // MAYAUSD_UTILS_COLORSPACE_H
13 changes: 5 additions & 8 deletions lib/mayaUsd/utils/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,7 @@ struct MDataHandleConvert
convert(const USD_Type& src, MDataHandle& dst, const ConverterArgs& args)
{
MAYA_Type tmpDst;
USD_Type tmpSrc
= args._doGammaCorrection ? UsdMayaColorSpace::ConvertLinearToMaya(src) : src;
USD_Type tmpSrc = args._doGammaCorrection ? MayaUsd::utils::ConvertLinearToMaya(src) : src;
TypedConverter<MAYA_Type, USD_Type>::convert(tmpSrc, tmpDst);
MDataHandleUtils<MAYA_Type>::set(dst, tmpDst);
}
Expand All @@ -642,7 +641,7 @@ struct MDataHandleConvert
TypedConverter<MAYA_Type, USD_Type>::convert(tmpSrc, dst);

if (args._doGammaCorrection)
dst = UsdMayaColorSpace::ConvertMayaToLinear(dst);
dst = MayaUsd::utils::ConvertMayaToLinear(dst);
}

// MDataHandle <--> UsdAttribute
Expand Down Expand Up @@ -707,8 +706,7 @@ template <class MAYA_Type, class USD_Type, NeedsGammaCorrection ColorCorrection>
convert(const USD_Type& src, MPlug& dst, const ConverterArgs& args)
{
MAYA_Type tmpDst;
USD_Type tmpSrc
= args._doGammaCorrection ? UsdMayaColorSpace::ConvertLinearToMaya(src) : src;
USD_Type tmpSrc = args._doGammaCorrection ? MayaUsd::utils::ConvertLinearToMaya(src) : src;
TypedConverter<MAYA_Type, USD_Type>::convert(tmpSrc, tmpDst);

MPlugUtils<MAYA_Type>::set(dst, tmpDst);
Expand All @@ -722,15 +720,14 @@ template <class MAYA_Type, class USD_Type, NeedsGammaCorrection ColorCorrection>
TypedConverter<MAYA_Type, USD_Type>::convert(tmpSrc, dst);

if (args._doGammaCorrection)
dst = UsdMayaColorSpace::ConvertMayaToLinear(dst);
dst = MayaUsd::utils::ConvertMayaToLinear(dst);
}
template <NeedsGammaCorrection C = ColorCorrection>
static typename std::enable_if<C == NeedsGammaCorrection::kYes, void>::type
convert(const USD_Type& src, const MPlug& plug, MDGModifier& dst, const ConverterArgs& args)
{
MAYA_Type tmpDst;
USD_Type tmpSrc
= args._doGammaCorrection ? UsdMayaColorSpace::ConvertLinearToMaya(src) : src;
USD_Type tmpSrc = args._doGammaCorrection ? MayaUsd::utils::ConvertLinearToMaya(src) : src;
TypedConverter<MAYA_Type, USD_Type>::convert(tmpSrc, tmpDst);

MDGModifierUtils<MAYA_Type>::set(plug, dst, tmpDst);
Expand Down
16 changes: 8 additions & 8 deletions lib/mayaUsd/utils/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ bool _GetColorAndTransparencyFromLambert(const MObject& shaderObj, GfVec3f* rgb,
displayColor[j] = color[j];
}
displayColor *= lambertFn.diffuseCoeff();
*rgb = UsdMayaColorSpace::ConvertMayaToLinear(displayColor);
*rgb = MayaUsd::utils::ConvertMayaToLinear(displayColor);
}
if (alpha) {
MColor trn = lambertFn.transparency();
Expand Down Expand Up @@ -815,7 +815,7 @@ bool _GetColorAndTransparencyFromStandardSurface(
displayColor[j] = color[j];
}
displayColor *= surfaceFn.base();
*rgb = UsdMayaColorSpace::ConvertMayaToLinear(displayColor);
*rgb = MayaUsd::utils::ConvertMayaToLinear(displayColor);
}
if (alpha) {
*alpha = 1.0f - surfaceFn.transmission();
Expand Down Expand Up @@ -843,7 +843,7 @@ bool _GetColorAndTransparencyFromDepNode(const MObject& shaderObj, GfVec3f* rgb,
for (int j = 0; j < 3; j++) {
colorPlug.child(j).getValue(displayColor[j]);
}
*rgb = UsdMayaColorSpace::ConvertMayaToLinear(displayColor);
*rgb = MayaUsd::utils::ConvertMayaToLinear(displayColor);
}

if (alpha) {
Expand Down Expand Up @@ -1311,7 +1311,7 @@ template <typename T> static T _GetVec(const UsdAttribute& attr, const VtValue&
const T ret = val.UncheckedGet<T>();

if (attr.GetRoleName() == SdfValueRoleNames->Color) {
return UsdMayaColorSpace::ConvertMayaToLinear(ret);
return MayaUsd::utils::ConvertMayaToLinear(ret);
}

return ret;
Expand Down Expand Up @@ -1585,7 +1585,7 @@ bool UsdMayaUtil::setPlugValue(const UsdAttribute& usdAttr, const UsdTimeCode ti
for (size_t i = 0u; i < valArray.size(); ++i) {
GfVec3d vecVal = valArray[i];
if (usdAttr.GetRoleName() == SdfValueRoleNames->Color) {
vecVal = UsdMayaColorSpace::ConvertMayaToLinear(vecVal);
vecVal = MayaUsd::utils::ConvertMayaToLinear(vecVal);
}
MPlug elemPlug = attrPlug.elementByPhysicalIndex(static_cast<unsigned int>(i), &status);
CHECK_MSTATUS_AND_RETURN(status, false);
Expand All @@ -1603,7 +1603,7 @@ bool UsdMayaUtil::setPlugValue(const UsdAttribute& usdAttr, const UsdTimeCode ti
for (size_t i = 0u; i < valArray.size(); ++i) {
GfVec3f vecVal = valArray[i];
if (usdAttr.GetRoleName() == SdfValueRoleNames->Color) {
vecVal = UsdMayaColorSpace::ConvertMayaToLinear(vecVal);
vecVal = MayaUsd::utils::ConvertMayaToLinear(vecVal);
}
MPlug elemPlug = attrPlug.elementByPhysicalIndex(static_cast<unsigned int>(i), &status);
CHECK_MSTATUS_AND_RETURN(status, false);
Expand All @@ -1621,7 +1621,7 @@ bool UsdMayaUtil::setPlugValue(const UsdAttribute& usdAttr, const UsdTimeCode ti
for (size_t i = 0u; i < valArray.size(); ++i) {
GfVec4d vecVal = valArray[i];
if (usdAttr.GetRoleName() == SdfValueRoleNames->Color) {
vecVal = UsdMayaColorSpace::ConvertMayaToLinear(vecVal);
vecVal = MayaUsd::utils::ConvertMayaToLinear(vecVal);
}
MPlug elemPlug = attrPlug.elementByPhysicalIndex(static_cast<unsigned int>(i), &status);
CHECK_MSTATUS_AND_RETURN(status, false);
Expand All @@ -1639,7 +1639,7 @@ bool UsdMayaUtil::setPlugValue(const UsdAttribute& usdAttr, const UsdTimeCode ti
for (size_t i = 0u; i < valArray.size(); ++i) {
GfVec4f vecVal = valArray[i];
if (usdAttr.GetRoleName() == SdfValueRoleNames->Color) {
vecVal = UsdMayaColorSpace::ConvertMayaToLinear(vecVal);
vecVal = MayaUsd::utils::ConvertMayaToLinear(vecVal);
}
MPlug elemPlug = attrPlug.elementByPhysicalIndex(static_cast<unsigned int>(i), &status);
CHECK_MSTATUS_AND_RETURN(status, false);
Expand Down