Version 2.1.2: Python bindings, OBJ assets support, bugfixes.
PiperOrigin-RevId: 434731612 Change-Id: I0cfda3e7a3d1c72036764986efc252ffa1b8c6b0
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// Copyright 2019 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
public abstract class MjBaseConstraint : MjComponent {
|
||||
public override MujocoLib.mjtObj ObjectType => MujocoLib.mjtObj.mjOBJ_EQUALITY;
|
||||
|
||||
protected abstract string _constraintName { get; }
|
||||
|
||||
public SolverImpedance SolverImpedanceSettings = SolverImpedance.Default;
|
||||
public SolverReference SolverReferenceSettings = SolverReference.Default;
|
||||
|
||||
protected abstract void ToMjcf(XmlElement mjcf);
|
||||
protected abstract void FromMjcf(XmlElement mjcf);
|
||||
|
||||
protected override void OnParseMjcf(XmlElement mjcf) {
|
||||
FromMjcf(mjcf);
|
||||
SolverReferenceSettings.FromMjcf(mjcf, "solref");
|
||||
SolverImpedanceSettings.FromMjcf(mjcf, "solimp");
|
||||
}
|
||||
|
||||
protected override XmlElement OnGenerateMjcf(XmlDocument doc) {
|
||||
var mjcf = (XmlElement)doc.CreateElement(_constraintName);
|
||||
ToMjcf(mjcf);
|
||||
SolverReferenceSettings.ToMjcf(mjcf, "solref");
|
||||
SolverImpedanceSettings.ToMjcf(mjcf, "solimp");
|
||||
return mjcf;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a34f7c43f90c84e64a45942e605c0a2b
|
||||
timeCreated: 1552309644
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
// Copyright 2019 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
public class MjConnect : MjBaseConstraint {
|
||||
public MjBaseBody Body1;
|
||||
public MjBaseBody Body2;
|
||||
protected override string _constraintName => "connect";
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
Body1 = mjcf.GetObjectReferenceAttribute<MjBaseBody>("body1");
|
||||
Body2 = mjcf.GetObjectReferenceAttribute<MjBaseBody>("body2");
|
||||
if (mjcf.GetStringAttribute("anchor") != null) {
|
||||
Debug.Log($"anchor in connect {name} ignored. Set Transforms in the editor.");
|
||||
}
|
||||
}
|
||||
|
||||
// Generate implementation specific XML element.
|
||||
protected override void ToMjcf(XmlElement mjcf) {
|
||||
if (Body1 == null || Body2 == null) {
|
||||
throw new NullReferenceException($"Both bodies in connect {name} are required.");
|
||||
}
|
||||
mjcf.SetAttribute("body1", Body1.MujocoName);
|
||||
mjcf.SetAttribute("body2", Body2.MujocoName);
|
||||
}
|
||||
|
||||
public void OnValidate() {
|
||||
if (Body1 != null && Body1 == Body2) {
|
||||
Debug.LogError("Body1 and Body2 can't be the same - resetting Body2.", this);
|
||||
Body2 = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee6081d65578643bf8a26f200299a51a
|
||||
timeCreated: 1552313909
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
// Copyright 2019 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
public class MjDistance : MjBaseConstraint {
|
||||
public MjGeom Geom1;
|
||||
public MjGeom Geom2;
|
||||
protected override string _constraintName => "distance";
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
Geom1 = mjcf.GetObjectReferenceAttribute<MjGeom>("geom1");
|
||||
Geom2 = mjcf.GetObjectReferenceAttribute<MjGeom>("geom2");
|
||||
}
|
||||
|
||||
protected override void ToMjcf(XmlElement mjcf) {
|
||||
if (Geom1 == null || Geom2 == null) {
|
||||
throw new NullReferenceException($"Both geoms in distance {name} must be assigned.");
|
||||
}
|
||||
|
||||
mjcf.SetAttribute("geom1", Geom1.MujocoName);
|
||||
mjcf.SetAttribute("geom2", Geom2.MujocoName);
|
||||
}
|
||||
|
||||
public void OnValidate() {
|
||||
if (Geom1 != null && Geom1 == Geom2) {
|
||||
Debug.LogError("Geom1 and Geom2 can't be the same - resetting Geom2.", this);
|
||||
Geom2 = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad0689a32f102481fb189836c11931f9
|
||||
timeCreated: 1552309644
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,59 @@
|
||||
// Copyright 2019 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
public class MjJointConstraint : MjBaseConstraint {
|
||||
[Tooltip("Mandatory.")]
|
||||
public MjBaseJoint Joint1;
|
||||
|
||||
[Tooltip("Optional - if empty, constrain the value of Joint1")]
|
||||
public MjBaseJoint Joint2;
|
||||
|
||||
public float[] PolynomialCoefficients = new float[5] { 0, 1, 0, 0, 0 };
|
||||
protected override string _constraintName => "joint";
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
Joint1 = mjcf.GetObjectReferenceAttribute<MjBaseJoint>("joint1");
|
||||
Joint2 = mjcf.GetObjectReferenceAttribute<MjBaseJoint>("joint2");
|
||||
PolynomialCoefficients =
|
||||
mjcf.GetFloatArrayAttribute("polycoef", defaultValue: new float[] { 0, 1, 0, 0, 0 });
|
||||
}
|
||||
|
||||
// Generate implementation specific XML element.
|
||||
protected override void ToMjcf(XmlElement mjcf) {
|
||||
if (Joint1 == null) {
|
||||
throw new NullReferenceException($"At least Joint1 in constraint {name} must be assigned.");
|
||||
}
|
||||
|
||||
mjcf.SetAttribute("joint1", Joint1.MujocoName);
|
||||
if (Joint2 != null) {
|
||||
mjcf.SetAttribute("joint2", Joint2.MujocoName);
|
||||
}
|
||||
mjcf.SetAttribute("polycoef", MjEngineTool.ArrayToMjcf(PolynomialCoefficients));
|
||||
}
|
||||
|
||||
public void OnValidate() {
|
||||
if (Joint1 != null && Joint1 == Joint2) {
|
||||
Debug.LogError("Joint1 and Joint2 can't be the same - resetting Joint2.", this);
|
||||
Joint2 = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1cf109d843189466880870d026d0c2c7
|
||||
timeCreated: 1552309644
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
// Copyright 2019 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
public class MjTendonConstraint : MjBaseConstraint {
|
||||
public MjBaseTendon Tendon1;
|
||||
public MjBaseTendon Tendon2;
|
||||
public float[] PolynomialCoefficients = new float[5] { 0, 1, 0, 0, 0 };
|
||||
protected override string _constraintName => "tendon";
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
Tendon1 = mjcf.GetObjectReferenceAttribute<MjBaseTendon>("tendon1");
|
||||
Tendon2 = mjcf.GetObjectReferenceAttribute<MjBaseTendon>("tendon2");
|
||||
PolynomialCoefficients =
|
||||
mjcf.GetFloatArrayAttribute("polycoef", new Single[] { 0, 1, 0, 0, 0 });
|
||||
}
|
||||
|
||||
// Generate implementation specific XML element.
|
||||
protected override void ToMjcf(XmlElement mjcf) {
|
||||
if (Tendon1 == null) {
|
||||
throw new NullReferenceException(
|
||||
$"At least Tendon1 in constraint {name} must be assigned.");
|
||||
}
|
||||
|
||||
mjcf.SetAttribute("tendon1", Tendon1.MujocoName);
|
||||
if (Tendon2 != null) {
|
||||
mjcf.SetAttribute("tendon2", Tendon2.MujocoName);
|
||||
}
|
||||
mjcf.SetAttribute("polycoef", MjEngineTool.ArrayToMjcf(PolynomialCoefficients));
|
||||
}
|
||||
|
||||
public void OnValidate() {
|
||||
if (Tendon1 != null && Tendon1 == Tendon2) {
|
||||
Debug.LogWarning(
|
||||
"Tendon1 and Tendon2 can't be the same - resetting Tendon2.", this);
|
||||
Tendon2 = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81536160634694c9f8b78d0de2fe6fde
|
||||
timeCreated: 1552309644
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,61 @@
|
||||
// Copyright 2019 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mujoco {
|
||||
|
||||
public class MjWeld : MjBaseConstraint {
|
||||
public MjBaseBody Body1;
|
||||
public MjBaseBody Body2;
|
||||
public Transform WeldOffset;
|
||||
protected override string _constraintName => "weld";
|
||||
|
||||
protected override unsafe void OnBindToRuntime(MujocoLib.mjModel_* model, MujocoLib.mjData_* data) {
|
||||
if (WeldOffset) {
|
||||
MjEngineTool.SetMjTransform(model->eq_data, WeldOffset.localPosition,
|
||||
WeldOffset.localRotation, MujocoId);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void FromMjcf(XmlElement mjcf) {
|
||||
Body1 = mjcf.GetObjectReferenceAttribute<MjBaseBody>("body1");
|
||||
Body2 = mjcf.GetObjectReferenceAttribute<MjBaseBody>("body2");
|
||||
var relpose = mjcf.GetStringAttribute("relpose");
|
||||
if (relpose != null) {
|
||||
Debug.Log(
|
||||
$"relpose {relpose} in weld {name} ignored. Set WeldOffset in the editor.");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ToMjcf(XmlElement mjcf) {
|
||||
if (Body1 == null || Body2 == null) {
|
||||
throw new NullReferenceException($"Both bodies in weld {name} must be assigned.");
|
||||
}
|
||||
|
||||
mjcf.SetAttribute("body1", Body1.MujocoName);
|
||||
mjcf.SetAttribute("body2", Body2.MujocoName);
|
||||
}
|
||||
|
||||
public void OnValidate() {
|
||||
if (Body1 != null && Body1 == Body2) {
|
||||
Debug.LogWarning("Body1 and Body2 can't be the same - resetting Body2.", this);
|
||||
Body2 = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b6f83e13e2c454767a785a138674c84f
|
||||
timeCreated: 1550663136
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user