Exception creating convex hull

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
musmuris
Posts: 4
Joined: Sat Jan 18, 2014 2:34 pm

Exception creating convex hull

Post by musmuris »

I'm starting to write a space game using Monogame, and so far have an asteroid field you can fly through - however currently you can fly right through the asteroids! Next step is to put BEPUphysics in - and my first stage was to try and make a convex hull for the asteroid. So I've just taken the points I'm using for display (136 vertices) and made Bepu Vector3s and passed them to ConvexHull and I get:

Argument Exception: "Invalid distance: mesh may not be concave, winding may not be consistent, or the center may be outside the mesh."

(This comes from InertiaHelper.ComputeMinimumRadius )

The code is just like:

Code: Select all

 
var inVerts = model.MeshData.Meshes[0].Vertices;
IList<BEPUutilities.Vector3> physverts = inVerts.Select(x => new BEPUutilities.Vector3((float) x.x, (float) x.y, (float) x.z)).ToList();          
ConvexHull cvh = new ConvexHull(BEPUutilities.Vector3.Zero, physverts, 100f);
(Note the "model" used above is one of my own design - Monogame doesn't have a content pipeline so I'm just reading points from a file with JSON data in for now! I could PM the point data if it helps?)

I'm I not right in assuming you can pass an arbitrary cloud of points to the algorithm and have it generate a convex hull?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Exception creating convex hull

Post by Norbo »

Interesting; I'll probably need the point data to diagnose this.
I'm I not right in assuming you can pass an arbitrary cloud of points to the algorithm and have it generate a convex hull?
You should be able to do it without an issue. There are some known corner cases where the algorithm can fail, but these are supposed to be very hard to hit without throwing really nasty geometry at it.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Exception creating convex hull

Post by Norbo »

It appears to be a numerical failure caused by overlapping vertices. The point set that didn't crash still had some bad tessellation after convex hull generation. The crash associated with the from-doubles point set (despite a difference of no more than 5.5e-7) was a numerical accident; the 'bad tessellation' is chaotic and highly sensitive to small variations in input.

To avoid any bad tessellation, run ConvexHullHelper.RemoveRedundantPoints on the point set before passing it to the convex hull generator.

To be clear, the convex hull generator is intended to produce correct results for this dataset without needing to run a RemoveRedundantPoints preprocess on it. RemoveRedundantPoints is supposed to be an optional and situational optimization not required for correctness. The fact that the generator has trouble is something I'd like to address eventually.
musmuris
Posts: 4
Joined: Sat Jan 18, 2014 2:34 pm

Re: Exception creating convex hull

Post by musmuris »

Thanks a lot for looking at this. I went back and looked at where the data was coming from (it's some old models I salvaged from a custom format), and it turns out the very original data was in float, that got read into doubles and then back into floats when I was building the convex hull - so it's possible the problems got introduced then. I'll try the redundant thing first, then if not I'll have to try and extract the original float data in the first place and see if that works.

If that fails I can also convert to string and then parse it! :twisted:
Post Reply