Skip to content

Instantly share code, notes, and snippets.

@pra-dan
Last active December 20, 2020 08:28
Show Gist options
  • Save pra-dan/e8977f98a778434c5c3faebd00c036d1 to your computer and use it in GitHub Desktop.
Save pra-dan/e8977f98a778434c5c3faebd00c036d1 to your computer and use it in GitHub Desktop.
import bpy
import os
from math import *
from mathutils import *
#set your own target here
target = bpy.data.objects['Cube']
cam = bpy.data.objects['Camera']
t_loc_x = target.location.x
t_loc_y = target.location.y
cam_loc_x = cam.location.x
cam_loc_y = cam.location.y
"""
The default pose is
X: 7m
Y: 1m
Z: 1m
Rotation_Z = 90 degrees (a.k.a cam.rotation_euler[2])
"""
R = (target.location.xy-cam.location.xy).length # Radius
init_angle = (1-2*bool((cam_loc_y-t_loc_y)<0))*acos((cam_loc_x-t_loc_x)/R)-2*pi*bool((cam_loc_y-t_loc_y)<0) # 8.13 degrees
target_angle = (pi/2 - init_angle) # Go 90-8 deg more
num_steps = 10 #how many rotation steps
for x in range(num_steps):
alpha = init_angle + (x)*target_angle/num_steps
cam.rotation_euler[2] = pi/2 + alpha #
cam.location.x = t_loc_x+cos(alpha)*R
cam.location.y = t_loc_y+sin(alpha)*R
# Define SAVEPATH and output filename
file = os.path.join('renders/', str(x)+'_'+str(round(alpha,2))+'_'+str(round(cam.location.x, 2))+'_'+str(round(cam.location.y, 2)))
# Render
bpy.context.scene.render.filepath = file
bpy.ops.render.render(write_still=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment