isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.47k stars 2.31k forks source link

write_triangle_mesh with textured OBJ #1731

Open tritolol opened 4 years ago

tritolol commented 4 years ago

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.

theNded commented 4 years ago

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

zhan-xu commented 4 years ago

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

germanros1987 commented 4 years ago

@zhan-xu could you please provide the data?

zhan-xu commented 4 years ago

@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.

manhha1402 commented 3 years ago

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)

cthenoz commented 2 years ago

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

yshen47 commented 4 months ago

same issue

meminz commented 1 month ago

Same issue, when i try to write the triangle mesh i get this errors

[Open3D WARNING] Write PNG failed: image has no data.
[Open3D WARNING] Write OBJ successful, but failed to write texture file.