import Blender
from Blender import *
import os
pi = 3.1415926535897932384626433832795
#############################################################
# GLOBALS #
#############################################################
VERSION ='0.0.2'
EVENTHASH = {
'NOEVENT': 1,
'REDRAW': 2,
'EXIT': 3,
'DO': 4
}
## Get scene data
cur = Scene.getCurrent()
## Get the current image render context
cntx = cur.getRenderingContext()
## Get the current frame
fra = Blender.Get('curframe')
## Get the current start and end frames
fr1 = cntx.startFrame()
fr2 = cntx.endFrame()
## Get the render path
pth1 = cntx.getRenderPath()
## Get aspect ratio
asp1 = cntx.aspectRatioX()
asp2 = cntx.aspectRatioY()
## Get image size
cntx1 = cntx.imageSizeX()
cntx2 = cntx.imageSizeY()
## Get camera settings functions
CamO = cur.getCurrentCamera()
CamG = CamO.getData()
## Get the camera angles
ang1 = CamO.getEuler()
## Get the lens value as it is
Cam1 = CamG.getLens()
DATAHASH = {
'SIZE': Draw.Create(100),
'FRAME': Draw.Create(fra),
'NAME': Draw.Create(pth1),
'TYPE': Draw.Create(2)
}
##
##
## Set everything
##
##
def RenderIt():
cntx.setRenderPath(DATAHASH['NAME'].val)
if (DATAHASH['TYPE'] == 1):
cntx.setImageType(Scene.Render.JPEG)
ext = '.jpg'
elif (DATAHASH['TYPE'] == 2):
cntx.setImageType(Scene.Render.PNG)
ext = '.png'
else:
cntx.setImageType(Scene.Render.TARGA)
ext= '.tga'
## disable extensions
cntx.enableExtensions(0)
## Set the aspect ratio
cntx.aspectRatioX(1)
cntx.aspectRatioY(1)
## Set the image render size
cntx.imageSizeX(DATAHASH['SIZE'].val)
cntx.imageSizeY(DATAHASH['SIZE'].val)
## Set the lens to 16.0
CamG.setLens(16.0)
## Set the start and end frames
cntx.startFrame(DATAHASH['FRAME'].val)
cntx.endFrame(DATAHASH['FRAME'].val)
#########################firts anim################################
## Set the render path
pth2 = (pth1 + '1')
cntx.setRenderPath(pth2)
## Set the camera angle
CamO.setEuler(pi/2,0.,0.)
cntx.renderAnim()
oldname = (pth2 +'0011')
newname = (pth2 + ext)
print oldname
print newname
os.rename(oldname, newname)
##########################second anim##################################
## Set the render path
pth2 = (pth1 + '2')
cntx.setRenderPath(pth2)
## Set the camera angle
CamO.setEuler(pi/2,0.,-pi/2)
cntx.renderAnim()
##########################third anim##################################
## Set the render path
pth2 = (pth1 + '3')
cntx.setRenderPath(pth2)
## Set the camera angle
CamO.setEuler(pi/2,0.,-pi)
cntx.renderAnim()
##########################fourth anim##################################
## Set the render path
pth2 = (pth1 + '4')
cntx.setRenderPath(pth2)
## Set the camera angle
CamO.setEuler(pi/2,0.,-3*pi/2)
cntx.renderAnim()
##########################fifth anim##################################
## Set the render path
pth2 = (pth1 + '5')
cntx.setRenderPath(pth2)
## Set the camera angle
CamO.setEuler(pi,0.,0.)
cntx.renderAnim()
##########################fifth anim##################################
## Set the render path
pth2 = (pth1 + '6')
cntx.setRenderPath(pth2)
## Set the camera angle
CamO.setEuler(0.,0.,0.)
cntx.renderAnim()
## Set the aspect ratio back to it's original setting
cntx.aspectRatioX(asp1)
cntx.aspectRatioY(asp2)
## Set the image render size back to it's original setting
cntx.imageSizeX(cntx1)
cntx.imageSizeY(cntx2)
## Set the lens back to it's original setting
CamG.setLens(Cam1)
## set the start and end frames back to their original settings
cntx.startFrame(fr1)
cntx.endFrame(fr2)
## Set the render path back to its original setting
cntx.setRenderPath(pth1)
## Set the camera angle back to it's original setting
CamO.setEuler(ang1)
## enable extensions
cntx.enableExtensions(1)
#############################################################
# MAIN WINDOW #
#############################################################
def MainWindow():
global EVENTHASH,VERSION
global DATA
#############################################################
# Backgrounds #
#############################################################
BGL.glClearColor(0.5, 0.5, 0.5, 0.0)
BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
BGL.glColor3f(0, 0, 0) # Black
BGL.glRectf(2, 2, 482, 520)
BGL.glColor3f(0.48, 0.4, 0.57) # Light Purple
BGL.glRectf(4, 479, 480, 510)
BGL.glRectf(4, 34, 480, 450)
BGL.glColor3f(0.3, 0.27, 0.35) # Dark purple
BGL.glRectf(4, 451,480, 478)
BGL.glRectf(4, 4, 480, 33)
#############################################################
# Common Header #
#############################################################
BGL.glColor3f(0.9, 0.8, 1)
BGL.glRasterPos2d(10, 500)
Draw.Text("BGC - Blender Go Cube v. "+VERSION)
BGL.glRasterPos2d(10, 484)
Draw.Text("(C) Feb 2005 Stefano Selleri <a.k.a. S68>")
Draw.Button("Exit", EVENTHASH['EXIT'], 407, 482, 70, 24)
Draw.Button("GENERATE", EVENTHASH['DO'], 7, 7, 470, 24)
BGL.glColor3f(0.9, 0.9, 0.9)
#############################################################
# Screen #
#############################################################
BGL.glRasterPos2d(10, 425)
Draw.Text("Rendering Parameters:")
DATAHASH['SIZE'] = Draw.Slider(
"Image size: ", EVENTHASH['NOEVENT'], 20, 400, 250, 18,
DATAHASH['SIZE'].val, 4, 10000, 0,
"The image will be a square")
DATAHASH['FRAME'] = Draw.Slider(
"Frame: ", EVENTHASH['NOEVENT'], 20, 380, 250, 18,
DATAHASH['FRAME'].val, 4, 10000, 0,
"The frame you want to render")
DATAHASH['NAME'] = Draw.String(
"Path: ", EVENTHASH['NOEVENT'], 20, 360, 250, 18,
DATAHASH['NAME'].val, 128,
"You need a full path and an image name without extension")
types = "Image type %t|JPG %x1|PNG %x2|Targa %x3"
DATAHASH['TYPE'] = Draw.Menu(types, EVENTHASH['NOEVENT'],
20, 340, 250, 18, 2, "Images will be this type")
#############################################################
# Graphics #
#############################################################
def draw():
MainWindow()
#############################################################
# Event Handler #
#############################################################
def event(evt, val):
if (evt== Draw.QKEY and not val):
Draw.Exit()
def bevent(evt):
global EVENTHASH
if (evt == EVENTHASH['EXIT']):
print 'EXIT'
Draw.Exit()
elif (evt == EVENTHASH['DO']):
RenderIt()
Draw.Redraw()
#############################################################
# Registering all functions #
#############################################################
Draw.Register(draw, event, bevent)
This is what I have so far, but the drop down menu for image types doesn’t work yet