From 2ded0a73b30cedec47f419d1aa76559b5137ffbe Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 11 Apr 2021 10:38:42 +0200 Subject: [PATCH] #5585: Expose material flags --- install/scripts/materialtest.py | 7 +++++++ .../interfaces/ShaderSystemInterface.cpp | 19 +++++++++++++++++++ .../script/interfaces/ShaderSystemInterface.h | 17 +++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/install/scripts/materialtest.py b/install/scripts/materialtest.py index 8f2d1d7321..7acd57abd9 100644 --- a/install/scripts/materialtest.py +++ b/install/scripts/materialtest.py @@ -36,16 +36,23 @@ newMaterial.setSortRequest(45.3) +print('Cull type: {0}'.format(newMaterial.getCullType())) +print('Clamp type: {0}'.format(newMaterial.getClampType())) +print('Flags: {0}'.format(newMaterial.getMaterialFlags())) + # There are a couple of pre-defined sort requests, corresponding to the engine code newMaterial.setSortRequest(dr.Material.SortRequest.NEAREST) newMaterial.setClampType(dr.Material.ClampType.NOREPEAT) # clamp newMaterial.setCullType(dr.Material.CullType.NONE) # twosided newMaterial.setPolygonOffset(0.3) +newMaterial.setMaterialFlag(dr.Material.Flag.NOSHADOWS) print('Full Material definition:\n{0}\n{{{1}}}'.format(newMaterial.getName(), newMaterial.getDefinition())) GlobalMaterialManager.saveMaterial(newMaterial.getName()) +newMaterial.clearMaterialFlag(dr.Material.Flag.NOSHADOWS) + fullPath = GlobalFileSystem.findFile(filename) + filename print(fullPath) os.remove(fullPath) diff --git a/plugins/script/interfaces/ShaderSystemInterface.cpp b/plugins/script/interfaces/ShaderSystemInterface.cpp index 2ff9a163ed..433866ede2 100644 --- a/plugins/script/interfaces/ShaderSystemInterface.cpp +++ b/plugins/script/interfaces/ShaderSystemInterface.cpp @@ -114,6 +114,22 @@ void ShaderSystemInterface::registerInterface(py::module& scope, py::dict& globa .value("ALPHAZEROCLAMP", CLAMP_ALPHAZEROCLAMP) .export_values(); + py::enum_(material, "Flag") + .value("NOSHADOWS", Material::FLAG_NOSHADOWS) + .value("NOSELFSHADOW", Material::FLAG_NOSELFSHADOW) + .value("FORCESHADOWS", Material::FLAG_FORCESHADOWS) + .value("NOOVERLAYS", Material::FLAG_NOOVERLAYS) + .value("FORCEOVERLAYS", Material::FLAG_FORCEOVERLAYS) + .value("TRANSLUCENT", Material::FLAG_TRANSLUCENT) + .value("FORCEOPAQUE", Material::FLAG_FORCEOPAQUE) + .value("NOFOG", Material::FLAG_NOFOG) + .value("NOPORTALFOG", Material::FLAG_NOPORTALFOG) + .value("UNSMOOTHEDTANGENTS", Material::FLAG_UNSMOOTHEDTANGENTS) + .value("MIRROR", Material::FLAG_MIRROR) + .value("POLYGONOFFSET", Material::FLAG_POLYGONOFFSET) + .value("ISLIGHTGEMSURF", Material::FLAG_ISLIGHTGEMSURF) + .export_values(); + material.def(py::init()); material.def("getName", &ScriptMaterial::getName); material.def("getShaderFileName", &ScriptMaterial::getShaderFileName); @@ -138,6 +154,9 @@ void ShaderSystemInterface::registerInterface(py::module& scope, py::dict& globa material.def("setClampType", &ScriptMaterial::setClampType); material.def("getCullType", &ScriptMaterial::getCullType); material.def("setCullType", &ScriptMaterial::setCullType); + material.def("getMaterialFlags", &ScriptMaterial::getMaterialFlags); + material.def("setMaterialFlag", &ScriptMaterial::setMaterialFlag); + material.def("clearMaterialFlag", &ScriptMaterial::clearMaterialFlag); // Expose the MaterialVisitor interface diff --git a/plugins/script/interfaces/ShaderSystemInterface.h b/plugins/script/interfaces/ShaderSystemInterface.h index 81bb70f34c..1978375b9a 100644 --- a/plugins/script/interfaces/ShaderSystemInterface.h +++ b/plugins/script/interfaces/ShaderSystemInterface.h @@ -141,6 +141,23 @@ class ScriptMaterial if (_material) _material->setCullType(type); } + int getMaterialFlags() const + { + return _material ? _material->getMaterialFlags() : 0; + } + + void setMaterialFlag(Material::Flags flag) + { + throwIfMaterialCannotBeModified(); + if (_material) _material->setMaterialFlag(flag); + } + + void clearMaterialFlag(Material::Flags flag) + { + throwIfMaterialCannotBeModified(); + if (_material) _material->clearMaterialFlag(flag); + } + private: void throwIfMaterialCannotBeModified() {