diff --git a/doc/includes/references.h b/doc/includes/references.h index 1f0d83d6..573d0734 100644 --- a/doc/includes/references.h +++ b/doc/includes/references.h @@ -916,6 +916,9 @@ struct mjModel_ { int nmeshtexcoord; // number of texcoords in all meshes int nmeshface; // number of triangular faces in all meshes int nmeshgraph; // number of ints in mesh auxiliary data + int nmeshpoly; // number of polygons in all meshes + int nmeshpolyvert; // number of vertices in all polygons + int nmeshpolymap; // number of polygons in vertex map int nskin; // number of skins int nskinvert; // number of vertices in all skins int nskintexvert; // number of vertiex with texcoords in all skins @@ -1222,6 +1225,15 @@ struct mjModel_ { mjtNum* mesh_pos; // translation applied to asset vertices (nmesh x 3) mjtNum* mesh_quat; // rotation applied to asset vertices (nmesh x 4) int* mesh_pathadr; // address of asset path for mesh; -1: none (nmesh x 1) + int* mesh_polynum; // number of polygons per mesh (nmesh x 1) + int* mesh_polyadr; // first polygon address per mesh (nmesh x 1) + mjtNum* mesh_polynormal; // all polygon normals (nmeshpoly x 3) + int* mesh_polyvertadr; // polygon vertex start address (nmeshpoly x 1) + int* mesh_polyvertnum; // number of vertices per polygon (nmeshpoly x 1) + int* mesh_polyvert; // all polygon vertices (nmeshpolyvert x 1) + int* mesh_polymapadr; // first polygon address per vertex (nmeshvert x 1) + int* mesh_polymapnum; // number of polygons per vertex (nmeshvert x 1) + int* mesh_polymap; // vertex to polygon map (nmeshpolymap x 1) // skins int* skin_matid; // skin material id; -1: none (nskin x 1) diff --git a/include/mujoco/mjmodel.h b/include/mujoco/mjmodel.h index e846c676..9c5fcb3b 100644 --- a/include/mujoco/mjmodel.h +++ b/include/mujoco/mjmodel.h @@ -624,6 +624,9 @@ struct mjModel_ { int nmeshtexcoord; // number of texcoords in all meshes int nmeshface; // number of triangular faces in all meshes int nmeshgraph; // number of ints in mesh auxiliary data + int nmeshpoly; // number of polygons in all meshes + int nmeshpolyvert; // number of vertices in all polygons + int nmeshpolymap; // number of polygons in vertex map int nskin; // number of skins int nskinvert; // number of vertices in all skins int nskintexvert; // number of vertiex with texcoords in all skins @@ -930,6 +933,15 @@ struct mjModel_ { mjtNum* mesh_pos; // translation applied to asset vertices (nmesh x 3) mjtNum* mesh_quat; // rotation applied to asset vertices (nmesh x 4) int* mesh_pathadr; // address of asset path for mesh; -1: none (nmesh x 1) + int* mesh_polynum; // number of polygons per mesh (nmesh x 1) + int* mesh_polyadr; // first polygon address per mesh (nmesh x 1) + mjtNum* mesh_polynormal; // all polygon normals (nmeshpoly x 3) + int* mesh_polyvertadr; // polygon vertex start address (nmeshpoly x 1) + int* mesh_polyvertnum; // number of vertices per polygon (nmeshpoly x 1) + int* mesh_polyvert; // all polygon vertices (nmeshpolyvert x 1) + int* mesh_polymapadr; // first polygon address per vertex (nmeshvert x 1) + int* mesh_polymapnum; // number of polygons per vertex (nmeshvert x 1) + int* mesh_polymap; // vertex to polygon map (nmeshpolymap x 1) // skins int* skin_matid; // skin material id; -1: none (nskin x 1) diff --git a/include/mujoco/mjxmacro.h b/include/mujoco/mjxmacro.h index 88b802b8..8a0359d5 100644 --- a/include/mujoco/mjxmacro.h +++ b/include/mujoco/mjxmacro.h @@ -96,6 +96,9 @@ X ( nmeshtexcoord ) \ X ( nmeshface ) \ X ( nmeshgraph ) \ + X ( nmeshpoly ) \ + X ( nmeshpolyvert ) \ + X ( nmeshpolymap ) \ XMJV( nskin ) \ XMJV( nskinvert ) \ X ( nskintexvert ) \ @@ -393,6 +396,15 @@ XNV ( int, mesh_facetexcoord, nmeshface, 3 ) \ XNV ( int, mesh_graph, nmeshgraph, 1 ) \ XMJV( int, mesh_pathadr, nmesh, 1 ) \ + X ( int, mesh_polynum, nmesh, 1 ) \ + X ( int, mesh_polyadr, nmesh, 1 ) \ + X ( mjtNum, mesh_polynormal, nmeshpoly, 3 ) \ + X ( int, mesh_polyvertadr, nmeshpoly, 1 ) \ + X ( int, mesh_polyvertnum, nmeshpoly, 1 ) \ + X ( int, mesh_polyvert, nmeshpolyvert, 1 ) \ + X ( int, mesh_polymapadr, nmeshvert, 1 ) \ + X ( int, mesh_polymapnum, nmeshvert, 1 ) \ + X ( int, mesh_polymap, nmeshpolymap, 1 ) \ XMJV( int, skin_matid, nskin, 1 ) \ XMJV( int, skin_group, nskin, 1 ) \ XMJV( float, skin_rgba, nskin, 4 ) \ diff --git a/introspect/structs.py b/introspect/structs.py index c6bfd012..af142658 100644 --- a/introspect/structs.py +++ b/introspect/structs.py @@ -973,6 +973,21 @@ STRUCTS: Mapping[str, StructDecl] = dict([ type=ValueType(name='int'), doc='number of ints in mesh auxiliary data', ), + StructFieldDecl( + name='nmeshpoly', + type=ValueType(name='int'), + doc='number of polygons in all meshes', + ), + StructFieldDecl( + name='nmeshpolyvert', + type=ValueType(name='int'), + doc='number of vertices in all polygons', + ), + StructFieldDecl( + name='nmeshpolymap', + type=ValueType(name='int'), + doc='number of polygons in vertex map', + ), StructFieldDecl( name='nskin', type=ValueType(name='int'), @@ -2971,6 +2986,78 @@ STRUCTS: Mapping[str, StructDecl] = dict([ ), doc='address of asset path for mesh; -1: none (nmesh x 1)', ), + StructFieldDecl( + name='mesh_polynum', + type=PointerType( + inner_type=ValueType(name='int'), + ), + doc='number of polygons per mesh', + array_extent=('nmesh',), + ), + StructFieldDecl( + name='mesh_polyadr', + type=PointerType( + inner_type=ValueType(name='int'), + ), + doc='first polygon address per mesh', + array_extent=('nmesh',), + ), + StructFieldDecl( + name='mesh_polynormal', + type=PointerType( + inner_type=ValueType(name='mjtNum'), + ), + doc='all polygon normals', + array_extent=('nmeshpoly', 3), + ), + StructFieldDecl( + name='mesh_polyvertadr', + type=PointerType( + inner_type=ValueType(name='int'), + ), + doc='polygon vertex start address', + array_extent=('nmeshpoly',), + ), + StructFieldDecl( + name='mesh_polyvertnum', + type=PointerType( + inner_type=ValueType(name='int'), + ), + doc='number of vertices per polygon', + array_extent=('nmeshpoly',), + ), + StructFieldDecl( + name='mesh_polyvert', + type=PointerType( + inner_type=ValueType(name='int'), + ), + doc='all polygon vertices', + array_extent=('nmeshpolyvert',), + ), + StructFieldDecl( + name='mesh_polymapadr', + type=PointerType( + inner_type=ValueType(name='int'), + ), + doc='first polygon address per vertex', + array_extent=('nmeshvert',), + ), + StructFieldDecl( + name='mesh_polymapnum', + type=PointerType( + inner_type=ValueType(name='int'), + ), + doc='number of polygons per vertex', + array_extent=('nmeshvert',), + ), + StructFieldDecl( + name='mesh_polymap', + type=PointerType( + inner_type=ValueType(name='int'), + ), + doc='vertex to polygon map', + array_extent=('nmeshpolymap',), + ), StructFieldDecl( name='skin_matid', type=PointerType( diff --git a/src/engine/engine_io.c b/src/engine/engine_io.c index 6ac78f31..ba2b3046 100644 --- a/src/engine/engine_io.c +++ b/src/engine/engine_io.c @@ -463,7 +463,8 @@ void mj_makeModel(mjModel** dest, int nlight, int nflex, int nflexnode, int nflexvert, int nflexedge, int nflexelem, int nflexelemdata, int nflexelemedge, int nflexshelldata, int nflexevpair, int nflextexcoord, int nmesh, int nmeshvert, int nmeshnormal, int nmeshtexcoord, int nmeshface, - int nmeshgraph, int nskin, int nskinvert, int nskintexvert, int nskinface, + int nmeshgraph, int nmeshpoly, int nmeshpolyvert, int nmeshpolymap, int nskin, int nskinvert, + int nskintexvert, int nskinface, int nskinbone, int nskinbonevert, int nhfield, int nhfielddata, int ntex, int ntexdata, int nmat, int npair, int nexclude, int neq, int ntendon, int nwrap, int nsensor, int nnumeric, int nnumericdata, int ntext, @@ -518,6 +519,9 @@ void mj_makeModel(mjModel** dest, m->nmeshtexcoord = nmeshtexcoord; m->nmeshface = nmeshface; m->nmeshgraph = nmeshgraph; + m->nmeshpoly = nmeshpoly; + m->nmeshpolyvert = nmeshpolyvert; + m->nmeshpolymap = nmeshpolymap; m->nskin = nskin; m->nskinvert = nskinvert; m->nskintexvert = nskintexvert; @@ -639,6 +643,7 @@ mjModel* mj_copyModel(mjModel* dest, const mjModel* src) { src->nflexelem, src->nflexelemdata, src->nflexelemedge, src->nflexshelldata, src->nflexevpair, src->nflextexcoord, src->nmesh, src->nmeshvert, src->nmeshnormal, src->nmeshtexcoord, src->nmeshface, src->nmeshgraph, + src->nmeshpoly, src->nmeshpolyvert, src->nmeshpolymap, src->nskin, src->nskinvert, src->nskintexvert, src->nskinface, src->nskinbone, src->nskinbonevert, src->nhfield, src->nhfielddata, src->ntex, src->ntexdata, src->nmat, src->npair, src->nexclude, @@ -829,7 +834,7 @@ mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz) { ints[42], ints[43], ints[44], ints[45], ints[46], ints[47], ints[48], ints[49], ints[50], ints[51], ints[52], ints[53], ints[54], ints[55], ints[56], ints[57], ints[58], ints[59], ints[60], ints[61], ints[62], - ints[63], ints[64], ints[65]); + ints[63], ints[64], ints[65], ints[66], ints[67], ints[68]); if (!m || m->nbuffer != sizes[getnsize()-1]) { mju_warning("Corrupted model, wrong size parameters"); mj_deleteModel(m); @@ -2178,10 +2183,7 @@ const char* mj_validateReferences(const mjModel* m) { // nadrs: number of elements in refarray // ntarget: number of elements in array where references are pointing // numarray: if refarray is an adr array, numarray is the corresponding num array, otherwise 0 - - // add flex fields (b/303056369) - -#define MJMODEL_REFERENCES \ +#define MJMODEL_REFERENCES \ X(body_parentid, nbody, nbody , 0 ) \ X(body_rootid, nbody, nbody , 0 ) \ X(body_weldid, nbody, nbody , 0 ) \ @@ -2212,6 +2214,12 @@ const char* mj_validateReferences(const mjModel* m) { X(mesh_faceadr, nmesh, nmeshface , m->mesh_facenum ) \ X(mesh_bvhadr, nmesh, nbvh , m->mesh_bvhnum ) \ X(mesh_graphadr, nmesh, nmeshgraph , 0 ) \ + X(mesh_polyadr, nmesh, nmeshpoly , m->mesh_polynum ) \ + X(mesh_polynormal, nmeshpoly*3, nmeshpoly*3 , 0 ) \ + X(mesh_polyvertadr, nmeshpoly, nmeshpolyvert , m->mesh_polyvertnum ) \ + X(mesh_polyvert, nmeshpolyvert, nmeshpolyvert , 0 ) \ + X(mesh_polymapadr, nmeshvert, nmeshpolymap , m->mesh_polymapnum ) \ + X(mesh_polymap, nmeshpolymap, nmeshpolymap , 0 ) \ X(flex_vertadr, nflex, nflexvert , m->flex_vertnum ) \ X(flex_edgeadr, nflex, nflexedge , m->flex_edgenum ) \ X(flex_elemadr, nflex, nflexelem , m->flex_elemnum ) \ diff --git a/src/engine/engine_io.h b/src/engine/engine_io.h index ffb60cac..809d9e83 100644 --- a/src/engine/engine_io.h +++ b/src/engine/engine_io.h @@ -56,15 +56,13 @@ void mj_makeModel(mjModel** dest, int njnt, int ngeom, int nsite, int ncam, int nlight, int nflex, int nflexnode, int nflexvert, int nflexedge, int nflexelem, int nflexelemdata, int nflexelemedge, int nflexshelldata, int nflexevpair, int nflextexcoord, int nmesh, int nmeshvert, int nmeshnormal, - int nmeshtexcoord, int nmeshface, int nmeshgraph, int nskin, int nskinvert, int nskintexvert, - int nskinface, int nskinbone, int nskinbonevert, int nhfield, int nhfielddata, - int ntex, int ntexdata, int nmat, int npair, int nexclude, - int neq, int ntendon, int nwrap, int nsensor, - int nnumeric, int nnumericdata, int ntext, int ntextdata, - int ntuple, int ntupledata, int nkey, int nmocap, int nplugin, - int npluginattr, int nuser_body, int nuser_jnt, int nuser_geom, - int nuser_site, int nuser_cam, int nuser_tendon, int nuser_actuator, - int nuser_sensor, int nnames, int npaths); + int nmeshtexcoord, int nmeshface, int nmeshgraph, int nmeshpoly, int nmeshpolyvert, + int nmeshpolymap, int nskin, int nskinvert, int nskintexvert, int nskinface, int nskinbone, + int nskinbonevert, int nhfield, int nhfielddata, int ntex, int ntexdata, int nmat, int npair, + int nexclude, int neq, int ntendon, int nwrap, int nsensor, int nnumeric, int nnumericdata, int ntext, + int ntextdata, int ntuple, int ntupledata, int nkey, int nmocap, int nplugin, int npluginattr, + int nuser_body, int nuser_jnt, int nuser_geom, int nuser_site, int nuser_cam, int nuser_tendon, + int nuser_actuator, int nuser_sensor, int nnames, int npaths); // copy mjModel; allocate new if dest is NULL MJAPI mjModel* mj_copyModel(mjModel* dest, const mjModel* src); diff --git a/src/user/user_model.cc b/src/user/user_model.cc index 02c8a018..c59c07f3 100644 --- a/src/user/user_model.cc +++ b/src/user/user_model.cc @@ -2780,6 +2780,14 @@ void mjCModel::CopyObjects(mjModel* m) { // get pointer mjCMesh* pme = meshes_[i]; + // zero out multi-ccd fields + for (int j = 0; j < pme->nvert(); j++) { + m->mesh_polymapadr[vert_adr + j] = 0; + m->mesh_polymapnum[vert_adr + j] = 0; + } + m->mesh_polynum[i] = 0; + m->mesh_polyadr[i] = 0; + // set fields m->mesh_vertadr[i] = vert_adr; m->mesh_vertnum[i] = pme->nvert(); @@ -4332,8 +4340,8 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) { nq, nv, nu, na, nbody, nbvh, nbvhstatic, nbvhdynamic, njnt, ngeom, nsite, ncam, nlight, nflex, nflexnode, nflexvert, nflexedge, nflexelem, nflexelemdata, nflexelemedge, nflexshelldata, nflexevpair, nflextexcoord, - nmesh, nmeshvert, nmeshnormal, nmeshtexcoord, nmeshface, nmeshgraph, - nskin, nskinvert, nskintexvert, nskinface, nskinbone, nskinbonevert, + nmesh, nmeshvert, nmeshnormal, nmeshtexcoord, nmeshface, nmeshgraph, 0, 0, + 0, nskin, nskinvert, nskintexvert, nskinface, nskinbone, nskinbonevert, nhfield, nhfielddata, ntex, ntexdata, nmat, npair, nexclude, neq, ntendon, nwrap, nsensor, nnumeric, nnumericdata, ntext, ntextdata, ntuple, ntupledata, nkey, nmocap, nplugin, npluginattr, diff --git a/unity/Runtime/Bindings/MjBindings.cs b/unity/Runtime/Bindings/MjBindings.cs index 80729811..79d5c5f0 100644 --- a/unity/Runtime/Bindings/MjBindings.cs +++ b/unity/Runtime/Bindings/MjBindings.cs @@ -5208,6 +5208,9 @@ public unsafe struct mjModel_ { public int nmeshtexcoord; public int nmeshface; public int nmeshgraph; + public int nmeshpoly; + public int nmeshpolyvert; + public int nmeshpolymap; public int nskin; public int nskinvert; public int nskintexvert; @@ -5480,6 +5483,15 @@ public unsafe struct mjModel_ { public double* mesh_pos; public double* mesh_quat; public int* mesh_pathadr; + public int* mesh_polynum; + public int* mesh_polyadr; + public double* mesh_polynormal; + public int* mesh_polyvertadr; + public int* mesh_polyvertnum; + public int* mesh_polyvert; + public int* mesh_polymapadr; + public int* mesh_polymapnum; + public int* mesh_polymap; public int* skin_matid; public int* skin_group; public float* skin_rgba;