I'm a complete beginner in Blender and Python Scripting so I apologize in advance for the fuzzy requests. I have a class that contains a name, a position (x,y) and a time t, and I would like to be able to show a text displaying this name at a particular (x,y,0) position at time frame t. I would like this text to appear and disappear progressively, so I thought about creating a text object along the whole timeline, set its transparency to zero except during some time interval around t where it would be a triangle function with maximum 1 at t.

After a bit of reading, I understood that usually a handler function is to be defined and then has to be registered in the, say, handlers.render_pre list. But I don't know how to use this procedure to my case since it seems to depend on a time frame parameter t for each different text to show.

My problem probably seems unclear so I attach what I've already written and I'd be happy to give more precisions about what I intend to do.

class pseudo:
def __init__(self, name, vec_position, vec_color):
    self.name = name
    self.vec_position = vec_position
    self.vec_color = vec_color

pl = [pseudo("sardine", [0.3, 0.4], [1.0, 0.0, 0.0]),
      pseudo("tartine", [-0.2, -0.4], [0.0, 0.0, 1.0])]

def print_pseudo(p):
    name = p.name
    x = p.vec_position[0]
    y = p.vec_position[1]
    r = p.vec_color[0]
    g = p.vec_color[1]
    b = p.vec_color[2]
    myFontCurve = bpy.data.curves.new(type = "FONT", name = name + "Curve")
    myFontOb = bpy.data.objects.new(name, myFontCurve)
    myFontOb.data.body = name
    myFontOb.location = (5 * x, 5 * y, 1)
    new_mat = bpy.data.materials.new("NAME")
    new_mat.diffuse_color = (r, g, b)
    myFontOb.active_material.use_transparency = True
    myFontOb.active_material.transparency_method = "Z_TRANSPARENCY"
    myFontOb.active_material.alpha = 1.0
    myFontOb.active_material.specular_alpha = 0.0

for p in pl:

Thanks a lot.


You need to use a material mat applied to each text object, and set its use_transparency property to true :

mat.use_transparency = True
mat.transparency_method = 'Z_TRANSPARENCY'

Then, around the particular t you want the text to have full opacity, you need to set the aplha property of the material, and insert a keyframe corresponding to the alpha

for i in range(anim_length):
    alpha = (t - i) / anim_length + 1 - t / anim_length
    scene.frame_set(t - i)
    mat.alpha = alpha
    scene.frame_set(t + i)
    mat.alpha = alpha

Hope that helps.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.