Add textured materials to render context, and refactor mjvGeom to refer to those textures.

PiperOrigin-RevId: 648719103
Change-Id: Idb4425bdeea3cbc1133cda3e4366574ed3bb5ccc
This commit is contained in:
Tom Erez
2024-07-02 08:00:06 -07:00
committed by Copybara-Service
parent af3233f98d
commit 3b73dfe33b
14 changed files with 252 additions and 195 deletions
+32
View File
@@ -1294,6 +1294,37 @@ static void makeFont(mjrContext* con, int fontscale) {
}
}
// make materials, just for those that have textures
static void makeMaterial(const mjModel* m, mjrContext* con) {
memset(con->mat_texid, -1, sizeof(con->mat_texid));
memset(con->mat_texuniform, 0, sizeof(con->mat_texuniform));
memset(con->mat_texrepeat, 0, sizeof(con->mat_texrepeat));
if (!m->nmat || !m->ntex) {
return;
}
if (m->nmat >= mjMAXMATERIAL-1) {
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];
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];
}
}
// find skybox texture
for (int i=0; i < m->ntex; i++) {
if (m->tex_type[i] == mjTEXTURE_SKYBOX) {
if (m->nmat >= mjMAXMATERIAL-2) {
mju_error("With skybox, maximum number of materials is %d", mjMAXMATERIAL);
}
con->mat_texid[mjNTEXMAT * (mjMAXMATERIAL-1)] = i;
break;
}
}
}
// make textures
@@ -1585,6 +1616,7 @@ void mjr_makeContext_offSize(const mjModel* m, mjrContext* con, int fontscale,
// make everything
makeOff(con);
makeShadow(m, con);
makeMaterial(m, con);
makeTexture(m, con);
makePlane(m, con);
makeMesh(m, con);