Skip to content

Commit

Permalink
#5585: Expose setShaderFileName, add script test to save material
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Apr 11, 2021
1 parent e9748dd commit 2abcd93
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions install/scripts/materialtest.py
@@ -1,3 +1,5 @@
import os

# Some interface tests

print("bc_rat can be modified" if GlobalMaterialManager.materialCanBeModified('bc_rat') else "bc_rat cannot be modified")
Expand Down Expand Up @@ -27,8 +29,16 @@
# Do something with the new material
print('The existing material reference now has the name {0}'.format(newMaterial.getName()))

filename = 'materials/_python_test.mtr'
newMaterial.setShaderFileName(filename)
newMaterial.setEditorImageExpressionFromString('textures/common/caulk')

GlobalMaterialManager.saveMaterial(newMaterial.getName())

fullPath = GlobalFileSystem.findFile(filename) + filename
print(fullPath)
os.remove(fullPath)

print("Removing {0} again...".format(newMaterial.getName()))
GlobalMaterialManager.removeMaterial(newMaterial.getName())

Expand Down
1 change: 1 addition & 0 deletions plugins/script/interfaces/ShaderSystemInterface.cpp
Expand Up @@ -87,6 +87,7 @@ void ShaderSystemInterface::registerInterface(py::module& scope, py::dict& globa
material.def(py::init<const MaterialPtr&>());
material.def("getName", &ScriptMaterial::getName);
material.def("getShaderFileName", &ScriptMaterial::getShaderFileName);
material.def("setShaderFileName", &ScriptMaterial::setShaderFileName);
material.def("getDescription", &ScriptMaterial::getDescription);
material.def("getDefinition", &ScriptMaterial::getDefinition);
material.def("isVisible", &ScriptMaterial::isVisible);
Expand Down
6 changes: 6 additions & 0 deletions plugins/script/interfaces/ShaderSystemInterface.h
Expand Up @@ -33,6 +33,12 @@ class ScriptMaterial
return _material ? _material->getShaderFileName() : "";
}

void setShaderFileName(const std::string& filename)
{
throwIfMaterialCannotBeModified();
if (_material) _material->setShaderFileName(filename);
}

std::string getDescription() {
return _material ? _material->getDescription() : "";
}
Expand Down

0 comments on commit 2abcd93

Please sign in to comment.