Skip to content

Commit b92c42a

Browse files
committed
[bindings/python] expose MeshData, don't know how I'll use it
1 parent a33f8e7 commit b92c42a

File tree

4 files changed

+45
-18
lines changed

4 files changed

+45
-18
lines changed

bindings/python/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ endif(GENERATE_PYTHON_STUBS)
55

66
find_package(eigenpy 3.2.0 REQUIRED)
77

8-
set(pycandlewick_SOURCES src/expose-renderer.cpp src/module.cpp)
8+
set(
9+
pycandlewick_SOURCES
10+
src/expose-mesh-data.cpp
11+
src/expose-renderer.cpp
12+
src/module.cpp
13+
)
914

1015
set(PYLIB_INSTALL_DIR ${PYTHON_SITELIB}/${PROJECT_NAME})
1116

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "fwd.hpp"
2+
#include "candlewick/utils/MeshData.h"
3+
4+
using namespace candlewick;
5+
6+
void exposeMeshData() {
7+
8+
bp::class_<MeshLayout>("MeshLayout", bp::no_init);
9+
10+
bp::class_<MeshData, boost::noncopyable>("MeshData", bp::no_init)
11+
.def_readonly("layout", &MeshData::layout)
12+
.add_property("numVertices", &MeshData::numVertices,
13+
"Number of vertices.")
14+
.add_property("vertexSize", &MeshData::vertexSize)
15+
.add_property("vertexBytes", &MeshData::vertexBytes,
16+
"Number of bytes in the vertex data.")
17+
.add_property("numIndices", &MeshData::numIndices, "Number of indices.")
18+
.add_property("isIndexed", &MeshData::isIndexed,
19+
"Whether the mesh is indexed.")
20+
21+
;
22+
}

bindings/python/src/expose-visualizer.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,32 @@
1010

1111
using namespace candlewick::multibody;
1212

13+
#define DEF_PROP_PROXY(name) \
14+
add_property(#name, bp::make_function( \
15+
+[](Visualizer &v) -> auto & { return v.name(); }, \
16+
bp::return_internal_reference<>()))
17+
1318
void exposeVisualizer() {
1419
eigenpy::OptionalConverter<ConstVectorRef, std::optional>::registration();
1520
bp::class_<Visualizer::Config>("VisualizerConfig", bp::init<>())
1621
.def_readwrite("width", &Visualizer::Config::width)
1722
.def_readwrite("height", &Visualizer::Config::height);
1823

19-
auto cl =
20-
bp::class_<Visualizer, boost::noncopyable>("Visualizer", bp::no_init)
21-
.def(bp::init<Visualizer::Config, const pin::Model &,
22-
const pin::GeometryModel &>(
23-
("self"_a, "config", "model", "geomModel")))
24-
.def(pinocchio::python::VisualizerPythonVisitor<Visualizer>{})
25-
.def_readonly("renderer", &Visualizer::renderer)
26-
.add_property("shouldExit", &Visualizer::shouldExit);
27-
24+
bp::class_<Visualizer, boost::noncopyable>("Visualizer", bp::no_init)
25+
.def(bp::init<Visualizer::Config, const pin::Model &,
26+
const pin::GeometryModel &>(
27+
("self"_a, "config", "model", "geomModel")))
28+
.def(pinocchio::python::VisualizerPythonVisitor<Visualizer>{})
29+
.def_readonly("renderer", &Visualizer::renderer)
2830
// fix for Pinocchio 3.5.0
2931
#if PINOCCHIO_VERSION_AT_MOST(3, 5, 0)
30-
#define DEF_PROP_PROXY(name) \
31-
add_property(#name, bp::make_function( \
32-
+[](Visualizer &v) -> auto & { return v.name(); }, \
33-
bp::return_internal_reference<>()))
34-
cl //
3532
.DEF_PROP_PROXY(model)
3633
.DEF_PROP_PROXY(visualModel)
3734
.DEF_PROP_PROXY(collisionModel)
3835
.DEF_PROP_PROXY(data)
3936
.DEF_PROP_PROXY(visualData)
40-
.DEF_PROP_PROXY(collisionData);
41-
#undef DEF_PROP_PROXY
37+
.DEF_PROP_PROXY(collisionData)
4238
#endif
39+
.add_property("shouldExit", &Visualizer::shouldExit);
4340
}
41+
#undef DEF_PROP_PROXY

bindings/python/src/module.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
using namespace candlewick;
88

9+
void exposeMeshData();
10+
void exposeRenderer();
911
#ifdef CANDLEWICK_PYTHON_PINOCCHIO_SUPPORT
1012
void exposeVisualizer();
1113
#endif
12-
void exposeRenderer();
1314

1415
BOOST_PYTHON_MODULE(pycandlewick) {
1516
bp::import("eigenpy");
@@ -26,6 +27,7 @@ BOOST_PYTHON_MODULE(pycandlewick) {
2627
// Register SDL_Quit() as a function to call when interpreter exits.
2728
Py_AtExit(SDL_Quit);
2829

30+
exposeMeshData();
2931
exposeRenderer();
3032
#ifdef CANDLEWICK_PYTHON_PINOCCHIO_SUPPORT
3133
{

0 commit comments

Comments
 (0)