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
+12
View File
@@ -54,6 +54,9 @@ class MjWrapper<raw::MjrContext> : public WrapperBase<raw::MjrContext> {
X(auxFBO_r);
X(auxColor);
X(auxColor_r);
X(mat_texid);
X(mat_texuniform);
X(mat_texrepeat);
X(textureType);
X(texture);
X(skinvertVBO);
@@ -95,6 +98,9 @@ MjrContextWrapper::MjWrapper()
X(auxFBO_r),
X(auxColor),
X(auxColor_r),
X(mat_texid),
X(mat_texuniform),
X(mat_texrepeat),
X(textureType),
X(texture),
X_SKIN(skinvertVBO),
@@ -119,6 +125,9 @@ MjrContextWrapper::MjWrapper(const MjModelWrapper& model, int fontscale)
X(auxFBO_r),
X(auxColor),
X(auxColor_r),
X(mat_texid),
X(mat_texuniform),
X(mat_texrepeat),
X(textureType),
X(texture),
X_SKIN(skinvertVBO),
@@ -238,6 +247,9 @@ PYBIND11_MODULE(_render, pymodule) {
X(auxFBO_r);
X(auxColor);
X(auxColor_r);
X(mat_texid);
X(mat_texuniform);
X(mat_texrepeat);
X(textureType);
X(texture);
X(skinvertVBO);
+1 -5
View File
@@ -1078,7 +1078,6 @@ MjvGLCameraWrapper::MjWrapper(const MjvGLCameraWrapper& other)
#define X(var) var(InitPyArray(ptr_->var, owner_))
MjvGeomWrapper::MjWrapper()
: WrapperBase(new raw::MjvGeom{}),
X(texrepeat),
X(size),
X(pos),
mat([this]() {
@@ -1091,7 +1090,6 @@ MjvGeomWrapper::MjWrapper()
MjvGeomWrapper::MjWrapper(raw::MjvGeom* ptr, py::handle owner)
: WrapperBase(ptr, owner),
X(texrepeat),
X(size),
X(pos),
mat([this]() {
@@ -2214,8 +2212,7 @@ This is useful for example when the MJB is not available as a file on disk.)"));
X(objtype);
X(objid);
X(category);
X(texid);
X(texuniform);
X(matid);
X(texcoord);
X(segid);
X(emission);
@@ -2228,7 +2225,6 @@ This is useful for example when the MJB is not available as a file on disk.)"));
#undef X
#define X(var) DefinePyArray(mjvGeom, #var, &MjvGeomWrapper::var)
X(texrepeat);
X(size);
X(pos);
X(mat);
+1 -1
View File
@@ -734,7 +734,7 @@ class MjWrapper<raw::MjvGeom> : public WrapperBase<raw::MjvGeom> {
py_array_or_tuple_t< \
std::remove_all_extents_t<decltype(raw::MjvGeom::var)>> \
var
X(texrepeat);
X(matid);
X(size);
X(pos);
X(mat);
+1 -8
View File
@@ -258,17 +258,10 @@ class USDPrimitiveMesh:
assert self.prim_mesh
x_scale, y_scale = self.geom.texrepeat
mesh_texcoord = np.array(self.prim_mesh.triangle_uvs)
mesh_facetexcoord = np.asarray(self.prim_mesh.triangles)
x_multiplier, y_multiplier = 1, 1
if self.geom.texuniform:
x_multiplier, y_multiplier = self.geom.size[:2]
mesh_texcoord[:, 0] *= x_scale * x_multiplier
mesh_texcoord[:, 1] *= y_scale * y_multiplier
# TODO(etom): bring back support for rescaling the texture coordinates.
return mesh_texcoord, mesh_facetexcoord.flatten()
+5 -1
View File
@@ -232,7 +232,11 @@ class USDExporter:
geom_name = mujoco.mj_id2name(self.model, geom.objtype, geom.objid)
assert geom_name not in self.geom_name2usd
texture_file = self.texture_files[geom.texid] if geom.texid != -1 else None
texture_file = (
self.texture_files[self.model.mat_texid[geom.matid]]
if geom.matid != -1
else None
)
# handles meshes in scene
if geom.type == mujoco.mjtGeom.mjGEOM_MESH: