Refactor: separate buffer indexing and swizzling.

This also fixes a sensor data reading bug: previously, _sensorIndex was multiplied by 3 by MjEngineTool.

PiperOrigin-RevId: 451699887
Change-Id: I864bcbf8159857764854b25311a26ec5672125d9
This commit is contained in:
Tom Erez
2022-05-29 00:23:57 -07:00
committed by Copybara-Service
parent 5cc73c30bf
commit 02f300c762
16 changed files with 213 additions and 86 deletions
+12 -6
View File
@@ -48,8 +48,10 @@ public class MjGeom : MjShapeComponent {
var MjParent = MjHierarchyTool.FindParentComponent<MjBaseBody>(this);
if (MjParent != null) {
var comInParentFrame = new MjTransformation(
translation: MjEngineTool.UnityVector3(model->geom_pos, MujocoId),
rotation: MjEngineTool.UnityQuaternion(model->geom_quat, MujocoId));
translation: MjEngineTool.UnityVector3(
MjEngineTool.MjVector3AtEntry(model->geom_pos, MujocoId)),
rotation: MjEngineTool.UnityQuaternion(
MjEngineTool.MjQuaternionAtEntry(model->geom_quat, MujocoId)));
// We don't want to bother calculating global transform in mujoco from mjModel,
// so we'll assume it's the same as the Unity transfor (it's the beginning of simulation after
@@ -78,13 +80,17 @@ public class MjGeom : MjShapeComponent {
public override unsafe void OnSyncState(MujocoLib.mjData_* data) {
if (ShapeType == ShapeTypes.Mesh) {
_geomInGlobalFrame.Set(
translation: MjEngineTool.UnityVector3(data->geom_xpos, MujocoId),
rotation: MjEngineTool.UnityQuaternionFromMatrix(data->geom_xmat, MujocoId));
translation: MjEngineTool.UnityVector3(
MjEngineTool.MjVector3AtEntry(data->geom_xpos, MujocoId)),
rotation: MjEngineTool.UnityQuaternionFromMatrix(
MjEngineTool.MjMatrixAtEntry(data->geom_xmat, MujocoId)));
var comInGlobalFrame = _geomInGlobalFrame * _comTransform;
comInGlobalFrame.StoreGlobal(transform);
} else {
transform.position = MjEngineTool.UnityVector3(data->geom_xpos, MujocoId);
transform.rotation = MjEngineTool.UnityQuaternionFromMatrix(data->geom_xmat, MujocoId);
transform.position = MjEngineTool.UnityVector3(
MjEngineTool.MjVector3AtEntry(data->geom_xpos, MujocoId));
transform.rotation = MjEngineTool.UnityQuaternionFromMatrix(
MjEngineTool.MjMatrixAtEntry(data->geom_xmat, MujocoId));
}
}
+4 -2
View File
@@ -40,8 +40,10 @@ public class MjSite : MjShapeComponent {
// Synchronize the state of the component.
public override unsafe void OnSyncState(MujocoLib.mjData_* data) {
transform.position = MjEngineTool.UnityVector3(data->site_xpos, MujocoId);
transform.rotation = MjEngineTool.UnityQuaternionFromMatrix(data->site_xmat, MujocoId);
transform.position = MjEngineTool.UnityVector3(
MjEngineTool.MjVector3AtEntry(data->site_xpos, MujocoId));
transform.rotation = MjEngineTool.UnityQuaternionFromMatrix(
MjEngineTool.MjMatrixAtEntry(data->site_xmat, MujocoId));
}
public void OnDrawGizmosSelected() {