[Addon] Particle mesh/hair driver "P-mh driver" (v0.3.1)

Hi,

I love the Molecular addon, it is the simulation system Blender was missing. But it lacks a way to drive meshes and hair particles with, which makes it not so useful for many people, which like me, want to render the simulations in an actual animation or something… So I decided to take on the task of making that possible!

Here is a simple cloth sim I made with Molecular, and drove the mesh with P-mh driver:

Here is a simple rigid body sim I made with Molecular, and drove the object with P-mh driver:

Currently P-mh driver can only make vertices follow particles at exactly the same position, or make objects follow solid groups of particles, so it can be used for cloth/surface and rigid body sim, but not yet for hair or soft body (I am working on it…). This addon makes a mesh follow the movement of a particle system. It is not a mesher, meaning it does not generate a mesh around the particles. We already have several options for meshers, which are very useful for fluids, but not for clothes, hair, etc.

To use P-mh driver, you can manually set up a cloth or rigid body particle simulation, or press the “Create Particle Cloth”/“Create Particle Rigid Body” button in the “P-mh driver” panel, which will create a particle system already set up for cloth/rigid body sim. Then you can tweak your simulation and bake it. And at last, for cloth sim you can set a custom directory for the bake file (if you don’t, it will save the bake file in the same directory as your .blend file, if your .blend file is not saved, it will save the bake file in your “User” folder), and finally, just press the “Bake Cloth”/“Bake Rigid Body” button, also in the “P-mh driver” panel.
During the baking process, Blender will freeze, but you can track the bake progress in the System Console (don’t forget to open it before you start baking).
P-mh driver uses the “Export Pointcache Format” addon (Included in Blender) for cloth sim, to generate a point cache (.pc2) file. The .pc2 file will have the name of the baked mesh.

And finally here is the Addon itself (compatible with Blender 2.71):

P-mh driver v0.3.1

Here is a feature list (YES=Already working, NO=Is not working yet, WIP=What I am currently working on):

-Drive a cloth mesh = YES
-Compensate for misplaced particles = YES
-Drive a rigid body mesh = YES
-Auto set up particle cloth sim = YES
-Auto set up particle rigid body sim = YES
-Cache/bake = YES
-User interface = YES
-Drive hair = WIP
-Generate particles from hair = WIP
-Drive meshes with rips = NO
-Deform a pre-modeled cloth mesh = NO
-Drive a soft body mesh = NO

Thanks to Nghia Ho for his great article on: Finding optimal rotation and translation between corresponding 3D points

Please comment, suggest features, report bugs, etc.

I hope you like it!

Luca Rood

Changelog:
v0.1 2014-07-06
-Mesh vertices follow particles. (cloth/surface)
-Drive vertices with missing particles (loose vertices).

v0.2 2014-07-23
-Auto set up particle cloth sim.
-Bake mesh movement to file.
-Optimized calculation and playback method.
-Local/World space conversion.
-UI.

v0.3 2014-07-30
-Object follow particle groups. (rigid body)
-Auto set up particle rigid body sim.

v0.3.1 2014-09-20
-Particle size calculation error fix.
-Minor interface bug fix.
-Switched particle search method to kd-tree. (performance improvement)

–Start of technical explanation–

Cloth: The addon looks for vertices and particles at the same position using a kd-tree search, and adds them to a correspondence list. It adds a “frame_change” handler, for a function that will set each vertex’s position to the position of its corresponding particle (if a vertex has no corresponding particle it sets it’s position to the average of the adjacent particles). Then it calls the “Export Pointcache Format” addon, which will save the mesh position on each frame to a .pc2 file. And finally it adds a “Mesh Cache” modifier to the mesh, pointing at the generated .pc2 file.

Rigid Body: The addon parents the object to an empty. Then uses the Kabsch algorithm to generate a rotation matrix, and applies it to that empty, it sets the empty’s location to the average of the particle cloud. Finally it adds a locrot keyframe to the empty. It repeats that process for each frame.

Very cool! I look forward to the hair integration.

Thanks.

Thanks Davids I appreciate your interest!
Hair and Solid body capabilities are next on the “ToDo” list. I have both those items figured out, I just have to write the code. I’ll probably add the solid body capability in the next version (v0.3), and the hair right after that!

