Skip to content

Fixes for MaterialX format checker#2647

Merged
jstone-lucasfilm merged 5 commits intoAcademySoftwareFoundation:mainfrom
kwokcb:mx_format_update
Nov 3, 2025
Merged

Fixes for MaterialX format checker#2647
jstone-lucasfilm merged 5 commits intoAcademySoftwareFoundation:mainfrom
kwokcb:mx_format_update

Conversation

@kwokcb
Copy link
Copy Markdown
Contributor

@kwokcb kwokcb commented Oct 28, 2025

Changes

The utility mx_format.py was not traversing to sub-folders so when applied to libraries it would miss some files.
This fixes some files which had invalid XML (unescaped characters) as PugiXML will "fix" this on write.

Two additional options have been added:

  • Check for XML syntax validity
  • MaterialX validation checking
    Both are off by default.

Results

  • Ran this again libraries folder. Changes are mostly cosmetic except for the mentioned fixes to missed files.
  • Ran this against resources folder. Found a file which had duplicate elements. Fixed manually.

- Add in XML syntax checking and validation as options.
  - Apply to libraries to fix some implementation files.
@kwokcb kwokcb mentioned this pull request Oct 28, 2025
Comment thread python/Scripts/mxformat.py
Comment thread python/Scripts/mxformat.py
<input name="specular_weight" type="float" value="1.0" uimin="0.0" uisoftmax="1.0" uiname="Specular Weight" uifolder="Specular"
doc="Multiplies the specular reflectivity." />
<input name="specular_color" type="color3" value="1, 1, 1" uimin="0,0,0" uimax="1,1,1" uiname="Specular Color" uifolder="Specular"
doc="Color of the specular reflection (controls the physical edge-tint for metals, and a non-physical overall tint for dielectrics)." />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be visually clearer to maintain our existing layout for shading model inputs, where the doc string is placed on its own line?

To my eye, the original formatting with the doc string on its own line seems clearer and more understandable, though it's true that our MaterialX format checker doesn't yet handle this automatically.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I don't find it any clearer with the new line break - as to me it hints that it is only the "doc" attribute on that line, but we can see in the example above that "uiName" comes after, which my eyes fail to parse because of the new line break.

Ultimately I don't have a super strong opinion here, other than I think the formatter tools rules should be the ultimate truth. If we want to enforce any formatting convention the it should be implemented in the formatting tool. I feel that any human post-editing of the files is potentially error prone, and burdensome.

If we are going to enforce "doc" on a new line - are we applying that everywhere? does it make sense everywhere? If we do can we also ensure it is the last attribute in the element?

I would cast a soft vote against making a new line, only because I worry there will be other corner cases where we don't want the additional lines.

For instance here - https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/libraries/stdlib/stdlib_defs.mtlx#L109

do we feel it would be beneficial to introduce new lines for each "doc" attribute, including the one in the "nodedef" element?

Copy link
Copy Markdown
Contributor Author

@kwokcb kwokcb Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though I believe one aim is make original XML as user readable for things like comments and doc strings this makes it so that non-standard "extra" XML rules keep on having to be introduced. Additionally this promotes hand-editing XML which from this PR can introduce unnoticed user errors.

My vote is thus to not introduce more special case handling which no other XML parser will ever handle. If we want formatted document strings then this should be introduced properly and no rely on newlines embedded into a text file.

Copy link
Copy Markdown
Contributor

@ld-kerley ld-kerley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a great change to me - anything we can do to improve our ability to keep formatting consistent across the project gets my vote.

Left a couple of small things that probably need to be fixed up locally below.

<input name="amount" type="float" nodename="tangent_rotate_degree_offset" />
<input name="axis" type="vector3" nodename="tangent_normal" /> />
<input name="axis" type="vector3" nodename="tangent_normal" />
<:anonymous name="1" />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a typo in the original source?

I'm a little surprised this passes validation - are we confident that the validator is processing all of the files too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. The std library generally get's loaded into docs and this get's validated. Strange it's never been caught. Can patch the original and log a new parsing issue.

