-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Apple : UsdMtlx MaterialXConfigAPI schema and MaterialX versioning #3157
Apple : UsdMtlx MaterialXConfigAPI schema and MaterialX versioning #3157
Conversation
Filed as internal issue #USD-9835 ❗ Please make sure that a signed CLA has been submitted! |
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
pxr/usd/usdMtlx/materialXInfoAPI.h
Outdated
/// | C++ Type | std::string | | ||
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->String | | ||
USDMTLX_API | ||
UsdAttribute GetMtlxinfoVersionAttr() const; |
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.
Style question: should "info" and "x" be capitalized in the function @ld-kerley ? (i.e. GetMtlXInfoVersionAttr()
)
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.
Following other MaterialX use in USD I think it should be Mtlx
, so lower case x. But I think you're right about the Info
part - thanks - I'll make sure that gets changed next time I push something here.
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.
Cool that's great. Thank you for getting this PR up and going!
pxr/imaging/hdMtlx/hdMtlx.cpp
Outdated
@@ -562,6 +562,12 @@ HdMtlxCreateMtlxDocumentFromHdMaterialNetworkInterface( | |||
|
|||
// Initialize a MaterialX Document | |||
mx::DocumentPtr mxDoc = mx::createDocument(); | |||
|
|||
// Need to figure out how to read the actual value from the netInterface | |||
std::string materialXVersionString = "1.37"; |
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.
@ld-kerley , should this default value be 1.38 like the schema has? Or maybe it's just a temporary/filler value that doesn't matter?
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.
Yes - this is place holder - I'm hoping that someone with a bit more intimate hydra understanding can guide me as to the right way to get the real MaterialX version string from USD here.
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.
Thanks for putting this together! Left some thoughts on the rest, but for the question of how to get the version string through I think we need to discuss our options :). But we're thinking about it, and will get back to you with ideas!
// and its affiliates, except as required to comply with Section 4(c) of | ||
// the License and to reproduce the content of the NOTICE file. | ||
// | ||
// You may obtain a copy of the Apache License at |
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.
Note that we recently updated our license text, so you'll want to go with the top-of-tree license text. If you're running usdSchemaGen with an old USD version (< 24.08) that might put the wrong text in.
pxr/usd/usdMtlx/reader.cpp
Outdated
@@ -1458,9 +1460,14 @@ UsdShadeMaterial | |||
_Context::BeginMaterial(const mx::ConstNodePtr& mtlxMaterial) | |||
{ | |||
if (TF_VERIFY(!_usdMaterial)) { | |||
auto mtlxVersionValue = VtValue(mtlxMaterial->getDocument()->getVersionString()); |
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.
I'm guessing this will return one of "" and "1.39" at the moment? Do we want to handle the fallback case and put 1.38 in instead here? Or does the document function do that already?
pxr/imaging/hdMtlx/hdMtlx.cpp
Outdated
@@ -585,6 +591,23 @@ HdMtlxCreateMtlxDocumentFromHdMaterialNetworkInterface( | |||
mxType, | |||
mxShaderNode); | |||
|
|||
// just for testing... | |||
bool localDebug = false; |
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.
There's a system in hydra called debug codes that would be perfect here. The idea is that you create a local "debugCodes.h/.cpp", like the ones in imaging/hd (for example); add a new debug code, such as HDMTLX_VERSION_UPGRADE; and here, replace "localDebug" with TfDebug::IsEnabled(HDMTLX_VERSION_UPGRADE).
You can trigger this either with the debug codes editor in usdview, or by setting the environment variable "TF_DEBUG" to "HDMTLX_VERSION_UPGRADE".
Having this as a debug code seems like a fantastic idea!
pxr/imaging/hdMtlx/hdMtlx.cpp
Outdated
@@ -562,6 +562,12 @@ HdMtlxCreateMtlxDocumentFromHdMaterialNetworkInterface( | |||
|
|||
// Initialize a MaterialX Document | |||
mx::DocumentPtr mxDoc = mx::createDocument(); | |||
|
|||
// Need to figure out how to read the actual value from the netInterface |
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.
A thought that @spiffmon had:
1.) Rename the property info:mtlx:version or something (such that it starts with "info:").
2.) Update materialAdapter.cpp (a) and dataSourceMaterial.cpp (b) to grab all attributes with the "info:" namespace prefix, and insert them into a new VtDictionary "info" on HdMaterialNetwork (a)/a new HdContainerDataSource named "info" on the material data source (b).
3.) Update dataSourceLegacyPrim.cpp and sceneIndexAdapterSceneDelegate.cpp to translate from the VtDictionary to the ContainerDataSource and back.
4.) Finally grab the version string off the material network here.
How does that feel, design wise/difficulty wise?
fc7a0a7
to
51a693e
Compare
@tcauchois - I took a stab at what you suggested. I think it's functional, but likely there are style things that could be tidied up, but before going too far down that road I wanted to share where I'm at for feedback, and make sure this is along the right lines. |
@@ -379,6 +379,19 @@ UsdImagingMaterialAdapter::GetMaterialResource(UsdPrim const &prim, | |||
time); | |||
} | |||
|
|||
// finally collect any 'info' on the Material prim | |||
VtDictionary infoDict; |
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.
(1) Do we only want to include authored attributes, or are we expecting the fallback of "1.38" to ever be useful? This won't pull fallbacks, but GetAttributes would(). Maybe moot since usdMtlx/reader.cpp looks to be manually creating the attribute.
(2) We may want to use prim.GetPropertiesInNamespace("info") (or GetAuthoredPropertiesInNamespace) instead here? And then auto attr = prop.As(), which returns null if it's not an attribute (e.g. if it's a relationship). See also: https://github.com/PixarAnimationStudios/OpenUSD/blob/release/pxr/usd/usdGeom/primvarsAPI.cpp#L215.
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.
I can't see that it would hurt any.
pxr/imaging/hd/utils.cpp
Outdated
infoValues.reserve(hdNetworkMap.info.size()); | ||
for (const auto& infoEntry : hdNetworkMap.info) | ||
{ | ||
// from _dataSourceLegacyPrim.cpp - _ToContainerDS(VtDictionary) |
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.
Here & elsewhere, no need to update this but if it's annoying you I think we could add VtDictionary <-> ContainerDS translators somewhere accessible (maybe retainedDataSource.h?).
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.
There were other places in the code where these conversions were happening, but I couldn't see a clean way to share that code. I don't want to bite off more than I can chew here, so maybe I'll leave that for a later refacor - or if anyone wants to jump in and make that change, thats also fine.
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
Hi @ld-kerley , we've been discussing the latest changes, and realizing that since the new data we're adding will potentially affect the network that gets built, it will, for instanced materials, be "prototype-affecting" data, rather than "per-instance data". With that in mind, we were thinking that the term "Config" captures the "weight" of the data better than "Info", which kind of implies it's just advisory (admitting it's unfortunate "info" is what's used in Shader/NodeDefAPI, a legacy Pixar (or maybe Katana?) thing). Would you be willing to change the schema name to MaterialXConfigAPI and the new datasource member to config? |
I'm personally open to any naming, and can see why "Info" implies advisory. Is there precedent for "Config" elsewhere in USD? I'd like to raise this with the wider MaterialX/USD community and ensure the name change doesn't raise any flags for anyone else. If there's no existing precedent for "Config" then I might open the discussion for alternatives, but if the "Config" suggestion fits in to some already established USD nomenclature, we should certainly stick with that. |
There is "internal pixar" precedent in the Presto scenegraph that "config attributes" imply structural changes to a prim's definition; while we are continuing discussions on whether that mechanism will need to be reflected in OpenUSD, it's not a sure thing. So sure, please do verify with the wider group and let us know if there are alt sugs! |
Perhaps of note, |
That's correct, @nvmkuruc . In fact, we've stopped authoring it in Presto/menva, but don't disallow it, for old assets. And yes, it doesn't restrict uses in property names or namespaces. |
/AzurePipelines run |
Azure Pipelines successfully started running 1 pipeline(s). |
…n run the upgrade. Still need to figure out how to get to the materialX library version in the USD document.
Add 'info' VtDictionary and transport thru hydra.
8353f22
to
82b8f48
Compare
Description of Change(s)
Initial pass at adding MaterialXInfoAPI applied schema, and then using this in UsdMtlx file format reader to append the version to the UsdShadeMaterial prims created.
HdMtlx also updated to explicitly write the MaterialX version in to the document that is reconstructed.
Outstanding: I need some input on the best way to get to the MaterialX version attribute on the UsdShadeMaterial prim from inside HdMtlx. I've left a hardcoded version string in the code so far at the place I think I need it.
Fixes Issue(s)