-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSofaSphereCollisionObjectEditor.cs
More file actions
89 lines (76 loc) · 3.9 KB
/
SofaSphereCollisionObjectEditor.cs
File metadata and controls
89 lines (76 loc) · 3.9 KB
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
82
83
84
85
86
87
88
89
using UnityEngine;
using UnityEditor;
using SofaUnity;
namespace SofaUnity
{
/// <summary>
/// Editor class corresponding to @sa SofaSphereCollisionModel object
/// This class inherite from @sa SofaMeshObjectEditor and will add specific parameter for Number of sphere collision to create.
/// Provide create method to create SofaSphereCollisionModel from Unity Menu and register it inside DAGNodeManager
/// Provide interface for user interaction
/// </summary>
[CustomEditor(typeof(SofaSphereCollisionObject), true)]
public class SofaSphereCollisionObjectEditor : SofaMeshObjectEditor
{
/// <summary>
/// Add SofaSphereCollisionModel creation to the SofaUnity Menu
/// </summary>
/// <returns>Pointer to the SofaSphereCollisionModel GameObject</returns>
[MenuItem("Tools/SofaUnity/SofaObject/SofaSphereCollisionObject")]
[MenuItem("GameObject/Tools/SofaUnity/SofaObject/SofaSphereCollisionObject")]
new public static GameObject CreateNew()
{
if (Selection.activeTransform == null)
{
Debug.LogError("Error1 creating SofaSphereCollisionObject GameObject. No valid gameObject selected under SofaContext.");
return null;
}
GameObject selectObj = Selection.activeGameObject;
if (selectObj.GetComponent<MeshFilter>() == null)
{
Debug.LogError("Error2 creating SofaSphereCollisionObject GameObject. Object should have a valid MeshFilter.");
return null;
}
SofaDAGNode parentDagN = selectObj.GetComponentInParent<SofaDAGNode>();
if (parentDagN == null)
{
// not under DAGNode, will look for SofaContext
GameObject _contextObject = GameObject.FindGameObjectWithTag("GameController");
if (_contextObject != null)
{
// Get Sofa context
parentDagN = _contextObject.GetComponent<SofaDAGNode>();
}
// still null, no SofaContext found
if (parentDagN == null)
{
Debug.LogError("Error3 creating SofaSphereCollisionObject GameObject. No valid SofaDAGNode found as parent of this gameObject or in SofaContext.");
return null;
}
else
{
Debug.Log("parentDagN found: " + parentDagN.name);
}
}
selectObj.AddComponent<SofaSphereCollisionObject>();
SofaDAGNodeManager nodeMgr = parentDagN.m_sofaContext.NodeGraphMgr;
if (nodeMgr != null)
nodeMgr.RegisterCustomObject(selectObj, parentDagN);
else
Debug.LogError("Error creating SofaSphereCollisionObject. Can't access SofaDAGNodeManager.");
return selectObj;
}
public override void OnInspectorGUI()
{
SofaSphereCollisionObject model = (SofaSphereCollisionObject)this.target;
model.parentT = (GameObject)EditorGUILayout.ObjectField("Parent Gameobject to mirror position", model.parentT, typeof(GameObject), true);
model.UsePositionOnly = EditorGUILayout.Toggle("Use Object Position Only (1 dof)", model.UsePositionOnly);
model.Factor = EditorGUILayout.Slider("Interpolation factor", model.Factor, 1, 100);
model.Radius = EditorGUILayout.Slider("Sphere radius", model.Radius, 0.001f, 10);
model.Activated = EditorGUILayout.Toggle("Activate collision", model.Activated);
model.Stiffness = EditorGUILayout.Slider("Contact stiffness", model.Stiffness, 1, 5000);
model.m_startOnPlay = EditorGUILayout.Toggle("Start on Play", model.m_startOnPlay);
EditorGUILayout.LabelField("Number of spheres", model.NbrSpheres.ToString());
}
}
}