5 /*----------------------------------------------------------------------
6 Copyright (c) 2004 Open Dynamics Framework Group
10 Redistribution and use in source and binary forms, with or without modification, are permitted provided
11 that the following conditions are met:
13 Redistributions of source code must retain the above copyright notice, this list of conditions
14 and the following disclaimer.
16 Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
20 Neither the name of the Open Dynamics Framework Group nor the names of its contributors may
21 be used to endorse or promote products derived from this software without specific prior written permission.
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 DISCLAIMED. IN NO EVENT SHALL THE INTEL OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
28 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 -----------------------------------------------------------------------*/
32 namespace ConvexDecomposition
41 mNumOutputVertices = 0;
47 bool mPolygons; // true if indices represents polygons, false indices are triangles
48 unsigned int mNumOutputVertices; // number of vertices in the output hull
49 float *mOutputVertices; // array of vertices, 3 floats each x,y,z
50 unsigned int mNumFaces; // the number of faces produced
51 unsigned int mNumIndices; // the total number of indices
52 unsigned int *mIndices; // pointer to indices.
54 // If triangles, then indices are array indexes into the vertex list.
55 // If polygons, indices are in the form (number of points in face) (p1, p2, p3, ..) etc..
60 QF_TRIANGLES = (1<<0), // report results as triangles, not polygons.
61 QF_REVERSE_ORDER = (1<<1), // reverse order of the triangle indices.
62 QF_SKIN_WIDTH = (1<<2), // extrude hull based on this skin width
75 mVertexStride = sizeof(float)*3;
76 mNormalEpsilon = 0.001f;
77 mMaxVertices = 4096; // maximum number of points to be considered for a convex hull.
79 mSkinWidth = 0.01f; // default is one centimeter
82 HullDesc(HullFlag flag,
84 const float *vertices,
90 mVertexStride = stride;
91 mNormalEpsilon = 0.001f;
93 mSkinWidth = 0.01f; // default is one centimeter
96 bool HasHullFlag(HullFlag flag) const
98 if ( mFlags & flag ) return true;
102 void SetHullFlag(HullFlag flag)
107 void ClearHullFlag(HullFlag flag)
112 unsigned int mFlags; // flags to use when generating the convex hull.
113 unsigned int mVcount; // number of vertices in the input point cloud
114 const float *mVertices; // the array of vertices.
115 unsigned int mVertexStride; // the stride of each vertex, in bytes.
116 float mNormalEpsilon; // the epsilon for removing duplicates. This is a normalized value, if normalized bit is on.
118 unsigned int mMaxVertices; // maximum number of vertices to be considered for the hull!
119 unsigned int mMaxFaces;
132 HullError CreateConvexHull(const HullDesc &desc, // describes the input request
133 HullResult &result); // contains the resulst
135 HullError ReleaseResult(HullResult &result); // release memory allocated for this result, we are done with it.
139 void BringOutYourDead(const float *verts,unsigned int vcount, float *overts,unsigned int &ocount,unsigned int *indices,unsigned indexcount);
141 bool CleanupVertices(unsigned int svcount,
142 const float *svertices,
144 unsigned int &vcount, // output number of vertices
145 float *vertices, // location to store the results.