Add support for multiple textures in one material (mjModel).

PiperOrigin-RevId: 648732764
Change-Id: I29b60dd62a069789a32017ff0d55e36b57e0052b
This commit is contained in:
Tom Erez
2024-07-02 08:49:24 -07:00
committed by Copybara-Service
parent 3b73dfe33b
commit df7ea3ed33
9 changed files with 20 additions and 11 deletions
+2 -2
View File
@@ -1220,7 +1220,7 @@ struct mjModel_ {
int* tex_pathadr; // address of texture asset path; -1: none (ntex x 1) int* tex_pathadr; // address of texture asset path; -1: none (ntex x 1)
// materials // 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) mjtByte* mat_texuniform; // make texture cube uniform (nmat x 1)
float* mat_texrepeat; // texture repetition for 2d mapping (nmat x 2) float* mat_texrepeat; // texture repetition for 2d mapping (nmat x 2)
float* mat_emission; // emission (x rgb) (nmat x 1) float* mat_emission; // emission (x rgb) (nmat x 1)
@@ -2792,7 +2792,7 @@ struct mjvFigure_ { // abstract 2D figure passed to OpenGL rendere
// line data // line data
int linepnt[mjMAXLINE]; // number of points in line; (0) disable 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 // output from renderer
int xaxispixel[2]; // range of x-axis in pixels int xaxispixel[2]; // range of x-axis in pixels
+1 -1
View File
@@ -935,7 +935,7 @@ struct mjModel_ {
int* tex_pathadr; // address of texture asset path; -1: none (ntex x 1) int* tex_pathadr; // address of texture asset path; -1: none (ntex x 1)
// materials // 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) mjtByte* mat_texuniform; // make texture cube uniform (nmat x 1)
float* mat_texrepeat; // texture repetition for 2d mapping (nmat x 2) float* mat_texrepeat; // texture repetition for 2d mapping (nmat x 2)
float* mat_emission; // emission (x rgb) (nmat x 1) float* mat_emission; // emission (x rgb) (nmat x 1)
+1 -1
View File
@@ -394,7 +394,7 @@ struct mjvFigure_ { // abstract 2D figure passed to OpenGL rendere
// line data // line data
int linepnt[mjMAXLINE]; // number of points in line; (0) disable 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 // output from renderer
int xaxispixel[2]; // range of x-axis in pixels int xaxispixel[2]; // range of x-axis in pixels
+1 -1
View File
@@ -413,7 +413,7 @@
X ( int, tex_adr, ntex, 1 ) \ X ( int, tex_adr, ntex, 1 ) \
X ( mjtByte, tex_rgb, ntexdata, 1 ) \ X ( mjtByte, tex_rgb, ntexdata, 1 ) \
XMJV( int, tex_pathadr, ntex, 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( mjtByte, mat_texuniform, nmat, 1 ) \
XMJV( float, mat_texrepeat, nmat, 2 ) \ XMJV( float, mat_texrepeat, nmat, 2 ) \
XMJV( float, mat_emission, nmat, 1 ) \ XMJV( float, mat_emission, nmat, 1 ) \
+1 -1
View File
@@ -2950,7 +2950,7 @@ STRUCTS: Mapping[str, StructDecl] = dict([
type=PointerType( type=PointerType(
inner_type=ValueType(name='int'), 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( StructFieldDecl(
name='mat_texuniform', name='mat_texuniform',
+1 -1
View File
@@ -168,7 +168,7 @@
X( float, light_, specular, nlight, 3 ) X( float, light_, specular, nlight, 3 )
#define MJMODEL_MATERIAL \ #define MJMODEL_MATERIAL \
X( int, mat_, texid, nmat, 1 ) \ X( int, mat_, texid, nmat, mjNTEXMAT ) \
X( mjtByte, mat_, texuniform, nmat, 1 ) \ X( mjtByte, mat_, texuniform, nmat, 1 ) \
X( float, mat_, texrepeat, nmat, 2 ) \ X( float, mat_, texrepeat, nmat, 2 ) \
X( float, mat_, emission, nmat, 1 ) \ X( float, mat_, emission, nmat, 1 ) \
+1 -1
View File
@@ -233,7 +233,7 @@ class USDExporter:
assert geom_name not in self.geom_name2usd assert geom_name not in self.geom_name2usd
texture_file = ( 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 if geom.matid != -1
else None else None
) )
+8 -2
View File
@@ -1307,8 +1307,10 @@ static void makeMaterial(const mjModel* m, mjrContext* con) {
mju_error("Maximum number of materials is %d", mjMAXMATERIAL); mju_error("Maximum number of materials is %d", mjMAXMATERIAL);
} }
for (int i=0; i < m->nmat; i++) { for (int i=0; i < m->nmat; i++) {
if (m->mat_texid[i] >= 0) { if (m->mat_texid[i*mjNTEXMAT] >= 0) {
con->mat_texid[i*mjNTEXMAT] = m->mat_texid[i]; 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_texuniform[i] = m->mat_texuniform[i];
con->mat_texrepeat[2*i] = m->mat_texrepeat[2*i]; con->mat_texrepeat[2*i] = m->mat_texrepeat[2*i];
con->mat_texrepeat[2*i+1] = m->mat_texrepeat[2*i+1]; 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); mju_error("With skybox, maximum number of materials is %d", mjMAXMATERIAL);
} }
con->mat_texid[mjNTEXMAT * (mjMAXMATERIAL-1)] = i; con->mat_texid[mjNTEXMAT * (mjMAXMATERIAL-1)] = i;
for (int j=1; j < mjNTEXMAT; j++) {
con->mat_texid[mjNTEXMAT * (mjMAXMATERIAL-1) + j] = -1;
}
break; break;
} }
} }
+4 -1
View File
@@ -2481,7 +2481,10 @@ void mjCModel::CopyObjects(mjModel* m) {
mjCMaterial* pmat = materials_[i]; mjCMaterial* pmat = materials_[i];
// set fields // set fields
m->mat_texid[i] = pmat->texid; m->mat_texid[mjNTEXMAT*i] = pmat->texid;
for (int j=1; j<mjNTEXMAT; j++) {
m->mat_texid[mjNTEXMAT*i+j] = -1;
}
m->mat_texuniform[i] = pmat->texuniform; m->mat_texuniform[i] = pmat->texuniform;
mjuu_copyvec(m->mat_texrepeat+2*i, pmat->texrepeat, 2); mjuu_copyvec(m->mat_texrepeat+2*i, pmat->texrepeat, 2);
m->mat_emission[i] = pmat->emission; m->mat_emission[i] = pmat->emission;