diff --git a/doc/includes/references.h b/doc/includes/references.h index 8d9c3ef7..b0c1a2bd 100644 --- a/doc/includes/references.h +++ b/doc/includes/references.h @@ -1220,7 +1220,7 @@ struct mjModel_ { int* tex_pathadr; // address of texture asset path; -1: none (ntex x 1) // materials - int* mat_texid; // texture id; -1: none (nmat x 1) + int* mat_texid; // indices of textures; -1: none (nmat x mjNTEXMAT) 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) @@ -2792,7 +2792,7 @@ struct mjvFigure_ { // abstract 2D figure passed to OpenGL rendere // line data int linepnt[mjMAXLINE]; // number of points in line; (0) disable - float linedata[mjMAXLINE][2*mjMAXLINEPNT]; // line data (x,y) + float linedata[mjMAXLINE][2*mjMAXLINEPNT]; // line data (x,y) // output from renderer int xaxispixel[2]; // range of x-axis in pixels diff --git a/include/mujoco/mjmodel.h b/include/mujoco/mjmodel.h index 0c3d9a03..9da23e75 100644 --- a/include/mujoco/mjmodel.h +++ b/include/mujoco/mjmodel.h @@ -935,7 +935,7 @@ struct mjModel_ { int* tex_pathadr; // address of texture asset path; -1: none (ntex x 1) // materials - int* mat_texid; // texture id; -1: none (nmat x 1) + int* mat_texid; // indices of textures; -1: none (nmat x mjNTEXMAT) 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/mjvisualize.h b/include/mujoco/mjvisualize.h index 124a511f..36ae5596 100644 --- a/include/mujoco/mjvisualize.h +++ b/include/mujoco/mjvisualize.h @@ -394,7 +394,7 @@ struct mjvFigure_ { // abstract 2D figure passed to OpenGL rendere // line data int linepnt[mjMAXLINE]; // number of points in line; (0) disable - float linedata[mjMAXLINE][2*mjMAXLINEPNT]; // line data (x,y) + float linedata[mjMAXLINE][2*mjMAXLINEPNT]; // line data (x,y) // output from renderer int xaxispixel[2]; // range of x-axis in pixels diff --git a/include/mujoco/mjxmacro.h b/include/mujoco/mjxmacro.h index 66a376eb..cb9dc58d 100644 --- a/include/mujoco/mjxmacro.h +++ b/include/mujoco/mjxmacro.h @@ -413,7 +413,7 @@ X ( int, tex_adr, ntex, 1 ) \ X ( mjtByte, tex_rgb, ntexdata, 1 ) \ XMJV( int, tex_pathadr, ntex, 1 ) \ - XMJV( int, mat_texid, nmat, 1 ) \ + XMJV( int, mat_texid, nmat, mjNTEXMAT ) \ XMJV( mjtByte, mat_texuniform, nmat, 1 ) \ XMJV( float, mat_texrepeat, nmat, 2 ) \ XMJV( float, mat_emission, nmat, 1 ) \ diff --git a/introspect/structs.py b/introspect/structs.py index be847f78..8bd9704a 100644 --- a/introspect/structs.py +++ b/introspect/structs.py @@ -2950,7 +2950,7 @@ STRUCTS: Mapping[str, StructDecl] = dict([ type=PointerType( inner_type=ValueType(name='int'), ), - doc='texture id; -1: none (nmat x 1)', + doc='indices of textures; -1: none (nmat x mjNTEXMAT)', # pylint: disable=line-too-long ), StructFieldDecl( name='mat_texuniform', diff --git a/python/mujoco/indexer_xmacro.h b/python/mujoco/indexer_xmacro.h index b604f008..0d0b529f 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, 1 ) \ + X( int, mat_, texid, nmat, mjNTEXMAT ) \ 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 d654b730..8ad10af8 100644 --- a/python/mujoco/usd/exporter.py +++ b/python/mujoco/usd/exporter.py @@ -233,7 +233,7 @@ class USDExporter: assert geom_name not in self.geom_name2usd texture_file = ( - self.texture_files[self.model.mat_texid[geom.matid]] + self.texture_files[self.model.mat_texid[mujoco.mjNTEXMAT*geom.matid]] if geom.matid != -1 else None ) diff --git a/src/render/render_context.c b/src/render/render_context.c index e07535ad..a4f0a4a8 100644 --- a/src/render/render_context.c +++ b/src/render/render_context.c @@ -1307,8 +1307,10 @@ 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] >= 0) { - con->mat_texid[i*mjNTEXMAT] = m->mat_texid[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]; + } con->mat_texuniform[i] = m->mat_texuniform[i]; con->mat_texrepeat[2*i] = m->mat_texrepeat[2*i]; con->mat_texrepeat[2*i+1] = m->mat_texrepeat[2*i+1]; @@ -1321,6 +1323,10 @@ static void makeMaterial(const mjModel* m, mjrContext* con) { 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; + } + break; } } diff --git a/src/user/user_model.cc b/src/user/user_model.cc index 2d43da6b..7159001e 100644 --- a/src/user/user_model.cc +++ b/src/user/user_model.cc @@ -2481,7 +2481,10 @@ void mjCModel::CopyObjects(mjModel* m) { mjCMaterial* pmat = materials_[i]; // set fields - m->mat_texid[i] = pmat->texid; + m->mat_texid[mjNTEXMAT*i] = pmat->texid; + for (int j=1; jmat_texid[mjNTEXMAT*i+j] = -1; + } m->mat_texuniform[i] = pmat->texuniform; mjuu_copyvec(m->mat_texrepeat+2*i, pmat->texrepeat, 2); m->mat_emission[i] = pmat->emission;