Showing posts with label Matlab. Show all posts
Showing posts with label Matlab. Show all posts

Saturday, June 4, 2011

Its a bird, it's a plane, it's... a tetropter (tetropters IV)

The nice thing about computer animation is that it allows you to actually see thing that you could only dimly imagine beforehand. One image that has been sitting in my mind for many years is the following: you see a dusty plain, and a herd of handlebars (Latifrons imperator) come galloping in from the right hand side of the image in the distance, and then wheel towards the viewer as if they were performing a well-rehearsed cavalry manoeuvre. I can almost hear them too...

Unfortunately I do not see anyone spending a small fortune to make this a reality, so I will have to content myself with what I can do myself, with my PC, at home. Some visions therefore remain locked in my head, but a few more modest ones do find their way out. Making tetropter flight visible is something I thought I worked on for quite some time; today I can show you a near-final result. Near final, because nothing creative is ever truly finished. In this case, the camera should move, the animals should vibrate in rhythm with the wing beats, there should be more details, there should be motion blur, and there absolutely has to be blurring to mimic a limited depth of field and through that create the illusion of small size.

Still, what I can show you is the principle of the thing. It's not a movie, but an illustration of wing movement in slow motion. Tetropters have been described several times on my blog. A summary of the tasks involved in animating them is found here, and entries on their design and wing movement patterns are here, here and here. In short, they are radial flying animals, whose four wings can do a 'double clap and fling', invented by yours truly, and later also by other people in the flying robot business. By the way, the movement of tetropter wings is not all that different from the complex way in which Earth insects move their wings.



This is an animated scheme to show how it all works: the wings are planes that are warped as they cycle through their movement cycle, so their shape is different depending on were they are. Where they are is governed by rotations along the x-, y- and z-axes, and all these paths can be altered and edited. The Matlab programs that do all this in the end write lots of 'obj' files: those are files describing 3D shapes; one is produced for each wing for each frame of the cycle (there are usually 120 frames in a cycle). A script written in Python then loads in a scene containing a body shape without wings in Vue Infinite, adds the appropriate wings per frame and stores the images. These are then used to form an animation, and those are what you see here.
The 3D shapes of the wings consist of 1600 small triangles, which is more than enough to show supple movement. As they are they do not look like wings at all, but there is another trick to take care of that.



The trick in question is to add transparency and colour. The transparency mainly makes unintersting parts invisible, but it is also useful to make the wing itself partly transparent as here. To create the fly-like animal above (Bombilator musca) I used an image of a real insect wing found on the internet, and used that to create a transparency mask. All of a sudden, the boring rectangular 'wings' produced by the Matlab program take on a biological appearance. Please do not look too closely at the body of the animal: it is a simple shape cobbled together in Vue. As you can see the animal has four legs and two sets of eyes: upper ones, presumably to scan for danger, and lower ones, near the food gathering end at the bottom.



A bit of colour makes a lot of difference, so here is a farfalloid, resembling a butterfly in overall appearance (Farfallapter caeruleus). Indeed, I stole its wings from a real Earth butterfly, albeit with some warping and editing. Mind you, quite a bit is lost in the conversion process.

Click to enlarge; copyright Gert van Dijk

To show that, here is a still of the Farfallapter; better, isn't it? Then again, you can see how crudely the wing is linked with the body...

I guess I now no longer have any excuse to put off work on the 'Flying with...' page. It is probably also time to redesign the site. I have already looked at that, but the days where you could learn HTML in two evenings seem to have gone for good.

Sunday, April 24, 2011

Three years on

More than once in the three years I have been writing this blog I thought there were no more interesting speculative biology projects to be found on the internet, but each time I was wrong. Will the supply dry up? Perhaps not: there are more and more exquisitely detailed Z-Brush monsters, but mostly those are orcs, dragons and the like. In other words: they are not very interesting from a biological point of view. The reverse situation can also be found: well-thought out projects with artwork that does not do it justice. I guess I will simply have to wait and see how much content I can find to fill the 'allied matters' component of the blog. The number of page views slowly went up over time, which is rewarding.

So how about the 'Furahan biology' component? There is progress, if you account for the glacier-like advance of a very large project that you do not really have time for. Then again, in the last three years I got to grips with InDesign, Photoshop, Painter and XBrush (not that I am proficient in any). The most noteworthy skill I am trying to acquire is digital painting, which is the most needed one. I think I need to do some 10 additional illustrations of the "It's a fish" type, and then I will have some 15 two-page spreads to show to potential publishers. An example of those can be found in the New Hades book shop on the Furaha site: got to the brand new 'Living World Series' and you will find the 'Encyclopaedia of Furahan Wildlife' (also shown here). I aim to use that lay-out to present the book to publishers.



Rough tetropter animation; copyright Gert van Dijk

It is not difficult to think up many new animals or plants; many forms that I have now could do with some adaptive radiation. But my interest is mostly aroused by more complex puzzles. As an example I will explain the struggle to produce a good tetropter flight animation. The basic principles have been outlined before (start here to work back in time), but for good measure I have repeated an old animation above. As you can see the animal is shown from below, and the four wings move to and fro while rotating. They also move through one another, because the animation uses stiff planes for the wings: it is not good enough. I want a better one firstly, because I am curious: I wish to see what a spotted farfalloid looks like, when its beating wing reveal electric blue surfaces at one point in their cling and flap cycle, and bright orange ones the next! The second reason is that I would like to paint a variety of tetropters -talk about infinite variety-, and getting the perspective right of four warped surfaces in complex motion can be done by hand, but would be easier to manipulate by computer. I will break the problem into pieces:



Problem 1: defining movement
The wings can easily be modelled as surfaces in Matlab. These move through the wing cycle, meaning there are different requisitions for movement around the x- y and z-axes. To control them I wrote editing programs, now nearly done. The surfaces cannot remain simple planes throughout the movement cycle, but will have to be bent and warped. The animation above shows where I am now, meaning at the phase where all the 'warp factors' have to be tweaked to get it right. What you see here represents 'untweaked warping' though!

Problem 2: exporting the wings
The 3D program I am most familiar with is Vue Infinite. I had already written a program to convert Matlab patches to obj. files, which helps. But I then stumbled upon a new program, ad that was the imported wings for successive frames did not end up at the same spot in the scene. Apparently Vue calculates the mean of all x-, y- and z-coordinates to calculate the centre of an object, and if the object changes shape so does it centre. Well, I can counter that by shifting the object each frame to compensate. This needs work...

Click to enlarge; copyright Gert van Dijk

Problem 3: texturing the wings
Obviously, the wings will need interesting patterns on them as well as partial transparency. That, as well as bump maps, proved to be in the obj. definition and could be manipulated.
Here is a rough example of a warped wing with transparency and all in Vue.


So now you may understand why it has taken such a long time to put up a 'Flying with...' page, along the 'Walking with..' and 'Swimming with...' pages: the tetropter flight animation has to be ready first, and that is a big job.