From 34d4a69027b2b7267862aa58da93c18654cd7d85 Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Thu, 22 Feb 2024 04:53:54 -0800 Subject: [PATCH] Remove user_objetcs and user_model includes from xml_urdf. PiperOrigin-RevId: 609330384 Change-Id: I19b330e4063d3be4401dcf1b2b957b55e0616037 --- src/user/user_api.cc | 12 ++++++++++++ src/user/user_api.h | 5 ++++- src/xml/xml_urdf.cc | 14 +++++++------- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/user/user_api.cc b/src/user/user_api.cc index 611bea39..87e0839e 100644 --- a/src/user/user_api.cc +++ b/src/user/user_api.cc @@ -370,6 +370,18 @@ mjmBody* mjm_findChild(mjmBody* bodyspec, const char* name) { +// find mesh by name +mjmMesh* mjm_findMesh(mjmModel* modelspec, const char* name) { + mjCModel* model = reinterpret_cast(modelspec->element); + mjCMesh* mesh = (mjCMesh*)model->FindObject(mjOBJ_MESH, std::string(name)); + if (!mesh) { + return nullptr; + } + return &(static_cast(mesh)->spec); +} + + + // set frame void mjm_setFrame(mjElement dest, mjmFrame* frame) { if (!frame) { diff --git a/src/user/user_api.h b/src/user/user_api.h index 7aed24a9..4754538c 100644 --- a/src/user/user_api.h +++ b/src/user/user_api.h @@ -824,11 +824,14 @@ MJAPI mjmModel* mjm_getModel(mjmBody* body); MJAPI mjmDefault* mjm_getDefault(mjElement element); // Find body in model by name. -MJAPI mjmBody* mjm_findBody(mjmModel* modelspec, const char* name); +MJAPI mjmBody* mjm_findBody(mjmModel* model, const char* name); // Find child body by name. MJAPI mjmBody* mjm_findChild(mjmBody* body, const char* name); +// Find mesh by name. +MJAPI mjmMesh* mjm_findMesh(mjmModel* model, const char* name); + // Get element id. MJAPI int mjm_getId(mjElement element); diff --git a/src/xml/xml_urdf.cc b/src/xml/xml_urdf.cc index f24ed933..872b0155 100644 --- a/src/xml/xml_urdf.cc +++ b/src/xml/xml_urdf.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include #include @@ -19,11 +20,10 @@ #include #include "user/user_api.h" -#include "user/user_model.h" -#include "user/user_objects.h" #include "user/user_util.h" #include "xml/xml_native_reader.h" #include "xml/xml_urdf.h" +#include "xml/xml_util.h" #include "tinyxml2.h" @@ -575,7 +575,7 @@ mjmGeom* mjXURDF::Geom(XMLElement* geom_elem, mjmBody* pbody, bool collision) { meshname = mjuu_stripext(meshname); // look for existing mesh - mjCMesh* mesh = (mjCMesh*)model->FindObject(mjOBJ_MESH, meshname); + mjmMesh* mesh = mjm_findMesh(&model->spec, meshname.c_str()); mjmMesh* pmesh = 0; // does not exist: create @@ -584,16 +584,16 @@ mjmGeom* mjXURDF::Geom(XMLElement* geom_elem, mjmBody* pbody, bool collision) { } // exists with different scale: append name with '1', create - else if (mesh->spec.scale[0]!=meshscale[0] || - mesh->spec.scale[1]!=meshscale[1] || - mesh->spec.scale[2]!=meshscale[2]) { + else if (mesh->scale[0]!=meshscale[0] || + mesh->scale[1]!=meshscale[1] || + mesh->scale[2]!=meshscale[2]) { pmesh = mjm_addMesh(&model->spec, 0); meshname = meshname + "1"; } // point to already existing spec else { - pmesh = &mesh->spec; + pmesh = mesh; } // set fields