Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Obi Handle and fixing particles at runtime
#2
(10-09-2019, 09:33 PM)msw201089 Wrote: I am running into an interesting problem. I am trying to create a new gameobject, attach an Obi Particle Handle component to it, set a particles mass and velocity to 0, then add that particle to the handle. I have tried to do this in almost every order possible by creating the gameobject first, adding the particle first, zeroing out mass and velocity first, and no matter what order the operations are done in inevitably the model freaks out and disappears, or only the particle itself freaks out. I have also tried to setup the handle in the editor and then disable and enable it at runtime but this also causes weird behavior.

Code sample:
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;
        actor.PushDataToSolver(ParticleData.INV_MASSES | ParticleData.VELOCITIES);
        */

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

        /*
        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);
    }
}

I have this script attached to the dragon in the sample scene from the Obi softbody asset.

Basically, I'm not sure if my code is causing the problems, I'm going about this the wrong way, or if I've found a bug.

Any help would be appreciated.

Unity version 2019.2.0f1

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 josemendez - 13-09-2019, 08:03 AM