Make model editing API public, fixes #364

Still missing:

- Detailed documentation.
- Python bindings.

PiperOrigin-RevId: 641445626
Change-Id: I20e67b707cf1bebae7e0cc94d17f7b76a89171f0
This commit is contained in:
Alessio Quaglino
2024-06-07 22:27:10 -07:00
committed by Copybara-Service
parent 4c3d9461ae
commit 7a06bcfdaf
46 changed files with 8508 additions and 980 deletions
+14 -14
View File
@@ -52,7 +52,7 @@ static T& operator+(T& base, std::string_view suffix) {
// create model
mjSpec* mjs_createSpec() {
mjSpec* mj_makeSpec() {
mjCModel* modelC = new mjCModel;
return &modelC->spec;
}
@@ -60,7 +60,7 @@ mjSpec* mjs_createSpec() {
// copy model
mjSpec* mjs_copySpec(const mjSpec* s) {
mjSpec* mj_copySpec(const mjSpec* s) {
mjCModel* modelC = new mjCModel(*static_cast<mjCModel*>(s->element));
return &modelC->spec;
}
@@ -68,7 +68,7 @@ mjSpec* mjs_copySpec(const mjSpec* s) {
// copy back model
void mjs_copyBack(mjSpec* s, const mjModel* m) {
void mj_copyBack(mjSpec* s, const mjModel* m) {
mjCModel* modelC = static_cast<mjCModel*>(s->element);
modelC->CopyBack(m);
}
@@ -76,7 +76,7 @@ void mjs_copyBack(mjSpec* s, const mjModel* m) {
// compile model
mjModel* mjs_compile(mjSpec* s, const mjVFS* vfs) {
mjModel* mj_compile(mjSpec* s, const mjVFS* vfs) {
mjCModel* modelC = static_cast<mjCModel*>(s->element);
return modelC->Compile(vfs);
}
@@ -84,7 +84,7 @@ mjModel* mjs_compile(mjSpec* s, const mjVFS* vfs) {
// recompile spec into existing model and data while preserving the state
void mjs_recompile(mjSpec* s, const mjVFS* vfs, mjModel* m, mjData* d) {
void mj_recompile(mjSpec* s, const mjVFS* vfs, mjModel* m, mjData* d) {
mjCModel* modelC = static_cast<mjCModel*>(s->element);
modelC->SaveState(d);
modelC->Compile(vfs, &m);
@@ -143,7 +143,7 @@ int mjs_isWarning(mjSpec* s) {
// delete model
void mjs_deleteSpec(mjSpec* s) {
void mj_deleteSpec(mjSpec* s) {
mjCModel* model = static_cast<mjCModel*>(s->element);
delete model;
}
@@ -151,7 +151,7 @@ void mjs_deleteSpec(mjSpec* s) {
// delete object, it will call the appropriate destructor since ~mjCBase is virtual
void mjs_delete(mjElement* element) {
void mjs_delete(mjsElement* element) {
mjCBase* object = static_cast<mjCBase*>(element);
delete object;
}
@@ -430,7 +430,7 @@ mjsKey* mjs_addKey(mjSpec* s) {
mjsPlugin* mjs_addPlugin(mjSpec* s) {
mjCModel* modelC = static_cast<mjCModel*>(s->element);
mjCPlugin* plugin = modelC->AddPlugin();
plugin->spec.instance = static_cast<mjElement*>(plugin);
plugin->spec.instance = static_cast<mjsElement*>(plugin);
return &plugin->spec;
}
@@ -458,7 +458,7 @@ mjSpec* mjs_getSpec(mjsBody* body) {
// get default
mjsDefault* mjs_getDefault(mjElement* element) {
mjsDefault* mjs_getDefault(mjsElement* element) {
return &(static_cast<mjCBase*>(element)->def->spec);
}
@@ -530,7 +530,7 @@ mjsFrame* mjs_findFrame(mjSpec* s, const char* name) {
// set frame
void mjs_setFrame(mjElement* dest, mjsFrame* frame) {
void mjs_setFrame(mjsElement* dest, mjsFrame* frame) {
if (!frame) {
return;
}
@@ -550,14 +550,14 @@ const char* mjs_resolveOrientation(double quat[4], mjtByte degree, const char* s
// get id
int mjs_getId(mjElement* element) {
int mjs_getId(mjsElement* element) {
return static_cast<mjCBase*>(element)->id;
}
// set default
void mjs_setDefault(mjElement* element, mjsDefault* defspec) {
void mjs_setDefault(mjsElement* element, mjsDefault* defspec) {
mjCBase* baseC = static_cast<mjCBase*>(element);
baseC->def = static_cast<mjCDef*>(defspec->element);
}
@@ -565,7 +565,7 @@ void mjs_setDefault(mjElement* element, mjsDefault* defspec) {
// return first child of selected type
mjElement* mjs_firstChild(mjsBody* body, mjtObj type) {
mjsElement* mjs_firstChild(mjsBody* body, mjtObj type) {
mjCBody* bodyC = static_cast<mjCBody*>(body->element);
return bodyC->NextChild(NULL, type);
}
@@ -573,7 +573,7 @@ mjElement* mjs_firstChild(mjsBody* body, mjtObj type) {
// return body's next child; return NULL if child is last
mjElement* mjs_nextChild(mjsBody* body, mjElement* child) {
mjsElement* mjs_nextChild(mjsBody* body, mjsElement* child) {
mjCBody* bodyC = static_cast<mjCBody*>(body->element);
return bodyC->NextChild(child);
}
+14 -743
View File
@@ -20,6 +20,7 @@
#include <mujoco/mjdata.h>
#include <mujoco/mjexport.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mjspec.h>
#include <mujoco/mjtnum.h>
@@ -33,749 +34,19 @@ extern "C" {
#define mjNAN NAN // used to mark undefined fields
//---------------------------------- C/C++ handles to strings and arrays ---------------------------
#ifdef __cplusplus
// C++, defined to be compatible with corresponding std types
using mjString = std::string;
using mjStringVec = std::vector<std::string>;
using mjIntVec = std::vector<int>;
using mjIntVecVec = std::vector<std::vector<int>>;
using mjFloatVec = std::vector<float>;
using mjFloatVecVec = std::vector<std::vector<float>>;
using mjDoubleVec = std::vector<double>;
#else
// C, opaque pointers
typedef struct mjString_ mjString;
typedef struct mjStringVec_ mjStringVec;
typedef struct mjIntVec_ mjIntVec;
typedef struct mjIntVecVec_ mjIntVecVec;
typedef struct mjFloatVec_ mjFloatVec;
typedef struct mjFloatVecVec_ mjFloatVecVec;
typedef struct mjDoubleVec_ mjDoubleVec;
#endif
//---------------------------------- enum types (mjt) ----------------------------------------------
typedef enum mjtGeomInertia_ { // type of inertia inference
mjINERTIA_VOLUME, // mass distributed in the volume
mjINERTIA_SHELL, // mass distributed on the surface
} mjtGeomInertia;
typedef enum mjtBuiltin_ { // type of built-in procedural texture
mjBUILTIN_NONE = 0, // no built-in texture
mjBUILTIN_GRADIENT, // gradient: rgb1->rgb2
mjBUILTIN_CHECKER, // checker pattern: rgb1, rgb2
mjBUILTIN_FLAT // 2d: rgb1; cube: rgb1-up, rgb2-side, rgb3-down
} mjtBuiltin;
typedef enum mjtMark_ { // mark type for procedural textures
mjMARK_NONE = 0, // no mark
mjMARK_EDGE, // edges
mjMARK_CROSS, // cross
mjMARK_RANDOM // random dots
} mjtMark;
typedef enum mjtLimited_ { // type of limit specification
mjLIMITED_FALSE = 0, // not limited
mjLIMITED_TRUE, // limited
mjLIMITED_AUTO, // limited inferred from presence of range
} mjtLimited;
typedef enum mjtInertiaFromGeom_ { // whether to infer body inertias from child geoms
mjINERTIAFROMGEOM_FALSE = 0, // do not use; inertial element required
mjINERTIAFROMGEOM_TRUE, // always use; overwrite inertial element
mjINERTIAFROMGEOM_AUTO // use only if inertial element is missing
} mjtInertiaFromGeom;
typedef enum mjtOrientation_ { // type of orientation specifier
mjORIENTATION_QUAT = 0, // quaternion
mjORIENTATION_AXISANGLE, // axis and angle
mjORIENTATION_XYAXES, // x and y axes
mjORIENTATION_ZAXIS, // z axis (minimal rotation)
mjORIENTATION_EULER, // Euler angles
} mjtOrientation;
//---------------------------------- attribute structs (mjs) ---------------------------------------
typedef struct mjElement_ { // element type, do not modify
mjtObj elemtype; // element type
} mjElement;
typedef struct mjSpec_ { // model specification
mjElement* element; // element type
mjString* modelname; // model name
// compiler settings
mjtByte autolimits; // infer "limited" attribute based on range
double boundmass; // enforce minimum body mass
double boundinertia; // enforce minimum body diagonal inertia
double settotalmass; // rescale masses and inertias; <=0: ignore
mjtByte balanceinertia; // automatically impose A + B >= C rule
mjtByte strippath; // automatically strip paths from mesh files
mjtByte fitaabb; // meshfit to aabb instead of inertia box
mjtByte degree; // angles in radians or degrees
char euler[3]; // sequence for euler rotations
mjString* meshdir; // mesh and hfield directory
mjString* texturedir; // texture directory
mjtByte discardvisual; // discard visual geoms in parser
mjtByte convexhull; // compute mesh convex hulls
mjtByte usethread; // use multiple threads to speed up compiler
mjtByte fusestatic; // fuse static bodies with parent
int inertiafromgeom; // use geom inertias (mjtInertiaFromGeom)
int inertiagrouprange[2]; // range of geom groups used to compute inertia
mjtByte exactmeshinertia; // if false, use old formula
mjLROpt LRopt; // options for lengthrange computation
// engine data
mjOption option; // physics options
mjVisual visual; // visual options
mjStatistic stat; // statistics override (if defined)
// sizes
size_t memory; // number of bytes in arena+stack memory
int nemax; // max number of equality constraints
int nuserdata; // number of mjtNums in userdata
int nuser_body; // number of mjtNums in body_user
int nuser_jnt; // number of mjtNums in jnt_user
int nuser_geom; // number of mjtNums in geom_user
int nuser_site; // number of mjtNums in site_user
int nuser_cam; // number of mjtNums in cam_user
int nuser_tendon; // number of mjtNums in tendon_user
int nuser_actuator; // number of mjtNums in actuator_user
int nuser_sensor; // number of mjtNums in sensor_user
int nkey; // number of keyframes
int njmax; // (deprecated) max number of constraints
int nconmax; // (deprecated) max number of detected contacts
size_t nstack; // (deprecated) number of mjtNums in mjData stack
// global data
mjString* comment; // comment at top of XML
mjString* modelfiledir; // path to model file
// other
mjtByte hasImplicitPluginElem; // already encountered an implicit plugin sensor/actuator
} mjSpec;
typedef struct mjsOrientation_ { // alternative orientation specifiers
mjtOrientation type; // active orientation specifier
double axisangle[4]; // axis and angle
double xyaxes[6]; // x and y axes
double zaxis[3]; // z axis (minimal rotation)
double euler[3]; // Euler angles
} mjsOrientation;
typedef struct mjsPlugin_ { // plugin specification
mjElement* instance; // element type
mjString* name; // name
mjString* instance_name; // instance name
int plugin_slot; // global registered slot number of the plugin
mjtByte active; // is the plugin active
mjString* info; // message appended to compiler errors
} mjsPlugin;
typedef struct mjsBody_ { // body specification
mjElement* element; // element type
mjString* name; // name
mjString* childclass; // childclass name
// body frame
double pos[3]; // frame position
double quat[4]; // frame orientation
mjsOrientation alt; // frame alternative orientation
// inertial frame
double mass; // mass
double ipos[3]; // inertial frame position
double iquat[4]; // inertial frame orientation
double inertia[3]; // diagonal inertia (in i-frame)
mjsOrientation ialt; // inertial frame alternative orientation
double fullinertia[6]; // non-axis-aligned inertia matrix
// other
mjtByte mocap; // is this a mocap body
double gravcomp; // gravity compensation
mjDoubleVec* userdata; // user data
mjtByte explicitinertial; // whether to save the body with explicit inertial clause
mjsPlugin plugin; // passive force plugin
mjString* info; // message appended to compiler errors
} mjsBody;
typedef struct mjsFrame_ { // frame specification
mjElement* element; // element type
mjString* name; // name
mjString* childclass; // childclass name
double pos[3]; // position
double quat[4]; // orientation
mjsOrientation alt; // alternative orientation
mjString* info; // message appended to compiler errors
} mjsFrame;
typedef struct mjsJoint_ { // joint specification
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
mjtJoint type; // joint type
// kinematics
double pos[3]; // anchor position
double axis[3]; // joint axis
double ref; // value at reference configuration: qpos0
// stiffness
double stiffness; // stiffness coefficient
double springref; // spring reference value: qpos_spring
double springdamper[2]; // timeconst, dampratio
// limits
int limited; // does joint have limits (mjtLimited)
double range[2]; // joint limits
double margin; // margin value for joint limit detection
mjtNum solref_limit[mjNREF]; // solver reference: joint limits
mjtNum solimp_limit[mjNIMP]; // solver impedance: joint limits
int actfrclimited; // are actuator forces on joint limited (mjtLimited)
double actfrcrange[2]; // actuator force limits
// dof properties
double armature; // armature inertia (mass for slider)
double damping; // damping coefficient
double frictionloss; // friction loss
mjtNum solref_friction[mjNREF]; // solver reference: dof friction
mjtNum solimp_friction[mjNIMP]; // solver impedance: dof friction
// other
int group; // group
mjtByte actgravcomp; // is gravcomp force applied via actuators
mjDoubleVec* userdata; // user data
mjString* info; // message appended to compiler errors
} mjsJoint;
typedef struct mjsGeom_ { // geom specification
mjElement* element; // element type
mjString* name; // name
mjString* classname; // classname
mjtGeom type; // geom type
// frame, size
double pos[3]; // position
double quat[4]; // orientation
mjsOrientation alt; // alternative orientation
double fromto[6]; // alternative for capsule, cylinder, box, ellipsoid
double size[3]; // type-specific size
// contact related
int contype; // contact type
int conaffinity; // contact affinity
int condim; // contact dimensionality
int priority; // contact priority
double friction[3]; // one-sided friction coefficients: slide, roll, spin
double solmix; // solver mixing for contact pairs
mjtNum solref[mjNREF]; // solver reference
mjtNum solimp[mjNIMP]; // solver impedance
double margin; // margin for contact detection
double gap; // include in solver if dist < margin-gap
// inertia inference
double mass; // used to compute density
double density; // used to compute mass and inertia from volume or surface
mjtGeomInertia typeinertia; // selects between surface and volume inertia
// fluid forces
mjtNum fluid_ellipsoid; // whether ellipsoid-fluid model is active
mjtNum fluid_coefs[5]; // ellipsoid-fluid interaction coefs
// visual
mjString* material; // name of material
float rgba[4]; // rgba when material is omitted
int group; // group
// other
mjString* hfieldname; // heightfield attached to geom
mjString* meshname; // mesh attached to geom
double fitscale; // scale mesh uniformly
mjDoubleVec* userdata; // user data
mjsPlugin plugin; // sdf plugin
mjString* info; // message appended to compiler errors
} mjsGeom;
typedef struct mjsSite_ { // site specification
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
// frame, size
double pos[3]; // position
double quat[4]; // orientation
mjsOrientation alt; // alternative orientation
double fromto[6]; // alternative for capsule, cylinder, box, ellipsoid
double size[3]; // geom size
// visual
mjtGeom type; // geom type
mjString* material; // name of material
int group; // group
float rgba[4]; // rgba when material is omitted
// other
mjDoubleVec* userdata; // user data
mjString* info; // message appended to compiler errors
} mjsSite;
typedef struct mjsCamera_ { // camera specification
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
// extrinsics
double pos[3]; // position
double quat[4]; // orientation
mjsOrientation alt; // alternative orientation
mjtCamLight mode; // tracking mode
mjString* targetbody; // target body for tracking/targeting
// intrinsics
double fovy; // y-field of view
double ipd; // inter-pupilary distance
float intrinsic[4]; // camera intrinsics (length)
float sensor_size[2]; // sensor size (length)
float resolution[2]; // resolution (pixel)
float focal_length[2]; // focal length (length)
float focal_pixel[2]; // focal length (pixel)
float principal_length[2]; // principal point (length)
float principal_pixel[2]; // principal point (pixel)
// other
mjDoubleVec* userdata; // user data
mjString* info; // message appended to compiler errors
} mjsCamera;
typedef struct mjsLight_ { // light specification
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
// frame
double pos[3]; // position
double dir[3]; // direction
mjtCamLight mode; // tracking mode
mjString* targetbody; // target body for targeting
// intrinsics
mjtByte active; // is light active
mjtByte directional; // is light directional or spot
mjtByte castshadow; // does light cast shadows
double bulbradius; // bulb radius, for soft shadows
float attenuation[3]; // OpenGL attenuation (quadratic model)
float cutoff; // OpenGL cutoff
float exponent; // OpenGL exponent
float ambient[3]; // ambient color
float diffuse[3]; // diffuse color
float specular[3]; // specular color
// other
mjString* info; // message appended to compiler errorsx
} mjsLight;
typedef struct mjsFlex_ {
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
// contact properties
int contype; // contact type
int conaffinity; // contact affinity
int condim; // contact dimensionality
int priority; // contact priority
double friction[3]; // one-sided friction coefficients: slide, roll, spin
double solmix; // solver mixing for contact pairs
mjtNum solref[mjNREF]; // solver reference
mjtNum solimp[mjNIMP]; // solver impedance
double margin; // margin for contact detection
double gap; // include in solver if dist<margin-gap
// other properties
int dim; // element dimensionality
double radius; // radius around primitive element
mjtByte internal; // enable internal collisions
mjtByte flatskin; // render flex skin with flat shading
int selfcollide; // mode for flex self colllision
int activelayers; // number of active element layers in 3D
int group; // group for visualizatioh
double edgestiffness; // edge stiffness
double edgedamping; // edge damping
float rgba[4]; // rgba when material is omitted
mjString* material; // name of material used for rendering
// mesh properties
mjStringVec* vertbody; // vertex body names
mjDoubleVec* vert; // vertex positions
mjIntVec* elem; // element vertex ids
mjFloatVec* texcoord; // vertex texture coordinates
// other
mjString* info; // message appended to compiler errors
} mjsFlex;
typedef struct mjsMesh_ { // mesh specification
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
mjString* content_type; // content type of file
mjString* file; // mesh file
double refpos[3]; // reference position
double refquat[4]; // reference orientation
double scale[3]; // rescale mesh
mjtByte smoothnormal; // do not exclude large-angle faces from normals
int maxhullvert; // maximum vertex count for the convex hull
mjFloatVec* uservert; // user vertex data
mjFloatVec* usernormal; // user normal data
mjFloatVec* usertexcoord; // user texcoord data
mjIntVec* userface; // user vertex indices
mjIntVec* userfacenormal; // user normal indices
mjIntVec* userfacetexcoord; // user texcoord indices
mjsPlugin plugin; // sdf plugin
mjString* info; // message appended to compiler errors
} mjsMesh;
typedef struct mjsHField_ { // height field specification
mjElement* 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)
int nrow; // number of rows
int ncol; // number of columns
mjFloatVec* userdata; // user-provided elevation data
mjString* info; // message appended to compiler errors
} mjsHField;
typedef struct mjsSkin_ { // skin specification
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
mjString* file; // skin file
mjString* material; // name of material used for rendering
float rgba[4]; // rgba when material is omitted
float inflate; // inflate in normal direction
int group; // group for visualization
// mesh
mjFloatVec* vert; // vertex positions
mjFloatVec* texcoord; // texture coordinates
mjIntVec* face; // faces
// skin
mjStringVec* bodyname; // body names
mjFloatVec* bindpos; // bind pos
mjFloatVec* bindquat; // bind quat
mjIntVecVec* vertid; // vertex ids
mjFloatVecVec* vertweight; // vertex weights
// other
mjString* info; // message appended to compiler errors
} mjsSkin;
typedef struct mjsTexture_ { // texture specification
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
mjtTexture type; // texture type
// method 1: builtin
int builtin; // builtin type (mjtBuiltin)
int mark; // mark type (mjtMark)
double rgb1[3]; // first color for builtin
double rgb2[3]; // second color for builtin
double markrgb[3]; // mark color
double random; // probability of random dots
int height; // height in pixels (square for cube and skybox)
int width; // width in pixels
// method 2: single file
mjString* content_type; // content type of file
mjString* file; // png file to load; use for all sides of cube
int gridsize[2]; // size of grid for composite file; (1,1)-repeat
char gridlayout[13]; // row-major: L,R,F,B,U,D for faces; . for unused
// method 3: separate files
mjStringVec* cubefiles; // different file for each side of the cube
// flip options
mjtByte hflip; // horizontal flip
mjtByte vflip; // vertical flip
// other
mjString* info; // message appended to compiler errors
} mjsTexture;
typedef struct mjsMaterial_ { // material specification
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
mjString* texture; // name of texture (empty: none)
mjtByte texuniform; // make texture cube uniform
float texrepeat[2]; // texture repetition for 2D mapping
float emission; // emission
float specular; // specular
float shininess; // shininess
float reflectance; // reflectance
float metallic; // metallic
float roughness; // roughness
float rgba[4]; // rgba
mjString* info; // message appended to compiler errors
} mjsMaterial;
typedef struct mjsPair_ {
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
mjString* geomname1; // name of geom 1
mjString* geomname2; // name of geom 2
// optional parameters: computed from geoms if not set by user
int condim; // contact dimensionality
mjtNum solref[mjNREF]; // solver reference, normal direction
mjtNum solreffriction[mjNREF]; // solver reference, frictional directions
mjtNum solimp[mjNIMP]; // solver impedance
double margin; // margin for contact detection
double gap; // include in solver if dist<margin-gap
double friction[5]; // full contact friction
mjString* info; // message appended to errors
} mjsPair;
typedef struct mjsExclude_ {
mjElement* 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
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
mjtEq type; // constraint type
double data[mjNEQDATA]; // type-dependent data
mjtByte active; // is equality initially active
mjString* name1; // name of object 1
mjString* name2; // name of object 2
mjtNum solref[mjNREF]; // solver reference
mjtNum solimp[mjNIMP]; // solver impedance
mjString* info; // message appended to errors
} mjsEquality;
typedef struct mjsTendon_ { // tendon specification
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
// stiffness, damping, friction
double stiffness; // stiffness coefficient
double springlength[2]; // spring resting length; {-1, -1}: use qpos_spring
double damping; // damping coefficient
double frictionloss; // friction loss
mjtNum solref_friction[mjNREF]; // solver reference: tendon friction
mjtNum solimp_friction[mjNIMP]; // solver impedance: tendon friction
// length range
int limited; // does tendon have limits (mjtLimited)
double range[2]; // length limits
double margin; // margin value for tendon limit detection
mjtNum solref_limit[mjNREF]; // solver reference: tendon limits
mjtNum solimp_limit[mjNIMP]; // solver impedance: tendon limits
// visual
mjString* material; // name of material for rendering
double width; // width for rendering
float rgba[4]; // rgba when material is omitted
int group; // group
// other
mjDoubleVec* userdata; // user data
mjString* info; // message appended to errors
} mjsTendon;
typedef struct mjsWrap_ { // wrapping object specification
mjElement* element; // element type
mjString* info; // message appended to errors
} mjsWrap;
typedef struct mjsActuator_ { // actuator specification
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
// gain, bias
mjtGain gaintype; // gain type
double gainprm[mjNGAIN]; // gain parameters
mjtBias biastype; // bias type
double biasprm[mjNGAIN]; // bias parameters
// activation state
mjtDyn dyntype; // dynamics type
double dynprm[mjNDYN]; // dynamics parameters
int actdim; // number of activation variables
int plugin_actdim; // actuator state size for plugins
mjtByte actearly; // apply next activations to qfrc
// transmission
mjtTrn trntype; // transmission type
double gear[6]; // length and transmitted force scaling
mjString* target; // name of transmission target
mjString* refsite; // reference site, for site transmission
mjString* slidersite; // site defining cylinder, for slider-crank
double cranklength; // crank length, for slider-crank
double lengthrange[2]; // transmission length range
double inheritrange; // automatic range setting for position and intvelocity
// input/output clamping
int ctrllimited; // are control limits defined (mjtLimited)
double ctrlrange[2]; // control range
int forcelimited; // are force limits defined (mjtLimited)
double forcerange[2]; // force range
int actlimited; // are activation limits defined (mjtLimited)
double actrange[2]; // activation range
// other
int group; // group
mjDoubleVec* userdata; // user data
mjsPlugin plugin; // actuator plugin
mjString* info; // message appended to compiler errors
} mjsActuator;
typedef struct mjsSensor_ { // sensor specification
mjElement* element; // element type
mjString* name; // name
mjString* classname; // class name
// sensor defintion
mjtSensor type; // type of sensor
mjtObj objtype; // type of sensorized object
mjString* objname; // name of sensorized object
mjtObj reftype; // type of referenced object
mjString* refname; // name of referenced object
// user-defined sensors
mjtDataType datatype; // data type for sensor measurement
mjtStage needstage; // compute stage needed to simulate sensor
int dim; // number of scalar outputs
// output post-processing
double cutoff; // cutoff for real and positive datatypes
double noise; // noise stdev
// other
mjDoubleVec* userdata; // user data
mjsPlugin plugin; // sensor plugin
mjString* info; // message appended to compiler errors
} mjsSensor;
typedef struct mjsNumeric_ { // custom numeric field specification
mjElement* 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
mjElement* element; // element type
mjString* name; // name
mjString* data; // text string
mjString* info; // message appended to compiler errors
} mjsText;
typedef struct mjsTuple_ { // tuple specification
mjElement* element; // element type
mjString* name; // name
mjIntVec* objtype; // object types
mjStringVec* objname; // object names
mjDoubleVec* objprm; // object parameters
mjString* info; // message appended to compiler errors
} mjsTuple;
typedef struct mjsKey_ { // keyframe specification
mjElement* element; // element type
mjString* name; // name
double time; // time
mjDoubleVec* qpos; // qpos
mjDoubleVec* qvel; // qvel
mjDoubleVec* act; // act
mjDoubleVec* mpos; // mocap pos
mjDoubleVec* mquat; // mocap quat
mjDoubleVec* ctrl; // ctrl
mjString* info; // message appended to compiler errors
} mjsKey;
typedef struct mjsDefault_ { // default specification
mjElement* element; // element type
mjString* name; // class name
mjsJoint* joint; // joint defaults
mjsGeom* geom; // geom defaults
mjsSite* site; // site defaults
mjsCamera* camera; // camera defaults
mjsLight* light; // light defaults
mjsFlex* flex; // flex defaults
mjsMesh* mesh; // mesh defaults
mjsMaterial* material; // material defaults
mjsPair* pair; // pair defaults
mjsEquality* equality; // equality defaults
mjsTendon* tendon; // tendon defaults
mjsActuator* actuator; // actuator defaults
} mjsDefault;
//---------------------------------- Top-level spec manipulation -----------------------------------
// Create spec.
MJAPI mjSpec* mjs_createSpec(void);
MJAPI mjSpec* mj_makeSpec(void);
// Compile spec to model.
MJAPI mjModel* mjs_compile(mjSpec* s, const mjVFS* vfs);
MJAPI mjModel* mj_compile(mjSpec* s, const mjVFS* vfs);
// Recompile spec to model preserving the current state.
MJAPI void mjs_recompile(mjSpec* s, const mjVFS* vfs, mjModel* m, mjData* d);
MJAPI void mj_recompile(mjSpec* s, const mjVFS* vfs, mjModel* m, mjData* d);
// Copy spec.
MJAPI mjSpec* mjs_copySpec(const mjSpec* s);
MJAPI mjSpec* mj_copySpec(const mjSpec* s);
// Get compiler error message from spec.
MJAPI const char* mjs_getError(mjSpec* s);
@@ -784,10 +55,10 @@ MJAPI const char* mjs_getError(mjSpec* s);
MJAPI int mjs_isWarning(mjSpec* s);
// Copy model fields back into spec.
MJAPI void mjs_copyBack(mjSpec* s, const mjModel* m);
MJAPI void mj_copyBack(mjSpec* s, const mjModel* m);
// Delete spec.
MJAPI void mjs_deleteSpec(mjSpec* s);
MJAPI void mj_deleteSpec(mjSpec* s);
//---------------------------------- Attachment ----------------------------------------------------
@@ -831,7 +102,7 @@ MJAPI mjsLight* mjs_addLight(mjsBody* body, mjsDefault* def);
MJAPI mjsFrame* mjs_addFrame(mjsBody* body, mjsFrame* parentframe);
// Delete object corresponding to the given element.
MJAPI void mjs_delete(mjElement* element);
MJAPI void mjs_delete(mjsElement* element);
//---------------------------------- Add non-tree elements -----------------------------------------
@@ -924,7 +195,7 @@ MJAPI mjsMesh* mjs_findMesh(mjSpec* s, const char* name);
MJAPI mjsFrame* mjs_findFrame(mjSpec* s, const char* name);
// Get default corresponding to an element.
MJAPI mjsDefault* mjs_getDefault(mjElement* element);
MJAPI mjsDefault* mjs_getDefault(mjsElement* element);
// Find default in model by class name.
MJAPI mjsDefault* mjs_findDefault(mjSpec* s, const char* classname);
@@ -933,16 +204,16 @@ MJAPI mjsDefault* mjs_findDefault(mjSpec* s, const char* classname);
MJAPI mjsDefault* mjs_getSpecDefault(mjSpec* s);
// Get element id.
MJAPI int mjs_getId(mjElement* element);
MJAPI int mjs_getId(mjsElement* element);
//---------------------------------- Tree traversal ------------------------------------------------
// Return body's first child of given type.
MJAPI mjElement* mjs_firstChild(mjsBody* body, mjtObj type);
MJAPI mjsElement* mjs_firstChild(mjsBody* body, mjtObj type);
// Return body's next child of the same type; return NULL if child is last.
MJAPI mjElement* mjs_nextChild(mjsBody* body, mjElement* child);
MJAPI mjsElement* mjs_nextChild(mjsBody* body, mjsElement* child);
//---------------------------------- Attribute setters ---------------------------------------------
@@ -993,10 +264,10 @@ MJAPI const double* mjs_getDouble(const mjDoubleVec* source, int* size);
MJAPI void mjs_setActivePlugins(mjSpec* s, void* activeplugins);
// Set element's default.
MJAPI void mjs_setDefault(mjElement* element, mjsDefault* def);
MJAPI void mjs_setDefault(mjsElement* element, mjsDefault* def);
// Set element's enlcosing frame.
MJAPI void mjs_setFrame(mjElement* dest, mjsFrame* frame);
MJAPI void mjs_setFrame(mjsElement* dest, mjsFrame* frame);
// Resolve alternative orientations to quat, return error if any.
MJAPI const char* mjs_resolveOrientation(double quat[4], mjtByte degree, const char* sequence,
+1 -1
View File
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#include "user/user_composite.h"
#include <algorithm>
+1 -1
View File
@@ -20,7 +20,7 @@
#include <vector>
#include <mujoco/mjmodel.h>
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#include "user/user_model.h"
#include "user/user_objects.h"
+3 -3
View File
@@ -34,7 +34,7 @@
#include "engine/engine_util_misc.h"
#include "engine/engine_util_spatial.h"
#include "user/user_flexcomp.h"
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#include "user/user_model.h"
#include "user/user_objects.h"
#include "user/user_util.h"
@@ -443,7 +443,7 @@ bool mjCFlexcomp::Make(mjSpec* spec, mjsBody* body, char* error, int error_sz) {
if (plugin.active) {
mjsPlugin* pplugin = &body->plugin;
pplugin->active = true;
pplugin->instance = static_cast<mjElement*>(plugin.instance);
pplugin->instance = static_cast<mjsElement*>(plugin.instance);
mjs_setString(pplugin->name, mjs_getString(plugin.name));
mjs_setString(pplugin->instance_name, plugin_instance_name.c_str());
}
@@ -507,7 +507,7 @@ bool mjCFlexcomp::Make(mjSpec* spec, mjsBody* body, char* error, int error_sz) {
if (plugin.active) {
mjsPlugin* pplugin = &pb->plugin;
pplugin->active = true;
pplugin->instance = static_cast<mjElement*>(plugin.instance);
pplugin->instance = static_cast<mjsElement*>(plugin.instance);
mjs_setString(pplugin->name, mjs_getString(plugin.name));
mjs_setString(pplugin->instance_name, plugin_instance_name.c_str());
}
+1 -1
View File
@@ -19,7 +19,7 @@
#include <vector>
#include <mujoco/mujoco.h>
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#include "user/user_model.h"
#include "user/user_objects.h"
+1
View File
@@ -15,6 +15,7 @@
#include <string.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mjvisualize.h>
#include <mujoco/mjspec.h>
#include "engine/engine_io.h"
#include "user/user_api.h"
+4 -3
View File
@@ -27,6 +27,7 @@
#include <utility>
#include <vector>
#include <mujoco/mjspec.h>
#include "user/user_api.h"
#ifdef MUJOCO_TINYOBJLOADER_IMPL
@@ -196,7 +197,7 @@ mjCMesh& mjCMesh::operator=(const mjCMesh& other) {
void mjCMesh::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.classname = &classname;
spec.file = &spec_file_;
@@ -1983,7 +1984,7 @@ mjCSkin& mjCSkin::operator=(const mjCSkin& other) {
void mjCSkin::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.classname = &classname;
spec.file = &spec_file_;
@@ -2395,7 +2396,7 @@ mjCFlex& mjCFlex::operator=(const mjCFlex& other) {
void mjCFlex::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.classname = &classname;
spec.material = &spec_material_;
+2 -1
View File
@@ -28,6 +28,7 @@
#include <mujoco/mjdata.h>
#include <mujoco/mjmacro.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mjspec.h>
#include <mujoco/mjtnum.h>
#include <mujoco/mjplugin.h>
#include <mujoco/mjvisualize.h>
@@ -416,7 +417,7 @@ void mjCModel::CreateObjectLists() {
void mjCModel::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.comment = &spec_comment_;
spec.modelfiledir = &spec_modelfiledir_;
spec.modelname = &spec_modelname_;
+2 -2
View File
@@ -27,13 +27,13 @@
#include <mujoco/mjmodel.h>
#include <mujoco/mjplugin.h>
#include <mujoco/mjtnum.h>
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#include "user/user_objects.h"
typedef std::map<std::string, int, std::less<> > mjKeyMap;
typedef std::array<mjKeyMap, mjNOBJECT> mjListKeyMap;
class mjCModel_ : public mjElement {
class mjCModel_ : public mjsElement {
public:
// attach namespaces
std::string prefix;
+25 -24
View File
@@ -45,6 +45,7 @@
#include "engine/engine_util_misc.h"
#include "engine/engine_util_solve.h"
#include "engine/engine_util_spatial.h"
#include <mujoco/mjspec.h>
#include "user/user_api.h"
#include "user/user_cache.h"
#include "user/user_model.h"
@@ -640,7 +641,7 @@ void mjCDef::PointToLocal() {
equality_.PointToLocal();
tendon_.PointToLocal();
actuator_.PointToLocal();
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.joint = &joint_.spec;
spec.geom = &geom_.spec;
@@ -949,7 +950,7 @@ mjCBody& mjCBody::operator-=(const mjCBody& subtree) {
void mjCBody::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.childclass = &classname;
spec.userdata = &spec_userdata_;
@@ -1256,7 +1257,7 @@ mjCBase* mjCBody::FindObject(mjtObj type, string _name, bool recursive) {
template <class T>
static mjElement* GetNext(std::vector<T*>& list, mjElement* child) {
static mjsElement* GetNext(std::vector<T*>& list, mjsElement* child) {
for (unsigned int i = 0; i < list.size()-1; i++) {
if (list[i]->spec.element == child) {
return list[i+1]->spec.element;
@@ -1268,7 +1269,7 @@ static mjElement* GetNext(std::vector<T*>& list, mjElement* child) {
// get next child of given type
mjElement* mjCBody::NextChild(mjElement* child, mjtObj type) {
mjsElement* mjCBody::NextChild(mjsElement* child, mjtObj type) {
if (type == mjOBJ_UNKNOWN) {
if (!child) {
throw mjCError(this, "child type must be specified if no child element is given");
@@ -1669,7 +1670,7 @@ void mjCFrame::SetParent(mjCBody* _body) {
void mjCFrame::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.childclass = &classname;
spec.info = &info;
@@ -1765,7 +1766,7 @@ bool mjCJoint::is_actfrclimited() const { return islimited(actfrclimited, actfrc
void mjCJoint::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.classname = &classname;
spec.userdata = &spec_userdata_;
@@ -1965,7 +1966,7 @@ mjCGeom& mjCGeom::operator=(const mjCGeom& other) {
// to be called after any default copy constructor
void mjCGeom::PointToLocal(void) {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.info = &info;
spec.classname = &classname;
@@ -2598,7 +2599,7 @@ mjCSite& mjCSite::operator=(const mjCSite& other) {
void mjCSite::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.info = &info;
spec.classname = &classname;
@@ -2750,7 +2751,7 @@ mjCCamera& mjCCamera::operator=(const mjCCamera& other) {
void mjCCamera::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.classname = &classname;
spec.userdata = &spec_userdata_;
@@ -2901,7 +2902,7 @@ mjCLight& mjCLight::operator=(const mjCLight& other) {
void mjCLight::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.classname = &classname;
spec.targetbody = &spec_targetbody_;
@@ -3001,7 +3002,7 @@ mjCHField& mjCHField::operator=(const mjCHField& other) {
void mjCHField::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.file = &spec_file_;
spec.content_type = &spec_content_type_;
@@ -3230,7 +3231,7 @@ mjCTexture& mjCTexture::operator=(const mjCTexture& other) {
void mjCTexture::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.classname = &classname;
spec.file = &spec_file_;
@@ -3941,7 +3942,7 @@ mjCMaterial& mjCMaterial::operator=(const mjCMaterial& other) {
void mjCMaterial::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.classname = &classname;
spec.texture = &spec_texture_;
@@ -4031,7 +4032,7 @@ mjCPair& mjCPair::operator=(const mjCPair& other) {
void mjCPair::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.classname = &classname;
spec.geomname1 = &spec_geomname1_;
@@ -4256,7 +4257,7 @@ mjCBodyPair& mjCBodyPair::operator=(const mjCBodyPair& other) {
void mjCBodyPair::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.bodyname1 = &spec_bodyname1_;
spec.bodyname2 = &spec_bodyname2_;
@@ -4390,7 +4391,7 @@ mjCEquality& mjCEquality::operator=(const mjCEquality& other) {
void mjCEquality::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.classname = &classname;
spec.name1 = &spec_name1_;
@@ -4559,7 +4560,7 @@ bool mjCTendon::is_limited() const { return islimited(limited, range); }
void mjCTendon::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.classname = &classname;
spec.material = &spec_material_;
@@ -4891,7 +4892,7 @@ mjCWrap& mjCWrap::operator=(const mjCWrap& other) {
void mjCWrap::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.info = &info;
}
@@ -5040,7 +5041,7 @@ bool mjCActuator::is_actlimited() const { return islimited(actlimited, actrange)
void mjCActuator::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.classname = &classname;
spec.userdata = &spec_userdata_;
@@ -5363,7 +5364,7 @@ mjCSensor& mjCSensor::operator=(const mjCSensor& other) {
void mjCSensor::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.classname = &classname;
spec.userdata = &spec_userdata_;
@@ -5866,7 +5867,7 @@ mjCNumeric& mjCNumeric::operator=(const mjCNumeric& other) {
void mjCNumeric::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.data = &spec_data_;
spec.info = &info;
@@ -5955,7 +5956,7 @@ mjCText& mjCText::operator=(const mjCText& other) {
void mjCText::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.data = &spec_data_;
spec.info = &info;
@@ -6035,7 +6036,7 @@ mjCTuple& mjCTuple::operator=(const mjCTuple& other) {
void mjCTuple::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.objtype = (mjIntVec*)&spec_objtype_;
spec.objname = &spec_objname_;
@@ -6170,7 +6171,7 @@ mjCKey& mjCKey::operator=(const mjCKey& other) {
void mjCKey::PointToLocal() {
spec.element = static_cast<mjElement*>(this);
spec.element = static_cast<mjsElement*>(this);
spec.name = &name;
spec.qpos = &spec_qpos_;
spec.qvel = &spec_qvel_;
+4 -4
View File
@@ -26,7 +26,7 @@
#include <mujoco/mjtnum.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mjplugin.h>
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#include "user/user_cache.h"
#include "user/user_util.h"
@@ -168,7 +168,7 @@ class mjCBoundingVolumeHierarchy : public mjCBoundingVolumeHierarchy_ {
//------------------------- class mjCBase ----------------------------------------------------------
// Generic functionality for all derived classes
class mjCBase_ : public mjElement {
class mjCBase_ : public mjsElement {
public:
int id; // object id
std::string name; // object name
@@ -309,7 +309,7 @@ class mjCBody : public mjCBody_, private mjsBody {
const std::vector<double>& get_userdata() { return userdata_; }
// get next child of given type
mjElement* NextChild(mjElement* child, mjtObj type = mjOBJ_UNKNOWN);
mjsElement* NextChild(mjsElement* child, mjtObj type = mjOBJ_UNKNOWN);
private:
mjCBody(const mjCBody& other, mjCModel* _model); // copy constructor
@@ -1624,7 +1624,7 @@ class mjCKey : public mjCKey_, private mjsKey {
//------------------------- class mjCDef -----------------------------------------------------------
// Describes one set of defaults
class mjCDef : public mjElement {
class mjCDef : public mjsElement {
friend class mjXWriter;
public:
+3 -3
View File
@@ -35,7 +35,7 @@
#include "cc/array_safety.h"
#include "engine/engine_crossplatform.h"
#include "engine/engine_resource.h"
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#include "user/user_util.h"
#include "user/user_vfs.h"
#include "xml/xml_native_reader.h"
@@ -345,7 +345,7 @@ mjSpec* mjParseXML(const char* filename, const mjVFS* vfs,
}
// create model, set filedir
spec = mjs_createSpec();
spec = mj_makeSpec();
const char* dir;
int ndir = 0;
mju_getResourceDir(resource, &dir, &ndir);
@@ -394,7 +394,7 @@ mjSpec* mjParseXML(const char* filename, const mjVFS* vfs,
// catch known errors
catch (mjXError err) {
mjCopyError(error, err.message, error_sz);
mjs_deleteSpec(spec);
mj_deleteSpec(spec);
return nullptr;
}
+1 -1
View File
@@ -19,7 +19,7 @@
#include <mujoco/mjexport.h>
#include <mujoco/mjmodel.h>
#include "user/user_api.h"
#include <mujoco/mjspec.h>
// Top level API
+7 -7
View File
@@ -28,7 +28,7 @@
#include <mujoco/mjmodel.h>
#include "engine/engine_io.h"
#include "engine/engine_resource.h"
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#include "user/user_vfs.h"
#include "xml/xml.h"
#include "xml/xml_native_reader.h"
@@ -59,7 +59,7 @@ std::optional<std::string> GlobalModel::ToXML(const mjModel* m, char* error,
mjCopyError(error, "No XML model loaded", error_sz);
return std::nullopt;
}
mjs_copyBack(spec_, m);
mj_copyBack(spec_, m);
std::string result = mjWriteXML(spec_, error, error_sz);
if (result.empty()) {
return std::nullopt;
@@ -70,7 +70,7 @@ std::optional<std::string> GlobalModel::ToXML(const mjModel* m, char* error,
void GlobalModel::Set(mjSpec* spec) {
std::lock_guard<std::mutex> lock(*mutex_);
if (spec_ != nullptr) {
mjs_deleteSpec(spec_);
mj_deleteSpec(spec_);
}
spec_ = spec;
}
@@ -96,13 +96,13 @@ mjModel* mj_loadXML(const char* filename, const mjVFS* vfs,
// parse new model
std::unique_ptr<mjSpec, std::function<void(mjSpec*)>> spec(
mjParseXML(filename, vfs, error, error_sz),
[](mjSpec* s) { mjs_deleteSpec(s); });
[](mjSpec* s) { mj_deleteSpec(s); });
if (!spec) {
return nullptr;
}
// compile new model
mjModel* m = mjs_compile(spec.get(), vfs);
mjModel* m = mj_compile(spec.get(), vfs);
if (!m) {
mjCopyError(error, mjs_getError(spec.get()), error_sz);
return nullptr;
@@ -248,7 +248,7 @@ int mj_saveXMLString(const mjSpec* s, char* xml, int xml_sz, char* error, int er
std::string error_msg = "Output string too short, should be at least " +
std::to_string(result.size()+1);
mjCopyError(error, error_msg.c_str(), error_sz);
return 0;
return result.size();
}
if (result.empty()) {
return 0;
@@ -256,6 +256,6 @@ int mj_saveXMLString(const mjSpec* s, char* xml, int xml_sz, char* error, int er
result.copy(xml, xml_sz);
xml[result.size()] = 0;
return 1;
return 0;
}
+1 -1
View File
@@ -17,7 +17,7 @@
#include <mujoco/mjexport.h>
#include <mujoco/mjmodel.h>
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#ifdef __cplusplus
extern "C" {
+1 -3
View File
@@ -21,9 +21,7 @@
#include <string>
#include <vector>
#include "user/user_api.h"
#include "user/user_model.h"
#include "user/user_objects.h"
#include <mujoco/mjspec.h>
#include "xml/xml_util.h"
#include "tinyxml2.h"
+1 -1
View File
@@ -19,7 +19,7 @@
#include <string>
#include "tinyxml2.h"
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#include "xml/xml_util.h"
+1 -1
View File
@@ -36,7 +36,7 @@
#include "engine/engine_plugin.h"
#include "engine/engine_util_errmem.h"
#include "engine/engine_util_misc.h"
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#include "user/user_composite.h"
#include "user/user_flexcomp.h"
#include "user/user_util.h"
+1 -1
View File
@@ -21,7 +21,7 @@
#include "tinyxml2.h"
#include <mujoco/mujoco.h>
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#include "xml/xml_base.h"
#include "xml/xml_util.h"
+2 -1
View File
@@ -22,11 +22,12 @@
#include <mujoco/mjmodel.h>
#include <mujoco/mjplugin.h>
#include <mujoco/mjspec.h>
#include <mujoco/mujoco.h>
#include "engine/engine_io.h"
#include "engine/engine_plugin.h"
#include "engine/engine_util_errmem.h"
#include "engine/engine_util_misc.h"
#include "user/user_api.h"
#include "user/user_model.h"
#include "user/user_objects.h"
#include "user/user_util.h"
+1 -1
View File
@@ -18,7 +18,7 @@
#include <cstdlib>
#include <string>
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#include "user/user_objects.h"
#include "xml/xml_base.h"
#include "tinyxml2.h"
+1
View File
@@ -20,6 +20,7 @@
#include <vector>
#include <mujoco/mjmodel.h>
#include <mujoco/mjspec.h>
#include "user/user_api.h"
#include "user/user_util.h"
#include "xml/xml_native_reader.h"
+1 -1
View File
@@ -19,7 +19,7 @@
#include <unordered_set>
#include <vector>
#include "user/user_api.h"
#include <mujoco/mjspec.h>
#include "xml/xml_base.h"
#include "tinyxml2.h"