Replace name attribute with setters and getters in the C API of mjSpec.
PiperOrigin-RevId: 778816015 Change-Id: Ieffb7a5bce37e887ff009f9a02d2434435e79ca1
This commit is contained in:
committed by
Copybara-Service
parent
1c5d47c94b
commit
594e17074a
@@ -334,14 +334,14 @@ class ModelWriter {
|
||||
}
|
||||
|
||||
void WriteMesh(const mjsMesh *mesh, const pxr::SdfPath &parent_path) {
|
||||
auto name = GetAvailablePrimName(*mesh->name, pxr::UsdGeomTokens->Mesh,
|
||||
auto name = GetAvailablePrimName(*mjs_getName(mesh->element), pxr::UsdGeomTokens->Mesh,
|
||||
parent_path);
|
||||
pxr::SdfPath subcomponent_path =
|
||||
CreatePrimSpec(data_, parent_path, name, pxr::UsdGeomTokens->Xform);
|
||||
pxr::SdfPath mesh_path =
|
||||
CreatePrimSpec(data_, subcomponent_path, kTokens->sourceMesh,
|
||||
pxr::UsdGeomTokens->Mesh);
|
||||
mesh_paths_[*mesh->name] = subcomponent_path;
|
||||
mesh_paths_[*mjs_getName(mesh->element)] = subcomponent_path;
|
||||
|
||||
if (write_physics_) {
|
||||
ApplyApiSchema(data_, mesh_path, MjcPhysicsTokens->MeshCollisionAPI);
|
||||
@@ -725,8 +725,9 @@ class ModelWriter {
|
||||
|
||||
void WriteMaterial(mjsMaterial *material, const pxr::SdfPath &parent_path) {
|
||||
// Create a Material prim.
|
||||
auto name = GetAvailablePrimName(
|
||||
*material->name, pxr::UsdShadeTokens->Material, parent_path);
|
||||
auto name =
|
||||
GetAvailablePrimName(*mjs_getName(material->element),
|
||||
pxr::UsdShadeTokens->Material, parent_path);
|
||||
pxr::SdfPath material_path =
|
||||
CreatePrimSpec(data_, parent_path, name, pxr::UsdShadeTokens->Material);
|
||||
|
||||
@@ -1008,9 +1009,9 @@ class ModelWriter {
|
||||
std::unordered_map<std::string, std::vector<mjsKey *>> keyframes_map;
|
||||
mjsKey *keyframe = mjs_asKey(mjs_firstElement(spec_, mjOBJ_KEY));
|
||||
while (keyframe) {
|
||||
std::string keyframe_name = keyframe->name->empty()
|
||||
std::string keyframe_name = mjs_getName(keyframe->element)->empty()
|
||||
? MjcPhysicsTokens->Keyframe
|
||||
: *keyframe->name;
|
||||
: *mjs_getName(keyframe->element);
|
||||
keyframes_map[keyframe_name].push_back(keyframe);
|
||||
keyframe = mjs_asKey(mjs_nextElement(spec_, keyframe->element));
|
||||
}
|
||||
@@ -1174,7 +1175,9 @@ class ModelWriter {
|
||||
|
||||
pxr::SdfPath WriteMeshGeom(const mjsGeom *geom,
|
||||
const pxr::SdfPath &body_path) {
|
||||
std::string mj_name = geom->name->empty() ? *geom->meshname : *geom->name;
|
||||
std::string mj_name = mjs_getName(geom->element)->empty()
|
||||
? *geom->meshname
|
||||
: *mjs_getName(geom->element);
|
||||
auto name =
|
||||
GetAvailablePrimName(mj_name, pxr::UsdGeomTokens->Mesh, body_path);
|
||||
pxr::SdfPath subcomponent_path =
|
||||
@@ -1196,8 +1199,8 @@ class ModelWriter {
|
||||
|
||||
pxr::SdfPath WriteSiteGeom(const mjsSite *site,
|
||||
const pxr::SdfPath &body_path) {
|
||||
auto name =
|
||||
GetAvailablePrimName(*site->name, pxr::UsdGeomTokens->Cube, body_path);
|
||||
auto name = GetAvailablePrimName(*mjs_getName(site->element),
|
||||
pxr::UsdGeomTokens->Cube, body_path);
|
||||
|
||||
int site_idx = mjs_getId(site->element);
|
||||
const mjtNum *size = &model_->site_size[site_idx * 3];
|
||||
@@ -1254,8 +1257,8 @@ class ModelWriter {
|
||||
|
||||
pxr::SdfPath WriteBoxGeom(const mjsGeom *geom,
|
||||
const pxr::SdfPath &body_path) {
|
||||
auto name =
|
||||
GetAvailablePrimName(*geom->name, pxr::UsdGeomTokens->Cube, body_path);
|
||||
auto name = GetAvailablePrimName(*mjs_getName(geom->element),
|
||||
pxr::UsdGeomTokens->Cube, body_path);
|
||||
|
||||
int geom_idx = mjs_getId(geom->element);
|
||||
mjtNum *geom_size = &model_->geom_size[geom_idx * 3];
|
||||
@@ -1282,8 +1285,8 @@ class ModelWriter {
|
||||
|
||||
pxr::SdfPath WriteCapsuleGeom(const mjsGeom *geom,
|
||||
const pxr::SdfPath &body_path) {
|
||||
auto name = GetAvailablePrimName(*geom->name, pxr::UsdGeomTokens->Capsule,
|
||||
body_path);
|
||||
auto name = GetAvailablePrimName(*mjs_getName(geom->element),
|
||||
pxr::UsdGeomTokens->Capsule, body_path);
|
||||
int geom_idx = mjs_getId(geom->element);
|
||||
mjtNum *geom_size = &model_->geom_size[geom_idx * 3];
|
||||
|
||||
@@ -1310,8 +1313,8 @@ class ModelWriter {
|
||||
|
||||
pxr::SdfPath WriteCylinderGeom(const mjsGeom *geom,
|
||||
const pxr::SdfPath &body_path) {
|
||||
auto name = GetAvailablePrimName(*geom->name, pxr::UsdGeomTokens->Cylinder,
|
||||
body_path);
|
||||
auto name = GetAvailablePrimName(*mjs_getName(geom->element),
|
||||
pxr::UsdGeomTokens->Cylinder, body_path);
|
||||
|
||||
int geom_idx = mjs_getId(geom->element);
|
||||
mjtNum *geom_size = &model_->geom_size[geom_idx * 3];
|
||||
@@ -1340,8 +1343,8 @@ class ModelWriter {
|
||||
|
||||
pxr::SdfPath WriteEllipsoidGeom(const mjsGeom *geom,
|
||||
const pxr::SdfPath &body_path) {
|
||||
auto name = GetAvailablePrimName(*geom->name, pxr::UsdGeomTokens->Sphere,
|
||||
body_path);
|
||||
auto name = GetAvailablePrimName(*mjs_getName(geom->element),
|
||||
pxr::UsdGeomTokens->Sphere, body_path);
|
||||
int geom_idx = mjs_getId(geom->element);
|
||||
mjtNum *geom_size = &model_->geom_size[geom_idx * 3];
|
||||
|
||||
@@ -1362,8 +1365,8 @@ class ModelWriter {
|
||||
|
||||
pxr::SdfPath WriteSphereGeom(const mjsGeom *geom,
|
||||
const pxr::SdfPath &body_path) {
|
||||
auto name = GetAvailablePrimName(*geom->name, pxr::UsdGeomTokens->Sphere,
|
||||
body_path);
|
||||
auto name = GetAvailablePrimName(*mjs_getName(geom->element),
|
||||
pxr::UsdGeomTokens->Sphere, body_path);
|
||||
int geom_idx = mjs_getId(geom->element);
|
||||
mjtNum *geom_size = &model_->geom_size[geom_idx * 3];
|
||||
return WriteSphere(name, geom_size, body_path);
|
||||
@@ -1399,8 +1402,8 @@ class ModelWriter {
|
||||
|
||||
pxr::SdfPath WritePlaneGeom(const mjsGeom *geom,
|
||||
const pxr::SdfPath &body_path) {
|
||||
auto name =
|
||||
GetAvailablePrimName(*geom->name, pxr::UsdGeomTokens->Plane, body_path);
|
||||
auto name = GetAvailablePrimName(*mjs_getName(geom->element),
|
||||
pxr::UsdGeomTokens->Plane, body_path);
|
||||
int geom_idx = mjs_getId(geom->element);
|
||||
mjtNum *geom_size = &model_->geom_size[geom_idx * 3];
|
||||
return WritePlane(name, geom_size, body_path);
|
||||
@@ -1409,8 +1412,8 @@ class ModelWriter {
|
||||
void WriteSite(mjsSite *site, const mjsBody *body) {
|
||||
const int body_id = mjs_getId(body->element);
|
||||
const auto &body_path = body_paths_[body_id];
|
||||
auto name =
|
||||
GetAvailablePrimName(*site->name, pxr::UsdGeomTokens->Xform, body_path);
|
||||
auto name = GetAvailablePrimName(*mjs_getName(site->element),
|
||||
pxr::UsdGeomTokens->Xform, body_path);
|
||||
|
||||
// Create a geom primitive and set its purpose to guide so it won't be
|
||||
// rendered.
|
||||
@@ -1519,7 +1522,8 @@ class ModelWriter {
|
||||
}
|
||||
|
||||
mjsDefault *spec_default = mjs_getDefault(geom->element);
|
||||
pxr::TfToken valid_class_name = GetValidPrimName(*spec_default->name);
|
||||
pxr::TfToken valid_class_name =
|
||||
GetValidPrimName(*mjs_getName(spec_default->element));
|
||||
pxr::SdfPath geom_class_path = class_path_.AppendChild(valid_class_name);
|
||||
if (!data_->HasSpec(geom_class_path)) {
|
||||
pxr::SdfPath class_path =
|
||||
@@ -1645,7 +1649,7 @@ class ModelWriter {
|
||||
break;
|
||||
default:
|
||||
TF_WARN("Unsupported joint type '%d' for joint '%s'. Skipping.",
|
||||
(int)type, joint->name->c_str());
|
||||
(int)type, mjs_getName(joint->element)->c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1658,7 +1662,7 @@ class ModelWriter {
|
||||
int body0_id_usd = model_->body_parentid[body_id];
|
||||
|
||||
const pxr::SdfPath &body1_path_usd = body_paths_[body1_id_usd];
|
||||
auto joint_name = joint ? *joint->name : "FixedJoint";
|
||||
auto joint_name = joint ? *mjs_getName(joint->element) : "FixedJoint";
|
||||
pxr::TfToken joint_name_token =
|
||||
GetAvailablePrimName(joint_name, kTokens->joint, body1_path_usd);
|
||||
pxr::SdfPath joint_path = CreatePrimSpec(data_, body1_path_usd,
|
||||
@@ -1892,7 +1896,7 @@ class ModelWriter {
|
||||
|
||||
void WriteCamera(mjsCamera *spec_cam, const mjsBody *body) {
|
||||
const auto &body_path = body_paths_[mjs_getId(body->element)];
|
||||
auto name = GetAvailablePrimName(*spec_cam->name,
|
||||
auto name = GetAvailablePrimName(*mjs_getName(spec_cam->element),
|
||||
pxr::UsdGeomTokens->Camera, body_path);
|
||||
// Create a root Xform for the world body with the model name if it exists
|
||||
// otherwise called 'World'.
|
||||
@@ -1950,7 +1954,8 @@ class ModelWriter {
|
||||
|
||||
void WriteLight(mjsLight *light, const mjsBody *body) {
|
||||
const auto &body_path = body_paths_[mjs_getId(body->element)];
|
||||
auto name = GetAvailablePrimName(*light->name, kTokens->light, body_path);
|
||||
auto name = GetAvailablePrimName(*mjs_getName(light->element),
|
||||
kTokens->light, body_path);
|
||||
// Create a root Xform for the world body with the model name if it exists
|
||||
// otherwise called 'World'.
|
||||
pxr::SdfPath light_path =
|
||||
@@ -1978,7 +1983,7 @@ class ModelWriter {
|
||||
mjsBody *parent = mjs_getParent(body->element);
|
||||
int parent_id = mjs_getId(parent->element);
|
||||
pxr::SdfPath parent_path = body_paths_[parent_id];
|
||||
pxr::TfToken body_name = GetValidPrimName(*body->name);
|
||||
pxr::TfToken body_name = GetValidPrimName(*mjs_getName(body->element));
|
||||
|
||||
// Create Xform prim for body.
|
||||
pxr::SdfPath body_path = CreatePrimSpec(data_, parent_path, body_name,
|
||||
@@ -2046,7 +2051,8 @@ class ModelWriter {
|
||||
// Create classes if necessary
|
||||
mjsDefault *spec_default = mjs_getDefault(body->element);
|
||||
|
||||
pxr::TfToken body_class_name = GetValidPrimName(*spec_default->name);
|
||||
pxr::TfToken body_class_name =
|
||||
GetValidPrimName(*mjs_getName(spec_default->element));
|
||||
pxr::SdfPath body_class_path = class_path_.AppendChild(body_class_name);
|
||||
if (!data_->HasSpec(body_class_path)) {
|
||||
CreateClassSpec(data_, class_path_, body_class_name);
|
||||
@@ -2069,7 +2075,7 @@ class ModelWriter {
|
||||
pxr::VtArray<pxr::TfToken>{kTokens->xformOpTransform});
|
||||
|
||||
pxr::VtDictionary customData;
|
||||
customData[kTokens->body_name] = *body->name;
|
||||
customData[kTokens->body_name] = *mjs_getName(body->element);
|
||||
SetPrimMetadata(data_, body_path, pxr::SdfFieldKeys->CustomData,
|
||||
customData);
|
||||
|
||||
|
||||
@@ -556,7 +556,7 @@ void ParseMjcPhysicsGeneralActuatorAPI(mjSpec* spec,
|
||||
const std::string* name) {
|
||||
pxr::UsdPrim prim = act.GetPrim();
|
||||
mjsActuator* mj_act = mjs_addActuator(spec, nullptr);
|
||||
mjs_setString(mj_act->name, prim.GetPath().GetAsString().c_str());
|
||||
mjs_setName(mj_act->element, prim.GetPath().GetAsString().c_str());
|
||||
mjs_setString(mj_act->target, name->c_str());
|
||||
mj_act->trntype = tran_type;
|
||||
|
||||
@@ -732,7 +732,7 @@ void ParseMjcPhysicsJointAPI(mjsJoint* mj_joint,
|
||||
mju_warning(
|
||||
"springdamper attribute for joint %s has incorrect size %zu, "
|
||||
"expected 2.",
|
||||
mj_joint->name->c_str(), springdamper.size());
|
||||
mjs_getName(mj_joint->element)->c_str(), springdamper.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -748,7 +748,7 @@ void ParseMjcPhysicsJointAPI(mjsJoint* mj_joint,
|
||||
mju_warning(
|
||||
"solreflimit attribute for joint %s has incorrect size %zu, "
|
||||
"expected %d.",
|
||||
mj_joint->name->c_str(), solreflimit.size(), mjNREF);
|
||||
mjs_getName(mj_joint->element)->c_str(), solreflimit.size(), mjNREF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -764,7 +764,7 @@ void ParseMjcPhysicsJointAPI(mjsJoint* mj_joint,
|
||||
mju_warning(
|
||||
"solimplimit attribute for joint %s has incorrect size %zu, "
|
||||
"expected %d.",
|
||||
mj_joint->name->c_str(), solimplimit.size(), mjNIMP);
|
||||
mjs_getName(mj_joint->element)->c_str(), solimplimit.size(), mjNIMP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -780,7 +780,8 @@ void ParseMjcPhysicsJointAPI(mjsJoint* mj_joint,
|
||||
mju_warning(
|
||||
"solreffriction attribute for joint %s has incorrect size %zu, "
|
||||
"expected %d.",
|
||||
mj_joint->name->c_str(), solreffriction.size(), mjNREF);
|
||||
mjs_getName(mj_joint->element)->c_str(), solreffriction.size(),
|
||||
mjNREF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -796,7 +797,8 @@ void ParseMjcPhysicsJointAPI(mjsJoint* mj_joint,
|
||||
mju_warning(
|
||||
"solimpfriction attribute for joint %s has incorrect size %zu, "
|
||||
"expected %d.",
|
||||
mj_joint->name->c_str(), solimpfriction.size(), mjNIMP);
|
||||
mjs_getName(mj_joint->element)->c_str(), solimpfriction.size(),
|
||||
mjNIMP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -898,7 +900,7 @@ void ParseUsdPhysicsCollider(mjSpec* spec,
|
||||
}
|
||||
|
||||
mjsGeom* geom = mjs_addGeom(parent, nullptr);
|
||||
mjs_setString(geom->name, prim.GetPath().GetAsString().c_str());
|
||||
mjs_setName(geom->element, prim.GetPath().GetAsString().c_str());
|
||||
geom->contype = 1;
|
||||
geom->conaffinity = 1;
|
||||
|
||||
@@ -983,7 +985,7 @@ void ParseUsdPhysicsCollider(mjSpec* spec,
|
||||
}
|
||||
|
||||
std::string mesh_name = usd_mesh.GetPath().GetAsString();
|
||||
mjs_setString(mesh->name, mesh_name.c_str());
|
||||
mjs_setName(mesh->element, mesh_name.c_str());
|
||||
mjs_setFloat(mesh->uservert, uservert.data(), uservert.size());
|
||||
mjs_setInt(mesh->userface, userface.data(), userface.size());
|
||||
|
||||
@@ -1047,7 +1049,7 @@ void ParseUsdPhysicsJoint(mjSpec* spec, const pxr::UsdPrim& prim, mjsBody* body,
|
||||
|
||||
mjsJoint* mj_joint = mjs_addJoint(body, nullptr);
|
||||
mj_joint->type = type;
|
||||
mjs_setString(mj_joint->name, prim.GetPath().GetAsString().c_str());
|
||||
mjs_setName(mj_joint->element, prim.GetPath().GetAsString().c_str());
|
||||
|
||||
if (prim.IsA<pxr::UsdPhysicsRevoluteJoint>()) {
|
||||
pxr::UsdPhysicsRevoluteJoint revolute(prim);
|
||||
@@ -1123,7 +1125,8 @@ void ParseUsdPhysicsJoint(mjSpec* spec, const pxr::UsdPrim& prim, mjsBody* body,
|
||||
|
||||
if (prim.HasAPI<pxr::MjcPhysicsActuatorAPI>()) {
|
||||
ParseMjcPhysicsGeneralActuatorAPI(spec, pxr::MjcPhysicsActuatorAPI(prim),
|
||||
mjtTrn::mjTRN_JOINT, mj_joint->name);
|
||||
mjtTrn::mjTRN_JOINT,
|
||||
mjs_getName(mj_joint->element));
|
||||
}
|
||||
|
||||
if (prim.HasAPI<pxr::MjcPhysicsJointAPI>()) {
|
||||
@@ -1136,7 +1139,7 @@ void ParseMjcPhysicsSite(mjSpec* spec, const pxr::MjcPhysicsSiteAPI& site_api,
|
||||
pxr::UsdGeomXformCache& xform_cache) {
|
||||
auto prim = site_api.GetPrim();
|
||||
mjsSite* site = mjs_addSite(parent, 0);
|
||||
mjs_setString(site->name, site_api.GetPrim().GetPath().GetAsString().c_str());
|
||||
mjs_setName(site->element, site_api.GetPrim().GetPath().GetAsString().c_str());
|
||||
SetLocalPoseFromPrim(site_api.GetPrim(), parent_prim, site, xform_cache);
|
||||
|
||||
// Convert USD type to MuJoCo type.
|
||||
@@ -1152,7 +1155,7 @@ void ParseMjcPhysicsSite(mjSpec* spec, const pxr::MjcPhysicsSiteAPI& site_api,
|
||||
ParseMjcPhysicsGeneralActuatorAPI(
|
||||
spec, pxr::MjcPhysicsActuatorAPI(prim),
|
||||
slider_crank ? mjtTrn::mjTRN_SLIDERCRANK : mjtTrn::mjTRN_SITE,
|
||||
site->name);
|
||||
mjs_getName(site->element));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1187,7 +1190,7 @@ void ParseMjcPhysicsKeyframe(mjSpec* spec,
|
||||
if (n_time_samples == 0) {
|
||||
// If no time samples, we create a single keyframe.
|
||||
mjsKey* key = mjs_addKey(spec);
|
||||
mjs_setString(key->name, prim.GetName().GetString().c_str());
|
||||
mjs_setName(key->element, prim.GetName().GetString().c_str());
|
||||
setKeyframeData(key, qpos_attr, &key->qpos);
|
||||
setKeyframeData(key, qvel_attr, &key->qvel);
|
||||
setKeyframeData(key, act_attr, &key->act);
|
||||
@@ -1203,7 +1206,7 @@ void ParseMjcPhysicsKeyframe(mjSpec* spec,
|
||||
mjsKey* key = mjs_addKey(spec);
|
||||
std::string key_name =
|
||||
prim.GetName().GetString() + "_" + std::to_string(keyframe_id++);
|
||||
mjs_setString(key->name, key_name.c_str());
|
||||
mjs_setName(key->element, key_name.c_str());
|
||||
key->time = time;
|
||||
setKeyframeData(key, qpos_attr, &key->qpos, &time);
|
||||
setKeyframeData(key, qvel_attr, &key->qvel, &time);
|
||||
@@ -1221,7 +1224,7 @@ mjsBody* ParseUsdPhysicsRigidbody(
|
||||
pxr::UsdGeomXformCache& xform_cache) {
|
||||
pxr::UsdPrim prim = rigidbody_api.GetPrim();
|
||||
mjsBody* body = mjs_addBody(parent, nullptr);
|
||||
mjs_setString(body->name, prim.GetPath().GetAsString().c_str());
|
||||
mjs_setName(body->element, prim.GetPath().GetAsString().c_str());
|
||||
SetLocalPoseFromPrim(prim, parent_prim, body, xform_cache);
|
||||
|
||||
if (prim.HasAPI<pxr::UsdPhysicsMassAPI>()) {
|
||||
@@ -1230,7 +1233,8 @@ mjsBody* ParseUsdPhysicsRigidbody(
|
||||
|
||||
if (prim.HasAPI<pxr::MjcPhysicsActuatorAPI>()) {
|
||||
ParseMjcPhysicsGeneralActuatorAPI(spec, pxr::MjcPhysicsActuatorAPI(prim),
|
||||
mjtTrn::mjTRN_BODY, body->name);
|
||||
mjtTrn::mjTRN_BODY,
|
||||
mjs_getName(body->element));
|
||||
}
|
||||
|
||||
mujoco::usd::SetUsdPrimPathUserValue(body->element, prim.GetPath());
|
||||
|
||||
@@ -1341,6 +1341,19 @@ mjsPlugin* mjs_asPlugin(mjsElement* element) {
|
||||
|
||||
|
||||
|
||||
// set element name
|
||||
void mjs_setName(mjsElement* element, const char* name) {
|
||||
if (element->elemtype == mjOBJ_DEFAULT) {
|
||||
mjCDef* def = static_cast<mjCDef*>(element);
|
||||
def->name = std::string(name);
|
||||
return;
|
||||
}
|
||||
mjCBase* baseC = static_cast<mjCBase*>(element);
|
||||
baseC->name = std::string(name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// copy buffer to destination buffer
|
||||
void mjs_setBuffer(mjByteVec* dest, const void* array, int size) {
|
||||
const std::byte* buffer = static_cast<const std::byte*>(array);
|
||||
@@ -1430,6 +1443,16 @@ void mjs_setDouble(mjDoubleVec* dest, const double* array, int size) {
|
||||
|
||||
|
||||
|
||||
// get name
|
||||
mjString* mjs_getName(mjsElement* element) {
|
||||
if (element->elemtype == mjOBJ_DEFAULT) {
|
||||
return &(static_cast<mjCDef*>(element)->name);
|
||||
}
|
||||
return &(static_cast<mjCBase*>(element)->name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// get string
|
||||
const char* mjs_getString(const mjString* source) {
|
||||
return source->c_str();
|
||||
|
||||
@@ -339,6 +339,9 @@ MJAPI mjsPlugin* mjs_asPlugin(mjsElement* element);
|
||||
|
||||
//---------------------------------- Attribute setters ---------------------------------------------
|
||||
|
||||
// Set element's name.
|
||||
MJAPI void mjs_setName(mjsElement* element, const char* name);
|
||||
|
||||
// Copy buffer.
|
||||
MJAPI void mjs_setBuffer(mjByteVec* dest, const void* array, int size);
|
||||
|
||||
@@ -375,6 +378,9 @@ MJAPI void mjs_setPluginAttributes(mjsPlugin* plugin, void* attributes);
|
||||
|
||||
//---------------------------------- Attribute getters ---------------------------------------------
|
||||
|
||||
// Get element's name.
|
||||
MJAPI mjString* mjs_getName(mjsElement* element);
|
||||
|
||||
// Get string contents.
|
||||
MJAPI const char* mjs_getString(const mjString* source);
|
||||
|
||||
|
||||
@@ -255,7 +255,7 @@ bool mjCComposite::MakeCable(mjCModel* model, mjsBody* body, char* error, int er
|
||||
|
||||
// add name to model
|
||||
mjsText* pte = mjs_addText(&model->spec);
|
||||
mjs_setString(pte->name, ("composite_" + prefix).c_str());
|
||||
mjs_setName(pte->element, ("composite_" + prefix).c_str());
|
||||
mjs_setString(pte->data, ("rope_" + prefix).c_str());
|
||||
|
||||
// populate uservert if not specified
|
||||
@@ -372,7 +372,7 @@ mjsBody* mjCComposite::AddCableBody(mjCModel* model, mjsBody* body, int ix,
|
||||
|
||||
// add body
|
||||
body = mjs_addBody(body, 0);
|
||||
mjs_setString(body->name, this_body);
|
||||
mjs_setName(body->element, this_body);
|
||||
if (first) {
|
||||
mjuu_setvec(body->pos, offset[0]+uservert[3*ix],
|
||||
offset[1]+uservert[3*ix+1],
|
||||
@@ -391,7 +391,7 @@ mjsBody* mjCComposite::AddCableBody(mjCModel* model, mjsBody* body, int ix,
|
||||
// add geom
|
||||
mjsGeom* geom = mjs_addGeom(body, &def[0].spec);
|
||||
mjs_setDefault(geom->element, mjs_getDefault(body->element));
|
||||
mjs_setString(geom->name, txt_geom);
|
||||
mjs_setName(geom->element, txt_geom);
|
||||
if (def[0].spec.geom->type == mjGEOM_CYLINDER ||
|
||||
def[0].spec.geom->type == mjGEOM_CAPSULE) {
|
||||
mjuu_zerovec(geom->fromto, 6);
|
||||
@@ -422,7 +422,7 @@ mjsBody* mjCComposite::AddCableBody(mjCModel* model, mjsBody* body, int ix,
|
||||
jnt->damping = jnt->type == mjJNT_FREE ? 0 : jnt->damping;
|
||||
jnt->armature = jnt->type == mjJNT_FREE ? 0 : jnt->armature;
|
||||
jnt->frictionloss = jnt->type == mjJNT_FREE ? 0 : jnt->frictionloss;
|
||||
mjs_setString(jnt->name, this_joint);
|
||||
mjs_setName(jnt->element, this_joint);
|
||||
}
|
||||
|
||||
// exclude contact pair
|
||||
@@ -436,7 +436,7 @@ mjsBody* mjCComposite::AddCableBody(mjCModel* model, mjsBody* body, int ix,
|
||||
if (last || first) {
|
||||
mjsSite* site = mjs_addSite(body, &def[0].spec);
|
||||
mjs_setDefault(site->element, mjs_getDefault(body->element));
|
||||
mjs_setString(site->name, txt_site);
|
||||
mjs_setName(site->element, txt_site);
|
||||
mjuu_setvec(site->pos, last ? length : 0, 0, 0);
|
||||
mjuu_setvec(site->quat, 1, 0, 0, 0);
|
||||
}
|
||||
@@ -480,7 +480,7 @@ void mjCComposite::MakeSkin2(mjCModel* model, mjtNum inflate) {
|
||||
// add skin, set name and material
|
||||
mjsSkin* skin = mjs_addSkin(&model->spec);
|
||||
mju::sprintf_arr(txt, "%sSkin", prefix.c_str());
|
||||
mjs_setString(skin->name, txt);
|
||||
mjs_setName(skin->element, txt);
|
||||
mjs_setString(skin->material, skinmaterial.c_str());
|
||||
mjuu_copyvec(skin->rgba, skinrgba, 4);
|
||||
skin->inflate = inflate;
|
||||
@@ -967,7 +967,7 @@ void mjCComposite::MakeSkin2Subgrid(mjCModel* model, mjtNum inflate) {
|
||||
char txt[100];
|
||||
mjsSkin* skin = mjs_addSkin(&model->spec);
|
||||
mju::sprintf_arr(txt, "%sSkin", prefix.c_str());
|
||||
mjs_setString(skin->name, txt);
|
||||
mjs_setName(skin->element, txt);
|
||||
mjs_setString(skin->material, skinmaterial.c_str());
|
||||
mjuu_copyvec(skin->rgba, skinrgba, 4);
|
||||
skin->inflate = inflate;
|
||||
|
||||
@@ -108,7 +108,7 @@ bool mjCFlexcomp::Make(mjsBody* body, char* error, int error_sz) {
|
||||
type == mjFCOMPTYPE_GMSH);
|
||||
|
||||
// check parent body name
|
||||
if (std::string(mjs_getString(body->name)).empty()) {
|
||||
if (mjs_getName(body->element)->empty()) {
|
||||
return comperr(error, "Parent body must have name", error_sz);
|
||||
}
|
||||
|
||||
@@ -410,7 +410,7 @@ bool mjCFlexcomp::Make(mjsBody* body, char* error, int error_sz) {
|
||||
|
||||
flex->model = model;
|
||||
flex->id = id;
|
||||
mjs_setString(pf->name, name.c_str());
|
||||
mjs_setName(pf->element, name.c_str());
|
||||
mjs_setInt(pf->elem, element.data(), element.size());
|
||||
mjs_setFloat(pf->texcoord, texcoord.data(), texcoord.size());
|
||||
mjs_setInt(pf->elemtexcoord, elemtexcoord.data(), elemtexcoord.size());
|
||||
@@ -420,7 +420,7 @@ bool mjCFlexcomp::Make(mjsBody* body, char* error, int error_sz) {
|
||||
|
||||
// rigid: set parent name, nothing else to do
|
||||
if (rigid) {
|
||||
mjs_appendString(pf->vertbody, mjs_getString(body->name));
|
||||
mjs_appendString(pf->vertbody, mjs_getName(body->element)->c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -443,7 +443,7 @@ bool mjCFlexcomp::Make(mjsBody* body, char* error, int error_sz) {
|
||||
|
||||
// pinned or trilinear: parent body
|
||||
if (pinned[i] || doftype == mjFCOMPDOF_TRILINEAR) {
|
||||
mjs_appendString(pf->vertbody, mjs_getString(body->name));
|
||||
mjs_appendString(pf->vertbody, mjs_getName(body->element)->c_str());
|
||||
|
||||
// add plugin
|
||||
if (plugin.active) {
|
||||
@@ -507,8 +507,8 @@ bool mjCFlexcomp::Make(mjsBody* body, char* error, int error_sz) {
|
||||
// construct body name, add to vertbody
|
||||
char txt[100];
|
||||
mju::sprintf_arr(txt, "%s_%d", name.c_str(), i);
|
||||
mjs_setString(pb->name, txt);
|
||||
mjs_appendString(pf->vertbody, mjs_getString(pb->name));
|
||||
mjs_setName(pb->element, txt);
|
||||
mjs_appendString(pf->vertbody, mjs_getName(pb->element)->c_str());
|
||||
|
||||
// clear flex vertex coordinates if allocated
|
||||
if (!centered) {
|
||||
@@ -538,7 +538,7 @@ bool mjCFlexcomp::Make(mjsBody* body, char* error, int error_sz) {
|
||||
node[3*(i*4+j*2+k)+0] = i == 0 ? minmax[0] : minmax[3];
|
||||
node[3*(i*4+j*2+k)+1] = j == 0 ? minmax[1] : minmax[4];
|
||||
node[3*(i*4+j*2+k)+2] = k == 0 ? minmax[2] : minmax[5];
|
||||
mjs_appendString(pf->nodebody, mjs_getString(body->name));
|
||||
mjs_appendString(pf->nodebody, mjs_getName(body->element)->c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -571,8 +571,8 @@ bool mjCFlexcomp::Make(mjsBody* body, char* error, int error_sz) {
|
||||
// construct node name, add to nodebody
|
||||
char txt[100];
|
||||
mju::sprintf_arr(txt, "%s_%d_%d_%d", name.c_str(), i, j, k);
|
||||
mjs_setString(pb->name, txt);
|
||||
mjs_appendString(pf->nodebody, mjs_getString(pb->name));
|
||||
mjs_setName(pb->element, txt);
|
||||
mjs_appendString(pf->nodebody, mjs_getName(pb->element)->c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +194,6 @@ mjCMesh& mjCMesh::operator=(const mjCMesh& other) {
|
||||
|
||||
void mjCMesh::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.file = &spec_file_;
|
||||
spec.content_type = &spec_content_type_;
|
||||
spec.uservert = &spec_vert_;
|
||||
@@ -2428,7 +2427,6 @@ mjCSkin& mjCSkin::operator=(const mjCSkin& other) {
|
||||
|
||||
void mjCSkin::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.file = &spec_file_;
|
||||
spec.material = &spec_material_;
|
||||
spec.vert = &spec_vert_;
|
||||
@@ -3327,7 +3325,6 @@ mjCFlex& mjCFlex::operator=(const mjCFlex& other) {
|
||||
|
||||
void mjCFlex::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.material = &spec_material_;
|
||||
spec.vertbody = &spec_vertbody_;
|
||||
spec.nodebody = &spec_nodebody_;
|
||||
|
||||
@@ -747,6 +747,7 @@ void mjCDef::NameSpace(const mjCModel* m) {
|
||||
|
||||
void mjCDef::CopyWithoutChildren(const mjCDef& other) {
|
||||
name = other.name;
|
||||
elemtype = other.elemtype;
|
||||
parent = nullptr;
|
||||
child.clear();
|
||||
joint_ = other.joint_;
|
||||
@@ -780,7 +781,6 @@ void mjCDef::PointToLocal() {
|
||||
tendon_.PointToLocal();
|
||||
actuator_.PointToLocal();
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.joint = &joint_.spec;
|
||||
spec.geom = &geom_.spec;
|
||||
spec.site = &site_.spec;
|
||||
@@ -1261,7 +1261,6 @@ void mjCBody::ResetId() {
|
||||
|
||||
void mjCBody::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.childclass = &classname;
|
||||
spec.userdata = &spec_userdata_;
|
||||
spec.plugin.plugin_name = &plugin_name;
|
||||
@@ -2310,7 +2309,6 @@ bool mjCFrame::IsAncestor(const mjCFrame* child) const {
|
||||
|
||||
void mjCFrame::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.childclass = &classname;
|
||||
spec.info = &info;
|
||||
}
|
||||
@@ -2461,7 +2459,6 @@ mjtNum* mjCJoint::qvel(const std::string& state_name) {
|
||||
|
||||
void mjCJoint::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.userdata = &spec_userdata_;
|
||||
spec.info = &info;
|
||||
userdata = nullptr;
|
||||
@@ -2659,7 +2656,6 @@ mjCGeom& mjCGeom::operator=(const mjCGeom& other) {
|
||||
// to be called after any default copy constructor
|
||||
void mjCGeom::PointToLocal(void) {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.info = &info;
|
||||
spec.userdata = &spec_userdata_;
|
||||
spec.material = &spec_material_;
|
||||
@@ -3481,7 +3477,6 @@ mjCSite& mjCSite::operator=(const mjCSite& other) {
|
||||
|
||||
void mjCSite::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.info = &info;
|
||||
spec.material = &spec_material_;
|
||||
spec.userdata = &spec_userdata_;
|
||||
@@ -3642,7 +3637,6 @@ mjCCamera& mjCCamera::operator=(const mjCCamera& other) {
|
||||
|
||||
void mjCCamera::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.userdata = &spec_userdata_;
|
||||
spec.targetbody = &spec_targetbody_;
|
||||
spec.info = &info;
|
||||
@@ -3800,7 +3794,6 @@ mjCLight& mjCLight::operator=(const mjCLight& other) {
|
||||
|
||||
void mjCLight::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.targetbody = &spec_targetbody_;
|
||||
spec.texture = &spec_texture_;
|
||||
spec.info = &info;
|
||||
@@ -3920,7 +3913,6 @@ mjCHField& mjCHField::operator=(const mjCHField& other) {
|
||||
|
||||
void mjCHField::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.file = &spec_file_;
|
||||
spec.content_type = &spec_content_type_;
|
||||
spec.userdata = &spec_userdata_;
|
||||
@@ -4185,7 +4177,6 @@ mjCTexture& mjCTexture::operator=(const mjCTexture& other) {
|
||||
|
||||
void mjCTexture::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.file = &spec_file_;
|
||||
spec.data = &data_;
|
||||
spec.content_type = &spec_content_type_;
|
||||
@@ -5054,7 +5045,6 @@ mjCMaterial& mjCMaterial::operator=(const mjCMaterial& other) {
|
||||
|
||||
void mjCMaterial::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.textures = &spec_textures_;
|
||||
spec.info = &info;
|
||||
textures = nullptr;
|
||||
@@ -5144,7 +5134,6 @@ mjCPair& mjCPair::operator=(const mjCPair& other) {
|
||||
|
||||
void mjCPair::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.geomname1 = &spec_geomname1_;
|
||||
spec.geomname2 = &spec_geomname2_;
|
||||
geomname1 = nullptr;
|
||||
@@ -5367,7 +5356,6 @@ mjCBodyPair& mjCBodyPair::operator=(const mjCBodyPair& other) {
|
||||
|
||||
void mjCBodyPair::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.bodyname1 = &spec_bodyname1_;
|
||||
spec.bodyname2 = &spec_bodyname2_;
|
||||
spec.info = &info;
|
||||
@@ -5502,7 +5490,6 @@ mjCEquality& mjCEquality::operator=(const mjCEquality& other) {
|
||||
|
||||
void mjCEquality::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.name1 = &spec_name1_;
|
||||
spec.name2 = &spec_name2_;
|
||||
spec.info = &info;
|
||||
@@ -5679,7 +5666,6 @@ bool mjCTendon::is_actfrclimited() const {
|
||||
|
||||
void mjCTendon::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.material = &spec_material_;
|
||||
spec.userdata = &spec_userdata_;
|
||||
spec.info = &info;
|
||||
@@ -6225,7 +6211,6 @@ mjtNum& mjCActuator::ctrl(const std::string& state_name) {
|
||||
|
||||
void mjCActuator::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.userdata = &spec_userdata_;
|
||||
spec.target = &spec_target_;
|
||||
spec.refsite = &spec_refsite_;
|
||||
@@ -6563,7 +6548,6 @@ mjCSensor& mjCSensor::operator=(const mjCSensor& other) {
|
||||
|
||||
void mjCSensor::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.userdata = &spec_userdata_;
|
||||
spec.objname = &spec_objname_;
|
||||
spec.refname = &spec_refname_;
|
||||
@@ -7103,7 +7087,6 @@ mjCNumeric& mjCNumeric::operator=(const mjCNumeric& other) {
|
||||
|
||||
void mjCNumeric::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.data = &spec_data_;
|
||||
spec.info = &info;
|
||||
data = nullptr;
|
||||
@@ -7193,7 +7176,6 @@ mjCText& mjCText::operator=(const mjCText& other) {
|
||||
|
||||
void mjCText::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.data = &spec_data_;
|
||||
spec.info = &info;
|
||||
data = nullptr;
|
||||
@@ -7274,7 +7256,6 @@ mjCTuple& mjCTuple::operator=(const mjCTuple& other) {
|
||||
|
||||
void mjCTuple::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.objtype = (mjIntVec*)&spec_objtype_;
|
||||
spec.objname = &spec_objname_;
|
||||
spec.objprm = &spec_objprm_;
|
||||
@@ -7410,7 +7391,6 @@ mjCKey& mjCKey::operator=(const mjCKey& other) {
|
||||
|
||||
void mjCKey::PointToLocal() {
|
||||
spec.element = static_cast<mjsElement*>(this);
|
||||
spec.name = &name;
|
||||
spec.qpos = &spec_qpos_;
|
||||
spec.qvel = &spec_qvel_;
|
||||
spec.act = &spec_act_;
|
||||
@@ -7556,7 +7536,6 @@ mjCPlugin::mjCPlugin(mjCModel* _model) {
|
||||
mjs_defaultPlugin(&spec);
|
||||
elemtype = mjOBJ_PLUGIN;
|
||||
spec.plugin_name = &plugin_name;
|
||||
spec.name = &name;
|
||||
spec.info = &info;
|
||||
|
||||
PointToLocal();
|
||||
|
||||
@@ -465,7 +465,6 @@ class mjCBody : public mjCBody_, private mjsBody {
|
||||
mjsBody spec;
|
||||
|
||||
// inherited
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
// used by mjXWriter and mjCModel
|
||||
@@ -564,7 +563,6 @@ class mjCFrame : public mjCFrame_, private mjsFrame {
|
||||
mjCFrame& operator=(const mjCFrame& other);
|
||||
|
||||
mjsFrame spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void CopyFromSpec(void);
|
||||
@@ -617,7 +615,6 @@ class mjCJoint : public mjCJoint_, private mjsJoint {
|
||||
mjCJoint& operator=(const mjCJoint& other);
|
||||
|
||||
mjsJoint spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void CopyFromSpec(void);
|
||||
@@ -696,7 +693,6 @@ class mjCGeom : public mjCGeom_, private mjsGeom {
|
||||
mjCGeom(const mjCGeom& other);
|
||||
mjCGeom& operator=(const mjCGeom& other);
|
||||
|
||||
using mjCBase::name;
|
||||
mjsGeom spec; // variables set by user
|
||||
double GetVolume() const; // compute geom volume
|
||||
void SetInertia(void); // compute and set geom inertia
|
||||
@@ -769,7 +765,6 @@ class mjCSite : public mjCSite_, private mjsSite {
|
||||
mjCBody* GetParent() const { return body; }
|
||||
|
||||
// use strings from mjCBase rather than mjStrings from mjsSite
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
// used by mjXWriter and mjCModel
|
||||
@@ -812,7 +807,6 @@ class mjCCamera : public mjCCamera_, private mjsCamera {
|
||||
mjCCamera& operator=(const mjCCamera& other);
|
||||
|
||||
mjsCamera spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
// used by mjXWriter and mjCModel
|
||||
@@ -858,7 +852,6 @@ class mjCLight : public mjCLight_, private mjsLight {
|
||||
mjCLight& operator=(const mjCLight& other);
|
||||
|
||||
mjsLight spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
// used by mjXWriter and mjCModel
|
||||
@@ -943,7 +936,6 @@ class mjCFlex: public mjCFlex_, private mjsFlex {
|
||||
mjCFlex& operator=(const mjCFlex& other);
|
||||
|
||||
mjsFlex spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void CopyFromSpec(void);
|
||||
@@ -1049,7 +1041,6 @@ class mjCMesh: public mjCMesh_, private mjsMesh {
|
||||
~mjCMesh();
|
||||
|
||||
mjsMesh spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void CopyFromSpec(void);
|
||||
@@ -1255,7 +1246,6 @@ class mjCSkin: public mjCSkin_, private mjsSkin {
|
||||
~mjCSkin();
|
||||
|
||||
mjsSkin spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
const std::string& File() const { return file_; }
|
||||
@@ -1313,7 +1303,6 @@ class mjCHField : public mjCHField_, private mjsHField {
|
||||
~mjCHField();
|
||||
|
||||
mjsHField spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void CopyFromSpec(void);
|
||||
@@ -1365,7 +1354,6 @@ class mjCTexture : public mjCTexture_, private mjsTexture {
|
||||
~mjCTexture();
|
||||
|
||||
mjsTexture spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void CopyFromSpec(void);
|
||||
@@ -1425,7 +1413,6 @@ class mjCMaterial : public mjCMaterial_, private mjsMaterial {
|
||||
mjCMaterial& operator=(const mjCMaterial& other);
|
||||
|
||||
mjsMaterial spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void CopyFromSpec();
|
||||
@@ -1465,7 +1452,6 @@ class mjCPair : public mjCPair_, private mjsPair {
|
||||
mjCPair& operator=(const mjCPair& other);
|
||||
|
||||
mjsPair spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void CopyFromSpec();
|
||||
@@ -1514,7 +1500,6 @@ class mjCBodyPair : public mjCBodyPair_, private mjsExclude {
|
||||
mjCBodyPair& operator=(const mjCBodyPair& other);
|
||||
|
||||
mjsExclude spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void CopyFromSpec();
|
||||
@@ -1560,7 +1545,6 @@ class mjCEquality : public mjCEquality_, private mjsEquality {
|
||||
mjCEquality& operator=(const mjCEquality& other);
|
||||
|
||||
mjsEquality spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void CopyFromSpec();
|
||||
@@ -1600,7 +1584,6 @@ class mjCTendon : public mjCTendon_, private mjsTendon {
|
||||
~mjCTendon();
|
||||
|
||||
mjsTendon spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void set_material(std::string _material) { material_ = _material; }
|
||||
@@ -1743,7 +1726,6 @@ class mjCActuator : public mjCActuator_, private mjsActuator {
|
||||
mjCActuator& operator=(const mjCActuator& other);
|
||||
|
||||
mjsActuator spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
// used by mjXWriter and mjCModel
|
||||
@@ -1804,7 +1786,6 @@ class mjCSensor : public mjCSensor_, private mjsSensor {
|
||||
mjCSensor& operator=(const mjCSensor& other);
|
||||
|
||||
mjsSensor spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
// used by mjXWriter and mjCModel
|
||||
@@ -1846,7 +1827,6 @@ class mjCNumeric : public mjCNumeric_, private mjsNumeric {
|
||||
~mjCNumeric();
|
||||
|
||||
mjsNumeric spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void PointToLocal();
|
||||
@@ -1878,7 +1858,6 @@ class mjCText : public mjCText_, private mjsText {
|
||||
~mjCText();
|
||||
|
||||
mjsText spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void PointToLocal();
|
||||
@@ -1915,7 +1894,6 @@ class mjCTuple : public mjCTuple_, private mjsTuple {
|
||||
~mjCTuple();
|
||||
|
||||
mjsTuple spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void PointToLocal();
|
||||
@@ -1959,7 +1937,6 @@ class mjCKey : public mjCKey_, private mjsKey {
|
||||
~mjCKey();
|
||||
|
||||
mjsKey spec;
|
||||
using mjCBase::name;
|
||||
using mjCBase::info;
|
||||
|
||||
void PointToLocal();
|
||||
|
||||
@@ -1355,7 +1355,7 @@ void mjXReader::OneFlex(XMLElement* elem, mjsFlex* flex) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(flex->name, name.c_str());
|
||||
mjs_setName(flex->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "material", material)) {
|
||||
mjs_setString(flex->material, material.c_str());
|
||||
@@ -1446,7 +1446,7 @@ void mjXReader::OneMesh(XMLElement* elem, mjsMesh* mesh, const mjVFS* vfs) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
*mesh->name = name;
|
||||
mjs_setName(mesh->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "content_type", content_type)) {
|
||||
*mesh->content_type = content_type;
|
||||
@@ -1521,7 +1521,7 @@ void mjXReader::OneSkin(XMLElement* elem, mjsSkin* skin, const mjVFS* vfs) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(skin->name, name.c_str());
|
||||
mjs_setName(skin->element, name.c_str());
|
||||
}
|
||||
auto file = ReadAttrFile(elem, "file", vfs, AssetDir());
|
||||
if (file.has_value()) {
|
||||
@@ -1611,7 +1611,7 @@ void mjXReader::OneMaterial(XMLElement* elem, mjsMaterial* material) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(material->name, name.c_str());
|
||||
mjs_setName(material->element, name.c_str());
|
||||
}
|
||||
|
||||
bool tex_attributes_found = false;
|
||||
@@ -1660,7 +1660,7 @@ void mjXReader::OneJoint(XMLElement* elem, mjsJoint* joint) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(joint->name, name.c_str());
|
||||
mjs_setName(joint->element, name.c_str());
|
||||
}
|
||||
if (MapValue(elem, "type", &n, joint_map, joint_sz)) {
|
||||
joint->type = (mjtJoint)n;
|
||||
@@ -1708,7 +1708,7 @@ void mjXReader::OneGeom(XMLElement* elem, mjsGeom* geom) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(geom->name, name.c_str());
|
||||
mjs_setName(geom->element, name.c_str());
|
||||
}
|
||||
if (MapValue(elem, "type", &n, geom_map, mjNGEOMTYPES)) {
|
||||
geom->type = (mjtGeom)n;
|
||||
@@ -1780,7 +1780,7 @@ void mjXReader::OneSite(XMLElement* elem, mjsSite* site) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(site->name, name.c_str());
|
||||
mjs_setName(site->element, name.c_str());
|
||||
}
|
||||
if (MapValue(elem, "type", &n, geom_map, mjNGEOMTYPES)) {
|
||||
site->type = (mjtGeom)n;
|
||||
@@ -1813,7 +1813,7 @@ void mjXReader::OneCamera(XMLElement* elem, mjsCamera* camera) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(camera->name, name.c_str());
|
||||
mjs_setName(camera->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "target", targetbody)) {
|
||||
mjs_setString(camera->targetbody, targetbody.c_str());
|
||||
@@ -1868,7 +1868,7 @@ void mjXReader::OneLight(XMLElement* elem, mjsLight* light) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(light->name, name.c_str());
|
||||
mjs_setName(light->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "texture", texture)) {
|
||||
mjs_setString(light->texture, texture.c_str());
|
||||
@@ -1929,7 +1929,7 @@ void mjXReader::OnePair(XMLElement* elem, mjsPair* pair) {
|
||||
|
||||
// read other parameters
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(pair->name, name.c_str());
|
||||
mjs_setName(pair->element, name.c_str());
|
||||
}
|
||||
ReadAttrInt(elem, "condim", &pair->condim);
|
||||
ReadAttr(elem, "solref", mjNREF, pair->solref, text, false, false);
|
||||
@@ -1957,7 +1957,7 @@ void mjXReader::OneEquality(XMLElement* elem, mjsEquality* equality) {
|
||||
// regular only
|
||||
if (!readingdefaults) {
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(equality->name, name.c_str());
|
||||
mjs_setName(equality->element, name.c_str());
|
||||
}
|
||||
|
||||
switch (equality->type) {
|
||||
@@ -2093,7 +2093,7 @@ void mjXReader::OneTendon(XMLElement* elem, mjsTendon* tendon) {
|
||||
|
||||
// read attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(tendon->name, name.c_str());
|
||||
mjs_setName(tendon->element, name.c_str());
|
||||
}
|
||||
ReadAttrInt(elem, "group", &tendon->group);
|
||||
if (ReadAttrTxt(elem, "material", material)) {
|
||||
@@ -2136,7 +2136,7 @@ void mjXReader::OneActuator(XMLElement* elem, mjsActuator* actuator) {
|
||||
|
||||
// common attributes
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(actuator->name, name.c_str());
|
||||
mjs_setName(actuator->element, name.c_str());
|
||||
}
|
||||
ReadAttrInt(elem, "group", &actuator->group);
|
||||
MapValue(elem, "ctrllimited", &actuator->ctrllimited, TFAuto_map, 3);
|
||||
@@ -2884,7 +2884,7 @@ void mjXReader::Custom(XMLElement* section) {
|
||||
|
||||
// read attributes
|
||||
ReadAttrTxt(elem, "name", elname, true);
|
||||
mjs_setString(numeric->name, elname.c_str());
|
||||
mjs_setName(numeric->element, elname.c_str());
|
||||
if (ReadAttrInt(elem, "size", &numeric->size)) {
|
||||
int sz = numeric->size < 500 ? numeric->size : 500;
|
||||
for (int i=0; i < sz; i++) {
|
||||
@@ -2915,7 +2915,7 @@ void mjXReader::Custom(XMLElement* section) {
|
||||
|
||||
// read attributes
|
||||
ReadAttrTxt(elem, "name", elname, true);
|
||||
mjs_setString(text->name, elname.c_str());
|
||||
mjs_setName(text->element, elname.c_str());
|
||||
ReadAttrTxt(elem, "data", str, true);
|
||||
if (str.empty()) {
|
||||
throw mjXError(elem, "text field cannot be empty");
|
||||
@@ -2935,7 +2935,7 @@ void mjXReader::Custom(XMLElement* section) {
|
||||
|
||||
// read attributes
|
||||
ReadAttrTxt(elem, "name", elname, true);
|
||||
mjs_setString(tuple->name, elname.c_str());
|
||||
mjs_setName(tuple->element, elname.c_str());
|
||||
|
||||
// read objects and add
|
||||
XMLElement* obj = FirstChildElement(elem);
|
||||
@@ -3151,7 +3151,7 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) {
|
||||
texture->colorspace = (mjtColorSpace)n;
|
||||
}
|
||||
if (ReadAttrTxt(elem, "name", texname)) {
|
||||
mjs_setString(texture->name, texname.c_str());
|
||||
mjs_setName(texture->element, texname.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "content_type", content_type)) {
|
||||
mjs_setString(texture->content_type, content_type.c_str());
|
||||
@@ -3243,7 +3243,7 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) {
|
||||
// read attributes
|
||||
string name, content_type;
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(hfield->name, name.c_str());
|
||||
mjs_setName(hfield->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "content_type", content_type)) {
|
||||
mjs_setString(hfield->content_type, content_type.c_str());
|
||||
@@ -3406,7 +3406,7 @@ void mjXReader::Body(XMLElement* section, mjsBody* body, mjsFrame* frame,
|
||||
// read attributes
|
||||
string name;
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(joint->name, name.c_str());
|
||||
mjs_setName(joint->element, name.c_str());
|
||||
}
|
||||
ReadAttrInt(elem, "group", &joint->group);
|
||||
MapValue(elem, "align", &joint->align, TFAuto_map, 3);
|
||||
@@ -3478,7 +3478,7 @@ void mjXReader::Body(XMLElement* section, mjsBody* body, mjsFrame* frame,
|
||||
// read attributes
|
||||
string name, childclass;
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(pframe->name, name.c_str());
|
||||
mjs_setName(pframe->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "childclass", childclass)) {
|
||||
mjs_setString(pframe->childclass, childclass.c_str());
|
||||
@@ -3579,7 +3579,7 @@ void mjXReader::Body(XMLElement* section, mjsBody* body, mjsFrame* frame,
|
||||
// read attributes
|
||||
string name, childclass;
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(child->name, name.c_str());
|
||||
mjs_setName(child->element, name.c_str());
|
||||
}
|
||||
if (ReadAttrTxt(elem, "childclass", childclass)) {
|
||||
mjs_setString(child->childclass, childclass.c_str());
|
||||
@@ -3688,7 +3688,7 @@ void mjXReader::Contact(XMLElement* section) {
|
||||
|
||||
// read name and body names
|
||||
if (ReadAttrTxt(elem, "name", exname)) {
|
||||
mjs_setString(exclude->name, exname.c_str());
|
||||
mjs_setName(exclude->element, exname.c_str());
|
||||
}
|
||||
ReadAttrTxt(elem, "body1", exbody1, true);
|
||||
mjs_setString(exclude->bodyname1, exbody1.c_str());
|
||||
@@ -3870,7 +3870,7 @@ void mjXReader::Sensor(XMLElement* section) {
|
||||
|
||||
// read name, noise, userdata
|
||||
if (ReadAttrTxt(elem, "name", name)) {
|
||||
mjs_setString(sensor->name, name.c_str());
|
||||
mjs_setName(sensor->element, name.c_str());
|
||||
}
|
||||
ReadAttr(elem, "cutoff", 1, &sensor->cutoff, text);
|
||||
ReadAttr(elem, "noise", 1, &sensor->noise, text);
|
||||
@@ -4215,7 +4215,7 @@ void mjXReader::Keyframe(XMLElement* section) {
|
||||
|
||||
// read name, time
|
||||
ReadAttrTxt(elem, "name", name);
|
||||
mjs_setString(key->name, name.c_str());
|
||||
mjs_setName(key->element, name.c_str());
|
||||
ReadAttr(elem, "time", 1, &key->time, text);
|
||||
|
||||
// read qpos
|
||||
|
||||
+13
-13
@@ -216,7 +216,7 @@ void mjXURDF::Parse(
|
||||
// if the mass is 0, assume the object is static
|
||||
if (!static_body && pbody->mass > 0) {
|
||||
mjsJoint* pjoint = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint->name, (urName[i] + "_free_joint").c_str());
|
||||
mjs_setName(pjoint->element, (urName[i] + "_free_joint").c_str());
|
||||
pjoint->type = mjJNT_FREE;
|
||||
}
|
||||
}
|
||||
@@ -327,7 +327,7 @@ void mjXURDF::Body(XMLElement* body_elem) {
|
||||
mjXUtil::ReadAttrTxt(elem, "name", geom_name);
|
||||
name = GetPrefixedName(name);
|
||||
if (urGeomNames.find(geom_name) == urGeomNames.end()) {
|
||||
mjs_setString(pgeom->name, geom_name.c_str());
|
||||
mjs_setName(pgeom->element, geom_name.c_str());
|
||||
urGeomNames.insert(geom_name);
|
||||
} else if (!geom_name.empty()) {
|
||||
std::cerr << "WARNING: Geom with duplicate name '" << geom_name
|
||||
@@ -350,7 +350,7 @@ void mjXURDF::Body(XMLElement* body_elem) {
|
||||
mjXUtil::ReadAttrTxt(elem, "name", geom_name);
|
||||
geom_name = GetPrefixedName(geom_name);
|
||||
if (urGeomNames.find(geom_name) == urGeomNames.end()) {
|
||||
mjs_setString(pgeom->name, geom_name.c_str());
|
||||
mjs_setName(pgeom->element, geom_name.c_str());
|
||||
urGeomNames.insert(geom_name);
|
||||
} else if (!geom_name.empty()) {
|
||||
std::cerr << "WARNING: Geom with duplicate name '" << geom_name
|
||||
@@ -420,7 +420,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
case 0: // revolute
|
||||
case 1: // continuous
|
||||
pjoint = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint->name, jntname.c_str());
|
||||
mjs_setName(pjoint->element, jntname.c_str());
|
||||
pjoint->type = mjJNT_HINGE;
|
||||
mjuu_setvec(pjoint->pos, 0, 0, 0);
|
||||
mjuu_copyvec(pjoint->axis, axis, 3);
|
||||
@@ -428,7 +428,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
|
||||
case 2: // prismatic
|
||||
pjoint = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint->name, jntname.c_str());
|
||||
mjs_setName(pjoint->element, jntname.c_str());
|
||||
pjoint->type = mjJNT_SLIDE;
|
||||
mjuu_setvec(pjoint->pos, 0, 0, 0);
|
||||
mjuu_copyvec(pjoint->axis, axis, 3);
|
||||
@@ -439,7 +439,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
|
||||
case 4: // floating
|
||||
pjoint = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint->name, jntname.c_str());
|
||||
mjs_setName(pjoint->element, jntname.c_str());
|
||||
pjoint->type = mjJNT_FREE;
|
||||
break;
|
||||
|
||||
@@ -450,7 +450,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
|
||||
// construct slider along x
|
||||
pjoint = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint->name, (jntname + "_TX").c_str());
|
||||
mjs_setName(pjoint->element, (jntname + "_TX").c_str());
|
||||
pjoint->type = mjJNT_SLIDE;
|
||||
tmpaxis[0] = mat[0];
|
||||
tmpaxis[1] = mat[3];
|
||||
@@ -460,7 +460,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
|
||||
// construct slider along y
|
||||
pjoint1 = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint1->name, (jntname + "_TY").c_str());
|
||||
mjs_setName(pjoint1->element, (jntname + "_TY").c_str());
|
||||
pjoint1->type = mjJNT_SLIDE;
|
||||
tmpaxis[0] = mat[1];
|
||||
tmpaxis[1] = mat[4];
|
||||
@@ -470,7 +470,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
|
||||
// construct hinge around z = locaxis
|
||||
pjoint2 = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint2->name, (jntname + "_RZ").c_str());
|
||||
mjs_setName(pjoint2->element, (jntname + "_RZ").c_str());
|
||||
pjoint2->type = mjJNT_HINGE;
|
||||
mjuu_setvec(pjoint2->pos, 0, 0, 0);
|
||||
mjuu_copyvec(pjoint2->axis, axis, 3);
|
||||
@@ -478,7 +478,7 @@ void mjXURDF::Joint(XMLElement* joint_elem) {
|
||||
|
||||
case 6: // ball joint
|
||||
pjoint = mjs_addJoint(pbody, 0);
|
||||
mjs_setString(pjoint->name, jntname.c_str());
|
||||
mjs_setName(pjoint->element, jntname.c_str());
|
||||
pjoint->type = mjJNT_BALL;
|
||||
mjuu_setvec(pjoint->pos, 0, 0, 0);
|
||||
mjuu_copyvec(pjoint->axis, axis, 3);
|
||||
@@ -530,7 +530,7 @@ mjsGeom* mjXURDF::Geom(XMLElement* geom_elem, mjsBody* pbody, bool collision) {
|
||||
|
||||
// add BOX geom, modify type later
|
||||
mjsGeom* pgeom = mjs_addGeom(pbody, 0);
|
||||
mjs_setString(pgeom->name, "");
|
||||
mjs_setName(pgeom->element, "");
|
||||
pgeom->type = mjGEOM_BOX;
|
||||
if (collision) {
|
||||
pgeom->contype = 1;
|
||||
@@ -624,7 +624,7 @@ mjsGeom* mjXURDF::Geom(XMLElement* geom_elem, mjsBody* pbody, bool collision) {
|
||||
// set fields
|
||||
if (newmesh) {
|
||||
mjs_setString(pmesh->file, meshfile.c_str());
|
||||
mjs_setString(pmesh->name, meshname.c_str());
|
||||
mjs_setName(pmesh->element, meshname.c_str());
|
||||
pmesh->scale[0] = meshscale[0];
|
||||
pmesh->scale[1] = meshscale[1];
|
||||
pmesh->scale[2] = meshscale[2];
|
||||
@@ -726,7 +726,7 @@ void mjXURDF::AddToTree(int n) {
|
||||
// add this body
|
||||
if (urName[n] != "world") {
|
||||
child = mjs_addBody(parent, 0);
|
||||
mjs_setString(child->name, urName[n].c_str());
|
||||
mjs_setName(child->element, urName[n].c_str());
|
||||
}
|
||||
|
||||
// add children recursively
|
||||
|
||||
Reference in New Issue
Block a user