Version 2.1.2: Python bindings, OBJ assets support, bugfixes.

PiperOrigin-RevId: 434731612
Change-Id: I0cfda3e7a3d1c72036764986efc252ffa1b8c6b0
This commit is contained in:
Saran Tunyasuvunakool
2022-03-15 14:04:44 +00:00
parent 175d25cd9f
commit 3577e2cf8b
304 changed files with 23906 additions and 1013 deletions
+15 -1
View File
@@ -1,4 +1,18 @@
# Changelog
# MuJoCo Plug-in for Unity
## [2.1.2] - 2022-03-15
### Minor modifications
When converting a world geom to a free-moving body, the parent body is created
where the geom is, rather than at the root.
File name changes:
- Added `.Runtime` to `Mujoco.asmdef` and the corresponding test file.
- Reorganized the files under `Runtime/Componenets` into different
subdirectories.
- File directories for Editor tests are now named with a capital letter.
## [2.1.1] - 2022-02-02
+8 -5
View File
@@ -42,15 +42,18 @@ public class MjGeomEditor : MjShapeComponentEditor {
Debug.LogError("This geom already has a Body parent.", geom.GetComponentInParent<MjBody>());
return;
}
var parent = new GameObject(geom.gameObject.name + " Body").transform;
var parent = new GameObject(geom.gameObject.name + " Body").AddComponent<MjBody>().transform;
parent.position = geom.transform.position;
geom.transform.parent = parent;
var root = geom.transform.root;
if (root != geom.transform) {
parent.parent = geom.transform.parent;
}
parent.gameObject.AddComponent<MjBody>();
var joint = new GameObject("Free Joint").AddComponent<MjFreeJoint>();
joint.transform.parent = parent;
geom.transform.parent = parent;
var joint = new GameObject("Free Joint").AddComponent<MjFreeJoint>().transform;
joint.position = geom.transform.position;
joint.parent = parent;
}
[MenuItem("CONTEXT/Collider/Add a matching MuJoCo geom")]
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "Mujoco.Editor",
"rootNamespace": "",
"references": [
"Mujoco"
"Mujoco.Runtime"
],
"includePlatforms": [],
"excludePlatforms": [],
+104 -17
View File
@@ -23,10 +23,6 @@ public static class MujocoLib {
// ----------------------------------Constants----------------------------------
public const bool THIRD_PARTY_MUJOCO_MJDATA_H_ = true;
public const bool THIRD_PARTY_MUJOCO_MJMODEL_H_ = true;
public const bool mjUSEDOUBLE = true;
public const double mjMINVAL = 1e-15;
public const double mjPI = 3.141592653589793;
public const double mjMAXVAL = 10000000000.0;
public const double mjMINMU = 1e-05;
@@ -39,13 +35,14 @@ public const int mjNEQDATA = 7;
public const int mjNDYN = 10;
public const int mjNGAIN = 10;
public const int mjNBIAS = 10;
public const int mjNFLUID = 12;
public const int mjNREF = 2;
public const int mjNIMP = 5;
public const int mjNSOLVER = 1000;
public const bool THIRD_PARTY_MUJOCO_MJRENDER_H_ = true;
public const int mjNAUX = 10;
public const int mjMAXTEXTURE = 1000;
public const bool THIRD_PARTY_MUJOCO_MJUI_H_ = true;
public const bool mjUSEDOUBLE = true;
public const double mjMINVAL = 1e-15;
public const int mjMAXUISECT = 10;
public const int mjMAXUIITEM = 80;
public const int mjMAXUITEXT = 300;
@@ -80,21 +77,13 @@ public const int mjKEY_F9 = 298;
public const int mjKEY_F10 = 299;
public const int mjKEY_F11 = 300;
public const int mjKEY_F12 = 301;
public const bool THIRD_PARTY_MUJOCO_MJVISUALIZE_H_ = true;
public const int mjNGROUP = 6;
public const int mjMAXLIGHT = 100;
public const int mjMAXOVERLAY = 500;
public const int mjMAXLINE = 100;
public const int mjMAXLINEPNT = 1000;
public const int mjMAXPLANEGRID = 200;
public const bool THIRD_PARTY_MUJOCO_MJXMACRO_H_ = true;
public const bool THIRD_PARTY_MUJOCO_MUJOCO_H_ = true;
public const int mjVERSION_HEADER = 211;
public const bool THIRD_PARTY_MUJOCO_MUJOCO_EXPORT_H_ = true;
public const bool MUJOCO_HELPER_DLL_LOCAL = true;
public const bool MUJOCO_HELPER_DLL_IMPORT = true;
public const bool MUJOCO_HELPER_DLL_EXPORT = true;
public const bool MJAPI = true;
public const bool MJLOCAL = true;
public const int mjVERSION_HEADER = 212;
// ------------------------------------Enums------------------------------------
@@ -1950,6 +1939,7 @@ public unsafe struct mjModel_ {
public double* geom_friction;
public double* geom_margin;
public double* geom_gap;
public double* geom_fluid;
public double* geom_user;
public float* geom_rgba;
public int* site_type;
@@ -2103,6 +2093,8 @@ public unsafe struct mjModel_ {
public int* sensor_needstage;
public int* sensor_objtype;
public int* sensor_objid;
public int* sensor_reftype;
public int* sensor_refid;
public int* sensor_dim;
public int* sensor_adr;
public double* sensor_cutoff;
@@ -2497,6 +2489,98 @@ public unsafe struct mjvScene_ {
public mjvLight_ lights5;
public mjvLight_ lights6;
public mjvLight_ lights7;
public mjvLight_ lights8;
public mjvLight_ lights9;
public mjvLight_ lights10;
public mjvLight_ lights11;
public mjvLight_ lights12;
public mjvLight_ lights13;
public mjvLight_ lights14;
public mjvLight_ lights15;
public mjvLight_ lights16;
public mjvLight_ lights17;
public mjvLight_ lights18;
public mjvLight_ lights19;
public mjvLight_ lights20;
public mjvLight_ lights21;
public mjvLight_ lights22;
public mjvLight_ lights23;
public mjvLight_ lights24;
public mjvLight_ lights25;
public mjvLight_ lights26;
public mjvLight_ lights27;
public mjvLight_ lights28;
public mjvLight_ lights29;
public mjvLight_ lights30;
public mjvLight_ lights31;
public mjvLight_ lights32;
public mjvLight_ lights33;
public mjvLight_ lights34;
public mjvLight_ lights35;
public mjvLight_ lights36;
public mjvLight_ lights37;
public mjvLight_ lights38;
public mjvLight_ lights39;
public mjvLight_ lights40;
public mjvLight_ lights41;
public mjvLight_ lights42;
public mjvLight_ lights43;
public mjvLight_ lights44;
public mjvLight_ lights45;
public mjvLight_ lights46;
public mjvLight_ lights47;
public mjvLight_ lights48;
public mjvLight_ lights49;
public mjvLight_ lights50;
public mjvLight_ lights51;
public mjvLight_ lights52;
public mjvLight_ lights53;
public mjvLight_ lights54;
public mjvLight_ lights55;
public mjvLight_ lights56;
public mjvLight_ lights57;
public mjvLight_ lights58;
public mjvLight_ lights59;
public mjvLight_ lights60;
public mjvLight_ lights61;
public mjvLight_ lights62;
public mjvLight_ lights63;
public mjvLight_ lights64;
public mjvLight_ lights65;
public mjvLight_ lights66;
public mjvLight_ lights67;
public mjvLight_ lights68;
public mjvLight_ lights69;
public mjvLight_ lights70;
public mjvLight_ lights71;
public mjvLight_ lights72;
public mjvLight_ lights73;
public mjvLight_ lights74;
public mjvLight_ lights75;
public mjvLight_ lights76;
public mjvLight_ lights77;
public mjvLight_ lights78;
public mjvLight_ lights79;
public mjvLight_ lights80;
public mjvLight_ lights81;
public mjvLight_ lights82;
public mjvLight_ lights83;
public mjvLight_ lights84;
public mjvLight_ lights85;
public mjvLight_ lights86;
public mjvLight_ lights87;
public mjvLight_ lights88;
public mjvLight_ lights89;
public mjvLight_ lights90;
public mjvLight_ lights91;
public mjvLight_ lights92;
public mjvLight_ lights93;
public mjvLight_ lights94;
public mjvLight_ lights95;
public mjvLight_ lights96;
public mjvLight_ lights97;
public mjvLight_ lights98;
public mjvLight_ lights99;
public mjvGLCamera_ camera0;
public mjvGLCamera_ camera1;
public byte enabletransform;
@@ -2663,11 +2747,14 @@ public static unsafe extern void mj_setConst(mjModel_* m, mjData_* d);
public static unsafe extern int mj_setLengthRange(mjModel_* m, mjData_* d, int index, mjLROpt_* opt, StringBuilder error, int error_sz);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mj_printFormattedModel(mjModel_* m, [MarshalAs(UnmanagedType.LPStr)]string filename, [MarshalAs(UnmanagedType.LPStr)]string float_format_str);
public static unsafe extern void mj_printFormattedModel(mjModel_* m, [MarshalAs(UnmanagedType.LPStr)]string filename, [MarshalAs(UnmanagedType.LPStr)]string float_format);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mj_printModel(mjModel_* m, [MarshalAs(UnmanagedType.LPStr)]string filename);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mj_printFormattedData(mjModel_* m, mjData_* d, [MarshalAs(UnmanagedType.LPStr)]string filename, [MarshalAs(UnmanagedType.LPStr)]string float_format);
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void mj_printData(mjModel_* m, mjData_* d, [MarshalAs(UnmanagedType.LPStr)]string filename);
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7d450c02683794ca6998862eebc97e43
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f98312e1fa23c4aa0a44050a7d76fc98
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6a18877f1d3c34909825953d015cc8cb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -44,7 +44,7 @@ namespace Mujoco {
MjEngineTool.PositionToMjcf(mjcf, this);
Settings.ToMjcf(mjcf);
mjcf.SetAttribute("range", $"0 {RangeUpper}");
mjcf.SetAttribute("range", MjEngineTool.MakeLocaleInvariant($"0 {RangeUpper}"));
return mjcf;
}
@@ -41,7 +41,7 @@ namespace Mujoco {
}
public void ToMjcf(XmlElement mjcf) {
mjcf.SetAttribute("armature", $"{Armature}");
mjcf.SetAttribute("armature", MjEngineTool.MakeLocaleInvariant($"{Armature}"));
Spring.ToMjcf(mjcf);
Solver.ToMjcf(mjcf);
}
@@ -62,10 +62,10 @@ namespace Mujoco {
public void ToMjcf(XmlElement mjcf) {
// Spring settings.
mjcf.SetAttribute("springref", $"{EquilibriumPose}");
mjcf.SetAttribute("springdamper", $"{TimeConstant} {DampingRatio}");
mjcf.SetAttribute("damping", $"{Damping}");
mjcf.SetAttribute("stiffness", $"{Stiffness}");
mjcf.SetAttribute("springref", MjEngineTool.MakeLocaleInvariant($"{EquilibriumPose}"));
mjcf.SetAttribute("springdamper", MjEngineTool.MakeLocaleInvariant($"{TimeConstant} {DampingRatio}"));
mjcf.SetAttribute("damping", MjEngineTool.MakeLocaleInvariant($"{Damping}"));
mjcf.SetAttribute("stiffness", MjEngineTool.MakeLocaleInvariant($"{Stiffness}"));
}
public void FromMjcf(XmlElement mjcf) {
@@ -102,7 +102,7 @@ namespace Mujoco {
}
public void ToMjcf(XmlElement element, string attributeName) {
element.SetAttribute(attributeName, $"{DMin} {DMax} {Width} {Midpoint} {Power}");
element.SetAttribute(attributeName, MjEngineTool.MakeLocaleInvariant($"{DMin} {DMax} {Width} {Midpoint} {Power}"));
}
}
@@ -122,7 +122,7 @@ namespace Mujoco {
}
public void ToMjcf(XmlElement element, string attributeName) {
element.SetAttribute(attributeName, $"{TimeConst} {DampRatio}");
element.SetAttribute(attributeName, MjEngineTool.MakeLocaleInvariant($"{TimeConst} {DampRatio}"));
}
}
@@ -153,9 +153,9 @@ namespace Mujoco {
ImpLimit.ToMjcf(mjcf, "solimplimit");
RefFriction.ToMjcf(mjcf, "solreffriction");
ImpFriction.ToMjcf(mjcf, "solimpfriction");
mjcf.SetAttribute("frictionloss", $"{FrictionLoss}");
mjcf.SetAttribute("frictionloss", MjEngineTool.MakeLocaleInvariant($"{FrictionLoss}"));
mjcf.SetAttribute("limited", $"{Limited}".ToLower());
mjcf.SetAttribute("margin", $"{Margin}");
mjcf.SetAttribute("margin", MjEngineTool.MakeLocaleInvariant($"{Margin}"));
}
public void FromMjcf(XmlElement mjcf) {
@@ -76,8 +76,8 @@ namespace Mujoco {
if (RangeLower > RangeUpper) {
throw new ArgumentException("Lower range value can't be bigger than Higher");
}
mjcf.SetAttribute("range", $"{RangeLower} {RangeUpper}");
mjcf.SetAttribute("ref", $"{Configuration}");
mjcf.SetAttribute("range", MjEngineTool.MakeLocaleInvariant($"{RangeLower} {RangeUpper}"));
mjcf.SetAttribute("ref", MjEngineTool.MakeLocaleInvariant($"{Configuration}"));
return mjcf;
}
+17 -17
View File
@@ -66,13 +66,13 @@ public class MjActuator : MjComponent {
mjcf.SetAttribute("forcelimited", $"{ForceLimited}".ToLowerInvariant());
mjcf.SetAttribute(
"ctrlrange",
$"{MjEngineTool.GetSorted(CtrlRange).x} {MjEngineTool.GetSorted(CtrlRange).y}");
MjEngineTool.MakeLocaleInvariant($"{MjEngineTool.GetSorted(CtrlRange).x} {MjEngineTool.GetSorted(CtrlRange).y}"));
mjcf.SetAttribute(
"forcerange",
$"{MjEngineTool.GetSorted(ForceRange).x} {MjEngineTool.GetSorted(ForceRange).y}");
MjEngineTool.MakeLocaleInvariant($"{MjEngineTool.GetSorted(ForceRange).x} {MjEngineTool.GetSorted(ForceRange).y}"));
mjcf.SetAttribute(
"lengthrange",
$"{MjEngineTool.GetSorted(LengthRange).x} {MjEngineTool.GetSorted(LengthRange).y}");
MjEngineTool.MakeLocaleInvariant($"{MjEngineTool.GetSorted(LengthRange).x} {MjEngineTool.GetSorted(LengthRange).y}"));
mjcf.SetAttribute("gear", MjEngineTool.ListToMjcf(Gear));
}
@@ -162,7 +162,7 @@ public class MjActuator : MjComponent {
public float Kp = 1.0f;
public void PositionToMjcf(XmlElement mjcf) {
mjcf.SetAttribute("kp", $"{Math.Abs(Kp)}");
mjcf.SetAttribute("kp", MjEngineTool.MakeLocaleInvariant($"{Math.Abs(Kp)}"));
}
public void PositionFromMjcf(XmlElement mjcf) {
Kp = mjcf.GetFloatAttribute("kp", defaultValue: 1.0f);
@@ -175,7 +175,7 @@ public class MjActuator : MjComponent {
public float Kv = 1.0f;
public void VelocityToMjcf(XmlElement mjcf) {
mjcf.SetAttribute("kv", $"{Math.Abs(Kv)}");
mjcf.SetAttribute("kv", MjEngineTool.MakeLocaleInvariant($"{Math.Abs(Kv)}"));
}
public void VelocityFromMjcf(XmlElement mjcf) {
Kv = mjcf.GetFloatAttribute("kv", defaultValue: 1.0f);
@@ -199,9 +199,9 @@ public class MjActuator : MjComponent {
public float[] Bias = new float[] { 0.0f, 0.0f, 0.0f };
public void CylinderToMjcf(XmlElement mjcf) {
mjcf.SetAttribute("timeconst", $"{CylinderTimeConst}");
mjcf.SetAttribute("area", $"{Math.Abs(Area)}");
mjcf.SetAttribute("diameter", $"{Math.Abs(Diameter)}");
mjcf.SetAttribute("timeconst", MjEngineTool.MakeLocaleInvariant($"{CylinderTimeConst}"));
mjcf.SetAttribute("area", MjEngineTool.MakeLocaleInvariant($"{Math.Abs(Area)}"));
mjcf.SetAttribute("diameter", MjEngineTool.MakeLocaleInvariant($"{Math.Abs(Diameter)}"));
mjcf.SetAttribute("bias", MjEngineTool.ArrayToMjcf(Bias));
}
@@ -246,16 +246,16 @@ public class MjActuator : MjComponent {
public float FvMax = 1.2f;
public void MuscleToMjcf(XmlElement mjcf) {
mjcf.SetAttribute("timeconst", $"{MuscleTimeConst[0]} {MuscleTimeConst[1]}");
mjcf.SetAttribute("timeconst", MjEngineTool.MakeLocaleInvariant($"{MuscleTimeConst[0]} {MuscleTimeConst[1]}"));
mjcf.SetAttribute(
"range", $"{MjEngineTool.GetSorted(Range).x} {MjEngineTool.GetSorted(Range).y}");
mjcf.SetAttribute("force", $"{Force}");
mjcf.SetAttribute("scale", $"{Scale}");
mjcf.SetAttribute("lmin", $"{LMin}");
mjcf.SetAttribute("lmax", $"{LMax}");
mjcf.SetAttribute("vmax", $"{VMax}");
mjcf.SetAttribute("fpmax", $"{FpMax}");
mjcf.SetAttribute("fvmax", $"{FvMax}");
"range", MjEngineTool.MakeLocaleInvariant($"{MjEngineTool.GetSorted(Range).x} {MjEngineTool.GetSorted(Range).y}"));
mjcf.SetAttribute("force", MjEngineTool.MakeLocaleInvariant($"{Force}"));
mjcf.SetAttribute("scale", MjEngineTool.MakeLocaleInvariant($"{Scale}"));
mjcf.SetAttribute("lmin", MjEngineTool.MakeLocaleInvariant($"{LMin}"));
mjcf.SetAttribute("lmax", MjEngineTool.MakeLocaleInvariant($"{LMax}"));
mjcf.SetAttribute("vmax", MjEngineTool.MakeLocaleInvariant($"{VMax}"));
mjcf.SetAttribute("fpmax", MjEngineTool.MakeLocaleInvariant($"{FpMax}"));
mjcf.SetAttribute("fvmax", MjEngineTool.MakeLocaleInvariant($"{FvMax}"));
}
public void MuscleFromMjcf(XmlElement mjcf) {
+12 -12
View File
@@ -291,14 +291,14 @@ public struct MjOptionStruct {
}
public XmlElement ToMjcf(XmlElement mjcf) {
mjcf.SetAttribute("impratio", $"{ImpRatio}");
mjcf.SetAttribute("impratio", MjEngineTool.MakeLocaleInvariant($"{ImpRatio}"));
mjcf.SetAttribute("magnetic", $"{Magnetic.x} {Magnetic.y} {Magnetic.z}");
mjcf.SetAttribute("wind", $"{Wind.x} {Wind.y} {Wind.z}");
mjcf.SetAttribute("magnetic", MjEngineTool.MakeLocaleInvariant($"{Magnetic.x} {Magnetic.y} {Magnetic.z}"));
mjcf.SetAttribute("wind", MjEngineTool.MakeLocaleInvariant($"{Wind.x} {Wind.y} {Wind.z}"));
mjcf.SetAttribute("density", $"{Density}");
mjcf.SetAttribute("viscosity", $"{Viscosity}");
mjcf.SetAttribute("o_margin", $"{OverrideMargin}");
mjcf.SetAttribute("density", MjEngineTool.MakeLocaleInvariant($"{Density}"));
mjcf.SetAttribute("viscosity", MjEngineTool.MakeLocaleInvariant($"{Viscosity}"));
mjcf.SetAttribute("o_margin", MjEngineTool.MakeLocaleInvariant($"{OverrideMargin}"));
OverrideSolRef.ToMjcf(mjcf, "o_solref");
OverrideSolImp.ToMjcf(mjcf, "o_solimp");
@@ -309,12 +309,12 @@ public struct MjOptionStruct {
mjcf.SetAttribute("jacobian", Jacobian.ToString());
mjcf.SetAttribute("solver", Solver.ToString());
mjcf.SetAttribute("iterations", $"{Iterations}");
mjcf.SetAttribute("tolerance", $"{Tolerance}");
mjcf.SetAttribute("noslip_iterations", $"{NoSlipIterations}");
mjcf.SetAttribute("noslip_tolerance", $"{NoSlipTolerance}");
mjcf.SetAttribute("mpr_iterations", $"{MprIterations}");
mjcf.SetAttribute("mpr_tolerance", $"{MprTolerance}");
mjcf.SetAttribute("iterations", MjEngineTool.MakeLocaleInvariant($"{Iterations}"));
mjcf.SetAttribute("tolerance", MjEngineTool.MakeLocaleInvariant($"{Tolerance}"));
mjcf.SetAttribute("noslip_iterations", MjEngineTool.MakeLocaleInvariant($"{NoSlipIterations}"));
mjcf.SetAttribute("noslip_tolerance", MjEngineTool.MakeLocaleInvariant($"{NoSlipTolerance}"));
mjcf.SetAttribute("mpr_iterations", MjEngineTool.MakeLocaleInvariant($"{MprIterations}"));
mjcf.SetAttribute("mpr_tolerance", MjEngineTool.MakeLocaleInvariant($"{MprTolerance}"));
var flags = (XmlElement)mjcf.AppendChild(
mjcf.OwnerDocument.CreateElement("flag"));
+1 -1
View File
@@ -43,7 +43,7 @@ public class MjInertial : MjComponent {
protected override XmlElement OnGenerateMjcf(XmlDocument doc) {
var mjcf = (XmlElement)doc.CreateElement("inertial");
MjEngineTool.PositionRotationToMjcf(mjcf, this);
mjcf.SetAttribute("mass", $"{Mass}");
mjcf.SetAttribute("mass", MjEngineTool.MakeLocaleInvariant($"{Mass}"));
mjcf.SetAttribute("diaginertia",
MjEngineTool.Vector3ToMjcf(MjEngineTool.MjExtents(DiagInertia)));
return mjcf;
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f9a0c761e9698497aba0a6c4d1774bd9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 00391142561004cc7befda5d7fcb3156
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -32,7 +32,7 @@ public class MjCapsuleShape : IMjShape {
" value of X and Y components.", transform);
}
mjcf.SetAttribute(
"size", $"{Radius * transform.lossyScale.x} {HalfHeight * transform.lossyScale.y}");
"size", MjEngineTool.MakeLocaleInvariant($"{Radius * transform.lossyScale.x} {HalfHeight * transform.lossyScale.y}"));
}
public void FromMjcf(XmlElement mjcf) {
@@ -32,7 +32,7 @@ public class MjCylinderShape : IMjShape {
" value of X and Y components.", transform);
}
mjcf.SetAttribute(
"size", $"{Radius * transform.lossyScale.x} {HalfHeight * transform.lossyScale.y}");
"size", MjEngineTool.MakeLocaleInvariant($"{Radius * transform.lossyScale.x} {HalfHeight * transform.lossyScale.y}"));
}
public void FromMjcf(XmlElement mjcf) {
@@ -64,9 +64,9 @@ public class MjGeom : MjShapeComponent {
protected override XmlElement OnGenerateMjcf(XmlDocument doc) {
var mjcf = (XmlElement)doc.CreateElement("geom");
if (Mass > 0) {
mjcf.SetAttribute("mass", $"{Mass}");
mjcf.SetAttribute("mass", MjEngineTool.MakeLocaleInvariant($"{Mass}"));
} else {
mjcf.SetAttribute("density", $"{Density}");
mjcf.SetAttribute("density", MjEngineTool.MakeLocaleInvariant($"{Density}"));
}
ShapeToMjcf(mjcf, transform);
MjEngineTool.PositionRotationToMjcf(mjcf, this);
@@ -78,15 +78,15 @@ public struct MjGeomSettings {
// Solver settings.
mjcf.SetAttribute("condim", $"{Solver.ConDim}");
mjcf.SetAttribute("solmix", $"{Solver.SolMix}");
mjcf.SetAttribute("solref", $"{Solver.SolRef.TimeConst} {Solver.SolRef.DampRatio}");
mjcf.SetAttribute("solmix", MjEngineTool.MakeLocaleInvariant($"{Solver.SolMix}"));
mjcf.SetAttribute("solref", MjEngineTool.MakeLocaleInvariant($"{Solver.SolRef.TimeConst} {Solver.SolRef.DampRatio}"));
mjcf.SetAttribute(
"solimp", $"{Solver.SolImp.DMin} {Solver.SolImp.DMax} {Solver.SolImp.Width}");
mjcf.SetAttribute("margin", $"{Solver.Margin}");
mjcf.SetAttribute("gap", $"{Solver.Gap}");
"solimp", MjEngineTool.MakeLocaleInvariant($"{Solver.SolImp.DMin} {Solver.SolImp.DMax} {Solver.SolImp.Width}"));
mjcf.SetAttribute("margin", MjEngineTool.MakeLocaleInvariant($"{Solver.Margin}"));
mjcf.SetAttribute("gap", MjEngineTool.MakeLocaleInvariant($"{Solver.Gap}"));
// Inertia and friction settings.
mjcf.SetAttribute("friction", $"{Friction.Sliding} {Friction.Torsional} {Friction.Rolling}");
mjcf.SetAttribute("friction", MjEngineTool.MakeLocaleInvariant($"{Friction.Sliding} {Friction.Torsional} {Friction.Rolling}"));
}
}
@@ -26,7 +26,7 @@ public class MjPlaneShape : IMjShape {
public void ToMjcf(XmlElement mjcf, Transform transform) {
var extents = new Vector3(Extents.x, Extents.y, 1.0f);
var scaledExtents = Vector3.Scale(extents, transform.lossyScale);
mjcf.SetAttribute("size", $"{scaledExtents.x} {scaledExtents.y} {scaledExtents.z}");
mjcf.SetAttribute("size", MjEngineTool.MakeLocaleInvariant($"{scaledExtents.x} {scaledExtents.y} {scaledExtents.z}"));
}
public void FromMjcf(XmlElement mjcf) {
@@ -32,7 +32,7 @@ public class MjSphereShape : IMjShape {
" component.\n Consider using Ellipsoid shape if you want to use non-uniform scaling.",
transform);
}
mjcf.SetAttribute("size", $"{Radius * transform.lossyScale.x}");
mjcf.SetAttribute("size", MjEngineTool.MakeLocaleInvariant($"{Radius * transform.lossyScale.x}"));
}
public void FromMjcf(XmlElement mjcf) {
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b58acb5cf1b8049acb79e46a0d8b851b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -51,9 +51,9 @@ public abstract class MjBaseTendon : MjComponent {
protected override XmlElement OnGenerateMjcf(XmlDocument doc) {
var mjcf = ToMjcf(doc);
Solver.ToMjcf(mjcf);
mjcf.SetAttribute("springlength", $"{SpringLength}");
mjcf.SetAttribute("damping", $"{Damping}");
mjcf.SetAttribute("stiffness", $"{Stiffness}");
mjcf.SetAttribute("springlength", MjEngineTool.MakeLocaleInvariant($"{SpringLength}"));
mjcf.SetAttribute("damping", MjEngineTool.MakeLocaleInvariant($"{Damping}"));
mjcf.SetAttribute("stiffness", MjEngineTool.MakeLocaleInvariant($"{Stiffness}"));
return mjcf;
}
@@ -57,13 +57,13 @@ public class MjFixedTendon : MjBaseTendon {
foreach (FixedTendonEntry fixedTendonEntry in JointList) {
var jointMjcf = doc.CreateElement("joint");
jointMjcf.SetAttribute("joint", fixedTendonEntry.Joint.MujocoName);
jointMjcf.SetAttribute("coef", $"{fixedTendonEntry.Coefficient}");
jointMjcf.SetAttribute("coef", MjEngineTool.MakeLocaleInvariant($"{fixedTendonEntry.Coefficient}"));
mjcf.AppendChild(jointMjcf);
}
if (RangeLower > RangeUpper) {
throw new ArgumentException("Lower range value can't be bigger than Higher");
}
mjcf.SetAttribute("range", $"{RangeLower} {RangeUpper}");
mjcf.SetAttribute("range", MjEngineTool.MakeLocaleInvariant($"{RangeLower} {RangeUpper}"));
return mjcf;
}
@@ -92,14 +92,14 @@ public class MjSpatialTendon : MjBaseTendon {
$"Exactly one of site/wrap geom/pulley {name} is required at each entry.");
}
elementMjcf = doc.CreateElement("pulley");
elementMjcf.SetAttribute("divisor", $"{spatialTendonEntry.PulleyDivisor}");
elementMjcf.SetAttribute("divisor", MjEngineTool.MakeLocaleInvariant($"{spatialTendonEntry.PulleyDivisor}"));
}
mjcf.AppendChild(elementMjcf);
}
if (RangeLower > RangeUpper) {
throw new ArgumentException("Lower range value can't be bigger than Higher");
}
mjcf.SetAttribute("range", $"{RangeLower} {RangeUpper}");
mjcf.SetAttribute("range", MjEngineTool.MakeLocaleInvariant($"{RangeLower} {RangeUpper}"));
return mjcf;
}
@@ -1,5 +1,5 @@
{
"name": "Mujoco",
"name": "Mujoco.Runtime",
"rootNamespace": "",
"references": [],
"includePlatforms": [],
+16 -4
View File
@@ -35,6 +35,10 @@ public static class MjEngineTool {
return name.Replace('/', '_');
}
public static string MakeLocaleInvariant(FormattableString interpolated) {
return FormattableString.Invariant(interpolated);
}
// Loads a model from the specified file.
// `filename` should contain an absolute path to the file.
public static unsafe MujocoLib.mjModel_* LoadModelFromFile(string fileName) {
@@ -190,11 +194,11 @@ public static class MjEngineTool {
}
public static string Vector3ToMjcf(Vector3 vec) {
return $"{vec.x} {vec.y} {vec.z}";
return MakeLocaleInvariant($"{vec.x} {vec.y} {vec.z}");
}
public static string QuaternionToMjcf(Quaternion quat) {
return $"{quat.w} {quat.x} {quat.y} {quat.z}";
return MakeLocaleInvariant($"{quat.w} {quat.x} {quat.y} {quat.z}");
}
// We can't use transform.localPosition because we allow arbitrary deep gameObject hierarchies
@@ -230,12 +234,20 @@ public static class MjEngineTool {
// Converts an array of floats to an Mjcf.
public static string ArrayToMjcf(float[] array) {
return String.Join(" ", array);
String ret = "";
foreach (float entry in array) {
ret += MakeLocaleInvariant($"{entry} ");
}
return ret.Substring(startIndex:0, length:ret.Length - 1);
}
// Converts a list of floats to an Mjcf.
public static string ListToMjcf(List<float> list) {
return String.Join(" ", list);
String ret = "";
foreach (float entry in list) {
ret += MakeLocaleInvariant($"{entry} ");
}
return ret.Substring(startIndex:0, length:ret.Length - 1);
}
// Generates an Mjcf of the specified component's transform.

Some files were not shown because too many files have changed in this diff Show More