Py4D Examples – particle party

Py4D Examples - particle party

I haven´t written about Py4D for quite a while now…

In the meantime, Maxon has first announced a cooperation with – and now the acquisition of Sebastian Rath´s praised python implementation for Cinema4D.

So finally – Cinema4D meets Python!

Let´s celebrate with some cool experiments!


If you are new to this blog or Py4D – a short introduction:

Py4D enhances C4D with a standard Python interpreter that provides access to the C4D SDK and allows to easily code platform indepentent scripts and plugins that control or extend C4D.

Basicly the same as COFFEE, C4D´s own scripting language, but Py4D has two major advantages:

  • It follows the C++ SDK more closely and implements it further than COFFEE does.
  • It is a easy to pickup, widely known language with a huge community and tons of existing code and librarys.

While C4D is a mighty tool in itself, this powerful scripting interface enables the user to work with external data, automate processes or build his own tools.

Being more the C++ type when it comes to plugin development and C4D, I enjoy being able to solve small problems just by hacking a few lines of code into the script manager.
I also prototype most of my plugins in Py4D before I start developing in C++ – it´s just more convenient.
The step of compiling for every test takes much more time in the long run.

So here´s the meat:

Four simple examples how to have a good time with Py4D and some particles…

Everyone requires C4D R11.5, the Thinking Particles module and the actual version of Py4D.

Update: All files have been updated to work with the R12 version of Cinema 4D.

Py4D has been through some changes since the open beta started, so I took the time to update the scripts I published in the boids, and strange attractor posts and included them here.

Click the images for a preview.

1. Stars4Py4D

This is a Py4D port of the Sagan experiment I did in flash <- check out this link, it´s fun :)

A good and simple first step with particles - position vectors get parsed from a CVS database and from a galaxy of suns… “My God. It’s full of stars!”

Hint: this example might be the best to start with, as it includes comments – the others don´t, because they use pretty much the same pattern.

Just download the package, load the scene and change the path to the CSV file within the “file” user data field of the Py4D Tag.

2. Phy4D

A very simple adaptation of a 2D “physic engine” – works only with spheres.
The direction of gravitation is animated to make this a little more interesting.

Have a look at the preview video and scene file.

3. Boids

This is simply a revival of the Py4D Boids post – same beast, but updated to the Py4D release version.
The script creates a flocking boids swarm, that behaves according to the rules outlined by Craig Reynolds.

Checkout this video from Sebastian and get the scenefile.

4. Strange Attractor

Again just the script from the original strange attractor post, but ported to the final SDK.
View the final rendering and the original post – you can use the Strange Attractor Finder to locate your very own, chaotic attractor!

Here´s the scene file.

Conclusion

Python and Cinema4D are a great team and Py4D is THE alternative to COFFEE.

I hope this gives everybody who is interested in Py4D and controlling particles, a small head start, some inspiration or at least something fun to play with :)

Thanks to Sebastian for suggestions, support – and of course Py4D.

Cheers!

10 thoughts on “Py4D Examples – particle party”

  1. Pingback: Py4D Examples – particle party | C4D Blog - cinema 4D daily

  2. Giuliano

    Thank for sharing, i’m little confuse with the use of python in c4d, after 4 hours of excersices, i was able only to load a cube!
    but i don’t surrender!

  3. astrowhiz

    Love the website. Really great examples. I’m trying to use the particle party script for a project simulating star formation in a galaxy. I’m stuck on how to assign the created particles to seperate groups as I require two sets of particles. If you had any ideas that would be great :-)

    1. flashgordon Post Author

      Hi astrowhiz,

      that sounds pretty interesting, would love to see the result.

      If you take a look at the ‘TP_MasterSystem’ class from the ‘thinkingparticles’ module in the documentation, you will find ‘AllocParticleGroup()’ and ‘SetGroup(particle_ID, group)’.

      Hope that helps :)

  4. nux95

    Hi Sebastian, great thing there :)

    But I have another question: How did you render the Particles in the last example ?

    thanks in advance, nux

    1. flashgordon Post Author

      Thanks nux95, but actually I am Jan, Sebastian Rath is the hell of a chap behind the C4D python module :)

      I rendered the strange attractor example by blending four videos with a different seed, thus multiplying the amount of particles my system could manage – take a look at the linked post for more details.

  5. astrowhiz

    Hi,
    Thanks for the reply. I’ve been looking through the documentation all day and trying those commands but didn’t have any luck. There’s probably something in the syntax I’m screwing up cos I’ve just started using python with C4D. I was slightly confused by the commands & arguments in the docs. In your example you just used tp. etc, is tp defined as the master system? Anyway I ended up creating two scenes and used mograph to place polys on the particles, then baked all frames and merged the scenes together. Here’s the prelim video http://cid-a0eb6ea5c61306dc.photos.live.com/self.aspx/galaxy%20formation/Clouds.wmv

    The xyz positions were output from a Fortran program I’m writing which simulates galaxy formation.

    1. flashgordon Post Author

      That attractor looks really cool, I think I even saw some stars escaping the core and merging with one of the spiral arms again – sweet.

      And yes, you can just write “tp” to import that module.

      Cheers!

  6. nmpribeiro@gmail.com

    Hi flashgordon! Amazing work there with the galaxy
    I am studying it :)

    Would be great to make it spin and clump those stars into arms heh like that video from astrowhiz but I assume he went other way around it.

    Can we do something like… ‘if particle is near camera -> simulate a particle system like a sun with flares’ or else, just a glowing point of some color? :) heh

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre lang="" line="">