Replace mjv_sceneState and related code with mjv_copy{Model,Data}

PiperOrigin-RevId: 760662776
Change-Id: I512bda9187fbc19ade6924b91d5cb2275078de42
This commit is contained in:
Yuval Tassa
2025-05-19 09:50:49 -07:00
committed by Copybara-Service
parent 8268c6d1ff
commit ced630181d
17 changed files with 357 additions and 3793 deletions
-11
View File
@@ -987,17 +987,6 @@ This structure contains everything needed to render the 3D scene in OpenGL.
.. mujoco-include:: mjvScene .. mujoco-include:: mjvScene
.. _mjvSceneState:
mjvSceneState
~~~~~~~~~~~~~
This structure contains the portions of :ref:`mjModel` and :ref:`mjData` that are required for
various ``mjv_*`` functions.
.. mujoco-include:: mjvSceneState
.. _mjvFigure: .. _mjvFigure:
mjvFigure mjvFigure
-63
View File
@@ -2004,15 +2004,6 @@ Rotate 3D vec in horizontal plane by angle between (0,1) and (forward_x,forward_
Move camera with mouse; action is mjtMouse. Move camera with mouse; action is mjtMouse.
.. _mjv_moveCameraFromState:
`mjv_moveCameraFromState <#mjv_moveCameraFromState>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mjv_moveCameraFromState
Move camera with mouse given a scene state; action is mjtMouse.
.. _mjv_movePerturb: .. _mjv_movePerturb:
`mjv_movePerturb <#mjv_movePerturb>`__ `mjv_movePerturb <#mjv_movePerturb>`__
@@ -2022,15 +2013,6 @@ Move camera with mouse given a scene state; action is mjtMouse.
Move perturb object with mouse; action is mjtMouse. Move perturb object with mouse; action is mjtMouse.
.. _mjv_movePerturbFromState:
`mjv_movePerturbFromState <#mjv_movePerturbFromState>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mjv_movePerturbFromState
Move perturb object with mouse given a scene state; action is mjtMouse.
.. _mjv_moveModel: .. _mjv_moveModel:
`mjv_moveModel <#mjv_moveModel>`__ `mjv_moveModel <#mjv_moveModel>`__
@@ -2173,15 +2155,6 @@ Free abstract scene.
Update entire scene given model state. Update entire scene given model state.
.. _mjv_updateSceneFromState:
`mjv_updateSceneFromState <#mjv_updateSceneFromState>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mjv_updateSceneFromState
Update entire scene from a scene state, return the number of new mjWARN_VGEOMFULL warnings.
.. _mjv_copyModel: .. _mjv_copyModel:
`mjv_copyModel <#mjv_copyModel>`__ `mjv_copyModel <#mjv_copyModel>`__
@@ -2191,42 +2164,6 @@ Update entire scene from a scene state, return the number of new mjWARN_VGEOMFUL
Copy mjModel, skip large arrays not required for abstract visualization. Copy mjModel, skip large arrays not required for abstract visualization.
.. _mjv_defaultSceneState:
`mjv_defaultSceneState <#mjv_defaultSceneState>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mjv_defaultSceneState
Set default scene state.
.. _mjv_makeSceneState:
`mjv_makeSceneState <#mjv_makeSceneState>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mjv_makeSceneState
Allocate resources and initialize a scene state object.
.. _mjv_freeSceneState:
`mjv_freeSceneState <#mjv_freeSceneState>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mjv_freeSceneState
Free scene state.
.. _mjv_updateSceneState:
`mjv_updateSceneState <#mjv_updateSceneState>`__
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. mujoco-include:: mjv_updateSceneState
Update a scene state from model and data.
.. _mjv_addGeoms: .. _mjv_addGeoms:
`mjv_addGeoms <#mjv_addGeoms>`__ `mjv_addGeoms <#mjv_addGeoms>`__
+6
View File
@@ -10,6 +10,12 @@ General
- Refactored island implementation so that island data is memory-contiguous. This speeds up island processing in the - Refactored island implementation so that island data is memory-contiguous. This speeds up island processing in the
solver and clears the way for the addition of the Newton and PGS solvers (currently only CG is supported). solver and clears the way for the addition of the Newton and PGS solvers (currently only CG is supported).
simulate
^^^^^^^^
- The struct ``mjv_sceneState`` has been removed. This struct was used for partial synchronization of ``mjModel`` and
``mjData`` when the Python viewer is used in passive mode. This functionality is now provided by :ref:`mjv_copyModel`
and :ref:`mjv_copyData`, which don't copy arrays which are not required for visualization.
Version 3.3.2 (April 28, 2025) Version 3.3.2 (April 28, 2025)
------------------------------ ------------------------------
-299
View File
@@ -2965,290 +2965,6 @@ struct mjvFigure_ { // abstract 2D figure passed to OpenGL rendere
float yaxisdata[2]; // range of y-axis in data units float yaxisdata[2]; // range of y-axis in data units
}; };
typedef struct mjvFigure_ mjvFigure; typedef struct mjvFigure_ mjvFigure;
struct mjvSceneState_ {
int nbuffer; // size of the buffer in bytes
void* buffer; // heap-allocated memory for all arrays in this struct
int maxgeom; // maximum number of mjvGeom supported by this state object
mjvScene scratch; // scratch space for vis geoms inserted by the user and plugins
// fields in mjModel that are necessary to re-render a scene
struct {
int nv;
int nu;
int na;
int nbody;
int nbvh;
int nbvhstatic;
int njnt;
int ngeom;
int nsite;
int ncam;
int nlight;
int nmesh;
int nskin;
int nflex;
int nflexvert;
int nflextexcoord;
int nskinvert;
int nskinface;
int nskinbone;
int nskinbonevert;
int nmat;
int neq;
int ntendon;
int ntree;
int nwrap;
int nsensor;
int nnames;
int npaths;
int nsensordata;
int narena;
mjOption opt;
mjVisual vis;
mjStatistic stat;
int* body_parentid;
int* body_rootid;
int* body_weldid;
int* body_mocapid;
int* body_jntnum;
int* body_jntadr;
int* body_dofnum;
int* body_dofadr;
int* body_geomnum;
int* body_geomadr;
mjtNum* body_iquat;
mjtNum* body_mass;
mjtNum* body_inertia;
int* body_bvhadr;
int* body_bvhnum;
int* bvh_depth;
int* bvh_child;
int* bvh_nodeid;
mjtNum* bvh_aabb;
int* jnt_type;
int* jnt_bodyid;
int* jnt_group;
int* geom_type;
int* geom_bodyid;
int* geom_contype;
int* geom_conaffinity;
int* geom_dataid;
int* geom_matid;
int* geom_group;
mjtNum* geom_size;
mjtNum* geom_aabb;
mjtNum* geom_rbound;
float* geom_rgba;
int* site_type;
int* site_bodyid;
int* site_matid;
int* site_group;
mjtNum* site_size;
float* site_rgba;
int* cam_orthographic;
mjtNum* cam_fovy;
mjtNum* cam_ipd;
int* cam_resolution;
float* cam_sensorsize;
float* cam_intrinsic;
mjtByte* light_directional;
mjtByte* light_castshadow;
float* light_bulbradius;
float* light_intensity;
float* light_range;
mjtByte* light_active;
float* light_attenuation;
float* light_cutoff;
float* light_exponent;
float* light_ambient;
float* light_diffuse;
float* light_specular;
mjtByte* flex_flatskin;
int* flex_dim;
int* flex_matid;
int* flex_group;
int* flex_interp;
int* flex_nodeadr;
int* flex_nodenum;
int* flex_nodebodyid;
int* flex_vertadr;
int* flex_vertnum;
int* flex_elem;
int* flex_elemtexcoord;
int* flex_elemlayer;
int* flex_elemadr;
int* flex_elemnum;
int* flex_elemdataadr;
int* flex_shell;
int* flex_shellnum;
int* flex_shelldataadr;
int* flex_texcoordadr;
int* flex_bvhadr;
int* flex_bvhnum;
mjtByte* flex_centered;
mjtNum* flex_node;
mjtNum* flex_radius;
float* flex_rgba;
float* flex_texcoord;
int* hfield_pathadr;
int* mesh_bvhadr;
int* mesh_bvhnum;
int* mesh_texcoordadr;
int* mesh_graphadr;
int* mesh_pathadr;
int* skin_matid;
int* skin_group;
float* skin_rgba;
float* skin_inflate;
int* skin_vertadr;
int* skin_vertnum;
int* skin_texcoordadr;
int* skin_faceadr;
int* skin_facenum;
int* skin_boneadr;
int* skin_bonenum;
float* skin_vert;
int* skin_face;
int* skin_bonevertadr;
int* skin_bonevertnum;
float* skin_bonebindpos;
float* skin_bonebindquat;
int* skin_bonebodyid;
int* skin_bonevertid;
float* skin_bonevertweight;
int* skin_pathadr;
int* tex_pathadr;
int* mat_texid;
mjtByte* mat_texuniform;
float* mat_texrepeat;
float* mat_emission;
float* mat_specular;
float* mat_shininess;
float* mat_reflectance;
float* mat_metallic;
float* mat_roughness;
float* mat_rgba;
int* eq_type;
int* eq_obj1id;
int* eq_obj2id;
int* eq_objtype;
mjtNum* eq_data;
int* tendon_num;
int* tendon_matid;
int* tendon_group;
mjtByte* tendon_limited;
mjtByte* tendon_actfrclimited;
mjtNum* tendon_width;
mjtNum* tendon_range;
mjtNum* tendon_actfrcrange;
mjtNum* tendon_stiffness;
mjtNum* tendon_damping;
mjtNum* tendon_frictionloss;
mjtNum* tendon_lengthspring;
float* tendon_rgba;
int* actuator_trntype;
int* actuator_dyntype;
int* actuator_trnid;
int* actuator_actadr;
int* actuator_actnum;
int* actuator_group;
mjtByte* actuator_ctrllimited;
mjtByte* actuator_actlimited;
mjtNum* actuator_ctrlrange;
mjtNum* actuator_actrange;
mjtNum* actuator_cranklength;
int* sensor_type;
int* sensor_objid;
int* sensor_adr;
int* name_bodyadr;
int* name_jntadr;
int* name_geomadr;
int* name_siteadr;
int* name_camadr;
int* name_lightadr;
int* name_eqadr;
int* name_tendonadr;
int* name_actuatoradr;
char* names;
char* paths;
} model;
// fields in mjData that are necessary to re-render a scene
struct {
mjWarningStat warning[mjNWARNING];
int nefc;
int ncon;
int nisland;
mjtNum time;
mjtNum* act;
mjtNum* ctrl;
mjtNum* xfrc_applied;
mjtByte* eq_active;
mjtNum* sensordata;
mjtNum* xpos;
mjtNum* xquat;
mjtNum* xmat;
mjtNum* xipos;
mjtNum* ximat;
mjtNum* xanchor;
mjtNum* xaxis;
mjtNum* geom_xpos;
mjtNum* geom_xmat;
mjtNum* site_xpos;
mjtNum* site_xmat;
mjtNum* cam_xpos;
mjtNum* cam_xmat;
mjtNum* light_xpos;
mjtNum* light_xdir;
mjtNum* subtree_com;
int* ten_wrapadr;
int* ten_wrapnum;
int* wrap_obj;
mjtNum* ten_length;
mjtNum* wrap_xpos;
mjtNum* bvh_aabb_dyn;
mjtByte* bvh_active;
int* island_dofadr;
int* dof_island;
int* efc_island;
int* tendon_efcadr;
mjtNum* flexvert_xpos;
mjContact* contact;
mjtNum* efc_force;
void* arena;
} data;
};
typedef struct mjvSceneState_ mjvSceneState;
//----------------------------- MJAPI FUNCTIONS -------------------------------- //----------------------------- MJAPI FUNCTIONS --------------------------------
void mj_defaultVFS(mjVFS* vfs); void mj_defaultVFS(mjVFS* vfs);
@@ -3437,14 +3153,8 @@ mjtNum mjv_frustumHeight(const mjvScene* scn);
void mjv_alignToCamera(mjtNum res[3], const mjtNum vec[3], const mjtNum forward[3]); void mjv_alignToCamera(mjtNum res[3], const mjtNum vec[3], const mjtNum forward[3]);
void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
const mjvScene* scn, mjvCamera* cam); const mjvScene* scn, mjvCamera* cam);
void mjv_moveCameraFromState(const mjvSceneState* scnstate, int action,
mjtNum reldx, mjtNum reldy,
const mjvScene* scn, mjvCamera* cam);
void mjv_movePerturb(const mjModel* m, const mjData* d, int action, mjtNum reldx, void mjv_movePerturb(const mjModel* m, const mjData* d, int action, mjtNum reldx,
mjtNum reldy, const mjvScene* scn, mjvPerturb* pert); mjtNum reldy, const mjvScene* scn, mjvPerturb* pert);
void mjv_movePerturbFromState(const mjvSceneState* scnstate, int action,
mjtNum reldx, mjtNum reldy,
const mjvScene* scn, mjvPerturb* pert);
void mjv_moveModel(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, void mjv_moveModel(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
const mjtNum roomup[3], mjvScene* scn); const mjtNum roomup[3], mjvScene* scn);
void mjv_initPerturb(const mjModel* m, mjData* d, const mjvScene* scn, mjvPerturb* pert); void mjv_initPerturb(const mjModel* m, mjData* d, const mjvScene* scn, mjvPerturb* pert);
@@ -3467,16 +3177,7 @@ void mjv_makeScene(const mjModel* m, mjvScene* scn, int maxgeom);
void mjv_freeScene(mjvScene* scn); void mjv_freeScene(mjvScene* scn);
void mjv_updateScene(const mjModel* m, mjData* d, const mjvOption* opt, void mjv_updateScene(const mjModel* m, mjData* d, const mjvOption* opt,
const mjvPerturb* pert, mjvCamera* cam, int catmask, mjvScene* scn); const mjvPerturb* pert, mjvCamera* cam, int catmask, mjvScene* scn);
int mjv_updateSceneFromState(const mjvSceneState* scnstate, const mjvOption* opt,
const mjvPerturb* pert, mjvCamera* cam, int catmask,
mjvScene* scn);
void mjv_copyModel(mjModel* dest, const mjModel* src); void mjv_copyModel(mjModel* dest, const mjModel* src);
void mjv_defaultSceneState(mjvSceneState* scnstate);
void mjv_makeSceneState(const mjModel* m, const mjData* d,
mjvSceneState* scnstate, int maxgeom);
void mjv_freeSceneState(mjvSceneState* scnstate);
void mjv_updateSceneState(const mjModel* m, mjData* d, const mjvOption* opt,
mjvSceneState* scnstate);
void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* opt, void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* opt,
const mjvPerturb* pert, int catmask, mjvScene* scn); const mjvPerturb* pert, int catmask, mjvScene* scn);
void mjv_makeLights(const mjModel* m, const mjData* d, mjvScene* scn); void mjv_makeLights(const mjModel* m, const mjData* d, mjvScene* scn);
-288
View File
@@ -406,292 +406,4 @@ struct mjvFigure_ { // abstract 2D figure passed to OpenGL rendere
}; };
typedef struct mjvFigure_ mjvFigure; typedef struct mjvFigure_ mjvFigure;
//---------------------------------- mjvSceneState -------------------------------------------------
struct mjvSceneState_ {
int nbuffer; // size of the buffer in bytes
void* buffer; // heap-allocated memory for all arrays in this struct
int maxgeom; // maximum number of mjvGeom supported by this state object
mjvScene scratch; // scratch space for vis geoms inserted by the user and plugins
// fields in mjModel that are necessary to re-render a scene
struct {
int nv;
int nu;
int na;
int nbody;
int nbvh;
int nbvhstatic;
int njnt;
int ngeom;
int nsite;
int ncam;
int nlight;
int nmesh;
int nskin;
int nflex;
int nflexvert;
int nflextexcoord;
int nskinvert;
int nskinface;
int nskinbone;
int nskinbonevert;
int nmat;
int neq;
int ntendon;
int ntree;
int nwrap;
int nsensor;
int nnames;
int npaths;
int nsensordata;
int narena;
mjOption opt;
mjVisual vis;
mjStatistic stat;
int* body_parentid;
int* body_rootid;
int* body_weldid;
int* body_mocapid;
int* body_jntnum;
int* body_jntadr;
int* body_dofnum;
int* body_dofadr;
int* body_geomnum;
int* body_geomadr;
mjtNum* body_iquat;
mjtNum* body_mass;
mjtNum* body_inertia;
int* body_bvhadr;
int* body_bvhnum;
int* bvh_depth;
int* bvh_child;
int* bvh_nodeid;
mjtNum* bvh_aabb;
int* jnt_type;
int* jnt_bodyid;
int* jnt_group;
int* geom_type;
int* geom_bodyid;
int* geom_contype;
int* geom_conaffinity;
int* geom_dataid;
int* geom_matid;
int* geom_group;
mjtNum* geom_size;
mjtNum* geom_aabb;
mjtNum* geom_rbound;
float* geom_rgba;
int* site_type;
int* site_bodyid;
int* site_matid;
int* site_group;
mjtNum* site_size;
float* site_rgba;
int* cam_orthographic;
mjtNum* cam_fovy;
mjtNum* cam_ipd;
int* cam_resolution;
float* cam_sensorsize;
float* cam_intrinsic;
mjtByte* light_directional;
mjtByte* light_castshadow;
float* light_bulbradius;
float* light_intensity;
float* light_range;
mjtByte* light_active;
float* light_attenuation;
float* light_cutoff;
float* light_exponent;
float* light_ambient;
float* light_diffuse;
float* light_specular;
mjtByte* flex_flatskin;
int* flex_dim;
int* flex_matid;
int* flex_group;
int* flex_interp;
int* flex_nodeadr;
int* flex_nodenum;
int* flex_nodebodyid;
int* flex_vertadr;
int* flex_vertnum;
int* flex_elem;
int* flex_elemtexcoord;
int* flex_elemlayer;
int* flex_elemadr;
int* flex_elemnum;
int* flex_elemdataadr;
int* flex_shell;
int* flex_shellnum;
int* flex_shelldataadr;
int* flex_texcoordadr;
int* flex_bvhadr;
int* flex_bvhnum;
mjtByte* flex_centered;
mjtNum* flex_node;
mjtNum* flex_radius;
float* flex_rgba;
float* flex_texcoord;
int* hfield_pathadr;
int* mesh_bvhadr;
int* mesh_bvhnum;
int* mesh_texcoordadr;
int* mesh_graphadr;
int* mesh_pathadr;
int* skin_matid;
int* skin_group;
float* skin_rgba;
float* skin_inflate;
int* skin_vertadr;
int* skin_vertnum;
int* skin_texcoordadr;
int* skin_faceadr;
int* skin_facenum;
int* skin_boneadr;
int* skin_bonenum;
float* skin_vert;
int* skin_face;
int* skin_bonevertadr;
int* skin_bonevertnum;
float* skin_bonebindpos;
float* skin_bonebindquat;
int* skin_bonebodyid;
int* skin_bonevertid;
float* skin_bonevertweight;
int* skin_pathadr;
int* tex_pathadr;
int* mat_texid;
mjtByte* mat_texuniform;
float* mat_texrepeat;
float* mat_emission;
float* mat_specular;
float* mat_shininess;
float* mat_reflectance;
float* mat_metallic;
float* mat_roughness;
float* mat_rgba;
int* eq_type;
int* eq_obj1id;
int* eq_obj2id;
int* eq_objtype;
mjtNum* eq_data;
int* tendon_num;
int* tendon_matid;
int* tendon_group;
mjtByte* tendon_limited;
mjtByte* tendon_actfrclimited;
mjtNum* tendon_width;
mjtNum* tendon_range;
mjtNum* tendon_actfrcrange;
mjtNum* tendon_stiffness;
mjtNum* tendon_damping;
mjtNum* tendon_frictionloss;
mjtNum* tendon_lengthspring;
float* tendon_rgba;
int* actuator_trntype;
int* actuator_dyntype;
int* actuator_trnid;
int* actuator_actadr;
int* actuator_actnum;
int* actuator_group;
mjtByte* actuator_ctrllimited;
mjtByte* actuator_actlimited;
mjtNum* actuator_ctrlrange;
mjtNum* actuator_actrange;
mjtNum* actuator_cranklength;
int* sensor_type;
int* sensor_objid;
int* sensor_adr;
int* name_bodyadr;
int* name_jntadr;
int* name_geomadr;
int* name_siteadr;
int* name_camadr;
int* name_lightadr;
int* name_eqadr;
int* name_tendonadr;
int* name_actuatoradr;
char* names;
char* paths;
} model;
// fields in mjData that are necessary to re-render a scene
struct {
mjWarningStat warning[mjNWARNING];
int nefc;
int ncon;
int nisland;
mjtNum time;
mjtNum* act;
mjtNum* ctrl;
mjtNum* xfrc_applied;
mjtByte* eq_active;
mjtNum* sensordata;
mjtNum* xpos;
mjtNum* xquat;
mjtNum* xmat;
mjtNum* xipos;
mjtNum* ximat;
mjtNum* xanchor;
mjtNum* xaxis;
mjtNum* geom_xpos;
mjtNum* geom_xmat;
mjtNum* site_xpos;
mjtNum* site_xmat;
mjtNum* cam_xpos;
mjtNum* cam_xmat;
mjtNum* light_xpos;
mjtNum* light_xdir;
mjtNum* subtree_com;
int* ten_wrapadr;
int* ten_wrapnum;
int* wrap_obj;
mjtNum* ten_length;
mjtNum* wrap_xpos;
mjtNum* bvh_aabb_dyn;
mjtByte* bvh_active;
int* island_dofadr;
int* dof_island;
int* efc_island;
int* tendon_efcadr;
mjtNum* flexvert_xpos;
mjContact* contact;
mjtNum* efc_force;
void* arena;
} data;
};
typedef struct mjvSceneState_ mjvSceneState;
#endif // MUJOCO_MJVISUALIZE_H_ #endif // MUJOCO_MJVISUALIZE_H_
+284 -290
View File
@@ -66,92 +66,92 @@
//-------------------------------- mjModel --------------------------------------------------------- //-------------------------------- mjModel ---------------------------------------------------------
// int fields of mjModel // int fields of mjModel
#define MJMODEL_INTS \ #define MJMODEL_INTS \
X ( nq ) \ X( nq ) \
XMJV( nv ) \ X( nv ) \
XMJV( nu ) \ X( nu ) \
XMJV( na ) \ X( na ) \
XMJV( nbody ) \ X( nbody ) \
XMJV( nbvh ) \ X( nbvh ) \
XMJV( nbvhstatic ) \ X( nbvhstatic ) \
X ( nbvhdynamic ) \ X( nbvhdynamic ) \
XMJV( njnt ) \ X( njnt ) \
XMJV( ngeom ) \ X( ngeom ) \
XMJV( nsite ) \ X( nsite ) \
XMJV( ncam ) \ X( ncam ) \
XMJV( nlight ) \ X( nlight ) \
XMJV( nflex ) \ X( nflex ) \
X ( nflexnode ) \ X( nflexnode ) \
XMJV( nflexvert ) \ X( nflexvert ) \
X ( nflexedge ) \ X( nflexedge ) \
X ( nflexelem ) \ X( nflexelem ) \
X ( nflexelemdata ) \ X( nflexelemdata ) \
X ( nflexelemedge ) \ X( nflexelemedge ) \
X ( nflexshelldata ) \ X( nflexshelldata ) \
X ( nflexevpair ) \ X( nflexevpair ) \
XMJV( nflextexcoord ) \ X( nflextexcoord ) \
XMJV( nmesh ) \ X( nmesh ) \
X ( nmeshvert ) \ X( nmeshvert ) \
X ( nmeshnormal ) \ X( nmeshnormal ) \
X ( nmeshtexcoord ) \ X( nmeshtexcoord ) \
X ( nmeshface ) \ X( nmeshface ) \
X ( nmeshgraph ) \ X( nmeshgraph ) \
X ( nmeshpoly ) \ X( nmeshpoly ) \
X ( nmeshpolyvert ) \ X( nmeshpolyvert ) \
X ( nmeshpolymap ) \ X( nmeshpolymap ) \
XMJV( nskin ) \ X( nskin ) \
XMJV( nskinvert ) \ X( nskinvert ) \
X ( nskintexvert ) \ X( nskintexvert ) \
XMJV( nskinface ) \ X( nskinface ) \
XMJV( nskinbone ) \ X( nskinbone ) \
XMJV( nskinbonevert ) \ X( nskinbonevert ) \
X ( nhfield ) \ X( nhfield ) \
X ( nhfielddata ) \ X( nhfielddata ) \
X ( ntex ) \ X( ntex ) \
X ( ntexdata ) \ X( ntexdata ) \
XMJV( nmat ) \ X( nmat ) \
X ( npair ) \ X( npair ) \
X ( nexclude ) \ X( nexclude ) \
XMJV( neq ) \ X( neq ) \
XMJV( ntendon ) \ X( ntendon ) \
XMJV( nwrap ) \ X( nwrap ) \
XMJV( nsensor ) \ X( nsensor ) \
X ( nnumeric ) \ X( nnumeric ) \
X ( nnumericdata ) \ X( nnumericdata ) \
X ( ntext ) \ X( ntext ) \
X ( ntextdata ) \ X( ntextdata ) \
X ( ntuple ) \ X( ntuple ) \
X ( ntupledata ) \ X( ntupledata ) \
X ( nkey ) \ X( nkey ) \
X ( nmocap ) \ X( nmocap ) \
X ( nplugin ) \ X( nplugin ) \
X ( npluginattr ) \ X( npluginattr ) \
X ( nuser_body ) \ X( nuser_body ) \
X ( nuser_jnt ) \ X( nuser_jnt ) \
X ( nuser_geom ) \ X( nuser_geom ) \
X ( nuser_site ) \ X( nuser_site ) \
X ( nuser_cam ) \ X( nuser_cam ) \
X ( nuser_tendon ) \ X( nuser_tendon ) \
X ( nuser_actuator ) \ X( nuser_actuator ) \
X ( nuser_sensor ) \ X( nuser_sensor ) \
XMJV( nnames ) \ X( nnames ) \
XMJV( npaths ) \ X( npaths ) \
X ( nnames_map ) \ X( nnames_map ) \
X ( nM ) \ X( nM ) \
X ( nB ) \ X( nB ) \
X ( nC ) \ X( nC ) \
X ( nD ) \ X( nD ) \
X ( nJmom ) \ X( nJmom ) \
XMJV( ntree ) \ X( ntree ) \
X ( ngravcomp ) \ X( ngravcomp ) \
X ( nemax ) \ X( nemax ) \
X ( njmax ) \ X( njmax ) \
X ( nconmax ) \ X( nconmax ) \
X ( nuserdata ) \ X( nuserdata ) \
XMJV( nsensordata ) \ X( nsensordata ) \
X ( npluginstate ) \ X( npluginstate ) \
X ( narena ) \ X( narena ) \
X ( nbuffer ) X( nbuffer )
/* nbuffer needs to be the final field */ /* nbuffer needs to be the final field */
@@ -178,31 +178,31 @@
// pointer fields of mjModel // pointer fields of mjModel
// XMJV means that the field is required to construct mjvScene // XNV means that the field is not required to construct mjvScene
// (by default we define XMJV to be the same as X) // (by default we define XNV to be the same as X)
#define MJMODEL_POINTERS \ #define MJMODEL_POINTERS \
X ( mjtNum, qpos0, nq, 1 ) \ X ( mjtNum, qpos0, nq, 1 ) \
X ( mjtNum, qpos_spring, nq, 1 ) \ X ( mjtNum, qpos_spring, nq, 1 ) \
XMJV( int, body_parentid, nbody, 1 ) \ X ( int, body_parentid, nbody, 1 ) \
XMJV( int, body_rootid, nbody, 1 ) \ X ( int, body_rootid, nbody, 1 ) \
XMJV( int, body_weldid, nbody, 1 ) \ X ( int, body_weldid, nbody, 1 ) \
XMJV( int, body_mocapid, nbody, 1 ) \ X ( int, body_mocapid, nbody, 1 ) \
XMJV( int, body_jntnum, nbody, 1 ) \ X ( int, body_jntnum, nbody, 1 ) \
XMJV( int, body_jntadr, nbody, 1 ) \ X ( int, body_jntadr, nbody, 1 ) \
XMJV( int, body_dofnum, nbody, 1 ) \ X ( int, body_dofnum, nbody, 1 ) \
XMJV( int, body_dofadr, nbody, 1 ) \ X ( int, body_dofadr, nbody, 1 ) \
X ( int, body_treeid, nbody, 1 ) \ X ( int, body_treeid, nbody, 1 ) \
XMJV( int, body_geomnum, nbody, 1 ) \ X ( int, body_geomnum, nbody, 1 ) \
XMJV( int, body_geomadr, nbody, 1 ) \ X ( int, body_geomadr, nbody, 1 ) \
X ( mjtByte, body_simple, nbody, 1 ) \ X ( mjtByte, body_simple, nbody, 1 ) \
X ( mjtByte, body_sameframe, nbody, 1 ) \ X ( mjtByte, body_sameframe, nbody, 1 ) \
X ( mjtNum, body_pos, nbody, 3 ) \ X ( mjtNum, body_pos, nbody, 3 ) \
X ( mjtNum, body_quat, nbody, 4 ) \ X ( mjtNum, body_quat, nbody, 4 ) \
X ( mjtNum, body_ipos, nbody, 3 ) \ X ( mjtNum, body_ipos, nbody, 3 ) \
XMJV( mjtNum, body_iquat, nbody, 4 ) \ X ( mjtNum, body_iquat, nbody, 4 ) \
XMJV( mjtNum, body_mass, nbody, 1 ) \ X ( mjtNum, body_mass, nbody, 1 ) \
X ( mjtNum, body_subtreemass, nbody, 1 ) \ X ( mjtNum, body_subtreemass, nbody, 1 ) \
XMJV( mjtNum, body_inertia, nbody, 3 ) \ X ( mjtNum, body_inertia, nbody, 3 ) \
X ( mjtNum, body_invweight0, nbody, 2 ) \ X ( mjtNum, body_invweight0, nbody, 2 ) \
X ( mjtNum, body_gravcomp, nbody, 1 ) \ X ( mjtNum, body_gravcomp, nbody, 1 ) \
X ( mjtNum, body_margin, nbody, 1 ) \ X ( mjtNum, body_margin, nbody, 1 ) \
@@ -210,17 +210,17 @@
X ( int, body_plugin, nbody, 1 ) \ X ( int, body_plugin, nbody, 1 ) \
X ( int, body_contype, nbody, 1 ) \ X ( int, body_contype, nbody, 1 ) \
X ( int, body_conaffinity, nbody, 1 ) \ X ( int, body_conaffinity, nbody, 1 ) \
XMJV( int, body_bvhadr, nbody, 1 ) \ X ( int, body_bvhadr, nbody, 1 ) \
XMJV( int, body_bvhnum, nbody, 1 ) \ X ( int, body_bvhnum, nbody, 1 ) \
XMJV( int, bvh_depth, nbvh, 1 ) \ X ( int, bvh_depth, nbvh, 1 ) \
XMJV( int, bvh_child, nbvh, 2 ) \ X ( int, bvh_child, nbvh, 2 ) \
XMJV( int, bvh_nodeid, nbvh, 1 ) \ X ( int, bvh_nodeid, nbvh, 1 ) \
XMJV( mjtNum, bvh_aabb, nbvhstatic, 6 ) \ X ( mjtNum, bvh_aabb, nbvhstatic, 6 ) \
XMJV( int, jnt_type, njnt, 1 ) \ X ( int, jnt_type, njnt, 1 ) \
X ( int, jnt_qposadr, njnt, 1 ) \ X ( int, jnt_qposadr, njnt, 1 ) \
X ( int, jnt_dofadr, njnt, 1 ) \ X ( int, jnt_dofadr, njnt, 1 ) \
XMJV( int, jnt_bodyid, njnt, 1 ) \ X ( int, jnt_bodyid, njnt, 1 ) \
XMJV( int, jnt_group, njnt, 1 ) \ X ( int, jnt_group, njnt, 1 ) \
X ( mjtByte, jnt_limited, njnt, 1 ) \ X ( mjtByte, jnt_limited, njnt, 1 ) \
X ( mjtByte, jnt_actfrclimited, njnt, 1 ) \ X ( mjtByte, jnt_actfrclimited, njnt, 1 ) \
X ( mjtByte, jnt_actgravcomp, njnt, 1 ) \ X ( mjtByte, jnt_actgravcomp, njnt, 1 ) \
@@ -246,23 +246,23 @@
X ( mjtNum, dof_damping, nv, 1 ) \ X ( mjtNum, dof_damping, nv, 1 ) \
X ( mjtNum, dof_invweight0, nv, 1 ) \ X ( mjtNum, dof_invweight0, nv, 1 ) \
X ( mjtNum, dof_M0, nv, 1 ) \ X ( mjtNum, dof_M0, nv, 1 ) \
XMJV( int, geom_type, ngeom, 1 ) \ X ( int, geom_type, ngeom, 1 ) \
XMJV( int, geom_contype, ngeom, 1 ) \ X ( int, geom_contype, ngeom, 1 ) \
XMJV( int, geom_conaffinity, ngeom, 1 ) \ X ( int, geom_conaffinity, ngeom, 1 ) \
X ( int, geom_condim, ngeom, 1 ) \ X ( int, geom_condim, ngeom, 1 ) \
XMJV( int, geom_bodyid, ngeom, 1 ) \ X ( int, geom_bodyid, ngeom, 1 ) \
XMJV( int, geom_dataid, ngeom, 1 ) \ X ( int, geom_dataid, ngeom, 1 ) \
XMJV( int, geom_matid, ngeom, 1 ) \ X ( int, geom_matid, ngeom, 1 ) \
XMJV( int, geom_group, ngeom, 1 ) \ X ( int, geom_group, ngeom, 1 ) \
X ( int, geom_priority, ngeom, 1 ) \ X ( int, geom_priority, ngeom, 1 ) \
X ( int, geom_plugin, ngeom, 1 ) \ X ( int, geom_plugin, ngeom, 1 ) \
X ( mjtByte, geom_sameframe, ngeom, 1 ) \ X ( mjtByte, geom_sameframe, ngeom, 1 ) \
X ( mjtNum, geom_solmix, ngeom, 1 ) \ X ( mjtNum, geom_solmix, ngeom, 1 ) \
X ( mjtNum, geom_solref, ngeom, mjNREF ) \ X ( mjtNum, geom_solref, ngeom, mjNREF ) \
X ( mjtNum, geom_solimp, ngeom, mjNIMP ) \ X ( mjtNum, geom_solimp, ngeom, mjNIMP ) \
XMJV( mjtNum, geom_size, ngeom, 3 ) \ X ( mjtNum, geom_size, ngeom, 3 ) \
XMJV( mjtNum, geom_aabb, ngeom, 6 ) \ X ( mjtNum, geom_aabb, ngeom, 6 ) \
XMJV( mjtNum, geom_rbound, ngeom, 1 ) \ X ( mjtNum, geom_rbound, ngeom, 1 ) \
X ( mjtNum, geom_pos, ngeom, 3 ) \ X ( mjtNum, geom_pos, ngeom, 3 ) \
X ( mjtNum, geom_quat, ngeom, 4 ) \ X ( mjtNum, geom_quat, ngeom, 4 ) \
X ( mjtNum, geom_friction, ngeom, 3 ) \ X ( mjtNum, geom_friction, ngeom, 3 ) \
@@ -270,17 +270,17 @@
X ( mjtNum, geom_gap, ngeom, 1 ) \ X ( mjtNum, geom_gap, ngeom, 1 ) \
XNV ( mjtNum, geom_fluid, ngeom, mjNFLUID ) \ XNV ( mjtNum, geom_fluid, ngeom, mjNFLUID ) \
X ( mjtNum, geom_user, ngeom, MJ_M(nuser_geom) ) \ X ( mjtNum, geom_user, ngeom, MJ_M(nuser_geom) ) \
XMJV( float, geom_rgba, ngeom, 4 ) \ X ( float, geom_rgba, ngeom, 4 ) \
XMJV( int, site_type, nsite, 1 ) \ X ( int, site_type, nsite, 1 ) \
XMJV( int, site_bodyid, nsite, 1 ) \ X ( int, site_bodyid, nsite, 1 ) \
XMJV( int, site_matid, nsite, 1 ) \ X ( int, site_matid, nsite, 1 ) \
XMJV( int, site_group, nsite, 1 ) \ X ( int, site_group, nsite, 1 ) \
X ( mjtByte, site_sameframe, nsite, 1 ) \ X ( mjtByte, site_sameframe, nsite, 1 ) \
XMJV( mjtNum, site_size, nsite, 3 ) \ X ( mjtNum, site_size, nsite, 3 ) \
X ( mjtNum, site_pos, nsite, 3 ) \ X ( mjtNum, site_pos, nsite, 3 ) \
X ( mjtNum, site_quat, nsite, 4 ) \ X ( mjtNum, site_quat, nsite, 4 ) \
X ( mjtNum, site_user, nsite, MJ_M(nuser_site) ) \ X ( mjtNum, site_user, nsite, MJ_M(nuser_site) ) \
XMJV( float, site_rgba, nsite, 4 ) \ X ( float, site_rgba, nsite, 4 ) \
X ( int, cam_mode, ncam, 1 ) \ X ( int, cam_mode, ncam, 1 ) \
X ( int, cam_bodyid, ncam, 1 ) \ X ( int, cam_bodyid, ncam, 1 ) \
X ( int, cam_targetbodyid, ncam, 1 ) \ X ( int, cam_targetbodyid, ncam, 1 ) \
@@ -289,33 +289,33 @@
X ( mjtNum, cam_poscom0, ncam, 3 ) \ X ( mjtNum, cam_poscom0, ncam, 3 ) \
X ( mjtNum, cam_pos0, ncam, 3 ) \ X ( mjtNum, cam_pos0, ncam, 3 ) \
X ( mjtNum, cam_mat0, ncam, 9 ) \ X ( mjtNum, cam_mat0, ncam, 9 ) \
XMJV( int, cam_orthographic, ncam, 1 ) \ X ( int, cam_orthographic, ncam, 1 ) \
XMJV( mjtNum, cam_fovy, ncam, 1 ) \ X ( mjtNum, cam_fovy, ncam, 1 ) \
XMJV( mjtNum, cam_ipd, ncam, 1 ) \ X ( mjtNum, cam_ipd, ncam, 1 ) \
XMJV( int, cam_resolution, ncam, 2 ) \ X ( int, cam_resolution, ncam, 2 ) \
XMJV( float, cam_sensorsize, ncam, 2 ) \ X ( float, cam_sensorsize, ncam, 2 ) \
XMJV( float, cam_intrinsic, ncam, 4 ) \ X ( float, cam_intrinsic, ncam, 4 ) \
X ( mjtNum, cam_user, ncam, MJ_M(nuser_cam) ) \ X ( mjtNum, cam_user, ncam, MJ_M(nuser_cam) ) \
X ( int, light_mode, nlight, 1 ) \ X ( int, light_mode, nlight, 1 ) \
X ( int, light_bodyid, nlight, 1 ) \ X ( int, light_bodyid, nlight, 1 ) \
X ( int, light_targetbodyid, nlight, 1 ) \ X ( int, light_targetbodyid, nlight, 1 ) \
XMJV( mjtByte, light_directional, nlight, 1 ) \ X ( mjtByte, light_directional, nlight, 1 ) \
XMJV( mjtByte, light_castshadow, nlight, 1 ) \ X ( mjtByte, light_castshadow, nlight, 1 ) \
XMJV( float, light_bulbradius, nlight, 1 ) \ X ( float, light_bulbradius, nlight, 1 ) \
XMJV( float, light_intensity, nlight, 1 ) \ X ( float, light_intensity, nlight, 1 ) \
XMJV( float, light_range, nlight, 1 ) \ X ( float, light_range, nlight, 1 ) \
XMJV( mjtByte, light_active, nlight, 1 ) \ X ( mjtByte, light_active, nlight, 1 ) \
X ( mjtNum, light_pos, nlight, 3 ) \ X ( mjtNum, light_pos, nlight, 3 ) \
X ( mjtNum, light_dir, nlight, 3 ) \ X ( mjtNum, light_dir, nlight, 3 ) \
X ( mjtNum, light_poscom0, nlight, 3 ) \ X ( mjtNum, light_poscom0, nlight, 3 ) \
X ( mjtNum, light_pos0, nlight, 3 ) \ X ( mjtNum, light_pos0, nlight, 3 ) \
X ( mjtNum, light_dir0, nlight, 3 ) \ X ( mjtNum, light_dir0, nlight, 3 ) \
XMJV( float, light_attenuation, nlight, 3 ) \ X ( float, light_attenuation, nlight, 3 ) \
XMJV( float, light_cutoff, nlight, 1 ) \ X ( float, light_cutoff, nlight, 1 ) \
XMJV( float, light_exponent, nlight, 1 ) \ X ( float, light_exponent, nlight, 1 ) \
XMJV( float, light_ambient, nlight, 3 ) \ X ( float, light_ambient, nlight, 3 ) \
XMJV( float, light_diffuse, nlight, 3 ) \ X ( float, light_diffuse, nlight, 3 ) \
XMJV( float, light_specular, nlight, 3 ) \ X ( float, light_specular, nlight, 3 ) \
X ( int, flex_contype, nflex, 1 ) \ X ( int, flex_contype, nflex, 1 ) \
X ( int, flex_conaffinity, nflex, 1 ) \ X ( int, flex_conaffinity, nflex, 1 ) \
X ( int, flex_condim, nflex, 1 ) \ X ( int, flex_condim, nflex, 1 ) \
@@ -329,42 +329,42 @@
X ( mjtByte, flex_internal, nflex, 1 ) \ X ( mjtByte, flex_internal, nflex, 1 ) \
X ( int, flex_selfcollide, nflex, 1 ) \ X ( int, flex_selfcollide, nflex, 1 ) \
X ( int, flex_activelayers, nflex, 1 ) \ X ( int, flex_activelayers, nflex, 1 ) \
XMJV( int, flex_dim, nflex, 1 ) \ X ( int, flex_dim, nflex, 1 ) \
XMJV( int, flex_matid, nflex, 1 ) \ X ( int, flex_matid, nflex, 1 ) \
XMJV( int, flex_group, nflex, 1 ) \ X ( int, flex_group, nflex, 1 ) \
XMJV( int, flex_interp, nflex, 1 ) \ X ( int, flex_interp, nflex, 1 ) \
XMJV( int, flex_nodeadr, nflex, 1 ) \ X ( int, flex_nodeadr, nflex, 1 ) \
XMJV( int, flex_nodenum, nflex, 1 ) \ X ( int, flex_nodenum, nflex, 1 ) \
XMJV( int, flex_vertadr, nflex, 1 ) \ X ( int, flex_vertadr, nflex, 1 ) \
XMJV( int, flex_vertnum, nflex, 1 ) \ X ( int, flex_vertnum, nflex, 1 ) \
X ( int, flex_edgeadr, nflex, 1 ) \ X ( int, flex_edgeadr, nflex, 1 ) \
X ( int, flex_edgenum, nflex, 1 ) \ X ( int, flex_edgenum, nflex, 1 ) \
XMJV( int, flex_elemadr, nflex, 1 ) \ X ( int, flex_elemadr, nflex, 1 ) \
XMJV( int, flex_elemnum, nflex, 1 ) \ X ( int, flex_elemnum, nflex, 1 ) \
XMJV( int, flex_elemdataadr, nflex, 1 ) \ X ( int, flex_elemdataadr, nflex, 1 ) \
X ( int, flex_elemedgeadr, nflex, 1 ) \ X ( int, flex_elemedgeadr, nflex, 1 ) \
XMJV( int, flex_shellnum, nflex, 1 ) \ X ( int, flex_shellnum, nflex, 1 ) \
XMJV( int, flex_shelldataadr, nflex, 1 ) \ X ( int, flex_shelldataadr, nflex, 1 ) \
X ( int, flex_evpairadr, nflex, 1 ) \ X ( int, flex_evpairadr, nflex, 1 ) \
X ( int, flex_evpairnum, nflex, 1 ) \ X ( int, flex_evpairnum, nflex, 1 ) \
XMJV( int, flex_texcoordadr, nflex, 1 ) \ X ( int, flex_texcoordadr, nflex, 1 ) \
XMJV( int, flex_nodebodyid, nflexnode, 1 ) \ X ( int, flex_nodebodyid, nflexnode, 1 ) \
X ( int, flex_vertbodyid, nflexvert, 1 ) \ X ( int, flex_vertbodyid, nflexvert, 1 ) \
X ( int, flex_edge, nflexedge, 2 ) \ X ( int, flex_edge, nflexedge, 2 ) \
X ( int, flex_edgeflap, nflexedge, 2 ) \ X ( int, flex_edgeflap, nflexedge, 2 ) \
XMJV( int, flex_elem, nflexelemdata, 1 ) \ X ( int, flex_elem, nflexelemdata, 1 ) \
XMJV( int, flex_elemtexcoord, nflexelemdata, 1 ) \ X ( int, flex_elemtexcoord, nflexelemdata, 1 ) \
X ( int, flex_elemedge, nflexelemedge, 1 ) \ X ( int, flex_elemedge, nflexelemedge, 1 ) \
XMJV( int, flex_elemlayer, nflexelem, 1 ) \ X ( int, flex_elemlayer, nflexelem, 1 ) \
XMJV( int, flex_shell, nflexshelldata,1 ) \ X ( int, flex_shell, nflexshelldata,1 ) \
X ( int, flex_evpair, nflexevpair, 2 ) \ X ( int, flex_evpair, nflexevpair, 2 ) \
X ( mjtNum, flex_vert, nflexvert, 3 ) \ X ( mjtNum, flex_vert, nflexvert, 3 ) \
X ( mjtNum, flex_vert0, nflexvert, 3 ) \ X ( mjtNum, flex_vert0, nflexvert, 3 ) \
XMJV( mjtNum, flex_node, nflexnode, 3 ) \ X ( mjtNum, flex_node, nflexnode, 3 ) \
X ( mjtNum, flex_node0, nflexnode, 3 ) \ X ( mjtNum, flex_node0, nflexnode, 3 ) \
X ( mjtNum, flexedge_length0, nflexedge, 1 ) \ X ( mjtNum, flexedge_length0, nflexedge, 1 ) \
X ( mjtNum, flexedge_invweight0, nflexedge, 1 ) \ X ( mjtNum, flexedge_invweight0, nflexedge, 1 ) \
XMJV( mjtNum, flex_radius, nflex, 1 ) \ X ( mjtNum, flex_radius, nflex, 1 ) \
X ( mjtNum, flex_stiffness, nflexelem, 21 ) \ X ( mjtNum, flex_stiffness, nflexelem, 21 ) \
X ( mjtNum, flex_bending, nflexedge, 16 ) \ X ( mjtNum, flex_bending, nflexedge, 16 ) \
X ( mjtNum, flex_damping, nflex, 1 ) \ X ( mjtNum, flex_damping, nflex, 1 ) \
@@ -373,23 +373,23 @@
X ( mjtByte, flex_edgeequality, nflex, 1 ) \ X ( mjtByte, flex_edgeequality, nflex, 1 ) \
X ( mjtByte, flex_rigid, nflex, 1 ) \ X ( mjtByte, flex_rigid, nflex, 1 ) \
X ( mjtByte, flexedge_rigid, nflexedge, 1 ) \ X ( mjtByte, flexedge_rigid, nflexedge, 1 ) \
XMJV( mjtByte, flex_centered, nflex, 1 ) \ X ( mjtByte, flex_centered, nflex, 1 ) \
XMJV( mjtByte, flex_flatskin, nflex, 1 ) \ X ( mjtByte, flex_flatskin, nflex, 1 ) \
XMJV( int, flex_bvhadr, nflex, 1 ) \ X ( int, flex_bvhadr, nflex, 1 ) \
XMJV( int, flex_bvhnum, nflex, 1 ) \ X ( int, flex_bvhnum, nflex, 1 ) \
XMJV( float, flex_rgba, nflex, 4 ) \ X ( float, flex_rgba, nflex, 4 ) \
XMJV( float, flex_texcoord, nflextexcoord, 2 ) \ X ( float, flex_texcoord, nflextexcoord, 2 ) \
X ( int, mesh_vertadr, nmesh, 1 ) \ X ( int, mesh_vertadr, nmesh, 1 ) \
X ( int, mesh_vertnum, nmesh, 1 ) \ X ( int, mesh_vertnum, nmesh, 1 ) \
X ( int, mesh_normaladr, nmesh, 1 ) \ X ( int, mesh_normaladr, nmesh, 1 ) \
X ( int, mesh_normalnum, nmesh, 1 ) \ X ( int, mesh_normalnum, nmesh, 1 ) \
XMJV( int, mesh_texcoordadr, nmesh, 1 ) \ X ( int, mesh_texcoordadr, nmesh, 1 ) \
X ( int, mesh_texcoordnum, nmesh, 1 ) \ X ( int, mesh_texcoordnum, nmesh, 1 ) \
X ( int, mesh_faceadr, nmesh, 1 ) \ X ( int, mesh_faceadr, nmesh, 1 ) \
X ( int, mesh_facenum, nmesh, 1 ) \ X ( int, mesh_facenum, nmesh, 1 ) \
XMJV( int, mesh_bvhadr, nmesh, 1 ) \ X ( int, mesh_bvhadr, nmesh, 1 ) \
XMJV( int, mesh_bvhnum, nmesh, 1 ) \ X ( int, mesh_bvhnum, nmesh, 1 ) \
XMJV( int, mesh_graphadr, nmesh, 1 ) \ X ( int, mesh_graphadr, nmesh, 1 ) \
X ( mjtNum, mesh_scale, nmesh, 3 ) \ X ( mjtNum, mesh_scale, nmesh, 3 ) \
X ( mjtNum, mesh_pos, nmesh, 3 ) \ X ( mjtNum, mesh_pos, nmesh, 3 ) \
X ( mjtNum, mesh_quat, nmesh, 4 ) \ X ( mjtNum, mesh_quat, nmesh, 4 ) \
@@ -400,7 +400,7 @@
XNV ( int, mesh_facenormal, nmeshface, 3 ) \ XNV ( int, mesh_facenormal, nmeshface, 3 ) \
XNV ( int, mesh_facetexcoord, nmeshface, 3 ) \ XNV ( int, mesh_facetexcoord, nmeshface, 3 ) \
XNV ( int, mesh_graph, nmeshgraph, 1 ) \ XNV ( int, mesh_graph, nmeshgraph, 1 ) \
XMJV( int, mesh_pathadr, nmesh, 1 ) \ X ( int, mesh_pathadr, nmesh, 1 ) \
XNV ( int, mesh_polynum, nmesh, 1 ) \ XNV ( int, mesh_polynum, nmesh, 1 ) \
XNV ( int, mesh_polyadr, nmesh, 1 ) \ XNV ( int, mesh_polyadr, nmesh, 1 ) \
XNV ( mjtNum, mesh_polynormal, nmeshpoly, 3 ) \ XNV ( mjtNum, mesh_polynormal, nmeshpoly, 3 ) \
@@ -410,51 +410,51 @@
XNV ( int, mesh_polymapadr, nmeshvert, 1 ) \ XNV ( int, mesh_polymapadr, nmeshvert, 1 ) \
XNV ( int, mesh_polymapnum, nmeshvert, 1 ) \ XNV ( int, mesh_polymapnum, nmeshvert, 1 ) \
XNV ( int, mesh_polymap, nmeshpolymap, 1 ) \ XNV ( int, mesh_polymap, nmeshpolymap, 1 ) \
XMJV( int, skin_matid, nskin, 1 ) \ X ( int, skin_matid, nskin, 1 ) \
XMJV( int, skin_group, nskin, 1 ) \ X ( int, skin_group, nskin, 1 ) \
XMJV( float, skin_rgba, nskin, 4 ) \ X ( float, skin_rgba, nskin, 4 ) \
XMJV( float, skin_inflate, nskin, 1 ) \ X ( float, skin_inflate, nskin, 1 ) \
XMJV( int, skin_vertadr, nskin, 1 ) \ X ( int, skin_vertadr, nskin, 1 ) \
XMJV( int, skin_vertnum, nskin, 1 ) \ X ( int, skin_vertnum, nskin, 1 ) \
XMJV( int, skin_texcoordadr, nskin, 1 ) \ X ( int, skin_texcoordadr, nskin, 1 ) \
XMJV( int, skin_faceadr, nskin, 1 ) \ X ( int, skin_faceadr, nskin, 1 ) \
XMJV( int, skin_facenum, nskin, 1 ) \ X ( int, skin_facenum, nskin, 1 ) \
XMJV( int, skin_boneadr, nskin, 1 ) \ X ( int, skin_boneadr, nskin, 1 ) \
XMJV( int, skin_bonenum, nskin, 1 ) \ X ( int, skin_bonenum, nskin, 1 ) \
XMJV( float, skin_vert, nskinvert, 3 ) \ X ( float, skin_vert, nskinvert, 3 ) \
X ( float, skin_texcoord, nskintexvert, 2 ) \ X ( float, skin_texcoord, nskintexvert, 2 ) \
XMJV( int, skin_face, nskinface, 3 ) \ X ( int, skin_face, nskinface, 3 ) \
XMJV( int, skin_bonevertadr, nskinbone, 1 ) \ X ( int, skin_bonevertadr, nskinbone, 1 ) \
XMJV( int, skin_bonevertnum, nskinbone, 1 ) \ X ( int, skin_bonevertnum, nskinbone, 1 ) \
XMJV( float, skin_bonebindpos, nskinbone, 3 ) \ X ( float, skin_bonebindpos, nskinbone, 3 ) \
XMJV( float, skin_bonebindquat, nskinbone, 4 ) \ X ( float, skin_bonebindquat, nskinbone, 4 ) \
XMJV( int, skin_bonebodyid, nskinbone, 1 ) \ X ( int, skin_bonebodyid, nskinbone, 1 ) \
XMJV( int, skin_bonevertid, nskinbonevert, 1 ) \ X ( int, skin_bonevertid, nskinbonevert, 1 ) \
XMJV( float, skin_bonevertweight, nskinbonevert, 1 ) \ X ( float, skin_bonevertweight, nskinbonevert, 1 ) \
XMJV( int, skin_pathadr, nskin, 1 ) \ X ( int, skin_pathadr, nskin, 1 ) \
X ( mjtNum, hfield_size, nhfield, 4 ) \ X ( mjtNum, hfield_size, nhfield, 4 ) \
X ( int, hfield_nrow, nhfield, 1 ) \ X ( int, hfield_nrow, nhfield, 1 ) \
X ( int, hfield_ncol, nhfield, 1 ) \ X ( int, hfield_ncol, nhfield, 1 ) \
X ( int, hfield_adr, nhfield, 1 ) \ X ( int, hfield_adr, nhfield, 1 ) \
XNV ( float, hfield_data, nhfielddata, 1 ) \ XNV ( float, hfield_data, nhfielddata, 1 ) \
XMJV( int, hfield_pathadr, nhfield, 1 ) \ X ( int, hfield_pathadr, nhfield, 1 ) \
X ( int, tex_type, ntex, 1 ) \ X ( int, tex_type, ntex, 1 ) \
X ( int, tex_height, ntex, 1 ) \ X ( int, tex_height, ntex, 1 ) \
X ( int, tex_width, ntex, 1 ) \ X ( int, tex_width, ntex, 1 ) \
X ( int, tex_nchannel, ntex, 1 ) \ X ( int, tex_nchannel, ntex, 1 ) \
X ( int, tex_adr, ntex, 1 ) \ X ( int, tex_adr, ntex, 1 ) \
XNV ( mjtByte, tex_data, ntexdata, 1 ) \ XNV ( mjtByte, tex_data, ntexdata, 1 ) \
XMJV( int, tex_pathadr, ntex, 1 ) \ X ( int, tex_pathadr, ntex, 1 ) \
XMJV( int, mat_texid, nmat, mjNTEXROLE ) \ X ( int, mat_texid, nmat, mjNTEXROLE ) \
XMJV( mjtByte, mat_texuniform, nmat, 1 ) \ X ( mjtByte, mat_texuniform, nmat, 1 ) \
XMJV( float, mat_texrepeat, nmat, 2 ) \ X ( float, mat_texrepeat, nmat, 2 ) \
XMJV( float, mat_emission, nmat, 1 ) \ X ( float, mat_emission, nmat, 1 ) \
XMJV( float, mat_specular, nmat, 1 ) \ X ( float, mat_specular, nmat, 1 ) \
XMJV( float, mat_shininess, nmat, 1 ) \ X ( float, mat_shininess, nmat, 1 ) \
XMJV( float, mat_reflectance, nmat, 1 ) \ X ( float, mat_reflectance, nmat, 1 ) \
XMJV( float, mat_metallic, nmat, 1 ) \ X ( float, mat_metallic, nmat, 1 ) \
XMJV( float, mat_roughness, nmat, 1 ) \ X ( float, mat_roughness, nmat, 1 ) \
XMJV( float, mat_rgba, nmat, 4 ) \ X ( float, mat_rgba, nmat, 4 ) \
X ( int, pair_dim, npair, 1 ) \ X ( int, pair_dim, npair, 1 ) \
X ( int, pair_geom1, npair, 1 ) \ X ( int, pair_geom1, npair, 1 ) \
X ( int, pair_geom2, npair, 1 ) \ X ( int, pair_geom2, npair, 1 ) \
@@ -466,74 +466,74 @@
X ( mjtNum, pair_gap, npair, 1 ) \ X ( mjtNum, pair_gap, npair, 1 ) \
X ( mjtNum, pair_friction, npair, 5 ) \ X ( mjtNum, pair_friction, npair, 5 ) \
X ( int, exclude_signature, nexclude, 1 ) \ X ( int, exclude_signature, nexclude, 1 ) \
XMJV( int, eq_type, neq, 1 ) \ X ( int, eq_type, neq, 1 ) \
XMJV( int, eq_obj1id, neq, 1 ) \ X ( int, eq_obj1id, neq, 1 ) \
XMJV( int, eq_obj2id, neq, 1 ) \ X ( int, eq_obj2id, neq, 1 ) \
XMJV( int, eq_objtype, neq, 1 ) \ X ( int, eq_objtype, neq, 1 ) \
X ( mjtByte, eq_active0, neq, 1 ) \ X ( mjtByte, eq_active0, neq, 1 ) \
X ( mjtNum, eq_solref, neq, mjNREF ) \ X ( mjtNum, eq_solref, neq, mjNREF ) \
X ( mjtNum, eq_solimp, neq, mjNIMP ) \ X ( mjtNum, eq_solimp, neq, mjNIMP ) \
XMJV( mjtNum, eq_data, neq, mjNEQDATA ) \ X ( mjtNum, eq_data, neq, mjNEQDATA ) \
X ( int, tendon_adr, ntendon, 1 ) \ X ( int, tendon_adr, ntendon, 1 ) \
XMJV( int, tendon_num, ntendon, 1 ) \ X ( int, tendon_num, ntendon, 1 ) \
XMJV( int, tendon_matid, ntendon, 1 ) \ X ( int, tendon_matid, ntendon, 1 ) \
XMJV( int, tendon_group, ntendon, 1 ) \ X ( int, tendon_group, ntendon, 1 ) \
XMJV( mjtByte, tendon_limited, ntendon, 1 ) \ X ( mjtByte, tendon_limited, ntendon, 1 ) \
XMJV( mjtByte, tendon_actfrclimited, ntendon, 1 ) \ X ( mjtByte, tendon_actfrclimited, ntendon, 1 ) \
XMJV( mjtNum, tendon_width, ntendon, 1 ) \ X ( mjtNum, tendon_width, ntendon, 1 ) \
X ( mjtNum, tendon_solref_lim, ntendon, mjNREF ) \ X ( mjtNum, tendon_solref_lim, ntendon, mjNREF ) \
X ( mjtNum, tendon_solimp_lim, ntendon, mjNIMP ) \ X ( mjtNum, tendon_solimp_lim, ntendon, mjNIMP ) \
X ( mjtNum, tendon_solref_fri, ntendon, mjNREF ) \ X ( mjtNum, tendon_solref_fri, ntendon, mjNREF ) \
X ( mjtNum, tendon_solimp_fri, ntendon, mjNIMP ) \ X ( mjtNum, tendon_solimp_fri, ntendon, mjNIMP ) \
XMJV( mjtNum, tendon_range, ntendon, 2 ) \ X ( mjtNum, tendon_range, ntendon, 2 ) \
XMJV( mjtNum, tendon_actfrcrange, ntendon, 2 ) \ X ( mjtNum, tendon_actfrcrange, ntendon, 2 ) \
X ( mjtNum, tendon_margin, ntendon, 1 ) \ X ( mjtNum, tendon_margin, ntendon, 1 ) \
XMJV( mjtNum, tendon_stiffness, ntendon, 1 ) \ X ( mjtNum, tendon_stiffness, ntendon, 1 ) \
XMJV( mjtNum, tendon_damping, ntendon, 1 ) \ X ( mjtNum, tendon_damping, ntendon, 1 ) \
X ( mjtNum, tendon_armature, ntendon, 1 ) \ X ( mjtNum, tendon_armature, ntendon, 1 ) \
XMJV( mjtNum, tendon_frictionloss, ntendon, 1 ) \ X ( mjtNum, tendon_frictionloss, ntendon, 1 ) \
XMJV( mjtNum, tendon_lengthspring, ntendon, 2 ) \ X ( mjtNum, tendon_lengthspring, ntendon, 2 ) \
X ( mjtNum, tendon_length0, ntendon, 1 ) \ X ( mjtNum, tendon_length0, ntendon, 1 ) \
X ( mjtNum, tendon_invweight0, ntendon, 1 ) \ X ( mjtNum, tendon_invweight0, ntendon, 1 ) \
X ( mjtNum, tendon_user, ntendon, MJ_M(nuser_tendon) ) \ X ( mjtNum, tendon_user, ntendon, MJ_M(nuser_tendon) ) \
XMJV( float, tendon_rgba, ntendon, 4 ) \ X ( float, tendon_rgba, ntendon, 4 ) \
X ( int, wrap_type, nwrap, 1 ) \ X ( int, wrap_type, nwrap, 1 ) \
X ( int, wrap_objid, nwrap, 1 ) \ X ( int, wrap_objid, nwrap, 1 ) \
X ( mjtNum, wrap_prm, nwrap, 1 ) \ X ( mjtNum, wrap_prm, nwrap, 1 ) \
XMJV( int, actuator_trntype, nu, 1 ) \ X ( int, actuator_trntype, nu, 1 ) \
XMJV( int, actuator_dyntype, nu, 1 ) \ X ( int, actuator_dyntype, nu, 1 ) \
X ( int, actuator_gaintype, nu, 1 ) \ X ( int, actuator_gaintype, nu, 1 ) \
X ( int, actuator_biastype, nu, 1 ) \ X ( int, actuator_biastype, nu, 1 ) \
XMJV( int, actuator_trnid, nu, 2 ) \ X ( int, actuator_trnid, nu, 2 ) \
XMJV( int, actuator_actadr, nu, 1 ) \ X ( int, actuator_actadr, nu, 1 ) \
XMJV( int, actuator_actnum, nu, 1 ) \ X ( int, actuator_actnum, nu, 1 ) \
XMJV( int, actuator_group, nu, 1 ) \ X ( int, actuator_group, nu, 1 ) \
XMJV( mjtByte, actuator_ctrllimited, nu, 1 ) \ X ( mjtByte, actuator_ctrllimited, nu, 1 ) \
X ( mjtByte, actuator_forcelimited, nu, 1 ) \ X ( mjtByte, actuator_forcelimited, nu, 1 ) \
XMJV( mjtByte, actuator_actlimited, nu, 1 ) \ X ( mjtByte, actuator_actlimited, nu, 1 ) \
X ( mjtNum, actuator_dynprm, nu, mjNDYN ) \ X ( mjtNum, actuator_dynprm, nu, mjNDYN ) \
X ( mjtNum, actuator_gainprm, nu, mjNGAIN ) \ X ( mjtNum, actuator_gainprm, nu, mjNGAIN ) \
X ( mjtNum, actuator_biasprm, nu, mjNBIAS ) \ X ( mjtNum, actuator_biasprm, nu, mjNBIAS ) \
X ( mjtByte, actuator_actearly, nu, 1 ) \ X ( mjtByte, actuator_actearly, nu, 1 ) \
XMJV( mjtNum, actuator_ctrlrange, nu, 2 ) \ X ( mjtNum, actuator_ctrlrange, nu, 2 ) \
X ( mjtNum, actuator_forcerange, nu, 2 ) \ X ( mjtNum, actuator_forcerange, nu, 2 ) \
XMJV( mjtNum, actuator_actrange, nu, 2 ) \ X ( mjtNum, actuator_actrange, nu, 2 ) \
X ( mjtNum, actuator_gear, nu, 6 ) \ X ( mjtNum, actuator_gear, nu, 6 ) \
XMJV( mjtNum, actuator_cranklength, nu, 1 ) \ X ( mjtNum, actuator_cranklength, nu, 1 ) \
X ( mjtNum, actuator_acc0, nu, 1 ) \ X ( mjtNum, actuator_acc0, nu, 1 ) \
X ( mjtNum, actuator_length0, nu, 1 ) \ X ( mjtNum, actuator_length0, nu, 1 ) \
X ( mjtNum, actuator_lengthrange, nu, 2 ) \ X ( mjtNum, actuator_lengthrange, nu, 2 ) \
X ( mjtNum, actuator_user, nu, MJ_M(nuser_actuator) ) \ X ( mjtNum, actuator_user, nu, MJ_M(nuser_actuator) ) \
X ( int, actuator_plugin, nu, 1 ) \ X ( int, actuator_plugin, nu, 1 ) \
XMJV( int, sensor_type, nsensor, 1 ) \ X ( int, sensor_type, nsensor, 1 ) \
X ( int, sensor_datatype, nsensor, 1 ) \ X ( int, sensor_datatype, nsensor, 1 ) \
X ( int, sensor_needstage, nsensor, 1 ) \ X ( int, sensor_needstage, nsensor, 1 ) \
X ( int, sensor_objtype, nsensor, 1 ) \ X ( int, sensor_objtype, nsensor, 1 ) \
XMJV( int, sensor_objid, nsensor, 1 ) \ X ( int, sensor_objid, nsensor, 1 ) \
X ( int, sensor_reftype, nsensor, 1 ) \ X ( int, sensor_reftype, nsensor, 1 ) \
X ( int, sensor_refid, nsensor, 1 ) \ X ( int, sensor_refid, nsensor, 1 ) \
X ( int, sensor_dim, nsensor, 1 ) \ X ( int, sensor_dim, nsensor, 1 ) \
XMJV( int, sensor_adr, nsensor, 1 ) \ X ( int, sensor_adr, nsensor, 1 ) \
X ( mjtNum, sensor_cutoff, nsensor, 1 ) \ X ( mjtNum, sensor_cutoff, nsensor, 1 ) \
X ( mjtNum, sensor_noise, nsensor, 1 ) \ X ( mjtNum, sensor_noise, nsensor, 1 ) \
X ( mjtNum, sensor_user, nsensor, MJ_M(nuser_sensor) ) \ X ( mjtNum, sensor_user, nsensor, MJ_M(nuser_sensor) ) \
@@ -561,12 +561,12 @@
X ( mjtNum, key_mpos, nkey, MJ_M(nmocap)*3 ) \ X ( mjtNum, key_mpos, nkey, MJ_M(nmocap)*3 ) \
X ( mjtNum, key_mquat, nkey, MJ_M(nmocap)*4 ) \ X ( mjtNum, key_mquat, nkey, MJ_M(nmocap)*4 ) \
X ( mjtNum, key_ctrl, nkey, MJ_M(nu) ) \ X ( mjtNum, key_ctrl, nkey, MJ_M(nu) ) \
XMJV( int, name_bodyadr, nbody, 1 ) \ X ( int, name_bodyadr, nbody, 1 ) \
XMJV( int, name_jntadr, njnt, 1 ) \ X ( int, name_jntadr, njnt, 1 ) \
XMJV( int, name_geomadr, ngeom, 1 ) \ X ( int, name_geomadr, ngeom, 1 ) \
XMJV( int, name_siteadr, nsite, 1 ) \ X ( int, name_siteadr, nsite, 1 ) \
XMJV( int, name_camadr, ncam, 1 ) \ X ( int, name_camadr, ncam, 1 ) \
XMJV( int, name_lightadr, nlight, 1 ) \ X ( int, name_lightadr, nlight, 1 ) \
X ( int, name_flexadr, nflex, 1 ) \ X ( int, name_flexadr, nflex, 1 ) \
X ( int, name_meshadr, nmesh, 1 ) \ X ( int, name_meshadr, nmesh, 1 ) \
X ( int, name_skinadr, nskin, 1 ) \ X ( int, name_skinadr, nskin, 1 ) \
@@ -575,18 +575,18 @@
X ( int, name_matadr, nmat, 1 ) \ X ( int, name_matadr, nmat, 1 ) \
X ( int, name_pairadr, npair, 1 ) \ X ( int, name_pairadr, npair, 1 ) \
X ( int, name_excludeadr, nexclude, 1 ) \ X ( int, name_excludeadr, nexclude, 1 ) \
XMJV( int, name_eqadr, neq, 1 ) \ X ( int, name_eqadr, neq, 1 ) \
XMJV( int, name_tendonadr, ntendon, 1 ) \ X ( int, name_tendonadr, ntendon, 1 ) \
XMJV( int, name_actuatoradr, nu, 1 ) \ X ( int, name_actuatoradr, nu, 1 ) \
X ( int, name_sensoradr, nsensor, 1 ) \ X ( int, name_sensoradr, nsensor, 1 ) \
X ( int, name_numericadr, nnumeric, 1 ) \ X ( int, name_numericadr, nnumeric, 1 ) \
X ( int, name_textadr, ntext, 1 ) \ X ( int, name_textadr, ntext, 1 ) \
X ( int, name_tupleadr, ntuple, 1 ) \ X ( int, name_tupleadr, ntuple, 1 ) \
X ( int, name_keyadr, nkey, 1 ) \ X ( int, name_keyadr, nkey, 1 ) \
X ( int, name_pluginadr, nplugin, 1 ) \ X ( int, name_pluginadr, nplugin, 1 ) \
XMJV( char, names, nnames, 1 ) \ X ( char, names, nnames, 1 ) \
X ( int, names_map, nnames_map, 1 ) \ X ( int, names_map, nnames_map, 1 ) \
XMJV( char, paths, npaths, 1 ) \ X ( char, paths, npaths, 1 ) \
//-------------------------------- mjData ---------------------------------------------------------- //-------------------------------- mjData ----------------------------------------------------------
@@ -596,60 +596,60 @@
// pointer fields of mjData // pointer fields of mjData
// XMJV means that the field is required to construct mjvScene // XNV means that the field is not required to construct mjvScene
// (by default we define XMJV to be the same as X) // (by default we define XNV to be the same as X)
#define MJDATA_POINTERS \ #define MJDATA_POINTERS \
X ( mjtNum, qpos, nq, 1 ) \ X ( mjtNum, qpos, nq, 1 ) \
X ( mjtNum, qvel, nv, 1 ) \ X ( mjtNum, qvel, nv, 1 ) \
XMJV( mjtNum, act, na, 1 ) \ X ( mjtNum, act, na, 1 ) \
X ( mjtNum, qacc_warmstart, nv, 1 ) \ X ( mjtNum, qacc_warmstart, nv, 1 ) \
X ( mjtNum, plugin_state, npluginstate, 1 ) \ X ( mjtNum, plugin_state, npluginstate, 1 ) \
XMJV( mjtNum, ctrl, nu, 1 ) \ X ( mjtNum, ctrl, nu, 1 ) \
X ( mjtNum, qfrc_applied, nv, 1 ) \ X ( mjtNum, qfrc_applied, nv, 1 ) \
XMJV( mjtNum, xfrc_applied, nbody, 6 ) \ X ( mjtNum, xfrc_applied, nbody, 6 ) \
XMJV( mjtByte, eq_active, neq, 1 ) \ X ( mjtByte, eq_active, neq, 1 ) \
X ( mjtNum, mocap_pos, nmocap, 3 ) \ X ( mjtNum, mocap_pos, nmocap, 3 ) \
X ( mjtNum, mocap_quat, nmocap, 4 ) \ X ( mjtNum, mocap_quat, nmocap, 4 ) \
X ( mjtNum, qacc, nv, 1 ) \ X ( mjtNum, qacc, nv, 1 ) \
X ( mjtNum, act_dot, na, 1 ) \ X ( mjtNum, act_dot, na, 1 ) \
X ( mjtNum, userdata, nuserdata, 1 ) \ X ( mjtNum, userdata, nuserdata, 1 ) \
XMJV( mjtNum, sensordata, nsensordata, 1 ) \ X ( mjtNum, sensordata, nsensordata, 1 ) \
X ( int, plugin, nplugin, 1 ) \ X ( int, plugin, nplugin, 1 ) \
X ( uintptr_t, plugin_data, nplugin, 1 ) \ X ( uintptr_t, plugin_data, nplugin, 1 ) \
XMJV( mjtNum, xpos, nbody, 3 ) \ X ( mjtNum, xpos, nbody, 3 ) \
XMJV( mjtNum, xquat, nbody, 4 ) \ X ( mjtNum, xquat, nbody, 4 ) \
XMJV( mjtNum, xmat, nbody, 9 ) \ X ( mjtNum, xmat, nbody, 9 ) \
XMJV( mjtNum, xipos, nbody, 3 ) \ X ( mjtNum, xipos, nbody, 3 ) \
XMJV( mjtNum, ximat, nbody, 9 ) \ X ( mjtNum, ximat, nbody, 9 ) \
XMJV( mjtNum, xanchor, njnt, 3 ) \ X ( mjtNum, xanchor, njnt, 3 ) \
XMJV( mjtNum, xaxis, njnt, 3 ) \ X ( mjtNum, xaxis, njnt, 3 ) \
XMJV( mjtNum, geom_xpos, ngeom, 3 ) \ X ( mjtNum, geom_xpos, ngeom, 3 ) \
XMJV( mjtNum, geom_xmat, ngeom, 9 ) \ X ( mjtNum, geom_xmat, ngeom, 9 ) \
XMJV( mjtNum, site_xpos, nsite, 3 ) \ X ( mjtNum, site_xpos, nsite, 3 ) \
XMJV( mjtNum, site_xmat, nsite, 9 ) \ X ( mjtNum, site_xmat, nsite, 9 ) \
XMJV( mjtNum, cam_xpos, ncam, 3 ) \ X ( mjtNum, cam_xpos, ncam, 3 ) \
XMJV( mjtNum, cam_xmat, ncam, 9 ) \ X ( mjtNum, cam_xmat, ncam, 9 ) \
XMJV( mjtNum, light_xpos, nlight, 3 ) \ X ( mjtNum, light_xpos, nlight, 3 ) \
XMJV( mjtNum, light_xdir, nlight, 3 ) \ X ( mjtNum, light_xdir, nlight, 3 ) \
XMJV( mjtNum, subtree_com, nbody, 3 ) \ X ( mjtNum, subtree_com, nbody, 3 ) \
X ( mjtNum, cdof, nv, 6 ) \ X ( mjtNum, cdof, nv, 6 ) \
X ( mjtNum, cinert, nbody, 10 ) \ X ( mjtNum, cinert, nbody, 10 ) \
XMJV( mjtNum, flexvert_xpos, nflexvert, 3 ) \ X ( mjtNum, flexvert_xpos, nflexvert, 3 ) \
X ( mjtNum, flexelem_aabb, nflexelem, 6 ) \ X ( mjtNum, flexelem_aabb, nflexelem, 6 ) \
X ( int, flexedge_J_rownnz, nflexedge, 1 ) \ X ( int, flexedge_J_rownnz, nflexedge, 1 ) \
X ( int, flexedge_J_rowadr, nflexedge, 1 ) \ X ( int, flexedge_J_rowadr, nflexedge, 1 ) \
X ( int, flexedge_J_colind, nflexedge, MJ_M(nv) ) \ X ( int, flexedge_J_colind, nflexedge, MJ_M(nv) ) \
X ( mjtNum, flexedge_J, nflexedge, MJ_M(nv) ) \ X ( mjtNum, flexedge_J, nflexedge, MJ_M(nv) ) \
X ( mjtNum, flexedge_length, nflexedge, 1 ) \ X ( mjtNum, flexedge_length, nflexedge, 1 ) \
XMJV( int, ten_wrapadr, ntendon, 1 ) \ X ( int, ten_wrapadr, ntendon, 1 ) \
XMJV( int, ten_wrapnum, ntendon, 1 ) \ X ( int, ten_wrapnum, ntendon, 1 ) \
X ( int, ten_J_rownnz, ntendon, 1 ) \ X ( int, ten_J_rownnz, ntendon, 1 ) \
X ( int, ten_J_rowadr, ntendon, 1 ) \ X ( int, ten_J_rowadr, ntendon, 1 ) \
X ( int, ten_J_colind, ntendon, MJ_M(nv) ) \ X ( int, ten_J_colind, ntendon, MJ_M(nv) ) \
XMJV( mjtNum, ten_length, ntendon, 1 ) \ X ( mjtNum, ten_length, ntendon, 1 ) \
X ( mjtNum, ten_J, ntendon, MJ_M(nv) ) \ X ( mjtNum, ten_J, ntendon, MJ_M(nv) ) \
XMJV( int, wrap_obj, nwrap, 2 ) \ X ( int, wrap_obj, nwrap, 2 ) \
XMJV( mjtNum, wrap_xpos, nwrap, 6 ) \ X ( mjtNum, wrap_xpos, nwrap, 6 ) \
X ( mjtNum, actuator_length, nu, 1 ) \ X ( mjtNum, actuator_length, nu, 1 ) \
X ( int, moment_rownnz, nu, 1 ) \ X ( int, moment_rownnz, nu, 1 ) \
X ( int, moment_rowadr, nu, 1 ) \ X ( int, moment_rowadr, nu, 1 ) \
@@ -660,8 +660,8 @@
XNV ( mjtNum, M, nC, 1 ) \ XNV ( mjtNum, M, nC, 1 ) \
XNV ( mjtNum, qLD, nC, 1 ) \ XNV ( mjtNum, qLD, nC, 1 ) \
X ( mjtNum, qLDiagInv, nv, 1 ) \ X ( mjtNum, qLDiagInv, nv, 1 ) \
XMJV( mjtNum, bvh_aabb_dyn, nbvhdynamic, 6 ) \ X ( mjtNum, bvh_aabb_dyn, nbvhdynamic, 6 ) \
XMJV( mjtByte, bvh_active, nbvh, 1 ) \ X ( mjtByte, bvh_active, nbvh, 1 ) \
X ( mjtNum, flexedge_velocity, nflexedge, 1 ) \ X ( mjtNum, flexedge_velocity, nflexedge, 1 ) \
X ( mjtNum, ten_velocity, ntendon, 1 ) \ X ( mjtNum, ten_velocity, ntendon, 1 ) \
X ( mjtNum, actuator_velocity, nu, 1 ) \ X ( mjtNum, actuator_velocity, nu, 1 ) \
@@ -834,12 +834,6 @@
X( mjtNum, solver_fwdinv, 2, 1 ) \ X( mjtNum, solver_fwdinv, 2, 1 ) \
X( mjtNum, energy, 2, 1 ) X( mjtNum, energy, 2, 1 )
// alias XMJV to be the same as X
// to obtain only X macros for fields that are relevant for mjvScene creation,
// redefine X to expand to nothing, and XMJV to do what's required
#define XMJV X
// alias XNV to be the same as X // alias XNV to be the same as X
// to obtain only X macros for fields that are relevant for mjvScene creation, // to obtain only X macros for fields that are relevant for mjvScene creation,
// redefine XNV to expand to nothing // redefine XNV to expand to nothing
-29
View File
@@ -625,20 +625,10 @@ MJAPI void mjv_alignToCamera(mjtNum res[3], const mjtNum vec[3], const mjtNum fo
MJAPI void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, MJAPI void mjv_moveCamera(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
const mjvScene* scn, mjvCamera* cam); const mjvScene* scn, mjvCamera* cam);
// Move camera with mouse given a scene state; action is mjtMouse.
MJAPI void mjv_moveCameraFromState(const mjvSceneState* scnstate, int action,
mjtNum reldx, mjtNum reldy,
const mjvScene* scn, mjvCamera* cam);
// Move perturb object with mouse; action is mjtMouse. // Move perturb object with mouse; action is mjtMouse.
MJAPI void mjv_movePerturb(const mjModel* m, const mjData* d, int action, mjtNum reldx, MJAPI void mjv_movePerturb(const mjModel* m, const mjData* d, int action, mjtNum reldx,
mjtNum reldy, const mjvScene* scn, mjvPerturb* pert); mjtNum reldy, const mjvScene* scn, mjvPerturb* pert);
// Move perturb object with mouse given a scene state; action is mjtMouse.
MJAPI void mjv_movePerturbFromState(const mjvSceneState* scnstate, int action,
mjtNum reldx, mjtNum reldy,
const mjvScene* scn, mjvPerturb* pert);
// Move model with mouse; action is mjtMouse. // Move model with mouse; action is mjtMouse.
MJAPI void mjv_moveModel(const mjModel* m, int action, mjtNum reldx, mjtNum reldy, MJAPI void mjv_moveModel(const mjModel* m, int action, mjtNum reldx, mjtNum reldy,
const mjtNum roomup[3], mjvScene* scn); const mjtNum roomup[3], mjvScene* scn);
@@ -695,28 +685,9 @@ MJAPI void mjv_freeScene(mjvScene* scn);
MJAPI void mjv_updateScene(const mjModel* m, mjData* d, const mjvOption* opt, MJAPI void mjv_updateScene(const mjModel* m, mjData* d, const mjvOption* opt,
const mjvPerturb* pert, mjvCamera* cam, int catmask, mjvScene* scn); const mjvPerturb* pert, mjvCamera* cam, int catmask, mjvScene* scn);
// Update entire scene from a scene state, return the number of new mjWARN_VGEOMFULL warnings.
MJAPI int mjv_updateSceneFromState(const mjvSceneState* scnstate, const mjvOption* opt,
const mjvPerturb* pert, mjvCamera* cam, int catmask,
mjvScene* scn);
// Copy mjModel, skip large arrays not required for abstract visualization. // Copy mjModel, skip large arrays not required for abstract visualization.
MJAPI void mjv_copyModel(mjModel* dest, const mjModel* src); MJAPI void mjv_copyModel(mjModel* dest, const mjModel* src);
// Set default scene state.
MJAPI void mjv_defaultSceneState(mjvSceneState* scnstate);
// Allocate resources and initialize a scene state object.
MJAPI void mjv_makeSceneState(const mjModel* m, const mjData* d,
mjvSceneState* scnstate, int maxgeom);
// Free scene state.
MJAPI void mjv_freeSceneState(mjvSceneState* scnstate);
// Update a scene state from model and data.
MJAPI void mjv_updateSceneState(const mjModel* m, mjData* d, const mjvOption* opt,
mjvSceneState* scnstate);
// Add geoms from selected categories. // Add geoms from selected categories.
MJAPI void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* opt, MJAPI void mjv_addGeoms(const mjModel* m, mjData* d, const mjvOption* opt,
const mjvPerturb* pert, int catmask, mjvScene* scn); const mjvPerturb* pert, int catmask, mjvScene* scn);
-208
View File
@@ -4011,44 +4011,6 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
), ),
doc='Move camera with mouse; action is mjtMouse.', doc='Move camera with mouse; action is mjtMouse.',
)), )),
('mjv_moveCameraFromState',
FunctionDecl(
name='mjv_moveCameraFromState',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
name='scnstate',
type=PointerType(
inner_type=ValueType(name='mjvSceneState', is_const=True),
),
),
FunctionParameterDecl(
name='action',
type=ValueType(name='int'),
),
FunctionParameterDecl(
name='reldx',
type=ValueType(name='mjtNum'),
),
FunctionParameterDecl(
name='reldy',
type=ValueType(name='mjtNum'),
),
FunctionParameterDecl(
name='scn',
type=PointerType(
inner_type=ValueType(name='mjvScene', is_const=True),
),
),
FunctionParameterDecl(
name='cam',
type=PointerType(
inner_type=ValueType(name='mjvCamera'),
),
),
),
doc='Move camera with mouse given a scene state; action is mjtMouse.',
)),
('mjv_movePerturb', ('mjv_movePerturb',
FunctionDecl( FunctionDecl(
name='mjv_movePerturb', name='mjv_movePerturb',
@@ -4093,44 +4055,6 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
), ),
doc='Move perturb object with mouse; action is mjtMouse.', doc='Move perturb object with mouse; action is mjtMouse.',
)), )),
('mjv_movePerturbFromState',
FunctionDecl(
name='mjv_movePerturbFromState',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
name='scnstate',
type=PointerType(
inner_type=ValueType(name='mjvSceneState', is_const=True),
),
),
FunctionParameterDecl(
name='action',
type=ValueType(name='int'),
),
FunctionParameterDecl(
name='reldx',
type=ValueType(name='mjtNum'),
),
FunctionParameterDecl(
name='reldy',
type=ValueType(name='mjtNum'),
),
FunctionParameterDecl(
name='scn',
type=PointerType(
inner_type=ValueType(name='mjvScene', is_const=True),
),
),
FunctionParameterDecl(
name='pert',
type=PointerType(
inner_type=ValueType(name='mjvPerturb'),
),
),
),
doc='Move perturb object with mouse given a scene state; action is mjtMouse.', # pylint: disable=line-too-long
)),
('mjv_moveModel', ('mjv_moveModel',
FunctionDecl( FunctionDecl(
name='mjv_moveModel', name='mjv_moveModel',
@@ -4560,48 +4484,6 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
), ),
doc='Update entire scene given model state.', doc='Update entire scene given model state.',
)), )),
('mjv_updateSceneFromState',
FunctionDecl(
name='mjv_updateSceneFromState',
return_type=ValueType(name='int'),
parameters=(
FunctionParameterDecl(
name='scnstate',
type=PointerType(
inner_type=ValueType(name='mjvSceneState', is_const=True),
),
),
FunctionParameterDecl(
name='opt',
type=PointerType(
inner_type=ValueType(name='mjvOption', is_const=True),
),
),
FunctionParameterDecl(
name='pert',
type=PointerType(
inner_type=ValueType(name='mjvPerturb', is_const=True),
),
),
FunctionParameterDecl(
name='cam',
type=PointerType(
inner_type=ValueType(name='mjvCamera'),
),
),
FunctionParameterDecl(
name='catmask',
type=ValueType(name='int'),
),
FunctionParameterDecl(
name='scn',
type=PointerType(
inner_type=ValueType(name='mjvScene'),
),
),
),
doc='Update entire scene from a scene state, return the number of new mjWARN_VGEOMFULL warnings.', # pylint: disable=line-too-long
)),
('mjv_copyModel', ('mjv_copyModel',
FunctionDecl( FunctionDecl(
name='mjv_copyModel', name='mjv_copyModel',
@@ -4622,96 +4504,6 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
), ),
doc='Copy mjModel, skip large arrays not required for abstract visualization.', # pylint: disable=line-too-long doc='Copy mjModel, skip large arrays not required for abstract visualization.', # pylint: disable=line-too-long
)), )),
('mjv_defaultSceneState',
FunctionDecl(
name='mjv_defaultSceneState',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
name='scnstate',
type=PointerType(
inner_type=ValueType(name='mjvSceneState'),
),
),
),
doc='Set default scene state.',
)),
('mjv_makeSceneState',
FunctionDecl(
name='mjv_makeSceneState',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
name='m',
type=PointerType(
inner_type=ValueType(name='mjModel', is_const=True),
),
),
FunctionParameterDecl(
name='d',
type=PointerType(
inner_type=ValueType(name='mjData', is_const=True),
),
),
FunctionParameterDecl(
name='scnstate',
type=PointerType(
inner_type=ValueType(name='mjvSceneState'),
),
),
FunctionParameterDecl(
name='maxgeom',
type=ValueType(name='int'),
),
),
doc='Allocate resources and initialize a scene state object.',
)),
('mjv_freeSceneState',
FunctionDecl(
name='mjv_freeSceneState',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
name='scnstate',
type=PointerType(
inner_type=ValueType(name='mjvSceneState'),
),
),
),
doc='Free scene state.',
)),
('mjv_updateSceneState',
FunctionDecl(
name='mjv_updateSceneState',
return_type=ValueType(name='void'),
parameters=(
FunctionParameterDecl(
name='m',
type=PointerType(
inner_type=ValueType(name='mjModel', is_const=True),
),
),
FunctionParameterDecl(
name='d',
type=PointerType(
inner_type=ValueType(name='mjData'),
),
),
FunctionParameterDecl(
name='opt',
type=PointerType(
inner_type=ValueType(name='mjvOption', is_const=True),
),
),
FunctionParameterDecl(
name='scnstate',
type=PointerType(
inner_type=ValueType(name='mjvSceneState'),
),
),
),
doc='Update a scene state from model and data.',
)),
('mjv_addGeoms', ('mjv_addGeoms',
FunctionDecl( FunctionDecl(
name='mjv_addGeoms', name='mjv_addGeoms',
File diff suppressed because it is too large Load Diff
+61 -70
View File
@@ -689,7 +689,7 @@ void UpdateWatch(mj::Simulate* sim, const mjModel* m, const mjData* d) {
// make physics section of UI // make physics section of UI
void MakePhysicsSection(mj::Simulate* sim) { void MakePhysicsSection(mj::Simulate* sim) {
mjOption* opt = sim->is_passive_ ? &sim->scnstate_.model.opt : &sim->m_->opt; mjOption* opt = sim->is_passive_ ? &sim->m_passive_->opt : &sim->m_->opt;
mjuiDef defPhysics[] = { mjuiDef defPhysics[] = {
{mjITEM_SECTION, "Physics", mjPRESERVE, nullptr, "AP"}, {mjITEM_SECTION, "Physics", mjPRESERVE, nullptr, "AP"},
{mjITEM_SELECT, "Integrator", 2, &(opt->integrator), "Euler\nRK4\nimplicit\nimplicitfast"}, {mjITEM_SELECT, "Integrator", 2, &(opt->integrator), "Euler\nRK4\nimplicit\nimplicitfast"},
@@ -873,8 +873,8 @@ void MakeRenderingSection(mj::Simulate* sim, const mjModel* m) {
// make visualization section of UI // make visualization section of UI
void MakeVisualizationSection(mj::Simulate* sim, const mjModel* m) { void MakeVisualizationSection(mj::Simulate* sim, const mjModel* m) {
mjStatistic* stat = sim->is_passive_ ? &sim->scnstate_.model.stat : &sim->m_->stat; mjStatistic* stat = sim->is_passive_ ? &sim->m_passive_->stat : &sim->m_->stat;
mjVisual* vis = sim->is_passive_ ? &sim->scnstate_.model.vis : &sim->m_->vis; mjVisual* vis = sim->is_passive_ ? &sim->m_passive_->vis : &sim->m_->vis;
mjuiDef defVisualization[] = { mjuiDef defVisualization[] = {
{mjITEM_SECTION, "Visualization", mjPRESERVE, nullptr, "AV"}, {mjITEM_SECTION, "Visualization", mjPRESERVE, nullptr, "AV"},
@@ -1503,7 +1503,7 @@ void UiEvent(mjuiState* state) {
// physics section // physics section
else if (it && it->sectionid==SECT_PHYSICS && sim->m_) { else if (it && it->sectionid==SECT_PHYSICS && sim->m_) {
mjOption* opt = sim->is_passive_ ? &sim->scnstate_.model.opt : &sim->m_->opt; mjOption* opt = sim->is_passive_ ? &sim->m_passive_->opt : &sim->m_->opt;
// update disable flags in mjOption // update disable flags in mjOption
opt->disableflags = 0; opt->disableflags = 0;
@@ -1765,15 +1765,14 @@ void UiEvent(mjuiState* state) {
return; return;
} }
// local pointers used below
mjModel* model = sim->is_passive_ ? sim->m_passive_ : sim->m_;
mjData* data = sim->is_passive_ ? sim->d_passive_ : sim->d_;
// 3D scroll // 3D scroll
if (state->type==mjEVENT_SCROLL && state->mouserect==3) { if (state->type==mjEVENT_SCROLL && state->mouserect==3 && model) {
// emulate vertical mouse motion = 2% of window height // emulate vertical mouse motion = 2% of window height
if (sim->m_ && !sim->is_passive_) { mjv_moveCamera(model, mjMOUSE_ZOOM, 0, -zoom_increment*state->sy, &sim->scn, &sim->cam);
mjv_moveCamera(sim->m_, mjMOUSE_ZOOM, 0, -zoom_increment*state->sy, &sim->scn, &sim->cam);
} else {
mjv_moveCameraFromState(
&sim->scnstate_, mjMOUSE_ZOOM, 0, -zoom_increment*state->sy, &sim->scn, &sim->cam);
}
return; return;
} }
@@ -1829,25 +1828,11 @@ void UiEvent(mjuiState* state) {
// move perturb or camera // move perturb or camera
mjrRect r = state->rect[3]; mjrRect r = state->rect[3];
if (sim->pert.active) { if (sim->pert.active) {
if (!sim->is_passive_) { mjv_movePerturb(model, data, action, state->dx / r.height, -state->dy / r.height,
mjv_movePerturb( &sim->scn, &sim->pert);
sim->m_, sim->d_, action, state->dx / r.height, -state->dy / r.height,
&sim->scn, &sim->pert);
} else {
mjv_movePerturbFromState(
&sim->scnstate_, action, state->dx / r.height, -state->dy / r.height,
&sim->scn, &sim->pert);
}
} else { } else {
if (!sim->is_passive_) { mjv_moveCamera(model, action, state->dx / r.height, -state->dy / r.height,
mjv_moveCamera( &sim->scn, &sim->cam);
sim->m_, action, state->dx / r.height, -state->dy / r.height,
&sim->scn, &sim->cam);
} else {
mjv_moveCameraFromState(
&sim->scnstate_, action, state->dx / r.height, -state->dy / r.height,
&sim->scn, &sim->cam);
}
} }
return; return;
} }
@@ -1881,10 +1866,11 @@ Simulate::Simulate(std::unique_ptr<PlatformUIAdapter> platform_ui,
platform_ui(std::move(platform_ui)), platform_ui(std::move(platform_ui)),
uistate(this->platform_ui->state()) { uistate(this->platform_ui->state()) {
mjv_defaultScene(&scn); mjv_defaultScene(&scn);
mjv_defaultSceneState(&scnstate_);
} }
// synchronize model and data
//------------------------- Synchronize render and physics threads ---------------------------------
// operations which require holding the mutex, prevents racing with physics thread // operations which require holding the mutex, prevents racing with physics thread
void Simulate::Sync() { void Simulate::Sync() {
MutexLock lock(this->mtx); MutexLock lock(this->mtx);
@@ -1947,10 +1933,10 @@ void Simulate::Sync() {
if (is_passive_) { if (is_passive_) {
// synchronize m_->opt with changes made via the UI // synchronize m_->opt with changes made via the UI
#define X(name) \ #define X(name) \
if (IsDifferent(scnstate_.model.opt.name, mjopt_prev_.name)) { \ if (IsDifferent(m_passive_->opt.name, mjopt_prev_.name)) { \
pending_.ui_update_physics = true; \ pending_.ui_update_physics = true; \
Copy(m_->opt.name, scnstate_.model.opt.name); \ Copy(m_->opt.name, m_passive_->opt.name); \
} }
X(timestep); X(timestep);
@@ -1984,9 +1970,9 @@ void Simulate::Sync() {
#undef X #undef X
// synchronize number of mjWARN_VGEOMFULL warnings // synchronize number of mjWARN_VGEOMFULL warnings
if (scnstate_.data.warning[mjWARN_VGEOMFULL].number > warn_vgeomfull_prev_) { if (d_passive_->warning[mjWARN_VGEOMFULL].number > warn_vgeomfull_prev_) {
d_->warning[mjWARN_VGEOMFULL].number += d_->warning[mjWARN_VGEOMFULL].number +=
scnstate_.data.warning[mjWARN_VGEOMFULL].number - warn_vgeomfull_prev_; d_passive_->warning[mjWARN_VGEOMFULL].number - warn_vgeomfull_prev_;
} }
} }
@@ -2135,25 +2121,19 @@ void Simulate::Sync() {
pending_.select = false; pending_.select = false;
} }
// update scene // update scene or sync data from user in passive mode
if (!is_passive_) { if (!is_passive_) {
mjv_updateScene(m_, d_, &this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn); mjv_updateScene(m_, d_, &this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn);
} else { } else {
mjv_updateSceneState(m_, d_, &this->opt, &scnstate_); mjv_copyModel(m_passive_, m_);
mjv_copyData(d_passive_, m_passive_, d_);
// append geoms from user_scn to scnstate_ scratch space // append geoms from user_scn to scratch space
if (user_scn) { if (user_scn) {
int ngeom = user_scn->ngeom; user_scn_geoms_.clear();
int maxgeom = scnstate_.scratch.maxgeom - scnstate_.scratch.ngeom; user_scn_geoms_.reserve(user_scn->ngeom);
if (ngeom > maxgeom) { for (int i = 0; i < user_scn->ngeom; ++i) {
mj_warning(d_, mjWARN_VGEOMFULL, scnstate_.scratch.maxgeom); user_scn_geoms_.push_back(user_scn->geoms[i]);
ngeom = maxgeom;
}
if (ngeom > 0) {
std::memcpy(scnstate_.scratch.geoms + scnstate_.scratch.ngeom,
user_scn->geoms,
sizeof(mjvGeom) * ngeom);
scnstate_.scratch.ngeom += ngeom;
} }
} }
@@ -2169,8 +2149,8 @@ void Simulate::Sync() {
Copy(user_scn_flags_prev_, user_scn->flags); Copy(user_scn_flags_prev_, user_scn->flags);
} }
mjopt_prev_ = scnstate_.model.opt; mjopt_prev_ = m_passive_->opt;
warn_vgeomfull_prev_ = scnstate_.data.warning[mjWARN_VGEOMFULL].number; warn_vgeomfull_prev_ = d_passive_->warning[mjWARN_VGEOMFULL].number;
} }
// update settings // update settings
@@ -2329,15 +2309,8 @@ void Simulate::LoadOnRenderThread() {
} }
} }
// re-create scene and context // re-create scene
mjv_makeScene(this->m_, &this->scn, kMaxGeom); mjv_makeScene(this->m_, &this->scn, kMaxGeom);
if (this->is_passive_) {
mjopt_prev_ = m_->opt;
opt_prev_ = opt;
cam_prev_ = cam;
warn_vgeomfull_prev_ = d_->warning[mjWARN_VGEOMFULL].number;
mjv_makeSceneState(this->m_, this->d_, &this->scnstate_, kMaxGeom);
}
this->platform_ui->RefreshMjrContext(this->m_, 50*(this->font+1)); this->platform_ui->RefreshMjrContext(this->m_, 50*(this->font+1));
UiModify(&this->ui0, &this->uistate, &this->platform_ui->mjr_context()); UiModify(&this->ui0, &this->uistate, &this->platform_ui->mjr_context());
@@ -2366,12 +2339,18 @@ void Simulate::LoadOnRenderThread() {
mju::strcpy_arr(this->previous_filename, this->filename); mju::strcpy_arr(this->previous_filename, this->filename);
} }
// update scene // update scene in managed mode, in passive mode copy data from user (update in RenderLoop)
if (!is_passive_) { if (!is_passive_) {
mjv_updateScene(this->m_, this->d_, mjv_updateScene(this->m_, this->d_, &this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn);
&this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn);
} else { } else {
mjv_updateSceneState(this->m_, this->d_, &this->opt, &this->scnstate_); mjopt_prev_ = m_->opt;
opt_prev_ = opt;
cam_prev_ = cam;
warn_vgeomfull_prev_ = d_->warning[mjWARN_VGEOMFULL].number;
// full copy on init
m_passive_ = mj_copyModel(nullptr, m_);
d_passive_ = mj_copyData(nullptr, m_passive_, d_);
} }
// set window title to model name // set window title to model name
@@ -2793,11 +2772,22 @@ void Simulate::RenderLoop() {
} }
// update scene, doing a full sync if in fully managed mode // update scene, doing a full sync if in fully managed mode
if (!this->is_passive_) { if (!is_passive_) {
Sync(); Sync();
} else { } else if (m_passive_ && d_passive_) {
scnstate_.data.warning[mjWARN_VGEOMFULL].number += mjv_updateSceneFromState( // the user has called Sync() in their code
&scnstate_, &this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn); mjv_updateScene(m_passive_, d_passive_,
&this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn);
// add user geoms to scene
int nusergeom = user_scn_geoms_.size();
int ngeom = std::min(nusergeom, this->scn.maxgeom - this->scn.ngeom);
if (ngeom < nusergeom) {
mj_warning(d_passive_, mjWARN_VGEOMFULL, this->scn.maxgeom);
}
std::memcpy(this->scn.geoms + this->scn.ngeom, user_scn_geoms_.data(),
ngeom * sizeof(mjvGeom));
this->scn.ngeom += ngeom;
} }
} // MutexLock (unblocks simulation thread) } // MutexLock (unblocks simulation thread)
@@ -2818,7 +2808,8 @@ void Simulate::RenderLoop() {
const MutexLock lock(this->mtx); const MutexLock lock(this->mtx);
mjv_freeScene(&this->scn); mjv_freeScene(&this->scn);
if (is_passive_) { if (is_passive_) {
mjv_freeSceneState(&scnstate_); mj_deleteData(d_passive_);
mj_deleteModel(m_passive_);
} }
this->exitrequest.store(2); this->exitrequest.store(2);
+6 -1
View File
@@ -130,7 +130,12 @@ class Simulate {
std::vector<mjtNum> ctrl_; std::vector<mjtNum> ctrl_;
std::vector<mjtNum> ctrl_prev_; std::vector<mjtNum> ctrl_prev_;
mjvSceneState scnstate_; // in passive mode the user owns m_ and d_, these "passive" instances are
// owned by Simulate, updated from the user by the Sync() method
mjModel* m_passive_;
mjData* d_passive_;
std::vector<mjvGeom> user_scn_geoms_;
mjOption mjopt_prev_; mjOption mjopt_prev_;
mjvOption opt_prev_; mjvOption opt_prev_;
mjvCamera cam_prev_; mjvCamera cam_prev_;
-2
View File
@@ -83,8 +83,6 @@ set(MUJOCO_ENGINE_SRCS
engine_vis_init.h engine_vis_init.h
engine_vis_interact.c engine_vis_interact.c
engine_vis_interact.h engine_vis_interact.h
engine_vis_state.c
engine_vis_state.h
engine_vis_visualize.c engine_vis_visualize.c
engine_vis_visualize.h engine_vis_visualize.h
) )
-409
View File
@@ -1,409 +0,0 @@
// Copyright 2023 DeepMind Technologies Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "engine/engine_vis_state.h"
#include <string.h>
#include <mujoco/mjdata.h>
#include <mujoco/mjexport.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mjvisualize.h>
#include <mujoco/mjxmacro.h>
#include "engine/engine_core_constraint.h"
#include "engine/engine_plugin.h"
#include "engine/engine_support.h"
#include "engine/engine_util_errmem.h"
#include "engine/engine_vis_init.h"
#include "engine/engine_vis_interact.h"
#include "engine/engine_vis_visualize.h"
#ifdef MEMORY_SANITIZER
#include <sanitizer/msan_interface.h>
#endif
// this source file needs to treat XMJV differently from other X macros
#undef XMJV
// round size up to multiples of 64-byte cache lines
static inline size_t roundUpToCacheLine(size_t n) {
return 64 * ((n / 64) + (n % 64 ? 1 : 0));
}
// set default scene
void mjv_defaultSceneState(mjvSceneState* scnstate) {
memset(scnstate, 0, sizeof(mjvSceneState));
mjv_defaultScene(&scnstate->scratch);
}
// allocate and init scene state
void mjv_makeSceneState(const mjModel* m, const mjData* d, mjvSceneState* scnstate, int maxgeom) {
mjv_freeScene(&scnstate->scratch);
mju_free(scnstate->buffer);
#ifdef MEMORY_SANITIZER
__msan_allocated_memory(scnstate, sizeof(mjvSceneState));
mjv_defaultScene(&scnstate->scratch);
#endif
scnstate->nbuffer = 0;
scnstate->maxgeom = maxgeom;
#define X(var)
#define XMJV(var) scnstate->model.var = m->var;
MJMODEL_INTS
#undef XMJV
#undef X
#define X(dtype, var, dim0, dim1)
#define XMJV(dtype, var, dim0, dim1) \
scnstate->nbuffer += roundUpToCacheLine(sizeof(dtype) * m->dim0 * dim1);
MJMODEL_POINTERS
#undef XMJV
#undef X
#define X(dtype, var, dim0, dim1)
#define XMJV(dtype, var, dim0, dim1) \
scnstate->nbuffer += roundUpToCacheLine(sizeof(dtype) * m->dim0 * dim1);
MJDATA_POINTERS
#undef XMJV
#undef X
// create an arena in the scnstate, to allow visualization code to use the stack.
// TODO: Consider allocating way less than narena, since stack allocations in
// visualization code are much smaller than the arena space required by the model,
// typically.
scnstate->nbuffer += roundUpToCacheLine(m->narena);
// buffer space required for contacts
int condimmax = mj_isPyramidal(m) ? 10 : 6;
scnstate->nbuffer += roundUpToCacheLine(sizeof(*d->contact) * maxgeom);
scnstate->nbuffer += roundUpToCacheLine(sizeof(*d->efc_force) * maxgeom * condimmax);
// buffer space required for islands
scnstate->nbuffer += roundUpToCacheLine(sizeof(*d->island_dofadr) * m->ntree);
scnstate->nbuffer += roundUpToCacheLine(sizeof(*d->dof_island) * m->nv);
scnstate->nbuffer += roundUpToCacheLine(sizeof(*d->efc_island) * maxgeom * condimmax);
scnstate->nbuffer += roundUpToCacheLine(sizeof(*d->tendon_efcadr) * m->ntendon);
scnstate->buffer = mju_malloc(scnstate->nbuffer);
char* ptr = scnstate->buffer;
#define X(dtype, var, dim0, dim1)
#define XMJV(dtype, var, dim0, dim1) \
scnstate->model.var = (dtype*)ptr; \
ptr += roundUpToCacheLine(sizeof(dtype) * m->dim0 * dim1);
MJMODEL_POINTERS
#undef XMJV
#undef X
#define X(dtype, var, dim0, dim1)
#define XMJV(dtype, var, dim0, dim1) \
scnstate->data.var = (dtype*)ptr; \
ptr += roundUpToCacheLine(sizeof(dtype) * m->dim0 * dim1);
MJDATA_POINTERS
#undef XMJV
#undef X
scnstate->model.narena = m->narena;
scnstate->data.arena = (void*)ptr;
ptr += roundUpToCacheLine(m->narena);
scnstate->data.contact = (mjContact*)ptr;
ptr += roundUpToCacheLine(sizeof(*scnstate->data.contact) * scnstate->maxgeom);
scnstate->data.efc_force = (mjtNum*)ptr;
ptr += roundUpToCacheLine(sizeof(*scnstate->data.efc_force) * scnstate->maxgeom * condimmax);
scnstate->data.island_dofadr = (int*)ptr;
ptr += roundUpToCacheLine(sizeof(*scnstate->data.island_dofadr) * scnstate->model.ntree);
scnstate->data.dof_island = (int*)ptr;
ptr += roundUpToCacheLine(sizeof(*scnstate->data.dof_island) * scnstate->model.nv);
scnstate->data.efc_island = (int*)ptr;
ptr += roundUpToCacheLine(sizeof(*scnstate->data.efc_island) * scnstate->maxgeom * condimmax);
scnstate->data.tendon_efcadr = (int*)ptr;
ptr += roundUpToCacheLine(sizeof(*scnstate->data.tendon_efcadr) * m->ntendon);
// should not occur
if (ptr - (char*)scnstate->buffer != scnstate->nbuffer) {
mjERROR("mjvSceneState buffer is not fully used");
}
mjv_makeScene(m, &scnstate->scratch, maxgeom);
}
// free scene state
void mjv_freeSceneState(mjvSceneState* scnstate) {
mjv_freeScene(&scnstate->scratch);
mju_free(scnstate->buffer);
mjv_defaultSceneState(scnstate);
}
// shallow copy scene state into model and data for use with mjv functions
void mjv_assignFromSceneState(const mjvSceneState* scnstate, mjModel* m, mjData* d) {
if (m) {
memset(m, 0, sizeof(mjModel));
#ifdef MEMORY_SANITIZER
// Tell msan to treat the entire buffer as uninitialized
__msan_allocated_memory(m, sizeof(mjModel));
#endif
#define X(var)
#define XMJV(var) m->var = scnstate->model.var;
MJMODEL_INTS
#undef XMJV
#undef X
m->opt = scnstate->model.opt;
m->vis = scnstate->model.vis;
m->stat = scnstate->model.stat;
m->narena = scnstate->model.narena;
#define X(dtype, var, dim0, dim1)
#define XMJV(dtype, var, dim0, dim1) m->var = scnstate->model.var;
MJMODEL_POINTERS
#undef XMJV
#undef X
}
if (d) {
memset(d, 0, sizeof(mjData));
#ifdef MEMORY_SANITIZER
// Tell msan to treat the entire buffer as uninitialized
__msan_allocated_memory(d, sizeof(mjData));
#endif
memcpy(d->warning, scnstate->data.warning, sizeof(d->warning));
d->threadpool = 0;
d->nefc = scnstate->data.nefc;
d->ncon = scnstate->data.ncon;
d->nisland = scnstate->data.nisland;
d->time = scnstate->data.time;
d->narena = scnstate->model.narena;
d->arena = scnstate->data.arena;
d->parena = 0;
d->pbase = 0;
d->pstack = 0;
#define X(dtype, var, dim0, dim1)
#define XMJV(dtype, var, dim0, dim1) d->var = scnstate->data.var;
MJDATA_POINTERS
#undef XMJV
#undef X
d->contact = scnstate->data.contact;
d->efc_force = scnstate->data.efc_force;
d->island_dofadr = scnstate->data.island_dofadr;
d->dof_island = scnstate->data.dof_island;
d->efc_island = scnstate->data.efc_island;
d->tendon_efcadr = scnstate->data.tendon_efcadr;
}
}
// update entire scene from a scene state, return the number of new mjWARN_VGEOMFULL warnings
int mjv_updateSceneFromState(const mjvSceneState* scnstate, const mjvOption* opt,
const mjvPerturb* pert, mjvCamera* cam, int catmask, mjvScene* scn) {
// shallow-copy scnstate pointers into mjModel and mjData
mjModel m;
mjData d;
mjv_assignFromSceneState(scnstate, &m, &d);
// save the number of mjWARN_VGEOMFULL warnings before the scene update
int warning_start = d.warning[mjWARN_VGEOMFULL].number;
// copy mjvGeoms added by plugins
int nplugingeom = scnstate->scratch.ngeom;
if (nplugingeom > scn->maxgeom) {
mj_warning(&d, mjWARN_VGEOMFULL, scn->maxgeom);
scn->ngeom = scn->maxgeom;
} else {
scn->ngeom = nplugingeom;
}
memcpy(scn->geoms, scnstate->scratch.geoms, sizeof(mjvGeom) * scn->ngeom);
// add all categories
mjv_addGeoms(&m, &d, opt, pert, catmask, scn);
// update camera
mjv_updateCamera(&m, &d, cam, scn);
// add lights
mjv_makeLights(&m, &d, scn);
// update flexes
if (opt->flags[mjVIS_FLEXVERT] || opt->flags[mjVIS_FLEXEDGE] ||
opt->flags[mjVIS_FLEXFACE] || opt->flags[mjVIS_FLEXSKIN]) {
mjv_updateActiveFlex(&m, &d, scn, opt);
}
// update skins
if (opt->flags[mjVIS_SKIN]) {
mjv_updateActiveSkin(&m, &d, scn, opt);
}
// return the number of new mjWARN_VGEOMFULL warnings generated
return d.warning[mjWARN_VGEOMFULL].number - warning_start;
}
// update a scene state from model and data
void mjv_updateSceneState(const mjModel* m, mjData* d, const mjvOption* opt,
mjvSceneState* scnstate) {
// Check that mjModel sizes haven't changed.
#define X(var)
#define XMJV(var) \
if (scnstate->model.var != m->var) { \
mjERROR("m->%s changed: %d vs %d", #var, scnstate->model.var, m->var); \
}
MJMODEL_INTS
#undef XMJV
#undef X
// Update plugin visualization cache.
scnstate->scratch.ngeom = 0;
if (m->nplugin) {
const int nslot = mjp_pluginCount();
// iterate over plugins, call visualize if defined
for (int i=0; i < m->nplugin; i++) {
const int slot = m->plugin[i];
const mjpPlugin* plugin = mjp_getPluginAtSlotUnsafe(slot, nslot);
if (!plugin) {
mjERROR("invalid plugin slot: %d", slot);
}
if (plugin->visualize) {
plugin->visualize(m, d, opt, &scnstate->scratch, i);
}
}
}
// Copy variable-sized arrays in mjModel.
#define X(dtype, var, dim0, dim1)
#define XMJV(dtype, var, dim0, dim1) \
memcpy(scnstate->model.var, m->var, sizeof(dtype) * m->dim0 * dim1);
MJMODEL_POINTERS
#undef XMJV
#undef X
scnstate->model.opt = m->opt;
scnstate->model.vis = m->vis;
scnstate->model.stat = m->stat;
// Copy mjData variables.
memcpy(scnstate->data.warning, d->warning, sizeof(d->warning));
scnstate->data.time = d->time;
// Copy variable-sized arrays in mjData.
#define X(dtype, var, dim0, dim1)
#define XMJV(dtype, var, dim0, dim1) \
memcpy(scnstate->data.var, d->var, sizeof(dtype) * m->dim0 * dim1);
MJDATA_POINTERS
#undef XMJV
#undef X
// Copy contacts.
{
if (d->ncon > scnstate->maxgeom) {
mj_warning(d, mjWARN_VGEOMFULL, scnstate->maxgeom);
scnstate->data.ncon = scnstate->maxgeom;
} else {
scnstate->data.ncon = d->ncon;
}
memcpy(scnstate->data.contact, d->contact, sizeof(*d->contact) * scnstate->data.ncon);
}
// Copy only the entries in efc_force and efc_island that correspond to contacts.
{
scnstate->data.nefc = 0;
for (int i = 0; i < scnstate->data.ncon; ++i) {
const mjContact* con = &d->contact[i];
scnstate->data.nefc += con->dim;
}
scnstate->data.nefc += scnstate->model.ntendon;
int efc_address = 0;
int ispyramid = mj_isPyramidal(m);
for (int i = 0; i < scnstate->data.ncon; ++i) {
mjContact* con = &scnstate->data.contact[i];
int dim = con->dim;
if (ispyramid && dim > 1){
dim = 2*(dim - 1);
}
for (int j = 0; j < dim; ++j) {
scnstate->data.efc_force[efc_address + j] = d->efc_force[con->efc_address + j];
if (d->nisland) {
scnstate->data.efc_island[efc_address + j] = d->efc_island[con->efc_address + j];
}
}
con->efc_address = efc_address;
efc_address += dim;
}
if (d->nisland) {
for (int i = 0; i < scnstate->model.ntendon; ++i) {
int efcadr = d->tendon_efcadr[i];
if (efcadr != -1) {
scnstate->data.efc_island[efcadr] = d->efc_island[efcadr];
}
}
}
}
// Copy island data.
scnstate->data.nisland = d->nisland;
if (d->nisland) {
memcpy(scnstate->data.island_dofadr, d->island_dofadr, sizeof(*d->island_dofadr) * d->nisland);
memcpy(scnstate->data.dof_island, d->dof_island, sizeof(*d->dof_island) * m->nv);
memcpy(scnstate->data.tendon_efcadr, d->tendon_efcadr, sizeof(*d->tendon_efcadr) * m->ntendon);
}
}
// move camera with mouse given a scene state; action is mjtMouse
void mjv_moveCameraFromState(const mjvSceneState* scnstate, int action,
mjtNum reldx, mjtNum reldy,
const mjvScene* scn, mjvCamera* cam) {
mjModel m;
mjv_assignFromSceneState(scnstate, &m, NULL);
mjv_moveCamera(&m, action, reldx, reldy, scn, cam);
}
// move perturb object with mouse given a scene state; action is mjtMouse
void mjv_movePerturbFromState(const mjvSceneState* scnstate, int action,
mjtNum reldx, mjtNum reldy,
const mjvScene* scn, mjvPerturb* pert) {
mjModel m;
mjData d;
mjv_assignFromSceneState(scnstate, &m, &d);
mjv_movePerturb(&m, &d, action, reldx, reldy, scn, pert);
}
-63
View File
@@ -1,63 +0,0 @@
// Copyright 2023 DeepMind Technologies Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef MUJOCO_SRC_ENGINE_ENGINE_VIS_STATE_H_
#define MUJOCO_SRC_ENGINE_ENGINE_VIS_STATE_H_
#include <mujoco/mjdata.h>
#include <mujoco/mjexport.h>
#include <mujoco/mjmodel.h>
#include <mujoco/mjtnum.h>
#include <mujoco/mjvisualize.h>
#ifdef __cplusplus
extern "C" {
#endif
// set default scene state
MJAPI void mjv_defaultSceneState(mjvSceneState* scnstate);
// allocate and init scene state
MJAPI void mjv_makeSceneState(const mjModel* m, const mjData* d,
mjvSceneState* scnstate, int maxgeom);
// free scene state
MJAPI void mjv_freeSceneState(mjvSceneState* scnstate);
// shallow copy scene state into model and data for use with mjv functions
void mjv_assignFromSceneState(const mjvSceneState* scnstate, mjModel* m, mjData* d);
// update entire scene from a scene state, return the number of new mjWARN_VGEOMFULL warnings
MJAPI int mjv_updateSceneFromState(const mjvSceneState* scnstate, const mjvOption* opt,
const mjvPerturb* pert, mjvCamera* cam, int catmask,
mjvScene* scn);
// update a scene state from model and data
MJAPI void mjv_updateSceneState(const mjModel* m, mjData* d, const mjvOption* opt,
mjvSceneState* scnstate);
// move camera with mouse given a scene state; action is mjtMouse
MJAPI void mjv_moveCameraFromState(const mjvSceneState* scnstate, int action,
mjtNum reldx, mjtNum reldy,
const mjvScene* scn, mjvCamera* cam);
// move perturb object with mouse given a scene state; action is mjtMouse
MJAPI void mjv_movePerturbFromState(const mjvSceneState* scnstate, int action,
mjtNum reldx, mjtNum reldy,
const mjvScene* scn, mjvPerturb* pert);
#ifdef __cplusplus
}
#endif
#endif // MUJOCO_SRC_ENGINE_ENGINE_VIS_STATE_H_
-7
View File
@@ -67,11 +67,4 @@ mujoco_test(engine_util_solve_test)
mujoco_test(engine_util_spatial_test) mujoco_test(engine_util_spatial_test)
mujoco_test(
engine_vis_state_test
PROPERTIES
ENVIRONMENT
"MUJOCO_PLUGIN_DIR=$<TARGET_FILE_DIR:elasticity>"
)
mujoco_test(engine_vis_visualize_test) mujoco_test(engine_vis_visualize_test)
-123
View File
@@ -1,123 +0,0 @@
// Copyright 2023 DeepMind Technologies Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <cstring>
#include <string>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <mujoco/mjvisualize.h>
#include <mujoco/mujoco.h>
#include "test/fixture.h"
namespace mujoco {
namespace {
using ::testing::NotNull;
using MjvSceneStateTest = MujocoTest;
constexpr int kMaxGeom = 10000;
static const char* const kHammockPath =
"engine/testdata/hammock/hammock.xml";
static const char* const kTendonPath =
"engine/testdata/island/tendon_wrap.xml";
static const char* const kFrustumPath =
"engine/testdata/vis_visualize/frustum.xml";
static const char* const kFlex = "testdata/flex.xml";
static const char* const kModelPath = "testdata/model.xml";
#define EXPECT_ZERO(exp) EXPECT_EQ(0, exp);
TEST_F(MjvSceneStateTest, CanUpdateFromState) {
for (const char* path :
{kHammockPath, kTendonPath, kModelPath, kFrustumPath, kFlex}) {
const std::string xml_path = GetTestDataFilePath(path);
mjModel* model = mj_loadXML(xml_path.c_str(), nullptr, 0, 0);
ASSERT_THAT(model, NotNull()) << "Failed to load model from " << path;
mjData* data = mj_makeData(model);
while (data->time < 2) {
mj_step(model, data);
}
mjvScene scn1;
mjv_defaultScene(&scn1);
mjv_makeScene(model, &scn1, kMaxGeom);
mjvOption opt;
mjv_defaultOption(&opt);
mjvPerturb pert;
mjv_defaultPerturb(&pert);
mjvCamera cam;
mjv_defaultFreeCamera(model, &cam);
// Enable all flags to exercise all code paths
for (int i = 0; i < mjNVISFLAG; ++i) {
opt.flags[i] = 1;
}
mjv_updateScene(model, data, &opt, &pert, &cam, mjCAT_ALL, &scn1);
EXPECT_GT(scn1.ngeom, 0);
if (model->nskin) EXPECT_GT(scn1.nskin, 0);
EXPECT_GT(scn1.nlight, 0);
mjvSceneState scnstate;
mjv_defaultSceneState(&scnstate);
mjv_makeSceneState(model, data, &scnstate, kMaxGeom);
mjv_updateSceneState(model, data, &opt, &scnstate);
mjvScene scn2;
mjv_defaultScene(&scn2);
mjv_makeScene(model, &scn2, kMaxGeom);
mjv_updateSceneFromState(&scnstate, &opt, &pert, &cam, mjCAT_ALL, &scn2);
EXPECT_EQ(scn1.ngeom, scn2.ngeom);
for (int i = 0; i < scn1.ngeom; ++i) {
EXPECT_ZERO(std::memcmp(&scn1.geoms[i], &scn2.geoms[i], sizeof(mjvGeom)));
}
// NB: scn->geomorder is a scratch space for use by mjr_render, so we don't
// need to compare them here.
EXPECT_LE(scn1.nskin, scn2.nskin);
EXPECT_ZERO(std::memcmp(scn1.skinfacenum, scn2.skinfacenum,
sizeof(*scn2.skinfacenum) * scn2.nskin));
EXPECT_ZERO(std::memcmp(scn1.skinvertadr, scn2.skinvertadr,
sizeof(*scn2.skinvertadr) * scn2.nskin));
EXPECT_ZERO(std::memcmp(scn1.skinvertnum, scn2.skinvertnum,
sizeof(*scn2.skinvertnum) * scn2.nskin));
EXPECT_ZERO(std::memcmp(scn1.skinvert, scn2.skinvert,
sizeof(*scn2.skinvert) * scn2.nskin));
EXPECT_ZERO(std::memcmp(scn1.skinnormal, scn2.skinnormal,
sizeof(*scn2.skinnormal) * scn2.nskin));
auto scn1_cmp_begin = reinterpret_cast<char*>(&scn1.nlight);
auto scn2_cmp_begin = reinterpret_cast<char*>(&scn2.nlight);
auto cmp_bytes =
sizeof(mjvScene) - (scn2_cmp_begin - reinterpret_cast<char*>(&scn2));
EXPECT_ZERO(std::memcmp(scn1_cmp_begin, scn2_cmp_begin, cmp_bytes));
mjv_freeScene(&scn1);
mjv_freeScene(&scn2);
mjv_freeSceneState(&scnstate);
mj_deleteData(data);
mj_deleteModel(model);
}
}
} // namespace
} // namespace mujoco
-285
View File
@@ -6276,270 +6276,6 @@ public unsafe struct mjvFigure_ {
public fixed int yaxispixel[2]; public fixed int yaxispixel[2];
public fixed float xaxisdata[2]; public fixed float xaxisdata[2];
public fixed float yaxisdata[2]; public fixed float yaxisdata[2];
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct model {
public int nv;
public int nu;
public int na;
public int nbody;
public int nbvh;
public int nbvhstatic;
public int njnt;
public int ngeom;
public int nsite;
public int ncam;
public int nlight;
public int nmesh;
public int nskin;
public int nflex;
public int nflexvert;
public int nflextexcoord;
public int nskinvert;
public int nskinface;
public int nskinbone;
public int nskinbonevert;
public int nmat;
public int neq;
public int ntendon;
public int ntree;
public int nwrap;
public int nsensor;
public int nnames;
public int npaths;
public int nsensordata;
public int narena;
public mjOption_ opt;
public mjVisual_ vis;
public mjStatistic_ stat;
public int* body_parentid;
public int* body_rootid;
public int* body_weldid;
public int* body_mocapid;
public int* body_jntnum;
public int* body_jntadr;
public int* body_dofnum;
public int* body_dofadr;
public int* body_geomnum;
public int* body_geomadr;
public double* body_iquat;
public double* body_mass;
public double* body_inertia;
public int* body_bvhadr;
public int* body_bvhnum;
public int* bvh_depth;
public int* bvh_child;
public int* bvh_nodeid;
public double* bvh_aabb;
public int* jnt_type;
public int* jnt_bodyid;
public int* jnt_group;
public int* geom_type;
public int* geom_bodyid;
public int* geom_contype;
public int* geom_conaffinity;
public int* geom_dataid;
public int* geom_matid;
public int* geom_group;
public double* geom_size;
public double* geom_aabb;
public double* geom_rbound;
public float* geom_rgba;
public int* site_type;
public int* site_bodyid;
public int* site_matid;
public int* site_group;
public double* site_size;
public float* site_rgba;
public int* cam_orthographic;
public double* cam_fovy;
public double* cam_ipd;
public int* cam_resolution;
public float* cam_sensorsize;
public float* cam_intrinsic;
public byte* light_directional;
public byte* light_castshadow;
public float* light_bulbradius;
public float* light_intensity;
public float* light_range;
public byte* light_active;
public float* light_attenuation;
public float* light_cutoff;
public float* light_exponent;
public float* light_ambient;
public float* light_diffuse;
public float* light_specular;
public byte* flex_flatskin;
public int* flex_dim;
public int* flex_matid;
public int* flex_group;
public int* flex_interp;
public int* flex_nodeadr;
public int* flex_nodenum;
public int* flex_nodebodyid;
public int* flex_vertadr;
public int* flex_vertnum;
public int* flex_elem;
public int* flex_elemtexcoord;
public int* flex_elemlayer;
public int* flex_elemadr;
public int* flex_elemnum;
public int* flex_elemdataadr;
public int* flex_shell;
public int* flex_shellnum;
public int* flex_shelldataadr;
public int* flex_texcoordadr;
public int* flex_bvhadr;
public int* flex_bvhnum;
public byte* flex_centered;
public double* flex_node;
public double* flex_radius;
public float* flex_rgba;
public float* flex_texcoord;
public int* hfield_pathadr;
public int* mesh_bvhadr;
public int* mesh_bvhnum;
public int* mesh_texcoordadr;
public int* mesh_graphadr;
public int* mesh_pathadr;
public int* skin_matid;
public int* skin_group;
public float* skin_rgba;
public float* skin_inflate;
public int* skin_vertadr;
public int* skin_vertnum;
public int* skin_texcoordadr;
public int* skin_faceadr;
public int* skin_facenum;
public int* skin_boneadr;
public int* skin_bonenum;
public float* skin_vert;
public int* skin_face;
public int* skin_bonevertadr;
public int* skin_bonevertnum;
public float* skin_bonebindpos;
public float* skin_bonebindquat;
public int* skin_bonebodyid;
public int* skin_bonevertid;
public float* skin_bonevertweight;
public int* skin_pathadr;
public int* tex_pathadr;
public int* mat_texid;
public byte* mat_texuniform;
public float* mat_texrepeat;
public float* mat_emission;
public float* mat_specular;
public float* mat_shininess;
public float* mat_reflectance;
public float* mat_metallic;
public float* mat_roughness;
public float* mat_rgba;
public int* eq_type;
public int* eq_obj1id;
public int* eq_obj2id;
public int* eq_objtype;
public double* eq_data;
public int* tendon_num;
public int* tendon_matid;
public int* tendon_group;
public byte* tendon_limited;
public byte* tendon_actfrclimited;
public double* tendon_width;
public double* tendon_range;
public double* tendon_actfrcrange;
public double* tendon_stiffness;
public double* tendon_damping;
public double* tendon_frictionloss;
public double* tendon_lengthspring;
public float* tendon_rgba;
public int* actuator_trntype;
public int* actuator_dyntype;
public int* actuator_trnid;
public int* actuator_actadr;
public int* actuator_actnum;
public int* actuator_group;
public byte* actuator_ctrllimited;
public byte* actuator_actlimited;
public double* actuator_ctrlrange;
public double* actuator_actrange;
public double* actuator_cranklength;
public int* sensor_type;
public int* sensor_objid;
public int* sensor_adr;
public int* name_bodyadr;
public int* name_jntadr;
public int* name_geomadr;
public int* name_siteadr;
public int* name_camadr;
public int* name_lightadr;
public int* name_eqadr;
public int* name_tendonadr;
public int* name_actuatoradr;
public char* names;
public char* paths;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct data {
public mjWarningStat_ warning0;
public mjWarningStat_ warning1;
public mjWarningStat_ warning2;
public mjWarningStat_ warning3;
public mjWarningStat_ warning4;
public mjWarningStat_ warning5;
public mjWarningStat_ warning6;
public mjWarningStat_ warning7;
public int nefc;
public int ncon;
public int nisland;
public double time;
public double* act;
public double* ctrl;
public double* xfrc_applied;
public byte* eq_active;
public double* sensordata;
public double* xpos;
public double* xquat;
public double* xmat;
public double* xipos;
public double* ximat;
public double* xanchor;
public double* xaxis;
public double* geom_xpos;
public double* geom_xmat;
public double* site_xpos;
public double* site_xmat;
public double* cam_xpos;
public double* cam_xmat;
public double* light_xpos;
public double* light_xdir;
public double* subtree_com;
public int* ten_wrapadr;
public int* ten_wrapnum;
public int* wrap_obj;
public double* ten_length;
public double* wrap_xpos;
public double* bvh_aabb_dyn;
public byte* bvh_active;
public int* island_dofadr;
public int* dof_island;
public int* efc_island;
public int* tendon_efcadr;
public double* flexvert_xpos;
public mjContact_* contact;
public double* efc_force;
public void* arena;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct mjvSceneState_ {
public int nbuffer;
public void* buffer;
public int maxgeom;
public mjvScene_ scratch;
public model model;
public data data;
}public struct mjuiItem_ {}public struct mjfItemEnable {} }public struct mjuiItem_ {}public struct mjfItemEnable {}
// ----------------------------Function declarations---------------------------- // ----------------------------Function declarations----------------------------
@@ -6979,15 +6715,9 @@ public static unsafe extern void mjv_alignToCamera(double* res, double* vec, dou
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] [DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mjv_moveCamera(mjModel_* m, int action, double reldx, double reldy, mjvScene_* scn, mjvCamera_* cam); public static unsafe extern void mjv_moveCamera(mjModel_* m, int action, double reldx, double reldy, mjvScene_* scn, mjvCamera_* cam);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mjv_moveCameraFromState(mjvSceneState_* scnstate, int action, double reldx, double reldy, mjvScene_* scn, mjvCamera_* cam);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] [DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mjv_movePerturb(mjModel_* m, mjData_* d, int action, double reldx, double reldy, mjvScene_* scn, mjvPerturb_* pert); public static unsafe extern void mjv_movePerturb(mjModel_* m, mjData_* d, int action, double reldx, double reldy, mjvScene_* scn, mjvPerturb_* pert);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mjv_movePerturbFromState(mjvSceneState_* scnstate, int action, double reldx, double reldy, mjvScene_* scn, mjvPerturb_* pert);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] [DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mjv_moveModel(mjModel_* m, int action, double reldx, double reldy, double* roomup, mjvScene_* scn); public static unsafe extern void mjv_moveModel(mjModel_* m, int action, double reldx, double reldy, double* roomup, mjvScene_* scn);
@@ -7030,24 +6760,9 @@ public static unsafe extern void mjv_freeScene(mjvScene_* scn);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] [DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mjv_updateScene(mjModel_* m, mjData_* d, mjvOption_* opt, mjvPerturb_* pert, mjvCamera_* cam, int catmask, mjvScene_* scn); public static unsafe extern void mjv_updateScene(mjModel_* m, mjData_* d, mjvOption_* opt, mjvPerturb_* pert, mjvCamera_* cam, int catmask, mjvScene_* scn);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern int mjv_updateSceneFromState(mjvSceneState_* scnstate, mjvOption_* opt, mjvPerturb_* pert, mjvCamera_* cam, int catmask, mjvScene_* scn);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] [DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mjv_copyModel(mjModel_* dest, mjModel_* src); public static unsafe extern void mjv_copyModel(mjModel_* dest, mjModel_* src);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mjv_defaultSceneState(mjvSceneState_* scnstate);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mjv_makeSceneState(mjModel_* m, mjData_* d, mjvSceneState_* scnstate, int maxgeom);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mjv_freeSceneState(mjvSceneState_* scnstate);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mjv_updateSceneState(mjModel_* m, mjData_* d, mjvOption_* opt, mjvSceneState_* scnstate);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)] [DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mjv_addGeoms(mjModel_* m, mjData_* d, mjvOption_* opt, mjvPerturb_* pert, int catmask, mjvScene_* scn); public static unsafe extern void mjv_addGeoms(mjModel_* m, mjData_* d, mjvOption_* opt, mjvPerturb_* pert, int catmask, mjvScene_* scn);