Skip to content

Commit

Permalink
Update AcademySoftwareFoundation#342 Sphinx Python Documentation.
Browse files Browse the repository at this point in the history
Work in progress.

This PR adds a new build target named `MaterialXDocsPython`,
which generates Python API documentation using Sphinx.

The existing developer guide contents are incorporated into
the new HTML documentation, which lives side-by-side to the
existing Doxygen-generated C++ API documentation.

The docstrings of the Python modules were tweaked to describe
what the individual modules are responsible for.

Signed-off-by: Stefan Habel <[email protected]>
  • Loading branch information
StefanHabel committed Oct 13, 2023
1 parent c7f01d8 commit 8a66335
Show file tree
Hide file tree
Showing 22 changed files with 470 additions and 63 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enable_testing()
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}/cmake/modules")

# JavaScript setup
option(MATERIALX_BUILD_JS "Build the MaterialX JavaScript package from C++ bindings. Requires the emscripten environment." OFF)
Expand Down
20 changes: 20 additions & 0 deletions cmake/modules/FindSphinx.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
include(FindPackageHandleStandardArgs)

find_package(Python3)
if(PYTHON3_FOUND)
get_filename_component(_PYTHON_EXECUTABLE_DIR "${PYTHON_EXECUTABLE}" DIRECTORY)
set(
_SPHINX_SEARCH_PATHS
"${_PYTHON_EXECUTABLE_DIR}"
"${_PYTHON_EXECUTABLE_DIR}/bin"
"${_PYTHON_EXECUTABLE_DIR}/Scripts"
)
endif()

find_program(
SPHINX_EXECUTABLE
NAMES sphinx-build sphinx-build.exe
HINTS ${_SPHINX_SEARCH_PATHS})
mark_as_advanced(SPHINX_EXECUTABLE)

find_package_handle_standard_args(Sphinx DEFAULT_MSG SPHINX_EXECUTABLE)
56 changes: 53 additions & 3 deletions documents/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# MaterialX C++ API Documentation
set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(DOXYGEN_HTML_OUTPUT_DIR ${DOXYGEN_OUTPUT_DIR}/html)
set(DOXYGEN_INPUT_LIST ${CMAKE_SOURCE_DIR}/documents/DeveloperGuide/MainPage.md
Expand All @@ -22,13 +23,62 @@ if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
add_custom_target(MaterialXDocs ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating HTML documentation: ${DOXYGEN_HTML_OUTPUT_DIR}/index.html")
COMMENT "Building MaterialX C++ API Documentation: ${DOXYGEN_HTML_OUTPUT_DIR}/index.html")
add_custom_command(TARGET MaterialXDocs PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/documents/DoxygenAwesome ${CMAKE_CURRENT_BINARY_DIR})
${CMAKE_SOURCE_DIR}/documents/DoxygenAwesome ${DOXYGEN_HTML_OUTPUT_DIR})
add_custom_command(TARGET MaterialXDocs PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/documents/Images ${CMAKE_CURRENT_BINARY_DIR})
${CMAKE_SOURCE_DIR}/documents/Images ${DOXYGEN_HTML_OUTPUT_DIR})
install(DIRECTORY ${DOXYGEN_HTML_OUTPUT_DIR}
DESTINATION "documents" MESSAGE_NEVER)
else()
message(WARNING "Unable to build MaterialX C++ API Documentation: Doxygen not found.")
endif(DOXYGEN_FOUND)


