Migrate mjModel size fields from int to mjtSize.

This change updates all size-related members within the `mjModel` struct from `int` to `mjtSize`. This allows MuJoCo to handle models with a larger number of elements. Corresponding changes were made to macros, function signatures, and I/O routines to accommodate the new `mjtSize` type.

PiperOrigin-RevId: 860144595
Change-Id: I701c6d607715d240766b6210a9773cd9e4258c59
This commit is contained in:
Yuval Tassa
2026-01-23 09:40:42 -08:00
committed by Copybara-Service
parent 4a64017a5f
commit 30b903b6c0
24 changed files with 832 additions and 802 deletions
+4
View File
@@ -60,6 +60,10 @@ General
CMake utility project. CMake utility project.
- ``USD_DIR`` is no longer used by the MuJoCo CMake project, instead use ``pxr_DIR`` if you have a pre-built USD library. - ``USD_DIR`` is no longer used by the MuJoCo CMake project, instead use ``pxr_DIR`` if you have a pre-built USD library.
- Users no longer have to set ``PXR_PLUGINPATH_NAME`` environment variable, MuJoCo should load USD plugins automatically. - Users no longer have to set ``PXR_PLUGINPATH_NAME`` environment variable, MuJoCo should load USD plugins automatically.
- Non-breaking ABI changes:
- Allcating sizes in :ref:`mjModel` now use 64-bit rather than 32-bit integers to accommodate larger
scenes.
MJX MJX
^^^ ^^^
+87 -86
View File
@@ -1006,95 +1006,96 @@ struct mjModel_ {
// ------------------------------- sizes // ------------------------------- sizes
// sizes needed at mjModel construction // sizes needed at mjModel construction
int nq; // number of generalized coordinates = dim(qpos) mjtSize nq; // number of generalized coordinates = dim(qpos)
int nv; // number of degrees of freedom = dim(qvel) mjtSize nv; // number of degrees of freedom = dim(qvel)
int nu; // number of actuators/controls = dim(ctrl) mjtSize nu; // number of actuators/controls = dim(ctrl)
int na; // number of activation states = dim(act) mjtSize na; // number of activation states = dim(act)
int nbody; // number of bodies mjtSize nbody; // number of bodies
int nbvh; // number of total bounding volumes in all bodies mjtSize nbvh; // number of total bounding volumes in all bodies
int nbvhstatic; // number of static bounding volumes (aabb stored in mjModel) mjtSize nbvhstatic; // number of static bounding volumes (aabb stored in mjModel)
int nbvhdynamic; // number of dynamic bounding volumes (aabb stored in mjData) mjtSize nbvhdynamic; // number of dynamic bounding volumes (aabb stored in mjData)
int noct; // number of total octree cells in all meshes mjtSize noct; // number of total octree cells in all meshes
int njnt; // number of joints mjtSize njnt; // number of joints
int ntree; // number of kinematic trees under world body mjtSize ntree; // number of kinematic trees under world body
int nM; // number of non-zeros in sparse inertia matrix mjtSize nM; // number of non-zeros in sparse inertia matrix
int nB; // number of non-zeros in sparse body-dof matrix mjtSize nB; // number of non-zeros in sparse body-dof matrix
int nC; // number of non-zeros in sparse reduced dof-dof matrix mjtSize nC; // number of non-zeros in sparse reduced dof-dof matrix
int nD; // number of non-zeros in sparse dof-dof matrix mjtSize nD; // number of non-zeros in sparse dof-dof matrix
int ngeom; // number of geoms mjtSize ngeom; // number of geoms
int nsite; // number of sites mjtSize nsite; // number of sites
int ncam; // number of cameras mjtSize ncam; // number of cameras
int nlight; // number of lights mjtSize nlight; // number of lights
int nflex; // number of flexes mjtSize nflex; // number of flexes
int nflexnode; // number of dofs in all flexes mjtSize nflexnode; // number of dofs in all flexes
int nflexvert; // number of vertices in all flexes mjtSize nflexvert; // number of vertices in all flexes
int nflexedge; // number of edges in all flexes mjtSize nflexedge; // number of edges in all flexes
int nflexelem; // number of elements in all flexes mjtSize nflexelem; // number of elements in all flexes
int nflexelemdata; // number of element vertex ids in all flexes mjtSize nflexelemdata; // number of element vertex ids in all flexes
int nflexelemedge; // number of element edge ids in all flexes mjtSize nflexelemedge; // number of element edge ids in all flexes
int nflexshelldata; // number of shell fragment vertex ids in all flexes mjtSize nflexshelldata; // number of shell fragment vertex ids in all flexes
int nflexevpair; // number of element-vertex pairs in all flexes mjtSize nflexevpair; // number of element-vertex pairs in all flexes
int nflextexcoord; // number of vertices with texture coordinates mjtSize nflextexcoord; // number of vertices with texture coordinates
int nJfe; // number of non-zeros in sparse flexedge Jacobian matrix mjtSize nJfe; // number of non-zeros in sparse flexedge Jacobian matrix
int nJfv; // number of non-zeros in sparse flexvert Jacobian matrix mjtSize nJfv; // number of non-zeros in sparse flexvert Jacobian matrix
int nmesh; // number of meshes mjtSize nmesh; // number of meshes
int nmeshvert; // number of vertices in all meshes mjtSize nmeshvert; // number of vertices in all meshes
int nmeshnormal; // number of normals in all meshes mjtSize nmeshnormal; // number of normals in all meshes
int nmeshtexcoord; // number of texcoords in all meshes mjtSize nmeshtexcoord; // number of texcoords in all meshes
int nmeshface; // number of triangular faces in all meshes mjtSize nmeshface; // number of triangular faces in all meshes
int nmeshgraph; // number of ints in mesh auxiliary data mjtSize nmeshgraph; // number of ints in mesh auxiliary data
int nmeshpoly; // number of polygons in all meshes mjtSize nmeshpoly; // number of polygons in all meshes
int nmeshpolyvert; // number of vertices in all polygons mjtSize nmeshpolyvert; // number of vertices in all polygons
int nmeshpolymap; // number of polygons in vertex map mjtSize nmeshpolymap; // number of polygons in vertex map
int nskin; // number of skins mjtSize nskin; // number of skins
int nskinvert; // number of vertices in all skins mjtSize nskinvert; // number of vertices in all skins
int nskintexvert; // number of vertices with texcoords in all skins mjtSize nskintexvert; // number of vertices with texcoords in all skins
int nskinface; // number of triangular faces in all skins mjtSize nskinface; // number of triangular faces in all skins
int nskinbone; // number of bones in all skins mjtSize nskinbone; // number of bones in all skins
int nskinbonevert; // number of vertices in all skin bones mjtSize nskinbonevert; // number of vertices in all skin bones
int nhfield; // number of heightfields mjtSize nhfield; // number of heightfields
int nhfielddata; // number of data points in all heightfields mjtSize nhfielddata; // number of data points in all heightfields
int ntex; // number of textures mjtSize ntex; // number of textures
int ntexdata; // number of bytes in texture rgb data mjtSize ntexdata; // number of bytes in texture rgb data
int nmat; // number of materials mjtSize nmat; // number of materials
int npair; // number of predefined geom pairs mjtSize npair; // number of predefined geom pairs
int nexclude; // number of excluded geom pairs mjtSize nexclude; // number of excluded geom pairs
int neq; // number of equality constraints mjtSize neq; // number of equality constraints
int ntendon; // number of tendons mjtSize ntendon; // number of tendons
int nwrap; // number of wrap objects in all tendon paths mjtSize nwrap; // number of wrap objects in all tendon paths
int nsensor; // number of sensors mjtSize nsensor; // number of sensors
int nnumeric; // number of numeric custom fields mjtSize nnumeric; // number of numeric custom fields
int nnumericdata; // number of mjtNums in all numeric fields mjtSize nnumericdata; // number of mjtNums in all numeric fields
int ntext; // number of text custom fields mjtSize ntext; // number of text custom fields
int ntextdata; // number of mjtBytes in all text fields mjtSize ntextdata; // number of mjtBytes in all text fields
int ntuple; // number of tuple custom fields mjtSize ntuple; // number of tuple custom fields
int ntupledata; // number of objects in all tuple fields mjtSize ntupledata; // number of objects in all tuple fields
int nkey; // number of keyframes mjtSize nkey; // number of keyframes
int nmocap; // number of mocap bodies mjtSize nmocap; // number of mocap bodies
int nplugin; // number of plugin instances mjtSize nplugin; // number of plugin instances
int npluginattr; // number of chars in all plugin config attributes mjtSize npluginattr; // number of chars in all plugin config attributes
int nuser_body; // number of mjtNums in body_user mjtSize nuser_body; // number of mjtNums in body_user
int nuser_jnt; // number of mjtNums in jnt_user mjtSize nuser_jnt; // number of mjtNums in jnt_user
int nuser_geom; // number of mjtNums in geom_user mjtSize nuser_geom; // number of mjtNums in geom_user
int nuser_site; // number of mjtNums in site_user mjtSize nuser_site; // number of mjtNums in site_user
int nuser_cam; // number of mjtNums in cam_user mjtSize nuser_cam; // number of mjtNums in cam_user
int nuser_tendon; // number of mjtNums in tendon_user mjtSize nuser_tendon; // number of mjtNums in tendon_user
int nuser_actuator; // number of mjtNums in actuator_user mjtSize nuser_actuator; // number of mjtNums in actuator_user
int nuser_sensor; // number of mjtNums in sensor_user mjtSize nuser_sensor; // number of mjtNums in sensor_user
int nnames; // number of chars in all names mjtSize nnames; // number of chars in all names
int npaths; // number of chars in all paths mjtSize npaths; // number of chars in all paths
// sizes set after mjModel construction // sizes set after mjModel construction
int nnames_map; // number of slots in the names hash map mjtSize nnames_map; // number of slots in the names hash map
int nJmom; // number of non-zeros in sparse actuator_moment matrix mjtSize nJmom; // number of non-zeros in sparse actuator_moment matrix
int ngravcomp; // number of bodies with nonzero gravcomp mjtSize ngravcomp; // number of bodies with nonzero gravcomp
int nemax; // number of potential equality-constraint rows mjtSize nemax; // number of potential equality-constraint rows
int njmax; // number of available rows in constraint Jacobian (legacy) mjtSize njmax; // number of available rows in constraint Jacobian (legacy)
int nconmax; // number of potential contacts in contact list (legacy) mjtSize nconmax; // number of potential contacts in contact list (legacy)
int nuserdata; // number of mjtNums reserved for the user mjtSize nuserdata; // number of mjtNums reserved for the user
int nsensordata; // number of mjtNums in sensor data vector mjtSize nsensordata; // number of mjtNums in sensor data vector
int npluginstate; // number of mjtNums in plugin state vector mjtSize npluginstate; // number of mjtNums in plugin state vector
// buffer sizes
mjtSize narena; // number of bytes in the mjData arena (inclusive of stack) mjtSize narena; // number of bytes in the mjData arena (inclusive of stack)
mjtSize nbuffer; // number of bytes in buffer mjtSize nbuffer; // number of bytes in buffer
+87 -86
View File
@@ -672,95 +672,96 @@ struct mjModel_ {
// ------------------------------- sizes // ------------------------------- sizes
// sizes needed at mjModel construction // sizes needed at mjModel construction
int nq; // number of generalized coordinates = dim(qpos) mjtSize nq; // number of generalized coordinates = dim(qpos)
int nv; // number of degrees of freedom = dim(qvel) mjtSize nv; // number of degrees of freedom = dim(qvel)
int nu; // number of actuators/controls = dim(ctrl) mjtSize nu; // number of actuators/controls = dim(ctrl)
int na; // number of activation states = dim(act) mjtSize na; // number of activation states = dim(act)
int nbody; // number of bodies mjtSize nbody; // number of bodies
int nbvh; // number of total bounding volumes in all bodies mjtSize nbvh; // number of total bounding volumes in all bodies
int nbvhstatic; // number of static bounding volumes (aabb stored in mjModel) mjtSize nbvhstatic; // number of static bounding volumes (aabb stored in mjModel)
int nbvhdynamic; // number of dynamic bounding volumes (aabb stored in mjData) mjtSize nbvhdynamic; // number of dynamic bounding volumes (aabb stored in mjData)
int noct; // number of total octree cells in all meshes mjtSize noct; // number of total octree cells in all meshes
int njnt; // number of joints mjtSize njnt; // number of joints
int ntree; // number of kinematic trees under world body mjtSize ntree; // number of kinematic trees under world body
int nM; // number of non-zeros in sparse inertia matrix mjtSize nM; // number of non-zeros in sparse inertia matrix
int nB; // number of non-zeros in sparse body-dof matrix mjtSize nB; // number of non-zeros in sparse body-dof matrix
int nC; // number of non-zeros in sparse reduced dof-dof matrix mjtSize nC; // number of non-zeros in sparse reduced dof-dof matrix
int nD; // number of non-zeros in sparse dof-dof matrix mjtSize nD; // number of non-zeros in sparse dof-dof matrix
int ngeom; // number of geoms mjtSize ngeom; // number of geoms
int nsite; // number of sites mjtSize nsite; // number of sites
int ncam; // number of cameras mjtSize ncam; // number of cameras
int nlight; // number of lights mjtSize nlight; // number of lights
int nflex; // number of flexes mjtSize nflex; // number of flexes
int nflexnode; // number of dofs in all flexes mjtSize nflexnode; // number of dofs in all flexes
int nflexvert; // number of vertices in all flexes mjtSize nflexvert; // number of vertices in all flexes
int nflexedge; // number of edges in all flexes mjtSize nflexedge; // number of edges in all flexes
int nflexelem; // number of elements in all flexes mjtSize nflexelem; // number of elements in all flexes
int nflexelemdata; // number of element vertex ids in all flexes mjtSize nflexelemdata; // number of element vertex ids in all flexes
int nflexelemedge; // number of element edge ids in all flexes mjtSize nflexelemedge; // number of element edge ids in all flexes
int nflexshelldata; // number of shell fragment vertex ids in all flexes mjtSize nflexshelldata; // number of shell fragment vertex ids in all flexes
int nflexevpair; // number of element-vertex pairs in all flexes mjtSize nflexevpair; // number of element-vertex pairs in all flexes
int nflextexcoord; // number of vertices with texture coordinates mjtSize nflextexcoord; // number of vertices with texture coordinates
int nJfe; // number of non-zeros in sparse flexedge Jacobian matrix mjtSize nJfe; // number of non-zeros in sparse flexedge Jacobian matrix
int nJfv; // number of non-zeros in sparse flexvert Jacobian matrix mjtSize nJfv; // number of non-zeros in sparse flexvert Jacobian matrix
int nmesh; // number of meshes mjtSize nmesh; // number of meshes
int nmeshvert; // number of vertices in all meshes mjtSize nmeshvert; // number of vertices in all meshes
int nmeshnormal; // number of normals in all meshes mjtSize nmeshnormal; // number of normals in all meshes
int nmeshtexcoord; // number of texcoords in all meshes mjtSize nmeshtexcoord; // number of texcoords in all meshes
int nmeshface; // number of triangular faces in all meshes mjtSize nmeshface; // number of triangular faces in all meshes
int nmeshgraph; // number of ints in mesh auxiliary data mjtSize nmeshgraph; // number of ints in mesh auxiliary data
int nmeshpoly; // number of polygons in all meshes mjtSize nmeshpoly; // number of polygons in all meshes
int nmeshpolyvert; // number of vertices in all polygons mjtSize nmeshpolyvert; // number of vertices in all polygons
int nmeshpolymap; // number of polygons in vertex map mjtSize nmeshpolymap; // number of polygons in vertex map
int nskin; // number of skins mjtSize nskin; // number of skins
int nskinvert; // number of vertices in all skins mjtSize nskinvert; // number of vertices in all skins
int nskintexvert; // number of vertices with texcoords in all skins mjtSize nskintexvert; // number of vertices with texcoords in all skins
int nskinface; // number of triangular faces in all skins mjtSize nskinface; // number of triangular faces in all skins
int nskinbone; // number of bones in all skins mjtSize nskinbone; // number of bones in all skins
int nskinbonevert; // number of vertices in all skin bones mjtSize nskinbonevert; // number of vertices in all skin bones
int nhfield; // number of heightfields mjtSize nhfield; // number of heightfields
int nhfielddata; // number of data points in all heightfields mjtSize nhfielddata; // number of data points in all heightfields
int ntex; // number of textures mjtSize ntex; // number of textures
int ntexdata; // number of bytes in texture rgb data mjtSize ntexdata; // number of bytes in texture rgb data
int nmat; // number of materials mjtSize nmat; // number of materials
int npair; // number of predefined geom pairs mjtSize npair; // number of predefined geom pairs
int nexclude; // number of excluded geom pairs mjtSize nexclude; // number of excluded geom pairs
int neq; // number of equality constraints mjtSize neq; // number of equality constraints
int ntendon; // number of tendons mjtSize ntendon; // number of tendons
int nwrap; // number of wrap objects in all tendon paths mjtSize nwrap; // number of wrap objects in all tendon paths
int nsensor; // number of sensors mjtSize nsensor; // number of sensors
int nnumeric; // number of numeric custom fields mjtSize nnumeric; // number of numeric custom fields
int nnumericdata; // number of mjtNums in all numeric fields mjtSize nnumericdata; // number of mjtNums in all numeric fields
int ntext; // number of text custom fields mjtSize ntext; // number of text custom fields
int ntextdata; // number of mjtBytes in all text fields mjtSize ntextdata; // number of mjtBytes in all text fields
int ntuple; // number of tuple custom fields mjtSize ntuple; // number of tuple custom fields
int ntupledata; // number of objects in all tuple fields mjtSize ntupledata; // number of objects in all tuple fields
int nkey; // number of keyframes mjtSize nkey; // number of keyframes
int nmocap; // number of mocap bodies mjtSize nmocap; // number of mocap bodies
int nplugin; // number of plugin instances mjtSize nplugin; // number of plugin instances
int npluginattr; // number of chars in all plugin config attributes mjtSize npluginattr; // number of chars in all plugin config attributes
int nuser_body; // number of mjtNums in body_user mjtSize nuser_body; // number of mjtNums in body_user
int nuser_jnt; // number of mjtNums in jnt_user mjtSize nuser_jnt; // number of mjtNums in jnt_user
int nuser_geom; // number of mjtNums in geom_user mjtSize nuser_geom; // number of mjtNums in geom_user
int nuser_site; // number of mjtNums in site_user mjtSize nuser_site; // number of mjtNums in site_user
int nuser_cam; // number of mjtNums in cam_user mjtSize nuser_cam; // number of mjtNums in cam_user
int nuser_tendon; // number of mjtNums in tendon_user mjtSize nuser_tendon; // number of mjtNums in tendon_user
int nuser_actuator; // number of mjtNums in actuator_user mjtSize nuser_actuator; // number of mjtNums in actuator_user
int nuser_sensor; // number of mjtNums in sensor_user mjtSize nuser_sensor; // number of mjtNums in sensor_user
int nnames; // number of chars in all names mjtSize nnames; // number of chars in all names
int npaths; // number of chars in all paths mjtSize npaths; // number of chars in all paths
// sizes set after mjModel construction // sizes set after mjModel construction
int nnames_map; // number of slots in the names hash map mjtSize nnames_map; // number of slots in the names hash map
int nJmom; // number of non-zeros in sparse actuator_moment matrix mjtSize nJmom; // number of non-zeros in sparse actuator_moment matrix
int ngravcomp; // number of bodies with nonzero gravcomp mjtSize ngravcomp; // number of bodies with nonzero gravcomp
int nemax; // number of potential equality-constraint rows mjtSize nemax; // number of potential equality-constraint rows
int njmax; // number of available rows in constraint Jacobian (legacy) mjtSize njmax; // number of available rows in constraint Jacobian (legacy)
int nconmax; // number of potential contacts in contact list (legacy) mjtSize nconmax; // number of potential contacts in contact list (legacy)
int nuserdata; // number of mjtNums reserved for the user mjtSize nuserdata; // number of mjtNums reserved for the user
int nsensordata; // number of mjtNums in sensor data vector mjtSize nsensordata; // number of mjtNums in sensor data vector
int npluginstate; // number of mjtNums in plugin state vector mjtSize npluginstate; // number of mjtNums in plugin state vector
// buffer sizes
mjtSize narena; // number of bytes in the mjData arena (inclusive of stack) mjtSize narena; // number of bytes in the mjData arena (inclusive of stack)
mjtSize nbuffer; // number of bytes in buffer mjtSize nbuffer; // number of bytes in buffer
+2 -2
View File
@@ -65,8 +65,8 @@
//-------------------------------- mjModel --------------------------------------------------------- //-------------------------------- mjModel ---------------------------------------------------------
// int fields of mjModel // size fields of mjModel
#define MJMODEL_INTS \ #define MJMODEL_SIZES \
X( nq ) \ X( nq ) \
X( nv ) \ X( nv ) \
X( nu ) \ X( nu ) \
+1 -1
View File
@@ -261,7 +261,7 @@ MJDATA_VIEW_GROUPS
if constexpr (std::string_view(#dim) == std::string_view("1")) { \ if constexpr (std::string_view(#dim) == std::string_view("1")) { \
return {}; \ return {}; \
} else { \ } else { \
return {n}; \ return {(int)n}; \
} \ } \
}() \ }() \
MUJOCO_DIAG_UNIGNORE_UNUSED_LAMBDA_CAPTURE MUJOCO_DIAG_UNIGNORE_UNUSED_LAMBDA_CAPTURE
+86 -86
View File
@@ -849,432 +849,432 @@ STRUCTS: Mapping[str, StructDecl] = dict([
fields=( fields=(
StructFieldDecl( StructFieldDecl(
name='nq', name='nq',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of generalized coordinates = dim(qpos)', doc='number of generalized coordinates = dim(qpos)',
), ),
StructFieldDecl( StructFieldDecl(
name='nv', name='nv',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of degrees of freedom = dim(qvel)', doc='number of degrees of freedom = dim(qvel)',
), ),
StructFieldDecl( StructFieldDecl(
name='nu', name='nu',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of actuators/controls = dim(ctrl)', doc='number of actuators/controls = dim(ctrl)',
), ),
StructFieldDecl( StructFieldDecl(
name='na', name='na',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of activation states = dim(act)', doc='number of activation states = dim(act)',
), ),
StructFieldDecl( StructFieldDecl(
name='nbody', name='nbody',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of bodies', doc='number of bodies',
), ),
StructFieldDecl( StructFieldDecl(
name='nbvh', name='nbvh',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of total bounding volumes in all bodies', doc='number of total bounding volumes in all bodies',
), ),
StructFieldDecl( StructFieldDecl(
name='nbvhstatic', name='nbvhstatic',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of static bounding volumes (aabb stored in mjModel)', # pylint: disable=line-too-long doc='number of static bounding volumes (aabb stored in mjModel)', # pylint: disable=line-too-long
), ),
StructFieldDecl( StructFieldDecl(
name='nbvhdynamic', name='nbvhdynamic',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of dynamic bounding volumes (aabb stored in mjData)', # pylint: disable=line-too-long doc='number of dynamic bounding volumes (aabb stored in mjData)', # pylint: disable=line-too-long
), ),
StructFieldDecl( StructFieldDecl(
name='noct', name='noct',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of total octree cells in all meshes', doc='number of total octree cells in all meshes',
), ),
StructFieldDecl( StructFieldDecl(
name='njnt', name='njnt',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of joints', doc='number of joints',
), ),
StructFieldDecl( StructFieldDecl(
name='ntree', name='ntree',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of kinematic trees under world body', doc='number of kinematic trees under world body',
), ),
StructFieldDecl( StructFieldDecl(
name='nM', name='nM',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse inertia matrix', doc='number of non-zeros in sparse inertia matrix',
), ),
StructFieldDecl( StructFieldDecl(
name='nB', name='nB',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse body-dof matrix', doc='number of non-zeros in sparse body-dof matrix',
), ),
StructFieldDecl( StructFieldDecl(
name='nC', name='nC',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse reduced dof-dof matrix', doc='number of non-zeros in sparse reduced dof-dof matrix',
), ),
StructFieldDecl( StructFieldDecl(
name='nD', name='nD',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse dof-dof matrix', doc='number of non-zeros in sparse dof-dof matrix',
), ),
StructFieldDecl( StructFieldDecl(
name='ngeom', name='ngeom',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of geoms', doc='number of geoms',
), ),
StructFieldDecl( StructFieldDecl(
name='nsite', name='nsite',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of sites', doc='number of sites',
), ),
StructFieldDecl( StructFieldDecl(
name='ncam', name='ncam',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of cameras', doc='number of cameras',
), ),
StructFieldDecl( StructFieldDecl(
name='nlight', name='nlight',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of lights', doc='number of lights',
), ),
StructFieldDecl( StructFieldDecl(
name='nflex', name='nflex',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of flexes', doc='number of flexes',
), ),
StructFieldDecl( StructFieldDecl(
name='nflexnode', name='nflexnode',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of dofs in all flexes', doc='number of dofs in all flexes',
), ),
StructFieldDecl( StructFieldDecl(
name='nflexvert', name='nflexvert',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of vertices in all flexes', doc='number of vertices in all flexes',
), ),
StructFieldDecl( StructFieldDecl(
name='nflexedge', name='nflexedge',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of edges in all flexes', doc='number of edges in all flexes',
), ),
StructFieldDecl( StructFieldDecl(
name='nflexelem', name='nflexelem',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of elements in all flexes', doc='number of elements in all flexes',
), ),
StructFieldDecl( StructFieldDecl(
name='nflexelemdata', name='nflexelemdata',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of element vertex ids in all flexes', doc='number of element vertex ids in all flexes',
), ),
StructFieldDecl( StructFieldDecl(
name='nflexelemedge', name='nflexelemedge',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of element edge ids in all flexes', doc='number of element edge ids in all flexes',
), ),
StructFieldDecl( StructFieldDecl(
name='nflexshelldata', name='nflexshelldata',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of shell fragment vertex ids in all flexes', doc='number of shell fragment vertex ids in all flexes',
), ),
StructFieldDecl( StructFieldDecl(
name='nflexevpair', name='nflexevpair',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of element-vertex pairs in all flexes', doc='number of element-vertex pairs in all flexes',
), ),
StructFieldDecl( StructFieldDecl(
name='nflextexcoord', name='nflextexcoord',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of vertices with texture coordinates', doc='number of vertices with texture coordinates',
), ),
StructFieldDecl( StructFieldDecl(
name='nJfe', name='nJfe',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse flexedge Jacobian matrix', doc='number of non-zeros in sparse flexedge Jacobian matrix',
), ),
StructFieldDecl( StructFieldDecl(
name='nJfv', name='nJfv',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse flexvert Jacobian matrix', doc='number of non-zeros in sparse flexvert Jacobian matrix',
), ),
StructFieldDecl( StructFieldDecl(
name='nmesh', name='nmesh',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of meshes', doc='number of meshes',
), ),
StructFieldDecl( StructFieldDecl(
name='nmeshvert', name='nmeshvert',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of vertices in all meshes', doc='number of vertices in all meshes',
), ),
StructFieldDecl( StructFieldDecl(
name='nmeshnormal', name='nmeshnormal',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of normals in all meshes', doc='number of normals in all meshes',
), ),
StructFieldDecl( StructFieldDecl(
name='nmeshtexcoord', name='nmeshtexcoord',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of texcoords in all meshes', doc='number of texcoords in all meshes',
), ),
StructFieldDecl( StructFieldDecl(
name='nmeshface', name='nmeshface',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of triangular faces in all meshes', doc='number of triangular faces in all meshes',
), ),
StructFieldDecl( StructFieldDecl(
name='nmeshgraph', name='nmeshgraph',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of ints in mesh auxiliary data', doc='number of ints in mesh auxiliary data',
), ),
StructFieldDecl( StructFieldDecl(
name='nmeshpoly', name='nmeshpoly',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of polygons in all meshes', doc='number of polygons in all meshes',
), ),
StructFieldDecl( StructFieldDecl(
name='nmeshpolyvert', name='nmeshpolyvert',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of vertices in all polygons', doc='number of vertices in all polygons',
), ),
StructFieldDecl( StructFieldDecl(
name='nmeshpolymap', name='nmeshpolymap',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of polygons in vertex map', doc='number of polygons in vertex map',
), ),
StructFieldDecl( StructFieldDecl(
name='nskin', name='nskin',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of skins', doc='number of skins',
), ),
StructFieldDecl( StructFieldDecl(
name='nskinvert', name='nskinvert',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of vertices in all skins', doc='number of vertices in all skins',
), ),
StructFieldDecl( StructFieldDecl(
name='nskintexvert', name='nskintexvert',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of vertices with texcoords in all skins', doc='number of vertices with texcoords in all skins',
), ),
StructFieldDecl( StructFieldDecl(
name='nskinface', name='nskinface',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of triangular faces in all skins', doc='number of triangular faces in all skins',
), ),
StructFieldDecl( StructFieldDecl(
name='nskinbone', name='nskinbone',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of bones in all skins', doc='number of bones in all skins',
), ),
StructFieldDecl( StructFieldDecl(
name='nskinbonevert', name='nskinbonevert',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of vertices in all skin bones', doc='number of vertices in all skin bones',
), ),
StructFieldDecl( StructFieldDecl(
name='nhfield', name='nhfield',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of heightfields', doc='number of heightfields',
), ),
StructFieldDecl( StructFieldDecl(
name='nhfielddata', name='nhfielddata',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of data points in all heightfields', doc='number of data points in all heightfields',
), ),
StructFieldDecl( StructFieldDecl(
name='ntex', name='ntex',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of textures', doc='number of textures',
), ),
StructFieldDecl( StructFieldDecl(
name='ntexdata', name='ntexdata',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of bytes in texture rgb data', doc='number of bytes in texture rgb data',
), ),
StructFieldDecl( StructFieldDecl(
name='nmat', name='nmat',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of materials', doc='number of materials',
), ),
StructFieldDecl( StructFieldDecl(
name='npair', name='npair',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of predefined geom pairs', doc='number of predefined geom pairs',
), ),
StructFieldDecl( StructFieldDecl(
name='nexclude', name='nexclude',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of excluded geom pairs', doc='number of excluded geom pairs',
), ),
StructFieldDecl( StructFieldDecl(
name='neq', name='neq',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of equality constraints', doc='number of equality constraints',
), ),
StructFieldDecl( StructFieldDecl(
name='ntendon', name='ntendon',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of tendons', doc='number of tendons',
), ),
StructFieldDecl( StructFieldDecl(
name='nwrap', name='nwrap',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of wrap objects in all tendon paths', doc='number of wrap objects in all tendon paths',
), ),
StructFieldDecl( StructFieldDecl(
name='nsensor', name='nsensor',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of sensors', doc='number of sensors',
), ),
StructFieldDecl( StructFieldDecl(
name='nnumeric', name='nnumeric',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of numeric custom fields', doc='number of numeric custom fields',
), ),
StructFieldDecl( StructFieldDecl(
name='nnumericdata', name='nnumericdata',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mjtNums in all numeric fields', doc='number of mjtNums in all numeric fields',
), ),
StructFieldDecl( StructFieldDecl(
name='ntext', name='ntext',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of text custom fields', doc='number of text custom fields',
), ),
StructFieldDecl( StructFieldDecl(
name='ntextdata', name='ntextdata',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mjtBytes in all text fields', doc='number of mjtBytes in all text fields',
), ),
StructFieldDecl( StructFieldDecl(
name='ntuple', name='ntuple',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of tuple custom fields', doc='number of tuple custom fields',
), ),
StructFieldDecl( StructFieldDecl(
name='ntupledata', name='ntupledata',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of objects in all tuple fields', doc='number of objects in all tuple fields',
), ),
StructFieldDecl( StructFieldDecl(
name='nkey', name='nkey',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of keyframes', doc='number of keyframes',
), ),
StructFieldDecl( StructFieldDecl(
name='nmocap', name='nmocap',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mocap bodies', doc='number of mocap bodies',
), ),
StructFieldDecl( StructFieldDecl(
name='nplugin', name='nplugin',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of plugin instances', doc='number of plugin instances',
), ),
StructFieldDecl( StructFieldDecl(
name='npluginattr', name='npluginattr',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of chars in all plugin config attributes', doc='number of chars in all plugin config attributes',
), ),
StructFieldDecl( StructFieldDecl(
name='nuser_body', name='nuser_body',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mjtNums in body_user', doc='number of mjtNums in body_user',
), ),
StructFieldDecl( StructFieldDecl(
name='nuser_jnt', name='nuser_jnt',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mjtNums in jnt_user', doc='number of mjtNums in jnt_user',
), ),
StructFieldDecl( StructFieldDecl(
name='nuser_geom', name='nuser_geom',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mjtNums in geom_user', doc='number of mjtNums in geom_user',
), ),
StructFieldDecl( StructFieldDecl(
name='nuser_site', name='nuser_site',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mjtNums in site_user', doc='number of mjtNums in site_user',
), ),
StructFieldDecl( StructFieldDecl(
name='nuser_cam', name='nuser_cam',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mjtNums in cam_user', doc='number of mjtNums in cam_user',
), ),
StructFieldDecl( StructFieldDecl(
name='nuser_tendon', name='nuser_tendon',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mjtNums in tendon_user', doc='number of mjtNums in tendon_user',
), ),
StructFieldDecl( StructFieldDecl(
name='nuser_actuator', name='nuser_actuator',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mjtNums in actuator_user', doc='number of mjtNums in actuator_user',
), ),
StructFieldDecl( StructFieldDecl(
name='nuser_sensor', name='nuser_sensor',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mjtNums in sensor_user', doc='number of mjtNums in sensor_user',
), ),
StructFieldDecl( StructFieldDecl(
name='nnames', name='nnames',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of chars in all names', doc='number of chars in all names',
), ),
StructFieldDecl( StructFieldDecl(
name='npaths', name='npaths',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of chars in all paths', doc='number of chars in all paths',
), ),
StructFieldDecl( StructFieldDecl(
name='nnames_map', name='nnames_map',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of slots in the names hash map', doc='number of slots in the names hash map',
), ),
StructFieldDecl( StructFieldDecl(
name='nJmom', name='nJmom',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of non-zeros in sparse actuator_moment matrix', doc='number of non-zeros in sparse actuator_moment matrix',
), ),
StructFieldDecl( StructFieldDecl(
name='ngravcomp', name='ngravcomp',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of bodies with nonzero gravcomp', doc='number of bodies with nonzero gravcomp',
), ),
StructFieldDecl( StructFieldDecl(
name='nemax', name='nemax',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of potential equality-constraint rows', doc='number of potential equality-constraint rows',
), ),
StructFieldDecl( StructFieldDecl(
name='njmax', name='njmax',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of available rows in constraint Jacobian (legacy)', doc='number of available rows in constraint Jacobian (legacy)',
), ),
StructFieldDecl( StructFieldDecl(
name='nconmax', name='nconmax',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of potential contacts in contact list (legacy)', doc='number of potential contacts in contact list (legacy)',
), ),
StructFieldDecl( StructFieldDecl(
name='nuserdata', name='nuserdata',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mjtNums reserved for the user', doc='number of mjtNums reserved for the user',
), ),
StructFieldDecl( StructFieldDecl(
name='nsensordata', name='nsensordata',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mjtNums in sensor data vector', doc='number of mjtNums in sensor data vector',
), ),
StructFieldDecl( StructFieldDecl(
name='npluginstate', name='npluginstate',
type=ValueType(name='int'), type=ValueType(name='mjtSize'),
doc='number of mjtNums in plugin state vector', doc='number of mjtNums in plugin state vector',
), ),
StructFieldDecl( StructFieldDecl(
+11 -7
View File
@@ -56,9 +56,13 @@ namespace {
// (dim0, dim1). // (dim0, dim1).
#define X_ARRAY_SHAPE(dim0, dim1) XArrayShapeImpl(#dim1)((dim0), (dim1)) #define X_ARRAY_SHAPE(dim0, dim1) XArrayShapeImpl(#dim1)((dim0), (dim1))
std::vector<int> XArrayShapeImpl1D(int dim0, int dim1) { return {dim0}; } std::vector<mjtSize> XArrayShapeImpl1D(mjtSize dim0, mjtSize dim1) {
return {dim0};
}
std::vector<int> XArrayShapeImpl2D(int dim0, int dim1) { return {dim0, dim1}; } std::vector<mjtSize> XArrayShapeImpl2D(mjtSize dim0, mjtSize dim1) {
return {dim0, dim1};
}
constexpr auto XArrayShapeImpl(const std::string_view dim1_str) { constexpr auto XArrayShapeImpl(const std::string_view dim1_str) {
if (dim1_str == "1") { if (dim1_str == "1") {
@@ -401,20 +405,20 @@ This is useful for example when the MJB is not available as a file on disk.)"));
#define X(var) \ #define X(var) \
mjModel.def_property_readonly( \ mjModel.def_property_readonly( \
#var, [](const MjModelWrapper& m) { return m.get()->var; }); #var, [](const MjModelWrapper& m) { return m.get()->var; });
MJMODEL_INTS MJMODEL_SIZES
#undef X #undef X
mjModel.def_property_readonly("_sizes", [](const MjModelWrapper& m) { mjModel.def_property_readonly("_sizes", [](const MjModelWrapper& m) {
int nint = 0; int nint = 0;
#define X(var) ++nint; #define X(var) ++nint;
MJMODEL_INTS MJMODEL_SIZES
#undef X #undef X
py::array_t<std::int64_t> sizes(nint); py::array_t<std::int64_t> sizes(nint);
{ {
int i = 0; int i = 0;
auto data = sizes.mutable_unchecked(); auto data = sizes.mutable_unchecked();
#define X(var) data[i++] = m.get()->var; #define X(var) data[i++] = m.get()->var;
MJMODEL_INTS MJMODEL_SIZES
#undef X #undef X
} }
py::detail::array_proxy(sizes.ptr())->flags &= py::detail::array_proxy(sizes.ptr())->flags &=
@@ -425,7 +429,7 @@ This is useful for example when the MJB is not available as a file on disk.)"));
mjModel.def_property_readonly_static("_size_fields", [](py::object) { mjModel.def_property_readonly_static("_size_fields", [](py::object) {
std::vector<std::string> fields; std::vector<std::string> fields;
#define X(var) fields.push_back(#var); #define X(var) fields.push_back(#var);
MJMODEL_INTS MJMODEL_SIZES
#undef X #undef X
return py::tuple(py::cast(fields)); return py::tuple(py::cast(fields));
}); });
@@ -433,7 +437,7 @@ This is useful for example when the MJB is not available as a file on disk.)"));
mjModel.def_property_readonly_static("_all_fields", [](py::object) { mjModel.def_property_readonly_static("_all_fields", [](py::object) {
std::vector<std::string> fields; std::vector<std::string> fields;
#define X(var) fields.push_back(#var); #define X(var) fields.push_back(#var);
MJMODEL_INTS MJMODEL_SIZES
#undef X #undef X
#define X(type, name, nr, nc) fields.push_back(#name); #define X(type, name, nr, nc) fields.push_back(#name);
MJMODEL_POINTERS MJMODEL_POINTERS
+2 -2
View File
@@ -1006,7 +1006,7 @@ using _impl::MjSolverStatList;
template <typename T, typename Shape> template <typename T, typename Shape>
std::enable_if_t<std::is_arithmetic_v<T>, pybind11::array_t<T>> std::enable_if_t<std::is_arithmetic_v<T>, pybind11::array_t<T>>
static InitPyArray(Shape&& shape, T* buf, pybind11::handle owner) { static InitPyArray(Shape&& shape, T* buf, pybind11::handle owner) {
int size = 1; mjtSize size = 1;
for (const auto& i : shape) { for (const auto& i : shape) {
size *= i; size *= i;
} }
@@ -1043,7 +1043,7 @@ template <typename T, typename Shape>
std::enable_if_t<!std::is_arithmetic_v<T> && !is_mj_struct_list_v<T>, std::enable_if_t<!std::is_arithmetic_v<T> && !is_mj_struct_list_v<T>,
pybind11::tuple> pybind11::tuple>
static InitPyArray(Shape&& shape, T* buf, pybind11::handle owner) { static InitPyArray(Shape&& shape, T* buf, pybind11::handle owner) {
int size = 1; mjtSize size = 1;
for (const auto& i : shape) { for (const auto& i : shape) {
size *= i; size *= i;
} }
+6 -2
View File
@@ -60,9 +60,13 @@ namespace {
// (dim0, dim1). // (dim0, dim1).
#define X_ARRAY_SHAPE(dim0, dim1) XArrayShapeImpl(#dim1)((dim0), (dim1)) #define X_ARRAY_SHAPE(dim0, dim1) XArrayShapeImpl(#dim1)((dim0), (dim1))
std::vector<int> XArrayShapeImpl1D(int dim0, int dim1) { return {dim0}; } std::vector<mjtSize> XArrayShapeImpl1D(mjtSize dim0, mjtSize dim1) {
return {dim0};
}
std::vector<int> XArrayShapeImpl2D(int dim0, int dim1) { return {dim0, dim1}; } std::vector<mjtSize> XArrayShapeImpl2D(mjtSize dim0, mjtSize dim1) {
return {dim0, dim1};
}
constexpr auto XArrayShapeImpl(const std::string_view dim1_str) { constexpr auto XArrayShapeImpl(const std::string_view dim1_str) {
if (dim1_str == "1") { if (dim1_str == "1") {
+2 -1
View File
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <cinttypes>
#include <chrono> #include <chrono>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
@@ -283,7 +284,7 @@ int main(int argc, char** argv) {
solver[m->opt.solver], solto6[m->opt.solver], iterations[0]/nstep); solver[m->opt.solver], solto6[m->opt.solver], iterations[0]/nstep);
std::printf(" Contacts / step : %.2f\n", static_cast<float>(contacts[0])/nstep); std::printf(" Contacts / step : %.2f\n", static_cast<float>(contacts[0])/nstep);
std::printf(" Constraints / step : %.2f\n", static_cast<float>(constraints[0])/nstep); std::printf(" Constraints / step : %.2f\n", static_cast<float>(constraints[0])/nstep);
std::printf(" Degrees of freedom : %d\n", m->nv); std::printf(" Degrees of freedom : %" PRId64 "\n", m->nv);
std::printf(" Dynamic memory usage : %.1f%% of %s\n\n", std::printf(" Dynamic memory usage : %.1f%% of %s\n\n",
100 * d[0]->maxuse_arena / (double)(d[0]->narena), 100 * d[0]->maxuse_arena / (double)(d[0]->narena),
mju_writeNumBytes(d[0]->narena)); mju_writeNumBytes(d[0]->narena));
+94 -96
View File
@@ -50,10 +50,7 @@
#pragma warning (disable: 4305) // disable MSVC warning: truncation from 'double' to 'float' #pragma warning (disable: 4305) // disable MSVC warning: truncation from 'double' to 'float'
#endif #endif
static const int MAX_ARRAY_SIZE = INT_MAX / 4; static const int MAX_ARRAY_SIZE = INT_MAX;
//----------------------------------- static utility functions -------------------------------------
//----------------------------------- static utility functions ------------------------------------- //----------------------------------- static utility functions -------------------------------------
@@ -70,24 +67,12 @@ static const int ID = 54321;
#define MJMODEL_MEMBER(name) (((mjModel*) NULL)->name) #define MJMODEL_MEMBER(name) (((mjModel*) NULL)->name)
// count ints in mjModel // count mjtSize members in mjModel
static int getnint(void) { static int getnsize(void) {
int cnt = 0;
#define X(name) cnt += _Generic(MJMODEL_MEMBER(name), int: 1, default: 0);
MJMODEL_INTS
#undef X
return cnt;
}
// count buffer members in mjModel (mjtSize)
static int getnbuffer(void) {
int cnt = 0; int cnt = 0;
#define X(name) cnt += _Generic(MJMODEL_MEMBER(name), mjtSize: 1, default: 0); #define X(name) cnt += _Generic(MJMODEL_MEMBER(name), mjtSize: 1, default: 0);
MJMODEL_INTS MJMODEL_SIZES
#undef X #undef X
return cnt; return cnt;
@@ -107,7 +92,7 @@ static int getnptr(void) {
// write to memory buffer // write to memory buffer
static void bufwrite(const void* src, int num, int szbuf, void* buf, int* ptrbuf) { static void bufwrite(const void* src, int num, mjtSize szbuf, void* buf, mjtSize* ptrbuf) {
// check pointers // check pointers
if (!src || !buf || !ptrbuf) { if (!src || !buf || !ptrbuf) {
mjERROR("NULL pointer passed to bufwrite"); mjERROR("NULL pointer passed to bufwrite");
@@ -125,7 +110,7 @@ static void bufwrite(const void* src, int num, int szbuf, void* buf, int* ptrbuf
// read from memory buffer // read from memory buffer
static void bufread(void* dest, int num, int szbuf, const void* buf, int* ptrbuf) { static void bufread(void* dest, int num, mjtSize szbuf, const void* buf, mjtSize* ptrbuf) {
// check pointers // check pointers
if (!dest || !buf || !ptrbuf) { if (!dest || !buf || !ptrbuf) {
mjERROR("NULL pointer passed to bufread"); mjERROR("NULL pointer passed to bufread");
@@ -184,8 +169,8 @@ static void mj_setPtrModel(mjModel* m) {
// performs the following operations: // performs the following operations:
// *nbuffer += SKIP(*offset) + type_size*nr*nc; // *nbuffer += SKIP(*offset) + type_size*nr*nc;
// *offset += SKIP(*offset) + type_size*nr*nc; // *offset += SKIP(*offset) + type_size*nr*nc;
static int safeAddToBufferSize(intptr_t* offset, mjtSize* nbuffer, static mjtSize safeAddToBufferSize(intptr_t* offset, mjtSize* nbuffer,
size_t type_size, int nr, int nc) { size_t type_size, mjtSize nr, mjtSize nc) {
if (type_size < 0 || nr < 0 || nc < 0) { if (type_size < 0 || nr < 0 || nc < 0) {
return 0; return 0;
} }
@@ -216,25 +201,58 @@ static void freeModelBuffers(mjModel* m) {
// allocate and initialize mjModel structure // allocate and initialize mjModel structure
void mj_makeModel(mjModel** dest, void mj_makeModel(mjModel** dest,
int nq, int nv, int nu, int na, int nbody, int nbvh, mjtSize nq, mjtSize nv, mjtSize nu, mjtSize na, mjtSize nbody, mjtSize nbvh, mjtSize nbvhstatic,
int nbvhstatic, int nbvhdynamic, int noct, int njnt, int ntree, mjtSize nbvhdynamic, mjtSize noct, mjtSize njnt, mjtSize ntree, mjtSize nM, mjtSize nB,
int nM, int nB, int nC, int nD, int ngeom, int nsite, int ncam, int nlight, mjtSize nC, mjtSize nD, mjtSize ngeom, mjtSize nsite, mjtSize ncam, mjtSize nlight,
int nflex, int nflexnode, int nflexvert, int nflexedge, int nflexelem, int nflexelemdata, mjtSize nflex, mjtSize nflexnode, mjtSize nflexvert, mjtSize nflexedge, mjtSize nflexelem,
int nflexelemedge, int nflexshelldata, int nflexevpair, int nflextexcoord, int nJfe, int nJfv, mjtSize nflexelemdata, mjtSize nflexelemedge, mjtSize nflexshelldata, mjtSize nflexevpair,
int nmesh, int nmeshvert, int nmeshnormal, int nmeshtexcoord, int nmeshface, mjtSize nflextexcoord, mjtSize nJfe, mjtSize nJfv, mjtSize nmesh, mjtSize nmeshvert,
int nmeshgraph, int nmeshpoly, int nmeshpolyvert, int nmeshpolymap, int nskin, int nskinvert, mjtSize nmeshnormal, mjtSize nmeshtexcoord, mjtSize nmeshface, mjtSize nmeshgraph,
int nskintexvert, int nskinface, mjtSize nmeshpoly, mjtSize nmeshpolyvert, mjtSize nmeshpolymap, mjtSize nskin,
int nskinbone, int nskinbonevert, int nhfield, int nhfielddata, int ntex, mjtSize nskinvert, mjtSize nskintexvert, mjtSize nskinface, mjtSize nskinbone,
int ntexdata, int nmat, int npair, int nexclude, int neq, int ntendon, mjtSize nskinbonevert, mjtSize nhfield, mjtSize nhfielddata, mjtSize ntex, mjtSize ntexdata,
int nwrap, int nsensor, int nnumeric, int nnumericdata, int ntext, mjtSize nmat, mjtSize npair, mjtSize nexclude, mjtSize neq, mjtSize ntendon, mjtSize nwrap,
int ntextdata, int ntuple, int ntupledata, int nkey, int nmocap, mjtSize nsensor, mjtSize nnumeric, mjtSize nnumericdata, mjtSize ntext, mjtSize ntextdata,
int nplugin, int npluginattr, int nuser_body, int nuser_jnt, int nuser_geom, mjtSize ntuple, mjtSize ntupledata, mjtSize nkey, mjtSize nmocap, mjtSize nplugin,
int nuser_site, int nuser_cam, int nuser_tendon, int nuser_actuator, mjtSize npluginattr, mjtSize nuser_body, mjtSize nuser_jnt, mjtSize nuser_geom,
int nuser_sensor, int nnames, int npaths) { mjtSize nuser_site, mjtSize nuser_cam, mjtSize nuser_tendon, mjtSize nuser_actuator,
mjtSize nuser_sensor, mjtSize nnames, mjtSize npaths) {
intptr_t offset = 0; intptr_t offset = 0;
int allocate = *dest ? 0 : 1; int allocate = *dest ? 0 : 1;
mjModel* m = NULL; mjModel* m = NULL;
// CHECK SIZE PARAMETERS
{
// dummy variables for MJMODEL_SIZES set after mjModel construction
int nnames_map=0, nJmom=0, ngravcomp=0, nemax=0, njmax=0;
int nconmax=0, nuserdata=0, nsensordata=0, npluginstate=0, narena=0, nbuffer=0;
// sizes must be non-negative and fit in int, except for the byte arrays texdata and textdata
#define X(name) \
if (name < 0) { \
mju_warning("Invalid model: %s is negative (%lld).", #name, (long long)name); \
return; \
} \
if (name >= MAX_ARRAY_SIZE && \
strcmp(#name, "ntexdata") != 0 && strcmp(#name, "ntextdata") != 0) { \
mju_warning("Invalid model: %s is too large. Expected < %d. Got %lld.", \
#name, MAX_ARRAY_SIZE, (long long)name); \
return; \
}
MJMODEL_SIZES
#undef X
// suppress unused variable warnings
(void)nnames_map; (void)nJmom; (void)ngravcomp; (void)nemax; (void)njmax;
(void)nconmax; (void)nuserdata; (void)nsensordata; (void)npluginstate; (void)narena; (void)nbuffer;
}
// nbody should always be positive
if (nbody == 0) {
mju_warning("Invalid model: nbody == 0");
return;
}
// allocate mjModel // allocate mjModel
if (!allocate) { if (!allocate) {
m = *dest; m = *dest;
@@ -336,29 +354,6 @@ void mj_makeModel(mjModel** dest,
m->nnames_map = mjLOAD_MULTIPLE * nnames_map; m->nnames_map = mjLOAD_MULTIPLE * nnames_map;
m->npaths = npaths; m->npaths = npaths;
#define X(name) \
if ((m->name) < 0) { \
if (allocate) mju_free(m); \
mju_warning("Invalid model: negative " #name); \
return; \
}
MJMODEL_INTS;
#undef X
// nbody should always be positive
if (m->nbody == 0) {
if (allocate) mju_free(m);
mju_warning("Invalid model: nbody == 0");
return;
}
// nmocap is going to get multiplied by 4, and shouldn't overflow
if (m->nmocap >= MAX_ARRAY_SIZE) {
if (allocate) mju_free(m);
mju_warning("Invalid model: nmocap too large");
return;
}
// compute buffer size // compute buffer size
m->nbuffer = 0; m->nbuffer = 0;
#define X(type, name, nr, nc) \ #define X(type, name, nr, nc) \
@@ -484,10 +479,10 @@ void mjv_copyModel(mjModel* dest, const mjModel* src) {
// save model to binary file, or memory buffer of szbuf>0 // save model to binary file, or memory buffer of szbuf>0
void mj_saveModel(const mjModel* m, const char* filename, void* buffer, int buffer_sz) { void mj_saveModel(const mjModel* m, const char* filename, void* buffer, int buffer_sz) {
FILE* fp = 0; FILE* fp = 0;
int ptrbuf = 0; mjtSize ptrbuf = 0;
// standard header // standard header
int header[NHEADER] = {ID, sizeof(mjtNum), getnint(), getnbuffer(), getnptr()}; int header[NHEADER] = {ID, sizeof(mjtNum), getnsize(), mj_version(), getnptr()};
// open file for writing if no buffer // open file for writing if no buffer
if (!buffer) { if (!buffer) {
@@ -502,7 +497,7 @@ void mj_saveModel(const mjModel* m, const char* filename, void* buffer, int buff
if (fp) { if (fp) {
fwrite(header, sizeof(int), NHEADER, fp); fwrite(header, sizeof(int), NHEADER, fp);
#define X(name) fwrite(&m->name, sizeof(m->name), 1, fp); #define X(name) fwrite(&m->name, sizeof(m->name), 1, fp);
MJMODEL_INTS MJMODEL_SIZES
#undef X #undef X
fwrite((void*)&m->opt, sizeof(mjOption), 1, fp); fwrite((void*)&m->opt, sizeof(mjOption), 1, fp);
fwrite((void*)&m->vis, sizeof(mjVisual), 1, fp); fwrite((void*)&m->vis, sizeof(mjVisual), 1, fp);
@@ -517,7 +512,7 @@ void mj_saveModel(const mjModel* m, const char* filename, void* buffer, int buff
} else { } else {
bufwrite(header, sizeof(header), buffer_sz, buffer, &ptrbuf); bufwrite(header, sizeof(header), buffer_sz, buffer, &ptrbuf);
#define X(name) bufwrite(&m->name, sizeof(m->name), buffer_sz, buffer, &ptrbuf); #define X(name) bufwrite(&m->name, sizeof(m->name), buffer_sz, buffer, &ptrbuf);
MJMODEL_INTS MJMODEL_SIZES
#undef X #undef X
bufwrite((void*)&m->opt, sizeof(mjOption), buffer_sz, buffer, &ptrbuf); bufwrite((void*)&m->opt, sizeof(mjOption), buffer_sz, buffer, &ptrbuf);
bufwrite((void*)&m->vis, sizeof(mjVisual), buffer_sz, buffer, &ptrbuf); bufwrite((void*)&m->vis, sizeof(mjVisual), buffer_sz, buffer, &ptrbuf);
@@ -539,7 +534,7 @@ void mj_saveModel(const mjModel* m, const char* filename, void* buffer, int buff
// load binary MJB model // load binary MJB model
mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz) { mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz) {
int ptrbuf = 0; mjtSize ptrbuf = 0;
mjModel *m = 0; mjModel *m = 0;
if (buffer_sz < NHEADER*sizeof(int)) { if (buffer_sz < NHEADER*sizeof(int)) {
@@ -551,7 +546,7 @@ mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz) {
bufread(header, NHEADER*sizeof(int), buffer_sz, buffer, &ptrbuf); bufread(header, NHEADER*sizeof(int), buffer_sz, buffer, &ptrbuf);
// check header // check header
int expected_header[NHEADER] = {ID, sizeof(mjtNum), getnint(), getnbuffer(), getnptr()}; int expected_header[NHEADER] = {ID, sizeof(mjtNum), getnsize(), mj_version(), getnptr()};
for (int i=0; i < NHEADER; i++) { for (int i=0; i < NHEADER; i++) {
if (header[i] != expected_header[i]) { if (header[i] != expected_header[i]) {
switch (i) { switch (i) {
@@ -564,11 +559,11 @@ mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz) {
return NULL; return NULL;
case 2: case 2:
mju_warning("Model and executable have different number of ints in mjModel"); mju_warning("Model and executable have different number of sizes in mjModel");
return NULL; return NULL;
case 3: case 3:
mju_warning("Model and executable have different number of size_t members in mjModel"); mju_warning("Model and executable use different MuJoCo version");
return NULL; return NULL;
default: default:
@@ -578,35 +573,39 @@ mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz) {
} }
} }
if (ptrbuf + sizeof(int)*getnint() + sizeof(mjtSize)*getnbuffer() > buffer_sz) { int nsize = getnsize(); // number of mjtSize fields in mjModel
if (ptrbuf + sizeof(mjtSize)*nsize > buffer_sz) {
mju_warning("Truncated model file - ran out of data while reading sizes"); mju_warning("Truncated model file - ran out of data while reading sizes");
return NULL; return NULL;
} }
// read mjModel construction fields // read mjModel construction fields
int ints[256]; mjtSize sizes[256];
bufread(ints, sizeof(int)*getnint(), buffer_sz, buffer, &ptrbuf); bufread(sizes, sizeof(mjtSize)*nsize, buffer_sz, buffer, &ptrbuf);
// allocate new mjModel // allocate new mjModel
mj_makeModel(&m, mj_makeModel(&m,
ints[0], ints[1], ints[2], ints[3], ints[4], ints[5], ints[6], sizes[0], sizes[1], sizes[2], sizes[3], sizes[4], sizes[5], sizes[6],
ints[7], ints[8], ints[9], ints[10], ints[11], ints[12], ints[13], sizes[7], sizes[8], sizes[9], sizes[10], sizes[11], sizes[12], sizes[13],
ints[14], ints[15], ints[16], ints[17], ints[18], ints[19], ints[20], sizes[14], sizes[15], sizes[16], sizes[17], sizes[18], sizes[19], sizes[20],
ints[21], ints[22], ints[23], ints[24], ints[25], ints[26], ints[27], sizes[21], sizes[22], sizes[23], sizes[24], sizes[25], sizes[26], sizes[27],
ints[28], ints[29], ints[30], ints[31], ints[32], ints[33], ints[34], sizes[28], sizes[29], sizes[30], sizes[31], sizes[32], sizes[33], sizes[34],
ints[35], ints[36], ints[37], ints[38], ints[39], ints[40], ints[41], sizes[35], sizes[36], sizes[37], sizes[38], sizes[39], sizes[40], sizes[41],
ints[42], ints[43], ints[44], ints[45], ints[46], ints[47], ints[48], sizes[42], sizes[43], sizes[44], sizes[45], sizes[46], sizes[47], sizes[48],
ints[49], ints[50], ints[51], ints[52], ints[53], ints[54], ints[55], sizes[49], sizes[50], sizes[51], sizes[52], sizes[53], sizes[54], sizes[55],
ints[56], ints[57], ints[58], ints[59], ints[60], ints[61], ints[62], sizes[56], sizes[57], sizes[58], sizes[59], sizes[60], sizes[61], sizes[62],
ints[63], ints[64], ints[65], ints[66], ints[67], ints[68], ints[69], sizes[63], sizes[64], sizes[65], sizes[66], sizes[67], sizes[68], sizes[69],
ints[70], ints[71], ints[72], ints[73], ints[74], ints[75], ints[76]); sizes[70], sizes[71], sizes[72], sizes[73], sizes[74], sizes[75], sizes[76]);
// read mjModel mjtSize fields // mj_makeModel may fail if the input buffer has invalid sizes
mjtSize sizes[8]; if (!m) {
bufread(sizes, sizeof(mjtSize)*getnbuffer(), buffer_sz, buffer, &ptrbuf); mju_warning("Invalid sizes, unable to load model");
return NULL;
}
// check mjtSize fields // check buffer size (last mjtSize field is nbuffer)
if (!m || m->nbuffer != sizes[getnbuffer()-1]) { if (m->nbuffer != sizes[nsize-1]) {
mju_warning("Corrupted model, wrong nbuffer field"); mju_warning("Corrupted model, wrong nbuffer field");
mj_deleteModel(m); mj_deleteModel(m);
return NULL; return NULL;
@@ -615,10 +614,9 @@ mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz) {
// set integer fields // set integer fields
{ {
int int_idx = 0; int int_idx = 0;
int size_idx = 0;
#define X(name) \ #define X(name) \
m->name = _Generic(m->name, mjtSize: sizes[size_idx++], default: ints[int_idx++]); m->name = sizes[int_idx++];
MJMODEL_INTS MJMODEL_SIZES
#undef X #undef X
} }
@@ -675,8 +673,8 @@ void mj_deleteModel(mjModel* m) {
// size of buffer needed to hold model // size of buffer needed to hold model
mjtSize mj_sizeModel(const mjModel* m) { mjtSize mj_sizeModel(const mjModel* m) {
mjtSize size = ( mjtSize size = (
sizeof(int)*(NHEADER+getnint()) sizeof(int)*NHEADER
+ sizeof(mjtSize)*getnbuffer() + sizeof(mjtSize)*getnsize()
+ sizeof(mjOption) + sizeof(mjOption)
+ sizeof(mjVisual) + sizeof(mjVisual)
+ sizeof(mjStatistic)); + sizeof(mjStatistic));
@@ -1832,14 +1830,14 @@ const char* mj_validateReferences(const mjModel* m) {
} }
} }
for (int i=0; i < m->nhfield; i++) { for (int i=0; i < m->nhfield; i++) {
int hfield_adr = m->hfield_adr[i] + m->hfield_nrow[i]*m->hfield_ncol[i]; mjtSize hfield_adr = m->hfield_adr[i] + ((mjtSize) m->hfield_nrow[i]) * m->hfield_ncol[i];
if (hfield_adr > m->nhfielddata || m->hfield_adr[i] < 0) { if (hfield_adr > m->nhfielddata || m->hfield_adr[i] < 0) {
return "Invalid model: hfield_adr out of bounds."; return "Invalid model: hfield_adr out of bounds.";
} }
} }
for (int i=0; i < m->ntex; i++) { for (int i=0; i < m->ntex; i++) {
int tex_adr = m->tex_adr[i] + m->tex_nchannel[i]*m->tex_height[i]*m->tex_width[i]; mjtSize nbytes = ((mjtSize) m->tex_nchannel[i]) * m->tex_height[i] * m->tex_width[i];
if (tex_adr > m->ntexdata || m->tex_adr[i] < 0) { if (m->tex_adr[i] + nbytes > m->ntexdata || m->tex_adr[i] < 0) {
return "Invalid model: tex_adr out of bounds."; return "Invalid model: tex_adr out of bounds.";
} }
} }
+16 -12
View File
@@ -48,18 +48,22 @@ void mj_defaultStatistic(mjStatistic* stat);
// allocate mjModel // allocate mjModel
void mj_makeModel(mjModel** dest, void mj_makeModel(mjModel** dest,
int nq, int nv, int nu, int na, int nbody, int nbvh, int nbvhstatic, int nbvhdynamic, int noct, mjtSize nq, mjtSize nv, mjtSize nu, mjtSize na, mjtSize nbody, mjtSize nbvh, mjtSize nbvhstatic,
int njnt, int ntree, int nM, int nB, int nC, int nD, int ngeom, int nsite, int ncam, int nlight, mjtSize nbvhdynamic, mjtSize noct, mjtSize njnt, mjtSize ntree, mjtSize nM, mjtSize nB,
int nflex, int nflexnode, int nflexvert, int nflexedge, int nflexelem, int nflexelemdata, mjtSize nC, mjtSize nD, mjtSize ngeom, mjtSize nsite, mjtSize ncam, mjtSize nlight,
int nflexelemedge, int nflexshelldata, int nflexevpair, int nflextexcoord, int nJfe, int nJfv, mjtSize nflex, mjtSize nflexnode, mjtSize nflexvert, mjtSize nflexedge, mjtSize nflexelem,
int nmesh, int nmeshvert, int nmeshnormal, int nmeshtexcoord, int nmeshface, int nmeshgraph, mjtSize nflexelemdata, mjtSize nflexelemedge, mjtSize nflexshelldata, mjtSize nflexevpair,
int nmeshpoly, int nmeshpolyvert, int nmeshpolymap, int nskin, int nskinvert, int nskintexvert, mjtSize nflextexcoord, mjtSize nJfe, mjtSize nJfv, mjtSize nmesh, mjtSize nmeshvert,
int nskinface, int nskinbone, int nskinbonevert, int nhfield, int nhfielddata, int ntex, mjtSize nmeshnormal, mjtSize nmeshtexcoord, mjtSize nmeshface, mjtSize nmeshgraph,
int ntexdata, int nmat, int npair, int nexclude, int neq, int ntendon, int nwrap, int nsensor, mjtSize nmeshpoly, mjtSize nmeshpolyvert, mjtSize nmeshpolymap, mjtSize nskin,
int nnumeric, int nnumericdata, int ntext, int ntextdata, int ntuple, int ntupledata, int nkey, mjtSize nskinvert, mjtSize nskintexvert, mjtSize nskinface, mjtSize nskinbone,
int nmocap, int nplugin, int npluginattr, int nuser_body, int nuser_jnt, int nuser_geom, mjtSize nskinbonevert, mjtSize nhfield, mjtSize nhfielddata, mjtSize ntex, mjtSize ntexdata,
int nuser_site, int nuser_cam, int nuser_tendon, int nuser_actuator, int nuser_sensor, mjtSize nmat, mjtSize npair, mjtSize nexclude, mjtSize neq, mjtSize ntendon, mjtSize nwrap,
int nnames, int npaths); mjtSize nsensor, mjtSize nnumeric, mjtSize nnumericdata, mjtSize ntext, mjtSize ntextdata,
mjtSize ntuple, mjtSize ntupledata, mjtSize nkey, mjtSize nmocap, mjtSize nplugin,
mjtSize npluginattr, mjtSize nuser_body, mjtSize nuser_jnt, mjtSize nuser_geom,
mjtSize nuser_site, mjtSize nuser_cam, mjtSize nuser_tendon, mjtSize nuser_actuator,
mjtSize nuser_sensor, mjtSize nnames, mjtSize npaths);
// copy mjModel; allocate new if dest is NULL // copy mjModel; allocate new if dest is NULL
MJAPI mjModel* mj_copyModel(mjModel* dest, const mjModel* src); MJAPI mjModel* mj_copyModel(mjModel* dest, const mjModel* src);
+3 -2
View File
@@ -551,7 +551,7 @@ void mj_printFormattedModel(const mjModel* m, const char* filename, const char*
fprintf(fp, "\n"); \ fprintf(fp, "\n"); \
} }
MJMODEL_INTS MJMODEL_SIZES
#undef X #undef X
fprintf(fp, "\n"); fprintf(fp, "\n");
@@ -636,7 +636,7 @@ void mj_printFormattedModel(const mjModel* m, const char* filename, const char*
(void)nu; (void)nu;
(void)nmocap; (void)nmocap;
const int* object_class; const mjtSize* object_class;
#define X(type, name, num, sz) \ #define X(type, name, num, sz) \
if (&m->num == object_class && sz > 0) { \ if (&m->num == object_class && sz > 0) { \
@@ -645,6 +645,7 @@ void mj_printFormattedModel(const mjModel* m, const char* filename, const char*
float: float_format, \ float: float_format, \
int: INT_FORMAT, \ int: INT_FORMAT, \
mjtByte: INT_FORMAT, \ mjtByte: INT_FORMAT, \
mjtSize: SIZE_FORMAT, \
default: NULL); \ default: NULL); \
if (format) { \ if (format) { \
fprintf(fp, " "); \ fprintf(fp, " "); \
+2 -1
View File
@@ -14,6 +14,7 @@
#include "engine/engine_support.h" #include "engine/engine_support.h"
#include <inttypes.h> // IWYU pragma: keep
#include <stddef.h> #include <stddef.h>
#include <mujoco/mjdata.h> #include <mujoco/mjdata.h>
@@ -343,7 +344,7 @@ void mj_copyState(const mjModel* m, const mjData* src, mjData* dst, int sig) {
void mj_setKeyframe(mjModel* m, const mjData* d, int k) { void mj_setKeyframe(mjModel* m, const mjData* d, int k) {
// check keyframe index // check keyframe index
if (k >= m->nkey) { if (k >= m->nkey) {
mjERROR("index must be smaller than %d (keyframes allocated in model)", m->nkey); mjERROR("index must be smaller than %" PRId64 " (keyframes allocated in model)", m->nkey);
} }
if (k < 0) { if (k < 0) {
mjERROR("keyframe index cannot be negative"); mjERROR("keyframe index cannot be negative");
+3 -2
View File
@@ -14,6 +14,7 @@
#include "render/render_context.h" #include "render/render_context.h"
#include <inttypes.h> // IWYU pragma: keep
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -1308,7 +1309,7 @@ static void makeMaterial(const mjModel* m, mjrContext* con) {
for (int i=0; i < m->ntex; i++) { for (int i=0; i < m->ntex; i++) {
if (m->tex_type[i] == mjTEXTURE_SKYBOX) { if (m->tex_type[i] == mjTEXTURE_SKYBOX) {
if (m->nmat >= mjMAXMATERIAL-2) { if (m->nmat >= mjMAXMATERIAL-2) {
mju_error("With skybox, maximum number of materials is %d, got %d", mju_error("With skybox, maximum number of materials is %d, got %" PRId64,
mjMAXMATERIAL-1, m->nmat); mjMAXMATERIAL-1, m->nmat);
} }
for (int j=0; j < mjNTEXROLE; j++) { for (int j=0; j < mjNTEXROLE; j++) {
@@ -1321,7 +1322,7 @@ static void makeMaterial(const mjModel* m, mjrContext* con) {
} }
if (m->nmat >= mjMAXMATERIAL-1) { if (m->nmat >= mjMAXMATERIAL-1) {
mju_error("Maximum number of materials is %d, got %d", mjMAXMATERIAL, m->nmat); mju_error("Maximum number of materials is %d, got %" PRId64, mjMAXMATERIAL, m->nmat);
} }
for (int i=0; i < m->nmat; i++) { for (int i=0; i < m->nmat; i++) {
if (m->mat_texid[i*mjNTEXROLE + mjTEXROLE_RGB] >= 0) { if (m->mat_texid[i*mjNTEXROLE + mjTEXROLE_RGB] >= 0) {
+34 -16
View File
@@ -2218,28 +2218,45 @@ void mjCModel::SetSizes() {
} }
// nhfielddata // nhfielddata
for (int i=0; i < nhfield; i++)nhfielddata += hfields_[i]->nrow * hfields_[i]->ncol; for (int i=0; i < nhfield; i++) {
nhfielddata += static_cast<mjtSize>(hfields_[i]->nrow) * hfields_[i]->ncol;
}
// ntexdata // ntexdata
for (int i=0; i < ntex; i++)ntexdata += textures_[i]->nchannel * textures_[i]->width * textures_[i]->height; for (int i=0; i < ntex; i++) {
const mjCTexture* tex = textures_[i];
ntexdata += static_cast<mjtSize>(tex->nchannel) * tex->width * tex->height;
}
// nwrap // nwrap
for (int i=0; i < ntendon; i++)nwrap += (int)tendons_[i]->path.size(); for (int i=0; i < ntendon; i++) {
nwrap += (int)tendons_[i]->path.size();
}
// nsensordata // nsensordata
for (int i=0; i < nsensor; i++)nsensordata += sensors_[i]->dim; for (int i=0; i < nsensor; i++) {
nsensordata += sensors_[i]->dim;
}
// nnumericdata // nnumericdata
for (int i=0; i < nnumeric; i++)nnumericdata += numerics_[i]->size; for (int i=0; i < nnumeric; i++) {
nnumericdata += numerics_[i]->size;
}
// ntextdata // ntextdata
for (int i=0; i < ntext; i++)ntextdata += (int)texts_[i]->data_.size() + 1; for (int i=0; i < ntext; i++) {
ntextdata += (int)texts_[i]->data_.size() + 1;
}
// ntupledata // ntupledata
for (int i=0; i < ntuple; i++)ntupledata += (int)tuples_[i]->objtype_.size(); for (int i=0; i < ntuple; i++) {
ntupledata += (int)tuples_[i]->objtype_.size();
}
// npluginattr // npluginattr
for (int i=0; i < nplugin; i++)npluginattr += (int)plugins_[i]->flattened_attributes.size(); for (int i=0; i < nplugin; i++) {
npluginattr += (int)plugins_[i]->flattened_attributes.size();
}
// nnames // nnames
nnames = (int)modelname_.size() + 1; nnames = (int)modelname_.size() + 1;
@@ -3185,10 +3202,10 @@ int mjCModel::CountNJmom(const mjModel* m) {
// copy objects outside kinematic tree // copy objects outside kinematic tree
void mjCModel::CopyObjects(mjModel* m) { void mjCModel::CopyObjects(mjModel* m) {
int adr, bone_adr, vert_adr, node_adr, normal_adr, face_adr, texcoord_adr, oct_adr; mjtSize adr, bone_adr, vert_adr, node_adr, normal_adr, face_adr, texcoord_adr, oct_adr;
int edge_adr, elem_adr, elemdata_adr, elemedge_adr, shelldata_adr, evpair_adr; mjtSize edge_adr, elem_adr, elemdata_adr, elemedge_adr, shelldata_adr, evpair_adr;
int bonevert_adr, graph_adr, data_adr, bvh_adr; mjtSize bonevert_adr, graph_adr, data_adr, bvh_adr;
int poly_adr, polymap_adr, polyvert_adr; mjtSize poly_adr, polymap_adr, polyvert_adr;
// sizes outside call to mj_makeModel // sizes outside call to mj_makeModel
m->nemax = nemax; m->nemax = nemax;
@@ -3556,7 +3573,8 @@ void mjCModel::CopyObjects(mjModel* m) {
m->hfield_adr[i] = data_adr; m->hfield_adr[i] = data_adr;
// copy elevation data // copy elevation data
memcpy(m->hfield_data + data_adr, phf->data.data(), phf->nrow*phf->ncol*sizeof(float)); memcpy(m->hfield_data + data_adr, phf->data.data(),
static_cast<mjtSize>(phf->nrow) * phf->ncol * sizeof(float));
// advance counter // advance counter
data_adr += phf->nrow*phf->ncol; data_adr += phf->nrow*phf->ncol;
@@ -3577,11 +3595,11 @@ void mjCModel::CopyObjects(mjModel* m) {
m->tex_adr[i] = data_adr; m->tex_adr[i] = data_adr;
// copy rgb data // copy rgb data
memcpy(m->tex_data + data_adr, ptex->data_.data(), mjtSize nbytes = static_cast<mjtSize>(ptex->nchannel) * ptex->width * ptex->height;
ptex->nchannel * ptex->width * ptex->height); memcpy(m->tex_data + data_adr, ptex->data_.data(), nbytes);
// advance counter // advance counter
data_adr += ptex->nchannel * ptex->width * ptex->height; data_adr += nbytes;
} }
// materials // materials
+71 -71
View File
@@ -54,81 +54,81 @@ class mjCModel_ : public mjsElement {
std::string suffix; std::string suffix;
protected: protected:
bool compiled; // already compiled flag bool compiled; // already compiled flag
// sizes set from object list lengths // sizes set from object list lengths
int nbody; // number of bodies mjtSize nbody; // number of bodies
int njnt; // number of joints mjtSize njnt; // number of joints
int ngeom; // number of geoms mjtSize ngeom; // number of geoms
int nsite; // number of sites mjtSize nsite; // number of sites
int ncam; // number of cameras mjtSize ncam; // number of cameras
int nlight; // number of lights mjtSize nlight; // number of lights
int nflex; // number of flexes mjtSize nflex; // number of flexes
int nmesh; // number of meshes mjtSize nmesh; // number of meshes
int nskin; // number of skins mjtSize nskin; // number of skins
int nhfield; // number of height fields mjtSize nhfield; // number of height fields
int ntex; // number of textures mjtSize ntex; // number of textures
int nmat; // number of materials mjtSize nmat; // number of materials
int npair; // number of geom pairs in pair array mjtSize npair; // number of geom pairs in pair array
int nexclude; // number of excluded body pairs mjtSize nexclude; // number of excluded body pairs
int neq; // number of equality constraints mjtSize neq; // number of equality constraints
int ntendon; // number of tendons mjtSize ntendon; // number of tendons
int nsensor; // number of sensors mjtSize nsensor; // number of sensors
int nnumeric; // number of numeric fields mjtSize nnumeric; // number of numeric fields
int ntext; // number of text fields mjtSize ntext; // number of text fields
int ntuple; // number of tuple fields mjtSize ntuple; // number of tuple fields
int nmocap; // number of mocap bodies mjtSize nmocap; // number of mocap bodies
int nplugin; // number of plugin instances mjtSize nplugin; // number of plugin instances
// sizes computed by Compile // sizes computed by Compile
int nq; // number of generalized coordinates = dim(qpos) mjtSize nq; // number of generalized coordinates = dim(qpos)
int nv; // number of degrees of freedom = dim(qvel) mjtSize nv; // number of degrees of freedom = dim(qvel)
int nu; // number of actuators/controls mjtSize nu; // number of actuators/controls
int na; // number of activation variables mjtSize na; // number of activation variables
int ntree; // number of trees mjtSize ntree; // number of trees
int nbvh; // number of total boundary volume hierarchies mjtSize nbvh; // number of total boundary volume hierarchies
int nbvhstatic; // number of static boundary volume hierarchies mjtSize nbvhstatic; // number of static boundary volume hierarchies
int nbvhdynamic; // number of dynamic boundary volume hierarchies mjtSize nbvhdynamic; // number of dynamic boundary volume hierarchies
int noct; // number of total octree cells mjtSize noct; // number of total octree cells
int nflexnode; // number of nodes in all flexes mjtSize nflexnode; // number of nodes in all flexes
int nflexvert; // number of vertices in all flexes mjtSize nflexvert; // number of vertices in all flexes
int nflexedge; // number of edges in all flexes mjtSize nflexedge; // number of edges in all flexes
int nflexelem; // number of elements in all flexes mjtSize nflexelem; // number of elements in all flexes
int nflexelemdata; // number of element vertex ids in all flexes mjtSize nflexelemdata; // number of element vertex ids in all flexes
int nflexelemedge; // number of element edges in all flexes mjtSize nflexelemedge; // number of element edges in all flexes
int nflexshelldata; // number of shell fragment vertex ids in all flexes mjtSize nflexshelldata; // number of shell fragment vertex ids in all flexes
int nflexevpair; // number of element-vertex pairs in all flexes mjtSize nflexevpair; // number of element-vertex pairs in all flexes
int nflextexcoord; // number of vertex texture coordinates in all flexes mjtSize nflextexcoord; // number of vertex texture coordinates in all flexes
int nJfe; // number of non-zeros in sparse flex edge constraint Jacobian mjtSize nJfe; // number of non-zeros in sparse flex edge constraint Jacobian
int nJfv; // number of non-zeros in sparse flex vertex constraint Jacobian mjtSize nJfv; // number of non-zeros in sparse flex vertex constraint Jacobian
int nmeshvert; // number of vertices in all meshes mjtSize nmeshvert; // number of vertices in all meshes
int nmeshnormal; // number of normals in all meshes mjtSize nmeshnormal; // number of normals in all meshes
int nmeshtexcoord; // number of texture coordinates in all meshes mjtSize nmeshtexcoord; // number of texture coordinates in all meshes
int nmeshface; // number of triangular faces in all meshes mjtSize nmeshface; // number of triangular faces in all meshes
int nmeshpoly; // number of polygon faces in all meshes mjtSize nmeshpoly; // number of polygon faces in all meshes
int nmeshgraph; // number of ints in mesh auxiliary data mjtSize nmeshgraph; // number of ints in mesh auxiliary data
int nmeshpolyvert; // number of vertices in all polygon faces mjtSize nmeshpolyvert; // number of vertices in all polygon faces
int nmeshpolymap; // number of polygons in vertex map mjtSize nmeshpolymap; // number of polygons in vertex map
int nskinvert; // number of vertices in all skins mjtSize nskinvert; // number of vertices in all skins
int nskintexvert; // number of vertices with texcoord in all skins mjtSize nskintexvert; // number of vertices with texcoord in all skins
int nskinface; // number of faces in all skins mjtSize nskinface; // number of faces in all skins
int nskinbone; // number of bones in all skins mjtSize nskinbone; // number of bones in all skins
int nskinbonevert; // number of vertices in all skins mjtSize nskinbonevert; // number of vertices in all skins
int nhfielddata; // number of data points in all hfields mjtSize nhfielddata; // number of data points in all hfields
int ntexdata; // number of texture bytes mjtSize ntexdata; // number of texture bytes
int nwrap; // number of wrap objects in all tendon paths mjtSize nwrap; // number of wrap objects in all tendon paths
int nsensordata; // number of mjtNums in sensor data vector mjtSize nsensordata; // number of mjtNums in sensor data vector
int nnumericdata; // number of mjtNums in all custom fields mjtSize nnumericdata; // number of mjtNums in all custom fields
int ntextdata; // number of chars in all text fields, including 0 mjtSize ntextdata; // number of chars in all text fields, including 0
int ntupledata; // number of objects in all tuple fields mjtSize ntupledata; // number of objects in all tuple fields
int npluginattr; // number of chars in all plugin config attributes mjtSize npluginattr; // number of chars in all plugin config attributes
int nnames; // number of chars in all names mjtSize nnames; // number of chars in all names
int npaths; // number of chars in all paths mjtSize npaths; // number of chars in all paths
int nM; // number of non-zeros in sparse inertia matrix mjtSize nM; // number of non-zeros in sparse inertia matrix
int nB; // number of non-zeros in sparse body-dof matrix mjtSize nB; // number of non-zeros in sparse body-dof matrix
int nC; // number of non-zeros in reduced sparse dof-dof matrix mjtSize nC; // number of non-zeros in reduced sparse dof-dof matrix
int nD; // number of non-zeros in sparse dof-dof matrix mjtSize nD; // number of non-zeros in sparse dof-dof matrix
int nJmom; // number of non-zeros in sparse actuator_moment matrix mjtSize nJmom; // number of non-zeros in sparse actuator_moment matrix
// statistics, as computed by mj_setConst // statistics, as computed by mj_setConst
double meaninertia_auto; // mean diagonal inertia, as computed by mj_setConst double meaninertia_auto; // mean diagonal inertia, as computed by mj_setConst
+5 -5
View File
@@ -4825,7 +4825,7 @@ void mjCTexture::BuiltinCube(void) {
if (w > std::numeric_limits<int>::max() / w) { if (w > std::numeric_limits<int>::max() / w) {
throw mjCError(this, "Cube texture width is too large."); throw mjCError(this, "Cube texture width is too large.");
} }
int ww = width*width; mjtSize ww = width*width;
// convert fixed colors // convert fixed colors
for (int j = 0; j < 3; j++) { for (int j = 0; j < 3; j++) {
@@ -4838,7 +4838,7 @@ void mjCTexture::BuiltinCube(void) {
// gradient // gradient
if (builtin == mjBUILTIN_GRADIENT) { if (builtin == mjBUILTIN_GRADIENT) {
if (ww > std::numeric_limits<int>::max() / 18) { if (ww > std::numeric_limits<std::int64_t>::max() / 18) {
throw mjCError(this, "Gradient texture width is too large."); throw mjCError(this, "Gradient texture width is too large.");
} }
for (int r = 0; r < w; r++) { for (int r = 0; r < w; r++) {
@@ -5176,7 +5176,7 @@ void mjCTexture::LoadCubeSingle(std::string filename, const mjVFS* vfs) {
// allocate data // allocate data
std::int64_t size = static_cast<std::int64_t>(width)*height; std::int64_t size = static_cast<std::int64_t>(width)*height;
if (size >= std::numeric_limits<int>::max() / 3 || size <= 0) { if (size >= std::numeric_limits<std::int64_t>::max() / 3 || size <= 0) {
throw mjCError(this, "Cube texture too large"); throw mjCError(this, "Cube texture too large");
} }
try { try {
@@ -5293,7 +5293,7 @@ void mjCTexture::LoadCubeSeparate(const mjVFS* vfs) {
} }
height = 6*width; height = 6*width;
std::int64_t size = static_cast<std::int64_t>(width)*height; std::int64_t size = static_cast<std::int64_t>(width)*height;
if (size >= std::numeric_limits<int>::max() / 3 || size <= 0) { if (size >= std::numeric_limits<mjtSize>::max() / 3 || size <= 0) {
throw mjCError(this, "PNG texture too large"); throw mjCError(this, "PNG texture too large");
} }
try { try {
@@ -5378,7 +5378,7 @@ void mjCTexture::Compile(const mjVFS* vfs) {
} }
std::int64_t size = static_cast<std::int64_t>(width)*height; std::int64_t size = static_cast<std::int64_t>(width)*height;
if (size >= std::numeric_limits<int>::max() / nchannel || size <= 0) { if (size >= std::numeric_limits<int64_t>::max() / nchannel || size <= 0) {
throw mjCError(this, "Builtin texture too large"); throw mjCError(this, "Builtin texture too large");
} }
// allocate data // allocate data
+5 -1
View File
@@ -203,6 +203,10 @@ auto Compare(unsigned char val1, unsigned char val2) {
return val1 != val2; return val1 != val2;
} }
auto Compare(mjtSize val1, mjtSize val2) {
return val1 > val2 ? val1 - val2 : val2 - val1;
}
// The maximum spacing between a normalised floating point number x and an // The maximum spacing between a normalised floating point number x and an
// adjacent normalised number is 2 epsilon |x|; a factor 10 is added accounting // adjacent normalised number is 2 epsilon |x|; a factor 10 is added accounting
// for losses during non-idempotent operations such as vector normalizations. // for losses during non-idempotent operations such as vector normalizations.
@@ -245,7 +249,7 @@ mjtNum CompareModel(const mjModel* m1, const mjModel* m2,
field = #name; \ field = #name; \
} \ } \
} }
MJMODEL_INTS MJMODEL_SIZES
#undef X #undef X
if (maxdif > 0) return maxdif; if (maxdif > 0) return maxdif;
+1 -1
View File
@@ -126,7 +126,7 @@ TEST_F(HeaderTest, MjModelIntsOrdered) {
std::vector<std::pair<const void*, const char*>> ints; std::vector<std::pair<const void*, const char*>> ints;
#define X(name) ints.push_back({static_cast<const void*>(&m.name), #name}); #define X(name) ints.push_back({static_cast<const void*>(&m.name), #name});
MJMODEL_INTS MJMODEL_SIZES
#undef X #undef X
CheckAddressOrdering(ints, "MJMODEL_INT"); CheckAddressOrdering(ints, "MJMODEL_INT");
+5 -28
View File
@@ -892,11 +892,11 @@ TEST_F(XMLReaderTest, LargeTextureTest) {
<mujoco> <mujoco>
<asset> <asset>
<!-- <!--
Use a texture width that exceeds the maximum texture size. For cube Use a texture width that exceeds the size representable by an int.
textures, the height is ignored and set to width*6. The default number of For cube textures, the height is ignored and set to width*6.
channels is 3. The default number of channels is 3.
The width in this test is chosen so that 6*width*width*3 is too large to The width in this test is chosen so that 6*width*width*3 is too large to
be represented as an integer. be represented as a 32-bit integer.
--> -->
<texture name="tex" builtin="gradient" width="10923" height="2"/> <texture name="tex" builtin="gradient" width="10923" height="2"/>
</asset> </asset>
@@ -906,30 +906,7 @@ TEST_F(XMLReaderTest, LargeTextureTest) {
std::array<char, 1024> error; std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size()); mjModel* model = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(model, IsNull()); EXPECT_THAT(model, NotNull());
mj_deleteModel(model);
}
TEST_F(XMLReaderTest, HugeTextureTest) {
static constexpr char xml[] = R"(
<mujoco>
<asset>
<!--
Use a texture width that exceeds the maximum texture size. For cube
textures, the height is ignored and set to width*6. The default number of
channels is 3.
The width in this test is chosen so that 6*width*width*3 is so large that
it overflows and becomes a positive integer.
-->
<texture name="tex" builtin="gradient" width="15447" height="2"/>
</asset>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
EXPECT_THAT(model, IsNull());
mj_deleteModel(model); mj_deleteModel(model);
} }
+86 -86
View File
@@ -5286,92 +5286,92 @@ public unsafe struct mjStatistic_ {
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public unsafe struct mjModel_ { public unsafe struct mjModel_ {
public int nq; public Int64 nq;
public int nv; public Int64 nv;
public int nu; public Int64 nu;
public int na; public Int64 na;
public int nbody; public Int64 nbody;
public int nbvh; public Int64 nbvh;
public int nbvhstatic; public Int64 nbvhstatic;
public int nbvhdynamic; public Int64 nbvhdynamic;
public int noct; public Int64 noct;
public int njnt; public Int64 njnt;
public int ntree; public Int64 ntree;
public int nM; public Int64 nM;
public int nB; public Int64 nB;
public int nC; public Int64 nC;
public int nD; public Int64 nD;
public int ngeom; public Int64 ngeom;
public int nsite; public Int64 nsite;
public int ncam; public Int64 ncam;
public int nlight; public Int64 nlight;
public int nflex; public Int64 nflex;
public int nflexnode; public Int64 nflexnode;
public int nflexvert; public Int64 nflexvert;
public int nflexedge; public Int64 nflexedge;
public int nflexelem; public Int64 nflexelem;
public int nflexelemdata; public Int64 nflexelemdata;
public int nflexelemedge; public Int64 nflexelemedge;
public int nflexshelldata; public Int64 nflexshelldata;
public int nflexevpair; public Int64 nflexevpair;
public int nflextexcoord; public Int64 nflextexcoord;
public int nJfe; public Int64 nJfe;
public int nJfv; public Int64 nJfv;
public int nmesh; public Int64 nmesh;
public int nmeshvert; public Int64 nmeshvert;
public int nmeshnormal; public Int64 nmeshnormal;
public int nmeshtexcoord; public Int64 nmeshtexcoord;
public int nmeshface; public Int64 nmeshface;
public int nmeshgraph; public Int64 nmeshgraph;
public int nmeshpoly; public Int64 nmeshpoly;
public int nmeshpolyvert; public Int64 nmeshpolyvert;
public int nmeshpolymap; public Int64 nmeshpolymap;
public int nskin; public Int64 nskin;
public int nskinvert; public Int64 nskinvert;
public int nskintexvert; public Int64 nskintexvert;
public int nskinface; public Int64 nskinface;
public int nskinbone; public Int64 nskinbone;
public int nskinbonevert; public Int64 nskinbonevert;
public int nhfield; public Int64 nhfield;
public int nhfielddata; public Int64 nhfielddata;
public int ntex; public Int64 ntex;
public int ntexdata; public Int64 ntexdata;
public int nmat; public Int64 nmat;
public int npair; public Int64 npair;
public int nexclude; public Int64 nexclude;
public int neq; public Int64 neq;
public int ntendon; public Int64 ntendon;
public int nwrap; public Int64 nwrap;
public int nsensor; public Int64 nsensor;
public int nnumeric; public Int64 nnumeric;
public int nnumericdata; public Int64 nnumericdata;
public int ntext; public Int64 ntext;
public int ntextdata; public Int64 ntextdata;
public int ntuple; public Int64 ntuple;
public int ntupledata; public Int64 ntupledata;
public int nkey; public Int64 nkey;
public int nmocap; public Int64 nmocap;
public int nplugin; public Int64 nplugin;
public int npluginattr; public Int64 npluginattr;
public int nuser_body; public Int64 nuser_body;
public int nuser_jnt; public Int64 nuser_jnt;
public int nuser_geom; public Int64 nuser_geom;
public int nuser_site; public Int64 nuser_site;
public int nuser_cam; public Int64 nuser_cam;
public int nuser_tendon; public Int64 nuser_tendon;
public int nuser_actuator; public Int64 nuser_actuator;
public int nuser_sensor; public Int64 nuser_sensor;
public int nnames; public Int64 nnames;
public int npaths; public Int64 npaths;
public int nnames_map; public Int64 nnames_map;
public int nJmom; public Int64 nJmom;
public int ngravcomp; public Int64 ngravcomp;
public int nemax; public Int64 nemax;
public int njmax; public Int64 njmax;
public int nconmax; public Int64 nconmax;
public int nuserdata; public Int64 nuserdata;
public int nsensordata; public Int64 nsensordata;
public int npluginstate; public Int64 npluginstate;
public Int64 narena; public Int64 narena;
public Int64 nbuffer; public Int64 nbuffer;
public mjOption_ opt; public mjOption_ opt;
+204 -204
View File
@@ -3410,532 +3410,532 @@ struct MjModel {
mjModel* get() const; mjModel* get() const;
void set(mjModel* ptr); void set(mjModel* ptr);
int nq() const { int nq() const {
return ptr_->nq; return static_cast<int>(ptr_->nq);
} }
void set_nq(int value) { void set_nq(int value) {
ptr_->nq = value; ptr_->nq = static_cast<mjtSize>(value);
} }
int nv() const { int nv() const {
return ptr_->nv; return static_cast<int>(ptr_->nv);
} }
void set_nv(int value) { void set_nv(int value) {
ptr_->nv = value; ptr_->nv = static_cast<mjtSize>(value);
} }
int nu() const { int nu() const {
return ptr_->nu; return static_cast<int>(ptr_->nu);
} }
void set_nu(int value) { void set_nu(int value) {
ptr_->nu = value; ptr_->nu = static_cast<mjtSize>(value);
} }
int na() const { int na() const {
return ptr_->na; return static_cast<int>(ptr_->na);
} }
void set_na(int value) { void set_na(int value) {
ptr_->na = value; ptr_->na = static_cast<mjtSize>(value);
} }
int nbody() const { int nbody() const {
return ptr_->nbody; return static_cast<int>(ptr_->nbody);
} }
void set_nbody(int value) { void set_nbody(int value) {
ptr_->nbody = value; ptr_->nbody = static_cast<mjtSize>(value);
} }
int nbvh() const { int nbvh() const {
return ptr_->nbvh; return static_cast<int>(ptr_->nbvh);
} }
void set_nbvh(int value) { void set_nbvh(int value) {
ptr_->nbvh = value; ptr_->nbvh = static_cast<mjtSize>(value);
} }
int nbvhstatic() const { int nbvhstatic() const {
return ptr_->nbvhstatic; return static_cast<int>(ptr_->nbvhstatic);
} }
void set_nbvhstatic(int value) { void set_nbvhstatic(int value) {
ptr_->nbvhstatic = value; ptr_->nbvhstatic = static_cast<mjtSize>(value);
} }
int nbvhdynamic() const { int nbvhdynamic() const {
return ptr_->nbvhdynamic; return static_cast<int>(ptr_->nbvhdynamic);
} }
void set_nbvhdynamic(int value) { void set_nbvhdynamic(int value) {
ptr_->nbvhdynamic = value; ptr_->nbvhdynamic = static_cast<mjtSize>(value);
} }
int noct() const { int noct() const {
return ptr_->noct; return static_cast<int>(ptr_->noct);
} }
void set_noct(int value) { void set_noct(int value) {
ptr_->noct = value; ptr_->noct = static_cast<mjtSize>(value);
} }
int njnt() const { int njnt() const {
return ptr_->njnt; return static_cast<int>(ptr_->njnt);
} }
void set_njnt(int value) { void set_njnt(int value) {
ptr_->njnt = value; ptr_->njnt = static_cast<mjtSize>(value);
} }
int ntree() const { int ntree() const {
return ptr_->ntree; return static_cast<int>(ptr_->ntree);
} }
void set_ntree(int value) { void set_ntree(int value) {
ptr_->ntree = value; ptr_->ntree = static_cast<mjtSize>(value);
} }
int nM() const { int nM() const {
return ptr_->nM; return static_cast<int>(ptr_->nM);
} }
void set_nM(int value) { void set_nM(int value) {
ptr_->nM = value; ptr_->nM = static_cast<mjtSize>(value);
} }
int nB() const { int nB() const {
return ptr_->nB; return static_cast<int>(ptr_->nB);
} }
void set_nB(int value) { void set_nB(int value) {
ptr_->nB = value; ptr_->nB = static_cast<mjtSize>(value);
} }
int nC() const { int nC() const {
return ptr_->nC; return static_cast<int>(ptr_->nC);
} }
void set_nC(int value) { void set_nC(int value) {
ptr_->nC = value; ptr_->nC = static_cast<mjtSize>(value);
} }
int nD() const { int nD() const {
return ptr_->nD; return static_cast<int>(ptr_->nD);
} }
void set_nD(int value) { void set_nD(int value) {
ptr_->nD = value; ptr_->nD = static_cast<mjtSize>(value);
} }
int ngeom() const { int ngeom() const {
return ptr_->ngeom; return static_cast<int>(ptr_->ngeom);
} }
void set_ngeom(int value) { void set_ngeom(int value) {
ptr_->ngeom = value; ptr_->ngeom = static_cast<mjtSize>(value);
} }
int nsite() const { int nsite() const {
return ptr_->nsite; return static_cast<int>(ptr_->nsite);
} }
void set_nsite(int value) { void set_nsite(int value) {
ptr_->nsite = value; ptr_->nsite = static_cast<mjtSize>(value);
} }
int ncam() const { int ncam() const {
return ptr_->ncam; return static_cast<int>(ptr_->ncam);
} }
void set_ncam(int value) { void set_ncam(int value) {
ptr_->ncam = value; ptr_->ncam = static_cast<mjtSize>(value);
} }
int nlight() const { int nlight() const {
return ptr_->nlight; return static_cast<int>(ptr_->nlight);
} }
void set_nlight(int value) { void set_nlight(int value) {
ptr_->nlight = value; ptr_->nlight = static_cast<mjtSize>(value);
} }
int nflex() const { int nflex() const {
return ptr_->nflex; return static_cast<int>(ptr_->nflex);
} }
void set_nflex(int value) { void set_nflex(int value) {
ptr_->nflex = value; ptr_->nflex = static_cast<mjtSize>(value);
} }
int nflexnode() const { int nflexnode() const {
return ptr_->nflexnode; return static_cast<int>(ptr_->nflexnode);
} }
void set_nflexnode(int value) { void set_nflexnode(int value) {
ptr_->nflexnode = value; ptr_->nflexnode = static_cast<mjtSize>(value);
} }
int nflexvert() const { int nflexvert() const {
return ptr_->nflexvert; return static_cast<int>(ptr_->nflexvert);
} }
void set_nflexvert(int value) { void set_nflexvert(int value) {
ptr_->nflexvert = value; ptr_->nflexvert = static_cast<mjtSize>(value);
} }
int nflexedge() const { int nflexedge() const {
return ptr_->nflexedge; return static_cast<int>(ptr_->nflexedge);
} }
void set_nflexedge(int value) { void set_nflexedge(int value) {
ptr_->nflexedge = value; ptr_->nflexedge = static_cast<mjtSize>(value);
} }
int nflexelem() const { int nflexelem() const {
return ptr_->nflexelem; return static_cast<int>(ptr_->nflexelem);
} }
void set_nflexelem(int value) { void set_nflexelem(int value) {
ptr_->nflexelem = value; ptr_->nflexelem = static_cast<mjtSize>(value);
} }
int nflexelemdata() const { int nflexelemdata() const {
return ptr_->nflexelemdata; return static_cast<int>(ptr_->nflexelemdata);
} }
void set_nflexelemdata(int value) { void set_nflexelemdata(int value) {
ptr_->nflexelemdata = value; ptr_->nflexelemdata = static_cast<mjtSize>(value);
} }
int nflexelemedge() const { int nflexelemedge() const {
return ptr_->nflexelemedge; return static_cast<int>(ptr_->nflexelemedge);
} }
void set_nflexelemedge(int value) { void set_nflexelemedge(int value) {
ptr_->nflexelemedge = value; ptr_->nflexelemedge = static_cast<mjtSize>(value);
} }
int nflexshelldata() const { int nflexshelldata() const {
return ptr_->nflexshelldata; return static_cast<int>(ptr_->nflexshelldata);
} }
void set_nflexshelldata(int value) { void set_nflexshelldata(int value) {
ptr_->nflexshelldata = value; ptr_->nflexshelldata = static_cast<mjtSize>(value);
} }
int nflexevpair() const { int nflexevpair() const {
return ptr_->nflexevpair; return static_cast<int>(ptr_->nflexevpair);
} }
void set_nflexevpair(int value) { void set_nflexevpair(int value) {
ptr_->nflexevpair = value; ptr_->nflexevpair = static_cast<mjtSize>(value);
} }
int nflextexcoord() const { int nflextexcoord() const {
return ptr_->nflextexcoord; return static_cast<int>(ptr_->nflextexcoord);
} }
void set_nflextexcoord(int value) { void set_nflextexcoord(int value) {
ptr_->nflextexcoord = value; ptr_->nflextexcoord = static_cast<mjtSize>(value);
} }
int nJfe() const { int nJfe() const {
return ptr_->nJfe; return static_cast<int>(ptr_->nJfe);
} }
void set_nJfe(int value) { void set_nJfe(int value) {
ptr_->nJfe = value; ptr_->nJfe = static_cast<mjtSize>(value);
} }
int nJfv() const { int nJfv() const {
return ptr_->nJfv; return static_cast<int>(ptr_->nJfv);
} }
void set_nJfv(int value) { void set_nJfv(int value) {
ptr_->nJfv = value; ptr_->nJfv = static_cast<mjtSize>(value);
} }
int nmesh() const { int nmesh() const {
return ptr_->nmesh; return static_cast<int>(ptr_->nmesh);
} }
void set_nmesh(int value) { void set_nmesh(int value) {
ptr_->nmesh = value; ptr_->nmesh = static_cast<mjtSize>(value);
} }
int nmeshvert() const { int nmeshvert() const {
return ptr_->nmeshvert; return static_cast<int>(ptr_->nmeshvert);
} }
void set_nmeshvert(int value) { void set_nmeshvert(int value) {
ptr_->nmeshvert = value; ptr_->nmeshvert = static_cast<mjtSize>(value);
} }
int nmeshnormal() const { int nmeshnormal() const {
return ptr_->nmeshnormal; return static_cast<int>(ptr_->nmeshnormal);
} }
void set_nmeshnormal(int value) { void set_nmeshnormal(int value) {
ptr_->nmeshnormal = value; ptr_->nmeshnormal = static_cast<mjtSize>(value);
} }
int nmeshtexcoord() const { int nmeshtexcoord() const {
return ptr_->nmeshtexcoord; return static_cast<int>(ptr_->nmeshtexcoord);
} }
void set_nmeshtexcoord(int value) { void set_nmeshtexcoord(int value) {
ptr_->nmeshtexcoord = value; ptr_->nmeshtexcoord = static_cast<mjtSize>(value);
} }
int nmeshface() const { int nmeshface() const {
return ptr_->nmeshface; return static_cast<int>(ptr_->nmeshface);
} }
void set_nmeshface(int value) { void set_nmeshface(int value) {
ptr_->nmeshface = value; ptr_->nmeshface = static_cast<mjtSize>(value);
} }
int nmeshgraph() const { int nmeshgraph() const {
return ptr_->nmeshgraph; return static_cast<int>(ptr_->nmeshgraph);
} }
void set_nmeshgraph(int value) { void set_nmeshgraph(int value) {
ptr_->nmeshgraph = value; ptr_->nmeshgraph = static_cast<mjtSize>(value);
} }
int nmeshpoly() const { int nmeshpoly() const {
return ptr_->nmeshpoly; return static_cast<int>(ptr_->nmeshpoly);
} }
void set_nmeshpoly(int value) { void set_nmeshpoly(int value) {
ptr_->nmeshpoly = value; ptr_->nmeshpoly = static_cast<mjtSize>(value);
} }
int nmeshpolyvert() const { int nmeshpolyvert() const {
return ptr_->nmeshpolyvert; return static_cast<int>(ptr_->nmeshpolyvert);
} }
void set_nmeshpolyvert(int value) { void set_nmeshpolyvert(int value) {
ptr_->nmeshpolyvert = value; ptr_->nmeshpolyvert = static_cast<mjtSize>(value);
} }
int nmeshpolymap() const { int nmeshpolymap() const {
return ptr_->nmeshpolymap; return static_cast<int>(ptr_->nmeshpolymap);
} }
void set_nmeshpolymap(int value) { void set_nmeshpolymap(int value) {
ptr_->nmeshpolymap = value; ptr_->nmeshpolymap = static_cast<mjtSize>(value);
} }
int nskin() const { int nskin() const {
return ptr_->nskin; return static_cast<int>(ptr_->nskin);
} }
void set_nskin(int value) { void set_nskin(int value) {
ptr_->nskin = value; ptr_->nskin = static_cast<mjtSize>(value);
} }
int nskinvert() const { int nskinvert() const {
return ptr_->nskinvert; return static_cast<int>(ptr_->nskinvert);
} }
void set_nskinvert(int value) { void set_nskinvert(int value) {
ptr_->nskinvert = value; ptr_->nskinvert = static_cast<mjtSize>(value);
} }
int nskintexvert() const { int nskintexvert() const {
return ptr_->nskintexvert; return static_cast<int>(ptr_->nskintexvert);
} }
void set_nskintexvert(int value) { void set_nskintexvert(int value) {
ptr_->nskintexvert = value; ptr_->nskintexvert = static_cast<mjtSize>(value);
} }
int nskinface() const { int nskinface() const {
return ptr_->nskinface; return static_cast<int>(ptr_->nskinface);
} }
void set_nskinface(int value) { void set_nskinface(int value) {
ptr_->nskinface = value; ptr_->nskinface = static_cast<mjtSize>(value);
} }
int nskinbone() const { int nskinbone() const {
return ptr_->nskinbone; return static_cast<int>(ptr_->nskinbone);
} }
void set_nskinbone(int value) { void set_nskinbone(int value) {
ptr_->nskinbone = value; ptr_->nskinbone = static_cast<mjtSize>(value);
} }
int nskinbonevert() const { int nskinbonevert() const {
return ptr_->nskinbonevert; return static_cast<int>(ptr_->nskinbonevert);
} }
void set_nskinbonevert(int value) { void set_nskinbonevert(int value) {
ptr_->nskinbonevert = value; ptr_->nskinbonevert = static_cast<mjtSize>(value);
} }
int nhfield() const { int nhfield() const {
return ptr_->nhfield; return static_cast<int>(ptr_->nhfield);
} }
void set_nhfield(int value) { void set_nhfield(int value) {
ptr_->nhfield = value; ptr_->nhfield = static_cast<mjtSize>(value);
} }
int nhfielddata() const { int nhfielddata() const {
return ptr_->nhfielddata; return static_cast<int>(ptr_->nhfielddata);
} }
void set_nhfielddata(int value) { void set_nhfielddata(int value) {
ptr_->nhfielddata = value; ptr_->nhfielddata = static_cast<mjtSize>(value);
} }
int ntex() const { int ntex() const {
return ptr_->ntex; return static_cast<int>(ptr_->ntex);
} }
void set_ntex(int value) { void set_ntex(int value) {
ptr_->ntex = value; ptr_->ntex = static_cast<mjtSize>(value);
} }
int ntexdata() const { int ntexdata() const {
return ptr_->ntexdata; return static_cast<int>(ptr_->ntexdata);
} }
void set_ntexdata(int value) { void set_ntexdata(int value) {
ptr_->ntexdata = value; ptr_->ntexdata = static_cast<mjtSize>(value);
} }
int nmat() const { int nmat() const {
return ptr_->nmat; return static_cast<int>(ptr_->nmat);
} }
void set_nmat(int value) { void set_nmat(int value) {
ptr_->nmat = value; ptr_->nmat = static_cast<mjtSize>(value);
} }
int npair() const { int npair() const {
return ptr_->npair; return static_cast<int>(ptr_->npair);
} }
void set_npair(int value) { void set_npair(int value) {
ptr_->npair = value; ptr_->npair = static_cast<mjtSize>(value);
} }
int nexclude() const { int nexclude() const {
return ptr_->nexclude; return static_cast<int>(ptr_->nexclude);
} }
void set_nexclude(int value) { void set_nexclude(int value) {
ptr_->nexclude = value; ptr_->nexclude = static_cast<mjtSize>(value);
} }
int neq() const { int neq() const {
return ptr_->neq; return static_cast<int>(ptr_->neq);
} }
void set_neq(int value) { void set_neq(int value) {
ptr_->neq = value; ptr_->neq = static_cast<mjtSize>(value);
} }
int ntendon() const { int ntendon() const {
return ptr_->ntendon; return static_cast<int>(ptr_->ntendon);
} }
void set_ntendon(int value) { void set_ntendon(int value) {
ptr_->ntendon = value; ptr_->ntendon = static_cast<mjtSize>(value);
} }
int nwrap() const { int nwrap() const {
return ptr_->nwrap; return static_cast<int>(ptr_->nwrap);
} }
void set_nwrap(int value) { void set_nwrap(int value) {
ptr_->nwrap = value; ptr_->nwrap = static_cast<mjtSize>(value);
} }
int nsensor() const { int nsensor() const {
return ptr_->nsensor; return static_cast<int>(ptr_->nsensor);
} }
void set_nsensor(int value) { void set_nsensor(int value) {
ptr_->nsensor = value; ptr_->nsensor = static_cast<mjtSize>(value);
} }
int nnumeric() const { int nnumeric() const {
return ptr_->nnumeric; return static_cast<int>(ptr_->nnumeric);
} }
void set_nnumeric(int value) { void set_nnumeric(int value) {
ptr_->nnumeric = value; ptr_->nnumeric = static_cast<mjtSize>(value);
} }
int nnumericdata() const { int nnumericdata() const {
return ptr_->nnumericdata; return static_cast<int>(ptr_->nnumericdata);
} }
void set_nnumericdata(int value) { void set_nnumericdata(int value) {
ptr_->nnumericdata = value; ptr_->nnumericdata = static_cast<mjtSize>(value);
} }
int ntext() const { int ntext() const {
return ptr_->ntext; return static_cast<int>(ptr_->ntext);
} }
void set_ntext(int value) { void set_ntext(int value) {
ptr_->ntext = value; ptr_->ntext = static_cast<mjtSize>(value);
} }
int ntextdata() const { int ntextdata() const {
return ptr_->ntextdata; return static_cast<int>(ptr_->ntextdata);
} }
void set_ntextdata(int value) { void set_ntextdata(int value) {
ptr_->ntextdata = value; ptr_->ntextdata = static_cast<mjtSize>(value);
} }
int ntuple() const { int ntuple() const {
return ptr_->ntuple; return static_cast<int>(ptr_->ntuple);
} }
void set_ntuple(int value) { void set_ntuple(int value) {
ptr_->ntuple = value; ptr_->ntuple = static_cast<mjtSize>(value);
} }
int ntupledata() const { int ntupledata() const {
return ptr_->ntupledata; return static_cast<int>(ptr_->ntupledata);
} }
void set_ntupledata(int value) { void set_ntupledata(int value) {
ptr_->ntupledata = value; ptr_->ntupledata = static_cast<mjtSize>(value);
} }
int nkey() const { int nkey() const {
return ptr_->nkey; return static_cast<int>(ptr_->nkey);
} }
void set_nkey(int value) { void set_nkey(int value) {
ptr_->nkey = value; ptr_->nkey = static_cast<mjtSize>(value);
} }
int nmocap() const { int nmocap() const {
return ptr_->nmocap; return static_cast<int>(ptr_->nmocap);
} }
void set_nmocap(int value) { void set_nmocap(int value) {
ptr_->nmocap = value; ptr_->nmocap = static_cast<mjtSize>(value);
} }
int nplugin() const { int nplugin() const {
return ptr_->nplugin; return static_cast<int>(ptr_->nplugin);
} }
void set_nplugin(int value) { void set_nplugin(int value) {
ptr_->nplugin = value; ptr_->nplugin = static_cast<mjtSize>(value);
} }
int npluginattr() const { int npluginattr() const {
return ptr_->npluginattr; return static_cast<int>(ptr_->npluginattr);
} }
void set_npluginattr(int value) { void set_npluginattr(int value) {
ptr_->npluginattr = value; ptr_->npluginattr = static_cast<mjtSize>(value);
} }
int nuser_body() const { int nuser_body() const {
return ptr_->nuser_body; return static_cast<int>(ptr_->nuser_body);
} }
void set_nuser_body(int value) { void set_nuser_body(int value) {
ptr_->nuser_body = value; ptr_->nuser_body = static_cast<mjtSize>(value);
} }
int nuser_jnt() const { int nuser_jnt() const {
return ptr_->nuser_jnt; return static_cast<int>(ptr_->nuser_jnt);
} }
void set_nuser_jnt(int value) { void set_nuser_jnt(int value) {
ptr_->nuser_jnt = value; ptr_->nuser_jnt = static_cast<mjtSize>(value);
} }
int nuser_geom() const { int nuser_geom() const {
return ptr_->nuser_geom; return static_cast<int>(ptr_->nuser_geom);
} }
void set_nuser_geom(int value) { void set_nuser_geom(int value) {
ptr_->nuser_geom = value; ptr_->nuser_geom = static_cast<mjtSize>(value);
} }
int nuser_site() const { int nuser_site() const {
return ptr_->nuser_site; return static_cast<int>(ptr_->nuser_site);
} }
void set_nuser_site(int value) { void set_nuser_site(int value) {
ptr_->nuser_site = value; ptr_->nuser_site = static_cast<mjtSize>(value);
} }
int nuser_cam() const { int nuser_cam() const {
return ptr_->nuser_cam; return static_cast<int>(ptr_->nuser_cam);
} }
void set_nuser_cam(int value) { void set_nuser_cam(int value) {
ptr_->nuser_cam = value; ptr_->nuser_cam = static_cast<mjtSize>(value);
} }
int nuser_tendon() const { int nuser_tendon() const {
return ptr_->nuser_tendon; return static_cast<int>(ptr_->nuser_tendon);
} }
void set_nuser_tendon(int value) { void set_nuser_tendon(int value) {
ptr_->nuser_tendon = value; ptr_->nuser_tendon = static_cast<mjtSize>(value);
} }
int nuser_actuator() const { int nuser_actuator() const {
return ptr_->nuser_actuator; return static_cast<int>(ptr_->nuser_actuator);
} }
void set_nuser_actuator(int value) { void set_nuser_actuator(int value) {
ptr_->nuser_actuator = value; ptr_->nuser_actuator = static_cast<mjtSize>(value);
} }
int nuser_sensor() const { int nuser_sensor() const {
return ptr_->nuser_sensor; return static_cast<int>(ptr_->nuser_sensor);
} }
void set_nuser_sensor(int value) { void set_nuser_sensor(int value) {
ptr_->nuser_sensor = value; ptr_->nuser_sensor = static_cast<mjtSize>(value);
} }
int nnames() const { int nnames() const {
return ptr_->nnames; return static_cast<int>(ptr_->nnames);
} }
void set_nnames(int value) { void set_nnames(int value) {
ptr_->nnames = value; ptr_->nnames = static_cast<mjtSize>(value);
} }
int npaths() const { int npaths() const {
return ptr_->npaths; return static_cast<int>(ptr_->npaths);
} }
void set_npaths(int value) { void set_npaths(int value) {
ptr_->npaths = value; ptr_->npaths = static_cast<mjtSize>(value);
} }
int nnames_map() const { int nnames_map() const {
return ptr_->nnames_map; return static_cast<int>(ptr_->nnames_map);
} }
void set_nnames_map(int value) { void set_nnames_map(int value) {
ptr_->nnames_map = value; ptr_->nnames_map = static_cast<mjtSize>(value);
} }
int nJmom() const { int nJmom() const {
return ptr_->nJmom; return static_cast<int>(ptr_->nJmom);
} }
void set_nJmom(int value) { void set_nJmom(int value) {
ptr_->nJmom = value; ptr_->nJmom = static_cast<mjtSize>(value);
} }
int ngravcomp() const { int ngravcomp() const {
return ptr_->ngravcomp; return static_cast<int>(ptr_->ngravcomp);
} }
void set_ngravcomp(int value) { void set_ngravcomp(int value) {
ptr_->ngravcomp = value; ptr_->ngravcomp = static_cast<mjtSize>(value);
} }
int nemax() const { int nemax() const {
return ptr_->nemax; return static_cast<int>(ptr_->nemax);
} }
void set_nemax(int value) { void set_nemax(int value) {
ptr_->nemax = value; ptr_->nemax = static_cast<mjtSize>(value);
} }
int njmax() const { int njmax() const {
return ptr_->njmax; return static_cast<int>(ptr_->njmax);
} }
void set_njmax(int value) { void set_njmax(int value) {
ptr_->njmax = value; ptr_->njmax = static_cast<mjtSize>(value);
} }
int nconmax() const { int nconmax() const {
return ptr_->nconmax; return static_cast<int>(ptr_->nconmax);
} }
void set_nconmax(int value) { void set_nconmax(int value) {
ptr_->nconmax = value; ptr_->nconmax = static_cast<mjtSize>(value);
} }
int nuserdata() const { int nuserdata() const {
return ptr_->nuserdata; return static_cast<int>(ptr_->nuserdata);
} }
void set_nuserdata(int value) { void set_nuserdata(int value) {
ptr_->nuserdata = value; ptr_->nuserdata = static_cast<mjtSize>(value);
} }
int nsensordata() const { int nsensordata() const {
return ptr_->nsensordata; return static_cast<int>(ptr_->nsensordata);
} }
void set_nsensordata(int value) { void set_nsensordata(int value) {
ptr_->nsensordata = value; ptr_->nsensordata = static_cast<mjtSize>(value);
} }
int npluginstate() const { int npluginstate() const {
return ptr_->npluginstate; return static_cast<int>(ptr_->npluginstate);
} }
void set_npluginstate(int value) { void set_npluginstate(int value) {
ptr_->npluginstate = value; ptr_->npluginstate = static_cast<mjtSize>(value);
} }
mjtSize narena() const { int narena() const {
return ptr_->narena; return static_cast<int>(ptr_->narena);
} }
void set_narena(mjtSize value) { void set_narena(int value) {
ptr_->narena = value; ptr_->narena = static_cast<mjtSize>(value);
} }
mjtSize nbuffer() const { int nbuffer() const {
return ptr_->nbuffer; return static_cast<int>(ptr_->nbuffer);
} }
void set_nbuffer(mjtSize value) { void set_nbuffer(int value) {
ptr_->nbuffer = value; ptr_->nbuffer = static_cast<mjtSize>(value);
} }
emscripten::val buffer() const { emscripten::val buffer() const {
return emscripten::val(emscripten::typed_memory_view(ptr_->nbuffer, static_cast<uint8_t*>(ptr_->buffer))); return emscripten::val(emscripten::typed_memory_view(ptr_->nbuffer, static_cast<uint8_t*>(ptr_->buffer)));
@@ -5337,11 +5337,11 @@ struct MjSpec {
void set_strippath(mjtByte value) { void set_strippath(mjtByte value) {
ptr_->strippath = value; ptr_->strippath = value;
} }
mjtSize memory() const { int memory() const {
return ptr_->memory; return static_cast<int>(ptr_->memory);
} }
void set_memory(mjtSize value) { void set_memory(int value) {
ptr_->memory = value; ptr_->memory = static_cast<mjtSize>(value);
} }
int nemax() const { int nemax() const {
return ptr_->nemax; return ptr_->nemax;
@@ -5421,11 +5421,11 @@ struct MjSpec {
void set_nconmax(int value) { void set_nconmax(int value) {
ptr_->nconmax = value; ptr_->nconmax = value;
} }
mjtSize nstack() const { int nstack() const {
return ptr_->nstack; return static_cast<int>(ptr_->nstack);
} }
void set_nstack(mjtSize value) { void set_nstack(int value) {
ptr_->nstack = value; ptr_->nstack = static_cast<mjtSize>(value);
} }
mjString comment() const { mjString comment() const {
return (ptr_ && ptr_->comment) ? *(ptr_->comment) : ""; return (ptr_ && ptr_->comment) ? *(ptr_->comment) : "";
@@ -6043,17 +6043,17 @@ struct MjData {
std::unique_ptr<MjData> copy(); std::unique_ptr<MjData> copy();
mjData* get() const; mjData* get() const;
void set(mjData* ptr); void set(mjData* ptr);
mjtSize narena() const { int narena() const {
return ptr_->narena; return static_cast<int>(ptr_->narena);
} }
void set_narena(mjtSize value) { void set_narena(int value) {
ptr_->narena = value; ptr_->narena = static_cast<mjtSize>(value);
} }
mjtSize nbuffer() const { int nbuffer() const {
return ptr_->nbuffer; return static_cast<int>(ptr_->nbuffer);
} }
void set_nbuffer(mjtSize value) { void set_nbuffer(int value) {
ptr_->nbuffer = value; ptr_->nbuffer = static_cast<mjtSize>(value);
} }
int nplugin() const { int nplugin() const {
return ptr_->nplugin; return ptr_->nplugin;
@@ -6079,20 +6079,20 @@ struct MjData {
void set_parena(size_t value) { void set_parena(size_t value) {
ptr_->parena = value; ptr_->parena = value;
} }
mjtSize maxuse_stack() const { int maxuse_stack() const {
return ptr_->maxuse_stack; return static_cast<int>(ptr_->maxuse_stack);
} }
void set_maxuse_stack(mjtSize value) { void set_maxuse_stack(int value) {
ptr_->maxuse_stack = value; ptr_->maxuse_stack = static_cast<mjtSize>(value);
} }
emscripten::val maxuse_threadstack() const { emscripten::val maxuse_threadstack() const {
return emscripten::val(emscripten::typed_memory_view(128, ptr_->maxuse_threadstack)); return emscripten::val(emscripten::typed_memory_view(128, ptr_->maxuse_threadstack));
} }
mjtSize maxuse_arena() const { int maxuse_arena() const {
return ptr_->maxuse_arena; return static_cast<int>(ptr_->maxuse_arena);
} }
void set_maxuse_arena(mjtSize value) { void set_maxuse_arena(int value) {
ptr_->maxuse_arena = value; ptr_->maxuse_arena = static_cast<mjtSize>(value);
} }
int maxuse_con() const { int maxuse_con() const {
return ptr_->maxuse_con; return ptr_->maxuse_con;
+15 -4
View File
@@ -97,10 +97,21 @@ def _generate_field_data(
): ):
builder = code_builder.CodeBuilder() builder = code_builder.CodeBuilder()
with builder.function(f"{f.type.name} {f.name}() const"):
builder.line(f"return ptr_->{f.name};") # `mjtSize` is a 64-bit signed integer type and would be represented in
with builder.function(f"void set_{f.name}({f.type.name} value)"): # JS/TS a `bigint` because it doesn't fit in the number primitive (a 64-bit
builder.line(f"ptr_->{f.name} = value;") # float). By casting int, we avoid "TS2345: Argument of type 'bigint' is not
# assignable to parameter of type 'number'" errors.
if f.type.name == "mjtSize":
with builder.function(f"int {f.name}() const"):
builder.line(f"return static_cast<int>(ptr_->{f.name});")
with builder.function(f"void set_{f.name}(int value)"):
builder.line(f"ptr_->{f.name} = static_cast<mjtSize>(value);")
else:
with builder.function(f"{f.type.name} {f.name}() const"):
builder.line(f"return ptr_->{f.name};")
with builder.function(f"void set_{f.name}({f.type.name} value)"):
builder.line(f"ptr_->{f.name} = value;")
return WrappedFieldData( return WrappedFieldData(
declaration=builder.to_string(), declaration=builder.to_string(),