Replace name attribute with setters and getters in the C API of mjSpec.

PiperOrigin-RevId: 778816015
Change-Id: Ieffb7a5bce37e887ff009f9a02d2434435e79ca1
This commit is contained in:
Alessio Quaglino
2025-07-03 02:29:49 -07:00
committed by Copybara-Service
parent 1c5d47c94b
commit 594e17074a
22 changed files with 290 additions and 400 deletions
+18
View File
@@ -4228,6 +4228,15 @@ Return spec's next element; return NULL if element is last.
Attribute setters
^^^^^^^^^^^^^^^^^
.. _mjs_setName:
`mjs_setName <#mjs_setName>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mjs_setName
Set element's name.
.. _mjs_setBuffer:
`mjs_setBuffer <#mjs_setBuffer>`__
@@ -4331,6 +4340,15 @@ Set plugin attributes.
Attribute getters
^^^^^^^^^^^^^^^^^
.. _mjs_getName:
`mjs_getName <#mjs_getName>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mjs_getName
Get element's name.
.. _mjs_getString:
`mjs_getString <#mjs_getString>`__
+2 -24
View File
@@ -1875,7 +1875,6 @@ typedef struct mjsPlugin_ { // plugin specification
} mjsPlugin;
typedef struct mjsBody_ { // body specification
mjsElement* element; // element type
mjString* name; // name
mjString* childclass; // childclass name
// body frame
@@ -1901,7 +1900,6 @@ typedef struct mjsBody_ { // body specification
} mjsBody;
typedef struct mjsFrame_ { // frame specification
mjsElement* element; // element type
mjString* name; // name
mjString* childclass; // childclass name
double pos[3]; // position
double quat[4]; // orientation
@@ -1910,7 +1908,6 @@ typedef struct mjsFrame_ { // frame specification
} mjsFrame;
typedef struct mjsJoint_ { // joint specification
mjsElement* element; // element type
mjString* name; // name
mjtJoint type; // joint type
// kinematics
@@ -1948,7 +1945,6 @@ typedef struct mjsJoint_ { // joint specification
} mjsJoint;
typedef struct mjsGeom_ { // geom specification
mjsElement* element; // element type
mjString* name; // name
mjtGeom type; // geom type
// frame, size
@@ -1994,7 +1990,6 @@ typedef struct mjsGeom_ { // geom specification
} mjsGeom;
typedef struct mjsSite_ { // site specification
mjsElement* element; // element type
mjString* name; // name
// frame, size
double pos[3]; // position
@@ -2015,7 +2010,6 @@ typedef struct mjsSite_ { // site specification
} mjsSite;
typedef struct mjsCamera_ { // camera specification
mjsElement* element; // element type
mjString* name; // name
// extrinsics
double pos[3]; // position
@@ -2042,7 +2036,6 @@ typedef struct mjsCamera_ { // camera specification
} mjsCamera;
typedef struct mjsLight_ { // light specification
mjsElement* element; // element type
mjString* name; // name
// frame
double pos[3]; // position
@@ -2070,7 +2063,6 @@ typedef struct mjsLight_ { // light specification
} mjsLight;
typedef struct mjsFlex_ { // flex specification
mjsElement* element; // element type
mjString* name; // name
// contact properties
int contype; // contact type
@@ -2117,7 +2109,6 @@ typedef struct mjsFlex_ { // flex specification
} mjsFlex;
typedef struct mjsMesh_ { // mesh specification
mjsElement* element; // element type
mjString* name; // name
mjString* content_type; // content type of file
mjString* file; // mesh file
double refpos[3]; // reference position
@@ -2136,7 +2127,6 @@ typedef struct mjsMesh_ { // mesh specification
} mjsMesh;
typedef struct mjsHField_ { // height field specification
mjsElement* element; // element type
mjString* name; // name
mjString* content_type; // content type of file
mjString* file; // file: (nrow, ncol, [elevation data])
double size[4]; // hfield size (ignore referencing geom size)
@@ -2147,7 +2137,6 @@ typedef struct mjsHField_ { // height field specification
} mjsHField;
typedef struct mjsSkin_ { // skin specification
mjsElement* element; // element type
mjString* name; // name
mjString* file; // skin file
mjString* material; // name of material used for rendering
float rgba[4]; // rgba when material is omitted
@@ -2171,7 +2160,6 @@ typedef struct mjsSkin_ { // skin specification
} mjsSkin;
typedef struct mjsTexture_ { // texture specification
mjsElement* element; // element type
mjString* name; // name
mjtTexture type; // texture type
mjtColorSpace colorspace; // colorspace
@@ -2207,7 +2195,6 @@ typedef struct mjsTexture_ { // texture specification
} mjsTexture;
typedef struct mjsMaterial_ { // material specification
mjsElement* element; // element type
mjString* name; // name
mjStringVec* textures; // names of textures (empty: none)
mjtByte texuniform; // make texture cube uniform
float texrepeat[2]; // texture repetition for 2D mapping
@@ -2222,7 +2209,6 @@ typedef struct mjsMaterial_ { // material specification
} mjsMaterial;
typedef struct mjsPair_ { // pair specification
mjsElement* element; // element type
mjString* name; // name
mjString* geomname1; // name of geom 1
mjString* geomname2; // name of geom 2
@@ -2238,14 +2224,12 @@ typedef struct mjsPair_ { // pair specification
} mjsPair;
typedef struct mjsExclude_ { // exclude specification
mjsElement* element; // element type
mjString* name; // name
mjString* bodyname1; // name of geom 1
mjString* bodyname2; // name of geom 2
mjString* info; // message appended to errors
} mjsExclude;
typedef struct mjsEquality_ { // equality specification
mjsElement* element; // element type
mjString* name; // name
mjtEq type; // constraint type
double data[mjNEQDATA]; // type-dependent data
mjtByte active; // is equality initially active
@@ -2258,7 +2242,6 @@ typedef struct mjsEquality_ { // equality specification
} mjsEquality;
typedef struct mjsTendon_ { // tendon specification
mjsElement* element; // element type
mjString* name; // name
// stiffness, damping, friction, armature
double stiffness; // stiffness coefficient
@@ -2294,7 +2277,6 @@ typedef struct mjsWrap_ { // wrapping object specification
} mjsWrap;
typedef struct mjsActuator_ { // actuator specification
mjsElement* element; // element type
mjString* name; // name
// gain, bias
mjtGain gaintype; // gain type
@@ -2334,7 +2316,6 @@ typedef struct mjsActuator_ { // actuator specification
} mjsActuator;
typedef struct mjsSensor_ { // sensor specification
mjsElement* element; // element type
mjString* name; // name
// sensor definition
mjtSensor type; // type of sensor
@@ -2359,20 +2340,17 @@ typedef struct mjsSensor_ { // sensor specification
} mjsSensor;
typedef struct mjsNumeric_ { // custom numeric field specification
mjsElement* element; // element type
mjString* name; // name
mjDoubleVec* data; // initialization data
int size; // array size, can be bigger than data size
mjString* info; // message appended to compiler errors
} mjsNumeric;
typedef struct mjsText_ { // custom text specification
mjsElement* element; // element type
mjString* name; // name
mjString* data; // text string
mjString* info; // message appended to compiler errors
} mjsText;
typedef struct mjsTuple_ { // tuple specification
mjsElement* element; // element type
mjString* name; // name
mjIntVec* objtype; // object types
mjStringVec* objname; // object names
mjDoubleVec* objprm; // object parameters
@@ -2380,7 +2358,6 @@ typedef struct mjsTuple_ { // tuple specification
} mjsTuple;
typedef struct mjsKey_ { // keyframe specification
mjsElement* element; // element type
mjString* name; // name
double time; // time
mjDoubleVec* qpos; // qpos
mjDoubleVec* qvel; // qvel
@@ -2392,7 +2369,6 @@ typedef struct mjsKey_ { // keyframe specification
} mjsKey;
typedef struct mjsDefault_ { // default specification
mjsElement* element; // element type
mjString* name; // class name
mjsJoint* joint; // joint defaults
mjsGeom* geom; // geom defaults
mjsSite* site; // site defaults
@@ -3480,6 +3456,7 @@ mjsElement* mjs_firstChild(mjsBody* body, mjtObj type, int recurse);
mjsElement* mjs_nextChild(mjsBody* body, mjsElement* child, int recurse);
mjsElement* mjs_firstElement(mjSpec* s, mjtObj type);
mjsElement* mjs_nextElement(mjSpec* s, mjsElement* element);
void mjs_setName(mjsElement* element, const char* name);
void mjs_setBuffer(mjByteVec* dest, const void* array, int size);
void mjs_setString(mjString* dest, const char* text);
void mjs_setStringVec(mjStringVec* dest, const char* text);
@@ -3491,6 +3468,7 @@ void mjs_setFloat(mjFloatVec* dest, const float* array, int size);
void mjs_appendFloatVec(mjFloatVecVec* dest, const float* array, int size);
void mjs_setDouble(mjDoubleVec* dest, const double* array, int size);
void mjs_setPluginAttributes(mjsPlugin* plugin, void* attributes);
mjString* mjs_getName(mjsElement* element);
const char* mjs_getString(const mjString* source);
const double* mjs_getDouble(const mjDoubleVec* source, int* size);
const void* mjs_getPluginAttributes(const mjsPlugin* plugin);
-24
View File
@@ -205,7 +205,6 @@ typedef struct mjsPlugin_ { // plugin specification
typedef struct mjsBody_ { // body specification
mjsElement* element; // element type
mjString* name; // name
mjString* childclass; // childclass name
// body frame
@@ -233,7 +232,6 @@ typedef struct mjsBody_ { // body specification
typedef struct mjsFrame_ { // frame specification
mjsElement* element; // element type
mjString* name; // name
mjString* childclass; // childclass name
double pos[3]; // position
double quat[4]; // orientation
@@ -244,7 +242,6 @@ typedef struct mjsFrame_ { // frame specification
typedef struct mjsJoint_ { // joint specification
mjsElement* element; // element type
mjString* name; // name
mjtJoint type; // joint type
// kinematics
@@ -284,7 +281,6 @@ typedef struct mjsJoint_ { // joint specification
typedef struct mjsGeom_ { // geom specification
mjsElement* element; // element type
mjString* name; // name
mjtGeom type; // geom type
// frame, size
@@ -332,7 +328,6 @@ typedef struct mjsGeom_ { // geom specification
typedef struct mjsSite_ { // site specification
mjsElement* element; // element type
mjString* name; // name
// frame, size
double pos[3]; // position
@@ -355,7 +350,6 @@ typedef struct mjsSite_ { // site specification
typedef struct mjsCamera_ { // camera specification
mjsElement* element; // element type
mjString* name; // name
// extrinsics
double pos[3]; // position
@@ -384,7 +378,6 @@ typedef struct mjsCamera_ { // camera specification
typedef struct mjsLight_ { // light specification
mjsElement* element; // element type
mjString* name; // name
// frame
double pos[3]; // position
@@ -414,7 +407,6 @@ typedef struct mjsLight_ { // light specification
typedef struct mjsFlex_ { // flex specification
mjsElement* element; // element type
mjString* name; // name
// contact properties
int contype; // contact type
@@ -463,7 +455,6 @@ typedef struct mjsFlex_ { // flex specification
typedef struct mjsMesh_ { // mesh specification
mjsElement* element; // element type
mjString* name; // name
mjString* content_type; // content type of file
mjString* file; // mesh file
double refpos[3]; // reference position
@@ -484,7 +475,6 @@ typedef struct mjsMesh_ { // mesh specification
typedef struct mjsHField_ { // height field specification
mjsElement* element; // element type
mjString* name; // name
mjString* content_type; // content type of file
mjString* file; // file: (nrow, ncol, [elevation data])
double size[4]; // hfield size (ignore referencing geom size)
@@ -498,7 +488,6 @@ typedef struct mjsHField_ { // height field specification
typedef struct mjsSkin_ { // skin specification
mjsElement* element; // element type
mjString* name; // name
mjString* file; // skin file
mjString* material; // name of material used for rendering
float rgba[4]; // rgba when material is omitted
@@ -524,7 +513,6 @@ typedef struct mjsSkin_ { // skin specification
typedef struct mjsTexture_ { // texture specification
mjsElement* element; // element type
mjString* name; // name
mjtTexture type; // texture type
mjtColorSpace colorspace; // colorspace
@@ -562,7 +550,6 @@ typedef struct mjsTexture_ { // texture specification
typedef struct mjsMaterial_ { // material specification
mjsElement* element; // element type
mjString* name; // name
mjStringVec* textures; // names of textures (empty: none)
mjtByte texuniform; // make texture cube uniform
float texrepeat[2]; // texture repetition for 2D mapping
@@ -579,7 +566,6 @@ typedef struct mjsMaterial_ { // material specification
typedef struct mjsPair_ { // pair specification
mjsElement* element; // element type
mjString* name; // name
mjString* geomname1; // name of geom 1
mjString* geomname2; // name of geom 2
@@ -597,7 +583,6 @@ typedef struct mjsPair_ { // pair specification
typedef struct mjsExclude_ { // exclude specification
mjsElement* element; // element type
mjString* name; // name
mjString* bodyname1; // name of geom 1
mjString* bodyname2; // name of geom 2
mjString* info; // message appended to errors
@@ -606,7 +591,6 @@ typedef struct mjsExclude_ { // exclude specification
typedef struct mjsEquality_ { // equality specification
mjsElement* element; // element type
mjString* name; // name
mjtEq type; // constraint type
double data[mjNEQDATA]; // type-dependent data
mjtByte active; // is equality initially active
@@ -621,7 +605,6 @@ typedef struct mjsEquality_ { // equality specification
typedef struct mjsTendon_ { // tendon specification
mjsElement* element; // element type
mjString* name; // name
// stiffness, damping, friction, armature
double stiffness; // stiffness coefficient
@@ -661,7 +644,6 @@ typedef struct mjsWrap_ { // wrapping object specification
typedef struct mjsActuator_ { // actuator specification
mjsElement* element; // element type
mjString* name; // name
// gain, bias
mjtGain gaintype; // gain type
@@ -703,7 +685,6 @@ typedef struct mjsActuator_ { // actuator specification
typedef struct mjsSensor_ { // sensor specification
mjsElement* element; // element type
mjString* name; // name
// sensor definition
mjtSensor type; // type of sensor
@@ -730,7 +711,6 @@ typedef struct mjsSensor_ { // sensor specification
typedef struct mjsNumeric_ { // custom numeric field specification
mjsElement* element; // element type
mjString* name; // name
mjDoubleVec* data; // initialization data
int size; // array size, can be bigger than data size
mjString* info; // message appended to compiler errors
@@ -739,7 +719,6 @@ typedef struct mjsNumeric_ { // custom numeric field specification
typedef struct mjsText_ { // custom text specification
mjsElement* element; // element type
mjString* name; // name
mjString* data; // text string
mjString* info; // message appended to compiler errors
} mjsText;
@@ -747,7 +726,6 @@ typedef struct mjsText_ { // custom text specification
typedef struct mjsTuple_ { // tuple specification
mjsElement* element; // element type
mjString* name; // name
mjIntVec* objtype; // object types
mjStringVec* objname; // object names
mjDoubleVec* objprm; // object parameters
@@ -757,7 +735,6 @@ typedef struct mjsTuple_ { // tuple specification
typedef struct mjsKey_ { // keyframe specification
mjsElement* element; // element type
mjString* name; // name
double time; // time
mjDoubleVec* qpos; // qpos
mjDoubleVec* qvel; // qvel
@@ -771,7 +748,6 @@ typedef struct mjsKey_ { // keyframe specification
typedef struct mjsDefault_ { // default specification
mjsElement* element; // element type
mjString* name; // class name
mjsJoint* joint; // joint defaults
mjsGeom* geom; // geom defaults
mjsSite* site; // site defaults
+6
View File
@@ -1600,6 +1600,9 @@ MJAPI mjsElement* mjs_nextElement(mjSpec* s, 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);
@@ -1636,6 +1639,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);
@@ -341,9 +341,14 @@ def generate_add() -> None:
else:
return '', '', ''
code_field = ''
set_types = []
names = []
if key == 'mjsPlugin':
code_field = ''
set_types = []
names = []
else:
code_field = 'set_name("name", out->element);'
set_types = ['name']
names = ['name']
for field in structs.STRUCTS[key].fields:
line, set_type, name = _field(field)
if line:
@@ -571,6 +576,21 @@ def generate_add() -> None:
}
};
"""
elif t == 'name':
code += """\n
auto set_name = [&kwargs](const char* str, raw::MjsElement* el) {
if (kwargs.contains(str)) {
try {
std::string name = kwargs[str].cast<std::string>();
mjs_setName(el, name.c_str());
} catch (const py::cast_error &e) {
throw pybind11::value_error(std::string(str) + " should be a string.");
}
}
};
"""
else:
raise NotImplementedError(f'Unsupported set type: {t} in {key}')
code += code_field
code += f"""\n
@@ -644,6 +664,25 @@ def generate_id() -> None:
print(code)
def generate_name() -> None:
"""Generate name functions."""
for key, _, _, _, _ in SPECS + [('mjsDefault', '', '', '', '')]:
if key == 'mjsPlugin':
continue
elem = key.removeprefix('mjs')
titlecase = 'Mjs' + elem
code = f"""\n
{key}.def_property("name",
[](raw::{titlecase}& self) -> std::string* {{
return mjs_getName(self.element);
}},
[](raw::{titlecase}& self, std::string& name) -> void {{
mjs_setName(self.element, name.c_str());
}}, py::return_value_policy::reference_internal);
"""
print(code)
def main(argv: Sequence[str]) -> None:
if len(argv) > 1:
raise app.UsageError('Too many command-line arguments.')
@@ -652,6 +691,7 @@ def main(argv: Sequence[str]) -> None:
generate_find()
generate_signature()
generate_id()
generate_name()
if __name__ == '__main__':
+36
View File
@@ -10191,6 +10191,26 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
),
doc="Return spec's next element; return NULL if element is last.",
)),
('mjs_setName',
FunctionDecl(
name='mjs_setName',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
name='element',
type=PointerType(
inner_type=ValueType(name='mjsElement'),
),
),
FunctionParameterDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='char', is_const=True),
),
),
),
doc="Set element's name.",
)),
('mjs_setBuffer',
FunctionDecl(
name='mjs_setBuffer',
@@ -10439,6 +10459,22 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
),
doc='Set plugin attributes.',
)),
('mjs_getName',
FunctionDecl(
name='mjs_getName',
return_type=PointerType(
inner_type=ValueType(name='mjString'),
),
parameters=(
FunctionParameterDecl(
name='element',
type=PointerType(
inner_type=ValueType(name='mjsElement'),
),
),
),
doc="Get element's name.",
)),
('mjs_getString',
FunctionDecl(
name='mjs_getString',
-168
View File
@@ -8222,13 +8222,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='childclass',
type=PointerType(
@@ -8347,13 +8340,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='childclass',
type=PointerType(
@@ -8403,13 +8389,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='type',
type=ValueType(name='mjtJoint'),
@@ -8575,13 +8554,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='type',
type=ValueType(name='mjtGeom'),
@@ -8783,13 +8755,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='pos',
type=ArrayType(
@@ -8880,13 +8845,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='pos',
type=ArrayType(
@@ -9019,13 +8977,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='pos',
type=ArrayType(
@@ -9154,13 +9105,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='contype',
type=ValueType(name='int'),
@@ -9380,13 +9324,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='content_type',
type=PointerType(
@@ -9501,13 +9438,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='content_type',
type=PointerType(
@@ -9568,13 +9498,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='file',
type=PointerType(
@@ -9684,13 +9607,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='type',
type=ValueType(name='mjtTexture'),
@@ -9830,13 +9746,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='textures',
type=PointerType(
@@ -9916,13 +9825,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='geomname1',
type=PointerType(
@@ -10005,13 +9907,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='bodyname1',
type=PointerType(
@@ -10047,13 +9942,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='type',
type=ValueType(name='mjtEq'),
@@ -10128,13 +10016,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='stiffness',
type=ValueType(name='double'),
@@ -10300,13 +10181,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='gaintype',
type=ValueType(name='mjtGain'),
@@ -10485,13 +10359,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='type',
type=ValueType(name='mjtSensor'),
@@ -10579,13 +10446,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='data',
type=PointerType(
@@ -10619,13 +10479,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='data',
type=PointerType(
@@ -10654,13 +10507,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='objtype',
type=PointerType(
@@ -10703,13 +10549,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='name',
),
StructFieldDecl(
name='time',
type=ValueType(name='double'),
@@ -10778,13 +10617,6 @@ STRUCTS: Mapping[str, StructDecl] = dict([
),
doc='element type',
),
StructFieldDecl(
name='name',
type=PointerType(
inner_type=ValueType(name='mjString'),
),
doc='class name',
),
StructFieldDecl(
name='joint',
type=PointerType(
+24 -12
View File
@@ -521,7 +521,8 @@ PYBIND11_MODULE(_specs, m) {
}
} else if (key == "name") {
try {
*out->name = kwargs["name"].cast<std::string>();
mjs_setName(out->element,
kwargs["name"].cast<std::string>().c_str());
} catch (const py::cast_error& e) {
throw pybind11::value_error("name is the wrong type.");
}
@@ -552,7 +553,8 @@ PYBIND11_MODULE(_specs, m) {
},
[](raw::MjsBody& self, raw::MjsDefault& default_) -> void {
mjs_setDefault(self.element, &default_);
});
},
py::return_value_policy::reference_internal);
mjsBody.def(
"find_all",
[](raw::MjsBody& self, mjtObj objtype) -> py::list {
@@ -819,7 +821,8 @@ PYBIND11_MODULE(_specs, m) {
},
[](raw::MjsGeom& self, raw::MjsDefault& default_) -> void {
mjs_setDefault(self.element, &default_);
});
},
py::return_value_policy::reference_internal);
mjsGeom.def_property_readonly(
"frame",
[](raw::MjsGeom& self) -> raw::MjsFrame* {
@@ -849,7 +852,8 @@ PYBIND11_MODULE(_specs, m) {
},
[](raw::MjsJoint& self, raw::MjsDefault& default_) -> void {
mjs_setDefault(self.element, &default_);
});
},
py::return_value_policy::reference_internal);
mjsJoint.def_property_readonly(
"frame",
[](raw::MjsJoint& self) -> raw::MjsFrame* {
@@ -879,7 +883,8 @@ PYBIND11_MODULE(_specs, m) {
},
[](raw::MjsSite& self, raw::MjsDefault& default_) -> void {
mjs_setDefault(self.element, &default_);
});
},
py::return_value_policy::reference_internal);
mjsSite.def(
"attach_body",
[](raw::MjsSite& self, raw::MjsBody& body,
@@ -926,7 +931,8 @@ PYBIND11_MODULE(_specs, m) {
},
[](raw::MjsCamera& self, raw::MjsDefault& default_) -> void {
mjs_setDefault(self.element, &default_);
});
},
py::return_value_policy::reference_internal);
mjsCamera.def_property_readonly(
"frame",
[](raw::MjsCamera& self) -> raw::MjsFrame* {
@@ -956,7 +962,8 @@ PYBIND11_MODULE(_specs, m) {
},
[](raw::MjsLight& self, raw::MjsDefault& default_) -> void {
mjs_setDefault(self.element, &default_);
});
},
py::return_value_policy::reference_internal);
mjsLight.def_property_readonly(
"frame",
[](raw::MjsLight& self) -> raw::MjsFrame* {
@@ -975,7 +982,8 @@ PYBIND11_MODULE(_specs, m) {
},
[](raw::MjsMaterial& self, raw::MjsDefault& default_) -> void {
mjs_setDefault(self.element, &default_);
});
},
py::return_value_policy::reference_internal);
// ============================= MJSMESH =====================================
mjSpec.def("delete", [](MjSpec& self, raw::MjsMesh& obj) {
@@ -988,7 +996,8 @@ PYBIND11_MODULE(_specs, m) {
},
[](raw::MjsMesh& self, raw::MjsDefault& default_) -> void {
mjs_setDefault(self.element, &default_);
});
},
py::return_value_policy::reference_internal);
// ============================= MJSPAIR =====================================
mjSpec.def("delete", [](MjSpec& self, raw::MjsPair& obj) {
@@ -1001,7 +1010,8 @@ PYBIND11_MODULE(_specs, m) {
},
[](raw::MjsPair& self, raw::MjsDefault& default_) -> void {
mjs_setDefault(self.element, &default_);
});
},
py::return_value_policy::reference_internal);
// ============================= MJSEQUAL ====================================
mjSpec.def("delete", [](MjSpec& self, raw::MjsEquality& obj) {
@@ -1014,7 +1024,8 @@ PYBIND11_MODULE(_specs, m) {
},
[](raw::MjsEquality& self, raw::MjsDefault& default_) -> void {
mjs_setDefault(self.element, &default_);
});
},
py::return_value_policy::reference_internal);
// ============================= MJSACTUATOR =================================
mjSpec.def("delete", [](MjSpec& self, raw::MjsActuator& obj) {
@@ -1027,7 +1038,8 @@ PYBIND11_MODULE(_specs, m) {
},
[](raw::MjsActuator& self, raw::MjsDefault& default_) -> void {
mjs_setDefault(self.element, &default_);
});
},
py::return_value_policy::reference_internal);
mjsActuator.def("set_to_motor", [](raw::MjsActuator* self) {
std::string err = mjs_setToMotor(self);
if (!err.empty()) {
@@ -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);
+20 -16
View File
@@ -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());
+23
View File
@@ -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();
+6
View File
@@ -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);
+7 -7
View File
@@ -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;
+9 -9
View File
@@ -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());
}
}
}
-3
View File
@@ -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_;
+1 -22
View File
@@ -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();
-23
View File
@@ -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();
+24 -24
View File
@@ -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
View File
@@ -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
+17 -17
View File
@@ -54,11 +54,11 @@ TEST_F(MujocoTest, GetSetData) {
double vec[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
const char* str = "sitename";
mjs_setString(site->name, str);
mjs_setName(site->element, str);
mjs_setDouble(site->userdata, vec, 10);
}
EXPECT_THAT(mjs_getString(site->name), HasSubstr("sitename"));
EXPECT_THAT(mjs_getName(site->element)->c_str(), HasSubstr("sitename"));
int nsize;
const double* vec = mjs_getDouble(site->userdata, &nsize);
@@ -199,7 +199,7 @@ TEST_F(PluginTest, DeletePlugin) {
mjsBody* body = mjs_addBody(mjs_findBody(spec, "world"), 0);
mjsJoint* joint = mjs_addJoint(body, 0);
mjsGeom* geom = mjs_addGeom(body, 0);
mjs_setString(joint->name, "j1");
mjs_setName(joint->element, "j1");
joint->type = mjJNT_SLIDE;
geom->size[0] = 1;
@@ -358,10 +358,10 @@ TEST_F(PluginTest, AttachExplicitPlugin) {
mjs_activatePlugin(child, "mujoco.sensor.touch_grid");
mjs_setString(plugin->plugin_name, "mujoco.sensor.touch_grid");
mjs_setString(sensor->plugin.plugin_name, "mujoco.sensor.touch_grid");
mjs_setString(body->name, "body");
mjs_setString(sensor->name, "touch2");
mjs_setName(body->element, "body");
mjs_setName(sensor->element, "touch2");
mjs_setString(sensor->objname, "touch2");
mjs_setString(site->name, "touch2");
mjs_setName(site->element, "touch2");
geom->size[0] = 0.1;
site->size[0] = 0.001;
sensor->type = mjSENS_PLUGIN;
@@ -470,8 +470,8 @@ TEST_F(MujocoTest, RecompileFails) {
mjsMaterial* mat1 = mjs_addMaterial(spec, 0);
mjsMaterial* mat2 = mjs_addMaterial(spec, 0);
mjs_setString(mat1->name, "yellow");
mjs_setString(mat2->name, "yellow");
mjs_setName(mat1->element, "yellow");
mjs_setName(mat2->element, "yellow");
EXPECT_EQ(mj_recompile(spec, 0, model, data), -1);
EXPECT_STREQ(mjs_getError(spec), "Error: repeated name 'yellow' in material");
@@ -752,7 +752,7 @@ TEST_F(PluginTest, TextureFromBuffer) {
mjSpec* spec = mj_makeSpec();
mjsTexture* t1 = mjs_addTexture(spec);
mjs_setString(t1->name, "tex1");
mjs_setName(t1->element, "tex1");
t1->type = mjTEXTURE_2D;
t1->width = 3;
t1->height = 2;
@@ -760,7 +760,7 @@ TEST_F(PluginTest, TextureFromBuffer) {
mjs_setBuffer(t1->data, (std::byte*)tex1, 18);
mjsTexture* t2 = mjs_addTexture(spec);
mjs_setString(t2->name, "tex2");
mjs_setName(t2->element, "tex2");
t2->type = mjTEXTURE_2D;
t2->width = 3;
t2->height = 2;
@@ -768,7 +768,7 @@ TEST_F(PluginTest, TextureFromBuffer) {
mjs_setBuffer(t2->data, (std::byte*)tex2, 18);
mjsMaterial* mat = mjs_addMaterial(spec, nullptr);
mjs_setString(mat->name, "mat");
mjs_setName(mat->element, "mat");
mjs_setInStringVec(mat->textures, mjTEXROLE_RGB, "tex1");
mjs_setInStringVec(mat->textures, mjTEXROLE_ORM, "tex2");
@@ -1706,7 +1706,7 @@ TEST_F(MujocoTest, AttachSpecToSite) {
EXPECT_THAT(world, NotNull());
mjsFrame* frame = mjs_addFrame(world, 0);
EXPECT_THAT(frame, NotNull());
mjs_setString(frame->name, "world");
mjs_setName(frame->element, "world");
mjs_setFrame(mjs_firstChild(world, mjOBJ_BODY, 0), frame);
mjs_setFrame(mjs_firstChild(world, mjOBJ_CAMERA, 0), frame);
@@ -1784,7 +1784,7 @@ TEST_F(MujocoTest, AttachSpecToBody) {
EXPECT_THAT(world, NotNull());
mjsFrame* frame = mjs_addFrame(world, 0);
EXPECT_THAT(frame, NotNull());
mjs_setString(frame->name, "world");
mjs_setName(frame->element, "world");
mjs_setFrame(mjs_firstChild(world, mjOBJ_BODY, 0), frame);
mjs_setFrame(mjs_firstChild(world, mjOBJ_CAMERA, 0), frame);
@@ -2152,14 +2152,14 @@ TEST_F(MujocoTest, InitTexture) {
EXPECT_THAT(spec, NotNull());
mjsTexture* texture = mjs_addTexture(spec);
mjs_setString(texture->name, "checker");
mjs_setName(texture->element, "checker");
texture->type = mjTEXTURE_CUBE;
texture->builtin = mjBUILTIN_CHECKER;
texture->width = 300;
texture->height = 300;
mjsMaterial* material = mjs_addMaterial(spec, 0);
mjs_setString(material->name, "floor");
mjs_setName(material->element, "floor");
mjs_setInStringVec(material->textures, mjTEXROLE_RGB, "checker");
mjsGeom* floor = mjs_addGeom(mjs_findBody(spec, "world"), 0);
@@ -2848,8 +2848,8 @@ TEST_F(MujocoTest, SetFrameReverseOrder) {
mjsBody* world = mjs_findBody(spec, "world");
mjsFrame* child = mjs_addFrame(world, nullptr);
mjsFrame* parent = mjs_addFrame(world, nullptr);
mjs_setString(child->name, "child");
mjs_setString(parent->name, "parent");
mjs_setName(child->element, "child");
mjs_setName(parent->element, "parent");
mjs_setFrame(child->element, parent);
mjSpec* copy = mj_copySpec(spec);
EXPECT_THAT(copy, NotNull());
+1 -1
View File
@@ -709,7 +709,7 @@ TEST_F(MujocoTest, Modeldir) {
mjsGeom* geom = mjs_addGeom(mjs_findBody(child, "world"), 0);
mjs_setString(child->meshdir, "meshdir");
mjs_setString(mesh->file, "cube.obj");
mjs_setString(mesh->name, "cube");
mjs_setName(mesh->element, "cube");
mjs_setString(geom->meshname, "cube");
mjs_setFrame(geom->element, frame);
geom->type = mjGEOM_MESH;
+3 -3
View File
@@ -308,9 +308,9 @@ TEST_F(MujocoTest, RepeatedMeshName) {
EXPECT_THAT(mesh1, NotNull());
EXPECT_THAT(mesh2, NotNull());
EXPECT_THAT(mesh3, IsNull());
EXPECT_STREQ(mjs_getString(mesh->name), "mesh");
EXPECT_STREQ(mjs_getString(mesh1->name), "mesh1");
EXPECT_STREQ(mjs_getString(mesh2->name), "mesh2");
EXPECT_STREQ(mjs_getName(mesh->element)->c_str(), "mesh");
EXPECT_STREQ(mjs_getName(mesh1->element)->c_str(), "mesh1");
EXPECT_STREQ(mjs_getName(mesh2->element)->c_str(), "mesh2");
mj_deleteSpec(spec);
}