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

extract RenderMan for Maya shading export from "pxrRis" shadingMode for use with "useRegistry" #787

Merged
Merged
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ option(BUILD_ADSK_PLUGIN "Build Autodesk USD plugin." ON)
option(BUILD_PXR_PLUGIN "Build the Pixar USD plugin and libraries." ON)
option(BUILD_AL_PLUGIN "Build the Animal Logic USD plugin and libraries." ON)
option(BUILD_HDMAYA "Build the Maya-To-Hydra plugin and scene delegate." ON)
option(BUILD_RFM_TRANSLATORS "Build translators for RenderMan for Maya shaders." ON)
option(BUILD_TESTS "Build tests." ON)
option(BUILD_STRICT_MODE "Enforce all warnings as errors." ON)
option(BUILD_SHARED_LIBS "Build libraries as shared or static." ON)
Expand Down
1 change: 1 addition & 0 deletions doc/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ BUILD_ADSK_PLUGIN | builds Autodesk USD plugin.
BUILD_PXR_PLUGIN | builds the Pixar USD plugin and libraries. | ON
BUILD_AL_PLUGIN | builds the Animal Logic USD plugin and libraries. | ON
BUILD_HDMAYA | builds the Maya-To-Hydra plugin and scene delegate. | ON
BUILD_RFM_TRANSLATORS | builds translators for RenderMan for Maya shaders. | ON
BUILD_TESTS | builds all unit tests. | ON
BUILD_STRICT_MODE | enforces all warnings as errors. | ON
BUILD_WITH_PYTHON_3 | build with python 3. | OFF
Expand Down
1 change: 1 addition & 0 deletions lib/mayaUsd/fileio/shading/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ target_sources(${PROJECT_NAME}
)

set(HEADERS
rfmShaderMap.h
shadingModeExporter.h
shadingModeExporterContext.h
shadingModeImporter.h
Expand Down
223 changes: 223 additions & 0 deletions lib/mayaUsd/fileio/shading/rfmShaderMap.h

Large diffs are not rendered by default.

24 changes: 0 additions & 24 deletions lib/mayaUsd/fileio/shading/shadingModeExporterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,29 +511,5 @@ UsdMayaShadingModeExportContext::MakeStandardMaterialPrim(
return UsdPrim();
}

std::string
UsdMayaShadingModeExportContext::GetStandardAttrName(
const MPlug& plug,
const bool allowMultiElementArrays) const
{
if (plug.isElement()) {
MString mayaPlgName = plug.array().partialName(false, false, false, false, false, true);
unsigned int logicalIdx = plug.logicalIndex();
if (allowMultiElementArrays) {
return TfStringPrintf("%s_%d", mayaPlgName.asChar(), logicalIdx);
}
else if (logicalIdx == 0) {
return mayaPlgName.asChar();
}
else {
return TfToken();
}
}
else {
MString mayaPlgName = plug.partialName(false, false, false, false, false, true);
return mayaPlgName.asChar();
}
}


PXR_NAMESPACE_CLOSE_SCOPE
14 changes: 0 additions & 14 deletions lib/mayaUsd/fileio/shading/shadingModeExporterContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,6 @@ class UsdMayaShadingModeExportContext
const std::string& name=std::string(),
SdfPathSet* const boundPrimPaths=nullptr) const;

/// Use this function to get a "standard" usd attr name for \p attrPlug.
/// The definition of "standard" may depend on arguments passed to the
/// script (i.e. stripping namespaces, etc.).
///
/// If attrPlug is an element in an array and if \p allowMultiElementArrays
/// is true, this will <attrName>_<idx>.
///
/// If it's false, this will return <attrName> if it's the 0-th logical
/// element and an empty token otherwise.
MAYAUSD_CORE_PUBLIC
std::string GetStandardAttrName(
const MPlug& attrPlug,
const bool allowMultiElementArrays) const;

