# Combining Keyframing + Time-Steps (Python)

**URL:** <https://vapor.discourse.group/t/combining-keyframing-time-steps-python/414>\
**Category:** Uncategorized\
**Created:** [October 23, 2024, 7:26pm UTC](https://vapor.discourse.group/t/combining-keyframing-time-steps-python/414 "2024-10-23T19:26:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ezx](https://avatars.discourse-cdn.com/v4/letter/e/7ba0ec/32.png) [@ezx](https://vapor.discourse.group/u/ezx)\
**Post date:** [October 23, 2024, 7:26pm UTC](https://vapor.discourse.group/t/combining-keyframing-time-steps-python/414/1 "2024-10-23T19:26:53Z")

</div>

Is there a built-in way to combine the keyframing technique along with making it so that the animation steps through time as well? Or will I have to manually interpolate the camera positions for each timestep-frame?

---

<div class="post-metadata">

**Author:** ![pearse](https://yyz2.discourse-cdn.com/free1/user_avatar/vapor.discourse.group/pearse/32/177_2.png) [@pearse](https://vapor.discourse.group/u/pearse)\
**Post date:** [October 24, 2024, 6:48pm UTC](https://vapor.discourse.group/t/combining-keyframing-time-steps-python/414/2 "2024-10-24T18:48:37Z")

</div>

The animate\_keyframes() utility function does not currently support incrementing through time but it’s something we are going to fix. In the meantime you’ll need to manually interpolate the camera and increment the timestep every X frames. Here’s one way you could approach that so the timestep is advanced every 5 frames:

```auto
# Import necessary modules

from vapor import session, camera

# Acquire the camera settings from an initial session file

ses1 = session.Session()
ses1.Load(homeDir + "/Examples/eastTroublesome/et_1.vs3")

cam1 = ses1.GetCamera()
dir1 = cam1.GetDirection()
pos1 = cam1.GetPosition()
up1 = cam1.GetUp()

# Acquire the camera settings from a secondary session file that we will transition into

ses2 = session.Session()
ses2.Load( homeDir + "/Examples/eastTroublesome/et_2.vs3")
cam2 = ses2.GetCamera()
dir2 = cam2.GetDirection()
pos2 = cam2.GetPosition()
up2 = cam2.GetUp()

# Difference between camera positions on each axis
dPositionX = (pos2[0] - pos1[0])
dPositionY = (pos2[1] - pos1[1])
dPositionZ = (pos2[2] - pos1[2])

# Difference between camera direction vectors on each axis
dDirectionX = (dir2[0] - dir1[0])
dDirectionY = (dir2[1] - dir1[1])
dDirectionZ = (dir2[2] - dir1[2])

# Difference between camera up vectors on each axis
dUpX = (up2[0] - up1[0])
dUpY = (up2[1] - up1[1])
dUpZ = (up2[2] - up1[2])

# Perform a linear interoplation between the Camera's start position, direction, and up vector

steps=50
for i in range(0,steps):
    position = [
        pos1[0]+dPositionX*i/steps,
        pos1[1]+dPositionY*i/steps,
        pos1[2]+dPositionZ*i/steps
    ]
    cam1.SetPosition( position )

    direction = [
        dir1[0]+dDirectionX*i/steps,
        dir1[1]+dDirectionY*i/steps,
        dir1[2]+dDirectionZ*i/steps
    ]
    cam1.SetDirection( direction )

    up = [
        up1[0]+dUpX*i/steps,
        up1[1]+dUpY*i/steps,
        up1[2]+dUpZ*i/steps
    ]
    cam1.SetUp( up )

    if ( i % 5 ):
            ses1.SetTimestep(int(i/5))

    ses1.Render( homeDir + "/Examples/eastTroublesome/captures/" + str(i) + ".png")

```
