1
+ #include " fwd.h"
2
+ #include " coal/BVH/BVH_model.h"
3
+
4
+ #include " pickle.hh"
5
+ #include " serializable.hh"
6
+
7
+ #include " coal/serialization/BVH_model.h"
8
+
9
+ using namespace coal ;
10
+ using namespace nb ::literals;
11
+
12
+ template <typename BV>
13
+ void exposeBVHModel (nb::module_& m, const char * name) {
14
+ using BVHType = BVHModel<BV>;
15
+ nb::class_<BVHType, BVHModelBase>(m, name)
16
+ .def (nb::init<>())
17
+ .def (nb::init<const BVHType&>(), " other" _a)
18
+ .DEF_CLASS_FUNC (BVHType, getNumBVs)
19
+ .DEF_CLASS_FUNC (BVHType, makeParentRelative)
20
+ .DEF_CLASS_FUNC (BVHType, memUsage)
21
+ .def (" clone" , &BVHType::clone, nb::rv_policy::take_ownership)
22
+ .def (python::v2::PickleVisitor<BVHType>())
23
+ .def (python::v2::SerializableVisitor<BVHType>());
24
+ }
25
+
26
+ void exposeBVHModels (nb::module_& m) {
27
+ using RowMatrixX3 = Eigen::Matrix<double , Eigen::Dynamic, 3 , Eigen::RowMajor>;
28
+ using MapRowMatrixX3 = Eigen::Map<RowMatrixX3>;
29
+ nb::class_<BVHModelBase, CollisionGeometry>(m, " BVHModelBase" )
30
+ .def (" vertex" ,
31
+ [](BVHModelBase& bvh, size_t i) -> Vec3s& {
32
+ if (i >= bvh.num_vertices ) throw nb::index_error ();
33
+ return (*bvh.vertices )[i];
34
+ })
35
+ .def (
36
+ " vertices" ,
37
+ [](BVHModelBase& bvh) {
38
+ if (bvh.num_vertices > 0 ) {
39
+ return MapRowMatrixX3{bvh.vertices ->data ()->data (),
40
+ bvh.num_vertices , 3 };
41
+ } else {
42
+ return MapRowMatrixX3{nullptr , 0 , 3 };
43
+ }
44
+ },
45
+ " Retrieve all vertices" )
46
+ .def (
47
+ " tri_indices" ,
48
+ [](const BVHModelBase& bvh, size_t i) {
49
+ if (i >= bvh.num_tris ) {
50
+ nb::index_error (" Triangle index out of range" );
51
+ }
52
+ return (*bvh.tri_indices )[i];
53
+ },
54
+ " index" _a, " Retrieve the triangle given by its index." )
55
+ .def_ro (" num_vertices" , &BVHModelBase::num_vertices)
56
+ .def_ro (" num_tris" , &BVHModelBase::num_tris)
57
+ .def_ro (" build_state" , &BVHModelBase::build_state)
58
+
59
+ .def_ro (" convex" , &BVHModelBase::convex)
60
+
61
+ .def (" buildConvexRepresentation" ,
62
+ &BVHModelBase::buildConvexRepresentation, " share_memory" _a)
63
+ .def (" buildConvexHull" , &BVHModelBase::buildConvexHull, " keepTriangle" _a,
64
+ " qhullCommand" _a = NULL )
65
+
66
+ .DEF_CLASS_FUNC (BVHModelBase, beginModel)
67
+ .DEF_CLASS_FUNC (BVHModelBase, addVertex)
68
+ .DEF_CLASS_FUNC (BVHModelBase, addVertices)
69
+ .DEF_CLASS_FUNC (BVHModelBase, addTriangle)
70
+ .DEF_CLASS_FUNC (BVHModelBase, addTriangles);
71
+
72
+ exposeBVHModel<OBB>(m, " OBB" );
73
+ exposeBVHModel<OBBRSS>(m, " OBBRSS" );
74
+ }
0 commit comments