KetchupMonki

camRot.py

May 5th, 2019
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. import math
  2. import bpy
  3.  
  4. #Duplicate the 'guideCam' X times, rotate as needed to keep focus on origin
  5. #Usage "blender -b model.blend -P rotateCam.py"
  6.  
  7. selectCamera = "guideCam"
  8. initial = 25
  9. divBy = 8
  10.  
  11. rotAroundX = 0
  12. rotAroundY = 0
  13.  
  14. scn = bpy.context.scene
  15. srcCam = bpy.data.objects[selectCamera]
  16.  
  17. initX = srcCam.location.x
  18. initY = srcCam.location.y
  19.  
  20. maxRads = 6.28318530718
  21.  
  22. for i in range(0, divBy):
  23.     rot = (maxRads / divBy) * i
  24.  
  25.     setX = rotAroundX + math.cos(rot) * (initX - rotAroundX) - math.sin(rot) * (initY - rotAroundY)
  26.     setY = rotAroundY + math.sin(rot) * (initX - rotAroundX) + math.cos(rot) * (initY - rotAroundY)
  27.  
  28.     newCam = srcCam.copy()
  29.     newCam.name = "cam" + str(chr(65 + i))
  30.     newCam.location.x = setX
  31.     newCam.location.y = setY
  32.     newRot = srcCam.rotation_euler[2] + rot
  33.     if newRot > maxRads:
  34.         newRot -= maxRads
  35.  
  36.     newCam.rotation_euler[2]  = newRot
  37.     scn.objects.link(newCam)
  38.  
  39. bpy.ops.wm.save_as_mainfile(filepath=bpy.data.filepath)
Advertisement
Add Comment
Please, Sign In to add comment