diff --git a/doc/includes/references.h b/doc/includes/references.h index 573d0734..e411bf2e 100644 --- a/doc/includes/references.h +++ b/doc/includes/references.h @@ -3011,6 +3011,7 @@ struct mjvSceneState_ { mjtNum* flex_node; mjtNum* flex_radius; float* flex_rgba; + float* flex_texcoord; int* hfield_pathadr; diff --git a/include/mujoco/mjvisualize.h b/include/mujoco/mjvisualize.h index a18036cf..96574ae0 100644 --- a/include/mujoco/mjvisualize.h +++ b/include/mujoco/mjvisualize.h @@ -537,6 +537,7 @@ struct mjvSceneState_ { mjtNum* flex_node; mjtNum* flex_radius; float* flex_rgba; + float* flex_texcoord; int* hfield_pathadr; diff --git a/include/mujoco/mjxmacro.h b/include/mujoco/mjxmacro.h index 8a0359d5..69950695 100644 --- a/include/mujoco/mjxmacro.h +++ b/include/mujoco/mjxmacro.h @@ -373,7 +373,7 @@ XMJV( int, flex_bvhadr, nflex, 1 ) \ XMJV( int, flex_bvhnum, nflex, 1 ) \ XMJV( float, flex_rgba, nflex, 4 ) \ - X ( float, flex_texcoord, nflextexcoord, 2 ) \ + XMJV( float, flex_texcoord, nflextexcoord, 2 ) \ X ( int, mesh_vertadr, nmesh, 1 ) \ X ( int, mesh_vertnum, nmesh, 1 ) \ X ( int, mesh_normaladr, nmesh, 1 ) \ diff --git a/introspect/structs.py b/introspect/structs.py index af142658..6c775660 100644 --- a/introspect/structs.py +++ b/introspect/structs.py @@ -7734,6 +7734,13 @@ STRUCTS: Mapping[str, StructDecl] = dict([ ), doc='', ), + StructFieldDecl( + name='flex_texcoord', + type=PointerType( + inner_type=ValueType(name='float'), + ), + doc='', + ), StructFieldDecl( name='hfield_pathadr', type=PointerType( diff --git a/src/user/user_flexcomp.cc b/src/user/user_flexcomp.cc index 912fb1cc..93167cea 100644 --- a/src/user/user_flexcomp.cc +++ b/src/user/user_flexcomp.cc @@ -597,7 +597,7 @@ int mjCFlexcomp::GridID(int ix, int iy, int iz) { // make grid bool mjCFlexcomp::MakeGrid(char* error, int error_sz) { int dim = def.Flex().spec.dim; - bool hastex = texcoord.empty(); + bool needtex = texcoord.empty() && mjs_getString(def.spec.flex->material)[0]; // 1D if (dim == 1) { @@ -646,7 +646,7 @@ bool mjCFlexcomp::MakeGrid(char* error, int error_sz) { point.push_back(0); // add texture coordinates, if not specified explicitly - if (!hastex) { + if (needtex) { texcoord.push_back(ix/(double)std::max(count[0]-1, 1)); texcoord.push_back(iy/(double)std::max(count[1]-1, 1)); } @@ -690,6 +690,12 @@ bool mjCFlexcomp::MakeGrid(char* error, int error_sz) { point.push_back(spacing[1]*(iy - 0.5*(count[1]-1))); point.push_back(spacing[2]*(iz - 0.5*(count[2]-1))); + // add texture coordinates, if not specified explicitly + if (needtex) { + texcoord.push_back(ix/(float)std::max(count[0]-1, 1)); + texcoord.push_back(iy/(float)std::max(count[1]-1, 1)); + } + // add elements if (ix < count[0]-1 && iy < count[1]-1 && iz < count[2]-1) { int vert[8] = { @@ -834,7 +840,7 @@ bool mjCFlexcomp::MakeSquare(char* error, int error_sz) { // make 3d box, ellipsoid or cylinder bool mjCFlexcomp::MakeBox(char* error, int error_sz) { double pos[3]; - bool needtex = texcoord.empty() && !std::string(mjs_getString(def.spec.flex->material)).empty(); + bool needtex = texcoord.empty() && mjs_getString(def.spec.flex->material)[0]; // set 3D def.spec.flex->dim = 3; diff --git a/unity/Runtime/Bindings/MjBindings.cs b/unity/Runtime/Bindings/MjBindings.cs index 79d5c5f0..df392f11 100644 --- a/unity/Runtime/Bindings/MjBindings.cs +++ b/unity/Runtime/Bindings/MjBindings.cs @@ -6338,6 +6338,7 @@ public unsafe struct model { public double* flex_node; public double* flex_radius; public float* flex_rgba; + public float* flex_texcoord; public int* hfield_pathadr; public int* mesh_bvhadr; public int* mesh_bvhnum;