|
18 | 18 | #include <utility>
|
19 | 19 | #include <vector>
|
20 | 20 |
|
21 |
| -#include <TriangleMeshDistance/include/tmd/TriangleMeshDistance.h> |
22 | 21 | #include <mujoco/mjplugin.h>
|
23 | 22 | #include <mujoco/mujoco.h>
|
24 | 23 | #include "sdf.h"
|
@@ -140,44 +139,19 @@ std::optional<SdfLib> SdfLib::Create(const mjModel* m, mjData* d,
|
140 | 139 | break;
|
141 | 140 | }
|
142 | 141 | }
|
143 |
| - int meshid = m->geom_dataid[geomid]; |
144 |
| - int nvert = m->mesh_vertnum[meshid]; |
145 |
| - int nface = m->mesh_facenum[meshid]; |
146 |
| - int* indices = m->mesh_face + 3*m->mesh_faceadr[meshid]; |
147 |
| - float* verts = m->mesh_vert + 3*m->mesh_vertadr[meshid]; |
148 |
| - std::vector<double> vertices(3*nvert); |
149 |
| - for (int i = 0; i < nvert; i++) { |
150 |
| - mjtNum vert[3] = {verts[3*i+0], verts[3*i+1], verts[3*i+2]}; |
151 |
| - mju_rotVecQuat(vert, vert, m->mesh_quat + 4*meshid); |
152 |
| - mju_addTo3(vert, m->mesh_pos + 3*meshid); |
153 |
| - vertices[3*i+0] = vert[0]; |
154 |
| - vertices[3*i+1] = vert[1]; |
155 |
| - vertices[3*i+2] = vert[2]; |
156 |
| - } |
157 |
| - tmd::TriangleMeshDistance mesh(vertices.data(), nvert, indices, nface); |
158 |
| - return SdfLib(mesh, m, meshid); |
| 142 | + return SdfLib(m, m->geom_dataid[geomid]); |
159 | 143 | }
|
160 | 144 |
|
161 | 145 | // plugin constructor
|
162 |
| -SdfLib::SdfLib(const tmd::TriangleMeshDistance& sdf, const mjModel* m, |
163 |
| - int meshid) { |
164 |
| - // TODO: do not evaluate the SDF multiple times at the same vertex |
165 |
| - // TODO: the value at hanging vertices should be computed from the parent |
| 146 | +SdfLib::SdfLib(const mjModel* m, int meshid) { |
166 | 147 | int octadr = m->mesh_octadr[meshid];
|
167 | 148 | int octnum = m->mesh_octnum[meshid];
|
168 | 149 | oct_aabb_.assign(m->oct_aabb + 6*octadr,
|
169 | 150 | m->oct_aabb + 6*octadr + 6*octnum);
|
170 | 151 | oct_child_.assign(m->oct_child + 8 * octadr,
|
171 | 152 | m->oct_child + 8 * octadr + 8 * octnum);
|
172 |
| - for (int i = 0; i < octnum; ++i) { |
173 |
| - for (int j = 0; j < 8; j++) { |
174 |
| - mjtNum v[3]; |
175 |
| - v[0] = oct_aabb_[6*i+0] + (j&1 ? 1 : -1) * oct_aabb_[6*i+3]; |
176 |
| - v[1] = oct_aabb_[6*i+1] + (j&2 ? 1 : -1) * oct_aabb_[6*i+4]; |
177 |
| - v[2] = oct_aabb_[6*i+2] + (j&4 ? 1 : -1) * oct_aabb_[6*i+5]; |
178 |
| - sdf_coeff_.push_back(sdf.signed_distance(v).distance); |
179 |
| - } |
180 |
| - } |
| 153 | + sdf_coeff_.assign(8 * octnum, 0); |
| 154 | + memcpy(sdf_coeff_.data(), m->oct_coeff + 8*octadr, 8*octnum*sizeof(mjtNum)); |
181 | 155 | mju_copy(box_, m->oct_aabb + 6*octadr, 6);
|
182 | 156 | }
|
183 | 157 |
|
|
0 commit comments