diff --git a/doc/python/magnum.trade.rst b/doc/python/magnum.trade.rst index 642ecf8..50bc73b 100644 --- a/doc/python/magnum.trade.rst +++ b/doc/python/magnum.trade.rst @@ -523,6 +523,11 @@ .. py:function:: magnum.trade.AbstractSceneConverter.begin_file :raise RuntimeError: If beginning the conversion fails + For compatibility with :ref:`os.path`, on Windows this function converts + all backslashes in :p:`filename` to forward slashes before passing it to + :dox:`Trade::AbstractSceneConverter::beginFike()`, which expects forward + slashes as directory separators on all platforms. + .. py:function:: magnum.trade.AbstractSceneConverter.end_file :raise AssertionError: If no conversion is in progress :raise RuntimeError: If ending the conversion fails diff --git a/src/python/magnum/trade.cpp b/src/python/magnum/trade.cpp index 194b5ce..e09578e 100644 --- a/src/python/magnum/trade.cpp +++ b/src/python/magnum/trade.cpp @@ -1712,7 +1712,16 @@ void trade(py::module_& m) { /** @todo begin/end (MeshOptimizer), begin/end data */ /** @todo drop std::string in favor of our own string caster */ .def("begin_file", [](Trade::AbstractSceneConverter& self, const std::string& filename) { - if(!self.beginFile(filename)) { + if(!self.beginFile( + #ifdef CORRADE_TARGET_WINDOWS + /* To allow people to conveniently use Python's os.path, we + need to convert backslashes to forward slashes as all + Corrade and Magnum APIs expect forward */ + Utility::Path::fromNativeSeparators(filename) + #else + filename + #endif + )) { PyErr_SetString(PyExc_RuntimeError, "beginning the conversion failed"); throw py::error_already_set{}; }