@@ -80,16 +80,19 @@ void Start()
8080
8181 if ( nbrSofaV == 0 || nbrSofaV != tmp . Count )
8282 {
83- Debug . LogError ( "This controller can only act on a valid mesh similar to the same as the SOFA one." ) ;
84- Debug . LogError ( "Found: Nbr Sofa vertices: " + nbrSofaV + " vs Nbr Unity vertices: " + nbrUnityV + " | not duplicated: " + tmp . Count ) ;
85- m_ready = false ;
86- return ;
83+ Debug . LogWarning ( "This controller can only act on a valid mesh similar to the same as the SOFA one." ) ;
84+ Debug . LogWarning ( "Found: Nbr Sofa vertices: " + nbrSofaV + " vs Nbr Unity vertices: " + nbrUnityV + " | not duplicated: " + tmp . Count ) ;
85+ m_sofaMesh . setNbrVertices ( tmp . Count ) ;
86+ nbrSofaV = tmp . Count ;
87+ //m_ready = false;
88+ //return;
8789 }
8890
8991 sofaToUnity = m_sofaMesh . m_sofaContext . GetScaleSofaToUnity ( ) ;
9092 unityToSofa = m_sofaMesh . m_sofaContext . GetScaleUnityToSofa ( ) ;
9193
9294 newPosition = new Vector3 [ nbrSofaV ] ;
95+ UpdateToSofa ( ) ;
9396
9497 m_ready = true ;
9598 }
@@ -100,13 +103,9 @@ void FixedUpdate()
100103 if ( ! m_ready )
101104 return ;
102105
103- for ( int i = 0 ; i < nbrSofaV ; ++ i )
104- {
105- newPosition [ i ] = transform . TransformPoint ( m_unityMesh . mesh . vertices [ map [ i ] ] ) ;
106- }
107- m_sofaMesh . SetPositions ( newPosition ) ;
106+ UpdateToSofa ( ) ;
108107
109- UpdateFromSofa ( ) ;
108+ // UpdateFromSofa();
110109 }
111110
112111 protected void UpdateFromSofa ( )
@@ -123,7 +122,8 @@ protected void UpdateFromSofa()
123122 }
124123
125124
126- protected void UpdateToSofa ( Vector3 my_newPosition )
125+ //protected void UpdateToSofa(Vector3 my_newPosition)
126+ protected void UpdateToSofa ( )
127127 {
128128 //if (isRigidMesh)
129129 //{
@@ -139,8 +139,12 @@ protected void UpdateToSofa(Vector3 my_newPosition)
139139 // m_sofaMesh.SetVertices(newPosition);
140140 //}
141141
142- //this.transform.position = my_newPosition;
143- //objectOri = my_newPosition;
142+ for ( int i = 0 ; i < nbrSofaV ; ++ i )
143+ {
144+ //Debug.Log("vertex sofa: " + i + " | vertex unity: " + map[i] + " | pos unity: " + m_unityMesh.mesh.vertices[map[i]]);
145+ newPosition [ i ] = transform . TransformPoint ( m_unityMesh . mesh . vertices [ map [ i ] ] ) ;
146+ }
147+ m_sofaMesh . SetPositions ( newPosition ) ;
144148 }
145149 }
146150}
0 commit comments