1 |
|
|
/* |
2 |
|
|
* Software License Agreement (BSD License) |
3 |
|
|
* |
4 |
|
|
* Copyright (c) 2011-2014, Willow Garage, Inc. |
5 |
|
|
* Copyright (c) 2014-2015, Open Source Robotics Foundation |
6 |
|
|
* Copyright (c) 2016-2019, CNRS - LAAS |
7 |
|
|
* Copyright (c) 2019, INRIA |
8 |
|
|
* All rights reserved. |
9 |
|
|
* |
10 |
|
|
* Redistribution and use in source and binary forms, with or without |
11 |
|
|
* modification, are permitted provided that the following conditions |
12 |
|
|
* are met: |
13 |
|
|
* |
14 |
|
|
* * Redistributions of source code must retain the above copyright |
15 |
|
|
* notice, this list of conditions and the following disclaimer. |
16 |
|
|
* * Redistributions in binary form must reproduce the above |
17 |
|
|
* copyright notice, this list of conditions and the following |
18 |
|
|
* disclaimer in the documentation and/or other materials provided |
19 |
|
|
* with the distribution. |
20 |
|
|
* * Neither the name of Open Source Robotics Foundation nor the names of its |
21 |
|
|
* contributors may be used to endorse or promote products derived |
22 |
|
|
* from this software without specific prior written permission. |
23 |
|
|
* |
24 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
25 |
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
26 |
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
27 |
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
28 |
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
29 |
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
30 |
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
31 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
32 |
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
33 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
34 |
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
35 |
|
|
* POSSIBILITY OF SUCH DAMAGE. |
36 |
|
|
*/ |
37 |
|
|
|
38 |
|
|
#ifndef HPP_FCL_MESH_LOADER_ASSIMP_H |
39 |
|
|
#define HPP_FCL_MESH_LOADER_ASSIMP_H |
40 |
|
|
|
41 |
|
|
#include <hpp/fcl/fwd.hh> |
42 |
|
|
#include <hpp/fcl/config.hh> |
43 |
|
|
#include <hpp/fcl/BV/OBBRSS.h> |
44 |
|
|
#include <hpp/fcl/BVH/BVH_model.h> |
45 |
|
|
|
46 |
|
|
struct aiScene; |
47 |
|
|
namespace Assimp { |
48 |
|
|
class Importer; |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
namespace hpp { |
52 |
|
|
namespace fcl { |
53 |
|
|
|
54 |
|
|
namespace internal { |
55 |
|
|
|
56 |
|
|
struct HPP_FCL_DLLAPI TriangleAndVertices { |
57 |
|
|
std::vector<fcl::Vec3f> vertices_; |
58 |
|
|
std::vector<fcl::Triangle> triangles_; |
59 |
|
|
}; |
60 |
|
|
|
61 |
|
|
struct HPP_FCL_DLLAPI Loader { |
62 |
|
|
Loader(); |
63 |
|
|
~Loader(); |
64 |
|
|
|
65 |
|
|
void load(const std::string& resource_path); |
66 |
|
|
|
67 |
|
|
Assimp::Importer* importer; |
68 |
|
|
aiScene const* scene; |
69 |
|
|
}; |
70 |
|
|
|
71 |
|
|
/** |
72 |
|
|
* @brief Recursive procedure for building a mesh |
73 |
|
|
* |
74 |
|
|
* @param[in] scale Scale to apply when reading the ressource |
75 |
|
|
* @param[in] scene Pointer to the assimp scene |
76 |
|
|
* @param[in] vertices_offset Current number of vertices in the model |
77 |
|
|
* @param tv Triangles and Vertices of the mesh submodels |
78 |
|
|
*/ |
79 |
|
|
HPP_FCL_DLLAPI void buildMesh(const fcl::Vec3f& scale, const aiScene* scene, |
80 |
|
|
unsigned vertices_offset, |
81 |
|
|
TriangleAndVertices& tv); |
82 |
|
|
|
83 |
|
|
/** |
84 |
|
|
* @brief Convert an assimp scene to a mesh |
85 |
|
|
* |
86 |
|
|
* @param[in] scale Scale to apply when reading the ressource |
87 |
|
|
* @param[in] scene Pointer to the assimp scene |
88 |
|
|
* @param[out] mesh The mesh that must be built |
89 |
|
|
*/ |
90 |
|
|
template <class BoundingVolume> |
91 |
|
318 |
inline void meshFromAssimpScene( |
92 |
|
|
const fcl::Vec3f& scale, const aiScene* scene, |
93 |
|
|
const shared_ptr<BVHModel<BoundingVolume> >& mesh) { |
94 |
|
636 |
TriangleAndVertices tv; |
95 |
|
|
|
96 |
✓✗ |
318 |
int res = mesh->beginModel(); |
97 |
|
|
|
98 |
✗✓ |
318 |
if (res != fcl::BVH_OK) { |
99 |
|
|
HPP_FCL_THROW_PRETTY("fcl BVHReturnCode = " << res, std::runtime_error); |
100 |
|
|
} |
101 |
|
|
|
102 |
✓✗ |
318 |
buildMesh(scale, scene, (unsigned)mesh->num_vertices, tv); |
103 |
✓✗ |
318 |
mesh->addSubModel(tv.vertices_, tv.triangles_); |
104 |
|
|
|
105 |
✓✗ |
318 |
mesh->endModel(); |
106 |
|
318 |
} |
107 |
|
|
|
108 |
|
|
} // namespace internal |
109 |
|
|
|
110 |
|
|
/** |
111 |
|
|
* @brief Read a mesh file and convert it to a polyhedral mesh |
112 |
|
|
* |
113 |
|
|
* @param[in] resource_path Path to the ressource mesh file to be read |
114 |
|
|
* @param[in] scale Scale to apply when reading the ressource |
115 |
|
|
* @param[out] polyhedron The resulted polyhedron |
116 |
|
|
*/ |
117 |
|
|
template <class BoundingVolume> |
118 |
|
318 |
inline void loadPolyhedronFromResource( |
119 |
|
|
const std::string& resource_path, const fcl::Vec3f& scale, |
120 |
|
|
const shared_ptr<BVHModel<BoundingVolume> >& polyhedron) { |
121 |
✓✗ |
636 |
internal::Loader scene; |
122 |
✓✗ |
318 |
scene.load(resource_path); |
123 |
|
|
|
124 |
✓✗ |
318 |
internal::meshFromAssimpScene(scale, scene.scene, polyhedron); |
125 |
|
318 |
} |
126 |
|
|
|
127 |
|
|
} // namespace fcl |
128 |
|
|
} // namespace hpp |
129 |
|
|
|
130 |
|
|
#endif // HPP_FCL_MESH_LOADER_ASSIMP_H |