Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Animation using Blender's Python Interface

Options
  • 04-10-2010 9:27pm
    #1
    Closed Accounts Posts: 827 ✭✭✭


    Not sure whether to ask this here or in the Development forum. I have a few hundred objects in Blender that I want to animate, these were generated using Blender's Python interface. While mesh modeling with this interface is pretty straightforward, I can't find a decent tutorial covering animation with it anywhere. Can anyone point me in the direction of one?


Comments

  • Closed Accounts Posts: 827 ✭✭✭thebaldsoprano


    I've put a very basic script together if anyone's interested in learning the programming side of Blender and is stuck like I was a couple of days ago. Nothing particularly exciting - it rotates a cube, but I'm chuffed to get at least something working :D

    It's probably over-simplified and may have a few faulty assumptions, but it works for me on Blender 2.49.
    import Blender
    import bpy
    import math
    
    scene = bpy.data.scenes.active
    
    context = scene.getRenderingContext()
    context.fps = 30
    context.sFrame = 0
    context.eFrame = 60
    context.sizeX = 640
    context.sizeY = 480
    
    vertices = [[-1.0, -1.0, -1.0],
                [-1.0, -1.0,  1.0],
                [ 1.0, -1.0, -1.0],
                [ 1.0, -1.0,  1.0],
                [ 1.0,  1.0, -1.0],
                [ 1.0,  1.0,  1.0],
                [-1.0,  1.0, -1.0],
                [-1.0,  1.0,  1.0]]
    
    faces = [[0, 1, 3, 2],
             [2, 3, 5, 4],
             [4, 5, 7, 6],
             [6, 7, 1, 0],
             [1, 7, 5, 3],
             [6, 0, 2, 4]]
    
    me = bpy.data.meshes.new("Cube_mesh")
    me.verts.extend(vertices)
    me.faces.extend(faces)
    
    ob = scene.objects.new(me, "Cube_object")
    
    Blender.Set("curframe", 0)
    ob.insertIpoKey(Blender.Object.ROT)
    
    Blender.Set("curframe", 60)
    ob.RotX = 2.0 * math.pi
    ob.RotY = 2.0 * math.pi
    ob.RotZ = 2.0 * math.pi
    ob.insertIpoKey(Blender.Object.ROT)
    
    scene.objects.active = ob
    


Advertisement