Skip to content

Commit d43c3ed

Browse files
committed
Move texture block copy out of render context so it can be modified online via mjmodel
1 parent bdeb7e7 commit d43c3ed

12 files changed

Lines changed: 54 additions & 95 deletions

File tree

‎doc/APIreference/APIglobals.rst‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,6 @@ Defined in `mjrender.h <https://github.com/google-deepmind/mujoco/blob/main/incl
583583
* - ``mjMAXTEXTURE``
584584
- 1000
585585
- Maximum number of textures allowed.
586-
* - ``mjMAXMATERIAL``
587-
- 1000
588-
- Maximum number of materials with textures.
589586

590587

591588
.. _glNumericUI:

‎doc/changelog.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ General
3232
exclusively in the compressed sparse row (CSR) format ``mjData.M``.
3333
- :ref:`mju_round` now breaks ties away from zero rather than towards :math:`+\infty`. This only affects
3434
negative half-integers, e.g. ``mju_round(-2.5)`` now returns -3 rather than -2.
35+
- Removed the ``mjMAXMATERIAL`` constant. The classic renderer no longer caps the number of textured materials.
36+
37+
.. admonition:: Breaking ABI changes
38+
:class: attention
39+
40+
- Removed ``mat_texid``, ``mat_texuniform`` and ``mat_texrepeat`` from ``mjrContext``; the equivalent per-geom fields
41+
``texid``, ``texuniform`` and ``texrepeat`` were added to ``mjvGeom``, populated from the model each frame by
42+
:ref:`mjv_updateScene`. The classic renderer now resolves them live, so runtime material changes (e.g. domain
43+
randomization) no longer require rebuilding the render context.
3544

3645
Version 3.10.0 (June 22, 2026)
3746
------------------------------

‎include/mujoco/mjrender.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ extern "C" {
2424

2525
#define mjNAUX 10 // number of auxiliary buffers
2626
#define mjMAXTEXTURE 1000 // maximum number of textures
27-
#define mjMAXMATERIAL 1000 // maximum number of materials with textures
2827

2928
//---------------------------------- primitive types (mjt) -----------------------------------------
3029

@@ -170,11 +169,6 @@ typedef struct mjrContext_ { // custom OpenGL context
170169
unsigned int auxColor[mjNAUX]; // auxiliary color buffer
171170
unsigned int auxColor_r[mjNAUX]; // auxiliary color buffer for resolving
172171

173-
// materials with textures
174-
int mat_texid[mjMAXMATERIAL*mjNTEXROLE]; // material texture ids (-1: no texture)
175-
int mat_texuniform[mjMAXMATERIAL]; // uniform cube mapping
176-
float mat_texrepeat[mjMAXMATERIAL*2]; // texture repetition for 2d mapping
177-
178172
// texture objects and info
179173
int ntexture; // number of allocated textures
180174
int textureType[mjMAXTEXTURE]; // type of texture (mjtTexture) (ntexture)

‎include/mujoco/mjvisualize.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ typedef struct mjvGeom_ { // abstract geom
229229
int objid; // mujoco object id; -1 for decor
230230
int category; // visual category
231231
int matid; // material id; -1: no textured material
232+
int texid; // texture id; -1: none
233+
int texuniform; // uniform cube mapping
232234
int texcoord; // mesh or flex geom has texture coordinates
233235
int segid; // segmentation id; -1: not shown
234236

@@ -243,6 +245,7 @@ typedef struct mjvGeom_ { // abstract geom
243245
float specular; // specular coef
244246
float shininess; // shininess coef
245247
float reflectance; // reflectance coef
248+
float texrepeat[2]; // texture repetition for 2d mapping
246249

247250
char label[100]; // text label
248251

‎python/mujoco/introspect/structs.py‎

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10140,6 +10140,16 @@
1014010140
type=ValueType(name='int'),
1014110141
doc='material id; -1: no textured material',
1014210142
),
10143+
StructFieldDecl(
10144+
name='texid',
10145+
type=ValueType(name='int'),
10146+
doc='texture id; -1: none',
10147+
),
10148+
StructFieldDecl(
10149+
name='texuniform',
10150+
type=ValueType(name='int'),
10151+
doc='uniform cube mapping',
10152+
),
1014310153
StructFieldDecl(
1014410154
name='texcoord',
1014510155
type=ValueType(name='int'),
@@ -10202,6 +10212,14 @@
1020210212
type=ValueType(name='float'),
1020310213
doc='reflectance coef',
1020410214
),
10215+
StructFieldDecl(
10216+
name='texrepeat',
10217+
type=ArrayType(
10218+
inner_type=ValueType(name='float'),
10219+
extents=(2,),
10220+
),
10221+
doc='texture repetition for 2d mapping',
10222+
),
1020510223
StructFieldDecl(
1020610224
name='label',
1020710225
type=ArrayType(
@@ -11178,30 +11196,6 @@
1117811196
),
1117911197
doc='auxiliary color buffer for resolving',
1118011198
),
11181-
StructFieldDecl(
11182-
name='mat_texid',
11183-
type=ArrayType(
11184-
inner_type=ValueType(name='int'),
11185-
extents=(10000,),
11186-
),
11187-
doc='material texture ids (-1: no texture)',
11188-
),
11189-
StructFieldDecl(
11190-
name='mat_texuniform',
11191-
type=ArrayType(
11192-
inner_type=ValueType(name='int'),
11193-
extents=(1000,),
11194-
),
11195-
doc='uniform cube mapping',
11196-
),
11197-
StructFieldDecl(
11198-
name='mat_texrepeat',
11199-
type=ArrayType(
11200-
inner_type=ValueType(name='float'),
11201-
extents=(2000,),
11202-
),
11203-
doc='texture repetition for 2d mapping',
11204-
),
1120511199
StructFieldDecl(
1120611200
name='ntexture',
1120711201
type=ValueType(name='int'),

‎python/mujoco/render.cc‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ class MjWrapper<raw::MjrContext> : public WrapperBase<raw::MjrContext> {
5454
X(auxFBO_r);
5555
X(auxColor);
5656
X(auxColor_r);
57-
X(mat_texid);
58-
X(mat_texuniform);
59-
X(mat_texrepeat);
6057
X(textureType);
6158
X(texture);
6259
X(skinvertVBO);
@@ -98,9 +95,6 @@ MjrContextWrapper::MjWrapper()
9895
X(auxFBO_r),
9996
X(auxColor),
10097
X(auxColor_r),
101-
X(mat_texid),
102-
X(mat_texuniform),
103-
X(mat_texrepeat),
10498
X(textureType),
10599
X(texture),
106100
X_SKIN(skinvertVBO),
@@ -125,9 +119,6 @@ MjrContextWrapper::MjWrapper(const MjModelWrapper& model, int fontscale)
125119
X(auxFBO_r),
126120
X(auxColor),
127121
X(auxColor_r),
128-
X(mat_texid),
129-
X(mat_texuniform),
130-
X(mat_texrepeat),
131122
X(textureType),
132123
X(texture),
133124
X_SKIN(skinvertVBO),
@@ -228,9 +219,6 @@ PYBIND11_MODULE(_render, pymodule, pybind11::mod_gil_not_used()) {
228219
X(auxFBO_r);
229220
X(auxColor);
230221
X(auxColor_r);
231-
X(mat_texid);
232-
X(mat_texuniform);
233-
X(mat_texrepeat);
234222
X(textureType);
235223
X(texture);
236224
X(skinvertVBO);

‎python/mujoco/structs.cc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,8 @@ This is useful for example when the MJB is not available as a file on disk.)"));
11851185
X(objid);
11861186
X(category);
11871187
X(matid);
1188+
X(texid);
1189+
X(texuniform);
11881190
X(texcoord);
11891191
X(segid);
11901192
X(emission);
@@ -1201,6 +1203,7 @@ This is useful for example when the MJB is not available as a file on disk.)"));
12011203
X(pos);
12021204
X(mat);
12031205
X(rgba);
1206+
X(texrepeat);
12041207
#undef X
12051208

12061209
DefinePyStr(mjvGeom, "label", &raw::MjvGeom::label);

‎python/mujoco/structs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ class MjWrapper<raw::MjvGeom> : public WrapperBase<raw::MjvGeom> {
832832
X(pos);
833833
X(mat);
834834
X(rgba);
835+
X(texrepeat);
835836
#undef X
836837
};
837838

‎python/mujoco/structs_wrappers.cc‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,8 @@ MjvGeomWrapper::MjWrapper()
11931193
static_assert(sizeof(ptr_->mat) == sizeof(ptr_->mat[0]) * 9);
11941194
return InitPyArray(std::array{3, 3}, ptr_->mat, owner_);
11951195
}()),
1196-
X(rgba) {
1196+
X(rgba),
1197+
X(texrepeat) {
11971198
mjv_initGeom(ptr_, mjGEOM_NONE, nullptr, nullptr, nullptr, nullptr);
11981199
}
11991200

@@ -1205,7 +1206,8 @@ MjvGeomWrapper::MjWrapper(raw::MjvGeom* ptr, py::handle owner)
12051206
static_assert(sizeof(ptr_->mat) == sizeof(ptr_->mat[0]) * 9);
12061207
return InitPyArray(std::array{3, 3}, ptr_->mat, owner_);
12071208
}()),
1208-
X(rgba) {}
1209+
X(rgba),
1210+
X(texrepeat) {}
12091211
#undef X
12101212

12111213
MjvGeomWrapper::MjWrapper(const MjvGeomWrapper& other) : MjvGeomWrapper() {

‎src/engine/engine_vis_visualize.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ static void setMaterial(const mjModel* m, mjvGeom* geom, int matid, const float*
241241
// set texture
242242
if (flags[mjVIS_TEXTURE] && matid >= 0) {
243243
geom->matid = matid;
244+
geom->texid = m->mat_texid[matid*mjNTEXROLE + mjTEXROLE_RGB];
245+
geom->texuniform = m->mat_texuniform[matid];
246+
geom->texrepeat[0] = m->mat_texrepeat[2*matid];
247+
geom->texrepeat[1] = m->mat_texrepeat[2*matid+1];
244248
}
245249

246250
// scale alpha for dynamic geoms only
@@ -379,6 +383,10 @@ void mjv_initGeom(mjvGeom* geom, int type, const mjtNum* size,
379383
// set defaults that cannot be assigned via this function
380384
geom->dataid = -1;
381385
geom->matid = -1;
386+
geom->texid = -1;
387+
geom->texuniform = 0;
388+
geom->texrepeat[0] = 0;
389+
geom->texrepeat[1] = 0;
382390
geom->texcoord = 0;
383391
geom->emission = 0;
384392
geom->specular = 0.5;

0 commit comments

Comments
 (0)
⌂ 换网址