-
Notifications
You must be signed in to change notification settings - Fork 203
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-114979 MAYA-114731 Fix correctness issues #1937
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,8 @@ class MtlxUsd_FileWriter : public MtlxUsd_BaseWriter | |
const SdfValueTypeName& typeName) override; | ||
|
||
private: | ||
SdfPath _GetPlace2DTexturePath(const MFnDependencyNode& depNodeFn); | ||
|
||
int _numChannels = 4; | ||
}; | ||
|
||
|
@@ -80,8 +82,8 @@ PXRUSDMAYA_REGISTER_SHADER_WRITER(file, MtlxUsd_FileWriter); | |
TF_DEFINE_PRIVATE_TOKENS( | ||
_tokens, | ||
|
||
// Prefix for helper nodes: | ||
((PrimvarReaderPrefix, "MayaGeomPropValue")) | ||
// Shared primvar writer (when no place2dTexture found): | ||
((PrimvarReaderShaderName, "shared_MayaGeomPropValue")) | ||
); | ||
// clang-format on | ||
|
||
|
@@ -148,45 +150,67 @@ MtlxUsd_FileWriter::MtlxUsd_FileWriter( | |
} | ||
|
||
// Now create a geompropvalue reader that the image shader will use. | ||
TfToken primvarReaderName( | ||
TfStringPrintf("%s_%s", _tokens->PrimvarReaderPrefix.GetText(), depNodeFn.name().asChar())); | ||
const SdfPath primvarReaderPath = nodegraphPath.AppendChild(primvarReaderName); | ||
UsdShadeShader primvarReaderSchema = UsdShadeShader::Define(GetUsdStage(), primvarReaderPath); | ||
|
||
primvarReaderSchema.CreateIdAttr(VtValue(TrMtlxTokens->ND_geompropvalue_vector2)); | ||
|
||
UsdShadeInput varnameInput | ||
= primvarReaderSchema.CreateInput(TrMtlxTokens->geomprop, SdfValueTypeNames->String); | ||
|
||
// We expose the primvar reader varname attribute to the material to allow | ||
// easy specialization based on UV mappings to geometries: | ||
SdfPath materialPath = GetUsdPath().GetParentPath(); | ||
UsdShadeMaterial materialSchema(GetUsdStage()->GetPrimAtPath(materialPath)); | ||
while (!materialSchema && !materialPath.IsEmpty()) { | ||
materialPath = materialPath.GetParentPath(); | ||
materialSchema = UsdShadeMaterial(GetUsdStage()->GetPrimAtPath(materialPath)); | ||
} | ||
SdfPath primvarReaderPath = _GetPlace2DTexturePath(depNodeFn); | ||
|
||
if (!GetUsdStage()->GetPrimAtPath(primvarReaderPath)) { | ||
UsdShadeShader primvarReaderSchema | ||
= UsdShadeShader::Define(GetUsdStage(), primvarReaderPath); | ||
primvarReaderSchema.CreateIdAttr(VtValue(TrMtlxTokens->ND_geompropvalue_vector2)); | ||
UsdShadeInput varnameInput | ||
= primvarReaderSchema.CreateInput(TrMtlxTokens->geomprop, SdfValueTypeNames->String); | ||
|
||
if (materialSchema) { | ||
TfToken inputName( | ||
TfStringPrintf("%s:%s", depNodeFn.name().asChar(), TrUsdTokens->varname.GetText())); | ||
UsdShadeInput materialInput | ||
= materialSchema.CreateInput(inputName, SdfValueTypeNames->String); | ||
materialInput.Set(UsdUtilsGetPrimaryUVSetName().GetString()); | ||
varnameInput.ConnectToSource(materialInput); | ||
} else { | ||
varnameInput.Set(UsdUtilsGetPrimaryUVSetName()); | ||
} | ||
TfStringPrintf("%s:%s", depNodeFn.name().asChar(), TrMtlxTokens->varnameStr.GetText())); | ||
|
||
// We expose the primvar reader varnameStr attribute to the material to allow | ||
// easy specialization based on UV mappings to geometries: | ||
UsdPrim materialPrim = primvarReaderSchema.GetPrim().GetParent(); | ||
UsdShadeMaterial materialSchema(materialPrim); | ||
while (!materialSchema && materialPrim) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we make sure to properly connect the NodeGraph. |
||
UsdShadeNodeGraph intermediateNodeGraph(materialPrim); | ||
if (intermediateNodeGraph) { | ||
UsdShadeInput intermediateInput | ||
= intermediateNodeGraph.CreateInput(inputName, SdfValueTypeNames->String); | ||
varnameInput.ConnectToSource(intermediateInput); | ||
varnameInput = intermediateInput; | ||
} | ||
|
||
UsdShadeOutput primvarReaderOutput | ||
= primvarReaderSchema.CreateOutput(TrMtlxTokens->out, SdfValueTypeNames->Float2); | ||
materialPrim = materialPrim.GetParent(); | ||
materialSchema = UsdShadeMaterial(materialPrim); | ||
} | ||
|
||
// TODO: Handle UV SRT with a ND_place2d_vector2 node. | ||
if (materialSchema) { | ||
UsdShadeInput materialInput | ||
= materialSchema.CreateInput(inputName, SdfValueTypeNames->String); | ||
materialInput.Set(UsdUtilsGetPrimaryUVSetName().GetString()); | ||
varnameInput.ConnectToSource(materialInput); | ||
} else { | ||
varnameInput.Set(UsdUtilsGetPrimaryUVSetName()); | ||
} | ||
|
||
UsdShadeOutput primvarReaderOutput | ||
= primvarReaderSchema.CreateOutput(TrMtlxTokens->out, SdfValueTypeNames->Float2); | ||
|
||
// TODO: Handle UV SRT with a ND_place2d_vector2 node. Make sure the name derives from the | ||
// place2dTexture node if there is one (see usdFileTextureWriter for details) | ||
|
||
// Connect the output of the primvar reader to the texture coordinate | ||
// input of the UV texture. | ||
texSchema.CreateInput(TrMtlxTokens->texcoord, SdfValueTypeNames->Float2) | ||
.ConnectToSource(primvarReaderOutput); | ||
} else { | ||
// Re-using an existing primvar reader: | ||
UsdShadeShader primvarReaderShaderSchema(GetUsdStage()->GetPrimAtPath(primvarReaderPath)); | ||
UsdShadeOutput primvarReaderOutput = primvarReaderShaderSchema.GetOutput(TrMtlxTokens->out); | ||
|
||
// Connect the output of the primvar reader to the texture coordinate | ||
// input of the UV texture. | ||
texSchema.CreateInput(TrMtlxTokens->texcoord, SdfValueTypeNames->Float2) | ||
.ConnectToSource(primvarReaderOutput); | ||
// TODO: Handle UV SRT with a ND_place2d_vector2 node. Make sure the name derives from the | ||
// place2dTexture node if there is one (see usdFileTextureWriter for details) | ||
|
||
// Connect the output of the primvar reader to the texture coordinate | ||
// input of the UV texture. | ||
texSchema.CreateInput(TrMtlxTokens->texcoord, SdfValueTypeNames->Float2) | ||
.ConnectToSource(primvarReaderOutput); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line 206-212 could be taken out of the if/else block instead of having a duplication of code. |
||
} | ||
} | ||
|
||
/* virtual */ | ||
|
@@ -422,4 +446,28 @@ UsdAttribute MtlxUsd_FileWriter::GetShadingAttributeForMayaAttrName( | |
return UsdAttribute(); | ||
} | ||
|
||
SdfPath MtlxUsd_FileWriter::_GetPlace2DTexturePath(const MFnDependencyNode& depNodeFn) | ||
{ | ||
MStatus status; | ||
std::string usdUvTextureName; | ||
const MPlug plug = depNodeFn.findPlug( | ||
TrMayaTokens->uvCoord.GetText(), | ||
/* wantNetworkedPlug = */ true, | ||
&status); | ||
if (status == MS::kSuccess && plug.isDestination(&status)) { | ||
MPlug source = plug.source(&status); | ||
if (status == MS::kSuccess && !source.isNull()) { | ||
MFnDependencyNode sourceNode(source.node()); | ||
usdUvTextureName = sourceNode.name().asChar(); | ||
} | ||
} | ||
|
||
if (usdUvTextureName.empty()) { | ||
// We want a single UV reader for all file nodes not connected to a place2DTexture node | ||
usdUvTextureName = _tokens->PrimvarReaderShaderName.GetString(); | ||
} | ||
|
||
return GetNodeGraph().GetPath().AppendChild(TfToken(usdUvTextureName.c_str())); | ||
} | ||
|
||
PXR_NAMESPACE_CLOSE_SCOPE |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,13 +88,7 @@ MtlxUsd_PreviewSurfaceWriter::MtlxUsd_PreviewSurfaceWriter( | |
|
||
shaderSchema.CreateIdAttr(VtValue(TrMtlxTokens->ND_UsdPreviewSurface_surfaceshader)); | ||
|
||
UsdShadeNodeGraph nodegraphSchema(GetNodeGraph()); | ||
if (!TF_VERIFY( | ||
nodegraphSchema, | ||
"Could not define UsdShadeNodeGraph at path '%s'\n", | ||
GetUsdPath().GetText())) { | ||
return; | ||
} | ||
UsdShadeNodeGraph nodegraphSchema; | ||
|
||
for (const TfToken& mayaAttrName : PxrMayaUsdPreviewSurfaceTokens->allTokens) { | ||
|
||
|
@@ -135,6 +129,15 @@ MtlxUsd_PreviewSurfaceWriter::MtlxUsd_PreviewSurfaceWriter( | |
|
||
// All connections go directly to the node graph: | ||
if (attrPlug.isConnected()) { | ||
if (!nodegraphSchema) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just-in-time creation to reduce number of empty NodeGraph generated. |
||
nodegraphSchema = UsdShadeNodeGraph(GetNodeGraph()); | ||
if (!TF_VERIFY( | ||
nodegraphSchema, | ||
"Could not define UsdShadeNodeGraph at path '%s'\n", | ||
GetUsdPath().GetText())) { | ||
return; | ||
} | ||
} | ||
UsdShadeOutput ngOutput = nodegraphSchema.CreateOutput(mayaAttrName, valueTypeName); | ||
input.ConnectToSource(ngOutput); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly indentation since we now detect shared place2dTexture nodes. Similar to what was done in usdFileTextureWriter.cpp in the first PR of the series.