Posts: 5
Threads: 2
Joined: Jun 2017
Reputation:
0
Obi Owner:
19-06-2017, 08:58 PM
(This post was last modified: 20-06-2017, 04:53 PM by lidiamartinez.
Edit Reason: Added extra info from the thread
)
Hi,
I am planning to purchase the complete OBI set. We need it for a new game. Is it possible to add custom colliders, mesh colliders or collider callbacks like distance fields?
We also need some areas (boxes) that are non-obi water. Is it possible to add forces to your particle simulation only in these areas to simulate bouancy?
And.. what happend to your soft-bodies? Can they be implemented via your API? different product?
thx a lot in advance
br
David
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
20-06-2017, 09:37 AM
(This post was last modified: 20-06-2017, 09:38 AM by josemendez.)
Hi David,
Unfortunately it is not possible to add custom colliders, at least not with good performance. This is because collision detection/resolution is implemented using SIMD vector instructions inside Obi's C++ lib, to which you don´t have access. It's either flexibility or performance, so we went with performance in this case.
You could get particle positions/velocities every frame and implement your own collision detection in C#, but it will be challenging to get it running at an acceptable speed for more than a couple thousand particles.
MeshColliders are fully supported by default, though.
------
Regarding fluids, keep in mind that Obi is a particle-based simulation that runs in the CPU. This means you´ll be able to simulate no more than 10000 particles in realtime in a desktop platform (not making an ocean with it, unfortunately).
Good news is that rigidbody buoyancy just works. Dense (heavy) rigidbodies will automatically sink and light ones will rise. Inter-fluid buoyancy (due to density gradient) also works out of the box. Dense fluids will sink and lighter ones will rise. See:
https://www.youtube.com/watch?v=gnYZc9558m0
Box and sphere shaped emitters are included, so you can easily create box-shaped fluid zones.
-----
Softbodies are WIP right now. Don´t have an ETA yet, but will announce them when they're mature enough.
cheers,
Posts: 5
Threads: 2
Joined: Jun 2017
Reputation:
0
Obi Owner:
Ah perfect, thx for your quick answer. The part with the collision is fine. For the water you misunderstood my bad english question maybe
I want to add an area of water (my water, not an obi water) and this should affect your simulation particles like other gravity, damping etc...
For example: I want a swimming obi rope on a water box (no obi particle fluid)
thx a lot
br
David
Ps: if you have another idea how I could simulate non-obi water to affect your particle simulation I would be happy to hear it, hehe
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(20-06-2017, 02:02 PM)davidrousal Wrote: Ah perfect, thx for your quick answer. The part with the collision is fine. For the water you misunderstood my bad english question maybe
I want to add an area of water (my water, not an obi water) and this should affect your simulation particles like other gravity, damping etc...
For example: I want a swimming obi rope on a water box (no obi particle fluid)
thx a lot
br
David
Ps: if you have another idea how I could simulate non-obi water to affect your particle simulation I would be happy to hear it, hehe
Ah, ok!
Obi supports triggers, so you can create a trigger box collider and the solver OnCollision event will return all contacts with the box each frame (i.e. all particles inside the box). Then you can just modify their velocities as you see fit. See:
http://obi.virtualmethodstudio.com/tutor...sions.html
Hint: for underwater obi rope/cloth, setting the solver's "velocity damping" to 0.7-0.9 can be very effective. Buoyancy however, you must implement that yourself as described above.
Posts: 5
Threads: 2
Joined: Jun 2017
Reputation:
0
Obi Owner:
21-06-2017, 09:19 PM
(This post was last modified: 21-06-2017, 09:23 PM by davidrousal.)
for reference if anyone needs similar behaviour
Code: public class ObiWaterBox : MonoBehaviour
{
public ObiSolver Solver;
private Collider mCollider;
private int mColliderIndex;
void Awake()
{
mCollider = GetComponent<Collider>();
for (int i = 0; i < Solver.colliderGroup.colliders.Count; ++i)
{
if (Solver.colliderGroup.colliders[i] == mCollider)
{
mColliderIndex = i;
break;
}
}
}
void OnEnable()
{
Solver.OnCollision += ObiCollision;
}
void OnDisable()
{
Solver.OnCollision -= ObiCollision;
}
void Start()
{
}
void ObiCollision(object sender, ObiSolver.ObiCollisionEventArgs eventArguments)
{
float damping = 10.0f;
float force = 20.0f;
Vector4 upForce = new Vector4(0.0f, force, 0.0f, 1.0f);
Vector4[] velocities = {new Vector4()};
foreach (Oni.Contact contact in eventArguments.contacts)
{
if(contact.other!=mColliderIndex)continue; //skip other collision
Oni.GetParticleVelocities(Solver.OniSolver, velocities, 1, contact.particle);
//force up
velocities[0] += Time.deltaTime * upForce;
//damping
velocities[0] -= Time.deltaTime * damping * velocities[0];
Oni.SetParticleVelocities(Solver.OniSolver, velocities, 1, contact.particle);
}
}
void Update()
{
}
}
Ps:
would be great if OBI API had methods like external force add to provide a list of particle indicies, would be less dll calls
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
22-06-2017, 12:13 PM
(This post was last modified: 23-06-2017, 03:12 PM by virtualmethod.
Edit Reason: eliminado el quote
)
Thanks a lot for the code, David!
There's already a couple methods in the API that do what you ask, but they're still undocumented (for some reason we write code faster than we write docs ):
Code: AddParticleExternalForces(solver, forces, particle_indices, num);
AddParticleExternalForce(solver, force, particle_indices, num);
The first method takes an array of forces and an array of particle indices. It applies forces[i] to particle_indices[i].
The second variation applies the same force to all particles in the array.
Posts: 5
Threads: 2
Joined: Jun 2017
Reputation:
0
Obi Owner:
can AddParticleExternalForces be called in ObiCollision? Because if I "replace" SetParticleVelocities with it the particles doesnt seem to be affected.
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
23-06-2017, 08:21 AM
(This post was last modified: 23-06-2017, 08:35 AM by josemendez.)
(23-06-2017, 06:08 AM)davidrousal Wrote: can AddParticleExternalForces be called in ObiCollision? Because if I "replace" SetParticleVelocities with it the particles doesnt seem to be affected.
OnCollision is called at the end of each frame, just before forces are reset. You should wait for the beginning of the next frame before applying forces using these methods, since external forces are applied at the beginning of the timestep.
Edit: the reason for this "deferred" application of forces is that they are applied in a special way for fluid and cloth particles, so they cannot be immediately added to velocities.
Also, keep in mind that your code applies accelerations, not forces. Depending on your particle masses, the same force can have greater or lesser effect than an acceleration.
|