Use global coordinates for computing the frame position of a primitive geom fitted to a mesh.

PiperOrigin-RevId: 500720200
Change-Id: I0a564aff1fe6943002db14f46f789cfdaef4d2de
This commit is contained in:
Alessio Quaglino
2023-01-09 08:28:44 -08:00
committed by Copybara-Service
parent f19d5d2f28
commit 19b6c70e13
6 changed files with 7576 additions and 13 deletions
+12
View File
@@ -4,9 +4,21 @@ Changelog
Upcoming version (not yet released)
-----------------------------------
General
^^^^^^^
- The function :ref:`mj_name2id` is now implemented using a hash function instead of a linear search for better
performance.
Bug fixes
^^^^^^^^^
- Fixed misalignment bug in mesh-to-primitive fitting when using the bounding box fitting option :at:`fitaabb`.
.. image:: images/changelog/aabb.png
:width: 300px
Version 2.3.1 (December 6, 2022)
-----------------------------------
Binary file not shown.

After

Width:  |  Height:  |  Size: 116 KiB

+10 -13
View File
@@ -334,6 +334,9 @@ double* mjCMesh::GetQuatPtr(mjtMeshType type) {
void mjCMesh::FitGeom(mjCGeom* geom, double* meshpos) {
int i;
// copy mesh pos into meshpos
mjuu_copyvec(meshpos, GetPosPtr(geom->typeinertia), 3);
// use inertial box
if (!model->fitaabb) {
// get inertia box type (shell or volume)
@@ -363,9 +366,6 @@ void mjCMesh::FitGeom(mjCGeom* geom, double* meshpos) {
default:
throw mjCError(this, "invalid geom type in fitting mesh %s", name.c_str());
}
// copy mesh pos into meshpos
mjuu_copyvec(meshpos, GetPosPtr(geom->typeinertia), 3);
}
// use AABB
@@ -385,13 +385,10 @@ void mjCMesh::FitGeom(mjCGeom* geom, double* meshpos) {
// find AABB box center
double cen[3] = {(AABB[0]+AABB[3])/2, (AABB[1]+AABB[4])/2, (AABB[2]+AABB[5])/2};
// copy box center into meshpos
mjuu_copyvec(meshpos, cen, 3);
// get AABB box half-sizes
double sz0 = AABB[3] - cen[0];
double sz1 = AABB[4] - cen[1];
double sz2 = AABB[5] - cen[2];
// add box center into meshpos
meshpos[0] += cen[0];
meshpos[1] += cen[1];
meshpos[2] += cen[2];
// compute depending on type
switch (geom->type) {
@@ -440,9 +437,9 @@ void mjCMesh::FitGeom(mjCGeom* geom, double* meshpos) {
case mjGEOM_ELLIPSOID:
case mjGEOM_BOX:
geom->size[0] = sz0;
geom->size[1] = sz1;
geom->size[2] = sz2;
geom->size[0] = AABB[3] - cen[0];
geom->size[1] = AABB[4] - cen[1];
geom->size[2] = AABB[5] - cen[2];
break;
default:
+40
View File
@@ -0,0 +1,40 @@
<mujoco>
<compiler fitaabb="true"/>
<asset>
<mesh file="stanford_bunny.obj"/>
</asset>
<worldbody>
<body euler="90 0 0">
<geom type="mesh" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos=".25 0 0">
<geom type="mesh" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos=".5 0 0">
<geom type="mesh" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos=".75 0 0">
<geom type="mesh" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos="1 0 0">
<geom type="mesh" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0">
<geom name="bunny_sphere" type="sphere" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos=".25 0 0">
<geom name="bunny_capsule" type="capsule" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos=".5 0 0">
<geom name="bunny_ellipsoid" type="ellipsoid" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos=".75 0 0">
<geom name="bunny_cylinder" type="cylinder" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos="1 0 0">
<geom name="bunny_box" type="box" mesh="stanford_bunny"/>
</body>
<light name="left" pos="0 0 1"/>
<light name="right" pos="1 0 1"/>
</worldbody>
</mujoco>
+40
View File
@@ -0,0 +1,40 @@
<mujoco>
<compiler fitaabb="false"/>
<asset>
<mesh file="stanford_bunny.obj"/>
</asset>
<worldbody>
<body euler="90 0 0">
<geom type="mesh" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos=".25 0 0">
<geom type="mesh" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos=".5 0 0">
<geom type="mesh" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos=".75 0 0">
<geom type="mesh" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos="1 0 0">
<geom type="mesh" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0">
<geom name="bunny_sphere" type="sphere" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos=".25 0 0">
<geom name="bunny_capsule" type="capsule" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos=".5 0 0">
<geom name="bunny_ellipsoid" type="ellipsoid" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos=".75 0 0">
<geom name="bunny_cylinder" type="cylinder" mesh="stanford_bunny"/>
</body>
<body euler="90 0 0" pos="1 0 0">
<geom name="bunny_box" type="box" mesh="stanford_bunny"/>
</body>
<light name="left" pos="0 0 1"/>
<light name="right" pos="1 0 1"/>
</worldbody>
</mujoco>
File diff suppressed because it is too large Load Diff