Page MenuHome

Fix T70095: Quadriflow crash running on a messy mesh
ClosedPublic

Authored by Sebastian Parborg (zeddb) on Sep 23 2019, 5:25 PM.

Details

Summary

Quadriflow does not support non manifold meshes. (Edges with > 3 connected faces and discontinuous face normal directions)

While it does sometimes "work" in these configurations, the results are not good and in most caches it just flat out will crash.

I've added a sanity check to make sure that the input mesh is manifold.

@Pablo Dobarro (pablodp606) I've noticed that the voxel remesher also fails with these messy meshes (bad result, no crashes).
Perhaps we want to add some kind of sanity check like this as well for openvdb?

Diff Detail

Event Timeline

source/blender/editors/object/object_remesh.c
193–200

Sounds like a quite expensive operation to do.
Would think that allocating a single array of integers with a size of number of edges, and then iterate over mloop and keep counts of edges is cheaper.

205

is_manifold.

Also comment actually belongs to a function, not a variable.

I'm not sure about adding sanity checks before OpenVDB as some people may want to use it to fix non manifold meshes. Usually OpenVDB produces unexpected results if there are holes bigger than the voxel size in the mesh. We can add a flag to close holes in the mesh before running it.

I'm not sure about adding sanity checks before OpenVDB as some people may want to use it to fix non manifold meshes. Usually OpenVDB produces unexpected results if there are holes bigger than the voxel size in the mesh. We can add a flag to close holes in the mesh before running it.

Right you are. It would be tricky to figure out if the meshing will fail. It is fast anyways, so the users can simply do some trail and error.

Sebastian Parborg (zeddb) marked 2 inline comments as done.

I've updated the patch to adress the feedback given.

Brecht Van Lommel (brecht) requested changes to this revision.Oct 1 2019, 7:40 PM
Brecht Van Lommel (brecht) added inline comments.
source/blender/editors/object/object_remesh.c
199–202

Use MEM_calloc instead of manually initializing to zero.

216

This break only breaks out of one loop, add poly_index < mesh->totpoly && is_manifold_consistent to the first loop to make it break out of both.

This revision now requires changes to proceed.Oct 1 2019, 7:40 PM
Sebastian Parborg (zeddb) marked 2 inline comments as done.

Updated with the latest feedback

This revision is now accepted and ready to land.Oct 4 2019, 12:55 PM
Jacques Lucke (JacquesLucke) added inline comments.
source/blender/editors/object/object_remesh.c
231

I think it could be quite a bit faster in some cases (but never slower) to just iterate over all loops, instead of having this nested loop.

Also, doesn't this function fit better in mesh_validate.c?

source/blender/editors/object/object_remesh.c
231

If you think than an extra bool check will be that much slower, I can simply set poly_index to totpoly to end the loop if you wish.

We discussed moving this to mesh_validate.c. IIRC we decided to wait until something else needed this too and write a some more general functions for this then.

source/blender/editors/object/object_remesh.c
231

Nah, that would be quite hacky.

The two benefits of just iterating over all loops are:

  1. The code is more simple. Only one loop is required and you could just break out of it.
  2. It's faster. Not mainly because of the extra condition (which is highly predictable), but because the memory access pattern is more predictable. By iterating over the polygons in an outer loop, you might have to jump around in the loops array, resulting in a worse cache hit rate.

Note, I don't care too much about whether this is changed or not. I just happened to see this function and thought about how it could be made better.

source/blender/editors/object/object_remesh.c
231

Ah sorry, I misunderstood you.

I can try to just have one for loop instead that loops over all mloops!

I do really appreciate that you go through the changes and propose changes like these.
Thanks!

Sebastian Parborg (zeddb) marked 2 inline comments as done.Oct 7 2019, 6:16 PM
Sebastian Parborg (zeddb) added inline comments.
source/blender/editors/object/object_remesh.c
231

This is now pushed to master:
rBfc9e921495312ace23af11a69e738a8a7adbaeed

Thanks again for pointing this out.