Point set is degenerate error when adding new ConvexHulls

Discuss any questions about BEPUphysics or problems encountered.
al9191
Posts: 68
Joined: Wed Nov 16, 2011 11:19 pm

Point set is degenerate error when adding new ConvexHulls

Post by al9191 »

I have method that creates our games dynamic objects where it creates them into a ConvexHull.

Code: Select all

public DynamicObject(int modelNum, string name, Vector3 pos)
            : base(modelNum, name, pos)
        {
            Vector3[] vertices;
            int[] indices;
            TriangleMesh.GetVerticesAndIndicesFromModel(GameModels.getModel(modelNum).PhysicsModel, out vertices, out indices);
            float scaleFactor = GameModels.getModel(modelNum).PhysicsScale.M11;
            Vector3 scale = new Vector3(scaleFactor,scaleFactor,scaleFactor);
            for (int i = 0; i < vertices.Length; i++ )
            {
                vertices[i] = Vector3.Multiply(vertices[i], scale);
            }
            body = new ConvexHull(pos, vertices, 50f);
            body.Tag = GameModels.getModel(modelNum);
        }
I am writing a manager to spawn new dynamic objects (which are enemies) when there are less than 15 found in the world. So I generate random x and z values and then place the enemy at (x, 0.5f, z) (providing the position is not occupied.)

It managed to spawn them fine, but then suddenly threw an AurgumentException after a while on the:

Code: Select all

body = new ConvexHull(pos, vertices, 50f);
line, saying "Point set is degenerate."
It seems to generate the exception sometimes, but the rest of the time the framerate just drops from 63 to around 27.

What does this mean and how do I fix it?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Point set is degenerate error when adding new ConvexHull

Post by Norbo »

That typically means the point set provided to the method has very little or no volume. It can't create a hull around a completely flat object, a line, or a single point. Certain nearly-degenerate point sets can also trigger the error if they're within certain tolerances.

If the loaded point set is clearly not degenerate, I could try loading the model in question to see if the hull generator is just hitting some numerical failure.
al9191
Posts: 68
Joined: Wed Nov 16, 2011 11:19 pm

Re: Point set is degenerate error when adding new ConvexHull

Post by al9191 »

The model it is creating it from loads and creates ConvexHulls perfectly.
Just every now and then, every few runs of game, or sometimes randomly while playing, after killing enemies and some new ones are spawned. Every now and then it will throw the exception on one of those being created. Even though they are all created from exactly the same model.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Point set is degenerate error when adding new ConvexHull

Post by Norbo »

Could you send me a simple reproduction case with the model showing the failure? A custom demo in the BEPUphysicsDemos would be great.

I don't know of any reason off the top of my head why there would be significant nondeterminism in computing the convex hull, but a reproduction case will highlight it.
al9191
Posts: 68
Joined: Wed Nov 16, 2011 11:19 pm

Re: Point set is degenerate error when adding new ConvexHull

Post by al9191 »

Ah ok thanks. I will attempt to create a replication case of it and send it to you. How do I go about making a custom demo in BEPUPhysics?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Point set is degenerate error when adding new ConvexHull

Post by Norbo »

How do I go about making a custom demo in BEPUPhysics?
The easiest way is just to copy-paste one of the existing demos in the BEPUphysicsDemos project, like the WallDemo, and replace the constructor code with your own. You can override the update and draw methods to perform any extra logic you need.

By default, the demos will just put all the entities created by the demo constructor into a BEPUphysicsDrawer model drawer. If you want to add other things to the drawer, you'll need to add it to the model drawer object owned by the Game.
al9191
Posts: 68
Joined: Wed Nov 16, 2011 11:19 pm

Re: Point set is degenerate error when adding new ConvexHull

Post by al9191 »

Sorry I was really busy over the weekend!
I have a custom demo. However, I have a question:

My ConvexHull is made from an fbx model. How do I go about referencing this in a demo?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Point set is degenerate error when adding new ConvexHull

Post by Norbo »

Plop it into the content project like usual and use the game's Content reference to load it in the demo. The StaticMeshDemo and others do it this way.
al9191
Posts: 68
Joined: Wed Nov 16, 2011 11:19 pm

Re: Point set is degenerate error when adding new ConvexHull

Post by al9191 »

I've added it to the content project and have put it to create the ConvexHull in the constructor from the model.

How do I send it to you?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Point set is degenerate error when adding new ConvexHull

Post by Norbo »

Quickest would probably be an uploaded zip here on the thread or via a PM if you'd prefer.
al9191
Posts: 68
Joined: Wed Nov 16, 2011 11:19 pm

Re: Point set is degenerate error when adding new ConvexHull

Post by al9191 »

Ok. I have created the demo and put it in the folder with the others. I don't actually know how to run it. But it is in the folder with the others like WallDemo.
Zip the whole demos project?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Point set is degenerate error when adding new ConvexHull

Post by Norbo »

I'll only need the one demo and the content file(s) it references. I'll stick them in the right spots locally.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Point set is degenerate error when adding new ConvexHull

Post by Norbo »

By the way, if you'd like to fiddle around with the demo yourself, you can run it by adding the demo to the DemosGame listing of demos or find the spot where it actually switches the Demo and replace the Activator.CreateInstance line with a direct constructor of your desired demo type.
al9191
Posts: 68
Joined: Wed Nov 16, 2011 11:19 pm

Re: Point set is degenerate error when adding new ConvexHull

Post by al9191 »

Thanks. I have ran it. It adds 10 of the convex hulls to the space on top of the ground.
There is no degenerate error happening when I run it as a demo.

The error seems to occur every now and then when running the game where it spawns enemies every time there is less than 15 enemies detected. I pick random x and z co-ordinates to spawn at, query the space if it is occupied, and if not add it to it.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Point set is degenerate error when adding new ConvexHull

Post by Norbo »

Given that it does not occur within hundreds of randomized construction attempts on both debug and release, it is likely that it is not some sort of sneaky nondeterminism or uncleared and reused state inherent to the the convex hull method itself.

That model does seem to confuse the algorithm a bit due to a surface with an internal coplanar vertex. The result are some unnecessary surface triangles. It should not cause degeneracy issues and collision detection will be unharmed. The existence of an unnecessary vertex will not reduce performance noticeably. The unnecessary surface triangles may confuse the inertia tensor calculation a bit, but it doesn't appear to be noticeable with this model. [If I get some time I'd really like to improve the convex hull algorithm- it's pretty ancient.]

Given all of that, my guess is that there is some intermittent issue interfering with the loading of objects at runtime. Asynchronous systems would be prime suspects.

However, the problem can be addressed by caching shape data. At initialization, you could create a single ConvexHull object representing the model. Then, for future objects, create an Entity directly from the ConvexHull.CollisionInformation.Shape, ConvexHull.Mass, ConvexHull.LocalInertiaTensor, and ConvexHull.Volume. By caching all of those values, no further work has to be done using the convex hull algorithm and no extra computation is needed for physical properties. If you noticed any "jig" when objects were created before, it will go away completely with caching, even on the Xbox360.
Post Reply