bFlocking
bFlocking - A custom written tool to generate artifical intelligence flocking in Maya 8.5+. Uses python
Example running in Maya
2D Flash version (refresh page to randomly regenerate the scene):
Download
Download the maya python script from the following location (currently v0.2.1):
http://www.flash-fx.net/3D/tools/bFlocking/bFlocking_0.2.1.zip
Older version(s) are here:
http://www.flash-fx.net/3D/tools/bFlocking/bFlocking_0.2.zip
http://www.flash-fx.net/3D/tools/bFlocking/bFlocking_0.1.zip
Download the early flash prototype code (Actionscript 2) from here: http://www.flash-fx.net/3D/tools/bFlocking/bflocking_flash_code.zip
Introduction
bFlocking is a tool to simulate basic flocking behaviours in Maya. It is based on the 'Boids' work of Craig Reynolds.
The first versions of bFlocking were originally written as a test in Flash using Actionscript 2. Some demo experiments can be seen at http://www.flash-fx.net/3D/tools/bFlocking/indexboids.php
Another example showing localised flocking, obstacle avoidance and boudaries can be seen at http://www.flash-fx.net/3D/masters/final_project/boids/rule123_revised7.swf
This version (currently 0.2.1) has been written in Python specifically for Maya 8.5+. A video demo of version 0.2.1 showing setup and usage can be seen here or a higher quality version downloaded from http://www.flash-fx.net/3D/tools/bFlocking/bFlocking_v0.2.1_demo.zip
An earlier version showing custom particle generation, older interface elements and switching between 2D and 3D modes can be seen here or a higher quality version downloaded from: http://www.flash-fx.net/3D/tools/bFlocking/bFlocking_v0.1_demo.zip
Setup
######### ## Setup - standard way ######### # Copy the file bFlocking.py to your current maya scripts folder # e.g, C:\Documents and Settings\username\My Documents\Maya\version\scripts # In the scripts folder there may or may not be a userSetup.py. If there is not then create it (using notepad) # and if there is then edit it with notepad and add in the following line (without the hash and spacing): # import bFlocking as fl # Now whenever you start Maya the bFlocking window will appear for you to use # Developing further: If you change any code then to reload the script just drop down the 'Coding' tab in the bFlocking window, # hit 'Delete Objects' and then 'Reload Script' ######## # Setup - command line ######## # in maya to import and execute the setup script, go to the python console and type the following commands: # import bFlocking as fl # fl.generateSim() # now run play from the movie playback commands # to reload the script after coding changes, in the python console run: # reload(fl)
Usage
Please read the readme file included with v0.2.1 for new information and instructions on usage. For v0.1 please read the information below.
For the basic flocking behaviour simply go with the default settings and click the 'New' button. This will create the necessary elements and when you click the 'Play' button or the standard Play movie button in Maya then boids will flock and move towards the locator object. If you increase the movie time (again in the usual maya interface) then you will be able to move the locator around and set keyframes so that the boids have a target that moves.
Time range Experimental. Allows you to either run the simulation 'off' independant on time (just keeps running) or 'on' whereby the simulation will generate the boids after the first frame and only run the simulation for the specified range.
Mode This sets the simulation in either 2D or 3D space. In 3D mode the alignment of boids is still not correct.
Flock type This sets either flocking (default) behaviour or swarming.
Obstacles This allows the user to generate spherical obstacles at random locations. When activated it displays obstacle parameters that can be changed.
Boundaries Experimental. This sets a boundary around the simulation so that the boids dont disappear over the horizon. Opens up the boundary area option if selected
Boid Parameters
This allows the setting of the number, spacing and radius of boids. Boid number and spacing should not exceed the allowable Min/Max XYZ setup area - if you exceed the allowable space then the script will show an error message in the script editor/bar.
Flocking - Strength of flocking attraction (lower value = greater attraction) and distance within which flocking occurs
Separation - Strength of repulsion between boids (lower value = greater repulsion) and distance within which separation occurs
Velocity - Strength of desire to match other boid velocities (lower value = greater desire) and distance whithin which velocity matching occurs
Locator - Strength of attraction of boids to the locator object (lower = greater attraction)
Obstacle Parameters
This allows the setting of the number, spacing and radius of obstacles. Obstacle number and spacing should not exceed the allowable Min/Max XYZ setup area - if you exceed the allowable space then the script will show an error message in the script editor/bar.
Avoidance - Strength of repulsion of obstacle (lower = greater repulsion) and distance within which the repulsion occurs
Coding Only for development of the boids system. If the script code is changed then click the 'Delete objects' button to remove all simulation objects and then click 'Reload Script' to reload the code and run the changes.
Run Simulation
'New' button creates a new simulation. If the Time range option is off (default) then the boids are created and displayed. If the Time range option is on then the script waits until the 'Start' Time range frame is reached before generating the boids.
'Reset' Resets the boids to their starting position
'Play' shortcut button to the standard Maya play button
'Stop' shortcut button to the standard Maya stop button
The only real thing to watch at present is that the various boid 'Strength' options are inverse to what you expect, i.e, a lower number is stronger and a higher number is weaker. Also if using boundaries and changing the boid speed you may find that they 'escape' ;o) Finally changing settings midway through a simulation and then continuing to run it (instead of creating a new one) will result in some wierd behaviour.
Help
Any problems or need any help just send feedback via the following page: Feeback
Versions
# 0.2.1 (05/09/2007) # - added new function to replace the geometry of the particles in a particle system. # - added new UI 'Replace Geometry' button and 2 textFields to display the selected particle system and geometry replacement model # 0.2 (05/09/2007) # - rewritten system to use Maya's Particle system. Means user can place particles with the particle tool and also # use Maya's own particle caching system # - rewritten separation rule # - removed strength option from separation UI section # - reordered UI strength options to reflect removal of separation strength # 0.1 (28/08/2007) # - added UI time range option. Allows simulation to be run between a time range or to run continuously # - added UI option to switch between flocking and swarming behaviours # - added UI option to enable/disable auto obstacle generation (hides obstacle options if disabled) # - modified generateSim() function to build the expresion used as well as update the UI parameters on execution # - renamed 'Run' button to 'Play' to reflect removal of runAll() function # - removed all globally accessed variables (all are now internal to the main class) # - removed runAll() function # 0.0.5 (24/08/2007) # - rewritten bFlocking functions as a class # - added keyable locator to direct boid movement # - added attributes and function to reset starting position of objects in a simulation # - added control to see if there is sufficient area to generate the specified boids and spacing # - added in rotation to boids (2D - still some problems with 3D) # - modified UI button controls to use 'New' (generate new objects), 'Reset' (resets original object positions), 'Run' and 'Stop' # - fixed bug whereby the averageFlocking function always caused flocking regardless of the distance parameter # 0.0.4 - added full set of usable configuration options in frames to UI including global, boid and obstacle parameters # 0.0.3 - added new boid rules, avoidObstacles, boundPosition and tendToPlace # 0.0.2 - added objectParams class to enclose boid and obstacle config variables # - restructured the expressions into a single looping call (more efficient) # - added UI window to run simulation, alter boid values and reload the module after code changes # 0.0.1 (07/2007 and 08/2007) # - Basic system created utilising 3 basic boids rules, averageFlock, boidSeparate and matchVelocity (based on initial flash tests) # - added basic vector class as well as the extra controls limitVelocity and makeMovement)
Todo
# - add UI controls to turn on and off the flocking behaviours as and when needed (keyframed) # - add option to set initial starting velocity of boids # - on obstacle selection (when the new system is in) it will need to try and calculate the radius and store it as a parameter # - add behaviour for predator/prey # - finish orienting boids in the y axis (only properly works in the xz axis) # - option to save current config values (xml?) # - option to choose/replace boids with custom models # - option to choose/replace obstacles with custom models # - link and unlink values of certain parameters, e.g, if avoidance strength is doubled then so is separation strength # - make all global influencing variables (flocking, separation, velocity etc) keyable and stored int he particle parrent object # - option to attach 2D simulation to a geometric surface # - add angle check so that boids only react to in-range boids that are in a certain visible arc # - condense 'longhand' code into shorthand flags (originally used longhand for ease of reading)
Copyright
© 2007
Simon Mann
http://www.flash-fx.net
Free to use and modify. Please leave my details in the script so that people can contact me and ask questions if needed. Cheers :o)


