Add mjs_getParent to retrieve the parent body of an object.
PiperOrigin-RevId: 715794859 Change-Id: Ib9792787cdb966f579938dde3f94ebabca8ef1fc
This commit is contained in:
committed by
Copybara-Service
parent
10c7207cea
commit
05d4c3d670
@@ -649,6 +649,30 @@ mjsBody* mjs_findChild(mjsBody* bodyspec, const char* name) {
|
||||
|
||||
|
||||
|
||||
// get parent body
|
||||
mjsBody* mjs_getParent(mjsElement* element) {
|
||||
switch (element->elemtype) {
|
||||
case mjOBJ_BODY:
|
||||
return &(static_cast<mjCBody*>(element)->GetParent()->spec);
|
||||
case mjOBJ_FRAME:
|
||||
return &(static_cast<mjCFrame*>(element)->GetParent()->spec);
|
||||
case mjOBJ_JOINT:
|
||||
return &(static_cast<mjCJoint*>(element)->GetParent()->spec);
|
||||
case mjOBJ_GEOM:
|
||||
return &(static_cast<mjCGeom*>(element)->GetParent()->spec);
|
||||
case mjOBJ_SITE:
|
||||
return &(static_cast<mjCSite*>(element)->GetParent()->spec);
|
||||
case mjOBJ_CAMERA:
|
||||
return &(static_cast<mjCCamera*>(element)->GetParent()->spec);
|
||||
case mjOBJ_LIGHT:
|
||||
return &(static_cast<mjCLight*>(element)->GetParent()->spec);
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// find frame by name
|
||||
mjsFrame* mjs_findFrame(mjSpec* s, const char* name) {
|
||||
mjsElement* frame = mjs_findElement(s, mjOBJ_FRAME, name);
|
||||
|
||||
Reference in New Issue
Block a user