What would be the logic for a text renderer?

Hi,

I am in need of a way to automate the rendering of titles and I want to use the logic editor to run a process of loading text files and rendering the result to specified folders. I have been told this can be done with the logic editor but so far I can’t find any information on how to automate file/text reading and image rendering. Does anyone have any ideas on how to go about doing this? I was hoping to keep the python stuff down to a minimum.

Cheers all.

OK sofar this is what I have got.
It will get the text ( itself ) into the 3D view. But I can’t get it to render.

import bpy

bpy.ops.text.to_3d_object(split_lines=False)
bpy.context.scene.render.filepath = “C:\TestRender”
bpy.context.scene.render.resolution_x = 800 #perhaps set resolution in code
bpy.context.scene.render.resolution_y = 600
bpy.ops.render.render()

Ah ha…

I found this …

delete any meshes or text in the current drawing

def removeObjects( scn ):
for ob in scn.objects:
if ob.type == ‘FONT’ or ob.type == ‘MESH’:
scn.objects.unlink( ob )
scn = bpy.context.scene
removeObjects( scn )

create several materials - each text line will use a different material

def makeMaterial(name, diffuse, specular, alpha):
mat = bpy.data.materials.new(name)
mat.diffuse_color = diffuse
mat.diffuse_shader = ‘LAMBERT’
mat.diffuse_intensity = 1.0
mat.specular_color = specular
mat.specular_shader = ‘COOKTORR’
mat.specular_intensity = 0.5
mat.alpha = alpha
mat.ambient = 1
return mat

def setMaterial(ob, mat):
me = ob.data
me.materials.append(mat)

red = makeMaterial(‘Red’, (1, 0, 0), (1, 1, 1), 1)
blue = makeMaterial(‘BlueSemi’, (0, 0, 1), (1, 1, 1), 0.5)
green = makeMaterial(‘GreenSemi’, (0, 1, 0), (1, 1, 1), 0.5)
yellow = makeMaterial(‘YellowSemi’, (1, 1, 0), (1, 1, 1), 0.5)

Create and name TextCurve object #1

bpy.ops.object.text_add(
location=(-3, 0, 3.6),
rotation=(pi/2, 0, 0))
ob = bpy.context.object
ob.name = ‘Text1’

TextCurve attributes

ob.data.name = ‘TextData1’
ob.data.body = “THREE.JS”
fnt = bpy.data.fonts.load(‘C:\Windows\Fonts\Impact.ttf’)
ob.data.font = fnt
ob.data.size = 2.75

Inherited Curve attributes

ob.data.bevel_depth = 0.1
ob.data.bevel_resolution = 5
ob.data.extrude = 0.5
setMaterial(ob, red)
bpy.ops.object.convert(target=‘MESH’, keep_original=False)

Create and name TextCurve object #2

bpy.ops.object.text_add(
location=(-3, 0, 1.6),
rotation=(pi/2, 0, 0))
ob = bpy.context.object
ob.name = ‘Text2’

TextCurve attributes

ob.data.name = ‘TextData2’
ob.data.body = “TEXT”
fnt = bpy.data.fonts.load(‘C:\Windows\Fonts\Georgia.ttf’)
ob.data.font = fnt
ob.data.bevel_depth = 0.1
ob.data.bevel_resolution = 5
ob.data.size = 3

Inherited Curve attributes

ob.data.extrude = 0.5
setMaterial(ob, green)
bpy.ops.object.convert(target=‘MESH’, keep_original=False)

Create and name TextCurve object #3

bpy.ops.object.text_add(
location=(-3, 0, 0),
rotation=(1.51, 0, 0))
ob = bpy.context.object
ob.name = ‘Text3’

TextCurve attributes

ob.data.body = “DEMO”
ob.data.name = ‘TextData3’
fnt = bpy.data.fonts.load(‘C:\Windows\Fonts\coopbl.ttf’)
ob.data.font = fnt
ob.data.bevel_depth = 0.1
ob.data.bevel_resolution = 5
ob.data.size = 2.32

Inherited Curve attributes

ob.data.extrude = 0.5
setMaterial(ob, yellow)
bpy.ops.object.convert(target=‘MESH’, keep_original=False)

Unfortunately the logic editor works only for the game engine mode (when you press P and go to game mode). Otherwise you will have to everything with Python scripting instead. The first approach is this:

Note: Have a text object in your scene called “Text” and focus the camera on it.



import bpy


def getTextObject():
    return bpy.context.scene.objects["Text"]


def changeText(object, text):
    object.data.body = text


def startRenderSequence(object, items, destination):
    counter = 0
    for i in items:
        changeText(object, i)
        renderImage(destination, "Image"+str(counter))
        counter += 1
        
def renderImage(directory, filename):
    bpy.ops.render.render()
    filepath = directory + "\\" + filename + ".png"
    bpy.context.scene.render.filepath = filepath
    bpy.ops.render.render(use_viewport = True, write_still=True)
    
def run():
    ob = getTextObject()    
    items = ["One", "Two", "Three", "Four", "Five"]
    startRenderSequence(ob, items, "C:\\Test")


run()
    


After that you will have to figure out what texts you want to render and which folders are going to.

Thanks const,

That is going to go a long way in helping me get what I am after.

Great!

Cheers! :slight_smile: