-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSofaBeamModelEditor.cs
More file actions
73 lines (64 loc) · 2.73 KB
/
SofaBeamModelEditor.cs
File metadata and controls
73 lines (64 loc) · 2.73 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
using UnityEngine;
using UnityEditor;
using SofaUnity;
using System.Collections.Generic;
namespace SofaUnity
{
/// <summary>
/// Editor class corresponding to @sa SofaBeamModel
/// Provide create method to create SofaBeamModel from Unity Menu
/// Provide interface to change beam radius and discretisation
/// </summary>
[CustomEditor(typeof(SofaBeamModel), true)]
public class SofaBeamModelEditor : Editor
{
/// <summary>
/// Add SofaBeamModel creation to the SofaUnity Menu
/// </summary>
/// <returns>Pointer to the SofaBeamModel GameObject</returns>
[MenuItem("Tools/SofaUnity/SofaComponent/SofaBeamModel")]
[MenuItem("GameObject/Tools/SofaUnity/SofaComponent/SofaBeamModel")]
public static GameObject CreateNew()
{
if (Selection.activeTransform != null)
{
GameObject selectObj = Selection.activeGameObject;
SofaDAGNode dagN = selectObj.GetComponent<SofaDAGNode>();
if (dagN == null)
{
Debug.LogError("Error2 creating SofaBeamModel object. No SofaDAGNode with a valid SofaMesh selected.");
return null;
}
SofaMesh mesh = dagN.GetSofaMesh();
if (mesh == null)
mesh = dagN.FindSofaMesh();
if (mesh == null)
{
Debug.LogError("Error3 creating SofaBeamModel object. No SofaDAGNode with a valid SofaMesh selected.");
return null;
}
GameObject go = new GameObject("SofaBeamModel - " + dagN.UniqueNameId);
SofaBeamModel bModel = go.AddComponent<SofaBeamModel>();
go.transform.parent = selectObj.transform;
bModel.m_sofaMesh = mesh;
return go;
}
else
{
Debug.LogError("Error1 creating SofaBeamModel object. No SofaDAGNode with a valid SofaMesh selected.");
}
return null;
}
/// Method to create parameters GUI
public override void OnInspectorGUI()
{
SofaBeamModel model = this.target as SofaBeamModel;
if (model == null)
return;
model.m_sofaMesh = (SofaMesh)EditorGUILayout.ObjectField("Beam SofaMesh", model.m_sofaMesh, typeof(SofaMesh), true);
model.BeamDiscretisation = EditorGUILayout.IntField("Beam Discretisation", model.BeamDiscretisation);
model.BeamRadius = EditorGUILayout.Slider("Beam Radius", model.BeamRadius, 0.001f, 30);
model.isRigidMesh = EditorGUILayout.Toggle("use Rigid Dof", model.isRigidMesh);
}
}
}