Skip to content

Commit

Permalink
Adds flatten filenames capability to export. (#1180)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Feldstein <[email protected]>
  • Loading branch information
feldstj and feldstj authored May 3, 2021
1 parent 278bd45 commit 2cf58a1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
13 changes: 13 additions & 0 deletions source/MaterialXFormat/XmlIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <MaterialXFormat/XmlIo.h>

#include <MaterialXFormat/PugiXML/pugixml.hpp>
#include <MaterialXFormat/Util.h>

#include <MaterialXCore/Types.h>

Expand Down Expand Up @@ -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);
}

Expand Down
9 changes: 9 additions & 0 deletions source/MaterialXFormat/XmlIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions source/MaterialXRuntime/RtFileIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
13 changes: 11 additions & 2 deletions source/MaterialXRuntime/RtFileIo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2cf58a1

Please sign in to comment.