Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Obi Handle and fixing particles at runtime
#3
So I tried to integrate the code that you gave and the behavior is still the same. I have attached a link to a youtube video that shows what happens when the key is pressed to execute the function in the code. I hope that you can derive a little more information about what\'s going on than I can because it just looks like the point is being updated by 2 separate things that are fighting for the position it is in.

I have also inserted the modification to the code I made. I tried the piece before and after pushing the actor data to the solver. As well as trying before and after the attaching of the handle and in all the situations the behavior was the same. I left the positions I tried the code in with what I sent to show where I tried it.

I will get in contact with support if it seems that this is something that shouldn't be happening but I wanted to confirm that it wasn't an error on my side before I did.

Thanks for the help so far though!

https://www.youtube.com/watch?v=MiISRnw3OWo&feature=youtu.be



Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;

public class ObiSoftBodyTester : MonoBehaviour
{
   ObiActor actor;

   public GameObject runtimeHandleGO;
   public ObiParticleHandle newHandle;
   public ObiSolver mySolver;

   // Start is called before the first frame update
   void Start()
   {
       actor = GetComponent<ObiActor>();
       Debug.Log(actor);
   }

   // Update is called once per frame
   void Update()
   {
       if (Input.GetKeyDown(KeyCode.A))
       {
           RunInit();
       }
   }

   public void RunInit()
   {
       runtimeHandleGO = new GameObject();

       newHandle = runtimeHandleGO.AddComponent<ObiParticleHandle>();
       newHandle.Actor = actor;

       newHandle.transform.position = actor.GetParticlePosition(actor.particleIndices[0]);

       /*
       mySolver.velocities[0] = Vector3.zero;
       mySolver.invMasses[0] = 0;
       */

       actor.velocities[0] = Vector3.zero;
       actor.invMasses[0] = 0;

       /*
       foreach (ObiShapeMatchingConstraintBatch batch in ((ObiSoftbody)actor).ShapeMatchingConstraints.GetBatches())
       {
           Oni.CalculateRestShapeMatching(actor.Solver.OniSolver, batch.OniBatch);
       }
       */

       actor.PushDataToSolver(ParticleData.INV_MASSES | ParticleData.VELOCITIES);

       /*
       foreach (ObiShapeMatchingConstraintBatch batch in ((ObiSoftbody)actor).ShapeMatchingConstraints.GetBatches())
       {
           Oni.CalculateRestShapeMatching(actor.Solver.OniSolver, batch.OniBatch);
       }
       */

       newHandle.AddParticle(0, actor.GetParticlePosition(actor.particleIndices[0]), Quaternion.identity, actor.invMasses[0], 0.0f);

       foreach (ObiShapeMatchingConstraintBatch batch in ((ObiSoftbody)actor).ShapeMatchingConstraints.GetBatches())
       {
           Oni.CalculateRestShapeMatching(actor.Solver.OniSolver, batch.OniBatch);
       }

       /*
       mySolver.velocities[0] = Vector3.zero;
       mySolver.invMasses[0] = 0;
       */

       /*
       actor.velocities[0] = Vector3.zero;
       actor.invMasses[0] = 0;
       actor.PushDataToSolver(ParticleData.INV_MASSES | ParticleData.VELOCITIES);
       */

       Debug.Log(newHandle.ParticleCount);
   }
}


Quote:josemendez
Hi there,

After modifying particle masses in a softbody, a call to Oni.CalculateRestShapeMatching() is required, like so:

Code:
foreach (ObiShapeMatchingConstraintBatch batch in ((ObiSoftbody)actor).ShapeMatchingConstraints.GetBatches())
               Oni.CalculateRestShapeMatching(actor.Solver.OniSolver, batch.OniBatch);

This is because shape matching relies on a rest configuration of the particles, basically their position and mass. If this rest configuration is altered you need to notify the engine.
Reply


Messages In This Thread
RE: Obi Handle and fixing particles at runtime - by msw201089 - 13-09-2019, 05:58 PM