KetchupMonki icon

camRot.py

KetchupMonki | PRO | 05/06/19 01:59:29 AM UTC | 0 ⭐ | 313 👁️ | Never ⏰ | []
Python |

1 KB

|

None

|

0 👍

/

0 👎

import math
import bpy
 
#Duplicate the 'guideCam' X times, rotate as needed to keep focus on origin
#Usage "blender -b model.blend -P rotateCam.py"
 
selectCamera = "guideCam"
initial = 25
divBy = 8
 
rotAroundX = 0
rotAroundY = 0
 
scn = bpy.context.scene
srcCam = bpy.data.objects[selectCamera]
 
initX = srcCam.location.x
initY = srcCam.location.y
 
maxRads = 6.28318530718
 
for i in range(0, divBy):
    rot = (maxRads / divBy) * i
 
    setX = rotAroundX + math.cos(rot) * (initX - rotAroundX) - math.sin(rot) * (initY - rotAroundY)
    setY = rotAroundY + math.sin(rot) * (initX - rotAroundX) + math.cos(rot) * (initY - rotAroundY)
 
    newCam = srcCam.copy()
    newCam.name = "cam" + str(chr(65 + i))
    newCam.location.x = setX
    newCam.location.y = setY
    newRot = srcCam.rotation_euler[2] + rot
    if newRot > maxRads:
        newRot -= maxRads
 
    newCam.rotation_euler[2]  = newRot
    scn.objects.link(newCam)
 
bpy.ops.wm.save_as_mainfile(filepath=bpy.data.filepath)

Comments