суббота, 24 апреля 2010 г.

Стул в Blender из скрипта на python

Задача
Нарисовать стул в Blender из скрипта на python.
Решение
from Blender import *

# Clean scene
def newactivescene():
    sc = Scene.New()
    oldsc = Scene.GetCurrent()
    sc.makeCurrent()
    Scene.Unlink(oldsc)
    return sc

sc = newactivescene()

# Camera
camera = Camera.New()
camob = Object.New('Camera')
camob.link(camera)
sc.link(camob)
camob.setLocation(3.5,-5,5.8)
camob.setEuler(60*2*3.14/360,0,30*2*3.14/360)
sc.setCurrentCamera(camob)

# Lamp
lamp = Lamp.New('Sun')
lampob = Object.New('Lamp')
lampob.link(lamp)
sc.link(lampob)
lampob.setLocation(2,-2.5,7)
lampob.setEuler(60*2*3.14/360,0,30*2*3.14/360)

# Legs height, weight
height = 1.9
weight = 1.8
# Legs
sc.objects.new(Mesh.Primitives.Cylinder(100,0.5,height)).\
setLocation(-weight/2,weight/2,height/2)
sc.objects.new(Mesh.Primitives.Cylinder(100,0.5,height)).\
setLocation(weight/2,weight/2,height/2)
sc.objects.new(Mesh.Primitives.Cylinder(100,0.5,height)).\
setLocation(weight/2,-weight/2,height/2)
sc.objects.new(Mesh.Primitives.Cylinder(100,0.5,height)).\
setLocation(-weight/2,-weight/2,height/2)
# Seat
sc.objects.new(Mesh.Primitives.Plane(weight+0.5)).\
setLocation(0,0,height)
# The back of
ob = sc.objects.new(Mesh.Primitives.Plane(weight+0.5))
ob.setLocation(0,(weight+0.5)/2,height+(weight+0.5)/2)
ob.setEuler(90*2*3.14/360,0,0)

Window.RedrawAll()


Пример
Выполнить python-скрипт в Blender можно несколькими способами, один из них (linux):
$ blender -P scriptname.py


Ссылки

Комментариев нет:

Отправить комментарий