Final Project Blender batch rendering of liquid surfaces

download Final Project Blender batch rendering of liquid surfaces

of 54

Transcript of Final Project Blender batch rendering of liquid surfaces

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    1/54

    UNIVERSITY OF COPENHAGEN

    DEPARTAMENT OF COMPUTER SCIENCE, DIKU

    Blender batch rendering of liquid

    Final project

    Presented by David Calabuig Lpez

    Supervisors: Morten Engell-Nrregrd and Kenny Erleben

    January 18, 2011

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    2/54

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    3/54

    ABSTRACT

    This project studies the problem of creating a command line tool for rendering ananimation in Blender. Blender is a cross-platform software tool, especially devoted to

    modeling, animation, and graphics creation. Blender has a very powerful feature thatnowadays it is very used; this feature is a fully functional Python interpreter. Thisallows any user to add functionality to Blender writing a simple Python script. AsBlender uses Python for scripting, thus is seems natural to use Python for creating thefunctionality of the tool.

    At DIKU the Image group invents new fluid simulation methods. One importantaspect of successful publication of research results is the ability to render nice animationmovies of the simulation results.

    This project proposes a solution for creating the animation of the simulation results.

    Thus, from the set of simulation results, the application will generate a render the videoanimation.

    The main features of the rendering are:

    Be able to specify simple parameters like the number of frames in thesequence, the number of lights in the scene or the material of the object.

    Have control over the codec's of the resulting animation movie. The application must work on three different platforms, Linux, Mac OSX

    and Windows.

    In summary, this project explores the potential in creating a simple tool that allowsresearchers to quickly create an animated film.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    4/54

    RESUMEN

    Este proyecto estudia el problema de crear una herramienta de lnea de comandospara renderizar una animacin en Blender. Blender es una herramienta informtica

    multiplataforma, dedicada especialmente al modelado, animacin, y creacin degrficos. Blender tiene una caracterstica muy poderosa que hoy en da es muy utilizada;esta caracterstica es un intrprete de Python totalmente funcional. Esto le permite acualquier usuario aadir funcionalidades a Blender escribiendo un simple script dePython. Como Blender usa Python para scripting, lo ms natural ser utilizar dicholenguaje de programacin para crear la funcionalidad de la herramienta.

    En el grupo de imagen DIKU inventan nuevos mtodos de simulacin de fluidos.Uno de los aspectos importantes del xito de la publicacin de resultados de lainvestigacin es la capacidad de renderizar animaciones de los resultados de lasimulacin.

    En este proyecto se propone una solucin para la creacin de la animacin de losresultados de la simulacin. As, a partir del conjunto de resultados de la simulacin, laaplicacin generar un render de la animacin de video.

    Las caractersticas ms destacables del render son:

    Ser capaz de especificar los parmetros simples como el paso de tiempoentre frames consecutivos, la posicin de la cmara, luces o materiales.

    Tener el control sobre codecs de la pelcula de animacin resultante. La aplicacin debe trabajar en tres diferentes plataformas, Linux, Mac OSX

    y Windows.

    En resumen, en este proyecto se desea explorar el potencial en la creacin de una

    herramienta sencilla que permite a los investigadores crear rpidamente una pelcula de

    animacin.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    5/54

    GENERAL INDEX

    General Index

    1. Introduction 1

    1.1. Introduction to project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2. Introduction to Blender . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3. Project objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    2. Analysis 42.1. Description of the workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

    2.1.1. Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.1.2. Python scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.1.3. Plugins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.1.4. Comparison of solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

    2.2. Detailed description of the solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    2.3. Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    3. Design 93.1. How to build the animation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.2. How to use the lights? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.3. How to use the materials? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.4. How will the graphical user interface be? . . . . . . . . . . . . . . . . . . . . . . . . . 133.5. Output files formats and their differences . . . . . . . . . . . . . . . . . . . . . . . . . 13

    3.5.1. Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.5.2. Video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

    4. Implementation 164.1. Graphical user interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

    4.1.1. Using Blender . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.1.2. Without using Blender . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

    4.2. Import figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204.3. Creation of video . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204.4. Insertion of lights . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.5. Insertion of materials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.6. Formats chosen for the output file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    4.6.1. PNG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    4.6.2. JPEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244.6.3. AVI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    6/54

    4.6.4. XVID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254.6.5. MPEG1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254.6.6. Formats comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

    5. Improvements, problems and examples 27

    5.1. Improvements in application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275.2. Problems found. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295.3. Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305.4. Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

    5.4.1. Example using Blender . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315.4.2. Example without using Blender . . . . . . . . . . . . . . . . . . . . . . . . . . 36

    6. Conclusions 396.1. Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396.2. Future Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

    Appendix A Source Code: Import figures 40

    Appendix B Source Code: Lights 42

    Appendix C Source Code: Materials 44

    Bibliography 46

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    7/54

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    8/54

    CHAPTER 1

    INTRODUCTION

    1.1. Introduction to project

    At DIKU the Image group invents new fluid simulation methods. One importantaspect of successful publication of research results is the ability to render nice animationmovies of the simulation results.

    In this project I wish to explore the potential in creating a simple tool that allows

    researchers to quickly create an animation movie.

    This tool will be used by a group of researchers from the University of Copenhagen.

    The tool will take as input a sequence of numbered files with extension. Obj asframe_000.obj, frame_001.obj, ..., frame_099.obj, etc., where each file contains rawdata for a single mesh frame in the animation. The application will output a videoanimation of simulation results.

    1.2. Introduction to BlenderOriginally, the program was developed as an own application by Dutch animation

    studio NeoGeo, the main author, Ton Roosendaal, founded the company "Not a NumberTechnologies" (NaN) in June 1998 to develop and distribute the program.

    The company went bankrupt in 2002, then creditors have agreed to offer Blender asa product of free and open source under the GNU GPL in exchange for 100,000. InMarch 2002 Ton Roosendaal founded the non-profit organization Blender Foundation(Blender). The first objective of the Blender Foundation was finding a way to continue

    developing and promoting Blender as an open source project based on the usercommunity. In July 2002, Ton managed to get the NaN investors "yes" for the Blender

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    9/54

    Foundation to carry out its plan to be open source. The campaign to "Free Blender" hadto get 100,000 for the Foundation to buy the rights to source code and intellectualproperty Blender NaN investors and subsequently release Blender to the open sourcecommunity. With an enthusiastic group of volunteers, among whom were several ex-NaN employees, the campaign to "Free Blender was launched. To the delight and

    surprise of everyone, the campaign reached the 100,000 EUR goal in only 7 weeks.

    On Sunday October 13, 2002, Blender was released to the world under the terms ofthe GNU General Public License (GPL). Blender development continues to this daydriven by a team of volunteers from various parts of the world led by Blender's creator,Ton Roosendaal. [1]

    Figure 1. Screenshot of Blender 3D interface.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    10/54

    1.3. Project objectivesThe specific objectives are:I. Plan and design a tool to create animation movies.II. Getting a better understanding of basis of computer graphic (such as

    lighting, materials, camera and so on).III. Evaluate the result of rendering and improve the tool if possible.IV. Getting a better understanding of the Python programming language.V. Learning the differences between the different kinds of formats.These objectives are developed in 6 chapters. The first section gives an introduction

    to the application to be developed and a brief introduction to the history and origin ofBlender.

    Chapter 2 will contain step by step description of the solution as well as therequirements that the application must meet and the description of workflow within the

    application.

    In Chapter 3 I describe the design; this is how I'm going to solve the project. It willalso describe the user interface.

    In Chapter 4 will describe how I have solved the application. It will introduce andwill explain the code snippets of the tool that I think most important.

    Chapter 5 will contain the various problems encountered in creating the tool.Application will be evaluated and explained by means of graphs of time because I havechosen a solution or another. Also examples of how to use the application will beshown.

    Chapter 6 will describe the conclusions on the project.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    11/54

    CHAPTER 2

    ANALYSIS

    2.1. Description of the workflow

    This section outlines the different types of workflow that can be used in theapplication.

    2.1.1. Types

    Blender has a very important feature; it is a fully functional Python interpreter. Thisfeature allows any user to add new functionality to Blender writing a simple script inPython.

    Python is an interactive, object-oriented and interpreted programming language. Itincorporates modules, exceptions, dynamic typing, dynamic data type of very high-levelclasses. Python combines high power with a very simple syntax. It is expressly designedto be used as an extension for applications that need a programmable interface, and thisis why Blender uses it.

    There are two ways of extending Blender: by using Python scripts and binaryplugins. The following will explain the advantages and disadvantages of each of the twooptions.

    2.1.2. Python scripts

    The first option is to use scripting with the Python programming language. Usingthis option will have advantages such as faster development: the user can write aprogram, save it and run it. In a compiled language one has to go through the steps ofcompiling and linking software, which can be a slow process. Another advantage ismultiplatform; it means that the same code works on any architecture, the only

    condition is that the language interpreter is available. No need to compile the code oncefor each architecture. A common disadvantage is the speed; interpreted programs are

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    12/54

    slower than compiled. However, the interpreted programs are usually short, so thedifference is negligible. In the Figure 2, I showed the scheme of scripts in python. Alsothe script to can interact with the main program, in our case Blender, uses theapplication programming interface known as API. The script also uses Python becauseit is the option most powerful, versatile, robust and easy to understand.

    Figure 2. First option: Scripts in Python.

    2.1.3. Plugins

    The second option uses plugins, we can see it in Figure 3. The plugins (loaded /called) in Blender via dlopen (). For those unfamiliar with the system dlopen, thisallows a program (Blender) use a compiled object as if it were part of the program itself,similar to when libraries are linked dynamically, except that the object, that is load, isdetermined when the program is running. The advantage of using the dlopen system forplugins is that it is very fast access to a function, and there are no overhead in the plugininterface, which is critical when the plugin can be called several million times in asingle render . The disadvantage of this system is that the plugin works as if it werereally part of Blender, so if the plugin is dying, Blender dies. The header files found in

    the subdirectory plugin / include / Blender installation are documented showing thefeatures that are provided to plugins.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    13/54

    Figure 3. Second option: Plugin.

    2.1.4. Comparison of solutions

    Of the two ways of extending Blender, it seems it really is preferable to use Pythonscript compared to writing a plugin. I choose the option of Python scripts because oneof the advantages is as faster development since the user only has to write the program,save it and run it. Another reason is that the same code can be used on otherarchitectures, in other words the application is multiplatform. Therefore, this is the

    option chosen to solve the problem of this project.

    Python script actually had some limited functionality in Blender 2.25, the latestreleased versions of NaN. When Blender became open source a lot of developers thatthey moved around the Foundation, they chose python script to work and, together withthe change of user interface, the Python API is probably the part of Blender has had alarger development. A complete reorganization of what existed was carried out andmany new modules were added.

    This evolution is still in progress and a better integration is to come in futureversions of Blender.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    14/54

    2.2. Detailed description of the solution

    The first solution has been written in a script that runs Python within Blender asshown in the figure below (see Figure 4).

    Figure 4. Screenshot of Blender 3D interface with the interface of scripts.

    The steps taken to the solution are the following:

    I. Import the file .obj to Blender as a figure.II. Select position of the camera.

    III. Add the Blender object, activate it.IV. When active, add a frame.V. Add the lights.

    VI. Add the material.VII. Rendering.

    VIII. Deactivate the objects and delete it.IX. I repeat this step until I have completed the 8 steps above for all the objects

    that make the video.

    2.3. Requirements

    As this is an application that it has files input .obj, these files must meet somerequirements that may be imported by the program. These files must be formatted .obj,for the tool will can make the animation. Another requirement is that the user change byhand in the script to the directory where the files .obj and its name, this requirement we

    hope improved later, trying to avoid this.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    15/54

    Before importing the .obj files, you must select the camera position where the userwants to be, it is understood that the user enters the coordinates of the camera which itdisplays the imported object. On the other hand the user cannot change the position oflights; position lights will always be the same in order to fulfill the lighting method ofthe three points explained in section 3.2.

    Another important requirement, for users not using Blender, is the input text file.This file is a text file containing the input features to create the animation. The usermust change the characteristics of input file by hand in the text, these features are: thedirectory where the .obj files and its name, the number of .obj files, the coordinates ofthe position of the camera, the number of lights, the route and type of material and typethe path and output file.

    I chose these features because they are necessary and which I thought appropriate tocreate the functionality to convert the .obj files input to render the animation video. Thisfunctionality is the goal pursued in this work.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    16/54

    CHAPTER 3

    DESIGN

    This chapter will discuss how information will flow between the user and theprogram, how could I create the animation, how are objects such as light or the materialor how will the graphical user interface be. That is, this section will answer thequestion: How can I fix it? A very general solution is that shown in the following figurenumber 5:

    Figure 5. General outline of how the project will address

    The following sections begin with a brief explanation of the object in the relevantsection (animation, lights, material or interface) and then I explain as I intend to solve it.The following will respond to different "how" previously made.

    3.1. How to build the animation?In this e-book "Fundamentals of 3D Image Synthesis. A Practical Approach to

    Blender", the authors Carlos Gonzlez Morcillo y David Vallejo Fernndez argue that:We can define the stage of animation as the generation, storage and presentation ofimages in rapid succession, producing a sensation of movement. The eye retains imagesviewed about 40 ms. By this "defect" of the visual system, people perceives as acontinuous sequence of images (static) that its display more than 20Hz. Each of these

    images on computer graphics are called Frame. [5]

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    17/54

    To create the animation we need to have mesh, first I import the .obj file objects.When I have all imported input objects, now the application have to create theanimation, a proposed solution to this animation is that the X object, the X object isvisible in the X frame, while in the X+1 frame will be visible X+1 object; so on for allobjects imported from all input files. I use a type of curves called IPO curves

    (Interpolation). These curves are curves of animation used in 3D design environmentsto control the variation of object attributes over time. In other words are interpolationcurves, from the values taken at control points (key frames), the parameter valuesinterpolated in between frames. What is used is in fact motion channels which make itpossible to store the deformation of a mesh in morph targets which can then be activatedat different frames this definition of IPO curves has as authors: Carlos GonzalezMorcillo and David Vallejo Fernandez. [5]

    3.2. How to use the lights?

    Now let us turn to a very important part of all the images in 3D, which is lighting.Many times we need the light coming from elsewhere, coming from various places, thatis more intense, that the lights have more intensity or any other color, All this is donewith the lamps. First, I begin by describing the basic types of lights.

    Lamp:This object of lighting is responsible simulate an ordinary bulb. Thelight that brings spreads in all directions from the position that is the lamp,which is known as "Omni-directional light." The illumination decays withdistance, this factor will be important in this type of lighting.

    Area: This object is a directional light, a light that comes as a particulardirection: Although spreads from one region or area almost as in theprevious case, but now is not the generator point of the light, it is a rectanglethat can be scaled to increase the radiating surface and thus the illuminatedarea. For these lamps is important: the distance to objects and the size of thelight source.

    Spot:Simulates a directional light source. The lighting comes from a lightedarea increasing as we move away from the spotlight. An example thatillustrates this kind of object can be the headlights of a vehicle, or the lightsused at concerts.

    Sun:Simulates the effect of sunlight. Illuminates the whole scene equally,regardless of position. The light generated a parallel rays according to adirection. It is therefore a directional light but does not decay in intensitydepending on the distance to the point where we place.

    Hemi:This light is similar to solar, but does not produce shadows cast bythe object. It can be considered directional in many ways, being independentsimilar to solar, of the point at which we place it.

    In the pictures below the reader can see the direction of light sources (see Figure 6)and the effects generated on a surface (see Figure 7):

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    18/54

    Figure 6. Different types of light.

    Figure 7. Effect of different types of lights.

    Now I will discuss how I have used the lights, I could have used the number andtypes of lights that I wanted but I have chosen the technique of lighting that is used inthe project. In the application, I will use the technique known as three points. The three-point lighting uses three light sources to illuminate a scene (hence the name). The firstand most important is the key of light [6]. The key can be placed anywhere on thescene. The following light is filler, which does what its name implies, fill in areas whereno light arrives. The last lamp, the back, which is placed behind the object and gives anillumination of its edges. The general outline of the position of these lights can be seenin the following image (see Figure 8). In the application I have chosen the position ofthe lights so as to meet the technique of the three points discussed above. These lights

    are oriented toward the center of the scene (0, 0, 0) but with different positions. Theuser can change these positions in the script of the application or by Blender in screenlayout: Default

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    19/54

    Figure 8. Three point lighting.

    3.3. How to use the materials?

    So far I have focused on defining the properties of light sources in the scene. Thefinal representation of an object is determined by the material and how it reflects light.The way to reflect determines the color and appearance that an object will have on thepicture. In very general terms, a material that absorbs certain frequencies of light and

    reflects others. The part reflected, which is complementary to that absorbed, is used tocalculate the color that corresponds to a certain point on the surface as seen from thecamera.

    As I want to represent real textures, I have been downloaded materials fromhttp://matrep.parastudios.de/ that simulate real textures and added to the programdepending on the type of object, the user can choose different textures as can be seen inFigure 9. The different textures from left to right and from top to bottom are: amber,Voronoi bronze, crystal, denses clouds, fire, red hot metal, water and wood. If the useris not interested in any of the material listed above, the user can also create their ownmaterials for the object.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    20/54

    Figure 9. Different types of materials [4].

    3.4. How will the graphical user interface be?

    The user interface is the means of interaction between the user and the program. Theuser communicates with the program via the keyboard and mouse, and the programprovides feedback through the window system.

    Also the application will can run from Blender for users who uses Blender and foruser that do not use Blender, the application will can run from a terminal.

    The user interaction is that the user of the information needed to create theanimation. Depending on whether the user is using Blender or not, the input informationwill be different. In section 4.1 will explain the differences in the input information foreach case.

    3.5. Output files formats and their differencesThere are many image formats out there for many different uses. A format stores

    an image in a losslessor lossy format; with lossy formats you suffer some imagedegredation but save disk space because the image is saved using fewer bytes. Alossless format preserves the image exactly, pixel for pixel. You can break formatsdown into staticimages and movie clips. Within either category there are standards(static formats and clip codecs) which may be proprietary standards (developed andcontrolled by one company), or open standards (which are community or consortium-controlled). Open standards generally outlive any one particular company and willalways be royalty-free and freely obtained by the viewer. Proprietary formats may only

    work with a specific video card, or while the codec may be free, the viewer may cost.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    21/54

    In Blender, there are two groups of output format: images and video. Thefollowing sections explain formats of each of these two categories. The explanation ofthese 2 categories, section 3.5.1 and 3.5.2, it has been copied of the Wikipedia ofBlender [13].

    3.5.1. Image

    Blender supports a wide mix of image formats. Some formats are produced byinternal Blender code. Others (Tiff, for example) may require a dynamic load library(such as libtiff.dll) in your Blender installation folder. The output image formats are:

    BMP Bit: Mapped Paint lossless format used by early paint programs. Cineon: format produced by a Kodak Cineon camera and used in high-end

    graphics software and more directed toward digital film. DPX: Digital Moving-Picture eXchange format; an open professional format

    (close to Cineon) that also contains metainformation about the picture; 16-bituncompressed bitmap (huge file size). Used in preservation.

    Iris: the standard Silicon Graphics Inc (SGI) format used on those spankingUnix OS machines.

    Jpeg: Joint Picture Expert Group (name of the consortium which defined it), anopen format that supports very good compression with little loss of quality. Onlysaves RGB value. Re-saving images results in more and more compression andloss of quality.

    MultiLayer: an OpenEXR format that supports storing multiple layers of imagestogether in one file. Each layer stores a renderpass, such as shadow, specularity,color, etc. You can specify the encoding used to save the MulitLayer file using

    the codec selector (ZIP (lossless) is shown and used by default). OpenEXR: an open and non-proprietary extended and highly dynamic range

    (HDR) image format, saving both Alpha and Z-depth buffer information. PNG: Portable Network Graphics, a standard meant to replace old GIF inasmuch

    as it is lossless, but supports full true colour images. Supports Alpha channel. Radiance HDR: a High Dynamic Range image format that can store images with

    big changes in lighting and color. TARGA and Targa raw: Truevision Advanced Raster Graphics Adapter is a

    simple raster graphics format established in 1984 and used by the original IBMPC's. Supports Alpha Channel.

    TIFF: Often used for teletype and facsimile (FAX) images.3.5.2. Video

    This explains the different formats of video:

    AVI Raw: saves an AVI uncompressed, lossless but with a huge size. AVI Jpeg: saves an AVI as a series of JPEG images. It has lost small but not so

    small as you can get a better compression algorithm. Also Jpeg AVI format doesnot read most of the players.

    AVI Codec: saves an AVI compressed with a codec. Blender automaticallyprovides a list of available codecs on your system and lets you select the various

    parameters. QuickTime: saves a QuickTime animation.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    22/54

    H.264: is a standard capable of providing good image quality at bit ratessubstantially lower than previous standards (MPEG-2, H.263 or MPEG-4 Part2), in addition to not increase the complexity of your design.

    MPEG: use codecs (coders-decoders) low loss compression using codecsinformation processing.

    Ogg Theora: a video compression method at a loss. The compressed video canbe stored on any media suitable container.

    Xvid: is the name of a popular codec developed as a free software project. Xvidencoded films offer high quality video in small file sizes, less time in addition toits compression in MPEG-2 due to a more advanced compression algorithm.

    In the created application, I have chosen the most popular formats and commontoday, which are as follows: for the category of image, the formats chosen are PNG,JPEG, and for the category of video, the formats chosen are Xvid and FFMPEG withencoded AVI and MPEG1. These 5 formats have been chosen because they are the mostwell-known and more used nowadays.

    In section 4.6 I will explain the pros and cons of some of the formats selected for theoutput file. I will also discuss why some are better than others in terms like imagequality file size, problems with proprietary viewers and so on.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    23/54

    CHAPTER 4

    IMPLEMENTATION

    This chapter describes and explains how the application has been made and how theapplication is created step by step, as already mentioned is some .obj files convert in anrender animation movie.

    I begin with the first section that is the first step which is the creation of a graphicaluser interface; the user introduced all the requirements of the application to importfigures. Then I create the animation and finally I explain the inclusion of lights and

    materials.

    In addition to the explanation of each step, in each section will be introduced piecesof code and pictures that I consider important to the creation of the application.

    4.1. Graphical user interface

    The first and most important point is the communication between the user and theapplication, in other words the graphical user interface. There are two ways to use the

    application, one of which is to run the script from Blender and the other is from theconsole. Now it will explain each of the two ways to run the application.

    4.1.1. Using Blender

    The first is for users who use Blender. The user opens Blender, he changes to thewindow to edit scripts, he opens the script and executes the application. When the userruns the script containing the application, the user changes to the Default view and notesthat in the menu of the window Object Tools appear buttons needed to create theanimation. The interface of the application from Blender shown in Figure 10, is divided

    into several parts which are discussed now:

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    24/54

    Position of the Camera:Here the user introduces coordinates of the cameraposition.

    Select obj files:This is a button which opens a file browser to select all .objfiles to be used to create the animation.

    Light:Here the user introduces the number of lights he wants to enter in thescene, taking a minimum of zero lights and a maximum of three lights. Theposition and color of the lights can be changed manually in the script beforerunning the application. The maximum three-light corresponds to the threepoints illumination method mentioned in paragraph 3.2.

    Materials Path: In this browser the user will write the path where thematerials are which can be introduced to the object in the scene.

    Type of Material:Clicking, the user will see a list of materials that can beapplied on the object of the scene. These materials have been described insection 3.3. For example, if the material selected is Amber, Amber materialis applied to the object in the scene.

    Type of output file:This button is the same as above but the user selects theoutput format the user wants to generate for the rendering of the scene.

    Output Path:In this browser the user will enter the path where to save theoutput file or output files generated.

    Generate the output file: This button generates the output file or outputfiles with the characteristics discussed above.

    Figure 10. Window graphical user interface of the application.

    If the user wants to introduce another type of material or other type of output file,he will need to add the new type to the window of the types of the interface and thenadd the code required to use the new type. In section 4.6 I explain how to introduce anew type of material.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    25/54

    4.1.2. Without using Blender

    The second way to use the application is for users who do not use Blender, forwhich the user must enter a command at the console with the following pattern:

    Now I explain each of the points from the previous command:

    PathOfBlender: This part contains the path where the application isinstalled Blender.

    -b:flag for background. -P:for telling it to run a python script. scriptApplication: This part will contain the path and name of the script of

    the application created.

    PathofInputData:This part defines the path and file name where the inputdata is to make the animation.

    The next point is to explain the input file (PathofInputData) and what characteristicsit should have in order to make the animation.

    The above table shows the features the user must have the input data file and inwhat order they should appear the features. It now explains each:

    Path of the Files:In this first line the user must put the path where the .objfiles are.

    Name of files:In this second line the user puts the name of all .obj files. Number of files:In this third line as its name indicates, the user will write

    the amount of files the user wants to make the animation.

    $> PathOfBlender b P scriptApplication PathOfInputData

    # Path of the files

    # Name of files

    # Number of files

    # Position X of the Camera

    # Position Y of the Camera

    # Position Z of the Camera

    # Lights

    # Path of the Materials

    # Material

    # Path output

    # Format output

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    26/54

    Position of the Camera: In this fourth, fifth and sixth line the userintroduces coordinates of the camera position.

    Lights:In the seventh line the user introduces the number of lights he wantsto enter the scene, taking a minimum of zero lights and a maximum of threelights. The maximum three-light corresponds to the illumination method to

    the three points mentioned in paragraph 3.2. Path of the Materials:In this eighth line the user introduces the path where

    the material is that the user can put the object in the scene. Material:In the ninth line, the user will introduce the material applied to the

    object in the scene. Path output:In the tenth line, the user will enter the path where he wants to

    save the output file. Format output:In the eleventh line, the user will introduce the output file

    format.

    Note that the type of materials can be: none, water, wood, amber, clouds, fireball,

    bronzeMetal, glass and hotmetal as seen in section 3.3. And the output file format canbe: png, jpeg, avi, Xvid, mpeg1 and none; as seen in section 3.5. In section 5.3.2 showsan example of the application using this part. Another thing to mention is that all thefeatures of the input file are strings; except the option of the number of lights, which isan integer (0, 1, 2 or 3).

    The following table shows a complete example of the input file with thecharacteristics discussed above.

    # Path of the files

    C:/Users/Calabuig/Desktop/Final Project/test/

    # Name of files

    cylinder

    # Number of files

    25

    # Position X of the Camera

    0.825

    # Position Y of the Camera

    -0.8

    # Position Z of the Camera

    0.51

    # Lights

    1

    # Path of the Materials

    clouds

    # Material

    C:/Users/Calabuig/Desktop/Final Project/Material/

    # Path output

    C:/Users/Calabuig/Desktop/Final Project/Results/

    # Format outputpng

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    27/54

    4.2. Import figures

    In Blender any user can import files with formats such as COLLADA (.dae), MotionCapture (.bvh), Scalable Vector Graphics (.svg), Stanford (.ply), Stl (.stl), 3D Studio(.3ds), Wavefront (.obj) and X3D Extensible 3D (.x3d/.wrl). These formats have

    implemented the way of how to import a Blender scene files with any of the formatsappointed, as the type of our input files to the application is within this set, I will use theinstruction the Blender API to import files with the format .obj.

    Therefore, to import all object files goes through a loop that will go from the object1 to the last object of the animation and for each object of the file of name(theFileName) with path (thePathFiles) with index number, I import it in the scene. Thisloop can see the code used in Appendix A.

    4.3. Creation of video

    Seen how figures of .obj files imported, I now turn to discuss the next step: creatingthe animation. We see that all the objects have been imported to the scene and that eachof them is a shape, as I want that will exist only a shape; therefore I join all the shapesof the files introduced in only shape with the following object operator:

    The next step is to get the effect explained in Chapter 3: Design the section 3.1.How to build the animation? So to achieve this effect, I will loop for all the objects inthe scene from the first object to the last object. In other words, in the iteration X theobject X will put the key value to 1 to display the object X and anterior and posteriorobjects, ie objects X-1 and X +1, will the key value to 0. This will get the effect that theobjects seem animated.

    bpy.ops.object.join_shapes()

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    28/54

    Figure 11. TimeLine window and IPO Curve Editor.

    The effect discussed in the previous paragraph is displayed in the image above (seeFigure 11), where the reader can see the IPO curves for displaying objects. These curvesare observed at the interface of editor of IPO curve in Figure 12, the user can see theeffect of viewing explained before where in the green curve we can see that the frame 6

    displays the object with name theFileName_00006.obj file. The representation of IPOcurves using a graph in which the horizontal axis of abscissas represents the frames(hence, time) and the ordinate the values that objects can take on the magnitude ofvisibility of objects. To achieve this effect I used the code of Appendix A which canhelp us understand this functionality.

    Figure 12. Interface Editor of IPO Curve.

    4.4. Insertion of lights

    Now the next step is the lighting of the scene. As explained in paragraph 3.2. How

    are the lights?, I use the traditional method of lighting called three-point lighting. The

    user has introduced in the interface and stored the number of lights in the variable

    theLights that are to be inserted into the scene. The lights are always oriented to the

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    29/54

    point (0, 0, 0) of the scene. It is seen in the snippet of code (see Appendix B) the

    position, rotation and characteristics of the lamp type inserted.

    4.5. Insertion of materials

    The next step is the insertion of selected materials in the interface. The path isintroduced in the interface where the user finds all types of materials to be inserted.

    The functionality described in the inclusion of materials, it shown in the snippet ofthe Appendix C where thePathMaterials will contain the path where the user placed thematerials to be imported. For the selection of materials to be imported, I use a booleanindicating whether the material is selected. For example, the code shows that ifbool_Water is true, the application will import the Water material into Blender, if it is

    false does not matter, this happens for all other types of materials.

    I have inserted different materials but the user perhaps wants to use another type ofmaterial. For it, the user will must use this code pattern and it introduce in the functionof "introduce_materials" of the application (see Appendix C):

    I am going to explain the characteristics that it is necessary to change into theprevious pattern whenever a new material introduces in the application:

    NAME_INTERFACE: Here the user will introduce the key name of thematerial that the user has chosen in the user's interface.

    NAME_FILE: This characteristic will be the name of the file of thematerial.

    NAME_MATERIAL:This characteristic will be the name of the materialinside the file NAME_FILE.

    Now, I propose a finished example of as inserting a new material of the webBlender Material [4] to the application. The texture chosen for the new material is"Beer". The first step is to add the name that the user will use in the interface; that is tosay the NAME_INTERFACE:

    ifmaterials == 'NAME_INTERFACE':

    bpy.ops.wm.link_append(filepath = thePathMaterials +

    "NAME_FILE.blend/", directory = thePathMaterials +

    "NAME_FILE.blend/Material/",link=False, filename="NAME_MATERIAL")ob.active_material = bpy.data.materials['NAME_MATERIAL']

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    30/54

    Later it is necessary to change the name of the file (NAME_FILE) and the name ofthe material (NAME_MATERIAL), these 2 characteristics depend on the downloadedmaterial. Therefore, the code that I will insert in the function introduce_material is thefollowing:

    Now, the user will be able already to use the new material that has downloadeditself. This step will have to repeat it whenever the user wants to insert a new material ofBlender Materials [4].

    4.6. Formats chosen for the output file

    In the section 3.5 Output file formats and their differences explained all types offormats for the output file that Blender supports. In the created application, I have

    chosen the most popular formats and common today, which are as follows: for thecategory of image, the formats chosen are PNG, JPEG, and for the category of video,the formats chosen are Xvid and FFMPEG with encoded AVI and MPEG1.

    In the following five sections I explain the pros and cons of the output formats Ihave chosen for the output file.

    4.6.1. PNG

    PNG stands for Portable Network Graphics (or, depending on whom you ask, the

    recursive PNG-Not-GIF). It was developed as an open alternative to GIF. PNG is an

    bpy.types.Scene.MyMaterial = EnumProperty(

    items = [('none','No Material','Material: None'),

    ('amber','Amber','Material: Amber'),

    ('bronzeMetal','Bronze Metal Voronoi','Material:

    Bronze Metal Voronoi'),

    ('crystal','Crystal','Material: Crystal'),

    ('clouds','Dense Clouds','Material: DenseClouds'),

    ('fireball','Fireball','Material: Fireball'),

    ('hotmetal','Red Hot Metal','Material: Red Hot

    Metal'),

    ('water','Water fresh','Material: Water fresh'),

    ('wood','Wood varnished','Material: Wood

    varnished')

    ('beer','Beer','Material: Beer')],

    name = "Type of material")scn['MyMaterial'] = 0

    ifmaterials == 'beer':

    bpy.ops.wm.link_append(filepath = thePathMaterials +

    "beer.blend/", directory = thePathMaterials +

    "beer.blend/Material/",link=False, filename="beer")ob.active_material = bpy.data.materials['beer']

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    31/54

    excellent file type for internet graphics, as it supports transparency in browsers with anelegance that GIF does not possess.

    PNG supports 8-bit color, but also supports 24-bit color RGB, like JPG does. Theyare also non-lossy files, compressing photographic images without degrading image

    quality.

    In addition to being an excellent format for transparency, the non-lossy nature of24-bit PNG is ideal for screenshot software, allowing pixel for pixel reproduction ofyour desktop environment.

    4.6.2. JPEG

    JPG was a file type developed by the Joint Photographic Experts Group (JPEG) tobe a standard for professional photographers. Like the method ZIP files use to find

    redundancies in files to compress data, JPGs compress image data by reducing sectionsof images to blocks of pixels or tiles. JPG compression has the unfortunate side effectof being permanent, however, as the technology for the file was created for storing largephotographic image files in surprisingly small spaces, and not for photo editing.

    JPGs have become the standard image of the internet because they can becompressed so much. However, because of the lossy nature of JPG, it is not an idealway to store art files. Even the highest quality setting for JPG is compressed, and willchange the look of your image, if only slightly. JPG is also not an ideal medium fortypography, crisp lines, or even photographs with sharp edges, as they are often blurredor smeared out by anti-aliasing.

    JPGs support 24-bit RGB and CMYK, as well as 8-bit Grayscale. Its alsoimportant to note that Grayscale JPGs do not compress nearly as much as color ones do.

    4.6.3. AVI

    AVI (Audio Video Interleave) format digital video files have been around sinceWindows 3.0 was released, many years ago. Due to it's longer history vs. MPEG formatfiles, the associated computer "drivers" for AVI tend to be more mature. Essentially,AVI programmatic control is more predictable (I.e. does what it is told to do) thanMPEG control. AVI driver architecture involves more layers than MPEG, but becauseof this, the underlying "decompression" algorithm becomes unimportant to theprogrammer. The "driver" interface (accessed through the Windows MCIprotocol/command language) is more standardized and comes from one vendor (namelyMicrosoft).

    AVI files allow more control over 256 palette display settings. That is, for scenessuch as computer generated animations, the animation source images can be designed touse certain non-base palette positions so as to eliminate palette shifting in a program.AVI, depending on encoding size, color depth, compressor, frame encoding rate, andaudio resolution, can have a significantly lower data rate than MPEG. AVI has another

    advantage over encoding via MPEG in that you can set the encoding size. That is, there

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    32/54

    is no "native" size per say. With the right system, you could encode AVI (all bit ahigher data rate) to turn out much better than MPEG

    4.6.4. XVID

    XviD is an open source MPEG-4 video codec library distributed under the terms ofthe GNU General Public License. It emerged to compete the proprietary DivX Procodec, which is placed under license restrictions and therefore is only available formembers of the DivX Advanced Research Centre (DARC).

    XviD codec is intended for compressing video data in order to facilitate and speedup online video data exchange and improve storage on hard disks. The codec is capableof stripping video data of unnecessary junk and ensures higher compression rates.XviD-compressed videos can be 200 times smaller than the source video, with thevisual quality well intact.

    XviD ensures fast compression and exceptional quality video performance andexceeds many expensive similar products. The codec is available for free, and it isincorporated in many hardware devices. The extensive hardware support eases dataexchange between portable, home and other types of devices. There are no feature,testing or time restrictions for XviD, and it can be used safely and conveniently all thetime. Since XviD is open-source software, its source code is available for public review,so anyone can check it and make sure there is no spyware or adware.

    4.6.5. MPEG1

    MPEG (Motion Pictures Experts Group) format video, as we know it, is technicallycalled MPEG-1. The MPEG-1 standard specifies a "native" size of 352x240. Colordepth is in millions (24-bit usually). Using a more advanced compression algorithmthan AVI compressors use, data rates as low as 150KB/sec. can net you 352x240, 30frames per sec., stereo 16-bit 44Khz. audio playback. One drawback of this type of fileis the software required to run it is currently immature and proprietary. Each vendor hasa different set of bugs. Basically, a finished file would have to be "pre-edited" and thenre-encoded. The main advantage of MPEG is high quality video at fairly low data rates.In properly equipped pcs, this is an excellent solution. We can size/position the videoanywhere on the screen in both AVI and MPEG format.

    4.6.6. Formats comparison

    This section compares the advantages and the disadvantages that have these 5elected formats. I have chosen these 5 formats (png, jpeg, avi, Xvid and mpeg1) becausethey are most used nowadays.

    First I will start with the images category: the images in format png have likeadvantage that they are non-lossy files, compressing photographic images withoutdegrading image quality. In other hand, the jpeg format is a standard for professionalphotographers. The two formats, jpeg and png, have become the standard image of the

    internet because they can be compressed so much; but the format png supportstransparency in browsers with an elegance.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    33/54

    Now, I am going to comment on the pros and contras of the video category for theelected formats: avi, Xvid y mpeg1. The advantages of using mpeg1 are: greatcompression and it can deliver full-motion video with relatively small file size. Alsousing a more advanced compression algorithm than avi compressors use and a

    disadvantage: software-based decompression just becoming available to general public.For the format avi, an advantage is: native support on Windows and a disadvantage isthat this format creates large files and also often problems syncing audio with video.With the right system, you could encode AVI (all bit a higher data rate) to turn outmuch better than MPEG. Finally, for the format Xvid: XviD-compressed videos can be200 times smaller than the source video, with the visual quality well intact.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    34/54

    CHAPTER 5

    IMPROVEMENTS, PROBLEMS ANDEXAMPLES

    In this chapter there will be a description of all the improvements made to theapplication as the improvement of the user graphic interface or also throughout thefunctionalities of the application itself. There will also be an explanation of all thedifferent issues. I have encountered when creating some functionalities and theapplication as a whole.

    5.1. Improvements in application

    This section explains the changes and improvements of the application. The firstimprovement is the graphical user interface when the user runs the application inBlender, the first draft of this interface was the one shown in Figure 13.

    In this first draft it can be seen that the user must introduce by hand the full path

    where the .obj files are and where the materials are as well as the user must introducethe name of the files the user want to use to create the animation.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    35/54

    Figure 13. Window graphical user interface of the first draft.

    In the second draft of the Blender interface (see Figure 14) the user can select thepath using a file browser where the .obj files are; also the user can choose the path usinga browser where the materials are and the path to the output file.

    Figure 14. Window graphical user interface of the second draft.

    Another improvement in the application is the subject of efficiency in import figures

    to the scene of Blender. There are two ways to import figures: one is using the BlenderAPI and the other creating a script that reads the vertices and faces of an .obj file. Tomake the measurement of time, I have used functions of the time's library:

    After measuring the time it takes to import the figures of the input files for each of

    the two forms, these durations were obtained and a graph was created (see Figure 15)where the x-axis contains the number of .obj files chosen and the y-axis shows the time

    initiation = time.time()

    # function - import .obj files

    end = time.time()total_time = end - initiation

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    36/54

    in seconds taken for the application to import the files. Therefore, shown in the Figure15 it is clear that more efficient option is import Blender API in blue against the scriptthat reads the positions of the vertices and faces of the figure of an .obj file in red.

    Figure 15. Graphical import 10, 20, 30, 40 and 50 .obj files

    Note: The blue line is not really zero, but these points are pretty small whencompared with the values of the red line. The blue line values are: 0.113, 0.352, 0.562,0.814 and 1.169. All values of unit of time are: seconds.

    5.2. Problems found

    This section discusses the problems encountered in creating the application. Thefirst of the problems is the API of Blender, I had to learn and find information about theAPI at any time to introduce light, material, objects and so on. Another problem that hasbeen constant is the Python programming language, which I have had to read me severalbooks to deepen the Python programming language. I have needed around 3 weeks toread, to learn and to deepening in the comprehension of python, these books that have

    helped me to understand better this programming language are those who are in thebibliography with number [10], [11] and [12].

    Other more specific problems that have emerged only when used, are problems suchas import materials to the scene and apply it to the figure. Another problem is: I couldn'trender the scene and I was thinking that the scene was correct; but the error was that thecamera of the scene was not active.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    37/54

    5.3. Comparisons

    This section I will present a comparison between different input options. I begin toexplain the first comparison is between the output files using one light and three lights,the other input options are the same, it just change the number of lights used.

    Figure 16. Comparison of the use of one light and three lights.

    It is noted in the previous figure (see Figure 16) that the first 8 frames correspond tothe output of the application using only one light for lighting and the remaining 8frames use 3 lamps, ie the method of the three points as described in Section 3.2. Forthis example I compare the time it took to render: for output using one light the averagetime for rendering is 2.65 seconds per frame, in other hand to the output using 3 lampsthe average time for rendering is 4.6 seconds per frame. Therefore and like conclusion,if the user introduces more lights, the render will be slower but with better lighting.

    The next point is to compare the time and quality rendering and size of output filesfor a given set of input data. First compare the quality, size and rendering time fordifferent image formats (png and jpeg).

    Figure 17. Rendering a same frame in JPEG and PNG

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    38/54

    It can be seen in the figure above (see Figure 17) rendering of the same frame fordifferent image output formats. The frame on the left is rendered with JPEG outputformat, which the rendering time was 0.98 seconds and the image size is 16.7KB. Andfor the frame on the right is rendered with PNG output format, which the rendering timewas 0.92 seconds and the image size is 35.3KB. Comparing the results, it appears that

    the rendering time is almost equal, while the size of the PNG format images is morethan double the size of JPEG images. Also the quality of the image PNG is better thatthe image JPEG.

    Now I will compare the different video formats (avi, Xvid and mpeg1). It has beenused for the 3 video formats the same input data are: the material of Water Fresh, a lightand 50 .obj files.

    Figure 18. A table that compares the different video formats.

    In Figure 18 I will show in the table: the rendering time, the output file size andquality of the output file for each video formats. Comparing the results, the above tableshows that the rendering time and file size video are very similar. Instead avi videoformat has worse image quality compared to formats: Xvid and mpeg1. In my opinion

    the best video format of the three is Xvid compared with avi and mpeg1, since in Xvidrendering time is in the midst of rendering time avi and mpeg1. About the size of thefile, the Xvid format is the smaller and in terms of quality the Xvid format gets a highquality image.

    5.4. Examples

    In this section, as its name suggests, will present an example using Blender and

    another example without using Blender.

    5.4.1. Example using Blender

    This section will explain the use of the application using Blender. This first step isto open the application of Blender; the user will load the script in Blender that containsthe functionality of this project. Later the user executes the script in Blender. Now theoptions of our application appear in the Object Tools of the view Default, in otherwords the buttons to create the animation explained in section 4.1.1 Using Blender, thiswindow corresponds to the red square in the Figure 19.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    39/54

    Figure 19. Window of the graphical user interface of the application.

    Now the user introduces the data of input:

    1. The first step is: Select position of the camera (see Figure 20).

    Figure 20. Window to select the number of lights.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    40/54

    2. The second step is: Select the .obj files (see Figure 21).

    Figure 21. Window to select .obj files.

    3. The third step: Select the number of lights (see Figure 22).

    Figure 22. Window to select the number of lights.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    41/54

    4. The fourth step: Choose the path where the materials are (see Figure 23).

    Figure 23. Window to select the path of materials.

    5. The fifth step: Select the type of the material and the output file (see Figure 24).

    Figure 24. Window to select type of material and output file.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    42/54

    6. The sixth step: Select the path of the output file (see Figure 25).

    Figure 25. Window to select the output path.

    7. The seventh step: the last step is pressing the Generate button to generate outputfile (see Figure 26).

    Figure 26. Window to press button: Generate the output file.

    Once the application has generated the output file, we go to the directory where theuser has chosen to save the output files and we see the result (see Figure 27 and Figure28).

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    43/54

    Figure 27. Results of 8 consecutive frames with 1 light and dense clouds texture.

    Figure 28. Results of 8 consecutive frames with 3 lights and wood texture.

    Note: the rendering time of a frame for the result of the Figure 18 is 0.98 seconds /frame. As for the result of the Figure 19 the average of rendering is 4.6 seconds / frame.

    Therefore, the choice of the number of lights and material of an object is very importantin terms of rendering time.

    5.4.2. Example without using Blender

    As explained there are users who do not use Blender and for that we saw in section4.1.2 how to use the application without opening Blender. Now I will show an example.First of all, the user must enter data into a file as explained in section 4.1.2 in this caseincluded the data in a notebook (see Figure 29).

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    44/54

    Figure 29. Example of input file.

    Note: the user must enter input data from any text editor and the user is notnecessary to open Blender because this option is for users who do not use Blender.When I have created the input data file; I open the console. I assume that any readerknows how to open a console. For example, in Windows from Start-> All Programs ->Accessories -> Command Prompt.

    The second step, when the input file is ready and opened the console, the only thingmissing is run the application with the command pattern (see Figure 30) explained inSection 4.1.2.

    Figure 30. Window with the command to run the application without using Blender.

    When the application is completed, I will go to the directory I've chosen to save thefile or output files and see the result for the example in this section in Figure 31.

    # Path of the files

    C:/Users/Calabuig/Desktop/Final Project/test/

    # Name of files

    cylinder

    # Number of files

    50

    # Position X of the Camera0.825

    # Position Y of the Camera

    -0.8

    # Position Z of the Camera

    0.51

    # Lights

    1

    # Path of the Materials

    hotmetal

    # Material

    C:/Users/Calabuig/Desktop/Final Project/Material/

    # Path output

    C:/Users/Calabuig/Desktop/Final Project/Results/# Format outputpng

    Microsoft Windows [Versin 6.1.7601]

    Copyright (c) 2009 Microsoft Corporation. Reservados todos los

    derechos.

    C:\Users\Calabuig>"C:\Program Files\Blender

    Foundation\Blender\blender.exe" -b -

    P applicationFinalCalabuig.py C:\Users\Calabuig\dataInput2.txt

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    45/54

    Figure 31. Results of 8 consecutive frames with 1 light and Hot Metal texture.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    46/54

    CHAPTER 6

    CONCLUSIN

    6.1. ConclusionsIn this work I have studied various aspects with the creation of a tool to render an

    animation in Blender. This has been pursued several objectives named in theintroduction to the study, these objectives are following:

    I. Plan and design a tool to create animation movies.II. Getting a better understanding of basis of computer graphic (such as

    lighting, materials and so on).III. Evaluate the result of rendering and improve the tool if possible.IV. Getting a better understanding of the Python programming language.V. Learning the differences between the different kinds of formats.These objectives have been met throughout the chapters of the work. This report has

    proposed a method for creating an animation for users who typically use Blender andfor users who do not use it. Thus, from the set of input files and of the properties ofoutput file, the application has the ability to render a set of .obj files in to an animationmovie.

    6.2. Future works

    As future lines of work could consider the following:

    Extending the method to be able to have the input files otherformats, not just the .obj format. To improve and optimize the method of creating animation. To can edit the parameters of light: choose color, position, power

    and so on. Being able to setup other parameters such as sky color, raytrace

    versus shadow buffer and so on.

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    47/54

    APPENDIX A. IMPORT FIGURES

    In this part the reader can see the code for the creation of the animation and how toimport .obj files to scene.

    # theFiles contains all the .obj files selected with the path

    theFiles = []

    ifconsole:

    for index in range(1,theNumberFiles):

    theFiles.append(thePathFiles + theFileName + ("%05d" %

    index) + ".obj")

    else:

    for file in theAllFiles:

    theFiles.append(theFilesPath + file.name)

    # Cleaning up the scene first by deleting everything

    bpy.ops.object.select_all(action= 'SELECT')

    bpy.ops.object.delete()

    # The beginning and end of the animation

    startframe = 1

    endframe = len(theFiles)

    # Make a pointer to the current scene

    scene = bpy.data.scenes['Scene']

    # We set the endframe of the animation to be this endframescene.frame_end = endframe

    for index in range(len(theFiles)):

    bpy.ops.import_scene.obj(filepath = theFiles[index])

    # Here all object are selected and joined

    # into one object as shapekeys

    bpy.ops.object.select_all(action= 'DESELECT')

    bpy.ops.object.select_all(action= 'SELECT')

    # This must be done to get the context right

    scene.objects.active = scene.objects['Mesh']

    # Note there is no check to make sure we actually select all.

    # This is a toggle so in theory we could choose none instead

    bpy.ops.object.join_shapes()

    # Make ob a pointer to the active object which should be the one we

    have just made

    ob = bpy.context.active_object

    # Find the one which has the shapekeys(the basis)

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    48/54

    # Run through as many frames as there are keys and set them to 0-1-

    0 for the frame

    # i-1, i, i+1 respectively for the ith shapekey

    for i in range(1, endframe - 1):

    # scene.frame_current = i

    j = i + 1

    k = i - 1name = 'Mesh.%03d' % i

    name2 = 'Mesh.%03d' % j

    name3 = 'Mesh.%03d' % k

    ob.data.shape_keys.key_blocks[name].value = 1.0

    ob.data.shape_keys.key_blocks[name].keyframe_insert( "value",frame =

    (i))

    ifk >= startframe:

    ob.data.shape_keys.key_blocks[name3].value = 0.0

    ob.data.shape_keys.key_blocks[name3].keyframe_insert( "value",frame

    = (i))

    ifj

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    49/54

    APPENDIX B. LIGHTS

    In this part the reader can see the code for the creation of the lights in the sceneusing the method of the three points of light.

    if theLights >= 1:

    # Add lamp into the scene

    bpy.ops.object.lamp_add(type='SPOT', view_align=False,

    location=(-13.21, -16.96, 8.26),

    rotation=(0.941318,0.917498,-1.18762),

    layers=(True, False, False, False,

    False, False,False, False, False, False, False, False, False,

    False, False, False, False, False, False, False))

    lamp1 = bpy.context.object

    # Configure Lighting Setup

    lamp1.name = 'Key'

    lamp1.data.energy = 12.0

    lamp1.data.distance = 30.0

    lamp1.data.spot_size = 1.570797

    lamp1.data.spot_blend =1

    lamp1.data.shadow_method = 'BUFFER_SHADOW'

    lamp1.data.shadow_buffer_type = 'HALFWAY'

    lamp1.data.shadow_filter_type = 'GAUSS'

    lamp1.data.shadow_buffer_soft = 20

    lamp1.data.shadow_buffer_size = 2048

    lamp1.data.shadow_buffer_bias = 1

    lamp1.data.shadow_buffer_samples = 16lamp1.data.use_auto_clip_start = True

    lamp1.data.use_auto_clip_end = True

    iftheLights >= 2:

    bpy.ops.object.lamp_add(type='SPOT', view_align=False,

    location=(-12.85, 19.61, 0.057),

    rotation=(1.53793,1.53793,3.68718),

    layers=(True, False, False, False,

    False, False,False, False, False, False, False, False, False,

    False, False, False, False, False, False, False))

    lamp3 = bpy.context.object

    lamp3.name = 'Spot1'

    lamp3.data.energy = 4.0lamp3.data.distance = 25.0

    lamp3.data.spot_size = 1.396264

    lamp3.data.spot_blend = 1

    lamp3.data.shadow_method = 'BUFFER_SHADOW'

    lamp3.data.shadow_buffer_type = 'HALFWAY'

    lamp3.data.shadow_filter_type = 'GAUSS'

    lamp3.data.shadow_buffer_soft = 10

    lamp3.data.shadow_buffer_size = 2048

    lamp3.data.shadow_buffer_bias = 0.100

    lamp3.data.shadow_buffer_samples = 8

    lamp3.data.use_auto_clip_start = Truelamp3.data.use_auto_clip_end = True

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    50/54

    iftheLights >= 3:

    bpy.ops.object.lamp_add(type='SPOT', view_align=False,

    location=(19.825, -18.28, -0.93),

    rotation=(1.61476, 0.709077, 0.853816),

    layers=(True, False, False, False, False, False,False,

    False, False, False, False, False, False, False, False, False,

    False, False, False, False))lamp2 = bpy.context.object

    lamp2.name = 'Spot2'

    lamp2.data.energy = 12.0

    lamp2.data.distance = 25.0

    lamp2.data.spot_size = 1.047198

    lamp2.data.spot_blend = 1

    lamp2.data.shadow_method = 'BUFFER_SHADOW'

    lamp2.data.shadow_buffer_type = 'HALFWAY'

    lamp2.data.shadow_filter_type = 'GAUSS'

    lamp2.data.shadow_buffer_soft = 5

    lamp2.data.shadow_buffer_size = 2048

    lamp2.data.shadow_buffer_bias = 0.100

    lamp2.data.shadow_buffer_samples = 16lamp2.data.use_auto_clip_start = Truelamp2.data.use_auto_clip_end = True

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    51/54

    APPENDIX C. MATERIALS

    In this part the reader can see the code to import the materials that can be used bydefault, described in Section 3.3.

    # Finally, selecting the mesh

    bpy.ops.object.select_name(name= "Mesh")

    ob = bpy.context.active_object

    # Add a slot for the material

    bpy.ops.object.material_slot_add()

    # Choose the material

    ifmaterials == 'none':

    print( "No material" )

    if materials == 'water':

    bpy.ops.wm.link_append(filepath = thePathMaterials +

    "water_fresh_water.blend/", directory = thePathMaterials +

    "water_fresh_water.blend/Material/" ,link=False, filename="water")

    ob.active_material = bpy.data.materials['water']

    ifmaterials == 'wood':

    bpy.ops.wm.link_append(filepath = thePathMaterials +

    "wood_varnished_wood.blend/",directory = thePathMaterials +

    "wood_varnished_wood.blend/Material/" , link=False,

    filename="Vanished_Wood")ob.active_material = bpy.data.materials['Vanished_Wood']

    ifmaterials == 'amber':

    bpy.ops.wm.link_append(filepath = thePathMaterials +

    "amber.blend/",directory=thePathMaterials +

    "amber.blend/Material/",link=False, filename="amber")

    ob.active_material = bpy.data.materials['amber']

    ifmaterials == 'clouds':

    bpy.ops.wm.link_append(filepath = thePathMaterials +

    "dense_clouds.blend/",directory = thePathMaterials +

    "dense_clouds.blend/Material/",link=False,

    filename="dense_clouds")ob.active_material = bpy.data.materials['dense_clouds']

    ifmaterials == 'fireball':

    bpy.ops.wm.link_append(filepath = thePathMaterials +

    "fireball.blend/",directory = thePathMaterials +

    "fireball.blend/Material/", link=False, filename="fireball")

    ob.active_material = bpy.data.materials['fireball']

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    52/54

    ifmaterials == 'bronzeMetal':

    bpy.ops.wm.link_append(filepath = thePathMaterials +

    "bronze_voronoi.blend/",directory = thePathMaterials +

    "bronze_voronoi.blend/Material/" ,link=False, filename="Bronze

    Voronoi")

    ob.active_material = bpy.data.materials['Bronze Voronoi']

    ifmaterials == 'crystal':

    bpy.ops.wm.link_append(filepath = thePathMaterials +

    "crystal.blend/",directory = thePathMaterials +

    "crystal.blend/Material/",link=False, filename="Crystal")

    ob.active_material = bpy.data.materials['Crystal']

    ifmaterials == 'hotmetal':

    bpy.ops.wm.link_append(filepath = thePathMaterials +

    "red_hot_metal.blend/",directory = thePathMaterials +

    "red_hot_metal.blend/Material/" ,

    link=False, filename="Red Hot Metal")

    ob.active_material = bpy.data.materials['Red Hot Metal']

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    53/54

    BIBLIOGRAPHY

    [1] Blender. [Online]http://es.wikipedia.org/wiki/Blender

    [2] Dean Leffingwell. Agile Software Requirements.Addison-Wesley, Pearson Edutacion. 2011.

    [3] Blender. [Online]http://wiki.blender.org/index.php/Doc:2.4/Books/Essential_Blender/11.2.Lightin

    g:_Discussion

    [4] Blender Materials. [Online]http://matrep.parastudios.de/

    [5] Sintesis de Imagen, Blender 3D. [Online]http://www.esi.uclm.es/www/cglez/fundamentos3D/index.html

    [6] Blender. Chapter 11: Lighting. [Online]http://wiki.blender.org/index.php/Doc:2.4/Books/Essential_Blender/11.1.Lighting:_Hands_on

    [7] Carsten Wartmann. Blender Book: Free 3D Graphics Software for the Web andVideo. Linux Journal Express. 2000.

    [8] Jason van Gumster. Blender For Dummies.Wiley Publishing, Inc. 2009.

    [9] Allen Downey, Jeffrey Elkner and Chris Meyers. Aprenda a pensar como unprogramador con Python. Wellesley. 2002.

    [10] Magnus Lie Hetland. Beginning Python: From Novice to Professional.

    Apress, Second Edition. 2008.

    [11] Raul Gonzalez. Python para todos. Creative Commons Reconocimiento 2.5.Edition Kindle. 2011.

    [12] Mark Lutz. Learning Python.OReilly Media, Third Edition. 2008.

    [13] Blender. Output. [Online]http://wiki.blender.org/index.php/Doc:2.4/Manual/Render/Output

    [14] Blender Artists. [Online]http://blenderartists.org/forum/index.php

  • 8/14/2019 Final Project Blender batch rendering of liquid surfaces

    54/54

    [15] Difference jpeg and png. [Online]http://www.howtogeek.com/howto/30941/whats-the-difference-between-jpg-png-and-gif/

    [16] Peter Symes. Digital Video Compression.

    Kindle Edition. 2003.

    [17] All about multimedia. [Online]http://www.webdeveloper.com/multimedia/multimedia_qa.html

    [18] Blender. Output. [Online]http://wiki.blender.org/index.php/Doc:2.4/Manual/Render/Output