Winter Scene animation

Discussions related to graphics (2D and 3D), animation and games programming
Posts: 272
Joined: Mon 02 Apr 2018, 09:12

Winter Scene animation

Post by guest »

The 'winter scene' animation in '' (supplied with BBCSDL v0.28a, see video below) was an interesting and instructive example of utilising a commercially available 3D model. I chose this model because it had a low polygon count (only 3506) and was relatively inexpensive (about £30, so good value considering the time it would have taken to create something comparable from scratch, which I couldn't have done anyway).

Adapting it for use in BBC BASIC (BBCSDL as it happens, but it could equally well have been BB4W) raised several issues that may be of interest to anybody faced with a similar challenge:
  • The model came as one .obj file but 11 separate texture images (some with matching transparency bitmaps). My 3D libraries support only one texture per object, so it was obviously going to be necessary either to split the .obj file into 11 .fvf files, or to combine the 11 textures into a single bitmap. Either would involve a 'custom' version of OBJ2FVF, with a comparable amount of effort, so I chose the latter because the BBC BASIC libraries work more efficiently with fewer objects.
  • It soon became apparent that simplistically combining the texture images into a single bitmap wasn't going to work, because the model relies on texture wrapping (that is, the automatic 'tiling' or tessellation of a small texture to cover a larger area by repeating it). One of the textures, for the ground, was tiled in both x- and y-directions so I had no choice but to separate this out as an independent object. Of the other ten textures some were not tiled at all (so weren't a problem) but some were tiled only in the x-direction. To make it possible to combine them into a single bitmap I had to stack them vertically as a strip, so that horizontal wrapping had the desired effect.
  • The 3D model's small polygon count is achieved by making extensive use of texture 'transparency' (i.e. an alpha channel). So for example a tree may be composed of a relatively small number of triangles, with the details of the branches and leaves modelled in 2D by means of the transparency mask (you can see this if you look closely). I initially tried to enable the mask with 'alpha blending' (as for example used in '', '' and ''), but the object-ordering restriction - discussed in a separate thread - was impossible to meet with such a complex model. So instead I have enabled simple alpha-based pixel pruning: this does mean that the transparency is 'binary' (either fully opaque or fully transparent) rather than 'linear', which causes some aliasing on edges.
  • iOS has a specific restriction, which the other supported platforms don't have, that textures can only be wrapped (tiled) if they have power-of-two dimensions (both width and height being 2^n pixels). Because I wanted the program to run in iOS I chose to make the 'ground' texture 256x256 pixels (GIF-encoded to keep the file size small) and the ten remaining combined textures a single 256 wide by 2048 high bitmap. This bitmap is PNG-encoded because it needs to support an alpha channel (the alternative would have been a 32-bpp BMP but being uncompressed it would have been a lot larger).
  • Tweaks to achieve the final animation included separating out the string of Christmas lights into two .fvf files so I could flash the lights in real time (the objects are simply swapped at regular intervals) and generating a separate .fvf file containing the snowflakes (1000 of them in the file) so they could be independently animated.
That's all there was to it! None of these issues was particularly complicated or time consuming to resolve, but whilst the solutions seem obvious in hindsight they needed quite a bit of thinking about (not helped by my mental deterioration). The final result is pretty close to the sample renderings at Turbosquid and I'm relatively pleased with it. I hope you are too! :)

Posts: 30
Joined: Fri 20 Apr 2018, 00:56

Re: Winter Scene animation

Post by kigohhere »

The animation is smooth, traditional and impressive.