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-106222 Rename pxrUsdPreviewSurface to usdPreviewSurface #744

Merged
merged 6 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion lib/usd/hdMaya/adapters/materialAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ class HdMayaShadingEngineAdapter : public HdMayaMaterialAdapter {
}

bool IsTranslucent() {
if (_surfaceShaderType == HdMayaAdapterTokens->pxrUsdPreviewSurface) {
if (_surfaceShaderType == HdMayaAdapterTokens->UsdPreviewSurface ||
_surfaceShaderType == HdMayaAdapterTokens->pxrUsdPreviewSurface) {
MFnDependencyNode node(_surfaceShader);
const auto plug =
node.findPlug(HdMayaAdapterTokens->opacity.GetText(), true);
Expand Down
2 changes: 2 additions & 0 deletions lib/usd/hdMaya/adapters/materialNetworkConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ void HdMayaMaterialNetworkConverter::initialize() {
defaultTextureMemoryLimit);

_nodeConverters = {
{HdMayaAdapterTokens->UsdPreviewSurface,
{UsdImagingTokens->UsdPreviewSurface, {}}},
{HdMayaAdapterTokens->pxrUsdPreviewSurface,
{UsdImagingTokens->UsdPreviewSurface, {}}},
{HdMayaAdapterTokens->lambert,
Expand Down
1 change: 1 addition & 0 deletions lib/usd/hdMaya/adapters/tokens.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ PXR_NAMESPACE_OPEN_SCOPE
(varname) \
(result) \
(eccentricity) \
(UsdPreviewSurface) \
(pxrUsdPreviewSurface)
// clang-format on

Expand Down
5 changes: 0 additions & 5 deletions lib/usd/pxrUsdPreviewSurface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,3 @@ if(IS_WINDOWS)
DESTINATION ${LIBRARY_INSTALL_PATH} OPTIONAL
)
endif()

install(
FILES AEpxrUsdPreviewSurfaceTemplate.mel
DESTINATION plugin/adsk/scripts
)
2 changes: 1 addition & 1 deletion lib/usd/pxrUsdPreviewSurface/overview.dox
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Overview

This plugin contains a "pxrUsdPreviewSurface" Maya shader node that provides
This plugin contains a "UsdPreviewSurface" Maya shader node that provides
JGamache-autodesk marked this conversation as resolved.
Show resolved Hide resolved
the Maya-side equivalent of the UsdPreviewSurface shader in USD. The Maya
shader has all of the same attributes as UsdPreviewSurface, and in fact uses
much of the same code.
Expand Down
4 changes: 2 additions & 2 deletions lib/usd/pxrUsdPreviewSurface/plugInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"Info": {
"UsdMaya": {
"PrimWriter": {
"mayaPlugin": "pxrUsdPreviewSurface",
"mayaPlugin": "mayaUsdPlugin",
JGamache-autodesk marked this conversation as resolved.
Show resolved Hide resolved
"providesTranslator": [
"pxrUsdPreviewSurface"
"UsdPreviewSurface"
JGamache-autodesk marked this conversation as resolved.
Show resolved Hide resolved
]
}
}
Expand Down
70 changes: 29 additions & 41 deletions lib/usd/pxrUsdPreviewSurface/usdPreviewSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <maya/MDataBlock.h>
#include <maya/MDataHandle.h>
#include <maya/MFloatVector.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnNumericData.h>
#include <maya/MGlobal.h>
Expand All @@ -42,40 +43,6 @@ TF_DEFINE_PUBLIC_TOKENS(
PxrMayaUsdPreviewSurfaceTokens,
PXRUSDPREVIEWSURFACE_USD_PREVIEW_SURFACE_TOKENS);


const MTypeId PxrMayaUsdPreviewSurface::typeId(0x00126403);
const MString PxrMayaUsdPreviewSurface::typeName(
PxrMayaUsdPreviewSurfaceTokens->MayaTypeName.GetText());

const MString PxrMayaUsdPreviewSurface::drawDbClassification(
TfStringPrintf(
"drawdb/shader/surface/%s",
PxrMayaUsdPreviewSurfaceTokens->MayaTypeName.GetText()).c_str());
const MString PxrMayaUsdPreviewSurface::fullClassification(
TfStringPrintf(
"shader/surface:shader/displacement:%s",
PxrMayaUsdPreviewSurface::drawDbClassification.asChar()).c_str());

// Attributes
MObject PxrMayaUsdPreviewSurface::clearcoatAttr;
MObject PxrMayaUsdPreviewSurface::clearcoatRoughnessAttr;
MObject PxrMayaUsdPreviewSurface::diffuseColorAttr;
MObject PxrMayaUsdPreviewSurface::displacementAttr;
MObject PxrMayaUsdPreviewSurface::emissiveColorAttr;
MObject PxrMayaUsdPreviewSurface::iorAttr;
MObject PxrMayaUsdPreviewSurface::metallicAttr;
MObject PxrMayaUsdPreviewSurface::normalAttr;
MObject PxrMayaUsdPreviewSurface::occlusionAttr;
MObject PxrMayaUsdPreviewSurface::opacityAttr;
MObject PxrMayaUsdPreviewSurface::roughnessAttr;
MObject PxrMayaUsdPreviewSurface::specularColorAttr;
MObject PxrMayaUsdPreviewSurface::useSpecularWorkflowAttr;

// Output Attributes
MObject PxrMayaUsdPreviewSurface::outColorAttr;
MObject PxrMayaUsdPreviewSurface::outTransparencyAttr;


/* static */
void*
PxrMayaUsdPreviewSurface::creator()
Expand All @@ -89,6 +56,22 @@ PxrMayaUsdPreviewSurface::initialize()
{
MStatus status;

MObject clearcoatAttr;
MObject clearcoatRoughnessAttr;
MObject diffuseColorAttr;
MObject displacementAttr;
MObject emissiveColorAttr;
MObject iorAttr;
MObject metallicAttr;
MObject normalAttr;
MObject occlusionAttr;
MObject opacityAttr;
MObject roughnessAttr;
MObject specularColorAttr;
MObject useSpecularWorkflowAttr;
MObject outColorAttr;
MObject outTransparencyAttr;

MFnNumericAttribute numericAttrFn;

clearcoatAttr = numericAttrFn.create(
Expand Down Expand Up @@ -388,10 +371,15 @@ PxrMayaUsdPreviewSurface::compute(const MPlug& plug, MDataBlock& dataBlock)

// XXX: For now, we simply propagate diffuseColor to outColor and
// opacity to outTransparency.

MFnDependencyNode depNodeFn(thisMObject());
MObject outColorAttr
= depNodeFn.attribute(PxrMayaUsdPreviewSurfaceTokens->OutColorAttrName.GetText());
MObject outTransparencyAttr
= depNodeFn.attribute(PxrMayaUsdPreviewSurfaceTokens->OutTransparencyAttrName.GetText());
JGamache-autodesk marked this conversation as resolved.
Show resolved Hide resolved
if (plug == outColorAttr) {
const MDataHandle diffuseColorData =
dataBlock.inputValue(diffuseColorAttr, &status);
MObject diffuseColorAttr
= depNodeFn.attribute(PxrMayaUsdPreviewSurfaceTokens->DiffuseColorAttrName.GetText());
const MDataHandle diffuseColorData = dataBlock.inputValue(diffuseColorAttr, &status);
CHECK_MSTATUS(status);
const MFloatVector diffuseColor = diffuseColorData.asFloatVector();

Expand All @@ -401,10 +389,10 @@ PxrMayaUsdPreviewSurface::compute(const MPlug& plug, MDataBlock& dataBlock)
outColorHandle.asFloatVector() = diffuseColor;
status = dataBlock.setClean(outColorAttr);
CHECK_MSTATUS(status);
}
else if (plug == outTransparencyAttr) {
const MDataHandle opacityData =
dataBlock.inputValue(opacityAttr, &status);
} else if (plug == outTransparencyAttr) {
MObject opacityAttr
= depNodeFn.attribute(PxrMayaUsdPreviewSurfaceTokens->OpacityAttrName.GetText());
const MDataHandle opacityData = dataBlock.inputValue(opacityAttr, &status);
CHECK_MSTATUS(status);
const float opacity = opacityData.asFloat();

Expand Down
45 changes: 0 additions & 45 deletions lib/usd/pxrUsdPreviewSurface/usdPreviewSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ PXR_NAMESPACE_OPEN_SCOPE


#define PXRUSDPREVIEWSURFACE_USD_PREVIEW_SURFACE_TOKENS \
((MayaTypeName, "pxrUsdPreviewSurface")) \
((ClearcoatAttrName, "clearcoat")) \
((ClearcoatRoughnessAttrName, "clearcoatRoughness")) \
((DiffuseColorAttrName, "diffuseColor")) \
Expand All @@ -63,50 +62,6 @@ TF_DECLARE_PUBLIC_TOKENS(
class PxrMayaUsdPreviewSurface : public MPxNode
{
public:
PXRUSDPREVIEWSURFACE_API
static const MTypeId typeId;
PXRUSDPREVIEWSURFACE_API
static const MString typeName;

PXRUSDPREVIEWSURFACE_API
static const MString drawDbClassification;
PXRUSDPREVIEWSURFACE_API
static const MString fullClassification;

// Attributes
PXRUSDPREVIEWSURFACE_API
static MObject clearcoatAttr;
PXRUSDPREVIEWSURFACE_API
static MObject clearcoatRoughnessAttr;
PXRUSDPREVIEWSURFACE_API
static MObject diffuseColorAttr;
PXRUSDPREVIEWSURFACE_API
static MObject displacementAttr;
PXRUSDPREVIEWSURFACE_API
static MObject emissiveColorAttr;
PXRUSDPREVIEWSURFACE_API
static MObject iorAttr;
PXRUSDPREVIEWSURFACE_API
static MObject metallicAttr;
PXRUSDPREVIEWSURFACE_API
static MObject normalAttr;
PXRUSDPREVIEWSURFACE_API
static MObject occlusionAttr;
PXRUSDPREVIEWSURFACE_API
static MObject opacityAttr;
PXRUSDPREVIEWSURFACE_API
static MObject roughnessAttr;
PXRUSDPREVIEWSURFACE_API
static MObject specularColorAttr;
PXRUSDPREVIEWSURFACE_API
static MObject useSpecularWorkflowAttr;

// Output Attributes.
PXRUSDPREVIEWSURFACE_API
static MObject outColorAttr;
PXRUSDPREVIEWSURFACE_API
static MObject outTransparencyAttr;

PXRUSDPREVIEWSURFACE_API
static void* creator();

Expand Down
83 changes: 39 additions & 44 deletions lib/usd/pxrUsdPreviewSurface/usdPreviewSurfacePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,78 +26,73 @@
#include <maya/MDrawRegistry.h>

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

PXR_NAMESPACE_USING_DIRECTIVE
PXR_NAMESPACE_OPEN_SCOPE

namespace {
const MString _RegistrantId("mayaUsd");
int _registrationCount = 0;

// Name of the plugin registering the preview surface class.
MString _registrantPluginName;

TfToken::Set _registeredTypeNames;
}

PXR_NAMESPACE_OPEN_SCOPE

/* static */
MStatus
PxrMayaUsdPreviewSurfacePlugin::initialize(MFnPlugin& plugin)
MStatus PxrMayaUsdPreviewSurfacePlugin::initialize(
MFnPlugin& plugin,
const MString& typeName,
MTypeId typeId,
const MString& registrantId)
{
// If we're already registered, do nothing.
if (_registrationCount++ > 0) {
return MS::kSuccess;
TfToken tfTypeName(typeName.asChar());
JGamache-autodesk marked this conversation as resolved.
Show resolved Hide resolved
if (_registeredTypeNames.count(tfTypeName) > 0) {
TF_CODING_ERROR("Trying to register typeName %s more than once", tfTypeName.GetText());
return MStatus::kFailure;
}
_registeredTypeNames.insert(tfTypeName);

_registrantPluginName = plugin.name();
MString drawDbClassification(
TfStringPrintf("drawdb/shader/surface/%s", typeName.asChar()).c_str());
MString fullClassification(
TfStringPrintf("shader/surface:shader/displacement:%s", drawDbClassification.asChar())
.c_str());

MStatus status = plugin.registerNode(
PxrMayaUsdPreviewSurface::typeName,
PxrMayaUsdPreviewSurface::typeId,
typeName,
typeId,
PxrMayaUsdPreviewSurface::creator,
PxrMayaUsdPreviewSurface::initialize,
MPxNode::kDependNode,
&PxrMayaUsdPreviewSurface::fullClassification);
&fullClassification);
CHECK_MSTATUS(status);

status =
MHWRender::MDrawRegistry::registerSurfaceShadingNodeOverrideCreator(
PxrMayaUsdPreviewSurface::drawDbClassification,
_RegistrantId,
PxrMayaUsdPreviewSurfaceShadingNodeOverride::creator);
status = MHWRender::MDrawRegistry::registerSurfaceShadingNodeOverrideCreator(
drawDbClassification, registrantId, PxrMayaUsdPreviewSurfaceShadingNodeOverride::creator);
CHECK_MSTATUS(status);

return status;
}

/* static */
MStatus
PxrMayaUsdPreviewSurfacePlugin::finalize(MFnPlugin& plugin)
MStatus PxrMayaUsdPreviewSurfacePlugin::finalize(
MFnPlugin& plugin,
const MString& typeName,
MTypeId typeId,
const MString& registrantId)
{
// If more than one plugin still has us registered, do nothing.
if (_registrationCount == 0 || _registrationCount-- > 1) {
return MS::kSuccess;
TfToken tfTypeName(typeName.asChar());
if (_registeredTypeNames.count(tfTypeName) == 0) {
TF_CODING_ERROR("TypeName %s is not currently registered", tfTypeName.GetText());
return MStatus::kFailure;
}
_registeredTypeNames.erase(tfTypeName);

deregisterFragments();
MString drawDbClassification(
TfStringPrintf("drawdb/shader/surface/%s", typeName.asChar()).c_str());

// Maya requires deregistration to be done by the same plugin that
// performed the registration. If this isn't possible, warn and don't
// deregister.
if (plugin.name() != _registrantPluginName) {
MGlobal::displayWarning(
"USD preview surface base cannot be deregistered, registering plugin "
+ _registrantPluginName + " is unloaded.");
return MS::kSuccess;
}
deregisterFragments();

MStatus status =
MHWRender::MDrawRegistry::deregisterSurfaceShadingNodeOverrideCreator(
PxrMayaUsdPreviewSurface::drawDbClassification,
_RegistrantId);
MStatus status = MHWRender::MDrawRegistry::deregisterSurfaceShadingNodeOverrideCreator(
drawDbClassification, registrantId);
CHECK_MSTATUS(status);

status = plugin.deregisterNode(PxrMayaUsdPreviewSurface::typeId);
status = plugin.deregisterNode(typeId);
CHECK_MSTATUS(status);

return status;
Expand Down
33 changes: 15 additions & 18 deletions lib/usd/pxrUsdPreviewSurface/usdPreviewSurfacePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,32 @@

#include "api.h"

#include <maya/MApiNamespace.h>

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

#include <maya/MApiNamespace.h>

PXR_NAMESPACE_OPEN_SCOPE

/// \class PxrMayaUsdPreviewSurfacePlugin
/// \brief Encapsulates plugin registration and deregistration of preview surface classes.
///
/// Preview surface support requires plugin registration of node classes, node
/// data, and draw support. This class provides this service, including if
/// multiple plugins that use preveiw surface are loaded: using reference
/// counting, only the first registration and the last deregistration will
/// be performed. Note that because of Maya architecture requirements,
/// deregistration will only be done if the deregistering plugin is the same as
/// the registering plugin. Otherwise, a warning is shown.

class PxrMayaUsdPreviewSurfacePlugin
{
public:
PXRUSDPREVIEWSURFACE_API
static MStatus initialize(MFnPlugin&);
/// data, and draw support. This class provides this service. Each client is expected
/// to provide a separate typeName and typeId to ensure proper plugin registration.
class PxrMayaUsdPreviewSurfacePlugin {
public:
PXRUSDPREVIEWSURFACE_API
static MStatus initialize(MFnPlugin&, const MString&, MTypeId, const MString&);

PXRUSDPREVIEWSURFACE_API
static MStatus finalize(MFnPlugin&);
PXRUSDPREVIEWSURFACE_API
static MStatus finalize(MFnPlugin&, const MString&, MTypeId, const MString&);
JGamache-autodesk marked this conversation as resolved.
Show resolved Hide resolved

static MStatus registerFragments();
PXRUSDPREVIEWSURFACE_API
static MStatus registerFragments();

static MStatus deregisterFragments();
PXRUSDPREVIEWSURFACE_API
static MStatus deregisterFragments();
};

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down
Loading