Open3D icon indicating copy to clipboard operation
Open3D copied to clipboard

write_triangle_mesh with textured OBJ

Open tritolol opened this issue 5 years ago • 8 comments
trafficstars

I'm running a simple I/O test for my textured OBJ mesh file using this code:

import open3d as o3d

def visualize(mesh):
    vis = o3d.visualization.Visualizer()
    vis.create_window()
    vis.add_geometry(mesh)
    vis.run()
    vis.destroy_window()

textured_mesh = o3d.io.read_triangle_mesh("input.obj")
visualize(textured_mesh)    # The mesh looks fine here
o3d.io.write_triangle_mesh("output.obj", textured_mesh, write_triangle_uvs=True)
textured_mesh = o3d.io.read_triangle_mesh("output.obj")
visualize(textured_mesh)    # The mesh looks broken here

The file is read correctly because I can visualize it and it looks just fine. However, the output obj file is not written correctly. When I visualize it, it looks broken:

image

The textures are not mapped correctly but also the mesh itself is rasterized in some strange way.

tritolol avatar Apr 21 '20 08:04 tritolol

Can you please share the obj/mtl and textures somewhere?

theNded avatar Apr 24 '20 15:04 theNded

Similar problem here. When I save a mesh to disk with write_triangle_uvs=False, the saved mesh has reduced number of vertices.

zhan-xu avatar Oct 27 '20 20:10 zhan-xu

@zhan-xu could you please provide the data?

germanros1987 avatar Nov 03 '20 01:11 germanros1987

@theNded So the problem is bit tricky. The obj file here is from my process which seems to have inconsistent faces and vertices numbers and quad faces. However, with version 0.10.0 and 0.9.0, using read_triangle_mesh will automatically discard redundant faces and convert the mesh into a pure triangle mesh. With 0.11.2, it doesn't preserve vertices, maybe due to the influence of the faces. This may not be a bug, but just for your information. I think this issue can be closed.

zhan-xu avatar Nov 12 '20 16:11 zhan-xu

I'm having the same problem with the function write_triangle_mesh with texture mesh obj file. Open3d is build from source, master branch The error: incompatible function arguments. The following argument types are supported:\n 1. (filename: str, mesh: open3d.cuda.pybind.geometry.TriangleMesh, write_ascii: bool = False, compressed: bool = False, write_vertex_normals: bool = True, write_vertex_colors: bool = True, write_triangle_uvs: bool = True, print_progress: bool = False)

manhha1402 avatar Sep 07 '21 12:09 manhha1402

Hi, I'm reviving this topic since I have the exact same problem.

I am working on Ubuntu 20.04 with Python 3.8 and open3D 0.15.2 installed via pip. Here is an example to reproduce the problem mesh_input.zip. I have a mesh saved as a PLY file (without texture). I try to read it with open3d and then save it again as an OBJ file (because I want to add texture and open3d notice me that texture is only supported with the OBJ file format). The problem is that it messes up the original mesh taht now looks kind of regularized.

import open3d as o3d

# Input mesh
p_ply = "mesh_example.ply"
# Output mesh
p_obj = "mesh_example.obj"

# Read PLY
mesh = o3d.io.read_triangle_mesh(p_ply, print_progress=True)
# Write OBJ
o3d.io.write_triangle_mesh(p_obj, mesh, compressed=True, print_progress=True)

Input mesh mesh_ply

Output mesh mesh_obj

cthenoz avatar Aug 05 '22 14:08 cthenoz