Skip to content

Bindings for Extension Libraries

Jeongseok Lee edited this page May 24, 2018 · 2 revisions

Template Member Functions

DART uses template member functions to construct Addon, BodyNode, and Joint instances. dartpy works around this limitation by wrapping these functions for a predefined set of template arguments. You need to register your classes with dartpy for these methods to work on custom types.

For custom Joints:

JointTemplateRegistry::register_type<MyJoint1>();
JointTemplateRegistry::register_type<MyJoint2>();
// ...

For custom BodyNodes:

BodyNodeTemplateRegistry::register_type<MyBodyNode1>();
BodyNodeTemplateRegistry::register_type<MyBodyNode2>();
BodyNodeTemplateRegistry::register_type<MyBodyNode3>();
// ...

If you want to use the createJointAndBodyNodePair() method on Skeleton, then you also need to register all pairs of BodyNode and Joint subclasses that you intend to pass as template arguments. Typically, this includes:

  1. each custom BodyNode paired with each custom Joint
  2. each custom BodyNode paired with each default Joint
  3. each default BodyNode paired with each custom Joint

dartpy provides the register_all_types helper function to register the cartesian product of two lists of types. You can register all of the above combinations using the three lines of code:

using MyJointTypes = typelist<MyJoint1, MyJoint2 /* ... */>;
using MyBodyNodeTypes = typelist<MyBodyNode1, MyBodyNode2, MyBodyNode3 /* ... */>;

JointAndNodeTemplateRegistry::register_all_types<MyJointTypes, AllNodeTypes>();
JointAndNodeTemplateRegistry::register_all_types<AllJointTypes, MyBodyNodeTypes>();
JointAndNodeTemplateRegistry::register_all_types<MyJointTypes, MyBodyNodeTypes>();

Note that this approach means that is is not generally possible to call createJointAndBodyNodePair with BodyNode and Joint types defined in two different extension libraries. If this is necessary, you need to modify one of the libraries to call register_type on that pair of BodyNode and Joint types.