From 2cf58a16b64f480dbe05db0ceeeb186fbdc7d1f0 Mon Sep 17 00:00:00 2001 From: Jonathan Feldstein Date: Mon, 3 May 2021 09:22:03 -0400 Subject: [PATCH] Adds flatten filenames capability to export. (#1180) Co-authored-by: Jonathan Feldstein --- source/MaterialXFormat/XmlIo.cpp | 13 +++++++++++++ source/MaterialXFormat/XmlIo.h | 9 +++++++++ source/MaterialXRuntime/RtFileIo.cpp | 6 ++++++ source/MaterialXRuntime/RtFileIo.h | 13 +++++++++++-- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/source/MaterialXFormat/XmlIo.cpp b/source/MaterialXFormat/XmlIo.cpp index 27e22c37f6..bdf5d400e2 100644 --- a/source/MaterialXFormat/XmlIo.cpp +++ b/source/MaterialXFormat/XmlIo.cpp @@ -6,6 +6,7 @@ #include #include +#include #include @@ -383,18 +384,30 @@ string writeToXmlString(DocumentPtr doc, const XmlWriteOptions* writeOptions) void exportToXmlStream(DocumentPtr doc, std::ostream& stream, const XmlExportOptions* exportOptions) { mergeLooks(doc, exportOptions); + if (exportOptions && exportOptions->flattenFilenames) + { + flattenFilenames(doc, exportOptions->imageSearchPath, exportOptions->stringResolver); + } writeToXmlStream(doc, stream, exportOptions); } void exportToXmlFile(DocumentPtr doc, const FilePath& filename, const XmlExportOptions* exportOptions) { mergeLooks(doc, exportOptions); + if (exportOptions && exportOptions->flattenFilenames) + { + flattenFilenames(doc, exportOptions->imageSearchPath, exportOptions->stringResolver); + } writeToXmlFile(doc, filename, exportOptions); } string exportToXmlString(DocumentPtr doc, const XmlExportOptions* exportOptions) { mergeLooks(doc, exportOptions); + if (exportOptions && exportOptions->flattenFilenames) + { + flattenFilenames(doc, exportOptions->imageSearchPath, exportOptions->stringResolver); + } return writeToXmlString(doc, exportOptions); } diff --git a/source/MaterialXFormat/XmlIo.h b/source/MaterialXFormat/XmlIo.h index 096bef4ad6..21fc769bea 100644 --- a/source/MaterialXFormat/XmlIo.h +++ b/source/MaterialXFormat/XmlIo.h @@ -80,6 +80,15 @@ class XmlExportOptions : public XmlWriteOptions /// The name of the lookgroup to merge std::string lookGroupToMerge; + + /// Whether to flatten filenames + bool flattenFilenames; + + /// Search path used for flattening filenames + FileSearchPath imageSearchPath; + + /// String resolver applied during flattening filenames + StringResolverPtr stringResolver; }; /// @class ExceptionParseError diff --git a/source/MaterialXRuntime/RtFileIo.cpp b/source/MaterialXRuntime/RtFileIo.cpp index 4a0e00c9ea..a1e65fd8a3 100644 --- a/source/MaterialXRuntime/RtFileIo.cpp +++ b/source/MaterialXRuntime/RtFileIo.cpp @@ -1726,6 +1726,9 @@ void RtFileIo::exportDocument(std::ostream& stream, const RtExportOptions* optio xmlExportOptions.writeXIncludeEnable = options->writeIncludes; xmlExportOptions.mergeLooks = options->mergeLooks; xmlExportOptions.lookGroupToMerge = options->lookGroupToMerge; + xmlExportOptions.flattenFilenames = options->flattenFilenames; + xmlExportOptions.imageSearchPath = options->imageSearchPath; + xmlExportOptions.stringResolver = options->stringResolver; } exportToXmlStream(document, stream, &xmlExportOptions); } @@ -1743,6 +1746,9 @@ void RtFileIo::exportDocument(const FilePath& documentPath, const RtExportOption xmlExportOptions.writeXIncludeEnable = options->writeIncludes; xmlExportOptions.mergeLooks = options->mergeLooks; xmlExportOptions.lookGroupToMerge = options->lookGroupToMerge; + xmlExportOptions.flattenFilenames = options->flattenFilenames; + xmlExportOptions.imageSearchPath = options->imageSearchPath; + xmlExportOptions.stringResolver = options->stringResolver; } exportToXmlFile(document, documentPath, &xmlExportOptions); } diff --git a/source/MaterialXRuntime/RtFileIo.h b/source/MaterialXRuntime/RtFileIo.h index e3d6ac13b3..48c49195dd 100644 --- a/source/MaterialXRuntime/RtFileIo.h +++ b/source/MaterialXRuntime/RtFileIo.h @@ -91,11 +91,20 @@ class RtExportOptions : public RtWriteOptions ~RtExportOptions() { } - // Whether to merge all of the looks/lookgroups into a single look + /// Whether to merge all of the looks/lookgroups into a single look bool mergeLooks; - // The name of the lookgroup to merge + /// The name of the lookgroup to merge std::string lookGroupToMerge; + + /// Whether to flatten filenames + bool flattenFilenames; + + /// Search path used for flattening filenames + FileSearchPath imageSearchPath; + + /// String resolver applied during flattening filenames + StringResolverPtr stringResolver; }; /// API for read and write of data from MaterialX files