kmammou / v-hacd

Automatically exported from code.google.com/p/v-hacd
BSD 3-Clause "New" or "Revised" License
1.42k stars 268 forks source link

How to set submesh boundaries when decomposing a mesh into convex submeshes #140

Open miyukin73 opened 2 years ago

miyukin73 commented 2 years ago

Hello,

I want to decompose the mesh of a cup into approximate convex submeshes.

I used V-HACD, and got the bellow files. Cup0722v1 (1).zip

However, when displayed on a simulation in Mujoco,

the bottom of the cup had become uneven as follows. image

I think it would be difficult to generate a perfectly clean cup shape because of the approximate decomposition technique.

For example, is it possible to consider the bottom of the cup as one par t or to divide the sides into smaller pieces?

Thank you in advance.

jratcliff63367 commented 2 years ago

That's probably just a matter of parameter tuning. I will look into this on Monday and help you get better quality results.

miyukin73 commented 2 years ago

Hello, @jratcliff63367

Thank you so much for your help...!

If possible, I would appreciate it if you could also check the following files.

Cup0831.zip

Thank you in advance.

jratcliff63367 commented 2 years ago

Ok, I took a look at it. And IMO the current version of V-HACD is giving good results for this mesh. Realize that the 'A' in V-HACD stands for 'approximate'. This cup is extremely concave. To fully represent it accurately would require a massive number of convex hulls. When you reduce it to a smaller number (the default value is 64 convex hulls) then you will get these approximation artifacts.

You can increase the number of convex hulls to make it have less approximation error but, of course, this will increase the memory and performance costs during simulation.

At the end of the day it is up to you to decide how many convex hulls you consider acceptable to use for an approximation.

Here are the results using the default values and 64 convex hulls. Personally I think these are pretty good results and I don't see anything wrong with it. The approximation artifacts at the bottom of the cup are a result of taking a completely concave surface and approximating it as a limited subset of convex pieces.

cup-default

If I increase the number of convex hulls dramatically, in this example all of the way up to 2000 hulls, you can see that the artifacts become smaller but still don't completely go away.

cup-full

So, at this point I don't see anything actually 'wrong' here. A convex approximation is just that, an approximation. In the case of a highly concave object, short of creating hundreds of thousands of convex pieces, it is never going to fit exactly perfectly.

miyukin73 commented 2 years ago

Thank you very much for your confirmation...!!

I have two questions.

First, is it possible to get xml and obj files when you increase the number of spheres to 2000? I would like to run an accurate simulation of a container and spheres as shown below,

but I am having trouble getting the same simulation results as in the real environment

because the sphere is currently in contact with the unevenness of the container.

Therefore, I would like to check the simulation result with your detailed files.

rotate0_0_9_a0 7_b0 7_c0 0075

Second, I would like to ask about the general method for "using highly concave objects" such as the containers used in this project.

I have learned about the use of V-HACD as a result of my research on the Internet,

but is there any other method that would be suitable for this case?

For example, is it possible to describe the container separately from the bottom and sides from the beginning?

I apologize that this is a very basic question, but I would be very grateful if you could reply.

Thank you in advance.

jratcliff63367 commented 2 years ago

Well, the current version of the PhysX SDK just added support for signed distance fields (SDF) which provides pixel perfect accuracy for simulation of any triangle mesh. Unfortunately this is a GPU only feature at this time.

You will never get a perfectly smooth surface representation by using V-HACD (or any convex decomposition library).

Imagine a curved surface like that cup. You would need effectively an infinite number of convex pieces to create a smooth surface.

This is really just a limitation of this approach.

First, is it possible to get xml and obj files when you increase the number of spheres to 2000?

I'm not sure what you mean by this. The maximum number of convex hulls is just a parameter you pass into the library. The library itself needs to be integrated into whatever tool chain you are working on.

jratcliff63367 commented 2 years ago

Here is an example of pushing the output to extreme limits. This screenshot has 8,340 convex pieces. As they get this tiny then the approximated surface gets smoother and smoother but it will never be perfect.

I used these command line parameters:

TestVHACD.exe .\meshes\cup.obj -v 10000000 -e 0.01 -h 100000 -d 18

-v 10000000 : Uses an insanely high voxel resolution of 10 million -e 0.01 : Sets the allowed error tolerance very low -h 10000 : Allows it to produce a massive number of output convex pieces -d 18 : Let's the library recurse extremely deeply into the octree.

cup-extreme

miyukin73 commented 2 years ago

Hello, @jratcliff63367

Thank you so much for the detailed explanation...!!

I will check it out.

Please let me know if I may ask you again when I have any further questions...!

Once again, thank you very much.