Skip to content

Commit

Permalink
#5585: Expose material flags
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Apr 11, 2021
1 parent 27eaae7 commit 2ded0a7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions install/scripts/materialtest.py
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions plugins/script/interfaces/ShaderSystemInterface.cpp
Expand Up @@ -114,6 +114,22 @@ void ShaderSystemInterface::registerInterface(py::module& scope, py::dict& globa
.value("ALPHAZEROCLAMP", CLAMP_ALPHAZEROCLAMP)
.export_values();

py::enum_<Material::Flags>(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<const MaterialPtr&>());
material.def("getName", &ScriptMaterial::getName);
material.def("getShaderFileName", &ScriptMaterial::getShaderFileName);
Expand All @@ -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

Expand Down
17 changes: 17 additions & 0 deletions plugins/script/interfaces/ShaderSystemInterface.h
Expand Up @@ -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()
{
Expand Down

0 comments on commit 2ded0a7

Please sign in to comment.