Fluid particles to mesh - python script

http://www.pasteall.org/pic/show.php?id=30519

this is a very “beta” script and it´s made for a very specific project and it has a lot of room for improvement,

the script is divided in three parts, the first one creates a sequence of meshes from the particles. and the second one tells the selected object that on every frame change, use the corespondent baked mesh, the third one is just a tool to change some attrib on every mesh

first part:
from start_frame to end_frame:
->creates a meta ball
->tell the some Particle system to draw the Meta ball
->convert the metaball to a mesh, and save it as a fake user

second part:
on every frame change:
->object = selected.object
->object.mesh = “Baked Mesh” + current_frame

third part:
if you didn´t like the result you can use the “reset.py” script to make the meshes not use a fake user, them save the .blend file and open it again. You use this code to change the material o

here´s a video of the result:
https://vimeo.com/40721951

some thoughts:

  • The script works best with fast moving particles…
  • It´s a little bit confusing at first…
  • maybe saving the meshes as an external file is better? i don´t know…
  • Remember to toggle console to see in what frame the script is running, if there are a lot of particles things can get pretty slow
  • Use a smooth modifier to make the fluid better looking
  • There is a command at line X in the MakeMeshes.py that scales the metaball, you can change that if it better suits your needs, but a rather small number you make a mesh with no vertices

I tried to upload the blend file, but that is taking a long time, so here are the scripts:

MakeMesh.py - Bakes the surface and makes the frame change operator (see part two)
http://www.pasteall.org/31080/python

AnimateMesh.py - makes the object mesh change every frame keep this one register so the mesh is animated on startup
http://www.pasteall.org/31081

DeleteMesh.py - makes every baked mesh not fake user, ypu can use this to change the material of every mesh also (just change the code)
http://www.pasteall.org/31082

could you make a video tutorial
I don’t know what Im doing wrong

ummm… I can do a video tutorial, but it´s going o take a while because I’m a little busy with commercial work,

but try this:
-> Toggle system console.
-> Make a particle system, name it ParticleSettings.001.
-> Make sure there is a material named Material in your scene, this one is going to be applied to every created mesh.
-> Create an mesh object (a cube, sphere, circle, does not matter what shape), make sure it´s the active object.
-> run the MakeMesh.py script.
-> press Alt+A to see the result
-> (optional) you can use a Smooth modifier to make the fluid look better.

tip1: at first, make a particle system with low particle emission (but try to keep them together), and a rather small animation start/end, just to make the baking processes faster
tip2: some times when you change the object layer, or re-opens the file the simulation doesn’t play, for that run the script AnimateMesh.py

tip3: if you want to start again, run DeleteMesh.py then save and re-open the file.

IMPORTANT: watch the console to see the baking process, a Cyclic dependency error is expected, but it isn’t a problem (I think, heheh), if you get any other error, please post it here =)

I hope this helps, I know the process is confusing but thats how I got it to make this work, maybe someone with more coding experience can help out =)

How well does it work with lots of particles?
(e.g. 3.000.000 or more?)

very impressive!

It’s not really fast and takes some time for 300 frames and 5k particles but it’s pretty good.
Too bad it only uses one core of my CPU.

And why does it create this big blob where the highlighted object was?

@Mitsuma: On my machine it works very well on a high particle count , the only thing that changes is baking time, that can go up to some hours, and I also have no idea on how to make the scipt use more processing power.
The “big blob” is the original metaball that is used as a draw object on the particle system. One way to overcome this, is to bake the particles far from the scene origin and mask it with another object (very hackish/stupid, i know).

@blenderificus: Thanks! I still got some issues like:
*the original metaball that is used as a “draw object” in the particle system and I have no Idea how to delete it after the metaball is converted to a mesh.
*making this more user friendly
*maybe the final baked mesh should be an external file like blender fluid system?
*I made this script basically for two reasons: you can´t use metaballs as draw objects in blender anymore (I think this was possible in 2.4…) and you can’t apply modifiers in metaball objects to make the mesh smoother

@Hperigo, still though, this is impressive. I hope to see this addon develop further. If you need more functionality in python that the current API allows, maybe a request to Campbell on the Blender Dev IRC channel would be worth your time

that look pertty neat(haven’t tried it yet), but the video looks cool
it would look neat with the material being a fire emission look like a fireball!

hey holyenigma74 & blenderificus, thanks for the good feedback! I’m getting a little bit more excited about this script!

blenderificus: I dont think that the blender python API needs more then it already has, it´s only a matter of me understanding it more =) maybe someone in the IRC (or here) chat can help me out with one or other technical difficulties =)

@bashi: oh I knew i had seen something like that before! but I didn´t remember what it was hehehe
about the “Generate a Point Cloud from the Particles and Parent-DupliVert the Metaballs”. The script does already does that, I think that the "draw object"in the particles system is a kind-of duplivert of the Mball object… so maybe generating a point cloud is an unnecessary step, unless it get rid of the original metaball when converting it to a mesh…

some thoughts:
->the system is fast because it´s using blender internal c++ stuff to generate the metaballs… and in the end you can use a Smooth modifier to make the mesh smoother (dãr), which is very fast and interective also, in the end the python stuff is only using a bunch of operators (mostly). But I´m glad it made you look in this subject again =), keep the ideas coming!
-> about the bug in the OSX, did you try to make the size of the particles bigger? so that the metaballs can touch each other? the probrem with that, is that it affects the simulation fluid simulation (not if you are using standard physics), another way to overcome this is to change the scale of the MBall at line 33 :wink:

Very interesting. I’ve been waiting forever for fluid meshing. Thanks for making this @Hperigo, I’ll check out the python script!

very interesting, how do you create the movement of the particles in your video?

thanks and good work (and sorry for the delay)