Skip to content

Commit 9057804

Browse files
committed
[src] Add option to use rigid dof in BeamModel
1 parent 56c4e04 commit 9057804

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

Scripts/Editor/Components/SofaBeamModelEditor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@ public override void OnInspectorGUI()
6565
model.m_sofaMesh = (SofaMesh)EditorGUILayout.ObjectField("Beam SofaMesh", model.m_sofaMesh, typeof(SofaMesh), true);
6666
model.BeamDiscretisation = EditorGUILayout.IntField("Beam Discretisation", model.BeamDiscretisation);
6767
model.BeamRadius = EditorGUILayout.Slider("Beam Radius", model.BeamRadius, 0.001f, 30);
68+
model.isRigidMesh = EditorGUILayout.Toggle("use Rigid Dof", model.isRigidMesh);
6869
}
6970
}

Scripts/Modules/Components/SofaBeamModel.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public class SofaBeamModel : MonoBehaviour
2020
/// Member: Unity Mesh object of this GameObject
2121
protected Mesh m_mesh;
2222

23+
/// Parameter bool to store information if vec3 or rigid are parsed.
24+
[SerializeField]
25+
public bool isRigidMesh = false;
26+
2327
/// Parameter of this beam, it determnines the discretisation of the circonference around each center point of the beam.
2428
[SerializeField]
2529
protected int m_beamDiscretisation = 4;
@@ -155,9 +159,14 @@ protected virtual void CreateBeamMesh()
155159
m_mesh.Clear();
156160
float[] sofaVertices = m_sofaMesh.SofaMeshTopology.m_vertexBuffer;
157161
m_vertCenter = new Vector3[nbrV];
162+
163+
int sizeDof = 3;
164+
if (isRigidMesh)
165+
sizeDof = 7;
166+
158167
for (int i = 0; i < nbrV; i++)
159168
{
160-
m_vertCenter[i] = new Vector3(sofaVertices[i * 3], sofaVertices[i * 3 + 1], sofaVertices[i * 3 + 2]);
169+
m_vertCenter[i] = new Vector3(sofaVertices[i * sizeDof], sofaVertices[i * sizeDof + 1], sofaVertices[i * sizeDof + 2]);
161170
}
162171

163172
int nbrPointPerCircle = 4 * m_beamDiscretisation + 1; // +1 to close cylinder UV
@@ -290,13 +299,17 @@ protected virtual void UpdateBeamMesh()
290299
if (nbrV < 2)
291300
return;
292301

293-
//Debug.Log("BeamModel::UpdateLinearMesh");
302+
int sizeDof = 3;
303+
if (isRigidMesh)
304+
sizeDof = 7;
305+
294306
float[] sofaVertices = m_sofaMesh.SofaMeshTopology.m_vertexBuffer;
295307
for (int i = 0; i < nbrV; i++)
296308
{
297-
m_vertCenter[i] = new Vector3(sofaVertices[i * 3], sofaVertices[i * 3 + 1], sofaVertices[i * 3 + 2]);
309+
m_vertCenter[i] = new Vector3(sofaVertices[i * sizeDof], sofaVertices[i * sizeDof + 1], sofaVertices[i * sizeDof + 2]);
298310
}
299311

312+
300313
// update borders first
301314
int idLast = m_vertices.Length - 1;
302315
m_vertices[0] = m_vertCenter[0];

0 commit comments

Comments
 (0)