Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textures are not rendered on flexcomp mesh and gmsh types #2464

Closed
2 tasks done
jsll opened this issue Feb 27, 2025 · 3 comments
Closed
2 tasks done

Textures are not rendered on flexcomp mesh and gmsh types #2464

jsll opened this issue Feb 27, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@jsll
Copy link

jsll commented Feb 27, 2025

Intro

Hi!

I am a researcher at KTH. I use MuJoCo for my research on deformable object manipulation.

My setup

MuJoCo version 3.2.8

What's happening? What did you expect?

When I apply texture to the flexcomp type mesh and gmsh the texture is not rendered.

Below is a screenshot of three flexcomp types: box, mesh, and gmesh, all with the same applied texture. Surprisingly, only the box model gets the texture applied.

This issue is related to #2013 (comment)

Image

Steps for reproduction

  1. Unzip the attached zip folder
  2. Load the model below.
  3. run ./simulate path_to_model_below

Minimal model for reproduction

Here are the assets folder that the model below reference to assets.zip

<mujoco model="texture_issue">

  <compiler meshdir="asset" texturedir="asset" />
  <option solver="CG" tolerance="1e-6" />

  <size memory="30M" />
  <option noslip_iterations="10">
    <flag multiccd="enable" />
  </option>

  <visual>
    <rgba haze="0.15 0.25 0.35 1"/>
    <quality shadowsize="4096"/>
    <map stiffness="700" shadowscale="0.5" fogstart="1" fogend="15" zfar="40" haze="1"/>
  </visual>

  <asset>
    <texture name="texsponge" type="2d" file="sponge.png" />
    <material name="matsponge" texture="texsponge" specular="0.3" />
    <texture name="texplane" type="2d" builtin="checker" rgb1=".2 .3 .4" rgb2=".1 0.15 0.2"
      width="512" height="512" mark="cross" markrgb=".8 .8 .8" />
    <material name="matplane" reflectance="0.3" texture="texplane" texrepeat="10 10"
      texuniform="true" />
  </asset>

  <worldbody>
    <light diffuse=".4 .4 .4" specular="0.1 0.1 0.1" pos="0 0 2.0" dir="0 0 -1" castshadow="false"/>
    <light directional="true" diffuse=".8 .8 .8" specular="0.2 0.2 0.2" pos="0 0 4" dir="0 0 -1"/>
    <body pos="0 0 1" name="body">
      <freejoint />
      <geom size=".1" contype="0" conaffinity="0" group="4" />
      <flexcomp name="softbox" type="box" count="7 7 7" spacing=".04 .04 .04"
        radius="0.01" dim="3" material="matsponge" dof="radial">
        <contact internal="false" selfcollide="none" />
        <edge equality="true" />
      </flexcomp>
    </body>
    <body
      pos="0.4 0 1" name="mesh">
      <freejoint />
      <geom size=".1" contype="0" conaffinity="0" group="4" />
      <flexcomp name="mesh" type="mesh" file="cloth.stl"
        radius="0.01" dim="2" material="matsponge">
        <contact internal="false" selfcollide="none" />
        <edge equality="true" />
      </flexcomp>
    </body>
    <body pos="0.6 0 1" name="gmsh">
      <freejoint />
      <geom size=".1" contype="0" conaffinity="0" group="4" />
      <flexcomp name="gmsh" type="gmsh" file="cloth.msh"
        radius="0.01" dim="2" material="matsponge" scale="0.1 0.1 0.1">
        <contact internal="false" selfcollide="none" />
        <edge equality="true" />
      </flexcomp>
    </body>
    <geom name="ground" type="plane" size="0 0 1" pos="0 0 0" quat="1 0 0 0" material="matplane"
      condim="1" />
  </worldbody>
</mujoco>

Code required for reproduction

Confirmations

@jsll jsll added the bug Something isn't working label Feb 27, 2025
@jsll
Copy link
Author

jsll commented Feb 27, 2025

Based on the fix for rendering texture on flexcomp grid types from here 6a86247, I think these two methods need to be modified

bool mjCFlexcomp::MakeMesh(mjCModel* model, char* error, int error_sz) {
bool mjCFlexcomp::MakeGMSH(mjCModel* model, char* error, int error_sz) {

@quagla
Copy link
Contributor

quagla commented Feb 27, 2025

Hi, for a box it's straightforward to compute the texture coordinates explicitly but for general meshes you have to provide the coordinates in the mesh file, see the lines that start vt in https://en.wikipedia.org/wiki/Wavefront_.obj_file

@jsll
Copy link
Author

jsll commented Feb 27, 2025

assets.zip

Hello.

Thanks for the input. So I changed the mesh to an obj file and unwrapped it. I also changed the model to include a flexcomp box, flexcomp mesh, and geom mesh. Again, all have the same texture applied. As you can see in the image below, the texture now gets correctly applied to the flexcomp box and the geom mesh but still not to the flexcomp mesh. Is there anything else that I have to do?

<mujoco model="texture_issue">

  <option solver="CG" tolerance="1e-6" />

  <size memory="30M" />
  <option noslip_iterations="10">
    <flag multiccd="enable" />
  </option>

  <visual>
    <rgba haze="0.15 0.25 0.35 1"/>
    <quality shadowsize="4096"/>
    <map stiffness="700" shadowscale="0.5" fogstart="1" fogend="15" zfar="40" haze="1"/>
  </visual>

  <asset>
    <texture name="texsponge" type="2d" file="sponge.png" />
    <material name="matsponge" texture="texsponge" specular="0.3" />
    <texture name="texplane" type="2d" builtin="checker" rgb1=".2 .3 .4" rgb2=".1 0.15 0.2"
      width="512" height="512" mark="cross" markrgb=".8 .8 .8" />
    <material name="matplane" reflectance="0.3" texture="texplane" texrepeat="10 10"
      texuniform="true" />
    <mesh name="test" file="cloth_extruded.obj" scale="1 1 1"/>
  </asset>

  <worldbody>
    <light diffuse=".4 .4 .4" specular="0.1 0.1 0.1" pos="0 0 2.0" dir="0 0 -1" castshadow="false"/>
    <light directional="true" diffuse=".8 .8 .8" specular="0.2 0.2 0.2" pos="0 0 4" dir="0 0 -1"/>
    <body pos="0 0 1" name="body">
      <freejoint />
      <geom size=".1" contype="0" conaffinity="0" group="4" />
      <flexcomp name="softbox" type="box" count="7 7 7" spacing=".04 .04 .04"
        radius="0.01" dim="3" material="matsponge" dof="radial">
        <contact internal="false" selfcollide="none" />
        <edge equality="true" />
      </flexcomp>
    </body>
    <body
      pos="0.4 0 1" name="objmesh">
      <freejoint />
      <geom size=".1" contype="0" conaffinity="0" group="4" />
      <flexcomp name="meshob" type="mesh" file="cloth_extruded.obj"
        radius="0.01" dim="2" material="matsponge">
        <contact internal="false" selfcollide="none" />
        <edge equality="true" />
      </flexcomp>
    </body>
    <body name="test">
      <freejoint/>
      <geom type="mesh" mesh="test" material="matsponge" pos="0.8 0 1" group="1" contype="0" conaffinity="0"/>
    </body>
    <geom name="ground" type="plane" size="0 0 1" pos="0 0 0" quat="1 0 0 0" material="matplane"
      condim="1" />
  </worldbody>
</mujoco>

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants