The WORM

A Path Following Procedural Animation System for Blender, Using Python
Click here to download Worm Zip format, 98k
There are a number of objects and creatures, in the world , which propel themselves by the relative motion between different parts of their bodies. This project got started, as a result of trying to model an animated worm in Blender. A worm expands the rear of it's body, while extending out the front. Once extended, the worm expands it's front segments and then relaxes and pulls in it's rear.
![]() |
![]() |
Two strings of Empties animated with Worm |
The rendered child objects |
With Blender, we can do this by creating a string of objects, as segments, and then linking the segments together into something complete.The animation, on ONE dimension, may then be achieved by creating IPOs for each segment, into a animation cycle representing a complete 'creep' or 'crawl'.
This animation cycle will be a lot of work, in itself. I have never seen a worm crawl in a perfectly straight line, and would want my worm to go to unusual places. Well, if you don't have a C-key, you are in trouble. You will need to animate the worm, and each of it's segments, along your desired path for the entire trip. You could try parenting the worm to a path, and drag it along, but it's travel will all be relative to the path position, and will not be able to bend, turn, slither and slide along according to it's own form of locomotion.
The Worm Path Animator will allow any object or objects to follow user defined paths, under their 'own power'. This could be for a group of related objects, following a single path, or a number of unrelated objects following different paths.
![]() |
Worm requires the use of three
files, external to Blender. Two are created, by you, in a
simple text editor, and the third is created by the Worm
script. A function selector allows you to either Record path animations, or render a scene, with the Follow Parent option. A Frames slider defines the number of frames to record a moving 'Parent', or the number of frames to force 'Children' to follow a 'Parent'. 'Reset' returns the 'children' to their starting position. You can also use the 'escape' key, with the mouse over the script/gui window. |
Worm uses the Python libraries 'array', 'string', and 'math'. You will probably need to install these in order to use Worm. Python 1.5 is available for free at http://www.python.org
The secret behind Worm, is that a 'child' object's position is measured against a 'parent' target. The distance and angle to the target is calculated, and then the 'child' object is allowed to travel towards the target, as far as is allowed by that particular frame of animation, as defined by a control object's LocX IPO curve. Think of a control object as the finger of a puppeteer controlling part of a marionette.
A quick note regarding my use of the terms 'child', and 'parent' here. This has NOTHING to do with Blender's CTRL-P type parenting. It is my unfortunate choice of terms to describe the relationship between a Worm object, which follows a path (child), and a Worm object, which is used to create a path (parent).
RECORDING A PATH
A 'path' can be any animated object, you wish other objects to follow. The examples in the .blend files were made by recording the positions of spheres, as they were dragged along a Blender curve path, but any moving object can be used. Once recorded, all the original parent objects can be deleted from the drawing, if you wish. The recorded 'RecFile' has saved all the postion information.
#1. Create the motion to follow.
Use any object that moves in any way.
#2. Create a Parent file.
Once you are satisfied with your 'parent' animation, open a simple text editor, and make a list of the 'parent' object names, which will be used to create motion paths. For example, if we used an object called 'Sphere.001', to move along a Curve Path we created, the entry in the parent file would be:
Sphere.001
If we had two objects, that we used to create two different paths, 'Sphere', and 'Sphere.001', our parent file list would read:
Sphere
Sphere.001
It is important to remember to use a 'newline' character (use 'Enter' , carriage return, or whatever you call it) to inform the Worm system of the proper separation between names. This INCLUDES at least one 'newline' at the end of the list. Don't worry too much about extra newlines, Tab keys or extra leading or trailing spaces. I have tried to filter out most of the common stuff. Name this file something you can remember, like 'parent.txt'.}}
#3. Load the Parent file, and name the RecFile
Load 'worm.py' into a text window in Blender. Start the script (Alt p in the text window). The user interface should then appear. Press the file bar labelled 'ParentFile', and enter the file path and name of your parent file. You can also modify line 18 of the script, to be more suitable for your own system.
Press the file bar labelled 'RecFile', and enter the path and desired name for the binary animation file to be produced by Worm. You may also modify line 17 to suit your system. WARNING An existing file of the same name will be overwritten, without asking. Use different names for the 'RecFile', or move them away, if you do not wish your recording files to be overwritten.
#4. Set the Menu option and Frames slider
Press the menu button, first labelled 'Function is Idle' and select 'Record Paths'. Set the 'Frames' slider for the number of frames you wish to record. Worm will warn you if the Parent file cannot be found, or if it sees something wrong. If you wish to change the maximum number of frames allowed by the slider, modify the script at line 32.
YOU MUST HAVE ONE OBJECT IN THE DRAWING LINKED TO THE SCRIPT.
![]()
Select an object
and press the script button
. Press 'New' and enter the name of the script,
'worm.py' where indicated above.
#5. Record the animation
Hit 'Alt a', in the 3d window. You animation will now be recorded. Make sure that you have set the total number of frames for Blender animation larger than the number set by the frames slider. Worm has only been tested with animations beginning at frame 1. Don't try using Worm, starting somewhere else. The binary animation file will be written to disk once the Blender animation has exceeded the frame count set in the slider. With the mouse over the Worm window, press the 'escape' key, and the model will reset.
Creating a 'Child' Animation
#1. Create the 'child' animation
Worm uses control objects to direct the individual character and motion of the 'child' objects. Blender doesn't like having it's IPO curves over written, and in many ways, just ignores a Python script trying to do something other than what an IPO curve instructs. What we do, is to create a set of control objects, which will have a one for one representation for the actual objects we wish to control.
The control object set could be a copy of the actual objects you wish to control. It would be wise to use empties, or linked mesh objects, in order to keep your file size down. Control objects are normally not rendered. On layer 11, in my example files, you can find the drawing's control objects.
Each control object is animated using a LocX ipo curve. If this sounds boring, remember that the recorded path will send this collection anywhere in 3d space. It is your control objects, and their LocX ipo curves, which describe the complex, interaction between the child objects. Take a look at the example files if you need a better understanding of this.
Last warning about child and control objects. It's ok to build and animate the child model, to get things right. Once done, copy everything you are using for the LocX animation, as your control set. Then delete the animation on the objects you will use as children.
Worm moves the children by changing dLoc values. Blender 1.x requires that some kind of Loc IPO curve exists, before dLoc values will work. Therefore you must still have at least a LocX IPO curve for each child object. After deleting any existing control animation from the children, place them at their starting positions in the drawing, select all children and (i key) insert a Loc IPO at frame 1. This will create a static curve for each child, and the dLoc changes, made by Worm, can then move the children. You could then delete the LocY, and LocZ curves, to limit the file size a bit.
#2. Create the Child/Parent File
Using the same general rules, as with the Parent file, create a text file in the following format:
Child_objectname, Parent_objectname, Control_objectname
| Child_objectname | The name of a child object |
| Parent_objectname | The name of the parent, which created the path for this child to follow |
| Control_objectname | The name of the object, whose LocX animation will control the progress of this child along the path |
Of course, one such line is needed for each child object in the drawing.
The comma (,) character is needed to separate the object names, within a line. The carrage return (newline) character is needed to end each line, and there must be at least one blank line at the end of the file. Save the file, with a useful name when you are finished.
#3. Final Drawing Setup
Present the child objects to the proper attitude and position that you wish them to enter the curve. This could be anywhere, but remember that all the child objects, for a given curve, will all pass through the first set of coordinates for the path. Placing the child objects sideways, and at the other end of the drawing, will cause them to drift towards the entry point, sideways.
Enter the file path and name for the Child/Parent file, you just created. Line 24 of the script is the place to change the default. Worm will warn you if there is something wrong with the file, or if it cannot find the children in the drawing.
Be sure that you have the correct RecFile entered into the middle file bar.
Set the frame slider to the number of frames you wish to render, and Blender's start frame at 1, and end frame to at least the slider value plus 1.
Press the menu button, and select 'Follow Parent'.
You are ready! Hit Alt a , for preview, or render the animation now in the usual way! The child objects will freeze when the frames slider value is exceeded. Remember that the reset button will return everything back to the frame 1 position, after you are ready.
| Now go listen to some strange old music | ![]() |