Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Obi Solver OnCollision
#1
Pregunta 
Hello everyone,

Is there any way to take particle color of collided fluid on OnCollision event?
Reply
#2
(02-11-2021, 01:34 PM)ProDea Wrote: Hello everyone,

Is there any way to take particle color of collided fluid on OnCollision event?

Yes, exact same way you'd take any other particle property upon collision:

Code:
var color = solver.colors[particleIndex];

Note however, this assumes the color of your fluid comes from particle color only. The final fluid color is calculated as:

Quote:particle renderer color * particle color

So if the color of your fluid comes from emitter or renderer color, you'll have to get which actor (emitter) the particle belongs to, then pick the color up from there. This can also be done, see "Retrieving the actor involved in a contact" in the manual:

http://obi.virtualmethodstudio.com/manua...sions.html
Reply
#3
Pregunta 
So is it something like this?

Code:
private void OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        var world = ObiColliderWorld.GetInstance();
        foreach (Oni.Contact contact in e.contacts)
        {
            if (contact.distance < 0.01)
            {
                ObiColliderBase col = world.colliderHandles[contact.bodyB].owner;

                if (col.CompareTag("Detect"))
                {
                    int particleIndex = _obiSolver.simplices[contact.bodyA];
                    ObiSolver.ParticleInActor pa = _obiSolver.particleToActor[particleIndex];
                    ObiEmitter emitter = pa.actor as ObiEmitter;
                    Color color = emitter.GetComponent<ObiParticleRenderer>().particleColor;
                   
                    Debug.Log(color);
                }
            }
        }
    }

This gives me the correct color which is 0,1,0 Green in that case. But GetComponent calls so much. Is it actually the most optimized way to get particle color or am I missing something over here?

I tried this too but it gives me 1,1,1 White color. I have fluid renderer in the scene on MainCamera and (On ObiEmitter object) Obi Particle Renderer has green color 0,1,0.

Code:
private void OnCollision(object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
    {
        var world = ObiColliderWorld.GetInstance();
        foreach (Oni.Contact contact in e.contacts)
        {
            if (contact.distance < 0.01)
            {
                ObiColliderBase col = world.colliderHandles[contact.bodyB].owner;

                if (col.CompareTag("Detect"))
                {
                    int particleIndex = _obiSolver.simplices[contact.bodyA];
                    ObiSolver.ParticleInActor pa = _obiSolver.particleToActor[particleIndex];
                    ObiEmitter emitter = pa.actor as ObiEmitter;
                    Color color = pa.actor.GetParticleColor(particleIndex);
                   
                    Debug.Log(color);
                }
            }
        }
    }
Reply
#4
(02-11-2021, 02:35 PM)ProDea Wrote: So is it something like this?


This gives me the correct color which is 0,1,0 Green in that case. But GetComponent calls so much. Is it actually the most optimized way to get particle color or am I missing something over here?

Your code is correct, fluid color in your case comes from the particle renderer. Particles are all white, so:

fluidColor = renderer color * particle color = (0,1,0) * (1,1,1) = (0,1,0).

(02-11-2021, 02:35 PM)ProDea Wrote: I tried this too but it gives me 1,1,1 White color. I have fluid renderer in the scene on MainCamera and (On ObiEmitter object) Obi Particle Renderer has green color 0,1,0.

Yes, this is correct and to be expected. Your particles are completely white, and being tinted green by the ObiParticleRenderer just before rendering.

If you set the ObiParticleRenderer white and your ObiEmitterShape green, then the emitted particles will be green, and tinted white like so:

fluidColor = renderer color * particle color = (1,1,1) * (0,1,0) = (0,1,0).

This would allow you to get rid of the GetComponent<> calls entirely. Note in your first script you could just cache the component if you wanted, no need to call GetComponent for every single contact like that.
Reply
#5
Dedo arriba 
Thank you so much for quick response!

I changed color with Use Shape Color and it worked out Sonrisa
Reply