Skip to content

Commit 96a1dbb

Browse files
authored
Patch EXR usage in PolyHaven (#32)
* Add support to try and grab PNG if available instead of EXR. If not then download EXR and use OIIO to convert if package is installed. * Make sure to remap the exr references in mtlx to png. * Fix packaged data for PolyHaven. Extract out all MTLX data during build so it's put into the package. * Patch up bad PolyHaven files. Will use exr as reference but have a jpg as download. * Cleanup. * Update renders and docs for polyhaven.
1 parent 1053465 commit 96a1dbb

83 files changed

Lines changed: 129860 additions & 1544 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.html

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -473,17 +473,18 @@ <h4>Examples</h4>
473473
<td>
474474
<b>PolyHaven</b>
475475
<table>
476+
<!-- https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/ -->
476477
<tr>
477478
<td>
478-
<img src="https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/data/PolyHavenMaterialX/polyhaven_aerial_asphalt_1.png" width=256px%><br>
479-
Ashphalt
479+
<img src="https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/examples/PolyHaven/aerial_asphalt_01_1k_materialx/aerial_asphalt_01_1k.png" width="256px"><br>
480+
Ashphalt 1
480481
</td>
481482
<td>
482-
<img src="https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/data/PolyHavenMaterialX/polyhaven_polystrylene.png" width=256px><br>
483+
<img src="https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/examples/PolyHaven/aerial_rocks_02_1k_materialx/aerial_rocks_02_1k.png" width="256px"><br>
483484
Polystyrene
484485
</td>
485486
<td>
486-
<img src="https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/data/PolyHavenMaterialX/polyhave_wood_trunk_wall.png" width=256px><br>
487+
<img src="https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/examples/PolyHaven/wood_trunk_wall_1k_materialx/wood_trunk_wall_1k.png" width="256px"><br>
487488
Wood Trunk Wall
488489
</td>
489490
</tr>
@@ -604,7 +605,7 @@ <h3>Package Building</h3>
604605
</div></code></pre>
605606
</div><p><div class="container-fluid p-2 rounded-4 border border-secondary border-rounded">
606607
<h3>Command Line Interfaces</h3>
607-
<h4>Python</h4>
608+
<h4>PhysicallyBased</h4>
608609
<ul>
609610
<li>
610611
<p>Query all materials fom PhysicallyBased and convert them to all support shading models. Save the material list and corresponding MaterialX files in the default output location. The build will include this information Python package under the <code>data</code> folder.</p>
@@ -614,11 +615,17 @@ <h4>Python</h4>
614615
<pre class="hljs"><code><div>materialxMaterials physbased
615616
</div></code></pre>
616617
</li>
618+
</ul>
619+
<h4>GPUOpen</h4>
620+
<ul>
617621
<li>
618622
<p>Query all materials fom GPUOpen. Extract out a few material packages (zip). Save the material lists, material names and unzipped packages (MaterialX and images) in the default output location. The build will include this information Python package under the <code>data</code> folder.</p>
619623
<pre class="hljs"><code><div>materialxMaterials gpuopen --materialNames=1 --saveMaterials=1
620624
</div></code></pre>
621625
</li>
626+
</ul>
627+
<h4>ambientCG</h4>
628+
<ul>
622629
<li>
623630
<p>Download the materials list fom ambientCG:</p>
624631
<pre class="hljs"><code><div>materialxMaterials acg --saveMaterials True
@@ -630,28 +637,56 @@ <h4>Python</h4>
630637
<pre class="hljs"><code><div>materialxMaterials acg --downloadMaterial <span class="hljs-string">"WoodFloor038"</span> --downloadResolution 2
631638
</div></code></pre>
632639
</li>
640+
</ul>
641+
<h4>PolyHaven</h4>
642+
<ul>
633643
<li>
634-
<p>Examine all texture assets on PolyHaven, and find all ones which have MaterialX resources. Does not download the asset.</p>
635-
<pre class="hljs"><code><div>polyHavenLoaderCmd.py --fetch --download_id=<span class="hljs-string">""</span>
644+
<p>Examine all texture assets on PolyHaven, and find all ones which have MaterialX resources.</p>
645+
<pre class="hljs"><code><div>polyHavenLoaderCmd.py -fe
636646
</div></code></pre>
637647
</li>
638648
<li>
639-
<p>Extract out a specific MateriaX asset with a given identifier.</p>
640-
<pre class="hljs"><code><div>polyHavenLoaderCmd.py --fetch --download_id=<span class="hljs-string">"aerial_asphalt_01"</span>
649+
<p>The extraction can be filtered by identifier:</p>
650+
<pre class="hljs"><code><div>polyHavenLoaderCmd.py -fe -id=<span class="hljs-string">"aerial_asphalt_01"</span>
641651
</div></code></pre>
642652
</li>
643653
<li>
644-
<p>Extract out the first 10 MaterialX assets.</p>
645-
<pre class="hljs"><code><div>polyHavenLoaderCmd.py --fetch -c 10
654+
<p>or by count. In this case the first 10 assets with MaterialX resources will be extracted.</p>
655+
<pre class="hljs"><code><div>polyHavenLoaderCmd.py -fe -c 10
656+
</div></code></pre>
657+
</li>
658+
</ul>
659+
<p>Note that this does not download any of the content for each asset, but instead<br>
660+
extract information into a file called <code>polyhaven_materialx_assets.json</code> for later usage.. The build process will include a file with this name under the <code>data</code> as part of the Python package. This avoids having to query the PolyHaven API repeatedly.</p>
661+
<ul>
662+
<li>
663+
<p>The user can either use a local version of this file by specifying the path the file as shown below, where an optional <code>--data_folder</code> argument can be used to specify the location of the file.</p>
664+
<pre class="hljs"><code><div>python -m materialxMaterials polyhaven --load [--data-folder &lt;myfolder location&gt; -id=<span class="hljs-string">"aerial_asphalt_01"</span>
646665
</div></code></pre>
647666
</li>
648667
<li>
649-
<p>Scan locally downloaded MaterialX asset information to download.</p>
650-
<pre class="hljs"><code><div>python -m materialxMaterials polyhaven --load --download_id=<span class="hljs-string">"aerial_asphalt_01"</span>
668+
<p>If <code>--load</code> is not specified then the the packaged will be used by default.</p>
669+
<pre class="hljs"><code><div>python -m materialxMaterials polyhaven -id=<span class="hljs-string">"aerial_asphalt_01"</span>
651670
</div></code></pre>
652671
</li>
653672
</ul>
654-
<h5>NodeJS</h5>
673+
<p>Download options include:</p>
674+
<ol>
675+
<li>
676+
<p><code>-x</code> or <code>--extract</code> to extract the content of the package (MaterialX and images) into a folder. By default the package will be downloaded but not extracted.</p>
677+
</li>
678+
<li>
679+
<p><code>-exr</code> or <code>--keep_exr</code> to keep the EXR files if they are included in the package. By default the equivalent PNG files are downloaded or EXR files are converted to PNG files. The latter requires the <code>OpenImageIO</code> package to be installed.</p>
680+
<ul>
681+
<li>Note that if EXR images are remapped then the MaterialX file references<br>
682+
are also remapped in the <code>.mtlx</code> file.</li>
683+
</ul>
684+
</li>
685+
<li>
686+
<p><code>-r</code> or <code>--download_resolution</code> to specify the resolution of the images to download. By default the lowest resolution images are downloaded. The user can specify &quot;1k&quot;, &quot;2k&quot;, &quot;4k&quot; or &quot;8k&quot;.</p>
687+
</li>
688+
</ol>
689+
<h4>GPUOpen (NodeJS)</h4>
655690
<p>The utility can be run from the <code>javascript\JsGPUOpenLoaderPackage</code> folder as follows:</p>
656691
<pre class="hljs"><code><div>npm start -- [&lt;arguments&gt;]
657692
</div></code></pre>

README.md

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,18 @@ See the <a href="https://kwokcb.github.io/materialxMaterials/examples/index.html
121121
<td>
122122
<b>PolyHaven</b>
123123
<table>
124+
<!-- https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/ -->
124125
<tr>
125126
<td>
126-
<img src="https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/data/PolyHavenMaterialX/polyhaven_aerial_asphalt_1.png" width=256px%><br>
127-
Ashphalt
127+
<img src="https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/examples/PolyHaven/aerial_asphalt_01_1k_materialx/aerial_asphalt_01_1k.png" width="256px"><br>
128+
Ashphalt 1
128129
</td>
129130
<td>
130-
<img src="https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/data/PolyHavenMaterialX/polyhaven_polystrylene.png" width=256px><br>
131+
<img src="https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/examples/PolyHaven/aerial_rocks_02_1k_materialx/aerial_rocks_02_1k.png" width="256px"><br>
131132
Polystyrene
132133
</td>
133134
<td>
134-
<img src="https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/data/PolyHavenMaterialX/polyhave_wood_trunk_wall.png" width=256px><br>
135+
<img src="https://kwokcb.github.io/materialxMaterials/src/materialxMaterials/examples/PolyHaven/wood_trunk_wall_1k_materialx/wood_trunk_wall_1k.png" width="256px"><br>
135136
Wood Trunk Wall
136137
</td>
137138
</tr>
@@ -295,7 +296,7 @@ npm run [build/start] # Build distribution or run the package
295296

296297
<h3>Command Line Interfaces</h3>
297298

298-
<h4>Python</h4>
299+
<h4>PhysicallyBased</h4>
299300

300301
- Query all materials fom PhysicallyBased and convert them to all support shading models. Save the material list and corresponding MaterialX files in the default output location. The build will include this information Python package under the <code>data</code> folder.
301302

@@ -307,13 +308,16 @@ npm run [build/start] # Build distribution or run the package
307308
```sh
308309
materialxMaterials physbased
309310
```
311+
<h4>GPUOpen</h4>
310312

311313
- Query all materials fom GPUOpen. Extract out a few material packages (zip). Save the material lists, material names and unzipped packages (MaterialX and images) in the default output location. The build will include this information Python package under the <code>data</code> folder.
312314

313315
```sh
314316
materialxMaterials gpuopen --materialNames=1 --saveMaterials=1
315317
```
316318

319+
<h4>ambientCG</h4>
320+
317321
- Download the materials list fom ambientCG:
318322

319323
```sh
@@ -326,28 +330,50 @@ package where the images are 2K PNG files:
326330
```sh
327331
materialxMaterials acg --downloadMaterial "WoodFloor038" --downloadResolution 2
328332
```
329-
- Examine all texture assets on PolyHaven, and find all ones which have MaterialX resources. Does not download the asset.
333+
334+
<h4>PolyHaven</h4>
335+
336+
- Examine all texture assets on PolyHaven, and find all ones which have MaterialX resources.
330337

331338
```sh
332-
polyHavenLoaderCmd.py --fetch --download_id=""
339+
polyHavenLoaderCmd.py -fe
333340
```
334341

335-
- Extract out a specific MateriaX asset with a given identifier.
342+
- The extraction can be filtered by identifier:
336343
```sh
337-
polyHavenLoaderCmd.py --fetch --download_id="aerial_asphalt_01"
344+
polyHavenLoaderCmd.py -fe -id="aerial_asphalt_01"
338345
```
339-
- Extract out the first 10 MaterialX assets.
346+
- or by count. In this case the first 10 assets with MaterialX resources will be extracted.
340347
```sh
341-
polyHavenLoaderCmd.py --fetch -c 10
348+
polyHavenLoaderCmd.py -fe -c 10
342349
```
343350

344-
- Scan locally downloaded MaterialX asset information to download.
351+
Note that this does not download any of the content for each asset, but instead
352+
extract information into a file called `polyhaven_materialx_assets.json` for later usage.. The build process will include a file with this name under the <code>data</code> as part of the Python package. This avoids having to query the PolyHaven API repeatedly.
353+
354+
- The user can either use a local version of this file by specifying the path the file as shown below, where an optional `--data_folder` argument can be used to specify the location of the file.
345355

346356
```sh
347-
python -m materialxMaterials polyhaven --load --download_id="aerial_asphalt_01"
357+
python -m materialxMaterials polyhaven --load [--data-folder <myfolder location> -id="aerial_asphalt_01"
348358
```
349359
350-
<h5>NodeJS</h5>
360+
- If `--load` is not specified then the the packaged will be used by default.
361+
362+
```sh
363+
python -m materialxMaterials polyhaven -id="aerial_asphalt_01"
364+
```
365+
366+
Download options include:
367+
368+
1. `-x` or `--extract` to extract the content of the package (MaterialX and images) into a folder. By default the package will be downloaded but not extracted.
369+
370+
2. `-exr` or `--keep_exr` to keep the EXR files if they are included in the package. By default the equivalent PNG files are downloaded or EXR files are converted to PNG files. The latter requires the `OpenImageIO` package to be installed.
371+
- Note that if EXR images are remapped then the MaterialX file references
372+
are also remapped in the `.mtlx` file.
373+
374+
3. `-r` or `--download_resolution` to specify the resolution of the images to download. By default the lowest resolution images are downloaded. The user can specify "1k", "2k", "4k" or "8k".
375+
376+
<h4>GPUOpen (NodeJS)</h4>
351377
352378
The utility can be run from the `javascript\JsGPUOpenLoaderPackage` folder as follows:
353379
5.13 MB
Binary file not shown.
9.86 MB
Binary file not shown.

0 commit comments

Comments
 (0)