17-12-2017, 01:08 PM
(This post was last modified: 17-12-2017, 01:09 PM by josemendez.)
(17-12-2017, 02:00 AM)writer51 Wrote: Can I get a Hallelujah! THANK YOU
This has been a long sought-after thing for us too!
Ok, so here's the patch and installation instructions. It will be a little hard to apply, as you must manually modify the existing ObiSolver.cs file in a couple places.
1.- Replace the existing ObiCollisionEventArgs and ObiFluidEventArgs class implementations (found at the beginning of ObiSolver.cs) with this:
Code:
public class ObiCollisionEventArgs : EventArgs{
public ObiList<Oni.Contact> contacts = new ObiList<Oni.Contact>(); /**< collision contacts.*/
}
public class ObiFluidEventArgs : EventArgs{
public ObiList<int> indices = new ObiList<int>(); /**< fluid particle indices.*/
public ObiList<Vector4> vorticities = new ObiList<Vector4>();
public ObiList<float> densities = new ObiList<float>();
}
private ObiCollisionEventArgs collisionArgs = new ObiCollisionEventArgs();
private ObiFluidEventArgs fluidArgs = new ObiFluidEventArgs();
2.- Replace TriggerFluidUpdateEvents and TriggerCollisionEvents functions with these:
Code:
private void TriggerFluidUpdateEvents(){
int numFluidParticles = Oni.GetConstraintCount(oniSolver,(int)Oni.ConstraintType.Density);
if (numFluidParticles > 0 && OnFluidUpdated != null){
fluidArgs.indices.SetCount(numFluidParticles);
fluidArgs.vorticities.SetCount(maxParticles);
fluidArgs.densities.SetCount(maxParticles);
Oni.GetActiveConstraintIndices(oniSolver,fluidArgs.indices.Data,numFluidParticles,(int)Oni.ConstraintType.Density);
Oni.GetParticleVorticities(oniSolver,fluidArgs.vorticities.Data,maxParticles,0);
Oni.GetParticleDensities(oniSolver,fluidArgs.densities.Data,maxParticles,0);
OnFluidUpdated(this,fluidArgs);
}
}
private void TriggerCollisionEvents(){
int numCollisions = Oni.GetConstraintCount(oniSolver,(int)Oni.ConstraintType.Collision);
if (OnCollision != null){
if (numCollisions > 0)
{
collisionArgs.contacts.SetCount(numCollisions);
Oni.GetCollisionContacts(oniSolver,collisionArgs.contacts.Data,numCollisions);
}
OnCollision(this,collisionArgs);
}
}
Lastly, include the ObiList.cs file you'll find attached in your project. That should be it! Collision and fluid update events will only generate a small amount of garbage in certain frames, when the amount of contacts/particles grows past the arrays capacity. Most frames, zero garbage will be generated.
Let me know if you have any issues with this.