Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Obi Handle and fixing particles at runtime
#4
(13-09-2019, 05:58 PM)msw201089 Wrote: 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);
   }
}

Hi,

If adding a handle at runtime, particle masses are not modified until the actor gets added to the solver at the start of the scene. So you're actually calling the code I gave before the masses are modified, not after.

You could call this by subscribing to the solver add event, but for ease of use I modified ObiParticleHandle.cs for you to do it automatically. Find the code attached.


Attached Files
.cs   ObiParticleHandle.cs (Size: 6.45 KB / Downloads: 7)
Reply


Messages In This Thread
RE: Obi Handle and fixing particles at runtime - by josemendez - 14-09-2019, 11:13 AM