AcademySoftwareFoundation / AcademySoftwareFoundation/MaterialX
Names defined in MaterialX documents displace library names and cause strange behavior
- Dominant language
- C++
- Stars
- 2.3k
- Forks
- 451
- Avg merge
- 5d 18h
- Merged PRs (30d)
- 6
Description
Slightly complex one here. One of our devs was asking a very interesting question while working with MaterialX:
> Here’s another strange one about naming: Why won’t it let me name the node angle? It always appends 2. But it lets me name it test just fine. Are there some reserved names or something like that…?
After some pondering, it hit me that all the library definitions reside at the top level of the document, which means the [unit def "angle"](https://github.com/AcademySoftwareFoundation/MaterialX/blob/main/libraries/stdlib/stdlib_defs.mtlx#L62) becomes the equivalent of a reserved keyword.
So, the next question was:
> I can already see bugs created by this since the library is usually added after the material document gets loaded, so a node named "ND_standard_surface_surfaceshader" will most probably displace the NodeDef from the library, which will gain an extra digit at the end and causing quite a lot of mischief trying to find node definitions later.
And indeed you can create such documents in a text editor that will completely break MaterialX in strange ways.
Can I suggest restructuring the internal of mx::Document to have a child named "\_\_library\_\_" which would get all those definitions as children. Then we would end up with a single reserved keyword that would have little risk of colliding with user work.
Contributor guide
Research direction
Start with the naming and library-loading behavior described in the issue, including the unit def "angle" in libraries/stdlib/stdlib_defs.mtlx and the mx::Document structure. Investigate how library definitions and user nodes share names, then assess the proposed __library__ child organization; done means user names no longer displace library definitions or break NodeDef lookup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100