MjSpec.to_xml() drops userfacetexcoord, so inline textured meshes do not reload

Aperta
#3,931 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 6 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp, python
Ambito
backend, compilers

Direzione di ricerca

Start with src/xml/xml_native_writer.cc around the mesh serialization code, then check src/xml/generated/mjcf_read_table.inc and src/user/user_mesh.cc as the issue identifies. Reproduce with the Python MjSpec example in the report and verify how inline face UV indices are represented during XML writing and loading. Done means the generated XML reloads with the same per-corner UV mapping; the issue also flags userfacenormal as a possible related gap.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

My setup

MuJoCo 4.0.1 from PyPI (mujoco-core 4.0.1, plus mujoco-usd 4.0.1 for the USD case), Python 3.12, Linux x86_64. The same code is on main.

What's happening? What did you expect?

MjSpec.to_xml() writes MJCF that does not compile for meshes with inline vertex data and userfacetexcoord. MJCF <mesh> has vertex, normal, texcoord, and face attributes but nothing for face texcoord indices, so the writer emits texcoord and drops userfacetexcoord. On reload the texcoord count no longer matches the vertex count:

Error: texcoord must be 2*nv if face texcoord indices are not provided in an OBJ file

When the texcoord count happens to equal the vertex count, the reload compiles instead, with UVs assigned to the wrong corners.

Meshes loaded from an OBJ file are not affected because the XML references the file. Inline meshes with per-corner UVs are common in specs built by importers. The USD decoder fills userfacetexcoord from faceVarying primvars:st, so every textured USD mesh hits this. 9 of the 40 MuJoCo Menagerie models I converted to USD and decoded fail to reload after to_xml(), including unitree_go2, boston_dynamics_spot, and aloha.

I expected to_xml() to write MJCF that reloads to the same mesh, for example through a facetexcoord attribute on <mesh> or by splitting vertices so each has one texcoord. userfacenormal looks like it has the same gap, but I have not tested it.

The relevant code at 4.0.1:

Steps for reproduction
  1. pip install mujoco==4.0.1
  2. Run the code below. It builds a tetrahedron with 4 vertices and a separate UV for each of its 12 face corners, compiles it, writes it with to_xml(), and reloads the XML.
  3. The original spec compiles, and the reloaded XML fails.
original spec compiles
<mesh name="tet" vertex="0 0 0 1 0 0 0 1 0 0 0 1" texcoord="0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1" face="0 2 1 0 1 3 0 3 2 1 2 3"/>
reloaded XML fails: Error: texcoord must be 2*nv if face texcoord indices are not provided in an OBJ file | Element name 'tet', id 0, line 5
Minimal model for reproduction

The spec is built in code because MJCF cannot express it.

Code required for reproduction
import mujoco

# Tetrahedron with 4 vertices and a separate UV per face corner (12 UVs).
spec = mujoco.MjSpec()
mesh = spec.add_mesh(name="tet")
mesh.uservert = [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]
mesh.userface = [0, 2, 1, 0, 1, 3, 0, 3, 2, 1, 2, 3]
mesh.usertexcoord = [0, 0, 1, 0, 0, 1] * 4
mesh.userfacetexcoord = list(range(12))
spec.worldbody.add_geom(type=mujoco.mjtGeom.mjGEOM_MESH, meshname="tet")
spec.compile()
print("original spec compiles")

xml = spec.to_xml()
print(next(line.strip() for line in xml.splitlines() if "<mesh" in line))
try:
    mujoco.MjSpec.from_string(xml).compile()
    print("reloaded XML compiles")
except ValueError as e:
    print("reloaded XML fails:", str(e).replace("\n", " | "))
Confirmations
Lingua principale
C++
Stelle
18.3k
Fork
2.2k
Merge medio
9g 11h
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google-deepmind/mujoco

Tutte le issue di google-deepmind/mujoco

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.