Posts

Your First Blender Script

Image
For this series I will present a script, walk through it line-by-line, display the results, and then include the full script. Import the libraries import bpy import math import mathutils import os Each of these statements imports one of the python scripts that are needed for what follows. bpy accesses all of the Blender libraries. math and mathutils provide access to a pair of math libraries. os is a wrapper for your operating system. Reset the environment bpy.ops.wm.read_factory_settings(use_empty=True) This statement sets the environment back to the "factory defaults" so that we can safely assume what the environmental settings are. Create the materials In Blender terminology, a material is an object which defines the color, reflectivity, etc. of an object and also selects the code which will be used for rendering these properties. The bits of code which do this are called shaders . Here we define a function that creates a single material object, bestows ...

Getting Started with Blender Scripting

Installation Blender, like many applications, requires that it be downloaded and installed. Easy enough. The latest version is always freely available at www.blender.org . Just follow the links. While installing Blender, be sure to note the installation folder so that you can add it to the system path later. Add Blender's folder to your PATH variable Once you have downloaded and installed Blender, you will need to add it to your environmental path. I found perfectly useful instructions for Windows here . Add the installation folder for Blender here. Test the installation Once you have done this, open up a command prompt and change directory to your Documents folder. This will usually be as easy as cd Documents . Enter the command blender -b -P dummy.py Be sure that -b is lower case and that -P is upper case. If this results in an error that the file dummy.py could not be found, everything is working correctly and you can go on to the next article. If you get any other er...

A New Beginning

It's been a few years since my last post, and in that time I've not done much POV-Ray work of any kind. I've tried my hand with Blender a few times, and each time I went away frustrated because the interface takes a college degree's worth of studying to learn. I ain't got time for that. It turns out that Blender has an entirely separate interface: Script files. My reasons for jumping ship are two-fold. First, POV-Ray is based on a rendering approach that does not incorporate the advances in rendering that have taken place in the past thirty years (with the exception that if the system has a multi-core CPU, POV-Ray will make use of it). Second, POV-Ray is not well-designed for modelling organic shapes, unless those shapes are amenable to procedural generation; but if you want to make realistic-looking humans or animals, you're out of luck. As a long-time POV-Ray scripter (30 years), I expect that a lot of the skills I developed for POV-Ray will carry over with...

Titling Made Simple

Titling is an important part of any animation. Well-done titling adds a touch of professionalism to your work. There are a lot of instances in which you will want to have some kind of titling in your POV-Ray scenes. There are two approaches you can employ to add titling: In-scene titling and post-processed titling. In-scene Titling The first approach has the advantage that it requires only one render. Its disadvantages are: The artist has to make sure that the other scene elements do not obscure the titling; If the titling is changed then the scene has to be entirely re-rendered; The method does not work well (if at all) in scenes where there is a camera effect in place (such as focal blur). In my earlier post about the main scene file , I invoke the scenery file and the titling file separately, so that the scenery file can specify the basic camera parameters, and the latter file can use these settings to place the titling exactly where it needs to be to appear in the re...

A Simple Button Macro

If your animations include a lot of science fiction work, or other instances where a push button is part of the scene, this short macro will do a bit of the work for you. #macro RoundButton(pB, pT, rB, rE, dD, fM) #local hB = vlength(pT - pB); #local vY = vnormalize(pT - pB); #local vX = vnormalize(vcross(vY, <vY.y,vY.z,-vY.x>)); #local vZ = vnormalize(vcross(vX, vY)); #if (fM) merge #else union #end { #if (dD < 0) #local rD = (2 * rB * rE - rB * rB - rE * rE - dD * dD) / 2 / dD - rE; difference { lathe { 5, <0,0>, <rB,0>, <rB, hB - rE>, <rB - rE, hB - rE>, <0, hB + rD + dD> } sphere { y * (hB + rD + dD), rD } bounded_by { cylinder { 0, y * hB, rB } } } #elseif (dD > 0) #local hB = hB - dD; #local rD = (rB * rB + rE * rE + dD * dD - 2 * rB * rE) / 2 / dD + rE; intersection { lathe { 6, <0,0>, <rB,0>, <rB, hB - rE>, <rB - rE, hB - rE>, <...

Motion Paths

A lot of animation involves moving either a character or the camera along a path through the scene, and so I'll provide a set of macros for defining a path. Some Helper Macros To make the code that follows a lot neater, I'll be using the following helper macros: #macro LinePoly(sVariable, sConstant, sLinear) (sLinear * sVariable + sConstant) #end #macro QuadPoly(sVariable, sConstant, sLinear, sQuadratic) ((sQuadratic * sVariable + sLinear) * sVariable + sConstant) #end #macro CubePoly(sVariable, sConstant, sLinear, sQuadratic, sCubic) (((sCubic * sVariable + sQuadratic) * sVariable + sLinear) * sVariable + sConstant) #end Continuity As with the macros that I provided in the last article, a motion path can have multiple levels of continuity, some of which are only necessary for specific applications. C 0 Continuity The minimal level of continuity is C 0 , which means that there are no open gaps in the path, but otherwise the motion is as simple as possible. Th...

Transition Macros

As part of my animation work I have a set of macros which simplify moving objects from one location to another, or in some other way allow me to transition an object from one state to another. Linear Changes There are going to be times when you want to fade a scene to black or from black, or fade between two scenes. You will want things to be at a starting state up until the motion or change begins, and for it to be at a certain place when the motion ends, and for it to stay there, and for the movement in between those times to occur at a steady rate. When that is the case, a macro like the following will come in handy: #macro Transition(tNow, tStart, pStart, tEnd, pEnd) #if (tNow <= tStart) (pStart) #elseif(tNow >= tEnd) (pEnd) #else (pStart + (pEnd - pStart) * (tNow - tStart) / (tEnd - tStart)) #end #end Call this macro with the parameters set to the following values: tNow : Set this to the current time of the animation (or the time for which you ...