Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Saturday, 22 November 2014

The wrong farf (Tetropters VI)

I made a few animations especially for the Loncon3 convention, some of them concerning tetrop
ters (see here for the previous tetropter post). The reason was that I wanted show some of the 'flight platforms' that tetropters could conceivable evolve into. So far, there are the 'standard, 'rowing', 'helicopter' and 'farf' modes.

Click to enlarge; copyright Gert van Dijk

These modes all have to do with the relative amount of movement in all the four ways a tetropter wing can move. The image above shows the idea: there is a general tetropter body, characterised by its vertical position, four jointed legs at the bottom and a head with sensors at the top (there is a head with smaller eyes and a mouth at the bottom end of the body, not visible here). The red, blue and green axes run through the attachment point of one wing and concern the movement of that wing. There are similar axes systems for the other wings, but these are not shown (the wings are, though, just). The arrows indicate the direction of rotation of each axes. A to and fro movement around the blue axis will result in a clockwise and anticlockwise movement. If you combine that with an up-and down movement around the red axis you get interesting patterns: the wing could describe a circle, but the most common pattern is a horizontal figure of eight. The wing moves clockwise and down, then at the end moves up quickly, so it can move down again while moving anticlockwise. That just leaves the green axis, which rotates the wing around its own longitudinal axis, allowing it to achieve the proper 'angle of attack'.

I said there are four ways to move a tetropter wing, and the fourth is not a rotation around an axis as are the first three, but warping the plane of the wing. Well, if you followed that an can envisage it, top of the class. Its more or less what you need to describe the movement of the wings of animals with hovering flight, so we are on common ground here.

I will probably come back to the other tetopter flight modes later, but let's talk about the farf mode. A farf is short for farfalla, the name the Furahan citizen-scientists gave to tetropters with a very long wing base. In fact, the image above has just such a wing membrane: you can see that the membrane lies against the vertical blue axis over its entire length. Actually, the wing membrane shown here would not be an actual one. It is just a rectangular placeholder, but is does show the principle of the thing nicely. This arrangement means that movement around the green axis cannot take place, and to get a good angle of attack the wing will have to warp considerably. If you think this scheme reminds you of a butterfly, you are right: butterflies also have wings with a broad long wing base. In fact, 'farfalla' is Italian for butterfly.



So here is an animation of a farf, made for this post, showing the placeholder wings. Not too bad, is it?


And this is the one I showed at Loncon3, with colours etc. Just about the day before I showed it, it dawned on me that I probably made a mistake in warping the wings. When the wings clap together, they have to be more or less flat, and then they should peel apart, first at the top, and then downwards towards the bottom. Well, that bit worked, but for some reasons I had also warped the wings in such a way that the distal end of the wings –that is the bit farthest away from the body- leans into the movement, so it moves before the part near the body. But the wings would encounter resistance from the air, and so the tip of the wings should probably lag behind the proximal part instead of leading it.

I do not think anyone noticed, but I also did not give the audience a long time to think about it. I will have to do another animation with the opposite effect, to see whether that looks better. But there's no time for that yet... Meanwhile, I hope you still enjoy the 'wrong farf', warped as it is.

Saturday, 2 August 2014

More cloak and dagger stuff: cloakfish IV

Cloakfish have been discussed here previously; for the latest instalment, go here. Before I go on, I wonder how to call them; the plural of 'fish' is still 'fish' when you are talking about the same species, but as far as I know 'fishes' is correct when dealing with more than one species. So should I write sentences like 'Clown cloakfish are founds in their thousands under floatreefs' and 'The many cloakfishes of all shapes and sizes in the peri-Archipelago seas'?

Anyway, cloakfishes (!) were developed as animations before I painted them. So far, they were animated using MS-DOS, believe it or not, but the result was a bit two-dimensional. I later used Matlab too, but only as a painting aid, not to produce animations. Their bodies were very simplistic and the cloaks themselves were just sheets, without any thickness to them. But when I saw large cloakfishes in my mind's eye, they floated majestically into view, with cloaks as substantial as those of a manta ray. In fact, the one I will show now is a 'shortsleeved cloakfish' so it does look a lot like a ray, but with four-sided radial symmetry, obviously. So how could I realise such a vision?

Click to enlarge; copyright Gert van Dijk
Well, with difficulty... The overall strategy consists of several steps: the firsts relies on Matlab to design the overall shape of a cloak, as shown above. The various curves are combined to form the outline of the cloak as well as of the part of the body -the dagger-  it is attached to.

Click to enlarge; copyright Gert van Dijk
Then, flesh out the form by creating two surfaces for each cloak so it smooths into the dagger. What you see above are two such half cloaks, together making up one cloak. If you were to stick four such ensembles together you would have a full cloak and dagger assembly.

Of course, there is movement to think of, and the shape of the cloak has to be changed over its movement cycle. I divided the cycle into 200 steps to have some temporal resolution. For each stage of the movement there are eight half cloaks, so we are now at 1600 files. All these shapes are written to store as 3D obj files, again, using Matlab.

