Skip to content

Instantly share code, notes, and snippets.

@ethanaeris
Last active May 21, 2017 11:37
Show Gist options
  • Save ethanaeris/cb4b1693e6bffb9f2b595fc1f1ebfb82 to your computer and use it in GitHub Desktop.
Save ethanaeris/cb4b1693e6bffb9f2b595fc1f1ebfb82 to your computer and use it in GitHub Desktop.
FastCameras
# -*- coding: utf-8 -*-
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "fast_cameras",
"author": "Laurent Laget",
"version": (0, 6),
"blender": (2, 78, 5),
"location": "Add",
"description": "Create fast_cameras",
"warning": "",
"wiki_url": "",
"category": "Add",
}
import bpy
def main(context):
for ob in context.scene.objects:
print(ob)
#Classe camera_panoramic
class camera_panoramic(bpy.types.Operator):
"""Create a camera setup for a panoramic view"""
bl_idname = "object.camera_panoramic"
bl_label = "camera_panoramic"
bl_options = {'REGISTER', 'UNDO'}
def invoke(self, context, event):
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.use_multiview = False
bpy.ops.object.camera_add(rotation=(0, -0, 0))
bpy.context.object.rotation_euler[0] = 1.5708
bpy.context.object.name = "Camera_Equilateral"
bpy.context.object.data.type = 'PANO'
bpy.context.object.data.cycles.panorama_type = 'EQUIRECTANGULAR'
bpy.ops.view3d.object_as_camera()
return {'FINISHED'}
#Class camera_vr_sidebyside360
class camera_vr_sbs360(bpy.types.Operator):
"""Create a camera setup for a 360 degrees view in stereo"""
bl_idname = "object.camera_vr_sbs360"
bl_label = "camera_vr_sbs360"
bl_options = {'REGISTER', 'UNDO'}
def invoke(self, context, event):
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.use_multiview = True
bpy.context.scene.render.views_format = 'STEREO_3D'
bpy.context.scene.render.image_settings.views_format = 'STEREO_3D'
bpy.context.scene.render.image_settings.stereo_3d_format.display_mode = 'SIDEBYSIDE'
bpy.context.scene.render.image_settings.stereo_3d_format.use_squeezed_frame = True
bpy.ops.object.camera_add(rotation=(0, -0, 0))
bpy.context.object.rotation_euler[0] = 1.5708
bpy.context.object.name = "camera_vr_sbs360"
bpy.context.object.data.type = 'PANO'
bpy.context.object.data.cycles.panorama_type = 'EQUIRECTANGULAR'
bpy.ops.view3d.object_as_camera()
bpy.context.object.data.stereo.use_spherical_stereo = True
return {'FINISHED'}
#Class camera_3d_sbs
class camera_3d_sbs(bpy.types.Operator):
"""Create a camera setup for a stereo side by side view"""
bl_idname = "object.camera_3d_sbs"
bl_label = "camera_3d_sbs"
bl_options = {'REGISTER', 'UNDO'}
def invoke(self, context, event):
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.render.use_multiview = True
bpy.context.scene.render.views_format = 'STEREO_3D'
bpy.context.scene.render.image_settings.views_format = 'STEREO_3D'
bpy.context.scene.render.image_settings.stereo_3d_format.display_mode = 'SIDEBYSIDE'
bpy.context.scene.render.image_settings.stereo_3d_format.use_squeezed_frame
bpy.ops.object.camera_add(rotation=(0, -0, 0))
bpy.context.object.rotation_euler[0] = 1.5708
bpy.context.object.name = "camera_3d_sbs"
bpy.context.object.data.type = 'PERSP'
bpy.ops.view3d.object_as_camera()
bpy.context.object.data.stereo.use_spherical_stereo = True
return {'FINISHED'}
#Class camera_turntable
class camera_turntable(bpy.types.Operator):
"""Create a camera turntable"""
bl_idname = "object.camera_turntable"
bl_label = "camera_turntable"
bl_options = {'REGISTER', 'UNDO'}
def invoke(self, context, event):
#Get object attributes
targetname = bpy.context.active_object
xname = bpy.context.object.dimensions[0]
yname = bpy.context.object.dimensions[1]
zname = bpy.context.object.dimensions[2]
#Get duration
duration = bpy.context.scene.frame_end
#Snap cursor to selected object
bpy.ops.view3d.snap_cursor_to_selected()
#Realign the camera
bpy.ops.object.camera_add(rotation=(1.5708, -0, 0))
#add track to constraint
bpy.ops.object.constraint_add(type='TRACK_TO')
bpy.context.object.constraints["Track To"].track_axis = 'TRACK_NEGATIVE_Z'
bpy.context.object.constraints["Track To"].up_axis = 'UP_Y'
#track to object
bpy.context.object.constraints["Track To"].target = targetname
#Name the camera
bpy.context.object.name = "camera_turntable"
bpy.context.object.data.type = 'PERSP'
bpy.ops.view3d.object_as_camera()
#create the circle path
bpy.ops.curve.primitive_bezier_circle_add(radius=1+yname+zname)
bpy.context.object.name = "circle_path"
bpy.context.object.rotation_euler[2] = 0.785398
#create variables for camera and circle
father_camera = bpy.data.objects['camera_turntable']
son_circle = bpy.data.objects['circle_path']
#deselect all and select camera and circle path by their variables
bpy.ops.object.select_all(action='DESELECT')
father_camera.select = True
son_circle.select = True
#make the camera the active parent, and parent them in follow path
bpy.context.scene.objects.active = son_circle
bpy.ops.object.parent_set(type='FOLLOW')
bpy.context.object.data.path_duration = duration
return {'FINISHED'}
def menu_item(self, context):
self.layout.operator(camera_panoramic.bl_idname, text="camera_Panoramic_Equilateral", icon="PLUGIN")
self.layout.operator(camera_vr_sbs360.bl_idname, text="camera_Vr_SideBySide_360", icon="PLUGIN")
self.layout.operator(camera_3d_sbs.bl_idname, text="camera_3d_SideBySide", icon="PLUGIN")
self.layout.operator(camera_turntable.bl_idname, text="camera_turntable", icon="PLUGIN")
def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_camera_add.append(menu_item)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_camera_add.remove(menu_item)
if __name__ == "__main__":
register()
@ethanaeris
Copy link
Author

ethanaeris commented Apr 1, 2017

Addon FastCameras
Create fast turntable, 3d, vr and panoramic cameras (equilateral for cycles)
/!\ Please use last Blender 2.78.4 builds and beyond, since it uses a camera directory.
To use : Shift+A ->camera -> choose your type of camera

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment