Obi Official Forum
How to fix the collided particle - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Softbody (https://obi.virtualmethodstudio.com/forum/forum-12.html)
+--- Thread: How to fix the collided particle (/thread-1072.html)



How to fix the collided particle - apapaxionga - 10-04-2019

I tried to set the collided particle's invmass to 0 but it explode the softbody.  I did it in the following way:
Code:
   void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
   {
       for (int i = 0; i < e.contacts.Count; ++i)
       {
           if (e.contacts.Data[i].distance < 0.001f)
           {
               Component collider;
               if (ObiCollider.idToCollider.TryGetValue(e.contacts.Data[i].other, out collider))
               {
                   solver.invMasses[e.contacts.Data[i].particle] = 0;
               }
           }
       }
   }

What is the correct way to achieve this ?


RE: How to fix the collided particle - josemendez - 11-04-2019

(10-04-2019, 11:43 PM)apapaxionga Wrote: I tried to set the collided particle's invmass to 0 but it explode the softbody.  I did it in the following way:
Code:
   void Solver_OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
   {
       for (int i = 0; i < e.contacts.Count; ++i)
       {
           if (e.contacts.Data[i].distance < 0.001f)
           {
               Component collider;
               if (ObiCollider.idToCollider.TryGetValue(e.contacts.Data[i].other, out collider))
               {
                   solver.invMasses[e.contacts.Data[i].particle] = 0;
               }
           }
       }
   }

What is the correct way to achieve this ?

When changing the mass of softbody particles in the solver, you have to recalculate shape matching centers of mass. Like this:
Code:
foreach (ObiShapeMatchingConstraintBatch batch in softbody.ShapeMatchingConstraints.GetBatches())
    Oni.CalculateRestShapeMatching(softbody.Solver.OniSolver,batch.OniBatch);

This is done automatically when you call PushDataToSolver() on a softbody, but not if you modify solver properties directly.