autonomousvision / sdfstudio

A Unified Framework for Surface Reconstruction
Apache License 2.0
1.95k stars 182 forks source link

Textured mesh artifact #82

Open gaoalexander opened 1 year ago

gaoalexander commented 1 year ago

Describe the bug When I extract a textured, uv-unwrapped mesh, there appears to be an artifact which looks like a discontinuity in the mesh along the x and y axis. The mesh looks like it is separated into 4 qudrants.

To Reproduce Steps to reproduce the behavior:

  1. Optimize SDF model (BakedSDF in this case)
  2. Export mesh.
  3. Extract textured, uv-unwrapped mesh.

Expected behavior Results are nearly as expected except for visible artifact.

Screenshots

Screenshot 2023-04-12 at 4 21 25 PM

Additional context Using default value target_num_faces=50000.

Raw mesh export (prior to re-loading to extract textured mesh) looks fine:

Screenshot 2023-04-12 at 4 37 59 PM
niujinshuchong commented 1 year ago

Hi, we use sliding window to extract the mesh so the mesh is not connected to each other at the window boundary. The textured mesh extraction will simplify the mesh using some algorithm so the mesh vertices position will be displaced and that's why you see it is separated into 4 parts.

But I don't why there are also many holes in the floor. Could you share the full commands to reproduce your results?

f-dy commented 1 year ago

@niujinshuchong can you please point to the code that does the mesh simplification? Why not stitch the sub-meshes before running the simplification?

f-dy commented 1 year ago

OK I think I found it, setting target_num_faces to None will skip decimation. For the second question, it seems like un-splitting vertices after mesh extraction would work.

niujinshuchong commented 1 year ago

@f-dy Un-splitting vertices sounds like a great idea! Could you kindly provide some reference of it? PR are also welcome.

f-dy commented 1 year ago

@niujinshuchong are vertices on both sides of the boundary supposed to have exactly the same coordinates? If yes, then using python's default dictionary hashing or anything that counts the number of identical elements in a list.vector is the easiest way to go.

Else, we would have to use a kdtree, put all vertices for all meshes in the kdtree (or just the boundary vertices, if we can easily identify them), then for each vertex do a ball search with a small radius (eg 1/1000 of the average edge length from the marching cubes result), and identify collocated vertices that way.

Looking at the code (here), you're running MC on volumes that don't overlap, so the boundary vertices may have wrong position and normal (to be checked). I think subvolumes should have an overlap of at least on voxels (but maybe I misread the code).

f-dy commented 1 year ago

To summarize, what I would recommend is:

niujinshuchong commented 1 year ago

@f-dy Thanks for the suggestion. The boundary vertices should have exactly same positions and these vertices can be merged with trimesh's merge_vertices. It's fixed in the latest commit.

However, we should run the sdf network with highest precision (use --torch-precision highest in ns-extract-mesh) to make sure the boundary vertices have the same positions, otherwise there might be some randomness.

jaysonnguyen commented 1 year ago

Hi, we use sliding window to extract the mesh so the mesh is not connected to each other at the window boundary. The textured mesh extraction will simplify the mesh using some algorithm so the mesh vertices position will be displaced and that's why you see it is separated into 4 parts.

But I don't why there are also many holes in the floor. Could you share the full commands to reproduce your results?

Hi @niujinshuchong, Do you have any solution to connect 4 parts of textured mesh?