Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-addons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-addons
Commits
77547e66
Commit
77547e66
authored
14 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
script to save out camera animation and switching
parent
cf0ccce4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
io_anim_camera.py
+143
-0
143 additions, 0 deletions
io_anim_camera.py
with
143 additions
and
0 deletions
io_anim_camera.py
0 → 100644
+
143
−
0
View file @
77547e66
# ##### 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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment