Improvements to document validation
This PR adds two new pieces to the correctness checking within MaterialX, these were discovered while doing work on MaterialX library files. I found them helpful, so I thought it might help to upstream the changes for others to benefit from too.
When loading libraries, there is now an optional boolean errorOnDuplicates, that will raise an error if a library contains an element is already present, previously this case would silently continue. I did wrestle with if this should just be called strict, incase there are other cases we want to add in the future. Open to input there.
Secondly I have added validation to TypedElement to validate if the type used has actually been registered in the document as a type. This very helpfully tracked down a couple of typos in work-in-progress code.
Finally I added the ability for the mxvalidate.py script to directly accept a path to alternate library locations.
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: ld-kerley (ce648d12d4ced4de552e8a78b414b31485995612, e6c6221b1d994f0a856a47393aa5b7234ab0aa95, 30de94790556476f098a8db4f2056f62b515117a, 062d337e9275413ad61e94d2595928a93db056c0)
- :white_check_mark: login: jstone-lucasfilm / name: Jonathan Stone (533a05343ba8d4474d3e1d03e12037ab28b6c528, 1214d9c0d25062b6b60229c4bc13b1f9f459e32c, 7b217bb10ab11e00e02c1d2e671e0bf2836e0b62, e96d237b984b8d665070c229864d01e16d39a67e)
Thanks for the feedback @kwokcb. This was certainly not posted as final work, and I wanted to get input on what I had thrown together internally to get me unstuck.
After a brief chat with @jstone-lucasfilm I added a ValidationOptions class to pass around configuration for the validation stage, this way we can add additional validations, without changing existing behavior.
Just on this specific build error, it looks like we'd need to add the new argument for Document::importLibrary to its JavaScript binding, so that existing calls continue to work as before:
https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/source/JsMaterialX/JsMaterialXCore/JsDocument.cpp#L26
I took a stab at resolving the JS bindings - but I don't have a local build setup to build them, and I also don't have a lot of experience with them either - perhaps someone with more JS chops could give me some pointers (or patch this PR)
Thanks for taking a look, @ld-kerley, and either @kwokcb or I can help to resolve that last JavaScript issue.
@ld-kerley We've now merged development work on MaterialX 1.39 back to the main branch of MaterialX, in preparation for the final weeks of development on the 1.39.0 release. When you have a chance, could you retarget this pull request back to the main branch as well?
@ld-kerley I'll close out this pull request for now, since it's framed in terms of a branch that we're planning to delete, but feel free to propose a similar pull request for the main branch in the future!