Add mujoco compiler settings to MjcSceneAPI in mjcPhysics.

PiperOrigin-RevId: 783729333
Change-Id: Ic1c3e4fb47a901de4eebdc2e987d276f4202d9ed
This commit is contained in:
Sam Haves
2025-07-16 06:08:38 -07:00
committed by Copybara-Service
parent 5069534a5c
commit ac0701d582
9 changed files with 1091 additions and 30 deletions
@@ -7,6 +7,69 @@ class "MjcSceneAPI" (
doc = "API providing global simulation options for MuJoCo."
)
{
uniform bool mjc:compiler:alignFree = 0 (
displayName = "Align Free"
doc = "This attribute toggles the default behaviour of an optimization that applies to bodies with a free joint and no child bodies. When True, the body frame and free joint will automatically be aligned with inertial frame, which leads to both faster and more stable simulation."
)
uniform token mjc:compiler:angle = "degree" (
allowedTokens = ["degree", "radian"]
displayName = "Angle"
doc = "This attribute specifies whether the angles in mjcPhysics attributes have units of degrees or radians if not otherwise noted."
)
uniform bool mjc:compiler:autoLimits = 1 (
displayName = "Automatic Limits"
doc = 'This attribute affects the behavior of attributes such as "limited" (on MjcJointAPI), "forcelimited" "ctrllimited", and "actlimited" (on MjcActuator). If True, these attributes are unnecessary and their value will be inferred from the presence of their corresponding "range" attribute. If False, no such inference will happen: For a joint to be limited, both limited=True and range:min/max must be specified. In this mode, it is an error to specify a range without a limit.'
)
uniform bool mjc:compiler:balanceInertia = 0 (
displayName = "Balance Inertia"
doc = 'A valid diagonal inertia matrix must satisfy A+B>=C for all permutations of the three diagonal elements. Some poorly designed models violate this constraint, which will normally result in a compile error. If this attribute is set to "true", the compiler will silently set all three diagonal elements to their average value whenever the above condition is violated.'
)
uniform double mjc:compiler:boundInertia = 0 (
displayName = "Bound Inertia"
doc = "This attribute imposes a lower bound on the diagonal inertia components of each body except for the world body."
)
uniform double mjc:compiler:boundMass = 0 (
displayName = "Bound Mass"
doc = "This attribute imposes a lower bound on the mass of each body except for the world body."
)
uniform bool mjc:compiler:fitAABB = 0 (
displayName = "Fit AABB"
doc = "The compiler is able to replace a mesh with a geometric primitive fitted to that mesh. If this attribute is True, the fitting procedure uses the axis-aligned bounding box (AABB) of the mesh. Otherwise it uses the equivalent-inertia box of the mesh."
)
uniform bool mjc:compiler:fuseStatic = 0 (
displayName = "Fuse Static"
doc = """This attribute controls a compiler optimization feature where static bodies are fused with their parent, and any elements defined in those bodies are reassigned to the parent. Static bodies are fused with their parent unless
* They are referenced by another element in the model.
* They contain a site which is referenced by a force or torque sensor.
"""
)
uniform token mjc:compiler:inertiaFromGeom = "auto" (
allowedTokens = ["false", "true", "auto"]
displayName = "Inertia From Geom"
doc = 'This attribute controls the automatic inference of body masses and inertias from geoms attached to the body. If this setting is "false", no automatic inference is performed. In that case each body must have explicitly defined mass and inertia with the inertial element, or else a compile error will be generated. If this setting is "true", the mass and inertia of each body will be inferred from the geoms attached to it, overriding any values specified with the inertial element. The default setting "auto" means that masses and inertias are inferred automatically only when the inertial element is missing in the body definition. One reason to set this attribute to "true" instead of "auto" is to override inertial data imported from a poorly designed model.'
)
uniform int mjc:compiler:inertiaGroupRange:max = 5 (
displayName = "Inertia Group Range Max"
doc = "This attribute specifies the maximum of the geom group range that is used to infer body masses and inertias (when such inference is enabled). The group attribute of geom is an integer. If this integer falls in the range specified here, the geom will be used in the inertial computation, otherwise it will be ignored. This feature is useful in models that have redundant sets of geoms for collision and visualization. Note that the world body does not participate in the inertial computations, so any geoms attached to it are automatically ignored. Therefore it is not necessary to adjust this attribute and the geom-specific groups so as to exclude world geoms from the inertial computation."
)
uniform int mjc:compiler:inertiaGroupRange:min = 0 (
displayName = "Inertia Group Range Min"
doc = "This attribute specifies the maximum of the geom group range that is used to infer body masses and inertias (when such inference is enabled). The group attribute of geom is an integer. If this integer falls in the range specified here, the collider will be used in the inertial computation, otherwise it will be ignored. Note that the world body does not participate in the inertial computations, so any geoms attached to it are automatically ignored. Therefore it is not necessary to adjust this attribute and the geom-specific groups so as to exclude world geoms from the inertial computation."
)
uniform bool mjc:compiler:saveInertial = 0 (
displayName = "Save Inertial"
doc = "If True, the compiler will save explicit inertial clauses for all bodies."
)
uniform double mjc:compiler:setTotalMass = -1 (
displayName = "Set Total Mass"
doc = "If this value is positive, the compiler will scale the masses and inertias of all bodies in the model, so that the total mass equals the value specified here. The world body has mass 0 and does not participate in any mass-related computations. This scaling is performed last, after all other operations affecting the body mass and inertia. The same scaling operation can be applied at runtime to the compiled mjModel with the function mj_setTotalmass."
)
uniform bool mjc:compiler:useThread = 1 (
displayName = "Use Thread"
doc = "If this is True, the model compiler will run in multi-threaded mode. Currently multi-threading is used for computing the length ranges of actuators and for parallel loading of meshes."
)
uniform bool mjc:flag:actuation = 1 (
displayName = "Actuation Forces Toggle"
doc = "Enables all standard computations related to actuator forces, including actuator dynamics."
@@ -615,6 +615,162 @@ UsdAttribute MjcPhysicsSceneAPI::CreateIslandFlagAttr(
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetAutoLimitsAttr() const {
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcCompilerAutoLimits);
}
UsdAttribute MjcPhysicsSceneAPI::CreateAutoLimitsAttr(
VtValue const &defaultValue, bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerAutoLimits, SdfValueTypeNames->Bool,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetBoundMassAttr() const {
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcCompilerBoundMass);
}
UsdAttribute MjcPhysicsSceneAPI::CreateBoundMassAttr(
VtValue const &defaultValue, bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerBoundMass, SdfValueTypeNames->Double,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetBoundInertiaAttr() const {
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcCompilerBoundInertia);
}
UsdAttribute MjcPhysicsSceneAPI::CreateBoundInertiaAttr(
VtValue const &defaultValue, bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerBoundInertia, SdfValueTypeNames->Double,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetSetTotalMassAttr() const {
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcCompilerSetTotalMass);
}
UsdAttribute MjcPhysicsSceneAPI::CreateSetTotalMassAttr(
VtValue const &defaultValue, bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerSetTotalMass, SdfValueTypeNames->Double,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetUseThreadAttr() const {
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcCompilerUseThread);
}
UsdAttribute MjcPhysicsSceneAPI::CreateUseThreadAttr(
VtValue const &defaultValue, bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerUseThread, SdfValueTypeNames->Bool,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetBalanceInertiaAttr() const {
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcCompilerBalanceInertia);
}
UsdAttribute MjcPhysicsSceneAPI::CreateBalanceInertiaAttr(
VtValue const &defaultValue, bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerBalanceInertia, SdfValueTypeNames->Bool,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetAngleAttr() const {
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcCompilerAngle);
}
UsdAttribute MjcPhysicsSceneAPI::CreateAngleAttr(VtValue const &defaultValue,
bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerAngle, SdfValueTypeNames->Token,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetFitAABBAttr() const {
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcCompilerFitAABB);
}
UsdAttribute MjcPhysicsSceneAPI::CreateFitAABBAttr(VtValue const &defaultValue,
bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerFitAABB, SdfValueTypeNames->Bool,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetFuseStaticAttr() const {
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcCompilerFuseStatic);
}
UsdAttribute MjcPhysicsSceneAPI::CreateFuseStaticAttr(
VtValue const &defaultValue, bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerFuseStatic, SdfValueTypeNames->Bool,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetInertiaFromGeomAttr() const {
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcCompilerInertiaFromGeom);
}
UsdAttribute MjcPhysicsSceneAPI::CreateInertiaFromGeomAttr(
VtValue const &defaultValue, bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerInertiaFromGeom, SdfValueTypeNames->Token,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetAlignFreeAttr() const {
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcCompilerAlignFree);
}
UsdAttribute MjcPhysicsSceneAPI::CreateAlignFreeAttr(
VtValue const &defaultValue, bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerAlignFree, SdfValueTypeNames->Bool,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetInertiaGroupRangeMinAttr() const {
return GetPrim().GetAttribute(
MjcPhysicsTokens->mjcCompilerInertiaGroupRangeMin);
}
UsdAttribute MjcPhysicsSceneAPI::CreateInertiaGroupRangeMinAttr(
VtValue const &defaultValue, bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerInertiaGroupRangeMin, SdfValueTypeNames->Int,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetInertiaGroupRangeMaxAttr() const {
return GetPrim().GetAttribute(
MjcPhysicsTokens->mjcCompilerInertiaGroupRangeMax);
}
UsdAttribute MjcPhysicsSceneAPI::CreateInertiaGroupRangeMaxAttr(
VtValue const &defaultValue, bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerInertiaGroupRangeMax, SdfValueTypeNames->Int,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
UsdAttribute MjcPhysicsSceneAPI::GetSaveInertialAttr() const {
return GetPrim().GetAttribute(MjcPhysicsTokens->mjcCompilerSaveInertial);
}
UsdAttribute MjcPhysicsSceneAPI::CreateSaveInertialAttr(
VtValue const &defaultValue, bool writeSparsely) const {
return UsdSchemaBase::_CreateAttr(
MjcPhysicsTokens->mjcCompilerSaveInertial, SdfValueTypeNames->Bool,
/* custom = */ false, SdfVariabilityUniform, defaultValue, writeSparsely);
}
namespace {
static inline TfTokenVector _ConcatenateAttributeNames(
const TfTokenVector &left, const TfTokenVector &right) {
@@ -679,6 +835,20 @@ const TfTokenVector &MjcPhysicsSceneAPI::GetSchemaAttributeNames(
MjcPhysicsTokens->mjcFlagInvdiscrete,
MjcPhysicsTokens->mjcFlagMulticcd,
MjcPhysicsTokens->mjcFlagIsland,
MjcPhysicsTokens->mjcCompilerAutoLimits,
MjcPhysicsTokens->mjcCompilerBoundMass,
MjcPhysicsTokens->mjcCompilerBoundInertia,
MjcPhysicsTokens->mjcCompilerSetTotalMass,
MjcPhysicsTokens->mjcCompilerUseThread,
MjcPhysicsTokens->mjcCompilerBalanceInertia,
MjcPhysicsTokens->mjcCompilerAngle,
MjcPhysicsTokens->mjcCompilerFitAABB,
MjcPhysicsTokens->mjcCompilerFuseStatic,
MjcPhysicsTokens->mjcCompilerInertiaFromGeom,
MjcPhysicsTokens->mjcCompilerAlignFree,
MjcPhysicsTokens->mjcCompilerInertiaGroupRangeMin,
MjcPhysicsTokens->mjcCompilerInertiaGroupRangeMax,
MjcPhysicsTokens->mjcCompilerSaveInertial,
};
static TfTokenVector allNames = _ConcatenateAttributeNames(
UsdAPISchemaBase::GetSchemaAttributeNames(true), localNames);
+119
View File
@@ -509,6 +509,125 @@ class "MjcSceneAPI"
displayName = "Constraint Island Discovery Toggle"
doc = """Enables the discovery of constraint islands."""
)
uniform bool mjc:compiler:autoLimits = True (
customData = {
string apiName = "AutoLimits"
}
displayName = "Automatic Limits"
doc = """This attribute affects the behavior of attributes such as "limited" (on MjcJointAPI), "forcelimited" "ctrllimited", and "actlimited" (on MjcActuator). If True, these attributes are unnecessary and their value will be inferred from the presence of their corresponding "range" attribute. If False, no such inference will happen: For a joint to be limited, both limited=True and range:min/max must be specified. In this mode, it is an error to specify a range without a limit."""
)
uniform double mjc:compiler:boundMass = 0.0 (
customData = {
string apiName = "BoundMass"
}
displayName = "Bound Mass"
doc = """This attribute imposes a lower bound on the mass of each body except for the world body."""
)
uniform double mjc:compiler:boundInertia = 0.0 (
customData = {
string apiName = "BoundInertia"
}
displayName = "Bound Inertia"
doc = """This attribute imposes a lower bound on the diagonal inertia components of each body except for the world body."""
)
uniform double mjc:compiler:setTotalMass = -1.0 (
customData = {
string apiName = "SetTotalMass"
}
displayName = "Set Total Mass"
doc = """If this value is positive, the compiler will scale the masses and inertias of all bodies in the model, so that the total mass equals the value specified here. The world body has mass 0 and does not participate in any mass-related computations. This scaling is performed last, after all other operations affecting the body mass and inertia. The same scaling operation can be applied at runtime to the compiled mjModel with the function mj_setTotalmass."""
)
uniform bool mjc:compiler:useThread = True (
customData = {
string apiName = "UseThread"
}
displayName = "Use Thread"
doc = """If this is True, the model compiler will run in multi-threaded mode. Currently multi-threading is used for computing the length ranges of actuators and for parallel loading of meshes."""
)
uniform bool mjc:compiler:balanceInertia = False (
customData = {
string apiName = "BalanceInertia"
}
displayName = "Balance Inertia"
doc = """A valid diagonal inertia matrix must satisfy A+B>=C for all permutations of the three diagonal elements. Some poorly designed models violate this constraint, which will normally result in a compile error. If this attribute is set to "true", the compiler will silently set all three diagonal elements to their average value whenever the above condition is violated."""
)
uniform token mjc:compiler:angle = "degree" (
allowedTokens = ["degree", "radian"]
customData = {
string apiName = "Angle"
}
displayName = "Angle"
doc = """This attribute specifies whether the angles in mjcPhysics attributes have units of degrees or radians if not otherwise noted."""
)
uniform bool mjc:compiler:fitAABB = False (
customData = {
string apiName = "FitAABB"
}
displayName = "Fit AABB"
doc = """The compiler is able to replace a mesh with a geometric primitive fitted to that mesh. If this attribute is True, the fitting procedure uses the axis-aligned bounding box (AABB) of the mesh. Otherwise it uses the equivalent-inertia box of the mesh."""
)
uniform bool mjc:compiler:fuseStatic = False (
customData = {
string apiName = "FuseStatic"
}
displayName = "Fuse Static"
doc = """This attribute controls a compiler optimization feature where static bodies are fused with their parent, and any elements defined in those bodies are reassigned to the parent. Static bodies are fused with their parent unless
* They are referenced by another element in the model.
* They contain a site which is referenced by a force or torque sensor.
"""
)
uniform token mjc:compiler:inertiaFromGeom = "auto" (
allowedTokens = ["false", "true", "auto"]
customData = {
string apiName = "InertiaFromGeom"
}
displayName = "Inertia From Geom"
doc = """This attribute controls the automatic inference of body masses and inertias from geoms attached to the body. If this setting is "false", no automatic inference is performed. In that case each body must have explicitly defined mass and inertia with the inertial element, or else a compile error will be generated. If this setting is "true", the mass and inertia of each body will be inferred from the geoms attached to it, overriding any values specified with the inertial element. The default setting "auto" means that masses and inertias are inferred automatically only when the inertial element is missing in the body definition. One reason to set this attribute to "true" instead of "auto" is to override inertial data imported from a poorly designed model."""
)
uniform bool mjc:compiler:alignFree = False (
customData = {
string apiName = "AlignFree"
}
displayName = "Align Free"
doc = """This attribute toggles the default behaviour of an optimization that applies to bodies with a free joint and no child bodies. When True, the body frame and free joint will automatically be aligned with inertial frame, which leads to both faster and more stable simulation."""
)
uniform int mjc:compiler:inertiaGroupRange:min = 0 (
customData = {
string apiName = "InertiaGroupRangeMin"
}
displayName = "Inertia Group Range Min"
doc = """This attribute specifies the maximum of the geom group range that is used to infer body masses and inertias (when such inference is enabled). The group attribute of geom is an integer. If this integer falls in the range specified here, the collider will be used in the inertial computation, otherwise it will be ignored. Note that the world body does not participate in the inertial computations, so any geoms attached to it are automatically ignored. Therefore it is not necessary to adjust this attribute and the geom-specific groups so as to exclude world geoms from the inertial computation."""
)
uniform int mjc:compiler:inertiaGroupRange:max = 5 (
customData = {
string apiName = "InertiaGroupRangeMax"
}
displayName = "Inertia Group Range Max"
doc = """This attribute specifies the maximum of the geom group range that is used to infer body masses and inertias (when such inference is enabled). The group attribute of geom is an integer. If this integer falls in the range specified here, the geom will be used in the inertial computation, otherwise it will be ignored. This feature is useful in models that have redundant sets of geoms for collision and visualization. Note that the world body does not participate in the inertial computations, so any geoms attached to it are automatically ignored. Therefore it is not necessary to adjust this attribute and the geom-specific groups so as to exclude world geoms from the inertial computation."""
)
uniform bool mjc:compiler:saveInertial = False (
customData = {
string apiName = "SaveInertial"
}
displayName = "Save Inertial"
doc = """If True, the compiler will save explicit inertial clauses for all bodies."""
)
}
class "MjcSiteAPI"
@@ -21,6 +21,7 @@ MjcPhysicsTokensType::MjcPhysicsTokensType()
auto_("auto", TfToken::Immortal),
cg("cg", TfToken::Immortal),
convex("convex", TfToken::Immortal),
degree("degree", TfToken::Immortal),
dense("dense", TfToken::Immortal),
elliptic("elliptic", TfToken::Immortal),
euler("euler", TfToken::Immortal),
@@ -46,6 +47,24 @@ MjcPhysicsTokensType::MjcPhysicsTokensType()
mjcArmature("mjc:armature", TfToken::Immortal),
mjcBiasPrm("mjc:biasPrm", TfToken::Immortal),
mjcBiasType("mjc:biasType", TfToken::Immortal),
mjcCompilerAlignFree("mjc:compiler:alignFree", TfToken::Immortal),
mjcCompilerAngle("mjc:compiler:angle", TfToken::Immortal),
mjcCompilerAutoLimits("mjc:compiler:autoLimits", TfToken::Immortal),
mjcCompilerBalanceInertia("mjc:compiler:balanceInertia",
TfToken::Immortal),
mjcCompilerBoundInertia("mjc:compiler:boundInertia", TfToken::Immortal),
mjcCompilerBoundMass("mjc:compiler:boundMass", TfToken::Immortal),
mjcCompilerFitAABB("mjc:compiler:fitAABB", TfToken::Immortal),
mjcCompilerFuseStatic("mjc:compiler:fuseStatic", TfToken::Immortal),
mjcCompilerInertiaFromGeom("mjc:compiler:inertiaFromGeom",
TfToken::Immortal),
mjcCompilerInertiaGroupRangeMax("mjc:compiler:inertiaGroupRange:max",
TfToken::Immortal),
mjcCompilerInertiaGroupRangeMin("mjc:compiler:inertiaGroupRange:min",
TfToken::Immortal),
mjcCompilerSaveInertial("mjc:compiler:saveInertial", TfToken::Immortal),
mjcCompilerSetTotalMass("mjc:compiler:setTotalMass", TfToken::Immortal),
mjcCompilerUseThread("mjc:compiler:useThread", TfToken::Immortal),
mjcCondim("mjc:condim", TfToken::Immortal),
mjcCrankLength("mjc:crankLength", TfToken::Immortal),
mjcCtrl("mjc:ctrl", TfToken::Immortal),
@@ -150,6 +169,7 @@ MjcPhysicsTokensType::MjcPhysicsTokensType()
none("none", TfToken::Immortal),
pgs("pgs", TfToken::Immortal),
pyramidal("pyramidal", TfToken::Immortal),
radian("radian", TfToken::Immortal),
rk4("rk4", TfToken::Immortal),
shell("shell", TfToken::Immortal),
sparse("sparse", TfToken::Immortal),
@@ -167,6 +187,7 @@ MjcPhysicsTokensType::MjcPhysicsTokensType()
auto_,
cg,
convex,
degree,
dense,
elliptic,
euler,
@@ -192,6 +213,20 @@ MjcPhysicsTokensType::MjcPhysicsTokensType()
mjcArmature,
mjcBiasPrm,
mjcBiasType,
mjcCompilerAlignFree,
mjcCompilerAngle,
mjcCompilerAutoLimits,
mjcCompilerBalanceInertia,
mjcCompilerBoundInertia,
mjcCompilerBoundMass,
mjcCompilerFitAABB,
mjcCompilerFuseStatic,
mjcCompilerInertiaFromGeom,
mjcCompilerInertiaGroupRangeMax,
mjcCompilerInertiaGroupRangeMin,
mjcCompilerSaveInertial,
mjcCompilerSetTotalMass,
mjcCompilerUseThread,
mjcCondim,
mjcCrankLength,
mjcCtrl,
@@ -293,6 +328,7 @@ MjcPhysicsTokensType::MjcPhysicsTokensType()
none,
pgs,
pyramidal,
radian,
rk4,
shell,
sparse,
@@ -655,6 +655,72 @@ class ModelWriter {
for (const auto &[token, flag] : disable_flags) {
create_flag_attr(token, flag, false);
}
// Compiler attributes
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Bool,
MjcPhysicsTokens->mjcCompilerAutoLimits,
(bool)spec_->compiler.autolimits);
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Double,
MjcPhysicsTokens->mjcCompilerBoundMass,
spec_->compiler.boundmass);
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Double,
MjcPhysicsTokens->mjcCompilerBoundInertia,
spec_->compiler.boundinertia);
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Double,
MjcPhysicsTokens->mjcCompilerSetTotalMass,
spec_->compiler.settotalmass);
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Bool,
MjcPhysicsTokens->mjcCompilerUseThread,
(bool)spec_->compiler.usethread);
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Bool,
MjcPhysicsTokens->mjcCompilerBalanceInertia,
(bool)spec_->compiler.balanceinertia);
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Token,
MjcPhysicsTokens->mjcCompilerAngle,
spec_->compiler.degree ? MjcPhysicsTokens->degree:MjcPhysicsTokens->radian);
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Bool,
MjcPhysicsTokens->mjcCompilerFitAABB,
(bool)spec_->compiler.fitaabb);
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Bool,
MjcPhysicsTokens->mjcCompilerFuseStatic,
(bool)spec_->compiler.fusestatic);
pxr::TfToken inertiafromgeom_token = MjcPhysicsTokens->auto_;
if (spec_->compiler.inertiafromgeom ==
mjINERTIAFROMGEOM_TRUE) { // mjINERTIA_TRUE
inertiafromgeom_token = MjcPhysicsTokens->true_;
} else if (spec_->compiler.inertiafromgeom ==
mjINERTIAFROMGEOM_FALSE) { // mjINERTIA_FALSE
inertiafromgeom_token = MjcPhysicsTokens->false_;
}
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Token,
MjcPhysicsTokens->mjcCompilerInertiaFromGeom,
inertiafromgeom_token);
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Bool,
MjcPhysicsTokens->mjcCompilerAlignFree,
(bool)spec_->compiler.alignfree);
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Int,
MjcPhysicsTokens->mjcCompilerInertiaGroupRangeMin,
spec_->compiler.inertiagrouprange[0]);
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Int,
MjcPhysicsTokens->mjcCompilerInertiaGroupRangeMax,
spec_->compiler.inertiagrouprange[1]);
WriteUniformAttribute(physics_scene_path, pxr::SdfValueTypeNames->Bool,
MjcPhysicsTokens->mjcCompilerSaveInertial,
(bool)spec_->compiler.saveinertial);
}
void WriteMeshes() {
+96
View File
@@ -520,6 +520,102 @@ void ParseUsdPhysicsScene(mjSpec* spec,
bool island_flag;
mjc_physics_scene.GetIslandFlagAttr().Get(&island_flag);
spec->option.enableflags |= (island_flag ? mjENBL_ISLAND : 0);
// Compiler attributes
auto auto_limits_attr = mjc_physics_scene.GetAutoLimitsAttr();
if (auto_limits_attr.HasAuthoredValue()) {
bool autolimits;
auto_limits_attr.Get(&autolimits);
spec->compiler.autolimits = autolimits;
}
auto use_thread_attr = mjc_physics_scene.GetUseThreadAttr();
if (use_thread_attr.HasAuthoredValue()) {
bool use_thread;
use_thread_attr.Get(&use_thread);
spec->compiler.usethread = use_thread;
}
auto balance_inertia_attr = mjc_physics_scene.GetBalanceInertiaAttr();
if (balance_inertia_attr.HasAuthoredValue()) {
bool balanceinertia;
balance_inertia_attr.Get(&balanceinertia);
spec->compiler.balanceinertia = balanceinertia;
}
auto angle_attr = mjc_physics_scene.GetAngleAttr();
if (angle_attr.HasAuthoredValue()) {
pxr::TfToken angle;
angle_attr.Get(&angle);
spec->compiler.degree = angle == MjcPhysicsTokens->degree;
}
auto fit_aabb_attr = mjc_physics_scene.GetFitAABBAttr();
if (fit_aabb_attr.HasAuthoredValue()) {
bool fitaabb;
fit_aabb_attr.Get(&fitaabb);
spec->compiler.fitaabb = fitaabb;
}
auto fuse_static_attr = mjc_physics_scene.GetFuseStaticAttr();
if (fuse_static_attr.HasAuthoredValue()) {
bool fusestatic;
fuse_static_attr.Get(&fusestatic);
spec->compiler.fusestatic = fusestatic;
}
auto inertia_from_geom_attr = mjc_physics_scene.GetInertiaFromGeomAttr();
if (inertia_from_geom_attr.HasAuthoredValue()) {
pxr::TfToken inertiafromgeom;
inertia_from_geom_attr.Get(&inertiafromgeom);
if (inertiafromgeom == MjcPhysicsTokens->auto_) {
spec->compiler.inertiafromgeom = mjINERTIAFROMGEOM_AUTO;
} else if(inertiafromgeom == MjcPhysicsTokens->false_) {
spec->compiler.inertiafromgeom = mjINERTIAFROMGEOM_FALSE;
} else if(inertiafromgeom == MjcPhysicsTokens->true_){
spec->compiler.inertiafromgeom = mjINERTIAFROMGEOM_TRUE;
} else {
mju_warning("Invalid inertiafromgeom token: %s",
inertiafromgeom.GetText());
}
}
auto align_free_attr = mjc_physics_scene.GetAlignFreeAttr();
if (align_free_attr.HasAuthoredValue()) {
bool alignfree;
align_free_attr.Get(&alignfree);
spec->compiler.alignfree = alignfree;
}
auto inertia_group_range_min_attr =
mjc_physics_scene.GetInertiaGroupRangeMinAttr();
auto inertia_group_range_max_attr =
mjc_physics_scene.GetInertiaGroupRangeMaxAttr();
if (inertia_group_range_min_attr.HasAuthoredValue() &&
inertia_group_range_max_attr.HasAuthoredValue()) {
int inertiagrouprangemin;
inertia_group_range_min_attr.Get(&inertiagrouprangemin);
int inertiagrouprangemax;
inertia_group_range_max_attr.Get(&inertiagrouprangemax);
spec->compiler.inertiagrouprange[0] = inertiagrouprangemin;
spec->compiler.inertiagrouprange[1] = inertiagrouprangemax;
} else if (inertia_group_range_min_attr.HasAuthoredValue() ||
inertia_group_range_max_attr.HasAuthoredValue()) {
mju_warning(
"Only one of inertiaGroupRangeMin and inertiaGroupRangeMax was "
"authored, ignoring both.");
}
auto save_inertial_attr = mjc_physics_scene.GetSaveInertialAttr();
if (save_inertial_attr.HasAuthoredValue()) {
bool saveinertial;
save_inertial_attr.Get(&saveinertial);
spec->compiler.saveinertial = saveinertial;
}
mjc_physics_scene.GetBoundMassAttr().Get(&spec->compiler.boundmass);
mjc_physics_scene.GetBoundInertiaAttr().Get(&spec->compiler.boundinertia);
mjc_physics_scene.GetSetTotalMassAttr().Get(&spec->compiler.settotalmass);
}
void ParseUsdPhysicsMassAPIForBody(mjsBody* body,