From f15bcd04b5e85803222f97122bf8d7cf16c78b78 Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Mon, 1 Aug 2022 05:11:42 -0700 Subject: [PATCH] Restore legacy center-of-mass computation when `exactmeshinertia` is false. PiperOrigin-RevId: 464511268 Change-Id: Ic7c640d01e58dba5049e9fcb2c1b75d6bff4f956 --- src/user/user_mesh.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/user/user_mesh.cc b/src/user/user_mesh.cc index 69923aa8..fc034875 100644 --- a/src/user/user_mesh.cc +++ b/src/user/user_mesh.cc @@ -993,9 +993,14 @@ void mjCMesh::Process() { // compute and add volume const double vec[3] = {cen[0]-facecen[0], cen[1]-facecen[1], cen[2]-facecen[2]}; double vol = type==mjSHELL_MESH ? a : mjuu_dot3(vec, nrm) * a / 3; - GetVolumeRef(type) += vol; + + // if legacy computation requested, then always positive + if (!model->exactmeshinertia) { + vol = fabs(vol); + } // add pyramid com + GetVolumeRef(type) += vol; for (j=0; j<3; j++) { CoM[j] += vol*(cen[j]*3.0/4.0 + facecen[j]/4.0); }