Archive for Python and Blender

Compiling Python problem and solution, Centos 5, Python 2.5.1

Trying to install an alternate copy of python than that which ships with Centos5 (Why do these package installers not rpm or yum the latest version?? Please can someone tell me!).

The first is to run ./configure

Then if you run make it will break with make: *** [libinstall] Error 1
The solution then is to edit ./Modules/Setup.dist and comment out line 180
rerun with make altinstall to not make it the default.

Leave a Comment

Missing libraries, fixing with yum and rpm, trying to make Blender work.

Blender runs pretty well in a cygwin x-windows shell (so far anyway). Getting Blender to actually work on my generic Centos 5 install was excruciating.

To find out what is missing from a system that will prevent an application from running use ldd as in the following example for the blender executable
[root@styx blender-2.45-linux-glibc236-py24-i386]# ldd blender | grep “not found”
libopenal.so.0 => not found
libalut.so.0 => not found
libSDL-1.2.so.0 => not found

Then to install packages:

[root@styx blender-2.45-linux-glibc236-py24-i386]# yum install libSDL-1.2.so.0
Loading “installonlyn” plugin
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
–> Populating transaction set with selected packages. Please wait.
—> Downloading header for SDL to pack into transaction set.
SDL-1.2.10-8.el5.i386.rpm 100% |=========================| 12 kB 00:00
—> Package SDL.i386 0:1.2.10-8.el5 set to be updated
–> Running transaction check

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
SDL i386 1.2.10-8.el5 base 233 k

Transaction Summary
=============================================================================
Install 1 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 233 k
Is this ok [y/N]: y
Downloading Packages:
(1/1): SDL-1.2.10-8.el5.i 100% |=========================| 233 kB 00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: SDL ######################### [1/1]

Installed: SDL.i386 0:1.2.10-8.el5
Complete!

Getting Blender working
The above mentioned package via, yum install libSDL-1.2.so.0
rpm -i /mnt/dante/everyone/openal-0.0.8-1.i586.rpm
rpm -i /mnt/dante/everyone/libalut-1.1.0-alt1.2.i586.rpm

Leave a Comment

Blender code to make a cube into red tinted glass

I wanted a glass floor between two datacentres so I could see the servers in the room below also. I put a slight red tint in the glass for effect. The greens sphere and blue cube are sticking out from behind the slice of glass. Theres a rock thing in front of the glass. A lamp shines from above which is casting a shadow on a screen behind.

glassdemo.jpg

Warning to newbies:

Make sure to show the outliner and refresh when you have run the code. Can be a pain in the backside trying to apply materials etc. to objects. The outliner shows whats going on.

import Blender
import math
from math import *
import Blender

from Blender import NMesh, Material

myCube = Blender.Object.Get(‘Cube’) #default cube, might as well use it. I resized it to make it more like a pain of glass

me=NMesh.GetRaw(‘Cube’)

“”"
diffuseColor 0.9324847 0.94625 0.9620039
ambientIntensity 0.1666667
specularColor 1.2298402 1.2298402 1.2298402
emissiveColor 0.0 0.0 0.0
shininess 0.7050781
transparency 0.8981037

“”"
#Set up materials
me.materials = [] # remove any exisiting materials (just for clarification)

mat_glassfloors=Material.New(‘glass’)
mat_glassfloors.setRGBCol(0.46,0,0) # dash of red
mat_glassfloors.setAlpha(0.3) # mat.alpha = 0.3 — almost transparent
mat_glassfloors.mode |= Material.Modes.ZTRANSP
me.addMaterial(mat_glassfloors)

me.update()
Blender.Redraw()

Leave a Comment

Handling Tuples in Python

Where farm1 is a Blender object , a tuple is like an array of typed data

WLH = farm1.getSize()
print “WLH = ” , WLH  # here we can see the list of reals
print “X is ” , XYZ[0]   # which are returned in order x,y,z
x = – WLH[0] / 0.2
y = – WLH[1] / 0.2

Leave a Comment

Making an object a parent in Blender and Python

Where farm1 is an instance of a blender object and the object name begins with the string ’seso’, farm1 is made the parent of all the objects

obs = [ob for ob in scn.objects if ob.name[0:4] == ’seso’]
scn.objects.selected = obs
for ob in obs:

print ob.name
farm1.makeParent(obs)

Leave a Comment

Creating a new lamp and camera

Two basic functions to create a camera and lamp

def newCamera():

cam = Blender.Camera.New(‘ortho’) # make ortho camera data object
ob = scn.objects.new(cam) # make a new object in this scene using the camera data
ob.setLocation (0.0, -5.0, 10.0) # position the object in the scene

def newLamp():

lamp = Blender.Lamp.New(‘Spot’)
ob = scn.objects.new(lamp)
ob.setLocation (0.0,-4.0,15)

Leave a Comment

XML Support (with minidom)

import Blender
from Blender import *
from xml.dom import minidom
global xmldoc
def load_xml(filename):

xmldoc=minidom.parse(filename)

#main
load_xml(“c:\somefile.xml”)

Leave a Comment