<input name="specular_weight" type="float" value="1.0" uimin="0.0" uisoftmax="1.0" uiname="Specular Weight" uifolder="Specular"
doc="Multiplies the specular reflectivity." />
<input name="specular_color" type="color3" value="1, 1, 1" uimin="0,0,0" uimax="1,1,1" uiname="Specular Color" uifolder="Specular"
doc="Color of the specular reflection (controls the physical edge-tint for metals, and a non-physical overall tint for dielectrics)." />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I don't find it any clearer with the new line break - as to me it hints that it is only the "doc" attribute on that line, but we can see in the example above that "uiName" comes after, which my eyes fail to parse because of the new line break.

Ultimately I don't have a super strong opinion here, other than I think the formatter tools rules should be the ultimate truth. If we want to enforce any formatting convention the it should be implemented in the formatting tool. I feel that any human post-editing of the files is potentially error prone, and burdensome.

If we are going to enforce "doc" on a new line - are we applying that everywhere? does it make sense everywhere? If we do can we also ensure it is the last attribute in the element?

I would cast a soft vote against making a new line, only because I worry there will be other corner cases where we don't want the additional lines.

For instance here - https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/libraries/stdlib/stdlib_defs.mtlx#L109

do we feel it would be beneficial to introduce new lines for each "doc" attribute, including the one in the "nodedef" element?

Comment thread libraries/stdlib/genglsl/stdlib_genglsl_impl.mtlx
<implementation name="IM_divide_vector4FA_genmdl" nodedef="ND_divide_vector4FA" sourcecode="{{in1}} / {{in2}}" target="genmdl" />
<implementation name="IM_divide_matrix33_genmdl" nodedef="ND_divide_matrix33" sourcecode="{{in1}}" target="genmdl" /> <!-- TODO: Implement properly -->
<implementation name="IM_divide_matrix44_genmdl" nodedef="ND_divide_matrix44" sourcecode="{{in1}}" target="genmdl" /> <!-- TODO: Implement properly -->
<implementation name="IM_divide_matrix33_genmdl" nodedef="ND_divide_matrix33" sourcecode="{{in1}}" target="genmdl" />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be good to move these comments above the lines they apply to - by hand.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing.

Comment thread libraries/stdlib/stdlib_defs.mtlx
@kwokcb
Copy link
Copy Markdown
Contributor Author

kwokcb commented Nov 3, 2025

As a general comment, I will revert all formatting changes which are under discussion and just keep the obvious XML error fixes. This should make the PR self-contained to just enhancing the mxformat utility.

Comment thread libraries/stdlib/genmdl/stdlib_genmdl_impl.mtlx
Copy link
Copy Markdown
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this investigation work, @kwokcb, and these improvements look good to me!

@jstone-lucasfilm jstone-lucasfilm merged commit 0c1ed1e into AcademySoftwareFoundation:main Nov 3, 2025
32 checks passed
@kwokcb kwokcb deleted the mx_format_update branch November 6, 2025 16:42
@JGamache-autodesk
Copy link
Copy Markdown
Contributor

Nice! I see we used the correct XML form and changed those && to &amp;&amp; in some inline implementations.

There still remains a definite XML format break enforced here. If we use UDIM tags, the resulting file will break the Python ElementTree parser:

   <input name="file" type="filename" value="diffuse<UDIM>.jpg" />

is illegal.

Correct XML representation is:

   <input name="file" type="filename" value="diffuse&lt;UDIM>.jpg" />

Looks like we chose readability by humans over strict adherence to W3 specifications by overriding PUGI code directly. This will be surprising to any TD wishing to apply XML based Python scripts to a collection of MaterialX documents. This hit me once this year as I use ET to check unit test result files and they started failing after I added UDIMs into the test mixture.

@ld-kerley
Copy link
Copy Markdown
Contributor

I would cast a vote to move to a completely conformant XML parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants