kmammou/v-hacd

question regarding shape decomposition

sancelot opened this issue · 7 comments

I made a decomposition of this shape :
image

The resulting convex shape is :
image

I would expect the red surface here should be sharp edge and not like this:
image

Is there a way to avoid / improve this ?

Regards
Steph

Can you upload this mesh as a Wavefront OBJ file and I will see what I can do to tweak it.

Can you upload this mesh as a Wavefront OBJ file and I will see what I can do to tweak it.

plaque.zip (obj files are not allowed, so it is a zip)

Ok, I looked into it and this is just something V-HACD cannot do with a high degree of accuracy. It fundamentally does an approximation, more for organic shapes where small errors aren't that big of deal. But in your example of a machined object with hard sharp angles, I can get it to produce somewhat 'better' results but never does it produce an exact representation.

Also, when I started dialing up the detail parameters really high I saw that the executable was crashing. I looked into it, and it was because by default CMAKE generates a 32 bit build. I hadn't even realize that was happening and it was running out of memory.

I rebuilt the executable as 64 bit so now you can dial the parameters up very high without it crashing.

Here is one example of some parameters I tried:

TestVHACD.exe .\meshes\plaque.obj -r 1000000 -e 0 -d 12 -h 512 -s false

The big change here is a higher voxel resolution (-r 1000000) a zero error tolerance (-d 0) allowing it to do deeper recursion (-d 12) allowing it to produce up to 512 convex hulls (-h 512) and turning off the 'shrinkwrapping option' which can sometimes introduce some slight error (-s false)

With these parameters I get this result. It's now has a better representation of that channel you highlighted but it still isn't perfect. So if this is to be used in say a robotics simulation or as a machine part it won't be good enough.

I'm not giving up on trying to produce better results, but at this time this was the best I could get.
plaque

So I continued tweaking parameters and found something that finally gives a perfect result for that channel.

The big change was relaxing the error metric to 0.1 rather than leaving it strictly at 0. I think this may be the best tuning parameter to mess with. I don't think using zero for the error metric is a good idea but low values (I would try between 0.01 and 0.1) maybe that helps it converge better.

I used this:

TestVHACD.exe .\meshes\plaque.obj -r 10000000 -e 0.1 -d 15 -h 512 -s false

And got this result:
plaque-better

Ok, this looks pretty good and is real-time results. So I would focus around this area for parameters.

Arguments: TestVHACD.exe .\meshes\plaque.obj -r 10000000 -e 0.01 -d 14 -h 128 -s false

Results:

plaque-best

Amazing. So, it will work, I have only to compile 64 bits and tune settings ?
Is that right ?

You don't need 64 bit. I just found that with an error tolerance of zero it can crash. I'm actually going to remove zero as an option. Just use the settings above.