ConvexHullShape error

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
mcmonkey
Posts: 92
Joined: Fri Apr 17, 2015 11:42 pm

ConvexHullShape error

Post by mcmonkey »

So I'm constructing a ConvexHullShape with this code:

Code: Select all

            List<Vector3> vertices = GetCollisionVertices(input);
            for (int i = 0; i < vertices.Count; i++)
            {
                SysConsole.Output(OutputType.INFO, "VERT: " + vertices[i]);
            }
            return new ConvexHullShape(vertices);
Simple and straight forward.

I got this error:
System.ArgumentException: Invalid distance. Ensure the mesh is convex, has consistent winding, and contains the passed-in center.
at BEPUphysics.CollisionShapes.ConvexShapes.InertiaHelper.ComputeMinimumRadius(IList`1 vertices, IList`1 triangleIndices, Vector3& center) in C:\Users\mcmonkey\Desktop\bepuphysics-c903135c4aea\bepu
physics_c903135c4aea\BEPUphysics\CollisionShapes\ConvexShapes\InertiaHelper.cs:line 566
at BEPUphysics.CollisionShapes.ConvexShapes.ConvexHullShape.ComputeDescription(IList`1 vertices, Single collisionMargin, Vector3& center, IList`1 outputHullTriangleIndices, IList`1 outputUniqueSurf
aceVertices) in C:\Users\mcmonkey\Desktop\bepuphysics-c903135c4aea\bepuphysics_c903135c4aea\BEPUphysics\CollisionShapes\ConvexShapes\ConvexHullShape.cs:line 170
at BEPUphysics.CollisionShapes.ConvexShapes.ConvexHullShape..ctor(IList`1 vertices) in C:\Users\mcmonkey\Desktop\bepuphysics-c903135c4aea\bepuphysics_c903135c4aea\BEPUphysics\CollisionShapes\Convex
Shapes\ConvexHullShape.cs:line 48
The vertex list used (edited to be a shorter bit of spam)
{-0.2847493, 1.846569, 0} {-0.2847493, 1.811087, -0.3602477} {0.2847494, 1.811087, -0.3602476} {-0.2847493, 1.706007, -0.7066513} {0.2847495, 1.706007, -0.7066513} {0.2847494, 1.811087, -0.3602476} {-0.2847493, 1.706007, -0.7066513} {-0.2847493, 1.535366, -1.025899} {0.2847494, 1.535366, -1.025899} {-0.2847493, 1.535366, -1.025899} {-0.2847493, 1.305721, -1.305722} {0.2847495, 1.305721, -1.305721} {-0.2847493, 1.305721, -1.305722} {-0.2847493, 1.025898, -1.535366} {0.2847494, 1.025898, -1.535366} {-0.2847493, 1.025898, -1.535366} {-0.2847493, 0.7066511, -1.706007} {0.2847494, 0.7066511, -1.706007} {-0.2847493, 0.7066511, -1.706007} {-0.2847493, 0.3602475, -1.811088} {0.2847494, 0.3602475, -1.811088} {-0.2847493, 0.3602475, -1.811088} {-0.2847493, -1.57037E-07, -1.846569} {0.2847494, -1.57037E-07, -1.846569} {-0.2847493, -0.3602478, -1.811088} {0.2847495, -0.3602478, -1.811088} {0.2847494, -1.57037E-07, -1.846569} {-0.2847493, -0.7066514, -1.706008} {0.2847495, -0.7066514, -1.706007} {0.2847495, -0.3602478, -1.811088} {-0.2847493, -1.025899, -1.535366} {0.2847494, -1.025899, -1.535366} {0.2847495, -0.7066514, -1.706007} {-0.2847493, -1.305722, -1.305722} {0.2847495, -1.305722, -1.305721} {0.2847494, -1.025899, -1.535366} {-0.2847493, -1.535366, -1.025899} {0.2847495, -1.535366, -1.025899} {0.2847495, -1.305722, -1.305721} {-0.2847493, -1.706008, -0.7066511} {0.2847494, -1.706008, -0.7066509} {0.2847495, -1.535366, -1.025899} {-0.2847493, -1.811088, -0.3602473} {0.2847494, -1.811088, -0.3602471} {0.2847494, -1.706008, -0.7066509} {-0.2847493, -1.846569, 6.74576E-07} {0.2847495, -1.846569, 8.94705E-07} {0.2847494, -1.811088, -0.3602471} {-0.2847493, -1.811088, 0.3602486} {0.2847495, -1.811088, 0.3602486} {0.2847495, -1.846569, 8.94705E-07} {-0.2847493, -1.706007, 0.7066523} {0.2847495, -1.706007, 0.7066525} {0.2847495, -1.811088, 0.3602486} {-0.2847493, -1.535366, 1.0259} {0.2847495, -1.535366, 1.0259} {0.2847495, -1.706007, 0.7066525} {-0.2847493, -1.305721, 1.305722} {0.2847494, -1.305721, 1.305723} {0.2847495, -1.535366, 1.0259} {-0.2847493, -1.025898, 1.535367} {0.2847494, -1.025898, 1.535367} {0.2847494, -1.305721, 1.305723} {-0.2847493, -0.7066503, 1.706008} {0.2847494, -0.7066503, 1.706008} {0.2847494, -1.025898, 1.535367} {-0.2847493, -0.7066503, 1.706008} {-0.2847495, -0.3602464, 1.811088} {0.2847494, -0.3602464, 1.811088} {-0.2847493, 1.4866E-06, 1.846569} {0.2847494, 1.4866E-06, 1.846569} {0.2847494, -0.3602464, 1.811088} {-0.2847493, 1.4866E-06, 1.846569} {-0.2847493, 0.3602494, 1.811087} {0.2847494, 0.3602494, 1.811088} {-0.2847493, 0.3602494, 1.811087} {-0.2847493, 0.706653, 1.706007} {0.2847494, 0.706653, 1.706007} {-0.2847493, 0.706653, 1.706007} {-0.2847493, 1.0259, 1.535365} {0.2847494, 1.0259, 1.535365} {-0.2847493, 1.0259, 1.535365} {-0.2847493, 1.305723, 1.30572} {0.2847494, 1.305723, 1.30572} {-0.2847493, 1.535367, 1.025897} {0.2847495, 1.535367, 1.025897} {0.2847494, 1.305723, 1.30572} {-0.2847493, 1.535367, 1.025897} {-0.2847493, 1.706008, 0.706649} {0.2847495, 1.706008, 0.7066493} {-0.2847493, -1.811088, 0.3602486} {-0.2847493, 1.535366, -1.025899} {-0.2847493, 1.811087, -0.3602477} {-0.2847493, 1.811088, 0.3602451} {-0.2847493, 1.846569, 0} {0.2847495, 1.846569, 2.3432E-07} {-0.2847493, 1.706008, 0.706649} {-0.2847493, 1.811088, 0.3602451} {0.2847495, 1.811088, 0.3602451} {0.2847494, -1.305721, 1.305723} {0.2847495, 1.706007, -0.7066513} {0.2847495, 1.305721, -1.305721} {-0.2847493, 1.846569, 0} {0.2847494, 1.811087, -0.3602476} {0.2847495, 1.846569, 2.3432E-07} {-0.2847493, 1.706007, -0.7066513} {0.2847494, 1.811087, -0.3602476} {-0.2847493, 1.811087, -0.3602477} {-0.2847493, 1.706007, -0.7066513} {0.2847494, 1.535366, -1.025899} {0.2847495, 1.706007, -0.7066513} {-0.2847493, 1.535366, -1.025899} {0.2847495, 1.305721, -1.305721} {0.2847494, 1.535366, -1.025899} {-0.2847493, 1.305721, -1.305722} {0.2847494, 1.025898, -1.535366} {0.2847495, 1.305721, -1.305721} {-0.2847493, 1.025898, -1.535366} {0.2847494, 0.7066511, -1.706007} {0.2847494, 1.025898, -1.535366} {-0.2847493, 0.7066511, -1.706007} {0.2847494, 0.3602475, -1.811088} {0.2847494, 0.7066511, -1.706007} {-0.2847493, 0.3602475, -1.811088} {0.2847494, -1.57037E-07, -1.846569} {0.2847494, 0.3602475, -1.811088} {-0.2847493, -0.3602478, -1.811088} {0.2847494, -1.57037E-07, -1.846569} {-0.2847493, -1.57037E-07, -1.846569} {-0.2847493, -0.7066514, -1.706008} {0.2847495, -0.3602478, -1.811088} {-0.2847493, -0.3602478, -1.811088} {-0.2847493, -1.025899, -1.535366} {0.2847495, -0.7066514, -1.706007} {-0.2847493, -0.7066514, -1.706008} {-0.2847493, -1.305722, -1.305722} {0.2847494, -1.025899, -1.535366} {-0.2847493, -1.025899, -1.535366} {-0.2847493, -1.535366, -1.025899} {0.2847495, -1.305722, -1.305721} {-0.2847493, -1.305722, -1.305722} {-0.2847493, -1.706008, -0.7066511} {0.2847495, -1.535366, -1.025899} {-0.2847493, -1.535366, -1.025899} {-0.2847493, -1.811088, -0.3602473} {0.2847494, -1.706008, -0.7066509} {-0.2847493, -1.706008, -0.7066511} {-0.2847493, -1.846569, 6.74576E-07} {0.2847494, -1.811088, -0.3602471} {-0.2847493, -1.811088, -0.3602473} {-0.2847493, -1.811088, 0.3602486} {0.2847495, -1.846569, 8.94705E-07} {-0.2847493, -1.846569, 6.74576E-07} {-0.2847493, -1.706007, 0.7066523} {0.2847495, -1.811088, 0.3602486} {-0.2847493, -1.811088, 0.3602486} {-0.2847493, -1.535366, 1.0259} {0.2847495, -1.706007, 0.7066525} {-0.2847493, -1.706007, 0.7066523} {-0.2847493, -1.305721, 1.305722} {0.2847495, -1.535366, 1.0259} {-0.2847493, -1.535366, 1.0259} {-0.2847493, -1.025898, 1.535367} {0.2847494, -1.305721, 1.305723} {-0.2847493, -1.305721, 1.305722} {-0.2847493, -0.7066503, 1.706008} {0.2847494, -1.025898, 1.535367} {-0.2847493, -1.025898, 1.535367} {-0.2847493, -0.7066503, 1.706008} {0.2847494, -0.3602464, 1.811088} {0.2847494, -0.7066503, 1.706008} {-0.2847493, 1.4866E-06, 1.846569} {0.2847494, -0.3602464, 1.811088} {-0.2847495, -0.3602464, 1.811088} {-0.2847493, 1.4866E-06, 1.846569} {0.2847494, 0.3602494, 1.811088} {0.2847494, 1.4866E-06, 1.846569} {-0.2847493, 0.3602494, 1.811087} {0.2847494, 0.706653, 1.706007} {0.2847494, 0.3602494, 1.811088} {-0.2847493, 0.706653, 1.706007} {0.2847494, 1.0259, 1.535365} {0.2847494, 0.706653, 1.706007} {-0.2847493, 1.0259, 1.535365} {0.2847494, 1.305723, 1.30572} {0.2847494, 1.0259, 1.535365} {-0.2847493, 1.535367, 1.025897} {0.2847494, 1.305723, 1.30572} {-0.2847493, 1.305723, 1.30572} {-0.2847493, 1.535367, 1.025897} {0.2847495, 1.706008, 0.7066493} {0.2847495, 1.535367, 1.025897} {-0.2847493, 1.811087, -0.3602477} {-0.2847493, 1.846569, 0} {-0.2847493, 1.811088, 0.3602451} {-0.2847493, 1.811088, 0.3602451} {-0.2847493, 1.706008, 0.706649} {-0.2847493, 1.811087, -0.3602477} {-0.2847493, 1.535367, 1.025897} {-0.2847493, 1.305723, 1.30572} {-0.2847493, 1.0259, 1.535365} {-0.2847493, 1.0259, 1.535365} {-0.2847493, 0.706653, 1.706007} {-0.2847493, 0.3602494, 1.811087} {-0.2847493, 0.3602494, 1.811087} {-0.2847493, 1.4866E-06, 1.846569} {-0.2847493, -1.025898, 1.535367} {-0.2847495, -0.3602464, 1.811088} {-0.2847493, -0.7066503, 1.706008} {-0.2847493, -1.025898, 1.535367} {-0.2847493, -1.025898, 1.535367} {-0.2847493, -1.305721, 1.305722} {-0.2847493, -1.535366, 1.0259} {-0.2847493, -1.535366, 1.0259} {-0.2847493, -1.706007, 0.7066523} {-0.2847493, -1.025898, 1.535367} {-0.2847493, -1.811088, 0.3602486} {-0.2847493, -1.846569, 6.74576E-07} {-0.2847493, -1.535366, -1.025899} {-0.2847493, -1.811088, -0.3602473} {-0.2847493, -1.706008, -0.7066511} {-0.2847493, -1.535366, -1.025899} {-0.2847493, -1.535366, -1.025899} {-0.2847493, -1.305722, -1.305722} {-0.2847493, -0.7066514, -1.706008} {-0.2847493, -1.025899, -1.535366} {-0.2847493, -0.7066514, -1.706008} {-0.2847493, -1.305722, -1.305722} {-0.2847493, -0.3602478, -1.811088} {-0.2847493, -1.57037E-07, -1.846569} {-0.2847493, 0.3602475, -1.811088} {-0.2847493, 0.3602475, -1.811088} {-0.2847493, 0.7066511, -1.706007} {-0.2847493, 1.535366, -1.025899} {-0.2847493, 1.025898, -1.535366} {-0.2847493, 1.305721, -1.305722} {-0.2847493, 0.7066511, -1.706007} {-0.2847493, 1.535366, -1.025899} {-0.2847493, 1.706007, -0.7066513} {-0.2847493, 1.811087, -0.3602477} {-0.2847493, 1.811087, -0.3602477} {-0.2847493, 1.706008, 0.706649} {-0.2847493, 1.535367, 1.025897} {-0.2847493, 1.535367, 1.025897} {-0.2847493, 1.0259, 1.535365} {-0.2847493, 1.811087, -0.3602477} {-0.2847493, 1.4866E-06, 1.846569} {-0.2847495, -0.3602464, 1.811088} {-0.2847493, -1.025898, 1.535367} {-0.2847493, -1.025898, 1.535367} {-0.2847493, -1.706007, 0.7066523} {-0.2847493, -1.811088, 0.3602486} {-0.2847493, -1.846569, 6.74576E-07} {-0.2847493, -1.811088, -0.3602473} {-0.2847493, -1.535366, -1.025899} {-0.2847493, -1.535366, -1.025899} {-0.2847493, -0.7066514, -1.706008} {-0.2847493, -0.3602478, -1.811088} {-0.2847493, -0.3602478, -1.811088} {-0.2847493, 0.3602475, -1.811088} {-0.2847493, -1.811088, 0.3602486} {-0.2847493, 1.305721, -1.305722} {-0.2847493, 1.535366, -1.025899} {-0.2847493, 0.7066511, -1.706007} {-0.2847493, 1.811087, -0.3602477} {-0.2847493, 1.0259, 1.535365} {-0.2847493, -1.811088, 0.3602486} {-0.2847493, 0.3602494, 1.811087} {-0.2847493, -1.025898, 1.535367} {-0.2847493, -1.811088, 0.3602486} {-0.2847493, -1.811088, 0.3602486} {-0.2847493, -1.535366, -1.025899} {-0.2847493, -0.3602478, -1.811088} {-0.2847493, 0.3602475, -1.811088} {-0.2847493, 1.535366, -1.025899} {-0.2847493, -1.811088, 0.3602486} {-0.2847493, 1.0259, 1.535365} {-0.2847493, 0.3602494, 1.811087} {-0.2847493, -1.811088, 0.3602486} {-0.2847493, 1.811088, 0.3602451} {0.2847495, 1.846569, 2.3432E-07} {0.2847495, 1.811088, 0.3602451} {-0.2847493, 1.706008, 0.706649} {0.2847495, 1.811088, 0.3602451} {0.2847495, 1.706008, 0.7066493} {0.2847495, 1.846569, 2.3432E-07} {0.2847494, 1.811087, -0.3602476} {0.2847495, 1.811088, 0.3602451} {0.2847495, 1.706007, -0.7066513} {0.2847494, 1.535366, -1.025899} {0.2847495, 1.305721, -1.305721} {0.2847495, 1.305721, -1.305721} {0.2847494, 1.025898, -1.535366} {0.2847494, 0.7066511, -1.706007} {0.2847494, 0.7066511, -1.706007} {0.2847494, 0.3602475, -1.811088} {0.2847495, 1.305721, -1.305721} {0.2847494, -1.57037E-07, -1.846569} {0.2847495, -0.3602478, -1.811088} {0.2847495, -0.7066514, -1.706007} {0.2847495, -0.7066514, -1.706007} {0.2847494, -1.025899, -1.535366} {0.2847495, -1.305722, -1.305721} {0.2847495, -1.305722, -1.305721} {0.2847495, -1.535366, -1.025899} {0.2847494, -1.811088, -0.3602471} {0.2847494, -1.706008, -0.7066509} {0.2847494, -1.811088, -0.3602471} {0.2847495, -1.535366, -1.025899} {0.2847495, -1.846569, 8.94705E-07} {0.2847495, -1.811088, 0.3602486} {0.2847495, -1.706007, 0.7066525} {0.2847495, -1.706007, 0.7066525} {0.2847495, -1.535366, 1.0259} {0.2847494, -1.305721, 1.305723} {0.2847494, -1.305721, 1.305723} {0.2847494, -1.025898, 1.535367} {0.2847494, -0.7066503, 1.706008} {0.2847494, -0.7066503, 1.706008} {0.2847494, -0.3602464, 1.811088} {0.2847494, 1.4866E-06, 1.846569} {0.2847494, 1.4866E-06, 1.846569} {0.2847494, 0.3602494, 1.811088} {0.2847494, 0.706653, 1.706007} {0.2847494, 0.706653, 1.706007} {0.2847494, 1.0259, 1.535365} {0.2847494, 1.305723, 1.30572} {0.2847494, 1.305723, 1.30572} {0.2847495, 1.535367, 1.025897} {0.2847495, 1.811088, 0.3602451} {0.2847495, 1.706008, 0.7066493} {0.2847495, 1.811088, 0.3602451} {0.2847495, 1.535367, 1.025897} {0.2847495, 1.706007, -0.7066513} {0.2847494, 0.706653, 1.706007} {0.2847495, 1.811088, 0.3602451} {0.2847495, 1.305721, -1.305721} {0.2847494, 0.3602475, -1.811088} {0.2847494, -1.57037E-07, -1.846569} {0.2847494, -1.57037E-07, -1.846569} {0.2847495, -0.7066514, -1.706007} {0.2847494, -1.811088, -0.3602471} {0.2847495, -1.305722, -1.305721} {0.2847494, -1.811088, -0.3602471} {0.2847495, -0.7066514, -1.706007} {0.2847495, -1.846569, 8.94705E-07} {0.2847495, -1.706007, 0.7066525} {0.2847494, -1.305721, 1.305723} {0.2847494, -1.305721, 1.305723} {0.2847494, -0.7066503, 1.706008} {0.2847495, 1.706007, -0.7066513} {0.2847494, 1.4866E-06, 1.846569} {0.2847494, 0.706653, 1.706007} {0.2847495, 1.706007, -0.7066513} {0.2847494, 1.305723, 1.30572} {0.2847495, 1.811088, 0.3602451} {0.2847494, 0.706653, 1.706007} {0.2847495, 1.706007, -0.7066513} {0.2847494, -0.7066503, 1.706008} {0.2847494, 1.4866E-06, 1.846569} {0.2847494, -1.57037E-07, -1.846569} {0.2847494, -1.811088, -0.3602471} {0.2847495, 1.305721, -1.305721} {0.2847495, -1.846569, 8.94705E-07} {0.2847494, -1.305721, 1.305723} {0.2847495, 1.305721, -1.305721} {0.2847495, 1.811088, 0.3602451} {0.2847494, 1.811087, -0.3602476} {0.2847495, 1.706007, -0.7066513} {0.2847495, 1.305721, -1.305721} {0.2847494, -1.811088, -0.3602471} {0.2847495, -1.846569, 8.94705E-07}
The vertices might be wound backwards (not really sure which way they're wound actually, or if they form valid triangles at all)... but that should be irrelevant, as this is a convex hull, not a triangle mesh. If I understand convex hulls correctly, the input is a list of points in space to be wrapped around, not triangles, right?


Also it's compiled locally to include recent edits, there's no modification to the convexhull code. It's built in release configuration (so line numbers are non-exact).
Lars
Posts: 3
Joined: Mon Jan 11, 2016 10:31 am

Re: ConvexHullShape error

Post by Lars »

Hi,

try this line before creating the new ConvexHullShape

Code: Select all

ConvexHullHelper.RemoveRedundantPoints(vertices);
mcmonkey
Posts: 92
Joined: Fri Apr 17, 2015 11:42 pm

Re: ConvexHullShape error

Post by mcmonkey »

Lars wrote:Hi,

try this line before creating the new ConvexHullShape

Code: Select all

ConvexHullHelper.RemoveRedundantPoints(vertices);
Ooh. That fixed it, thanks!


Now the question is why is that necessary to do in my own code?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: ConvexHullShape error

Post by Norbo »

The vertices might be wound backwards (not really sure which way they're wound actually, or if they form valid triangles at all)... but that should be irrelevant, as this is a convex hull, not a triangle mesh. If I understand convex hulls correctly, the input is a list of points in space to be wrapped around, not triangles, right?
The point set handed to a ConvexHullShape is indeed just a soup of orderless points. That error is spawned by an internal function that operates on a triangle mesh generated from the point set. Input containing degenerate point subsets can cause bad triangle meshes.
Now the question is why is that necessary to do in my own code?
Two reasons, with some confounders.
1) Ideally, shapes would be preprocessed in some kind of content pipeline so that a minimum amount of work has to be done at runtime. For maximum efficiency, this would using the ConvexHullShape(IList<Vector3> localSurfaceVertices, ConvexShapeDescription description) constructor, which doesn't do any processing at all, with preprocessed data.
2) RemoveRedundantPoints has a configurable threshold for what a 'redundant' point is, with a default of 0.001. Different data sets could have different needed thresholds, so including it by default could introduce some odd behavior.

In practice, the ConvexHullShape does have constructor overloads which do some processing, and it wouldn't be a huge stretch to add RemoveRedundantPoints to them. I'm probably going to make things more explicitly separated in v2.
Post Reply