MAYAUSD_CORE_PUBLIC
UsdMayaShadingModeExportContext(
const MObject& shadingEngine,
Expand Down
13 changes: 6 additions & 7 deletions lib/mayaUsd/fileio/shading/shadingModePxrRis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
// limitations under the License.
//

// Defines the RenderMan for Maya mapping between Pxr objects and Maya internal nodes
#include "shadingModePxrRis_rfm_map.h"

#include <mayaUsd/fileio/shading/rfmShaderMap.h>
#include <mayaUsd/fileio/shading/shadingModeExporter.h>
#include <mayaUsd/fileio/shading/shadingModeExporterContext.h>
#include <mayaUsd/fileio/shading/shadingModeImporter.h>
#include <mayaUsd/fileio/shading/shadingModeRegistry.h>
#include <mayaUsd/fileio/translators/translatorUtil.h>
#include <mayaUsd/fileio/utils/roundTripUtil.h>
#include <mayaUsd/fileio/utils/shadingUtil.h>
#include <mayaUsd/fileio/utils/writeUtil.h>
#include <mayaUsd/utils/converter.h>
#include <mayaUsd/utils/util.h>
Expand Down Expand Up @@ -125,7 +124,7 @@ class PxrRisShadingModeExporter : public UsdMayaShadingModeExporter {

// Now look into the RIS TABLE if the typeName doesn't starts with Pxr.
if (!TfStringStartsWith(mayaTypeName, _tokens->PxrShaderPrefix)) {
for (const auto& i : _RFM_RISNODE_TABLE) {
for (const auto& i : RfmNodesToShaderIds) {
if (i.first == mayaTypeName) {
return i.second;
}
Expand Down Expand Up @@ -225,7 +224,7 @@ class PxrRisShadingModeExporter : public UsdMayaShadingModeExporter {
// maybe that's OK? nothing downstream cares about it.

const TfToken attrName = TfToken(
context.GetStandardAttrName(attrPlug, false));
UsdMayaShadingUtil::GetStandardAttrName(attrPlug, false));
if (attrName.IsEmpty()) {
continue;
}
Expand Down Expand Up @@ -270,7 +269,7 @@ class PxrRisShadingModeExporter : public UsdMayaShadingModeExporter {
UsdShadeConnectableAPI::ConnectToSource(
input,
UsdShadeShader(cPrim),
TfToken(context.GetStandardAttrName(connectedPlug, false)));
TfToken(UsdMayaShadingUtil::GetStandardAttrName(connectedPlug, false)));
}
}

Expand Down Expand Up @@ -455,7 +454,7 @@ _GetMayaTypeNameForShaderId(
const TfToken& shaderId)
{
// Remap the mayaTypeName if found in the RIS table.
for (const auto & i : _RFM_RISNODE_TABLE) {
for (const auto & i : RfmNodesToShaderIds) {
if (i.second == shaderId) {
return i.first;
}
Expand Down
80 changes: 0 additions & 80 deletions lib/mayaUsd/fileio/shading/shadingModePxrRis_rfm_map.h

This file was deleted.

14 changes: 4 additions & 10 deletions lib/mayaUsd/fileio/shading/shadingModeUseRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ class UseRegistryShadingModeExporter : public UsdMayaShadingModeExporter
return nullptr;
}

if (depNode.hasFn(MFn::kDagNode)) {
// XXX: Skip DAG nodes for now, but we may eventually want/need
// to consider them.
return nullptr;
}

if (!UsdMayaUtil::isWritable(depNode)) {
return nullptr;
}
Expand Down Expand Up @@ -266,14 +260,14 @@ class UseRegistryShadingModeExporter : public UsdMayaShadingModeExporter
// Maya plugs represent so that we can author the
// connection in USD.

const TfToken srcPlugName =
TfToken(context.GetStandardAttrName(srcPlug, false));
const TfToken srcPlugName = TfToken(
UsdMayaShadingUtil::GetStandardAttrName(srcPlug, false));
UsdAttribute srcAttribute =
srcShaderInfo->GetShadingAttributeForMayaAttrName(
srcPlugName);

const TfToken dstPlugName =
TfToken(context.GetStandardAttrName(dstPlug, false));
const TfToken dstPlugName = TfToken(
UsdMayaShadingUtil::GetStandardAttrName(dstPlug, false));
UsdAttribute dstAttribute =
dstShaderInfo->GetShadingAttributeForMayaAttrName(
dstPlugName);
Expand Down
32 changes: 32 additions & 0 deletions lib/mayaUsd/fileio/utils/shadingUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,47 @@
#include "shadingUtil.h"

#include <pxr/pxr.h>
#include <pxr/base/tf/stringUtils.h>
#include <pxr/base/tf/token.h>
#include <pxr/usd/sdf/valueTypeName.h>
#include <pxr/usd/usdShade/input.h>
#include <pxr/usd/usdShade/material.h>
#include <pxr/usd/usdShade/output.h>
#include <pxr/usd/usdShade/shader.h>

#include <maya/MPlug.h>
#include <maya/MString.h>

#include <string>


PXR_NAMESPACE_USING_DIRECTIVE


std::string
UsdMayaShadingUtil::GetStandardAttrName(
const MPlug& attrPlug,
bool allowMultiElementArrays)
{
if (!attrPlug.isElement()) {
const MString mayaPlugName =
attrPlug.partialName(false, false, false, false, false, true);
return mayaPlugName.asChar();
}

const MString mayaPlugName =
attrPlug.array().partialName(false, false, false, false, false, true);
const unsigned int logicalIndex = attrPlug.logicalIndex();

if (allowMultiElementArrays) {
return TfStringPrintf("%s_%d", mayaPlugName.asChar(), logicalIndex);
} else if (logicalIndex == 0) {
return mayaPlugName.asChar();
}

return std::string();
}

UsdShadeInput
UsdMayaShadingUtil::CreateMaterialInputAndConnectShader(
UsdShadeMaterial& material,
Expand Down
24 changes: 23 additions & 1 deletion lib/mayaUsd/fileio/utils/shadingUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#ifndef PXRUSDMAYA_SHADING_UTIL_H
#define PXRUSDMAYA_SHADING_UTIL_H

/// \file

#include <mayaUsd/base/api.h>

#include <pxr/pxr.h>
#include <pxr/base/tf/token.h>
#include <pxr/usd/sdf/valueTypeName.h>
Expand All @@ -24,12 +28,30 @@
#include <pxr/usd/usdShade/output.h>
#include <pxr/usd/usdShade/shader.h>

#include <mayaUsd/base/api.h>
#include <maya/MPlug.h>

#include <string>


PXR_NAMESPACE_OPEN_SCOPE


namespace UsdMayaShadingUtil
{
/// Get a "standard" USD attribute name for \p attrPlug.
///
/// If \p attrPlug is not an element in a Maya array attribute, then its name
/// is simply returned.
///
/// If \p attrPlug is an element in an array and if \p allowMultiElementArrays
/// is true, this will return a name of the form "<attrName>_<index>". If
/// \p allowMultiElementArrays is false, this will return <attrName> if it's
/// the 0-th logical element. Otherwise it will return an empty string.
MAYAUSD_CORE_PUBLIC
std::string GetStandardAttrName(
const MPlug& attrPlug,
bool allowMultiElementArrays);

/// Create an input on the given material and shader and create a connection
/// between them.
///
Expand Down
12 changes: 10 additions & 2 deletions lib/usd/translators/shading/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -----------------------------------------------------------------------------
# sources
# -----------------------------------------------------------------------------
target_sources(${TARGET_NAME}
target_sources(${TARGET_NAME}
PRIVATE
symmetricShaderWriter.cpp
usdBlinnReader.cpp
usdBlinnWriter.cpp
usdFileTextureWriter.cpp
Expand All @@ -18,8 +19,15 @@ target_sources(${TARGET_NAME}
usdUVTextureReader.cpp
)

if (BUILD_RFM_TRANSLATORS)
target_sources(${TARGET_NAME}
PRIVATE
rfmShaderTranslation.cpp
)
endif()

if (MAYA_APP_VERSION VERSION_GREATER_EQUAL 2020)
target_sources(${TARGET_NAME}
target_sources(${TARGET_NAME}
PRIVATE
usdStandardSurfaceReader.cpp
usdStandardSurfaceWriter.cpp
Expand Down
Loading