MCPcopy Create free account
hub / github.com/RoboVerseOrg/RoboVerse / write_obj_file

Function write_obj_file

scripts/conversion/mjcf2urdf.py:325–353  ·  view source on GitHub ↗

Write mesh data to OBJ file with proper UV mapping and material reference.

(
    vertices: np.ndarray,
    faces: np.ndarray,
    normals: np.ndarray,
    texcoords: np.ndarray,
    scale: list,
    filepath: str,
    material_name: str,
)

Source from the content-addressed store, hash-verified

323
324
325def write_obj_file(
326 vertices: np.ndarray,
327 faces: np.ndarray,
328 normals: np.ndarray,
329 texcoords: np.ndarray,
330 scale: list,
331 filepath: str,
332 material_name: str,
333) -> None:
334 """
335 Write mesh data to OBJ file with proper UV mapping and material reference.
336 """
337 mtl_filename = os.path.splitext(os.path.basename(filepath))[0] + ".mtl"
338 mtl_filepath = os.path.join(os.path.dirname(filepath), mtl_filename)
339 texture_filename = "texture_map.png"
340 write_mtl_file(material_name, texture_filename, mtl_filepath)
341 with open(filepath, "w") as f:
342 f.write(f"mtllib {mtl_filename}\n")
343 for v in vertices:
344 scaled_v = [v[0] * scale[0], v[1] * scale[1], v[2] * scale[2]]
345 f.write(f"v {scaled_v[0]} {scaled_v[1]} {scaled_v[2]}\n")
346 for vt in texcoords:
347 f.write(f"vt {vt[0]} {1.0 - vt[1]}\n")
348 for vn in normals:
349 f.write(f"vn {vn[0]} {vn[1]} {vn[2]}\n")
350 f.write(f"usemtl {material_name}\n")
351 for face in faces:
352 v1, v2, v3 = face + 1
353 f.write(f"f {v1}/{v1}/{v1} {v2}/{v2}/{v2} {v3}/{v3}/{v3}\n")
354
355
356def get_mesh_and_texture_paths(xml_path: str) -> tuple:

Callers

nothing calls this directly

Calls 1

write_mtl_fileFunction · 0.70

Tested by

no test coverage detected