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-106892 - Export and import color space information on file nodes #862

Merged
merged 2 commits into from
Oct 22, 2020
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
21 changes: 16 additions & 5 deletions lib/usd/translators/shading/usdFileTextureWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <pxr/usdImaging/usdImaging/tokens.h>

#include <maya/MFnDependencyNode.h>
#include <maya/MGlobal.h>
#include <maya/MObject.h>
#include <maya/MPlug.h>
#include <maya/MStatus.h>
Expand Down Expand Up @@ -72,6 +73,7 @@ TF_DEFINE_PRIVATE_TOKENS(
(alphaOffset)
(colorGain)
(colorOffset)
(colorSpace)
(defaultColor)
(fileTextureName)
(outAlpha)
Expand Down Expand Up @@ -233,11 +235,20 @@ PxrUsdTranslators_FileTextureWriter::Write(const UsdTimeCode& usdTime)
fileTextureName = relativePath.generic_string();
}

shaderSchema.CreateInput(
_tokens->file,
SdfValueTypeNames->Asset).Set(
SdfAssetPath(fileTextureName.c_str()),
usdTime);
UsdShadeInput fileInput = shaderSchema.CreateInput(_tokens->file, SdfValueTypeNames->Asset);
fileInput.Set(SdfAssetPath(fileTextureName.c_str()), usdTime);

MPlug colorSpacePlug = depNodeFn.findPlug(_tokens->colorSpace.GetText(), true, &status);
if (status == MS::kSuccess) {
MString colorRuleCmd;
colorRuleCmd.format(
"colorManagementFileRules -evaluate \"^1s\";", fileTextureNamePlug.asString());
const MString colorSpaceByRule(MGlobal::executeCommandStringResult(colorRuleCmd));
const MString colorSpace(colorSpacePlug.asString(&status));
if (status == MS::kSuccess && colorSpace != colorSpaceByRule) {
fileInput.GetAttr().SetColorSpace(TfToken(colorSpace.asChar()));
}
}

// The Maya file node's 'colorGain' and 'alphaGain' attributes map to the
// UsdUVTexture's scale input.
Expand Down
10 changes: 10 additions & 0 deletions lib/usd/translators/shading/usdUVTextureReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ TF_DEFINE_PRIVATE_TOKENS(
(alphaOffset)
(colorGain)
(colorOffset)
(colorSpace)
(defaultColor)
(fileTextureName)
(outAlpha)
Expand Down Expand Up @@ -190,6 +191,15 @@ bool PxrMayaUsdUVTexture_Reader::Read(UsdMayaPrimReaderContext* context)
if (status == MS::kSuccess) {
UsdMayaReadUtil::SetMayaAttr(mayaAttr, val);
}

// colorSpace:
if (usdInput.GetAttr().HasColorSpace()) {
MString colorSpace = usdInput.GetAttr().GetColorSpace().GetText();
mayaAttr = depFn.findPlug(_tokens->colorSpace.GetText(), true, &status);
if (status == MS::kSuccess) {
mayaAttr.setString(colorSpace);
}
}
}

// The Maya file node's 'colorGain' and 'alphaGain' attributes map to the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def testUsdPreviewSurfaceRoundtrip(self):
txfile = os.path.join("UsdExportImportRoundtripPreviewSurface",
"Brazilian_rosewood_pxr128.png")
cmds.setAttr(file_node+".fileTextureName", txfile, type="string")
cmds.setAttr(file_node+".colorSpace", "ACEScg", type="string")
cmds.setAttr(file_node + ".defaultColor", 0.5, 0.25, 0.125,
type="double3")

Expand Down Expand Up @@ -135,6 +136,7 @@ def testUsdPreviewSurfaceRoundtrip(self):
self.assertTrue(cmds.getAttr("usdPreviewSurface2.useSpecularWorkflow"))
self.assertEqual(cmds.getAttr("file2.defaultColor"),
[(0.5, 0.25, 0.125)])
self.assertEqual(cmds.getAttr(file_node+".colorSpace"), "ACEScg")
original_path = cmds.getAttr(file_node+".fileTextureName")
imported_path = cmds.getAttr("file2.fileTextureName")
# imported path will be absolute:
Expand Down