diff --git a/plugins/script/interfaces/ShaderSystemInterface.cpp b/plugins/script/interfaces/ShaderSystemInterface.cpp index 7f86fbe3bd..1943bb0243 100644 --- a/plugins/script/interfaces/ShaderSystemInterface.cpp +++ b/plugins/script/interfaces/ShaderSystemInterface.cpp @@ -31,43 +31,46 @@ void ShaderSystemInterface::foreachShader(ShaderVisitor& visitor) // Note: foreachShader only traverses the loaded materials, use a small adaptor to traverse all known ShaderNameToShaderWrapper adaptor(visitor); - GlobalMaterialManager().foreachShaderName(boost::bind(&ShaderNameToShaderWrapper::visit, &adaptor, _1)); + GlobalMaterialManager().foreachShaderName( + std::bind(&ShaderNameToShaderWrapper::visit, &adaptor, std::placeholders::_1)); } -ScriptShader ShaderSystemInterface::getMaterialForName(const std::string& name) { +ScriptShader ShaderSystemInterface::getMaterialForName(const std::string& name) +{ return ScriptShader(GlobalMaterialManager().getMaterialForName(name)); } // IScriptInterface implementation -void ShaderSystemInterface::registerInterface(boost::python::object& nspace) { +void ShaderSystemInterface::registerInterface(py::module& scope, py::dict& globals) +{ // Add the declaration for a Shader object - nspace["Shader"] = boost::python::class_( - "Shader", boost::python::init()) - .def("getName", &ScriptShader::getName) - .def("getShaderFileName", &ScriptShader::getShaderFileName) - .def("getDescription", &ScriptShader::getDescription) - .def("getDefinition", &ScriptShader::getDefinition) - .def("isVisible", &ScriptShader::isVisible) - .def("isAmbientLight", &ScriptShader::isAmbientLight) - .def("isBlendLight", &ScriptShader::isBlendLight) - .def("isFogLight", &ScriptShader::isFogLight) - .def("isNull", &ScriptShader::isNull) - ; + py::class_ shader(scope, "Shader"); + + shader.def(py::init()); + shader.def("getName", &ScriptShader::getName); + shader.def("getShaderFileName", &ScriptShader::getShaderFileName); + shader.def("getDescription", &ScriptShader::getDescription); + shader.def("getDefinition", &ScriptShader::getDefinition); + shader.def("isVisible", &ScriptShader::isVisible); + shader.def("isAmbientLight", &ScriptShader::isAmbientLight); + shader.def("isBlendLight", &ScriptShader::isBlendLight); + shader.def("isFogLight", &ScriptShader::isFogLight); + shader.def("isNull", &ScriptShader::isNull); // Expose the ShaderVisitor interface - nspace["ShaderVisitor"] = - boost::python::class_("ShaderVisitor") - .def("visit", boost::python::pure_virtual(&ShaderVisitorWrapper::visit)) - ; + + py::class_ visitor(scope, "ShaderVisitor"); + visitor.def(py::init<>()); + visitor.def("visit", &ShaderVisitor::visit); // Add the module declaration to the given python namespace - nspace["GlobalMaterialManager"] = boost::python::class_("GlobalMaterialManager") - .def("foreachShader", &ShaderSystemInterface::foreachShader) - .def("getMaterialForName", &ShaderSystemInterface::getMaterialForName) - ; + py::class_ materialManager(scope, "MaterialManager"); + + materialManager.def("foreachShader", &ShaderSystemInterface::foreachShader); + materialManager.def("getMaterialForName", &ShaderSystemInterface::getMaterialForName); // Now point the Python variable "GlobalMaterialManager" to this instance - nspace["GlobalMaterialManager"] = boost::python::ptr(this); + globals["GlobalMaterialManager"] = this; } } // namespace script diff --git a/plugins/script/interfaces/ShaderSystemInterface.h b/plugins/script/interfaces/ShaderSystemInterface.h index 8e11fbe564..64d1211dda 100644 --- a/plugins/script/interfaces/ShaderSystemInterface.h +++ b/plugins/script/interfaces/ShaderSystemInterface.h @@ -1,11 +1,12 @@ #pragma once -#include +#include #include "ishaders.h" #include "iscript.h" -namespace script { +namespace script +{ /** * This class represents a single Shader as seen by the Python script. @@ -69,14 +70,18 @@ class ShaderVisitor // Wrap around the EntityClassVisitor interface class ShaderVisitorWrapper : - public ShaderVisitor, - public boost::python::wrapper + public ShaderVisitor { public: - void visit(const MaterialPtr& shader) + void visit(const MaterialPtr& shader) override { // Wrap this method to python - this->get_override("visit")(ScriptShader(shader)); + PYBIND11_OVERLOAD_PURE( + void, /* Return type */ + ShaderVisitor, /* Parent class */ + visit, /* Name of function in C++ (must match Python name) */ + ScriptShader(shader) /* Argument(s) */ + ); } }; @@ -91,8 +96,7 @@ class ShaderSystemInterface : ScriptShader getMaterialForName(const std::string& name); // IScriptInterface implementation - void registerInterface(boost::python::object& nspace); + void registerInterface(py::module& scope, py::dict& globals) override; }; -typedef std::shared_ptr ShaderSystemInterfacePtr; } // namespace script