I just released P-mh driver v0.2! I hit some bumps in the road, so this release is a bit later than I was planing, but at the end it all panned out.
In this release, I turned the script into an addon, and added the UI. I also added a button that automatically sets up a particle system ready for cloth simulation.
You no longer have to apply the object’s transformations, as the new version converts between world and local space.

But the real improvement is the baking system! This new version, uses the “Export Pointcache Format” addon (Included in Blender) to create a .pc2 file, containing the baked mesh movement. And uses a “Mesh Cache” modifier to deform the mesh accordingly. What is so great about this? The performance improvement! (and of coarse that now you can store your mesh movement.) In v0.1, I used a function that was called on every frame change and set the mesh position. I was able to run a 15625 verts mesh at 8.5 fps average, with the new system, I run the same mesh at full 24 fps. There is also a minor improvement in the correspondence calculation, averaging 5 runs on the 15625 verts mesh, I got an improvement, from 1.94 seconds to 1.66 seconds. That improvement will of coarse be more noticeable on larger meshes.

Please comment, suggest features, report bugs, etc.

I hope you all like my addon!

Luca Rood

should we try and do a tutorial where you use this “in production”, let’s say i make a character do a walkcycle and we put a skirt or a shirt on him to see how it works and teach the rest of the world how useful it’d be and how to actually make it work?

I’d be glad to help you out with that :smiley:

@electronicpulse: First of all, thanks for your interest! Now, about the “in production” thing, I actually started working on this addon, because of a short animation I am currently writing. The main character is a girl (with long hair), and I am really not satisfied with Blender’s current hair simulator (the cloth simulator doesn’t bother me too much…), that’s why I decided to make an addon to transfer Molecular simulations to those things. So I guess I was already planning this addon with an “in production” focus in mind. That being said, I’ll probably take a long time to make the actual short.

In the mean time I am planning to make a full demo/tutorial, as soon as I have more features integrated in the addon, as it doesn’t do much yet (and the interface is prone to change a lot, turning a tutorial more confusing than helpful)… I am currently integrating a system to transfer rigid body Molecular simulations to object motion. As unlike blender’s standard rigid bodies, particle rigid bodies add the ability for them to be affected by other particle simulations, like fluids for example. After that, I’ll finally be integrating the hair capability! That, I guess, would be the right moment to make said demo/tutorial.

Btw, I took a look at your work, great stuff, specially the characters’ motion and expression!!!

If you want to help with the demo, it would be great. But I’d like to do it already with the added features. Let’s keep in touch!

@Luca Rood nice addon! I like the idea to use molecular simulations. I think it’s will be good, when you make short video tutorial(how it’s works)

this is quite amazing, might be worth an email to the gooseberry team - the hair and cloth sims are a big target for the project. It would be great if they could implement a particle based approach like this, making integrated physics finally possible in blender.

@floo, thanks! I’m just finishing the rigid body system, so I’ll probably be releasing v0.3 tomorrow, then I’ll start working on the hair code. After that I can make the tutorial. So it won’t take too long!

@russcript, thanks for your interest! I would love to see Molecular integrated in Blender, I don’t know if pyroevil (Molecular creator) has submitted Molecular for Blender integration, for now you have to download it separately. But if/when Molecular is integrated in Blender, I’ll be submitting my addon for integration, as it makes no sense to integrate my addon in Blender without having Molecular integrated.

@lucarood thanks, and well whenever you need my help, just PM me and we’ll talk!

cheers

Hi blender people :wink:

I just released P-mh driver v0.3!
This version adds the rigid body capability!
Now, the greatest feature will finally be available in the next version (v0.4), Hair capability!

Please comment, suggest features, report bugs, etc.

I hope you like it!

Luca Rood

Question, how does this compare to the cloth simulation, in terms of performance?
Which is faster, P-mh or cloth sim?
What are the advantages/disadvantages of the standard method versus this molecular driven method (assuming all planned features were implemented)?

Same questions for softbody aswell.

Thank you.

@Auuman Anubis, First I would like to make it clear that the simulation itself is not made by P-mh driver! The simulation is made with the Molecular addon. P-mh driver only transfers the motion from the simulation to the mesh (and soon hair too).

