Patch Bullet to make it's convex hull implementation usable in BMesh
[blender.git] / extern / bullet2 / patches / convex_hull.patch
1 Index: extern/bullet2/src/Bullet-C-Api.h
2 ===================================================================
3 --- extern/bullet2/src/Bullet-C-Api.h   (revision 51556)
4 +++ extern/bullet2/src/Bullet-C-Api.h   (working copy)
5 @@ -167,6 +167,16 @@ extern "C" {
6         // needed for source/blender/blenkernel/intern/collision.c
7         double plNearestPoints(float p1[3], float p2[3], float p3[3], float q1[3], float q2[3], float q3[3], float *pa, float *pb, float normal[3]);
8  
9 +
10 +       /* Convex Hull */
11 +       PL_DECLARE_HANDLE(plConvexHull);
12 +       plConvexHull plConvexHullCompute(float (*coords)[3], int count);
13 +       int plConvexHullNumVertices(plConvexHull hull);
14 +       int plConvexHullNumFaces(plConvexHull hull);
15 +       void plConvexHullGetVertex(plConvexHull hull, int n, float coords[3], int *original_index);
16 +       int plConvexHullGetFaceSize(plConvexHull hull, int n);
17 +       void plConvexHullGetFaceVertices(plConvexHull hull, int n, int *vertices);
18 +
19  #ifdef __cplusplus
20  }
21  #endif
22 Index: extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp
23 ===================================================================
24 --- extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp (revision 51556)
25 +++ extern/bullet2/src/BulletDynamics/Dynamics/Bullet-C-API.cpp (working copy)
26 @@ -23,7 +23,7 @@ subject to the following restrictions:
27  #include "Bullet-C-Api.h"
28  #include "btBulletDynamicsCommon.h"
29  #include "LinearMath/btAlignedAllocator.h"
30 -
31 +#include "LinearMath/btConvexHullComputer.h"
32  
33  
34  #include "LinearMath/btVector3.h"
35 @@ -403,3 +403,60 @@ double plNearestPoints(float p1[3], float p2[3], float p3[3], float q1[3], float
36         return -1.0f;   
37  }
38  
39 +// Convex hull
40 +plConvexHull plConvexHullCompute(float (*coords)[3], int count)
41 +{
42 +       btConvexHullComputer *computer = new btConvexHullComputer;
43 +       computer->compute(reinterpret_cast< float* >(coords),
44 +                                         sizeof(*coords), count, 0, 0);
45 +       return reinterpret_cast<plConvexHull>(computer);
46 +}
47 +
48 +int plConvexHullNumVertices(plConvexHull hull)
49 +{
50 +       btConvexHullComputer *computer(reinterpret_cast< btConvexHullComputer* >(hull));
51 +       return computer->vertices.size();
52 +}
53 +
54 +int plConvexHullNumFaces(plConvexHull hull)
55 +{
56 +       btConvexHullComputer *computer(reinterpret_cast< btConvexHullComputer* >(hull));
57 +       return computer->faces.size();
58 +}
59 +
60 +void plConvexHullGetVertex(plConvexHull hull, int n, float coords[3],
61 +                                                  int *original_index)
62 +{
63 +       btConvexHullComputer *computer(reinterpret_cast< btConvexHullComputer* >(hull));
64 +       const btVector3 &v(computer->vertices[n]);
65 +       coords[0] = v[0];
66 +       coords[1] = v[1];
67 +       coords[2] = v[2];
68 +       (*original_index) = computer->original_vertex_index[n];
69 +}
70 +
71 +int plConvexHullGetFaceSize(plConvexHull hull, int n)
72 +{
73 +       btConvexHullComputer *computer(reinterpret_cast< btConvexHullComputer* >(hull));
74 +       const btConvexHullComputer::Edge *e_orig, *e;
75 +       int count;
76 +
77 +       for (e_orig = &computer->edges[computer->faces[n]], e = e_orig, count = 0;
78 +                count == 0 || e != e_orig;
79 +                e = e->getNextEdgeOfFace(), count++);
80 +       return count;
81 +}
82 +
83 +void plConvexHullGetFaceVertices(plConvexHull hull, int n, int *vertices)
84 +{
85 +       btConvexHullComputer *computer(reinterpret_cast< btConvexHullComputer* >(hull));
86 +       const btConvexHullComputer::Edge *e_orig, *e;
87 +       int count;
88 +
89 +       for (e_orig = &computer->edges[computer->faces[n]], e = e_orig, count = 0;
90 +                count == 0 || e != e_orig;
91 +                e = e->getNextEdgeOfFace(), count++)
92 +       {
93 +               vertices[count] = e->getTargetVertex();
94 +       }
95 +}
96 Index: extern/bullet2/src/LinearMath/btConvexHullComputer.cpp
97 ===================================================================
98 --- extern/bullet2/src/LinearMath/btConvexHullComputer.cpp      (revision 51556)
99 +++ extern/bullet2/src/LinearMath/btConvexHullComputer.cpp      (working copy)
100 @@ -2661,6 +2661,7 @@ btScalar btConvexHullComputer::compute(const void* coords, bool doubleCoords, in
101         }
102  
103         vertices.resize(0);
104 +       original_vertex_index.resize(0);
105         edges.resize(0);
106         faces.resize(0);
107  
108 @@ -2671,6 +2672,7 @@ btScalar btConvexHullComputer::compute(const void* coords, bool doubleCoords, in
109         {
110                 btConvexHullInternal::Vertex* v = oldVertices[copied];
111                 vertices.push_back(hull.getCoordinates(v));
112 +               original_vertex_index.push_back(v->point.index);
113                 btConvexHullInternal::Edge* firstEdge = v->edges;
114                 if (firstEdge)
115                 {
116 Index: extern/bullet2/src/LinearMath/btConvexHullComputer.h
117 ===================================================================
118 --- extern/bullet2/src/LinearMath/btConvexHullComputer.h        (revision 51556)
119 +++ extern/bullet2/src/LinearMath/btConvexHullComputer.h        (working copy)
120 @@ -67,6 +67,7 @@ class btConvexHullComputer
121  
122                 // Vertices of the output hull
123                 btAlignedObjectArray<btVector3> vertices;
124 +               btAlignedObjectArray<int> original_vertex_index;
125  
126                 // Edges of the output hull
127                 btAlignedObjectArray<Edge> edges;