Move SDF precomputation to the mujoco compiler.
Before: ``` Simulation time : 2.24 s Steps per second : 4472 Realtime factor : 8.94 x Time per step : 223.6 µs Newton iters / step : 2.47 Contacts / step : 3.37 Constraints / step : 13.49 Degrees of freedom : 12 Dynamic memory usage : 0.2% of 14M ``` After: ``` Simulation time : 1.71 s Steps per second : 5854 Realtime factor : 11.71 x Time per step : 170.8 µs Newton iters / step : 2.19 Contacts / step : 3.45 Constraints / step : 13.79 Degrees of freedom : 12 Dynamic memory usage : 0.2% of 14M ``` PiperOrigin-RevId: 781075182 Change-Id: Ie509047ff581ab0df4b10bbd394c27d350ab5a13
This commit is contained in:
committed by
Copybara-Service
parent
a3d251f552
commit
96118da08b
@@ -32,6 +32,7 @@
|
||||
|
||||
#include <mujoco/mjspec.h>
|
||||
#include "user/user_api.h"
|
||||
#include <TriangleMeshDistance/include/tmd/TriangleMeshDistance.h>
|
||||
|
||||
#ifdef MUJOCO_TINYOBJLOADER_IMPL
|
||||
#define TINYOBJLOADER_IMPLEMENTATION
|
||||
@@ -1548,6 +1549,25 @@ void mjCMesh::Process() {
|
||||
}
|
||||
octree_.SetFace(vert_, face_);
|
||||
octree_.CreateOctree(aamm);
|
||||
|
||||
// compute sdf coefficients
|
||||
// TODO: only check !plugin.active once sdflib is removed
|
||||
if (plugin.active && *plugin.name == "sdf") {
|
||||
tmd::TriangleMeshDistance sdf(vert_.data(), nvert(), face_.data(), nface());
|
||||
|
||||
// TODO: do not evaluate the SDF multiple times at the same vertex
|
||||
// TODO: the value at hanging vertices should be computed from the parent
|
||||
const double* nodes = octree_.Nodes().data();
|
||||
for (int i = 0; i < octree_.NumNodes(); ++i) {
|
||||
for (int j = 0; j < 8; j++) {
|
||||
mjtNum v[3];
|
||||
v[0] = nodes[6*i+0] + (j&1 ? 1 : -1) * nodes[6*i+3];
|
||||
v[1] = nodes[6*i+1] + (j&2 ? 1 : -1) * nodes[6*i+4];
|
||||
v[2] = nodes[6*i+2] + (j&4 ? 1 : -1) * nodes[6*i+5];
|
||||
octree_.AddCoeff(sdf.signed_distance(v).distance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// transform CoM to origin
|
||||
|
||||
Reference in New Issue
Block a user