33 #ifndef DART_COLLISION_FCL_MESH_COLLISIONSHAPES_HPP_
34 #define DART_COLLISION_FCL_MESH_COLLISIONSHAPES_HPP_
37 #include <assimp/scene.h>
54 ::fcl::BVHModel<BV>* model = new ::fcl::BVHModel<BV>;
57 for (
unsigned int i = 0; i < _mesh->mNumMeshes; i++)
59 for (
unsigned int j = 0; j < _mesh->mMeshes[i]->mNumFaces; j++)
62 for (
unsigned int k = 0; k < 3; k++)
64 const aiVector3D& vertex
66 ->mVertices[_mesh->mMeshes[i]->mFaces[j].mIndices[k]];
68 vertex.x * _scaleX, vertex.y * _scaleY, vertex.z * _scaleZ);
71 model->addTriangle(vertices[0], vertices[1], vertices[2]);
86 float v[59][3] = {{0, 0, 0},
87 {0.135299, -0.461940, -0.135299},
88 {0.000000, -0.461940, -0.191342},
89 {-0.135299, -0.461940, -0.135299},
90 {-0.191342, -0.461940, 0.000000},
91 {-0.135299, -0.461940, 0.135299},
92 {0.000000, -0.461940, 0.191342},
93 {0.135299, -0.461940, 0.135299},
94 {0.191342, -0.461940, 0.000000},
95 {0.250000, -0.353553, -0.250000},
96 {0.000000, -0.353553, -0.353553},
97 {-0.250000, -0.353553, -0.250000},
98 {-0.353553, -0.353553, 0.000000},
99 {-0.250000, -0.353553, 0.250000},
100 {0.000000, -0.353553, 0.353553},
101 {0.250000, -0.353553, 0.250000},
102 {0.353553, -0.353553, 0.000000},
103 {0.326641, -0.191342, -0.326641},
104 {0.000000, -0.191342, -0.461940},
105 {-0.326641, -0.191342, -0.326641},
106 {-0.461940, -0.191342, 0.000000},
107 {-0.326641, -0.191342, 0.326641},
108 {0.000000, -0.191342, 0.461940},
109 {0.326641, -0.191342, 0.326641},
110 {0.461940, -0.191342, 0.000000},
111 {0.353553, 0.000000, -0.353553},
112 {0.000000, 0.000000, -0.500000},
113 {-0.353553, 0.000000, -0.353553},
114 {-0.500000, 0.000000, 0.000000},
115 {-0.353553, 0.000000, 0.353553},
116 {0.000000, 0.000000, 0.500000},
117 {0.353553, 0.000000, 0.353553},
118 {0.500000, 0.000000, 0.000000},
119 {0.326641, 0.191342, -0.326641},
120 {0.000000, 0.191342, -0.461940},
121 {-0.326641, 0.191342, -0.326641},
122 {-0.461940, 0.191342, 0.000000},
123 {-0.326641, 0.191342, 0.326641},
124 {0.000000, 0.191342, 0.461940},
125 {0.326641, 0.191342, 0.326641},
126 {0.461940, 0.191342, 0.000000},
127 {0.250000, 0.353553, -0.250000},
128 {0.000000, 0.353553, -0.353553},
129 {-0.250000, 0.353553, -0.250000},
130 {-0.353553, 0.353553, 0.000000},
131 {-0.250000, 0.353553, 0.250000},
132 {0.000000, 0.353553, 0.353553},
133 {0.250000, 0.353553, 0.250000},
134 {0.353553, 0.353553, 0.000000},
135 {0.135299, 0.461940, -0.135299},
136 {0.000000, 0.461940, -0.191342},
137 {-0.135299, 0.461940, -0.135299},
138 {-0.191342, 0.461940, 0.000000},
139 {-0.135299, 0.461940, 0.135299},
140 {0.000000, 0.461940, 0.191342},
141 {0.135299, 0.461940, 0.135299},
142 {0.191342, 0.461940, 0.000000},
143 {0.000000, -0.500000, 0.000000},
144 {0.000000, 0.500000, 0.000000}};
146 = {{1, 2, 9}, {9, 2, 10}, {2, 3, 10}, {10, 3, 11}, {3, 4, 11},
147 {11, 4, 12}, {4, 5, 12}, {12, 5, 13}, {5, 6, 13}, {13, 6, 14},
148 {6, 7, 14}, {14, 7, 15}, {7, 8, 15}, {15, 8, 16}, {8, 1, 16},
149 {16, 1, 9}, {9, 10, 17}, {17, 10, 18}, {10, 11, 18}, {18, 11, 19},
150 {11, 12, 19}, {19, 12, 20}, {12, 13, 20}, {20, 13, 21}, {13, 14, 21},
151 {21, 14, 22}, {14, 15, 22}, {22, 15, 23}, {15, 16, 23}, {23, 16, 24},
152 {16, 9, 24}, {24, 9, 17}, {17, 18, 25}, {25, 18, 26}, {18, 19, 26},
153 {26, 19, 27}, {19, 20, 27}, {27, 20, 28}, {20, 21, 28}, {28, 21, 29},
154 {21, 22, 29}, {29, 22, 30}, {22, 23, 30}, {30, 23, 31}, {23, 24, 31},
155 {31, 24, 32}, {24, 17, 32}, {32, 17, 25}, {25, 26, 33}, {33, 26, 34},
156 {26, 27, 34}, {34, 27, 35}, {27, 28, 35}, {35, 28, 36}, {28, 29, 36},
157 {36, 29, 37}, {29, 30, 37}, {37, 30, 38}, {30, 31, 38}, {38, 31, 39},
158 {31, 32, 39}, {39, 32, 40}, {32, 25, 40}, {40, 25, 33}, {33, 34, 41},
159 {41, 34, 42}, {34, 35, 42}, {42, 35, 43}, {35, 36, 43}, {43, 36, 44},
160 {36, 37, 44}, {44, 37, 45}, {37, 38, 45}, {45, 38, 46}, {38, 39, 46},
161 {46, 39, 47}, {39, 40, 47}, {47, 40, 48}, {40, 33, 48}, {48, 33, 41},
162 {41, 42, 49}, {49, 42, 50}, {42, 43, 50}, {50, 43, 51}, {43, 44, 51},
163 {51, 44, 52}, {44, 45, 52}, {52, 45, 53}, {45, 46, 53}, {53, 46, 54},
164 {46, 47, 54}, {54, 47, 55}, {47, 48, 55}, {55, 48, 56}, {48, 41, 56},
165 {56, 41, 49}, {2, 1, 57}, {3, 2, 57}, {4, 3, 57}, {5, 4, 57},
166 {6, 5, 57}, {7, 6, 57}, {8, 7, 57}, {1, 8, 57}, {49, 50, 58},
167 {50, 51, 58}, {51, 52, 58}, {52, 53, 58}, {53, 54, 58}, {54, 55, 58},
168 {55, 56, 58}, {56, 49, 58}};
170 ::fcl::BVHModel<BV>* model = new ::fcl::BVHModel<BV>;
174 for (
int i = 0; i < 112; i++)
177 v[f[i][0]][0] * _sizeX, v[f[i][0]][1] * _sizeY, v[f[i][0]][2] * _sizeZ);
179 v[f[i][1]][0] * _sizeX, v[f[i][1]][1] * _sizeY, v[f[i][1]][2] * _sizeZ);
181 v[f[i][2]][0] * _sizeX, v[f[i][2]][1] * _sizeY, v[f[i][2]][2] * _sizeZ);
185 model->addTriangle(p1, p2, p3);
207 int faces[6][4] = {{0, 1, 2, 3},
215 v[0][0] = v[1][0] = v[2][0] = v[3][0] = -_sizeX / 2;
216 v[4][0] = v[5][0] = v[6][0] = v[7][0] = _sizeX / 2;
217 v[0][1] = v[1][1] = v[4][1] = v[5][1] = -_sizeY / 2;
218 v[2][1] = v[3][1] = v[6][1] = v[7][1] = _sizeY / 2;
219 v[0][2] = v[3][2] = v[4][2] = v[7][2] = -_sizeZ / 2;
220 v[1][2] = v[2][2] = v[5][2] = v[6][2] = _sizeZ / 2;
222 ::fcl::BVHModel<BV>* model = new ::fcl::BVHModel<BV>;
226 for (
int i = 0; i < 6; i++)
229 v[faces[i][0]][0], v[faces[i][0]][1], v[faces[i][0]][2]);
231 v[faces[i][1]][0], v[faces[i][1]][1], v[faces[i][1]][2]);
233 v[faces[i][2]][0], v[faces[i][2]][1], v[faces[i][2]][2]);
237 model->addTriangle(p1, p2, p3);
239 v[faces[i][0]][0], v[faces[i][0]][1], v[faces[i][0]][2]);
241 v[faces[i][2]][0], v[faces[i][2]][1], v[faces[i][2]][2]);
243 v[faces[i][3]][0], v[faces[i][3]][1], v[faces[i][3]][2]);
247 model->addTriangle(p1, p2, p3);
262 const int CACHE_SIZE = 240;
265 float sinCache[CACHE_SIZE];
266 float cosCache[CACHE_SIZE];
270 float sintemp, costemp;
272 float radiusLow, radiusHigh;
274 if (_slices >= CACHE_SIZE)
275 _slices = CACHE_SIZE - 1;
277 if (_slices < 2 || _stacks < 1 || _baseRadius < 0.0 || _topRadius < 0.0
284 zBase = -_height / 2;
287 deltaRadius = _baseRadius - _topRadius;
290 for (i = 0; i < _slices; i++)
293 sinCache[i] = sin(angle);
294 cosCache[i] = cos(angle);
297 sinCache[_slices] = sinCache[0];
298 cosCache[_slices] = cosCache[0];
300 ::fcl::BVHModel<BV>* model = new ::fcl::BVHModel<BV>;
306 sintemp = sinCache[0];
307 costemp = cosCache[0];
308 radiusLow = _baseRadius;
311 radiusLow * sintemp, radiusLow * costemp, zLow);
313 for (i = 1; i < _slices; i++)
316 radiusLow * sinCache[i], radiusLow * cosCache[i], zLow);
318 radiusLow * sinCache[i + 1], radiusLow * cosCache[i + 1], zLow);
321 model->addTriangle(p1, p2, p3);
323 Eigen::Vector3d v(radiusLow * sinCache[i], radiusLow * cosCache[i], zLow);
327 for (i = 0; i < _slices; i++)
329 for (j = 0; j < _stacks; j++)
331 zLow = j * _height / _stacks + zBase;
332 zHigh = (j + 1) * _height / _stacks + zBase;
333 radiusLow = _baseRadius - deltaRadius * (
static_cast<float>(j) / _stacks);
335 = _baseRadius - deltaRadius * (
static_cast<float>(j + 1) / _stacks);
338 radiusLow * sinCache[i], radiusLow * cosCache[i], zLow);
340 radiusLow * sinCache[i + 1], radiusLow * cosCache[i + 1], zLow);
342 radiusHigh * sinCache[i], radiusHigh * cosCache[i], zHigh);
344 radiusHigh * sinCache[i + 1], radiusHigh * cosCache[i + 1], zHigh);
350 model->addTriangle(p1, p2, p3);
351 model->addTriangle(p2, p3, p4);
356 sintemp = sinCache[0];
357 costemp = cosCache[0];
358 radiusLow = _topRadius;
359 zLow = zBase + _height;
361 radiusLow * sintemp, radiusLow * costemp, zLow);
363 for (i = 1; i < _slices; i++)
366 radiusLow * sinCache[i], radiusLow * cosCache[i], zLow);
368 radiusLow * sinCache[i + 1], radiusLow * cosCache[i + 1], zLow);
371 model->addTriangle(p1, p2, p3);
::fcl::Vec3f Vector3
Definition: BackwardCompatibility.hpp:148
dart::collision::fcl::Vector3 transform(const dart::collision::fcl::Transform3 &t, const dart::collision::fcl::Vector3 &v)
Transforms a 3-dim vector by a transform and returns the result.
Definition: BackwardCompatibility.cpp:133
::fcl::Transform3f Transform3
Definition: BackwardCompatibility.hpp:150
::fcl::BVHModel< BV > * createMesh(float _scaleX, float _scaleY, float _scaleZ, const aiScene *_mesh, const dart::collision::fcl::Transform3 &_transform)
Definition: CollisionShapes.hpp:46
::fcl::BVHModel< BV > * createCylinder(double _baseRadius, double _topRadius, double _height, int _slices, int _stacks, const dart::collision::fcl::Transform3 &_transform)
Definition: CollisionShapes.hpp:254
::fcl::BVHModel< BV > * createCube(float _sizeX, float _sizeY, float _sizeZ, const dart::collision::fcl::Transform3 &_transform)
Definition: CollisionShapes.hpp:193
::fcl::BVHModel< BV > * createEllipsoid(float _sizeX, float _sizeY, float _sizeZ, const dart::collision::fcl::Transform3 &_transform)
Definition: CollisionShapes.hpp:80
Definition: BulletCollisionDetector.cpp:65
static constexpr T pi()
Definition: Constants.hpp:45