diff --git a/doc/APIreference/APItypes.rst b/doc/APIreference/APItypes.rst index bca236ad..61d2d7fa 100644 --- a/doc/APIreference/APItypes.rst +++ b/doc/APIreference/APItypes.rst @@ -175,6 +175,17 @@ Texture types, specifying how the texture will be mapped. These values are used .. mujoco-include:: mjtTexture +.. _mjtTextureRole: + +mjtTextureRole +~~~~~~~~~~~~~~ + +Texture roles, specifying how the renderer should interpret the texture. Note that the MuJoCo built-in renderer only +uses RGB textures. These values are used to store the texture index in the material's array ``m->mat_texid``. + +.. mujoco-include:: mjtTextureRole + + .. _mjtIntegrator: mjtIntegrator diff --git a/doc/includes/references.h b/doc/includes/references.h index b96978f9..cce47515 100644 --- a/doc/includes/references.h +++ b/doc/includes/references.h @@ -477,6 +477,19 @@ typedef enum mjtTexture_ { // type of texture mjTEXTURE_CUBE, // cube texture, suitable for all other geom types mjTEXTURE_SKYBOX // cube texture used as skybox } mjtTexture; +typedef enum mjtTextureRole_ { // role of texture map in rendering + mjTEXROLE_USER = 0, // unspecified + mjTEXROLE_RGB, // base color (albedo) + mjTEXROLE_OCCLUSION, // ambient occlusion + mjTEXROLE_ROUGHNESS, // roughness + mjTEXROLE_METALLIC, // metallic + mjTEXROLE_NORMAL, // normal (bump) map + mjTEXROLE_OPACITY, // transperancy + mjTEXROLE_EMISSIVE, // light emission + mjTEXROLE_RGBA, // base color, opacity + mjTEXROLE_ORM, // occlusion, roughness, metallic + mjNTEXROLE +} mjtTextureRole; typedef enum mjtIntegrator_ { // integrator mode mjINT_EULER = 0, // semi-implicit Euler mjINT_RK4, // 4th-order Runge Kutta @@ -1217,7 +1230,7 @@ struct mjModel_ { int* tex_pathadr; // address of texture asset path; -1: none (ntex x 1) // materials - int* mat_texid; // indices of textures; -1: none (nmat x mjNTEXMAT) + int* mat_texid; // indices of textures; -1: none (nmat x mjNTEXROLE) mjtByte* mat_texuniform; // make texture cube uniform (nmat x 1) float* mat_texrepeat; // texture repetition for 2d mapping (nmat x 2) float* mat_emission; // emission (x rgb) (nmat x 1) @@ -1544,9 +1557,9 @@ struct mjrContext_ { // custom OpenGL context unsigned int auxColor_r[mjNAUX]; // auxiliary color buffer for resolving // materials with textures - int mat_texid[mjMAXMATERIAL*mjNTEXMAT]; // material texture ids (-1: no texture) - int mat_texuniform[mjMAXMATERIAL]; // texture repetition for 2d mapping - int mat_texrepeat[mjMAXMATERIAL*2]; // texture repetition for 2d mapping + int mat_texid[mjMAXMATERIAL*mjNTEXROLE]; // material texture ids (-1: no texture) + int mat_texuniform[mjMAXMATERIAL]; // texture repetition for 2d mapping + int mat_texrepeat[mjMAXMATERIAL*2]; // texture repetition for 2d mapping // texture objects and info int ntexture; // number of allocated textures diff --git a/include/mujoco/mjmodel.h b/include/mujoco/mjmodel.h index 2262932e..b559a98c 100644 --- a/include/mujoco/mjmodel.h +++ b/include/mujoco/mjmodel.h @@ -42,7 +42,6 @@ #define mjNIMP 5 // number of solver impedance parameters #define mjNSOLVER 200 // size of one mjData.solver array #define mjNISLAND 20 // number of mjData.solver arrays -#define mjNTEXMAT 6 // number of textures per material //---------------------------------- enum types (mjt) ---------------------------------------------- @@ -133,6 +132,21 @@ typedef enum mjtTexture_ { // type of texture } mjtTexture; +typedef enum mjtTextureRole_ { // role of texture map in rendering + mjTEXROLE_USER = 0, // unspecified + mjTEXROLE_RGB, // base color (albedo) + mjTEXROLE_OCCLUSION, // ambient occlusion + mjTEXROLE_ROUGHNESS, // roughness + mjTEXROLE_METALLIC, // metallic + mjTEXROLE_NORMAL, // normal (bump) map + mjTEXROLE_OPACITY, // transperancy + mjTEXROLE_EMISSIVE, // light emission + mjTEXROLE_RGBA, // base color, opacity + mjTEXROLE_ORM, // occlusion, roughness, metallic + mjNTEXROLE +} mjtTextureRole; + + typedef enum mjtIntegrator_ { // integrator mode mjINT_EULER = 0, // semi-implicit Euler mjINT_RK4, // 4th-order Runge Kutta @@ -930,7 +944,7 @@ struct mjModel_ { int* tex_pathadr; // address of texture asset path; -1: none (ntex x 1) // materials - int* mat_texid; // indices of textures; -1: none (nmat x mjNTEXMAT) + int* mat_texid; // indices of textures; -1: none (nmat x mjNTEXROLE) mjtByte* mat_texuniform; // make texture cube uniform (nmat x 1) float* mat_texrepeat; // texture repetition for 2d mapping (nmat x 2) float* mat_emission; // emission (x rgb) (nmat x 1) diff --git a/include/mujoco/mjrender.h b/include/mujoco/mjrender.h index 098cfa0e..020ecc5d 100644 --- a/include/mujoco/mjrender.h +++ b/include/mujoco/mjrender.h @@ -115,9 +115,9 @@ struct mjrContext_ { // custom OpenGL context unsigned int auxColor_r[mjNAUX]; // auxiliary color buffer for resolving // materials with textures - int mat_texid[mjMAXMATERIAL*mjNTEXMAT]; // material texture ids (-1: no texture) - int mat_texuniform[mjMAXMATERIAL]; // texture repetition for 2d mapping - int mat_texrepeat[mjMAXMATERIAL*2]; // texture repetition for 2d mapping + int mat_texid[mjMAXMATERIAL*mjNTEXROLE]; // material texture ids (-1: no texture) + int mat_texuniform[mjMAXMATERIAL]; // texture repetition for 2d mapping + int mat_texrepeat[mjMAXMATERIAL*2]; // texture repetition for 2d mapping // texture objects and info int ntexture; // number of allocated textures diff --git a/include/mujoco/mjxmacro.h b/include/mujoco/mjxmacro.h index 4d33d9e6..85f23af1 100644 --- a/include/mujoco/mjxmacro.h +++ b/include/mujoco/mjxmacro.h @@ -414,7 +414,7 @@ X ( int, tex_adr, ntex, 1 ) \ X ( mjtByte, tex_data, ntexdata, 1 ) \ XMJV( int, tex_pathadr, ntex, 1 ) \ - XMJV( int, mat_texid, nmat, mjNTEXMAT ) \ + XMJV( int, mat_texid, nmat, mjNTEXROLE ) \ XMJV( mjtByte, mat_texuniform, nmat, 1 ) \ XMJV( float, mat_texrepeat, nmat, 2 ) \ XMJV( float, mat_emission, nmat, 1 ) \ diff --git a/introspect/enums.py b/introspect/enums.py index 0542e17e..7308b664 100644 --- a/introspect/enums.py +++ b/introspect/enums.py @@ -119,6 +119,24 @@ ENUMS: Mapping[str, EnumDecl] = dict([ ('mjTEXTURE_SKYBOX', 2), ]), )), + ('mjtTextureRole', + EnumDecl( + name='mjtTextureRole', + declname='enum mjtTextureRole_', + values=dict([ + ('mjTEXROLE_USER', 0), + ('mjTEXROLE_RGB', 1), + ('mjTEXROLE_OCCLUSION', 2), + ('mjTEXROLE_ROUGHNESS', 3), + ('mjTEXROLE_METALLIC', 4), + ('mjTEXROLE_NORMAL', 5), + ('mjTEXROLE_OPACITY', 6), + ('mjTEXROLE_EMISSIVE', 7), + ('mjTEXROLE_RGBA', 8), + ('mjTEXROLE_ORM', 9), + ('mjNTEXROLE', 10), + ]), + )), ('mjtIntegrator', EnumDecl( name='mjtIntegrator', diff --git a/introspect/structs.py b/introspect/structs.py index b2a4f893..cd7928bf 100644 --- a/introspect/structs.py +++ b/introspect/structs.py @@ -2925,7 +2925,7 @@ STRUCTS: Mapping[str, StructDecl] = dict([ type=PointerType( inner_type=ValueType(name='int'), ), - doc='indices of textures; -1: none (nmat x mjNTEXMAT)', # pylint: disable=line-too-long + doc='indices of textures; -1: none (nmat x mjNTEXROLE)', # pylint: disable=line-too-long ), StructFieldDecl( name='mat_texuniform', @@ -7967,7 +7967,7 @@ STRUCTS: Mapping[str, StructDecl] = dict([ name='mat_texid', type=ArrayType( inner_type=ValueType(name='int'), - extents=(600,), + extents=(1000,), ), doc='material texture ids (-1: no texture)', ), diff --git a/python/mujoco/indexer_xmacro.h b/python/mujoco/indexer_xmacro.h index d729384c..199c46c7 100644 --- a/python/mujoco/indexer_xmacro.h +++ b/python/mujoco/indexer_xmacro.h @@ -168,7 +168,7 @@ X( float, light_, specular, nlight, 3 ) #define MJMODEL_MATERIAL \ - X( int, mat_, texid, nmat, mjNTEXMAT ) \ + X( int, mat_, texid, nmat, mjNTEXROLE ) \ X( mjtByte, mat_, texuniform, nmat, 1 ) \ X( float, mat_, texrepeat, nmat, 2 ) \ X( float, mat_, emission, nmat, 1 ) \ diff --git a/python/mujoco/usd/exporter.py b/python/mujoco/usd/exporter.py index e3c126eb..db4a0fc5 100644 --- a/python/mujoco/usd/exporter.py +++ b/python/mujoco/usd/exporter.py @@ -252,7 +252,9 @@ class USDExporter: assert geom_name not in self.geom_names texture_file = ( - self.texture_files[self.model.mat_texid[geom.matid][0]] + self.texture_files[ + self.model.mat_texid[geom.matid][mujoco.mjTEXROLE_RGB] + ] if geom.matid != -1 else None ) diff --git a/src/engine/engine_print.c b/src/engine/engine_print.c index 0504c768..3202c7a2 100644 --- a/src/engine/engine_print.c +++ b/src/engine/engine_print.c @@ -334,7 +334,7 @@ void mj_printFormattedModel(const mjModel* m, const char* filename, const char* const int* object_class; #define X(type, name, num, sz) \ - if (&m->num == object_class && (strncmp(#name, "name_", 5) != 0) && sz) { \ + if (&m->num == object_class && (strncmp(#name, "name_", 5) != 0) && sz > 0) { \ const char* format = _Generic(*m->name, \ double: float_format, \ float: float_format, \ diff --git a/src/render/render_context.c b/src/render/render_context.c index 96f863de..d47b7ca1 100644 --- a/src/render/render_context.c +++ b/src/render/render_context.c @@ -1307,9 +1307,9 @@ static void makeMaterial(const mjModel* m, mjrContext* con) { mju_error("Maximum number of materials is %d", mjMAXMATERIAL); } for (int i=0; i < m->nmat; i++) { - if (m->mat_texid[i*mjNTEXMAT] >= 0) { - for (int j=0; j < mjNTEXMAT; j++) { - con->mat_texid[i*mjNTEXMAT + j] = m->mat_texid[i*mjNTEXMAT + j]; + if (m->mat_texid[i*mjNTEXROLE + mjTEXROLE_RGB] >= 0) { + for (int j=0; j < mjNTEXROLE; j++) { + con->mat_texid[i*mjNTEXROLE + j] = m->mat_texid[i*mjNTEXROLE + j]; } con->mat_texuniform[i] = m->mat_texuniform[i]; con->mat_texrepeat[2*i] = m->mat_texrepeat[2*i]; @@ -1322,10 +1322,10 @@ static void makeMaterial(const mjModel* m, mjrContext* con) { if (m->nmat >= mjMAXMATERIAL-2) { mju_error("With skybox, maximum number of materials is %d", mjMAXMATERIAL); } - con->mat_texid[mjNTEXMAT * (mjMAXMATERIAL-1)] = i; - for (int j=1; j < mjNTEXMAT; j++) { - con->mat_texid[mjNTEXMAT * (mjMAXMATERIAL-1) + j] = -1; + for (int j=0; j < mjNTEXROLE; j++) { + con->mat_texid[mjNTEXROLE * (mjMAXMATERIAL-1) + j] = -1; } + con->mat_texid[mjNTEXROLE * (mjMAXMATERIAL-1) + mjTEXROLE_RGB] = i; break; } diff --git a/src/render/render_gl3.c b/src/render/render_gl3.c index 598161fb..06ded789 100644 --- a/src/render/render_gl3.c +++ b/src/render/render_gl3.c @@ -63,7 +63,9 @@ static void settexture(int type, int state, const mjrContext* con, const mjvGeom float plane[4], scl[2]; int texid = -1; if (geom) { - texid = (geom->matid == -1) ? -1 : con->mat_texid[mjNTEXMAT * geom->matid]; + if (geom->matid >= 0) { + texid = con->mat_texid[mjNTEXROLE * geom->matid + mjTEXROLE_RGB]; + } } // shadow diff --git a/src/user/user_model.cc b/src/user/user_model.cc index 6517414b..f365a994 100644 --- a/src/user/user_model.cc +++ b/src/user/user_model.cc @@ -2520,10 +2520,10 @@ void mjCModel::CopyObjects(mjModel* m) { mjCMaterial* pmat = materials_[i]; // set fields - m->mat_texid[mjNTEXMAT*i] = pmat->texid; - for (int j=1; jmat_texid[mjNTEXMAT*i+j] = -1; + for (int j=0; jmat_texid[mjNTEXROLE*i+j] = -1; } + m->mat_texid[mjNTEXROLE*i+mjTEXROLE_RGB] = pmat->texid; m->mat_texuniform[i] = pmat->texuniform; mjuu_copyvec(m->mat_texrepeat+2*i, pmat->texrepeat, 2); m->mat_emission[i] = pmat->emission; diff --git a/unity/Runtime/Bindings/MjBindings.cs b/unity/Runtime/Bindings/MjBindings.cs index 4dd43872..dea70955 100644 --- a/unity/Runtime/Bindings/MjBindings.cs +++ b/unity/Runtime/Bindings/MjBindings.cs @@ -50,7 +50,6 @@ public const int mjNREF = 2; public const int mjNIMP = 5; public const int mjNSOLVER = 200; public const int mjNISLAND = 20; -public const int mjNTEXMAT = 6; public const bool THIRD_PARTY_MUJOCO_INCLUDE_MJPLUGIN_H_ = true; public const bool mjEXTERNC = true; public const bool THIRD_PARTY_MUJOCO_MJRENDER_H_ = true; @@ -209,6 +208,19 @@ public enum mjtTexture : int{ mjTEXTURE_CUBE = 1, mjTEXTURE_SKYBOX = 2, } +public enum mjtTextureRole : int{ + mjTEXROLE_USER = 0, + mjTEXROLE_RGB = 1, + mjTEXROLE_OCCLUSION = 2, + mjTEXROLE_ROUGHNESS = 3, + mjTEXROLE_METALLIC = 4, + mjTEXROLE_NORMAL = 5, + mjTEXROLE_OPACITY = 6, + mjTEXROLE_EMISSIVE = 7, + mjTEXROLE_RGBA = 8, + mjTEXROLE_ORM = 9, + mjNTEXROLE = 10, +} public enum mjtIntegrator : int{ mjINT_EULER = 0, mjINT_RK4 = 1, @@ -5631,7 +5643,7 @@ public unsafe struct mjrContext_ { public fixed uint auxFBO_r[10]; public fixed uint auxColor[10]; public fixed uint auxColor_r[10]; - public fixed int mat_texid[600]; + public fixed int mat_texid[1000]; public fixed int mat_texuniform[100]; public fixed int mat_texrepeat[200]; public int ntexture;