diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..2c9ff0d --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: kwokcb diff --git a/README.md b/README.md index 424bbfb..82e1a7d 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,25 @@ The supported targets are: Any future specification changes will go into MaterialX core as noted by issues logged [here](https://github.com/AcademySoftwareFoundation/MaterialX/issues) +A [Khronos branch](https://github.com/KhronosGroup/MaterialX/tree/gltf_mtlx_interop) using this library is available in a branch. This +currently includes integration in the MaterialXViewer and +MaterialX GraphEditor. Note that no pipeline tools are integrated there (such as baking) hence export expects the target nodegraph denoted in the next section. + + +
+ +
+Figure: Snapshot of some sample assets imported into the MaterialX GraphEditor + Some of the documentation for this site will be migrating to the [MaterialX Learning Site](https://kwokcb.github.io/MaterialX_Learn/) (As of August, 2023). **Stay Tuned** ## 2. Target MaterialX Representation -There is a specific target MaterialX node graph configuration which is the target for distillation / export as well as remixing / import. +There is a specific target MaterialX node graph configuration which is the target for distillation / export as well as remixing / import. These nodegraphs can be created in various editors including Maya, Houdini, etc and USD HDStorm integrations in general as long as the appropriate MaterialX library version is used. +
Figure: Layout of "target" nodegraphs. Note that 0 or more upstream pattern graphs are supported for inputs to the root PBR shader The definitions for these nodes can be found as part of the [core MaterialX library definitions](https://github.com/kwokcb/MaterialX/blob/main/libraries/bxdf/gltf_pbr.mtlx) @@ -191,7 +202,7 @@ graph LR; style IMPL_gltf_pbr_surfaceshader_alpha_cutoff fill:#0bb, color:#111 ``` - +See [here](https://kwokcb.github.io/MaterialX_Learn/documents/definitions/gltf_pbr.html) for a description of the node. diff --git a/build_no_update.bat b/build_no_update.bat new file mode 100644 index 0000000..7c9cd58 --- /dev/null +++ b/build_no_update.bat @@ -0,0 +1,18 @@ +@echo off + +mkdir build +cd build +cmake -DGLTF_MATERIALX_TEST_RENDER=ON -G "Visual Studio 16 2019" -A "x64" -DCMAKE_BUILD_TYPE=RelWithDebInfo .. +cmake --build . --target install --config RelWithDebInfo +ctest -VV --output-on-failure --build-config RelWithDebInfo -j1 -R glTF + +REM cd .. +REM build\installed\bin\glTF2Mtlx --gltf ./resources/ABeautifulGame/glTF/ABeautifulGame.gltf --assignments +REM echo "-- Converstion to MTLTX from GLTF --" > conversion_log.txt +REM cat ./resources/ABeautifulGame/glTF/ABeautifulGame.gltf.mtlx >> conversion_log.txt + +REM build\installed\bin\glTF2Mtlx --mtlx ./resources/ABeautifulGame/glTF/ABeautifulGame.gltf.mtlx +REM echo "-- Converstion to GLTF from MTLX --" >> conversion_log.txt +REM cat ./resources/ABeautifulGame/glTF/ABeautifulGame.gltf.mtlx._converted.gltf >> conversion_log.txt + + diff --git a/docs/glTF_import_graphEditor.png b/docs/glTF_import_graphEditor.png new file mode 100644 index 0000000..8fc4a91 Binary files /dev/null and b/docs/glTF_import_graphEditor.png differ diff --git a/docs/gltf_import-graphEditor2.png b/docs/gltf_import-graphEditor2.png new file mode 100644 index 0000000..3f5c9f3 Binary files /dev/null and b/docs/gltf_import-graphEditor2.png differ diff --git a/source/MaterialXglTF/GltfMaterialHandler.cpp b/source/MaterialXglTF/GltfMaterialHandler.cpp index bd45e8f..47af00f 100644 --- a/source/MaterialXglTF/GltfMaterialHandler.cpp +++ b/source/MaterialXglTF/GltfMaterialHandler.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -280,9 +281,7 @@ void GltfMaterialHandler::translateShaders(DocumentPtr doc, std::ostream& logger // const string TARGET_GLTF = "gltf_pbr"; ShaderTranslatorPtr translator = ShaderTranslator::create(); - vector materialNodes; - std::unordered_set shaderOutputs; - findRenderableMaterialNodes(doc, materialNodes, false, shaderOutputs); + vector materialNodes = findRenderableMaterialNodes(doc); for (auto elem : materialNodes) { NodePtr materialNode = elem->asA(); @@ -384,7 +383,8 @@ bool GltfMaterialHandler::save(const FilePath& filePath, std::ostream& logger) const string gltf_versionString = "2.0"; data->asset.generator = const_cast((new string("MaterialX " + mtlx_versionString + " to glTF " + gltf_versionString + " generator"))->c_str());; data->asset.version = const_cast((new string(gltf_versionString))->c_str()); - data->asset.copyright = "Created via glTF translation utilities found here: https://github.com/kwokcb/glTF_MaterialX"; + std::string *copyright = new string("Created via glTF translation utilities found here : https://github.com/kwokcb/glTF_MaterialX"); + data->asset.copyright = const_cast((copyright)->c_str()); // Scan for PBR shader nodes const string PBR_CATEGORY_STRING("gltf_pbr"); @@ -626,8 +626,8 @@ bool GltfMaterialHandler::save(const FilePath& filePath, std::ostream& logger) NodePtr ormNode= nullptr; imageNode = nullptr; const string extractCategory("extract"); - bool fileNameMismatch = false; - bool separateOcclusion = false; + //bool fileNameMismatch = false; + //bool separateOcclusion = false; for (size_t e = 0; e < 3; e++) { const string& inputName = extractInputs[e]; @@ -800,16 +800,16 @@ bool GltfMaterialHandler::save(const FilePath& filePath, std::ostream& logger) } ormFilename.removeExtension(); - FilePath filePath = ormFilename.asString() + "_combined.png"; + FilePath ormfilePath = ormFilename.asString() + "_combined.png"; bool saved = loader->saveImage(filePath, outputImage); logger << " --> Write ORM image to disk: " << filePath.asString() << ". SUCCESS: " << std::to_string(saved) << std::endl; cgltf_texture* texture = &(textureList[imageIndex]); roughness.metallic_roughness_texture.texture = texture; - initialize_cgtlf_texture(*texture, imageNode->getNamePath(), filePath, + initialize_cgtlf_texture(*texture, imageNode->getNamePath(), ormfilePath, &(imageList[imageIndex])); imageIndex++; - logger << " --> Write cgltf image name: " << filePath.asString() << std::endl; + logger << " --> Write cgltf image name: " << ormfilePath.asString() << std::endl; } } } diff --git a/source/MaterialXglTF/GltfMaterialHandler.h b/source/MaterialXglTF/GltfMaterialHandler.h index ae7ea7e..3031459 100644 --- a/source/MaterialXglTF/GltfMaterialHandler.h +++ b/source/MaterialXglTF/GltfMaterialHandler.h @@ -49,7 +49,7 @@ class MX_GLTF_API MaterialHandler /// to perform actions such as shader translation and baking. /// /// Document to modify - virtual void translateShaders(DocumentPtr doc, std::ostream& log) {}; + virtual void translateShaders(DocumentPtr /*doc*/, std::ostream& /*log*/) {}; /// /// Set document containing MaterialX definitions. This includes core library diff --git a/source/MaterialXglTF/GltfMaterialUtil.cpp b/source/MaterialXglTF/GltfMaterialUtil.cpp index 099c014..6eee932 100644 --- a/source/MaterialXglTF/GltfMaterialUtil.cpp +++ b/source/MaterialXglTF/GltfMaterialUtil.cpp @@ -34,6 +34,9 @@ bool GltfMaterialUtil::mtlx2glTF(MaterialHandlerPtr gltfMTLXLoader, bool GltfMaterialUtil::haveSingleDocBake(const FilePath& errorFile) { +#ifndef MTLX_TRANSLATE_SHADER + return false; +#endif FilePath shaderTranslator(MTLX_TRANSLATE_SHADER); if (shaderTranslator.isEmpty()) {