PySwarm Wiki
Advertisement

PySwarm's Engine[]

The “engine” behind the PySwarm for Carrara’s Python script is the set of rules that defines the behavior of the BOIDs, and thus the group at large. You can think of these rules as descriptions (or prescriptions) for how each BOID responds to and interacts with its environment, which is determined primarily by what the other BOIDs in the scene are doing at that time. These rules are applied to each and every BOID at specific time intervals. From this description, you will notice that groups are leaderless, in that there is no one specific BOID who determines how the others will act. Each BOID is given equal power in determining the group’s future behavior. Thus, the behavior of the group, in essence, emerges from the collective responses of the BOIDs through continuous feedback. A good example of this is when PySwarm places the BOIDs you’ve create into a circle, all facing the same direction. When the simulation begins, you will notice the BOIDs seem to hesitate, as if not sure what to do. Yet, this behavior is often very brief (maybe 10 seconds or less), and then the group is off in one direction or another as if they had always meant to do so.

How It Works[]

So how does the script work? PySwarm’s processing sequence (coded in Python script) is as follows:

1. Initialize the PySwarm system of variables

2. For each keyframe (starting with the first keyframe selected for animation):

a. For each BOID in the group:

i. Calculate the BOID’s change in velocity based on the rules that are active

ii. Update the BOID's velocity by adding the change

iii. Update the BOID’s current position based on its new velocity

3. Advance to the next animation keyframe

4. Repeat steps 2 and 3 above until the end of the PySwarm selected sequence is reached.

After running the PySwarm script (which takes a few seconds unless you are using complex objects for BOIDs), PySwarm will have loaded a number of keyframes for each BOID. You can then use the animation scrubber to view the results right away, and if you’re satisfied with the results, go straight to rendering.

That’s it!

Advertisement