# MaterialX Python API Documentation
set(SPHINX_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(SPHINX_HTML_OUTPUT_DIR ${SPHINX_OUTPUT_DIR}/html-sphinx)
set(
SPHINX_INPUT_LIST
${CMAKE_SOURCE_DIR}/documents/DeveloperGuide/
)
set(MATERIALX_PYTHONPATH ${CMAKE_SOURCE_DIR}/lib)
set(MATERIALX_LOGO_FILENAME "MaterialXLogo_200x155.png")

find_package(Sphinx)

if(SPHINX_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/sphinx-conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/conf.py)

add_custom_target(MaterialXDocsPython ${SPHINX_EXECUTABLE}
-c ${CMAKE_CURRENT_BINARY_DIR}
${SPHINX_INPUT_LIST}
${SPHINX_HTML_OUTPUT_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Building MaterialX Python API Documentation: ${SPHINX_HTML_OUTPUT_DIR}/index.html")

# Add post-build commands to copy our logo and custom style sheet to the
# "_static" folder
add_custom_command(
TARGET MaterialXDocsPython POST_BUILD COMMAND ${CMAKE_COMMAND}
-E copy ${CMAKE_SOURCE_DIR}/documents/sphinx-custom.css
${SPHINX_HTML_OUTPUT_DIR}/_static/custom.css
)
add_custom_command(
TARGET MaterialXDocsPython POST_BUILD COMMAND ${CMAKE_COMMAND}
-E copy ${CMAKE_SOURCE_DIR}/documents/Images/${MATERIALX_LOGO_FILENAME}
${SPHINX_HTML_OUTPUT_DIR}/_static/
)

# Add a post-build command to copy the DoxygenAwesome style sheet to the
# "_static" folder
add_custom_command(
TARGET MaterialXDocsPython POST_BUILD COMMAND ${CMAKE_COMMAND}
-E copy_directory ${CMAKE_SOURCE_DIR}/documents/DoxygenAwesome
${SPHINX_HTML_OUTPUT_DIR}/_static/DoxygenAwesome
)
else()
message(WARNING "Unable to build MaterialX Python API Documentation: Sphinx not found.")
endif(SPHINX_FOUND)
23 changes: 12 additions & 11 deletions documents/DeveloperGuide/GraphEditor.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,30 @@

The MaterialX Graph Editor is an example application for visualizing, creating, and editing MaterialX graphs. It utilizes the ImGui framework as well as additional ImGui extensions such as the Node Editor.

### Example Images
## Example Images

![MaterialX Graph Editor with procedural marble example](../Images/MaterialXGraphEditor_Marble.png)

**Figure 1:** MaterialX Graph Editor with procedural marble example
<img src="/documents/Images/MaterialXGraphEditor_Marble.png" />

## Building The MaterialX Graph Editor
## Building the MaterialX Graph Editor
Select the `MATERIALX_BUILD_GRAPH_EDITOR` option in CMake to build the MaterialX Graph Editor. Installation will copy the **MaterialXGraphEditor** executable to a `/bin` directory within the selected install folder.

### Summary of Graph Editor Features
## Summary of Graph Editor Features

1. **Load Material**: Load a material document in the MTLX format.
2. **Save Material**: Save out a graph as a mterial document in MTLX format.
3. **New Material**: Clear all information to set up for the creation of a new material
4. **Node Property Editor**: View or edit properties of the selected node.
5. **Render View**: View the rendered material.

### Buttons
## Buttons

To display a new material and graph, click the `Load Material` button and and navigate to the [Example Materials](../../resources/Materials/Examples) folder, which contains a selection of materials in the MTLX format, and select a document to load. The Graph Editor will display the graph hierarchy of the selected document for visualization and editing.

To save out changes to the graphs as MTLX files click the `Save Material` button. This will save the position of the nodes in the graph for future use as well.

### Editor Window
## Editor Window

The MaterialX document is displayed as nodes in the Editor window. When a file is intially loaded the material node, surface shader node, and any enclosing nodegraphs will be displayed. Double-clicking on a nodegraph, or any node defined as a subgraph, will display the contents of that graph.

Expand All @@ -40,19 +41,19 @@ Another type of node present in the `Add Node` pop-up is the group, or backgroun

To search the editor window for a specific node use `CTRL` + `F` to bring up the search bar.

### Node Property Editor
## Node Property Editor
When a node is selected in the graph, its information is displayed on the left-hand column in the `Node Property Editor`. This editor displays the name of the node, its category, its inputs, the input name, types and values. Inputs that are connected to other nodes will not display a value.

This is where a node's properties such as its name and input values can be adjusted. When an input value is changed the material is automatically updated to reflect that change. The node info button displays the `doc` string for the selected node and its inputs if they exist. This `doc` string is currently read only.

The show All Inputs checkbox displays all possible inputs for a node. With the box unchecked only inputs that have a connection or have had a value set will be shown. Only these inputs will be saved out when the graph is saved.

### Render View
## Render View
Above the `Node Property Editor`, the `Render View` displays the current material on the Arnold Shader Ball. If inside a subgraph it will display the material associated with that subgraph; otherwise it will display the output of the selected node. It automatically updates when any changes are made to the graph.

To adjust the relative sizes of the Node Property Editor and Render View windows, drag the separator between these windows in the application. The render view window camera can be changed using the left or right mouse buttons to manipulate the shader ball.

### Keyboard Shortcuts
## Keyboard Shortcuts

- `TAB`: Add Node Popup
- `Right Click`: pan along the editor
Expand All @@ -66,7 +67,7 @@ To adjust the relative sizes of the Node Property Editor and Render View windows
- `+` : Zoom in with the camera when mouse is over the Render View Window.
- `-` : Zoom out with the camera when mouse is over the Render View Window.

### Command-Line Options
## Command-Line Options

The following are common command-line options for MaterialXGraphEditor, and a complete list can be displayed with the `--help` option.
- `--material [FILENAME]` : Specify the filename of the MTLX document to be displayed in the graph editor
Expand All @@ -75,7 +76,7 @@ The following are common command-line options for MaterialXGraphEditor, and a co
- `--library [FILEPATH]` : Specify an additional data library folder (e.g. 'vendorlib', 'studiolib'). This relative path will be appended to each location in the data search path when loading data libraries.
- `--captureFilename [FILENAME]` : Specify the filename to which the first rendered frame should be written

### Known Limitations
## Known Limitations

- Creating new connections using the `channels` attribute of an input is not yet supported, though existing `channels` connections will be displayed in graphs.
- Assigning a new `colorspace` attribute to an input is not yet supported, though existing `colorspace` attributes on inputs will be respected by the render view.
22 changes: 11 additions & 11 deletions documents/DeveloperGuide/MainPage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

MaterialX is an open standard for representing rich material and look-development content in computer graphics, enabling its platform-independent description and exchange across applications and renderers. Launched at [Industrial Light & Magic](https://www.ilm.com/) in 2012, MaterialX has been a key technology in their feature films and real-time experiences since _Star Wars: The Force Awakens_ and _Millennium Falcon: Smugglers Run_. The project was released as open source in 2017, with companies including Sony Pictures Imageworks, Pixar, Autodesk, Adobe, and SideFX contributing to its ongoing development. In 2021, MaterialX became the seventh hosted project of the [Academy Software Foundation](https://www.aswf.io/).

### Quick Start for Developers
## Quick Start for Developers

- Download the latest version of the [CMake](https://cmake.org/) build system.
- Point CMake to the root of the MaterialX library and generate C++ projects for your platform and compiler.
- Select the `MATERIALX_BUILD_PYTHON` option to build Python bindings.
- Select the `MATERIALX_BUILD_VIEWER` option to build the MaterialX viewer.

### Supported Platforms
## Supported Platforms

The MaterialX codebase requires a compiler with support for C++14, and can be built with any of the following:

Expand All @@ -19,9 +19,9 @@ The MaterialX codebase requires a compiler with support for C++14, and can be bu

The Python bindings for MaterialX are based on [PyBind11](https://github.com/pybind/pybind11), and support Python versions 3.6 and greater.

### Building MaterialX
## Building MaterialX

#### Building MaterialX C++
### Building MaterialX C++

The MaterialX C++ libraries are automatically included when building MaterialX through CMake.

Expand All @@ -32,7 +32,7 @@ To enable OpenImageIO support in MaterialX builds, the following additional opti

See the [MaterialX Unit Tests](https://github.com/AcademySoftwareFoundation/MaterialX/tree/main/source/MaterialXTest) page for documentation on shader generation and render testing in GLSL, OSL, and MDL.

#### Building MaterialX Python
### Building MaterialX Python

By default, the `MATERIALX_BUILD_PYTHON` option will use the active version of Python in the developer's path. To select a specific version of Python, use one or more of the following advanced options:

Expand All @@ -44,25 +44,25 @@ Additional options for the generation of MaterialX Python include the following:
- `MATERIALX_PYTHON_OCIO_DIR`: Path to a folder containing the default OCIO configuration to be packaged with MaterialX Python. The recommended OpenColorIO configuration for MaterialX is [ACES 1.2](https://github.com/colour-science/OpenColorIO-Configs/tree/feature/aces-1.2-config/aces_1.2).
- `MATERIALX_PYTHON_PYBIND11_DIR`: Path to a folder containing the PyBind11 source to be used in building MaterialX Python. Defaults to the included PyBind11 source.

#### Building The MaterialX Viewer
### Building The MaterialX Viewer

Select the `MATERIALX_BUILD_VIEWER` option to build the MaterialX Viewer. Installation will copy the **MaterialXView** executable to a `bin/` directory within the selected install folder.

#### Building API Documentation
### Building API Documentation

To generate HTML documentation for the MaterialX C++ API, make sure a version of [Doxygen](https://www.doxygen.org/) is on your path, and select the advanced option `MATERIALX_BUILD_DOCS` in CMake. This option will add a target named `MaterialXDocs` to your project, which can be built as an independent step from your development environment.

### Installing MaterialX
## Installing MaterialX

Building the `install` target of your project will install the MaterialX C++ and Python libraries to the folder specified by the `CMAKE_INSTALL_PREFIX` setting, and will install MaterialX Python as a third-party library in your Python environment. Installation of MaterialX Python as a third-party library can be disabled by setting `MATERIALX_INSTALL_PYTHON` to `OFF`.

### MaterialX Versioning
## MaterialX Versioning

The MaterialX codebase uses a modified semantic versioning system where the *major* and *minor* versions match that of the corresponding MaterialX [specification](https://www.materialx.org/Specification.html), and the *build* version represents engineering advances within that specification version. MaterialX documents are similarly marked with the specification version they were authored in, and they are valid to load into any MaterialX codebase with an equal or higher specification version.

Upgrading of MaterialX documents from earlier versions is handled at import time by the Document::upgradeVersion method, which applies the syntax and node interface upgrades that have occurred in previous specification revisions. This allows the syntax conventions of MaterialX and the names and interfaces of nodes to evolve over time, without invalidating documents from earlier versions.
Upgrading of MaterialX documents from earlier versions is handled at import time by the `Document::upgradeVersion()` method, which applies the syntax and node interface upgrades that have occurred in previous specification revisions. This allows the syntax conventions of MaterialX and the names and interfaces of nodes to evolve over time, without invalidating documents from earlier versions.

### Additional Links
## Additional Links

- The main [MaterialX website](http://www.materialx.org) provides background on the project's history, industry collaborations, and recent presentations.
- The [Python Scripts](https://github.com/materialx/MaterialX/tree/main/python/Scripts) folder contains standalone examples of MaterialX Python code.
Expand Down
10 changes: 5 additions & 5 deletions documents/DeveloperGuide/ShaderGeneration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A shader generation framework is implemented as part of MaterialX. This can help

Note that this system has no runtime and the output produced is source code, not binary executable code. The source code produced needs to be compiled by a shading language compiler before being executed by the renderer. See Figure 1 for a high level overview of the system.

![Shader generation with multiple shader generators](/documents/Images/shadergen.png)
![Shader generation with multiple shader generators](../Images/shadergen.png)

**Figure 1**: Shader generation with multiple shader generators.

Expand Down Expand Up @@ -43,12 +43,12 @@ Figure 2. The first option is to keep inline code in a file. The file extension
<input name="in2" type="color3" />
<output name="out" type="color3" defaultinput="in1" />
</nodedef>
<... more types ...>
// ... more types ...

// Implementation elements for node <add>
<implementation name="IM_add_float" nodedef="ND_add_float" file="mx_add.inline" />
<implementation name="IM_add_color3" nodedef="ND_add_color3" file="mx_add.inline" />
<... more types ...>
// ... more types ...

// Nodedef elements for node <mix>
<nodedef name="ND_mix_float" node="mix">
Expand All @@ -63,12 +63,12 @@ Figure 2. The first option is to keep inline code in a file. The file extension
<input name="mix" type="color3" />
<output name="out" type="color3" defaultinput="bg" />
</nodedef>
<... more types ...>
// ... more types ...

// Implementation elements for node <mix>
<implementation name="IM_mix_float" nodedef="ND_mix_float" sourcecode="mix({{bg}}, {{fg}}, {{mix}})" />
<implementation name="IM_mix_color3" nodedef="ND_mix_color3" sourcecode="mix({{bg}}, {{fg}}, {{mix}})" />
<... more types ...>
// ... more types ...
```
```c++
// File 'mx_add.inline' contains:
Expand Down
Loading

0 comments on commit 8a66335

Please sign in to comment.