USD decoder applies newton:inertia without clearing physics:diagonalInertia and physics:principalAxes
メンテナーはふだん 6 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
調査の方向性
plugin/usd_decoder/usd_decoder.ccを読み、特に922~953行付近のParseUsdPhysicsMassAPIForBodyと、3373~3398行付近のsrc/user/user_objects.ccにある質量検証を確認してください。提供されたUSDステージで再現し、デコードされた慣性をMJCFの参照値と比較してください。設定されたnewton:inertiaがフォールバック属性を上書きし、デコードされた慣性がソースMJCFと一致すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
My setup
MuJoCo 4.0.1 with mujoco-usd 4.0.1 from PyPI (usd-core 25.11, newton-usd-schemas 0.7.0), Python 3.12, Linux x86_64. The same code is on main.
What's happening? What did you expect?
NewtonMassAPI's newton:inertia is a full inertia tensor in the body's local frame that, per the schema, overrides physics:diagonalInertia and physics:principalAxes when authored. Writers can author both so that readers without the Newton schemas still get the principal-axis form, and mujoco-usd-converter does this for every MJCF body with fullinertia.
The decoder does not apply the override. It copies physics:principalAxes to iquat and physics:diagonalInertia to inertia, then copies newton:inertia to fullinertia and leaves the other two set. Compilation fails:
Error: fullinertia and diagonal inertia cannot both be specified
This blocks every converted MJCF that uses fullinertia. In MuJoCo Menagerie that is 10 of 54 scenes, including franka_emika_panda, unitree_a1, agility_cassie, and robotstudio_so101.
Removing only physics:diagonalInertia is not a workaround. The model then compiles, but the compiler rotates fullinertia by iquat, which still holds physics:principalAxes, so a tensor that is already in the body frame is rotated a second time and the inertia is wrong.
I expected the decoder, when newton:inertia is authored, to set fullinertia and reset inertia to zero and iquat to identity, so the tensor is used as authored in the body frame and the result matches the source MJCF.
The relevant code at 4.0.1:
usd_decoder.ccParseUsdPhysicsMassAPIForBodysets all three.user_objects.ccrejectsfullinertiawith diagonal inertia and rotatesfullinertiabyiquat.
Steps for reproduction
pip install mujoco-usd==4.0.1- Run the code below. It builds a body with mass 1 and the tensor
0.3 0.25 0.2 0.01 0 0three ways and compares each decoded inertia with the same body in MJCF. - Authoring all three attributes fails.
newton:inertiaalone matches the MJCF exactly.physics:principalAxeswithnewton:inertiacompiles with the wrong inertia.
diagonalInertia + principalAxes + newton:inertia: Error: fullinertia and diagonal inertia cannot both be specified
newton:inertia only: compiles, max |inertia - MJCF| = 0
principalAxes + newton:inertia: compiles, max |inertia - MJCF| = 0.00857
Minimal model for reproduction
The stages are built in memory by the code below. The equivalent MJCF:
minimal XML
<mujoco>
<worldbody>
<body name="b">
<freejoint/>
<inertial pos="0 0 0" mass="1" fullinertia="0.3 0.25 0.2 0.01 0 0"/>
<geom type="sphere" size="0.1"/>
</body>
</worldbody>
</mujoco>
Code required for reproduction
import mujoco
import numpy as np
from pxr import Gf, Sdf, Usd, UsdGeom, UsdPhysics, Vt
FULL = [0.3, 0.25, 0.2, 0.01, 0.0, 0.0]
MJCF = f"""<mujoco><worldbody><body name="b"><freejoint/>
<inertial pos="0 0 0" mass="1" fullinertia="{' '.join(map(str, FULL))}"/>
<geom type="sphere" size="0.1"/></body></worldbody></mujoco>"""
def body_frame_tensor(inertia, iquat):
mat = np.zeros(9)
mujoco.mju_quat2Mat(mat, np.asarray(iquat, dtype=float))
rot = mat.reshape(3, 3)
return rot @ np.diag(inertia) @ rot.T
def make_stage(diag=None, axes=None, newton=None) -> Usd.Stage:
stage = Usd.Stage.CreateInMemory()
UsdGeom.SetStageMetersPerUnit(stage, 1.0)
UsdGeom.SetStageUpAxis(stage, UsdGeom.Tokens.z)
body = UsdGeom.Xform.Define(stage, "/World/b").GetPrim()
UsdPhysics.RigidBodyAPI.Apply(body)
mass_api = UsdPhysics.MassAPI.Apply(body)
mass_api.CreateMassAttr().Set(1.0)
mass_api.CreateCenterOfMassAttr().Set(Gf.Vec3f(0, 0, 0))
if diag is not None:
mass_api.CreateDiagonalInertiaAttr().Set(Gf.Vec3f(*diag))
if axes is not None:
mass_api.CreatePrincipalAxesAttr().Set(Gf.Quatf(*axes))
if newton is not None:
body.ApplyAPI("NewtonMassAPI")
body.GetAttribute("newton:inertia").Set(Vt.DoubleArray(newton))
sphere = UsdGeom.Sphere.Define(stage, "/World/b/geom")
sphere.CreateRadiusAttr().Set(0.1)
UsdPhysics.CollisionAPI.Apply(sphere.GetPrim())
return stage
ref = mujoco.MjModel.from_xml_string(MJCF)
ref_tensor = body_frame_tensor(ref.body_inertia[1], ref.body_iquat[1])
# Principal-axis decomposition of FULL, authored as the PhysicsMassAPI fallback for newton:inertia.
eigval, eigvec, quat = np.zeros(3), np.zeros(9), np.zeros(4)
tensor = np.array([[FULL[0], FULL[3], FULL[4]], [FULL[3], FULL[1], FULL[5]], [FULL[4], FULL[5], FULL[2]]])
mujoco.mju_eig3(eigval, eigvec, quat, tensor.flatten())
cases = {
"diagonalInertia + principalAxes + newton:inertia": dict(diag=eigval, axes=quat, newton=FULL),
"newton:inertia only": dict(newton=FULL),
"principalAxes + newton:inertia": dict(axes=quat, newton=FULL),
}
for name, kwargs in cases.items():
stage = make_stage(**kwargs)
try:
model = mujoco.MjSpec.from_file(stage.GetRootLayer().identifier).compile()
error = np.abs(body_frame_tensor(model.body_inertia[1], model.body_iquat[1]) - ref_tensor).max()
print(f"{name}: compiles, max |inertia - MJCF| = {error:.3g}")
except ValueError as e:
print(f"{name}: {str(e).splitlines()[0]}")
Confirmations
- I searched the latest documentation thoroughly before posting.
- I searched previous Issues and Discussions, I am certain this has not been raised before.
- 主要言語
- C++
- スター
- 18.3k
- フォーク
- 2.2k
- 平均マージ
- 9日 11時間
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
google-deepmind/mujoco のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
google-deepmind/mujoco#3929 ·
メンテナーはふだん 6 日以内に返信
-
`import mujoco.mjx` fails with TypeError when warp-lang is too old対応中かも @moah0911 が 22 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
google-deepmind/mujoco#3738 ·
メンテナーはふだん 6 日以内に返信
-
Unity 6.6 support再び着手できるかも @Balint-H が 53 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンenhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
google-deepmind/mujoco#3615 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 6 日以内に返信
-
Filament: `filament.ao.bilateral_threshold` and six other model options are ignored since 4.0.1, which changed the default ambient occlusion対応中かも @jeongseok-meta が今日担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 56/100
google-deepmind/mujoco#3933 ·
メンテナーはふだん 6 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 56/100
google-deepmind/mujoco#3931 ·
メンテナーはふだん 6 日以内に返信
google-deepmind/mujoco の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
maplibre/maplibre-native#5072 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
tenstorrent/tt-umd#4017 ·
メンテナーはふだん 3 日以内に返信
-
difficulty:easy func:gui prio:low type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
NatronGitHub/Natron#1538 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
hyprwm/hyprsunset#103 · コメント 1 件 ·