| 1 |
# A blender modelling script |
|---|
| 2 |
# Generates a logo |
|---|
| 3 |
# |
|---|
| 4 |
# Usage: blender -P scene-model.py |
|---|
| 5 |
# |
|---|
| 6 |
# Conrad Parker <conrad@metadecks.org> |
|---|
| 7 |
# October 16, 2006 |
|---|
| 8 |
|
|---|
| 9 |
import math |
|---|
| 10 |
import sys |
|---|
| 11 |
import Blender as B |
|---|
| 12 |
|
|---|
| 13 |
# Set up the scene |
|---|
| 14 |
scene = B.Scene.New('MyScene') |
|---|
| 15 |
scene.makeCurrent() |
|---|
| 16 |
print 'Current scene name is ', scene.name |
|---|
| 17 |
|
|---|
| 18 |
# Create a camera |
|---|
| 19 |
cam_obj = B.Object.New('Camera') |
|---|
| 20 |
cam_data = B.Camera.New('ortho') |
|---|
| 21 |
cam_obj.link(cam_data) |
|---|
| 22 |
scene.link(cam_obj) |
|---|
| 23 |
# position object |
|---|
| 24 |
cam_obj.loc = (0, 0, 3) |
|---|
| 25 |
# rotate camera to look towards origin |
|---|
| 26 |
r = math.radians(90) |
|---|
| 27 |
cam_obj.rot = (0, 0, 0) |
|---|
| 28 |
|
|---|
| 29 |
# Create a lamp |
|---|
| 30 |
lamp_obj = B.Object.New('Lamp') |
|---|
| 31 |
lamp_data = B.Lamp.New('Lamp') |
|---|
| 32 |
lamp_obj.link(lamp_data) |
|---|
| 33 |
scene.link(lamp_obj) |
|---|
| 34 |
# position object |
|---|
| 35 |
lamp_obj.loc = (0, 0, 10) |
|---|
| 36 |
|
|---|
| 37 |
############################################################ |
|---|
| 38 |
# Now, make some texty logo thing |
|---|
| 39 |
|
|---|
| 40 |
txt = B.Text3d.New('Logo3d') |
|---|
| 41 |
txt.setExtrudeDepth(0.1) |
|---|
| 42 |
txt.setExtrudeBevelDepth(0.03) |
|---|
| 43 |
txt.setBevelAmount(10) |
|---|
| 44 |
|
|---|
| 45 |
txt.setAlignment(B.Text3d.MIDDLE) |
|---|
| 46 |
txt.setText("Pants") |
|---|
| 47 |
|
|---|
| 48 |
txt_obj = B.Object.New('Text', 'Logo') |
|---|
| 49 |
txt_obj.link(txt) |
|---|
| 50 |
scene.link(txt_obj) |
|---|
| 51 |
txt.loc = (0, 0, 0) |
|---|
| 52 |
|
|---|
| 53 |
############################################################ |
|---|
| 54 |
# Set up a script and scriptlink it to frame change |
|---|
| 55 |
|
|---|
| 56 |
t = B.Text.Load('step.py') |
|---|
| 57 |
t.setName('StepScript') |
|---|
| 58 |
txt_obj.addScriptLink('StepScript', 'FrameChanged') |
|---|
| 59 |
|
|---|
| 60 |
############################################################ |
|---|
| 61 |
# Redraw the scene |
|---|
| 62 |
|
|---|
| 63 |
#B.Redraw(-1) |
|---|
| 64 |
|
|---|
| 65 |
# Some random debugging stuff |
|---|
| 66 |
#for i in scene.getChildren(): |
|---|
| 67 |
# print i.name |
|---|
| 68 |
|
|---|
| 69 |
############################################################ |
|---|
| 70 |
# Render |
|---|
| 71 |
|
|---|
| 72 |
# from http://en.wikibooks.org/wiki/Blender_3D:_Blending_Into_Python/Cookbook#Render_to_a_dir |
|---|
| 73 |
|
|---|
| 74 |
# recursive dir creation. |
|---|
| 75 |
def _mkdir(newdir): |
|---|
| 76 |
import os, sys |
|---|
| 77 |
"""works the way a good mkdir should :) |
|---|
| 78 |
- already exists, silently complete |
|---|
| 79 |
- regular file in the way, raise an exception |
|---|
| 80 |
- parent directory(ies) does not exist, make them as well |
|---|
| 81 |
""" |
|---|
| 82 |
if os.path.isdir(newdir): |
|---|
| 83 |
pass |
|---|
| 84 |
elif os.path.exists(newdir): |
|---|
| 85 |
raise OSError("a file with the same name as the desired " \ |
|---|
| 86 |
"dir, '%s', already exists." % newdir) |
|---|
| 87 |
else: |
|---|
| 88 |
head, tail = os.path.split(newdir) |
|---|
| 89 |
if head and not os.path.isdir(head): |
|---|
| 90 |
_mkdir(head) |
|---|
| 91 |
#print "_mkdir %s" % repr(newdir) |
|---|
| 92 |
if tail: |
|---|
| 93 |
os.mkdir(newdir) |
|---|
| 94 |
|
|---|
| 95 |
path="/tmp/renderfarm/render" |
|---|
| 96 |
|
|---|
| 97 |
# Should probably create the paths if not existing. |
|---|
| 98 |
_mkdir(path) |
|---|
| 99 |
|
|---|
| 100 |
scene= B.Scene.GetCurrent() |
|---|
| 101 |
context = scene.getRenderingContext() |
|---|
| 102 |
context.setRenderPath(path) |
|---|
| 103 |
context.setImageType(B.Scene.Render.PNG) |
|---|
| 104 |
context.enableExtensions(1) |
|---|
| 105 |
|
|---|
| 106 |
context.renderAnim() |
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
############################################################ |
|---|
| 110 |
B.Quit() |
|---|