Obi Official Forum
Help Modifying Emitter - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Fluid (https://obi.virtualmethodstudio.com/forum/forum-3.html)
+--- Thread: Help Modifying Emitter (/thread-2047.html)



Modifying Emitter - ilterbilguven - 14-02-2020

Hi,

Current emitter kills particles by lifespan. I want emitter to kill by position (For example, if a particle's Y position is below -5).

I managed to kill by that, but now emitter isn't working properly after when a particle is killed. How can I fix this?

Here's my CustomEmitter:

Code:
namespace Obi
{
  [AddComponentMenu("Physics/Obi/Obi Emitter", 850)]
  [ExecuteInEditMode]
  public class CustomObiEmitter : ObiActor
  {
     .
      .
      .

     [SerializeField] private float[] _posYs;
     
     public override void LoadBlueprint(ObiSolver solver)
     {
        .

        _posYs = new float[particleCount];
        for (var i = 0; i < _posYs.Length; ++i)
           _posYs[i] = 1;
       
        .
     }

      .
      .
      .

     protected override void SwapWithFirstInactiveParticle(int index)
     {
        .
        _posYs.Swap(index, activeParticleCount);
     }


     public bool EmitParticle(float offset, float deltaTime)
     {
        .
       
        _posYs[activeParticleCount] = 1;
       
        .
         .
         .
     }


     public override void BeginStep(float stepTime)
     {
         .
         .
         .
       
        for (int i = activeParticleCount - 1; i >= 0; --i)
        {
           _posYs[i] = m_Solver.positions[i].y;

           if (_posYs[i] <= -5)
           {
              KillParticle(i);
           }
        }

        .
         .
         .
       
       
     }
  }
}



RE: Modifying Emitter - josemendez - 14-02-2020

(14-02-2020, 01:59 PM)ilterbilguven Wrote: Hi,

Current emitter kills particles by lifespan. I want emitter to kill by position (For example, if a particle's Y position is below -5).

I managed to kill by that, but now emitter isn't working properly after when a particle is killed. How can I fix this?

Here's my CustomEmitter:

Code:
namespace Obi
{
  [AddComponentMenu("Physics/Obi/Obi Emitter", 850)]
  [ExecuteInEditMode]
  public class CustomObiEmitter : ObiActor
  {
     .
     .
     .

     [SerializeField] private float[] _posYs;
     
     public override void LoadBlueprint(ObiSolver solver)
     {
        .

        _posYs = new float[particleCount];
        for (var i = 0; i < _posYs.Length; ++i)
           _posYs[i] = 1;
       
        .
     }

     .
     .
     .

     protected override void SwapWithFirstInactiveParticle(int index)
     {
        .
        _posYs.Swap(index, activeParticleCount);
     }


     public bool EmitParticle(float offset, float deltaTime)
     {
        .
       
        _posYs[activeParticleCount] = 1;
       
        .
        .
        .
     }


     public override void BeginStep(float stepTime)
     {
        .
        .
        .
       
        for (int i = activeParticleCount - 1; i >= 0; --i)
        {
           _posYs[i] = m_Solver.positions[i].y;

           if (_posYs[i] <= -5)
           {
              KillParticle(i);
           }
        }

        .
        .
        .
       
       
     }
  }
}

Why not simply setting the particle's life to zero when it meets the condition you want (y < -5) instead of modifying the emitter class itself? Huh


RE: Modifying Emitter - ilterbilguven - 14-02-2020

(14-02-2020, 02:59 PM)josemendez Wrote: Why not simply setting the particle's life to zero when it meets the condition you want (y < -5) instead of modifying the emitter class itself?   Huh

Well, that's simple too. I want to keep that as a time-based emitter, mine is position-based.

Anyway, your solution shows same result. To illustrate: I have 2000+ particles. At the beginning (e.g after 50th particle), if a particle hits the condition, emitter stops working properly.