Now performance wise, that depends on the settings on the Molecular simulation vs the settings on the standard cloth/soft body simulation (you can’t really compare the speeds…). Though the Molecular + P-mh method adds an extra step: you have to make the particle simulation, and then apply it to the mesh, while the standard cloth is a one step process. But most time will be consumed by Molecular, then the P-mh part should be pretty quick.

Now about the advantages, in just a cloth simulation, there won’t be a big difference, other than slightly more realistic simulation, and better collisions (also, Molecular can rip clothes, but that will not be supported by P-mh any time soon). The real difference comes in the hair simulation and mixed simulations. The hair simulation will be much more realistic than the rather poor hair simulation system currently in Blender, and it will also add collision capabilities to the hair. Now the greatest advantage of using particles to simulate everything (Cloth, Soft Body, Rigid Body, Hair, Fluids, etc.), is that those simulations can interact with each other. So for example, you can drop a cloth in water, and they will interact realistically!

Now, the only disadvantage I can think of is the difficulty, it is somewhat harder to set up a Molecular + P-mh simulation, than a standard simulation in Blender.

Thanks for the reply :slight_smile:

I’m really looking forward to this, so to get an accurate comparison, I should simply us the Molecular simulation with point density equal to vertex density on a cloth simulation (with collision and self collision enabled) to get a benchmark on performance.

I’ve found blenders cloth sim to be too slow for my work, and it would be great to get more accurate effects processed faster. :slight_smile:

@Auuman Anubis, Thanks for the interest :slight_smile:

But, it is a little more complex than that to benchmark the methods. You have to take in consideration that both methods have settings that greatly affect simulation time, such as “quality steps”, “collision quality” and “self-collision quality” for the standard cloth, and “search length”, “max links” and “substeps” for the particle cloth. So a speed comparison would be very subjective. Though I wouldn’t put my money in the particle method if my main goal was speed. :
The goal for this method, is high quality simulation, and integrated physics. Though according to pyroevil’s website, one of the things on his to do list, is to multi-thread more of his code, which should make simulation quicker. And as I said on my previous post, the P-mh part is pretty quick, the actual Molecular simulation is what takes the time…

Just to get an idea, generally, what is the vertex count of the meshes you usually simulate?

4k to 6k cloaks and capes. I use so many polys because my characters use thin cloth (like cotton or silk) which require a lot of polys to capture enough folds to be convincing.

Well, the demo on my first post, has over 15k verts. The Molecular sim took a bit over 4 min, and the P-mh bake took about 15 sec, so everything is still under 5 min (120 frames btw). I know that accounts for just 5 sec at 24 fps, but still, if your meshes are only 4-6k it should be practical… And also, while simulating, Molecular is using only about 20% of my CPU, so I can still easily work on other things in the meantime. You should try it out by yourself, to see if this method is suited for you.

Good luck! :wink:

I hope to get some feedback soon! :slight_smile:

I don’t know how to compile a 64bit version of numpy (I’ve never compiled anything before) :lol

My OS, blender, and python are all x64 (-_-)
Not sure when I’ll be able to test this :confused:

@Auuman Anubis: I have a few things to say:

-Numpy is only needed if you are using the rigid body feature. The cloth/surface doesn not depend on numpy.
-You don’t need 64bit numpy just because you OS is 64bit. My OS is also x64, but I hate compiling things, so I use 32bit numpy. Though 32bit numpy will not work on 64bit blender, so you will have to install 32bit blender as well.
-I am working on including the numpy function used by the addon in its code, so future versions of P-mh driver may not need numpy anymore.

Good luck!

Hi everyone,

I just added a rigid body demo!

And also I wanted to say that project Gooseberry has demonstrated their new hair collision system about two weeks ago. But I will still make the particle/hair integration, and continue working on this addon, as it will add integrated physics capability to blender. Blender is moving more and more towards Bullet, so integrated physics is getting closer, but I really believe in particle physics systems, so that does not affect P-mh driver’s development!

Luca Rood

I’ve seen the Gooseberry hair collision system, it didn’t look as accurate as P-mh driver.