From CSclasswiki
Jump to: navigation, search


For this Special Studies, I will be working with Professor Joseph O'Rourke, helping him create animations which illustrate lessons for his computational geometry textbook, "How to Fold It".

The first goal for this project is to create an animation of the spinning chain linkages found within a paper spinner. A paper spinner is a specially folded and cut piece of paper which has many diamond-shaped cuts in the middle. It begins folded in half, but as the two halves are pulled apart, the series of diamonds spin around a center axis, creating a very cool effect.

Example of a spinner

I will also be animating one or more other videos for this textbook, as well as exploring Blender on my own.

Part I: Unfolding linkages in Pov-Ray


2/13: After a bit of a delay, this weekend I started to re-explore POV-Ray. A few days prior, we had attempted to export an image from Mathematica to POV-Ray by using Export[], which resulted in a list of hundreds of triangles, which came together to form the "tube" shape from Mathematica. This was not very nice looking, and such a long-list would be a huge hassle to do anything with.

This time, I implemented a method which Jo discovered when he created an image for a Fixed-angle 4-chain - creating a series of cylinders with spheres at their joints. This was an easy method to use but a bit tedious, having to copy-paste a series of coordinates into different parts of the code. I cleaned up my code after re-reading the 4-chain code, and declared the points as constants, rather than having them scattered everywhere. I was a bit confused about how the camera parameters worked, so I experimented with that for a while. The chain linkage looks fairly nice now.

2/20: I am investigating how to automate the process of generating frames in POV-Ray. It would be one thing if it were only using the ~25 frames shown in the Mathematica file, but for a smooth animation, it will be tedious or impossible.

First, the equation and its initial values need to be exported from Mathematica. This is a simple process using MM's "Export[]" function. These values will be exported into a text file.

There will be a Python script, which will parse the text file for the relevant information, and manipulate it to get it to unfold (probably based on some sort of time parameter). This script will create a large string, with commands which may look like "cylinder{x0,x1,x2,x3}" Once the new coordinates (i.e. x0, x1...) are generated, they will be filled in in the corresponding places in the text file. Searching around has confirmed that you can write directly into a .pov file with no problem. The question is how to format it (after the picture).


I am not exactly sure about using scripts to open programs - like how to actually run POV-Ray and get it to render an image. Currently I am reading about Python's subprocess capabilities. subprocesses

I also just found this explanation of a way to use Pov-Ray through Python, though I do not fully understand it yet: ActiveState - Povray for Python

In addition, I found some sort of a framework for using Python to write Pov_ray. pypov

I have not yet decided exactly how I will do this.

Writing a Script in Python

3/6: Rather than get into processes, I decided to focus just on getting Python to automatically generate a Pov-Ray file which could then be run by the user.

Originally, I succeeded in writing one frame automatically; to get all the frames, I had to figure out how to automatically create file names. That proved to be easy enough, just creating a list of strings, and substituting them for the filename.

First, I exported all the coordinates from the Mathematica file into a .txt file, by using Export["testV.txt", Vstore]. Next, I opened the txt file in Python and parsed it. I sort of used a hack - I copied all the data that remained constant into two files - begin.txt and end.txt. I wrote the contents of begin.txt to a string, then I created strings like "#define p" + i + (etc...)", which are the only places that are modified (with different coordinates for each frame). Finally, I concatenated the contents of end.txt to this string, and then output it to a .pov file, "experiment.pov". I was having some problems until I remembered to close files within Python after reading/writing them.

Next, I rewrote part of it to loop through all the filenames and create all the frames. This is working except in situations where there are scientific notation coordinates like "4.718447854656915*^-16" which is coming up in my frame14. Not sure how to fix this yet. Files are currently in my H drive, not uploaded anywhere yet.

Beautification & Pictures

3/20: Over break, I experimented with getting the camera angle correct, since the angle provided by Mathematica was extremely close up and strange. I got that working, so now I am focusing on "making it pretty" - fixing light/radiosity and adding textures and things. I have also added a plane for a bit of a background.

As a small note, I fixed the scientific notation problem from above - Pov-Ray uses the format "4.718447854656915e-16".

Example images from a few different frames (no anti-aliasing):

First, just the correct angle. Frame9.jpg

Some beautification. Frame15.jpg

After perfecting the details, I will edit my Python program to reflect said changes and make an animation of it, to make sure it all looks correct.

3/24: I fixed some further things with the lighting and camera angle, and then updated my Python program to reflect these details. In Python, I also cleaned up my code a bit, including using the "slice" function to eliminate some lines. I do not have an automated way to open each Pov-ray file and render its image, so I went through and rendered them myself. Next, I followed Katie's instructions for importing into iMovie (CSC400-Katie#iMovie) and created an animation, which can be found here:

The final result looks pretty good, if maybe a bit choppy and faded. One of the frames appears to be going through the floor, but when I pushed the ground plane further away, it looked the same. I think it is just very close. Also, a few of the frames seem out of order (I did switch two around in iMovie already), but I'm not sure why this is happening. I can't think of how my Python for each loop would get messed up - could it be a problem in the Mathematica file?

Better Automation & Exporting Frames to iMovie

3/29: On Prof. O'Rourke's request, I expanded my animation from 16 frames to 200. The way I had originally written my Python code was not completely automated - I had some hardcoded pov-ray code that was stored in a text file which I concatenated to a string I created in Python. I changed my code to accept as many coordinates as were generated from the Mathematica file and automatically write the corresponding Pov-ray code.

This wiki will not allow me to upload .zip files, even though it says I am allowed to. My Python program and the coordinates I used can be found here:

Then I generated my 200 Pov-ray files. I luckily discovered a "Queue" button on the program, which allows you to select all of your files and add them to a file queue. Pov-ray automatically goes through the queue and renders each one. This saved me a great deal of time. Next, I repeated my iMovie procedure from above, with 200 frames this time.