Click to enlarge; copyright Gert van Dijk
Meanwhile, design a head in a suitable program such as Sculptris. There you are; it is not very detailed, but more details would probably not be visible anyway. Also create an underwater landscape in Vue Infinite with a simple animation to allow the cloakfish to glide through the water. Open the programming language Python and write a script for Vue Infinite; from within Vue, use the Python script to load the eight appropriate half cloaks for each frame, the head too, assign textures, transport the lot to the correct positions, render an image and store it. At a reasonable resolution of 640x360 that will take about 30 hours.

Copyright Gert van Dijk

All that remains then is to create a film, perhaps add sounds, etc. What you see above is a trial version in which the cloakfish is just white. I rather like the movement. For a better view, visit Loncon3, where I intend to show a good version... 


PS 1: this is post #200...
PS 2: I am considering returning to blogging regularly after Loncon3.


(PS 3: this is to stop a particular site from copying my blog: 7InDB4PgQaCddePKQEqA )

Sunday, 30 December 2012

Tetropters V: a livelier animation

Regular readers may know that I return to the subject of tetropters from time to time, in a slow and fragmented effort to produce a documentary video showing the little beasties hovering through the air as if they were real, perhaps with an appropriate narrator (as I wrote earlier, David Attenborough would be perfect).

New readers may however respond by saying "What on Earth is a tetropter!?". Part of the answer lies in rephrasing that as "What on Furaha is a tetropter!?" Well, tetropters are small exoskeletal insectoids with a radial base-four Bauplan using a double clap-and-fling wing movement. That is about as short a description as can be given, I think. Those who wish to read more can find the latest instalment ('Tetropters IV') right here, with links to the previous three chapters.

'Tetropters IV' had reached the stage where I could simulate tetropter wing movement, resulting in animations showing a completely immobile body in a completely immobile environment and a fixed camera position. To get there had required a lot of work, but so much more was needed: the animals' bodies should be detailed -and should probably have internal movement as well-; there should be a larger variety of wing shapes; the animal should tilt a bit in the direction of movement, and larger tetropters with slow wing beats should bob up and down in flight, like a butterfly does when flying. And to mimic the effect of a macro lens the scene the depth of field should be narrow, with blurring of nearby and far objects.

 Copyright Gert van Dijk

I used some time in the holiday season to work on the animation, pushing against the limitations of time and capability. The first result of that push stage is shown above, and had the animal moving about freely in three dimensions. To do so I wrote a program in Matlab to define a 3D path in x, y and z-coordinates. The movement is based on the number of frames per second and the numbers of seconds the film should last for. To keep the wings moving there is the number of frames per cycle to consider. I added a little tremor to the vertical component of the movement, so the animal bobs up and down a bit, in phase with its wing beats. All this resulted is a text file with a lot of numbers stipulating where the animal is and at which phase its wings are. The more difficult part was convincing the rendering program 'Vue Infinite' to accept all these numbers and produce a nice image per frame. I had to work on a program in the language 'Python', which I am hardly familiar with, but which can be used to control almost any function in Vue Infinite. I got over that and made the animation above. Not too bad, is it? In an earlier version Evan Black commented that an improved animation might have the effect that the coarser aspects of the design, such as wing attachment, would be less noticeable if the animation would be developed more. I think that that now proves to be true. By the way, the three axes and the balls are there to tell me whether the animal is with regard to local space. I also did not bother to set the wing cycle to match with the movement; in a real scene the wings should beat much more often over the course of such a movement.

Copyright Gert van Dijk

The next stage, shown above, involved 'lens blurring' and body tilting. After various tries and errors Vue Infinite could do lens blurring, but in a very complicated manner: there was a variable that had to entered as a percentage, so I stopped at 100%. The blurring only worked as intended when I set it to 2000%, something I learned after having received help from the Vue Infinite forum at E-on software.
  As for the body tilting, that involved rotations around all three axes. I wrote the program so i could control the rotations by hand, but added an automated feature that differentiated a position path. There should probably be a time delay in that the body should probably start to tilt in a given direction slightly before it starts to move that way, but the lack of such a delay is not noticeable. There could be various way for tetropters to change direction; they could change the aspect ration of specific wings or during specific phases of wing movement, or they could bend their bodies to change their centre of gravity. Regardless, I think the tilt adds a nice touch, rendering the flight a bit like that of a helicopter.

Copyright Gert van Dijk 

The animation above shows where I am now: camera movement. The camera follows the tetropter. As all this is a simulation that could be done perfectly, so every bob up and down would be followed, and the body would stay centred on the image with mathematical perfection. That would look very artificial: a human camera operator would lag behind the movement and would not follow tiny variations. I mimicked that by having the camera follow a smoothed path rather than the actual one, but I do not think the smoothing is good enough yet; it probably needs a delay function as well.

Oh well, there are enough things left for the next stage, such as adding a suitable body. I will probably sculpt one in Sculptrix or build one in Vue itself. The latter option will result in an artificial technical look but has the advantage of colouring the animal with ease. The Sculptrix option will produce a much more biologically looking body, but requires colouring in some other program, another new task to learn (apparently Photoshop can be used to paint 3D objects). So, do not hold your breath, but 'Tetropters VI' will probably be the final documentary, adding all the items mentioned earlier.

Except for the narrator, I am afraid...

Saturday, 4 June 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.