Skip to content

Commit 29db390

Browse files
authored
[Scripts] Fix: Topological change when mesh is a point cloud without topology. Update demo use case: SPHFluidParticles (#212)
* Fix warning on SPHDemo sofa scene * Fix: Topological change when mesh is a point cloud without topology. Update demo use case: SPHFluidParticles
1 parent 8c7b7f2 commit 29db390

3 files changed

Lines changed: 185 additions & 177 deletions

File tree

Core/Scripts/Core/Components/SofaMesh.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,10 @@ protected override void Update_impl()
227227
else if (m_listenerCounter < 0)
228228
Debug.LogError("SofaMesh has " + m_listenerCounter + " listerners, this should not be possible");
229229

230-
if (this.TopologyType() != TopologyObjectType.NO_TOPOLOGY && m_sofaMeshAPI.HasTopologyChanged())
231-
{
232-
//Debug.Log("SofaMesh::updateImpl TopologyChanged");
233-
HandleTopologyChange();
234-
}
230+
// First check if topology has changed and handle it
231+
HandleTopologyChange();
235232

233+
// Then update the topology and vertices positions
236234
UpdateTopology();
237235
}
238236

@@ -395,6 +393,27 @@ protected void UpdateUnityVertices()
395393
/// Method called by \sa update_impl() to recompute the topology if changed
396394
protected void HandleTopologyChange()
397395
{
396+
// Handle specific case of point cloud without topology first
397+
if (this.TopologyType() == TopologyObjectType.NO_TOPOLOGY)
398+
{
399+
int _nbV = m_sofaMeshAPI.getNbVertices();
400+
if (m_nbVertices != _nbV)
401+
{
402+
m_nbVertices = _nbV;
403+
m_unityVertices = new Vector3[m_nbVertices];
404+
m_vertexBuffer = null;
405+
m_vertexBuffer = new float[m_nbVertices * m_meshDim];
406+
}
407+
408+
return;
409+
}
410+
411+
// Check if topology has changed. If not, nothing to do
412+
if (!m_sofaMeshAPI.HasTopologyChanged()) {
413+
return;
414+
}
415+
416+
// Handle change of topology depending on the type of topology
398417
if (this.TopologyType() == TopologyObjectType.TRIANGLE)
399418
{
400419
Debug.LogError("HandleTopologyChange for TRIANGLE not implemented yet!");
@@ -446,13 +465,6 @@ protected void UpdateTopology()
446465
}
447466
else if (this.TopologyType() == TopologyObjectType.NO_TOPOLOGY)
448467
{
449-
int _nbV = m_sofaMeshAPI.getNbVertices();
450-
if (m_nbVertices != _nbV)
451-
{
452-
m_nbVertices = _nbV;
453-
m_unityVertices = new Vector3[m_nbVertices];
454-
}
455-
456468
UpdateUnityVertices();
457469
}
458470

0 commit comments

Comments
 (0)