Notes on iMovie: Make sure when you create a new project, you set Project Properties to "Fit to Screen" rather than "Ken Burns." Once all your frames are added, you can double click on the first frame and change the display time to as short as 0.1 s. This was convenient because with the original 1s (lowest value I could find) the video would have taken forever.

Final product:

I am not 100% happy with the quality; I blame iMovie.

4/6: Because the m4v was getting messed up in YouTube, I have re-exported it in .mov format. It looks much nicer and now works with YouTube. Here it is:

Part II: Experimenting with Blender

Learning the Basics

Note: I found to be immensely helpful - all but one of my tutorials were from there. They have a wide range of topics, from beginner to advanced, on every aspect of Blender. There are many other links from, but I would highly recommend looking at BlenderCookie, and I plan to use their tutorials over the summer.

3/31: As I am currently in between animating things for Prof O'Rourke's textbook, I decided to explore Blender. I worked with Blender very briefly 2 years ago, so I pretty much have to start from scratch. Blender is a massive program, so I was a bit intimidated, but I consulted the Blender website, which has many, many links to tutorials. I am very excited by the possibilities (even silly stuff like tutorials on realistic-looking grass).

Anyway, after watching super basic tutorials on things like how the user interface, I followed this beginner tutorial to make a scene with a snowman. Here is my result:


The lighting is a bit dark, but it's my first try, so it's ok. Soon I would like to create a model of a figurine I have in my room, and then investigate animation.

More Modeling: Balloons and Dunny

4/5: I completed (most of) another tutorial, creating a bunch of balloons, found here. I did not realize until I had gotten a bit of the way in that it was an intermediate level tutorial, so the author was moving a bit quickly, and I could not follow some of the things he was explaining. Nevertheless, my balloons came out balloony.


4/20: I had been working on modelling a Dunny figurine in my room, shaped like the photo below, and had been planning on trying to animate him when I was done. However, when I met with Prof O'Rourke, he pointed out that I was running out of time and should pick either modelling or animating to pursue. I did a little more work on my figurine before abandoning him, but he is not perfect. For example, he is not perfectly smooth, and his right arm's faces seem to have disappeared.

(example photo)Dunnyex.jpg

(My model) Dunny.png

Basic Animation: Armatures and Rigs

Next, I searched out animation tutorials. The first couple which I tried to use, while they called themselves "basic introductions," assumed that I knew more than I did. Finally I found an excellent tutorial of super basic movement. Blender animation is composed of armatures, basically bones which you can connect and move how you wish. This tutorial taught me about basic movement (dragging), and two important principles: follow-through (an object will not stop moving immediately after it stops) and overlapping action (connected/looser pieces continue moving after an object stops).

This intro animation is just two bones, a main one and a hanging tip, which are dragged and then stop, but still swing a bit. Since my animation is only bones, with no actual substance around them, it can not be rendered. Here is a link to the animation tutorialand a screenshot of my armature in action.


My next planned step is to animate some sort of small figure. Even if I can not animate something amazing before the end of the semester, I definitely plan to work on this over the summer and see what interesting things I can create.

Animating With a Rig

5/6: I discovered that in addition to armatures, there is something else used in animation called a "rig." Some information on armatures and rigs can be found here in this documentation. As far as I understand, a rig is a set of armatures that is linked together, and controls the animation of a mesh. Since I am starting at the very basics of animation, I decided to follow a tutorial to create a bouncing ball rig. Halfway through the tutorial, I could not find something the instructor was talking about, and decided to check to see if a new version of Blender had been released. It turns out that at some point since I started, they upgraded to version 2.57 (from 2.4-something). It is much, much nicer, and now I know why I kept getting lost in the tutorials.

Here is an example of new Blender interface, with animation-editing windows, and the ball's rig.


Here is the set of armatures themselves, around the ball.


As you can see, they just look like rectangles, but can also be shaped like the armatures I used for my hanging-chain tutorial above, or just sticks, or sort of rounded. Their size can be altered just like any other shape, and the way you connect them to each other and to actual meshes determines how the mesh is altered when you drag the armatures.

So, once that was all set up and I finished animating, I added basic smoothing, color, and lighting, and rendered it. I am working on duplicating keyframes (each new pose in the animation) so that my video bounces more than once, but I am having problems with them all staying together.

Ballframe.PNG Animation of bouncy ball!

Animating a Snowman

5/8: I decided to put my bouncy-ball stretching skills to use, and what could be more appropriate for my first animation than my first model? I decided to try and get my snowman to bounce around. My first try turned out pretty amusingly, with the exception of one problem: somehow, the tip vertex of the nose decided not to come along with the rest of the model as it moved, instead staying locked to a single point. I am not sure if this happened when I set up my armatures, or if somehow it just did not get included when I joined the snowman mesh together.

Example of nose-stretch: SnowOuttake.PNG

I added the trees and ground back in, and created a little video, which can be found here: Snowman (Blooper)

I am currently working on fixing the nose-situation.

Edit: The nose-situation has been resolved. I first tried just redoing the armature from scratch, and that didn't work, and I tried reselecting the snowman, that didn't work. Frustrated, I just built a new snowman from scratch. Even that didn't help! The nose finally started cooperating when I shrank it a bit. There must be something different about vertices which go past the main object. I think the actual "squishing" was cuter in the first video, but the nose was a pretty big problem.

One nice thing about having to redo this video (besides practice) was that I had time to pay closer attention to what all of my armatures were doing, and I changed some a bit. For example, I rotated some of them (especially the bottom), which seems to have gotten rid of the snowman's wrinkling.

Final, no-nose-stretching video: Snowman: Final Cut