1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
// 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 UnityEditor;
using UnityEngine;
namespace Mujoco {
[CustomEditor(typeof(MjGeom), true)]
[CanEditMultipleObjects]
public class MjGeomEditor : MjShapeComponentEditor {
public override void OnInspectorGUI() {
serializedObject.Update();
EditorGUILayout.PropertyField(serializedObject.FindProperty("Mass"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("Density"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("Settings"));
serializedObject.ApplyModifiedProperties();
base.OnInspectorGUI();
}
[MenuItem("CONTEXT/MjGeom/Add mesh renderer")]
private static void AddMeshComponents(MenuCommand menuCommand) {
var geom = menuCommand.context as MjGeom;
geom.gameObject.AddComponent<MjMeshFilter>();
geom.gameObject.AddComponent<MeshRenderer>().material = new Material(Shader.Find("Diffuse"));
}
[MenuItem("CONTEXT/MjGeom/Convert to free object")]
private static void ConvertToFreeObject(MenuCommand menuCommand) {
var geom = menuCommand.context as MjGeom;
if (geom.GetComponentInParent<MjBody>()) {
Debug.LogError("This geom already has a Body parent.", geom.GetComponentInParent<MjBody>());
return;
}
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;
}
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")]
private static void AddMatchingGeom(MenuCommand menuCommand) {
var collider = menuCommand.context as Collider;
collider.enabled = false;
var geom = collider.gameObject.AddComponent<MjGeom>();
if (collider as BoxCollider) {
geom.ShapeType = MjShapeComponent.ShapeTypes.Box;
} else if (collider as SphereCollider) {
geom.ShapeType = MjShapeComponent.ShapeTypes.Sphere;
} else if (collider as CapsuleCollider) {
geom.ShapeType = MjShapeComponent.ShapeTypes.Capsule;
} else if (collider as MeshCollider) {
geom.ShapeType = MjShapeComponent.ShapeTypes.Mesh;
((MjMeshShape)geom.Shape).Mesh = ((MeshCollider)collider).sharedMesh;
} else {
Debug.LogError("Collider type not supported yet.", collider);
collider.enabled = true;
GameObject.DestroyImmediate(geom);
}
}
}
}
|