Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-04-01 16:45:45 +0400
committerCampbell Barton <ideasman42@gmail.com>2010-04-01 16:45:45 +0400
commit77547e66b182c8a8f73c6f8fe1f753250f6c0c4a (patch)
treedbaca4fa9b15135999098ac7352755f357184c2a /io_anim_camera.py
parentcf0ccce4853ad96eed26b90e40487c4c67571354 (diff)
script to save out camera animation and switching
Diffstat (limited to 'io_anim_camera.py')
-rw-r--r--io_anim_camera.py143
1 files changed, 143 insertions, 0 deletions
diff --git a/io_anim_camera.py b/io_anim_camera.py
new file mode 100644
index 00000000..696c2a1a
--- /dev/null
+++ b/io_anim_camera.py
@@ -0,0 +1,143 @@
+# ##### 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 #####
+
+# <pep8 compliant>
+
+bl_addon_info = {
+ 'name': 'I/O: Camera Animation',
+ 'author': 'Campbell Barton',
+ 'version': '0.1',
+ 'blender': (2, 5, 3),
+ 'location': 'File > Export > Camera Animation',
+ 'url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/' \
+ 'Scripts/File_I-O/Camera_Animation',
+ 'category': 'Import/Export'}
+
+
+import bpy
+
+
+def writeCameras(context, path, start_frame, end_frame):
+
+ data_attrs = ['lens', 'shift_x', 'shift_y', 'dof_distance', 'clip_start', 'clip_end', 'draw_size']
+ obj_attrs = ['restrict_render']
+
+ fw = open(path, 'w').write
+
+ scene = bpy.context.scene
+
+ cameras = [(obj, obj.data) for obj in scene.objects if obj.type == 'CAMERA']
+
+ frame_range = range(start_frame, end_frame + 1)
+
+ fw("cameras = {}\n")
+ fw("scene = bpy.context.scene\n")
+ fw("\n")
+
+ for obj, obj_data in cameras:
+ fw("data = bpy.data.cameras.new('%s')\n" % obj.name)
+ for attr in data_attrs:
+ fw("data.%s = %s\n" % (attr, repr(getattr(obj_data, attr))))
+
+ fw("obj = bpy.data.objects.new('%s', data)\n" % obj.name)
+
+ for attr in obj_attrs:
+ fw("obj.%s = %s\n" % (attr, repr(getattr(obj, attr))))
+
+ fw("scene.objects.link(obj)\n")
+ fw("cameras['%s'] = obj\n" % obj.name)
+ fw("\n")
+
+
+ for f in frame_range:
+ scene.set_frame(f)
+ fw("# new frame\n")
+ fw("scene.set_frame(%d)\n" % f)
+
+ for obj, obj_data in cameras:
+ fw("obj = cameras['%s']\n" % obj.name)
+
+ matrix = obj.matrix.copy()
+ fw("obj.location = %s\n" % repr(tuple(matrix.translation_part())))
+ fw("obj.scale = %s\n" % repr(tuple(matrix.scale_part())))
+ fw("obj.rotation_euler = %s\n" % repr(tuple(matrix.to_euler())))
+
+ fw("obj.keyframe_insert('location')\n")
+ fw("obj.keyframe_insert('scale')\n")
+ fw("obj.keyframe_insert('rotation_euler')\n")
+
+ # only key the angle
+ fw("data = obj.data\n")
+ fw("data.lens = %s\n" % obj_data.lens)
+ fw("data.keyframe_insert('lens')\n")
+
+ fw("\n")
+
+ # now markers
+ fw("# markers\n")
+ for marker in scene.timeline_markers:
+ fw("marker = scene.timeline_markers.add('%s')\n" % marker.name)
+ fw("marker.frame = %d\n" % marker.frame)
+ if marker.camera:
+ fw("marker.camera = cameras['%s']\n" % marker.camera.name)
+ fw("\n")
+
+
+from bpy.props import *
+
+
+class CameraExporter(bpy.types.Operator):
+ '''Save a python script which re-creartes cameras and markers elsewhere'''
+ bl_idname = "export_animation.cameras"
+ bl_label = "Export Camera & Markers"
+
+ path = StringProperty(name="File Path", description="File path used for importing the RAW file", maxlen=1024, default="")
+ filename = StringProperty(name="File Name", description="Name of the file.")
+ directory = StringProperty(name="Directory", description="Directory of the file.")
+
+ start_frame = IntProperty(name="Start Frame",
+ description="Start frame for export",
+ default=1, min=1, max=300000)
+ end_frame = IntProperty(name="End Frame",
+ description="End frame for export",
+ default=250, min=1, max=300000)
+
+ def execute(self, context):
+ writeCameras(context, self.properties.path, self.start_frame, self.end_frame)
+ return {'FINISHED'}
+
+ def invoke(self, context, event):
+ self.start_frame = context.scene.start_frame
+ self.end_frame = context.scene.end_frame
+
+ wm = context.manager
+ wm.add_fileselect(self)
+ return {'RUNNING_MODAL'}
+
+
+def menu_export(self, context):
+ default_path = bpy.data.filename.replace(".blend", ".py")
+ self.layout.operator(CameraExporter.bl_idname, text="Cameras & Markers (.py)").path = default_path
+
+
+def register():
+ bpy.types.register(CameraExporter)
+ bpy.types.INFO_MT_file_export.append(menu_export)
+
+if __name__ == "__main__":
+ register()