Skip to content

Commit

Permalink
Add save material option (#571)
Browse files Browse the repository at this point in the history
* Add save material option

* Fix the wrong assignment

* Persist uniform changes into the material document

* Change the MaterialX document on every edit

* Skip stdlib and extra XIncludes

* Remove compile warnings

* Code review requests

* Fix integer enum on properties

* Remove compile warnings

* Fix compile error: lambda capture 'INVALID_INDEX' is not required
  • Loading branch information
fleith authored Aug 8, 2019
1 parent 0a506d5 commit 22e8091
Show file tree
Hide file tree
Showing 8 changed files with 272 additions and 129 deletions.
4 changes: 4 additions & 0 deletions source/MaterialXRender/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ unsigned int getUIProperties(ConstValueElementPtr nodeDefElement, UIProperties&
{
uiProperties.enumerationValues.push_back(Value::createValue(enumerationValues));
}
if(uiProperties.enumeration.size() != uiProperties.enumerationValues.size())
{
throw std::runtime_error("Every enum must have a value!");
}
propertyCount++;
}
}
Expand Down
54 changes: 30 additions & 24 deletions source/MaterialXTest/RenderUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,31 @@ void ShaderRenderTester::printRunLog(const RenderProfileTimes &profileTimes,
//}
}

void ShaderRenderTester::loadDependentLibraries(GenShaderUtil::TestSuiteOptions options, mx::FilePath searchPath, mx::DocumentPtr& dependLib)
{
dependLib = mx::createDocument();

const mx::StringVec libraries = { "stdlib", "pbrlib", "lights" };
mx::loadLibraries(libraries, searchPath, dependLib, nullptr);
for (size_t i = 0; i < options.externalLibraryPaths.size(); i++)
{
const mx::FilePath& extraPath = options.externalLibraryPaths[i];
mx::FilePathVec libraryFiles = extraPath.getFilesInDirectory("mtlx");
for (size_t l = 0; l < libraryFiles.size(); l++)
{
std::cout << "Extra library path: " << (extraPath / libraryFiles[l]).asString() << std::endl;
mx::loadLibrary((extraPath / libraryFiles[l]), dependLib);
}
}

// Load shader definitions used in the test suite.
loadLibrary(mx::FilePath::getCurrentPath() / mx::FilePath("libraries/bxdf/standard_surface.mtlx"), dependLib);
loadLibrary(mx::FilePath::getCurrentPath() / mx::FilePath("libraries/bxdf/usd_preview_surface.mtlx"), dependLib);

// Load any addition per validator libraries
loadAdditionalLibraries(dependLib, options);
}

bool ShaderRenderTester::validate(const mx::FilePathVec& testRootPaths, const mx::FilePath optionsFilePath)
{
// Test has been turned off so just do nothing.
Expand Down Expand Up @@ -143,36 +168,17 @@ bool ShaderRenderTester::validate(const mx::FilePathVec& testRootPaths, const mx

ioTimer.endTimer();

// Add files to skip
addSkipFiles();

// Library search path
mx::FilePath searchPath = mx::FilePath::getCurrentPath() / mx::FilePath("libraries");

// Load in the library dependencies once
// This will be imported in each test document below
ioTimer.startTimer();
mx::DocumentPtr dependLib = mx::createDocument();

// Add files to skip
addSkipFiles();

const mx::StringVec libraries = { "stdlib", "pbrlib", "lights" };
mx::loadLibraries(libraries, searchPath, dependLib, nullptr);
for (size_t i = 0; i < options.externalLibraryPaths.size(); i++)
{
const mx::FilePath& extraPath = options.externalLibraryPaths[i];
mx::FilePathVec libraryFiles = extraPath.getFilesInDirectory("mtlx");
for (size_t l = 0; l < libraryFiles.size(); l++)
{
std::cout << "Extra library path: " << (extraPath / libraryFiles[l]).asString() << std::endl;
mx::loadLibrary((extraPath / libraryFiles[l]), dependLib);
}
}

// Load shader definitions used in the test suite.
loadLibrary(mx::FilePath::getCurrentPath() / mx::FilePath("libraries/bxdf/standard_surface.mtlx"), dependLib);
loadLibrary(mx::FilePath::getCurrentPath() / mx::FilePath("libraries/bxdf/usd_preview_surface.mtlx"), dependLib);

// Load any addition per validator libraries
loadAdditionalLibraries(dependLib, options);
mx::DocumentPtr dependLib;
loadDependentLibraries(options, searchPath, dependLib);
ioTimer.endTimer();

// Create validators and generators
Expand Down
4 changes: 4 additions & 0 deletions source/MaterialXTest/RenderUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ class ShaderRenderTester
_skipFiles.insert("default_viewer_lights.mtlx");
}

// Load dependencies
void loadDependentLibraries(GenShaderUtil::TestSuiteOptions options, mx::FilePath searchPath,
mx::DocumentPtr& dependLib);

// Load any additional libraries requird by the generator
virtual void loadAdditionalLibraries(mx::DocumentPtr /*dependLib*/,
GenShaderUtil::TestSuiteOptions& /*options*/) {};
Expand Down
Loading

0 comments on commit 22e8091

Please sign in to comment.