Skip to content

Commit

Permalink
Command line interface (#33)
Browse files Browse the repository at this point in the history
* docs update.

* Rebuild.

* Command line updates
Also change the default data to be the test data checkerboard.

* Cleanup.
  • Loading branch information
kwokcb authored Nov 21, 2024
1 parent 463fa6a commit 292fc2e
Show file tree
Hide file tree
Showing 17 changed files with 547 additions and 125 deletions.
30 changes: 14 additions & 16 deletions README.html
Original file line number Diff line number Diff line change
Expand Up @@ -389,21 +389,19 @@ <h3 id="setup">Setup</h3>
<p><code>pip install .</code></p>
<p>All dependencies listed will be installed if required.</p>
<h4 id="command-line-interfaces">Command Line Interfaces</h4>
<p>To convert from a MaterialX document to produce a glTF JSON document the<br>
<code>materialx_to_gltf.py</code> utility script may be used.</p>
<p>The following is an example converting a sample file found in the test folder.<br>
The results are saved to a file called <code>checkerboard_graph.gltf</code>.</p>
<code>
python source/gltf_materialx_converter/materialx_to_gltf.py "tests/data/checkerboard_graph.mtlx"
</code>
<p>To convert from a MaterialX document to produce a glTF JSON document the <code>materialx_to_gltf.py</code> utility script may be used.</p>
<p>The following is an example converting a sample file found in the test folder. The results are saved to a file called <code>checkerboard_graph.gltf</code>.</p>
<p><code>python -m gltf_materialx_converter mtlx &quot;tests/data/checkerboard_graph.mtlx&quot;</code></p>
<p>or</p>
<p><code>python source/gltf_materialx_converter/materialx_to_gltf.py &quot;tests/data/checkerboard_graph.mtlx&quot;</code></p>
<p>to run the local script.</p>
<hr>
<p>To convert from a document containing glTF procedural content to produce a MaterialX document the<br>
<code>gltf_to_materialx.py</code> utility script may be used.</p>
<p>The following is an example converting a sample file found in the test folder.<br>
The results are saved to a file called <code>checkerboard_graph_fromgltf.mtlx</code>.</p>
<code>
python source/gltf_materialx_converter/gltf_to_materialx.py "tests/data/checkerboard_graph.gltf"
</code>
<p>To convert from a document containing glTF procedural content to produce a MaterialX document the <code>gltf_to_materialx.py</code> utility script may be used.</p>
<p>The following is an example converting a sample file found in the test folder. The results are saved to a file called <code>checkerboard_graph_fromgltf.mtlx</code>.</p>
<p><code>python -m gltf_materialx_converter gltf &quot;tests/data/checkerboard_graph.gltf&quot;</code></p>
<p>or</p>
<p><code>python source/gltf_materialx_converter/gltf_to_materialx.py &quot;tests/data/checkerboard_graph.gltf&quot;</code></p>
<p>to run the local script.</p>
<h4 id="api-example">API Example</h4>
<p>The following is a simple example of using the API to convert from MaterialX to glTF<br>
and then back to MaterialX.</p>
Expand Down Expand Up @@ -445,9 +443,9 @@ <h4 id="api">API</h4>
It is assumed that <code>Doxygen</code> has been installed locally.</p>
<h3 id="tests">Tests</h3>
<p>The following command can be used to run tests from the root folder:</p>
<code>
<pre>
python -m unittest discover -s tests -p "test_*.py"
</code>
</pre>
<h3 id="supported-materialx-configurations">Supported MaterialX Configurations</h3>
<p>Only specific configurations of MaterialX can be mapped to glTF Texture Procedurals.</p>
<ol>
Expand Down
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,31 @@ All dependencies listed will be installed if required.

#### Command Line Interfaces

To convert from a MaterialX document to produce a glTF JSON document the
`materialx_to_gltf.py` utility script may be used.
To convert from a MaterialX document to produce a glTF JSON document the `materialx_to_gltf.py` utility script may be used.

The following is an example converting a sample file found in the test folder.
The results are saved to a file called `checkerboard_graph.gltf`.
The following is an example converting a sample file found in the test folder. The results are saved to a file called `checkerboard_graph.gltf`.

<code>
python source/gltf_materialx_converter/materialx_to_gltf.py "tests/data/checkerboard_graph.mtlx"
</code>
`python -m gltf_materialx_converter mtlx "tests/data/checkerboard_graph.mtlx"`

or

`python source/gltf_materialx_converter/materialx_to_gltf.py "tests/data/checkerboard_graph.mtlx"`

to run the local script.

<hr>

To convert from a document containing glTF procedural content to produce a MaterialX document the
`gltf_to_materialx.py` utility script may be used.
To convert from a document containing glTF procedural content to produce a MaterialX document the `gltf_to_materialx.py` utility script may be used.

The following is an example converting a sample file found in the test folder. The results are saved to a file called `checkerboard_graph_fromgltf.mtlx`.

The following is an example converting a sample file found in the test folder.
The results are saved to a file called `checkerboard_graph_fromgltf.mtlx`.
`python -m gltf_materialx_converter gltf "tests/data/checkerboard_graph.gltf"`

<code>
python source/gltf_materialx_converter/gltf_to_materialx.py "tests/data/checkerboard_graph.gltf"
</code>
or

`python source/gltf_materialx_converter/gltf_to_materialx.py "tests/data/checkerboard_graph.gltf"`

to run the local script.

#### API Example

Expand Down Expand Up @@ -100,9 +104,9 @@ It is assumed that `Doxygen` has been installed locally.

The following command can be used to run tests from the root folder:

<code>
<pre>
python -m unittest discover -s tests -p "test_*.py"
</code>
</pre>

### Supported MaterialX Configurations

Expand Down
36 changes: 20 additions & 16 deletions documents/README_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,31 @@ All dependencies listed will be installed if required.

#### Command Line Interfaces

To convert from a MaterialX document to produce a glTF JSON document the
`materialx_to_gltf.py` utility script may be used.
To convert from a MaterialX document to produce a glTF JSON document the `materialx_to_gltf.py` utility script may be used.

The following is an example converting a sample file found in the test folder.
The results are saved to a file called `checkerboard_graph.gltf`.
The following is an example converting a sample file found in the test folder. The results are saved to a file called `checkerboard_graph.gltf`.

<code>
python source/gltf_materialx_converter/materialx_to_gltf.py "tests/data/checkerboard_graph.mtlx"
</code>
`python -m gltf_materialx_converter mtlx "tests/data/checkerboard_graph.mtlx"`

or

`python source/gltf_materialx_converter/materialx_to_gltf.py "tests/data/checkerboard_graph.mtlx"`

to run the local script.

<hr>

To convert from a document containing glTF procedural content to produce a MaterialX document the
`gltf_to_materialx.py` utility script may be used.
To convert from a document containing glTF procedural content to produce a MaterialX document the `gltf_to_materialx.py` utility script may be used.

The following is an example converting a sample file found in the test folder. The results are saved to a file called `checkerboard_graph_fromgltf.mtlx`.

The following is an example converting a sample file found in the test folder.
The results are saved to a file called `checkerboard_graph_fromgltf.mtlx`.
`python -m gltf_materialx_converter gltf "tests/data/checkerboard_graph.gltf"`

<code>
python source/gltf_materialx_converter/gltf_to_materialx.py "tests/data/checkerboard_graph.gltf"
</code>
or

`python source/gltf_materialx_converter/gltf_to_materialx.py "tests/data/checkerboard_graph.gltf"`

to run the local script.

#### API Example

Expand Down Expand Up @@ -100,9 +104,9 @@ It is assumed that `Doxygen` has been installed locally.

The following command can be used to run tests from the root folder:

<code>
<pre>
python -m unittest discover -s tests -p "test_*.py"
</code>
</pre>

### Supported MaterialX Configurations

Expand Down
32 changes: 28 additions & 4 deletions documents/html/____main_____8py_source.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,35 @@
<div class="line"><a id="l00005" name="l00005"></a><span class="lineno"> 5</span> <span class="stringliteral">&#39;&#39;&#39;</span></div>
<div class="line"><a id="l00006" name="l00006"></a><span class="lineno"> 6</span><span class="stringliteral"> Main entry point for running commands in the package.</span></div>
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno"> 7</span><span class="stringliteral"> &#39;&#39;&#39;</span></div>
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno"> 8</span> <span class="keywordflow">return</span> </div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno"> 9</span> </div>
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno"> 8</span> argCount = len(sys.argv)</div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno"> 9</span> <span class="keywordflow">if</span> argCount &lt; 2:</div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno"> 10</span> print(<span class="stringliteral">&#39;No arguments provided. Use -h or --help for help.&#39;</span>)</div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno"> 11</span> <span class="keywordflow">return</span> 1</div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno"> 12</span> <span class="keywordflow">if</span> sys.argv[1] == <span class="stringliteral">&#39;-h&#39;</span> <span class="keywordflow">or</span> sys.argv[1] == <span class="stringliteral">&#39;--help&#39;</span>:</div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno"> 13</span> print(<span class="stringliteral">&#39;Usage: python -m gltf_materialx_converter &lt;command&gt; [options] where command is mtlx2gltf or gltf2mtlx&#39;</span>)</div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno"> 14</span> </div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno"> 15</span> <span class="comment"># Check if the command is valid</span></div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno"> 16</span> <span class="comment"># Check if the command is valid</span></div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno"> 17</span> cmdArgs = sys.argv[1:]</div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno"> 18</span> <span class="keywordflow">if</span> cmdArgs[0] == <span class="stringliteral">&#39;gltf&#39;</span>:</div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"> 19</span> cmdArgs[0] = <span class="stringliteral">&#39;materialx_to_gltf.py&#39;</span></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno"> 20</span> <span class="keywordflow">elif</span> cmdArgs[0] == <span class="stringliteral">&#39;mtlx&#39;</span>:</div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span> cmdArgs[0] = <span class="stringliteral">&#39;gltf_to_materialx.py&#39;</span></div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span> <span class="keywordflow">else</span>:</div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"> 23</span> print(<span class="stringliteral">&#39;Unknown command specified:&#39;</span>, cmdArgs[0])</div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span> <span class="keywordflow">return</span> 1</div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span> </div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span> <span class="comment"># Build the command</span></div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span> cmd = <span class="stringliteral">&#39; &#39;</span>.join(cmdArgs)</div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span> packageLocation = os.path.dirname(__file__)</div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span> cmd = <span class="stringliteral">&#39;python &#39;</span> + packageLocation + <span class="stringliteral">&#39;/&#39;</span> + cmd</div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span> </div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span> <span class="comment"># Run the command</span></div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span> <span class="keywordflow">return</span> subprocess.call(cmd, shell=<span class="keyword">True</span>)</div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span> </div>
</div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno"> 10</span><span class="keywordflow">if</span> __name__ == <span class="stringliteral">&#39;__main__&#39;</span>:</div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno"> 11</span> sys.exit(<a class="code hl_function" href="namespacegltf__materialx__converter_1_1____main____.html#aa0dc9a2ccf91bf2828efea2e404a61f8">main</a>())</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span><span class="keywordflow">if</span> __name__ == <span class="stringliteral">&#39;__main__&#39;</span>:</div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno"> 35</span> sys.exit(<a class="code hl_function" href="namespacegltf__materialx__converter_1_1____main____.html#aa0dc9a2ccf91bf2828efea2e404a61f8">main</a>())</div>
<div class="ttc" id="anamespacegltf__materialx__converter_1_1____main_____html_aa0dc9a2ccf91bf2828efea2e404a61f8"><div class="ttname"><a href="namespacegltf__materialx__converter_1_1____main____.html#aa0dc9a2ccf91bf2828efea2e404a61f8">gltf_materialx_converter.__main__.main</a></div><div class="ttdeci">int main()</div><div class="ttdoc">Main entry point for running commands in the package.</div><div class="ttdef"><b>Definition</b> <a href="#l00004">__main__.py:4</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
Expand Down
18 changes: 13 additions & 5 deletions documents/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,17 @@ <h3><a class="anchor" id="command-line-interfaces"></a>
Command Line Interfaces</h3>
<p>To convert from a MaterialX document to produce a glTF JSON document the <code><a class="el" href="materialx__to__gltf_8py.html" title="Command line utility to convert from MaterialX documents to glTF Texture Procedurals documents&quot;.">materialx_to_gltf.py</a></code> utility script may be used.</p>
<p>The following is an example converting a sample file found in the test folder. The results are saved to a file called <code>checkerboard_graph.gltf</code>.</p>
<p><code> python <a class="el" href="materialx__to__gltf_8py.html" title="Command line utility to convert from MaterialX documents to glTF Texture Procedurals documents&quot;.">source/gltf_materialx_converter/materialx_to_gltf.py</a> "tests/data/checkerboard_graph.mtlx" </code></p>
<p><code>python -m <a class="el" href="namespacegltf__materialx__converter.html">gltf_materialx_converter</a> mtlx "tests/data/checkerboard_graph.mtlx"</code></p>
<p>or</p>
<p><code>python <a class="el" href="materialx__to__gltf_8py.html" title="Command line utility to convert from MaterialX documents to glTF Texture Procedurals documents&quot;.">source/gltf_materialx_converter/materialx_to_gltf.py</a> "tests/data/checkerboard_graph.mtlx"</code></p>
<p>to run the local script.</p>
<hr />
<p>To convert from a document containing glTF procedural content to produce a MaterialX document the <code><a class="el" href="gltf__to__materialx_8py.html" title="Command line utility to convert from glTF Texture Procedurals documents to MaterialX documents&quot;.">gltf_to_materialx.py</a></code> utility script may be used.</p>
<p>The following is an example converting a sample file found in the test folder. The results are saved to a file called <code>checkerboard_graph_fromgltf.mtlx</code>.</p>
<p><code> python <a class="el" href="gltf__to__materialx_8py.html" title="Command line utility to convert from glTF Texture Procedurals documents to MaterialX documents&quot;.">source/gltf_materialx_converter/gltf_to_materialx.py</a> "tests/data/checkerboard_graph.gltf" </code></p>
<p><code>python -m <a class="el" href="namespacegltf__materialx__converter.html">gltf_materialx_converter</a> gltf "tests/data/checkerboard_graph.gltf"</code></p>
<p>or</p>
<p><code>python <a class="el" href="gltf__to__materialx_8py.html" title="Command line utility to convert from glTF Texture Procedurals documents to MaterialX documents&quot;.">source/gltf_materialx_converter/gltf_to_materialx.py</a> "tests/data/checkerboard_graph.gltf"</code></p>
<p>to run the local script.</p>
<h3><a class="anchor" id="api-example"></a>
API Example</h3>
<p>The following is a simple example of using the API to convert from MaterialX to glTF and then back to MaterialX.</p>
Expand Down Expand Up @@ -187,9 +193,11 @@ <h3><a class="anchor" id="api"></a>
<h2><a class="anchor" id="tests"></a>
Tests</h2>
<p>The following command can be used to run tests from the root folder:</p>
<p><code> python -m unittest discover -s tests -p "test_*.py" </code></p>
<h2><a class="anchor" id="supported-materialx-configurations"></a>
Supported MaterialX Configurations</h2>
<pre>
python -m unittest discover -s tests -p "test_*.py"
</pre><p>#</p>
<h1><a class="anchor" id="supported-materialx-configurations"></a>
Supported MaterialX Configurations</h1>
<p>Only specific configurations of MaterialX can be mapped to glTF Texture Procedurals.</p><ol type="1">
<li>There must be a <code>surfacematerial</code> material node</li>
<li>There must be a <code>glTF PBR</code> or <code>unlit</code> node connected to the surface shader input of the material.</li>
Expand Down
23 changes: 12 additions & 11 deletions documents/html/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
var index =
[
[ "Documentation", "index.html#autotoc_md14", [
[ "Introduction", "index.html#autotoc_md9", null ],
[ "Dependencies", "index.html#autotoc_md10", null ],
[ "Setup", "index.html#autotoc_md11", [
[ "Command Line Interfaces", "index.html#autotoc_md12", null ],
[ "API Example", "index.html#autotoc_md13", null ],
[ "API", "index.html#autotoc_md15", null ]
[ "Supported MaterialX Configurations", "index.html#supported-materialx-configurations", [
[ "Introduction", "index.html#introduction", null ],
[ "Dependencies", "index.html#dependencies", null ],
[ "Setup", "index.html#setup", [
[ "Command Line Interfaces", "index.html#command-line-interfaces", null ],
[ "API Example", "index.html#api-example", null ]
] ],
[ "Tests", "index.html#autotoc_md16", null ],
[ "Supported MaterialX Configurations", "index.html#autotoc_md17", [
[ "Test Data", "index.html#autotoc_md18", null ]
[ "Documentation", "index.html#documentation-1", [
[ "API", "index.html#api", null ]
] ],
[ "Development Information", "index.html#autotoc_md19", null ]
[ "Tests", "index.html#tests", [
[ "Test Data", "index.html#test-data", null ]
] ],
[ "Development Information", "index.html#development-information", null ]
] ]
];
Loading

0 comments on commit 292fc2e

Please sign in to comment.