-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSofaMeshObjectEditor.cs
More file actions
131 lines (107 loc) · 4.79 KB
/
SofaMeshObjectEditor.cs
File metadata and controls
131 lines (107 loc) · 4.79 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using UnityEngine;
using UnityEditor;
using SofaUnity;
namespace SofaUnity
{
/// <summary>
/// Editor Class to define the creation and UI of SofaMeshObject GameObject
/// </summary>
[CustomEditor(typeof(SofaMeshObject), true)]
public class SofaMeshObjectEditor : Editor
{
public static SofaDAGNode GetDAGNodeSelected()
{
if (Selection.activeTransform == null)
{
Debug.LogError("Error1 creating SofaDAGNode GameObject. No valid SofaContext nor SofaDAGNode selected.");
return null;
}
GameObject selectObj = Selection.activeGameObject;
SofaDAGNode parentDagN = selectObj.GetComponent<SofaDAGNode>();
if (parentDagN == null)
{
// not a DAGNode selected. Check if SofaComponent
SofaBaseComponent sofaComponent = selectObj.GetComponent<SofaBaseComponent>();
// If neither a sofa component, nothing can be done
if (sofaComponent == null)
{
Debug.LogError("Error2 creating SofaDAGNode GameObject. No valid SofaDAGNode or SofaComponent selected.");
return null;
}
// otherwise will search for DAGNode owner of this component and add New DAGNode as child of this owner
parentDagN = sofaComponent.m_ownerNode;
if (parentDagN == null)
{
Debug.LogError("Error3 creating SofaDAGNode GameObject. SofaComponent selected has no valid SofaDAGNode owner.");
return null;
}
}
return parentDagN;
}
bool normalBtn = false;
/// <summary>
/// Add SofaMeshObject Object creation to the SofaUnity Menu
/// </summary>
/// <returns>Pointer to the SofaMeshObject GameObject</returns>
[MenuItem("Tools/SofaUnity/SofaObject/SofaMeshObject")]
[MenuItem("GameObject/Tools/SofaUnity/SofaObject/SofaMeshObject")]
public static GameObject CreateNew()
{
GameObject go = new GameObject("SofaMeshObject");
go.AddComponent<SofaMeshObject>();
return go;
}
/// <summary>
/// Method to set the UI of the SofaMeshObject GameObject
/// </summary>
public override void OnInspectorGUI()
{
SofaMeshObject mesh = (SofaMeshObject)this.target;
if (mesh.IsAwake() == false)
return;
// Check box to change normals direction
normalBtn = EditorGUILayout.Toggle("Inverse Normals", mesh.m_invertNormals);
mesh.invertNormals = normalBtn;
//// Add Triansformation fields
//mesh.translation = EditorGUILayout.Vector3Field("Translation", mesh.m_translation);
//EditorGUILayout.Separator();
//mesh.rotation = EditorGUILayout.Vector3Field("Rotation", mesh.m_rotation);
//EditorGUILayout.Separator();
//mesh.scale = EditorGUILayout.Vector3Field("Scale", mesh.m_scale);
//EditorGUILayout.Separator();
//// Add FEM fields
//if (mesh.m_mass != float.MinValue)
//{
// mesh.mass = EditorGUILayout.Slider("Mass", mesh.m_mass, 0.0001f, 1000);
// EditorGUILayout.Separator();
//}
//if (mesh.m_young != float.MinValue)
//{
// mesh.young = EditorGUILayout.Slider("Young Modulus", mesh.m_young, 0.0001f, 10000);
// EditorGUILayout.Separator();
//}
//if (mesh.m_poisson != float.MinValue)
//{
// mesh.poisson = EditorGUILayout.Slider("Poisson Ratio", mesh.m_poisson, 0.0001f, 0.49f);
// EditorGUILayout.Separator();
//}
//if (mesh.m_stiffness != float.MinValue)
//{
// mesh.stiffness = EditorGUILayout.Slider("Stiffness", mesh.m_stiffness, 0.0001f, 10000);
// EditorGUILayout.Separator();
//}
//if (mesh.m_damping != float.MinValue)
//{
// mesh.damping = EditorGUILayout.Slider("Damping", mesh.m_damping, 0.0001f, 100);
// EditorGUILayout.Separator();
//}
//if (mesh.hasCollisionSphere())
//{
// mesh.radius = EditorGUILayout.Slider("Sphere radius", mesh.radius, 0.001f, 10);
// mesh.contactStiffness = EditorGUILayout.Slider("Spheree Contact stiffness", mesh.contactStiffness, 1, 5000);
// mesh.showCollisionSphere = EditorGUILayout.Toggle("Display Collision Spheres", mesh.showCollisionSphere);
// EditorGUILayout.Separator();
//}
}
}
}