4141
4242#include " IECoreVDB/VDBObject.h"
4343
44+ // OpenVDB 10.0 and earlier used `boost::python` for its Python bindings, but
45+ // this was switched to PyBind11 in OpenVDB 10.1. We need to take a different
46+ // approach to binding VDBObject's grid accessors in each case.
47+ #if OPENVDB_LIBRARY_MAJOR_VERSION_NUMBER > 10 || OPENVDB_LIBRARY_MAJOR_VERSION_NUMBER == 10 && OPENVDB_LIBRARY_MINOR_VERSION_NUMBER >= 1
48+ #include " IECorePython/PyBindConverter.h"
49+ #define IECOREVDB_USE_PYBIND
50+ #endif
4451
4552using namespace boost ::python;
4653using namespace IECoreVDB ;
4754
55+ #ifndef IECOREVDB_USE_PYBIND
56+
4857namespace
4958{
5059
@@ -118,18 +127,6 @@ openvdb::GridBase::Ptr getGridFromPyObject( const boost::python::object &gridObj
118127
119128} // namespace iepyopenvdb
120129
121-
122- boost::python::list gridNames ( VDBObject::Ptr vdbObject )
123- {
124- boost::python::list result;
125- std::vector<std::string> names = vdbObject->gridNames ();
126- for ( const auto &name : names )
127- {
128- result.append ( name );
129- }
130- return result;
131- }
132-
133130boost::python::object findGrid ( VDBObject::Ptr vdbObject, const std::string &gridName )
134131{
135132 openvdb::GridBase::Ptr grid = vdbObject->findGrid ( gridName );
@@ -151,17 +148,44 @@ void insertGrid( VDBObject::Ptr vdbObject, boost::python::object pyObject )
151148
152149} // namespace
153150
151+ #endif // #ifndef IECOREVDB_USE_PYBIND
152+
153+ namespace
154+ {
155+
156+ boost::python::list gridNames ( VDBObject::Ptr vdbObject )
157+ {
158+ boost::python::list result;
159+ std::vector<std::string> names = vdbObject->gridNames ();
160+ for ( const auto &name : names )
161+ {
162+ result.append ( name );
163+ }
164+ return result;
165+ }
166+
167+ } // namespace
168+
154169BOOST_PYTHON_MODULE ( _IECoreVDB )
155170{
156171
172+ #ifdef IECOREVDB_USE_PYBIND
173+ IECorePython::PyBindConverter<openvdb::GridBase::Ptr>::registerConverters ();
174+ #endif
175+
157176 IECorePython::RunTimeTypedClass<VDBObject>()
158177 .def (init<const std::string &>())
159178 .def (init<>())
160179 .def (" gridNames" , &::gridNames)
161180 .def (" metadata" , &VDBObject::metadata)
162181 .def (" removeGrid" , &VDBObject::removeGrid)
182+ #ifdef IECOREVDB_USE_PYBIND
183+ .def ( " findGrid" , (openvdb::GridBase::Ptr (VDBObject::*)( const std::string &name ))&VDBObject::findGrid )
184+ .def ( " insertGrid" , &VDBObject::insertGrid )
185+ #else
163186 .def (" findGrid" , &::findGrid)
164187 .def (" insertGrid" , &::insertGrid)
188+ #endif
165189 .def (" unmodifiedFromFile" , &VDBObject::unmodifiedFromFile)
166190 .def (" fileName" , &VDBObject::fileName)
167191 ;
0 commit comments