# Fluid like motion in 3d space on the cheap?

Hey,

I am looking for advice on the best approach to have something like 3d Fluid or wind like turbulence effect on particles, think like in a wind tunnel, or a human body inside a storm, with objects in 3d space being taken into account in the sim ideally (I could do this bit with collisions in 3d space on the particles, ignoring the fluid).

What I tried so far is to have a 3d particles system and then use MSAFluid addon to add forces and obstacles to the particles on the XY plane. It works well in 2D but in a 3d space it doesnt work quite as well as all the particles start to be aligned behind each other in 3d space. See attached screenshot:
http://dl.dropbox.com/u/40737/Screen%20Shot%202012-03-11%20at%2011.30.01.png

I wonder how I could fake the 3d dimension on top of the MSAFluid in some way. Maybe have a second instance of the fluid for the third dimension? Or have a bit of perlin noise to make the particles move randomly on the z axis. Problem with the perlin approach might be that it would not respect what happens in the MSAFluid in terms of obstacles and different forces being applied to the fluid etc.

The solution I am looking for hopefully doesnt require a 3d solver but ideally I can somhow fake the effect, I really just need them to move a bit more naturally on the Z-axis.

Thanks for all suggestions!

I’ve never used msafluid, but maybe you can get something out of this general line of thought…

I don’t know if msafluid is particle based or texture based, but either way you may be able to make this concept work for you.

Supposing that it’s some kind of navier stokes type simulation, and velocity vectors being generated, you can experiment with mixing the x/y velocity vectors into the z vector. When there’s a surge, the particles will bulge out in both directions z. You can also try adding some kind of z gravity force into a loop, maybe with collision detection, after the main fluid sim goes down. Again, sorry if it’s totally n/a with msafluid, but I’ve done that with openCL to good result.

Also, you might want to look at some cl n-body type particle code, because incorporating some of that logic/looking at it, might give you some ideas about how to extend it in a way that can still be realtime.

I know you didnt want a 3d solution but there are a couple of bullet physics addons available http://ofxaddons.com/#physics

Hey Guys,

Thanks a lot for the advice! @gtoledo3 that surge idea could work, just wondering how would you best determine the surge. MSA fluid works pretty much like you thought, you get velocities vectors from a x,y coordinate back. So to do the ‘surge’ I would add up the x and y velocity, look how big that value is and use to change the direction of the particle into -Z or +Z? Could you explain it a bit more if you don’t mind, my 3d math is not very good, i.e. I dont know how to change the direction of a particle along a direction vector for example.

Doesn’t need to be proper code if you just give a bit more of an idea what the surge function could look like I’ll be able to figure it out.

Thanks,
Thomas

So, supposing somewhere in the “life” phase of a particle engine, there’s velocity values for x and y vectors, on the return phase, you can try something like:

dst_ver[tid] = (float4)(pos.x * 2 - 1, pos.y * 2 - 1, 0+((fluid_vel.x+fluid_vel.y)*amplitude),1)

Where amplitude is the intensity of the z force effect caused by assumed “fluid_vel” x and y vectors. Which would be the velocities from the particle system “as is” or after being run through some other kind of noise or whatever. You can’t really use pos.x or pos.y for anything to offset z in a directly useful way, that I know of; it’s some kind of velocity info from x and y that corresponds to the movement of the particles directly that needs to be added into the z lane.

If you try to add the velocities during the life phase of the particle, if the return for z is 0, it will probably stop the particles from actually moving on the z axis. If the velocity is added to the z vector during the return phase of a loop, it will usually make the particle blast out in z in both directions.