Skip to content

Commit

Permalink
Add convex argument to PlanningWorld::attachMesh
Browse files Browse the repository at this point in the history
  • Loading branch information
KolinGuo committed Apr 15, 2024
1 parent 03e11c4 commit 041a305
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
3 changes: 2 additions & 1 deletion include/mplib/planning_world.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,10 @@ class PlanningWorldTpl {
* @param art_name: name of the planned articulation to attach to
* @param link_id: index of the link of the planned articulation to attach to
* @param pose: attached pose (relative pose from attached link to object)
* @param convex: whether to load mesh as a convex mesh. Default: ``false``.
*/
void attachMesh(const std::string &mesh_path, const std::string &art_name,
int link_id, const Pose<S> &pose);
int link_id, const Pose<S> &pose, bool convex = false);

/**
* Detaches object with given name.
Expand Down
9 changes: 8 additions & 1 deletion mplib/pymp/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,13 @@ class PlanningWorld:
:param pose: attached pose (relative pose from attached link to object)
"""
def attach_mesh(
self, mesh_path: str, art_name: str, link_id: int, pose: Pose
self,
mesh_path: str,
art_name: str,
link_id: int,
pose: Pose,
*,
convex: bool = False,
) -> None:
"""
Attaches given mesh to specified link of articulation (auto touch_links)
Expand All @@ -403,6 +409,7 @@ class PlanningWorld:
:param art_name: name of the planned articulation to attach to
:param link_id: index of the link of the planned articulation to attach to
:param pose: attached pose (relative pose from attached link to object)
:param convex: whether to load mesh as a convex mesh. Default: ``False``.
"""
@typing.overload
def attach_object(
Expand Down
3 changes: 2 additions & 1 deletion pybind/docstring/planning_world.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ Attaches given mesh to specified link of articulation (auto touch_links)
:param mesh_path: path to a mesh file
:param art_name: name of the planned articulation to attach to
:param link_id: index of the link of the planned articulation to attach to
:param pose: attached pose (relative pose from attached link to object))doc";
:param pose: attached pose (relative pose from attached link to object)
:param convex: whether to load mesh as a convex mesh. Default: ``False``.)doc";

static const char *__doc_mplib_PlanningWorldTpl_attachObject =
R"doc(
Expand Down
4 changes: 2 additions & 2 deletions pybind/pybind_planning_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ void build_pyplanning_world(py::module &pymp) {
py::arg("art_name"), py::arg("link_id"), py::arg("pose"),
DOC(mplib, PlanningWorldTpl, attachBox))
.def("attach_mesh", &PlanningWorld::attachMesh, py::arg("mesh_path"),
py::arg("art_name"), py::arg("link_id"), py::arg("pose"),
DOC(mplib, PlanningWorldTpl, attachMesh))
py::arg("art_name"), py::arg("link_id"), py::arg("pose"), py::kw_only(),
py::arg("convex") = false, DOC(mplib, PlanningWorldTpl, attachMesh))
.def("detach_object", &PlanningWorld::detachObject, py::arg("name"),
py::arg("also_remove") = false, DOC(mplib, PlanningWorldTpl, detachObject))
.def("print_attached_body_pose", &PlanningWorld::printAttachedBodyPose,
Expand Down
16 changes: 11 additions & 5 deletions src/planning_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,19 @@ void PlanningWorldTpl<S>::attachBox(const Vector3<S> &size, const std::string &a
template <typename S>
void PlanningWorldTpl<S>::attachMesh(const std::string &mesh_path,
const std::string &art_name, int link_id,
const Pose<S> &pose) {
// TODO(merge): Convex mesh?
const Pose<S> &pose, bool convex) {
// FIXME: Use link_name to avoid changes
auto name = art_name + "_" + std::to_string(link_id) + "_mesh";
attachObject(
name, collision_detection::fcl::loadMeshAsBVH<S>(mesh_path, Vector3<S> {1, 1, 1}),
art_name, link_id, pose);
if (convex)
attachObject(
name,
collision_detection::fcl::loadMeshAsConvex<S>(mesh_path, Vector3<S> {1, 1, 1}),
art_name, link_id, pose);
else
attachObject(
name,
collision_detection::fcl::loadMeshAsBVH<S>(mesh_path, Vector3<S> {1, 1, 1}),
art_name, link_id, pose);
}

template <typename S>
Expand Down

0 comments on commit 041a305

Please sign in to comment.