AcademySoftwareFoundation / AcademySoftwareFoundation/MaterialX
Proposal: Migrate comment documentation to nodedef doc attributes for std libraries
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 2.3k
- Forks
- 464
- Avg merge
- 4d 21h
- Merged PRs (30d)
- 11
Description
Proposal
This is an off-shoot of a discussion about PugiXML custom changes with @jstone-lucasfilm and @ld-kerley
The impetus being to remove the custom comment and line spacing custom changes to the library.
The main reason to have this is to allow for documentation of node definitions using XML comments.
The proposal here is to move the comments into the nodedef doc meta-data tag which makes it publicly
visible to integrations. (@ashwinbhat , for glTF PBR spec ratification this will at least start to have docs on nodes
which can be enhanced with things like boundary conditions).
As an additional change, if nodegraph XML comments are to be preserved then the doc tag would be needed there.
Test
Here is some sample code which could work for nodedefs and the result. It's mostly a heuristic to try and
guess what comments go with which nodedefs. The comment immeiate before a nodedef(s) is the doc string.
def transferCommentsToNodeDefs(libFile):
readOptions = mx.XmlReadOptions()
readOptions.readComments = True
readOptions.readNewlines = True
readOptions.upgradeVersion = False
outputDoc = mx.createDocument()
mx.readFromXmlFile(outputDoc, libFile, mx.FileSearchPath(), readOptions)
# Extract out comments and nodedefs
currentComment = []
children = outputDoc.getChildren()
for child in children:
if child.getCategory() == 'comment':
docstring = child.getAttribute('doc')
if len(docstring) > 0:
docstring = re.sub(r'\s+', ' ', docstring.replace('\n', ' ').lstrip())
docstring = docstring.strip()
# Repace end .. with .
if docstring.endswith('..'):
docstring = docstring[:-1]
currentComment.append(['comment', docstring, child.getName() ])
elif child.getCategory() == 'nodedef':
currentComment.append(['nodedef', child.getName()])
strippedComments = []
# Heuristic to find comments for nodedefs:
# 1. Accumulate nodedefs until a comment is found
# 2. Add an association between the comment and nodedefs
# 3. Skip if a comment is found immediately before a comment
# 4. Keep track of comments to remove
hitComment = False
nodedefList = []
removeComments = []
for i in range(len(currentComment)-1, -1, -1):
if not hitComment and currentComment[i][0] == 'comment':
if len(nodedefList) > 0:
# Keep track of comments to remove.
# Add [ nodedef, comment ] pair
removeComments.append(currentComment[i][2])
for nodedef in nodedefList:
strippedComments.append([nodedef, currentComment[i][1]])
nodedefList.clear();
hitComment = True
elif currentComment[i][0] == 'nodedef':
nodedefList.append(currentComment[i][1])
hitComment = False
# Apply comments to nodedefs:
# 1. Find nodedefs
# 2. Add new comments to existing comments
print('nodedefs with new comments')
for i in range(len(strippedComments)):
print(strippedComments[i])
nodedef = outputDoc.getChild(strippedComments[i][0])
if nodedef is None:
print('Cannot find nodedef:', strippedComments[i][0])
continue
currentDoc = nodedef.getAttribute('doc')
newDoc = strippedComments[i][1]
if len(currentDoc) > 0:
newDoc = newDoc + " " + currentDoc
nodedef.setAttribute('doc', newDoc)
# Remove comments
for i in range(len(removeComments)):
outputDoc.removeChild(removeComments[i])
return outputDoc
Snippets from result on stdlib_defs.mtlx
<nodedef name="ND_sign_float" node="sign" nodegroup="math" doc="Node: <sign>. Sign of each input channel: -1, 0 or +1">
<input name="in" type="float" value="0.0" />
<output name="out" type="float" defaultinput="in" />
</nodedef>
<nodedef name="ND_clamp_float" node="clamp" nodegroup="math" doc="Node: <clamp>. Clamp incoming value to a specified range of values.">
<input name="in" type="float" value="0.0" />
<input name="low" type="float" value="0.0" />
<input name="high" type="float" value="1.0" />
<output name="out" type="float" defaultinput="in" />
</nodedef>
<nodedef name="ND_range_color3" node="range" nodegroup="adjustment" doc="Node: <range> Supplemental Node. Remap a value from one range of float/color/vector values to another, optionally applying a gamma correction in the middle, and optionally clamping output values.">
<input name="in" type="color3" value="0.0, 0.0, 0.0" />
<input name="inlow" type="color3" value="0.0, 0.0, 0.0" />
<input name="inhigh" type="color3" value="1.0, 1.0, 1.0" />
<input name="gamma" type="color3" value="1.0, 1.0, 1.0" />
<input name="outlow" type="color3" value="0.0, 0.0, 0.0" />
<input name="outhigh" type="color3" value="1.0, 1.0, 1.0" />
<input name="doclamp" type="boolean" value="false" />
<output name="out" type="color3" defaultinput="in" />
</nodedef>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the comment and nodedef handling shown in the issue, using stdlib_defs.mtlx as the example input and output. Review how comments are currently represented for nodedef and nodegraph elements, then determine how the proposed metadata migration should preserve existing documentation. Done means the relevant standard-library comments are represented in nodedef doc attributes, with nodegraph handling addressed if required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, xml
- Domain
- documentation
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100