Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Animation using Blender's Python Interface

  • 04-10-2010 09: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