Skip to content

Commit dc531b6

Browse files
committed
IECoreUSDModule : Make compatible with USD 25.05
In which the USD Python bindings are now performed using a copy of `boost::python`, housed in the `pxr_boost::python` namespace. We bind a few functions of our own that deal with `pxr` types, so we now need to teach our `boost::python` how to pass them to `pxr_boost::python`.
1 parent 022ddae commit dc531b6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

contrib/IECoreUSD/src/IECoreUSD/bindings/IEUSDModule.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939

4040
#include "IECore/IndexedIO.h"
4141

42+
#if PXR_VERSION >= 2505
43+
#include "pxr/external/boost/python.hpp"
44+
#endif
45+
4246
#include "boost/python.hpp"
4347

4448
using namespace boost::python;
@@ -86,10 +90,45 @@ static list fromInternalPath( list l )
8690
return vectorToList( path );
8791
}
8892

93+
#if PXR_VERSION >= 2505
94+
95+
// Registers `boost::python` converters for types
96+
// wrapped using `pxr_boost::python`.
97+
template<typename T>
98+
struct PxrBoostConverter
99+
{
100+
101+
static void registerConverters()
102+
{
103+
boost::python::to_python_converter<T, ToPxrBoost>();
104+
/// \todo Add conversion from Python when we have
105+
/// a use for it. See PyBindConverter for an example.
106+
}
107+
108+
private :
109+
110+
struct ToPxrBoost
111+
{
112+
static PyObject *convert( const T &t )
113+
{
114+
pxr::pxr_boost::python::object o( t );
115+
Py_INCREF( o.ptr() );
116+
return o.ptr();
117+
}
118+
};
119+
120+
};
121+
122+
#endif // PXR_VERSION >= 2505
123+
89124
} // namespace
90125

91126
BOOST_PYTHON_MODULE( _IECoreUSD )
92127
{
128+
PxrBoostConverter<pxr::TfToken>::registerConverters();
129+
PxrBoostConverter<pxr::VtValue>::registerConverters();
130+
PxrBoostConverter<pxr::SdfValueTypeName>::registerConverters();
131+
93132
{
94133
object dataAlgoModule( handle<>( borrowed( PyImport_AddModule( "IECoreUSD.DataAlgo" ) ) ) );
95134
scope().attr( "DataAlgo" ) = dataAlgoModule;

0 commit comments

Comments
 (0)