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
09b3e872
Commit
09b3e872
authored
13 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
pep8'ify
parent
a7fb1b31
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
io_export_after_effects.py
+83
-78
83 additions, 78 deletions
io_export_after_effects.py
with
83 additions
and
78 deletions
io_export_after_effects.py
+
83
−
78
View file @
09b3e872
#
*****
BEGIN GPL LICENSE BLOCK
*****
#
#####
BEGIN GPL LICENSE BLOCK
#####
#
#
# This program is free software
:
you can redistribute it and/or
modify
# This program is free software
;
you can redistribute it and/or
# it under the terms of the GNU General Public License
as published by
#
modify
it under the terms of the GNU General Public License
# the Free Software Foundation
,
either version
3 of the License, or
#
as published by
the Free Software Foundation
;
either version
2
# (at your option) any later version.
#
of the License, or
(at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# but WITHOUT ANY WARRANTY; without even the implied warranty of
...
@@ -11,12 +11,13 @@
...
@@ -11,12 +11,13 @@
# GNU General Public License for more details.
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program; if not, write to the Free Software Foundation,
#
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# The Original Code is: all of this file.
#
# ***** END GPL LICENSE BLOCK *****
#
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
bl_info
=
{
bl_info
=
{
'
name
'
:
'
Export: Adobe After Effects (.jsx)
'
,
'
name
'
:
'
Export: Adobe After Effects (.jsx)
'
,
'
description
'
:
'
Export cameras, selected objects & camera solution 3D Markers to Adobe After Effects CS3 and above
'
,
'
description
'
:
'
Export cameras, selected objects & camera solution 3D Markers to Adobe After Effects CS3 and above
'
,
...
@@ -63,6 +64,7 @@ def get_comp_data(context):
...
@@ -63,6 +64,7 @@ def get_comp_data(context):
'
curframe
'
:
scene
.
frame_current
,
'
curframe
'
:
scene
.
frame_current
,
}
}
# create list of active camera for each frame in case active camera is set by markers
# create list of active camera for each frame in case active camera is set by markers
def
get_active_cam_for_each_frame
(
scene
,
start
,
end
):
def
get_active_cam_for_each_frame
(
scene
,
start
,
end
):
active_cam_frames
=
[]
active_cam_frames
=
[]
...
@@ -73,15 +75,15 @@ def get_active_cam_for_each_frame(scene, start, end):
...
@@ -73,15 +75,15 @@ def get_active_cam_for_each_frame(scene, start, end):
if
marker
.
camera
:
if
marker
.
camera
:
sorted_markers
.
append
([
marker
.
frame
,
marker
])
sorted_markers
.
append
([
marker
.
frame
,
marker
])
sorted_markers
=
sorted
(
sorted_markers
)
sorted_markers
=
sorted
(
sorted_markers
)
for
i
,
marker
in
enumerate
(
sorted_markers
):
for
i
,
marker
in
enumerate
(
sorted_markers
):
cam
=
marker
[
1
].
camera
cam
=
marker
[
1
].
camera
if
i
is
0
and
marker
[
0
]
>
start
:
if
i
is
0
and
marker
[
0
]
>
start
:
start_range
=
start
start_range
=
start
else
:
else
:
start_range
=
sorted_markers
[
i
][
0
]
start_range
=
sorted_markers
[
i
][
0
]
if
len
(
sorted_markers
)
>
i
+
1
:
if
len
(
sorted_markers
)
>
i
+
1
:
end_range
=
sorted_markers
[
i
+
1
][
0
]
-
1
end_range
=
sorted_markers
[
i
+
1
][
0
]
-
1
else
:
else
:
end_range
=
end
end_range
=
end
for
i
in
range
(
start_range
,
end_range
+
1
):
for
i
in
range
(
start_range
,
end_range
+
1
):
...
@@ -91,7 +93,8 @@ def get_active_cam_for_each_frame(scene, start, end):
...
@@ -91,7 +93,8 @@ def get_active_cam_for_each_frame(scene, start, end):
# in this case active_cam_frames array will have legth of 1. This will indicate that there is only one active cam in all frames
# in this case active_cam_frames array will have legth of 1. This will indicate that there is only one active cam in all frames
active_cam_frames
.
append
(
scene
.
camera
)
active_cam_frames
.
append
(
scene
.
camera
)
return
(
active_cam_frames
)
return
(
active_cam_frames
)
# create managable list of selected objects
# create managable list of selected objects
def
get_selected
(
context
):
def
get_selected
(
context
):
...
@@ -108,7 +111,7 @@ def get_selected(context):
...
@@ -108,7 +111,7 @@ def get_selected(context):
elif
is_plane
(
ob
):
elif
is_plane
(
ob
):
# not ready yet. is_plane(object) returns False in all cases. This is temporary
# not ready yet. is_plane(object) returns False in all cases. This is temporary
solids
.
append
([
ob
,
convert_name
(
ob
.
name
)])
solids
.
append
([
ob
,
convert_name
(
ob
.
name
)])
elif
ob
.
type
==
'
LAMP
'
:
elif
ob
.
type
==
'
LAMP
'
:
# not ready yet. Lamps will be exported as nulls. This is temporary
# not ready yet. Lamps will be exported as nulls. This is temporary
nulls
.
append
([
ob
,
convert_name
(
ob
.
name
)])
nulls
.
append
([
ob
,
convert_name
(
ob
.
name
)])
...
@@ -125,18 +128,20 @@ def get_selected(context):
...
@@ -125,18 +128,20 @@ def get_selected(context):
return
selection
return
selection
# check if object is plane and can be exported as AE's solid
# check if object is plane and can be exported as AE's solid
def
is_plane
(
object
):
def
is_plane
(
object
):
# work in progress. Not ready yet
# work in progress. Not ready yet
return
False
return
False
# convert names of objects to avoid errors in AE.
# convert names of objects to avoid errors in AE.
def
convert_name
(
name
):
def
convert_name
(
name
):
name
=
"
_
"
+
name
name
=
"
_
"
+
name
if
name
[
0
].
isdigit
():
if
name
[
0
].
isdigit
():
name
=
"
_
"
+
name
name
=
"
_
"
+
name
name
=
bpy
.
path
.
clean_name
(
name
)
name
=
bpy
.
path
.
clean_name
(
name
)
name
=
name
.
replace
(
"
-
"
,
"
_
"
)
name
=
name
.
replace
(
"
-
"
,
"
_
"
)
...
@@ -219,7 +224,8 @@ def convert_transform_matrix(matrix, width, height, aspect, x_rot_correction=Fal
...
@@ -219,7 +224,8 @@ def convert_transform_matrix(matrix, width, height, aspect, x_rot_correction=Fal
#
#
# above is true if square pixels are used. If not - aspect compensation is needed, so final formula is:
# above is true if square pixels are used. If not - aspect compensation is needed, so final formula is:
# zoom = lens * dimension / sensor * aspect
# zoom = lens * dimension / sensor * aspect
#
def
convert_lens
(
camera
,
width
,
height
,
aspect
):
def
convert_lens
(
camera
,
width
,
height
,
aspect
):
if
camera
.
data
.
sensor_fit
==
'
VERTICAL
'
:
if
camera
.
data
.
sensor_fit
==
'
VERTICAL
'
:
sensor
=
camera
.
data
.
sensor_height
sensor
=
camera
.
data
.
sensor_height
...
@@ -227,7 +233,7 @@ def convert_lens(camera, width, height, aspect):
...
@@ -227,7 +233,7 @@ def convert_lens(camera, width, height, aspect):
else
:
else
:
sensor
=
camera
.
data
.
sensor_width
sensor
=
camera
.
data
.
sensor_width
dimension
=
width
dimension
=
width
zoom
=
camera
.
data
.
lens
*
dimension
/
sensor
*
aspect
zoom
=
camera
.
data
.
lens
*
dimension
/
sensor
*
aspect
return
zoom
return
zoom
...
@@ -284,28 +290,28 @@ def write_jsx_file(file, data, selection, include_active_cam, include_selected_c
...
@@ -284,28 +290,28 @@ def write_jsx_file(file, data, selection, include_active_cam, include_selected_c
'
rotationX
'
:
''
,
'
rotationX
'
:
''
,
'
zoom
'
:
''
,
'
zoom
'
:
''
,
}
}
'''
# create structure for solids. Not ready yet. Temporarily not active
# create structure for solids. Not ready yet. Temporarily not active
#
for i, obj in enumerate(selection['solids']):
for i, obj in enumerate(selection[
'
solids
'
]):
#
name_ae = selection['solids'][i][1]
name_ae = selection[
'
solids
'
][i][1]
#
js_data['solids'][name_ae] = {
js_data[
'
solids
'
][name_ae] = {
#
'position': '',
'
position
'
:
''
,
#
'orientation': '',
'
orientation
'
:
''
,
#
'rotationX': '',
'
rotationX
'
:
''
,
#
'scale': '',
'
scale
'
:
''
,
#
}
}
# create structure for lights. Not ready yet. Temporarily not active
# create structure for lights. Not ready yet. Temporarily not active
#
for i, obj in enumerate(selection['lights']):
for i, obj in enumerate(selection[
'
lights
'
]):
#
name_ae = selection['lights'][i][1]
name_ae = selection[
'
lights
'
][i][1]
#
js_data['nulls'][name_ae] = {
js_data[
'
nulls
'
][name_ae] = {
#
'position': '',
'
position
'
:
''
,
#
'orientation': '',
'
orientation
'
:
''
,
#
'rotationX': '',
'
rotationX
'
:
''
,
#
'scale': '',
'
scale
'
:
''
,
#
}
}
'''
# create structure for nulls
# create structure for nulls
for
i
,
obj
in
enumerate
(
selection
[
'
nulls
'
]):
# nulls representing blender's obs except cameras, lamps and solids
for
i
,
obj
in
enumerate
(
selection
[
'
nulls
'
]):
# nulls representing blender's obs except cameras, lamps and solids
if
include_selected_objects
:
if
include_selected_objects
:
...
@@ -354,8 +360,7 @@ def write_jsx_file(file, data, selection, include_active_cam, include_selected_c
...
@@ -354,8 +360,7 @@ def write_jsx_file(file, data, selection, include_active_cam, include_selected_c
matrix
=
Matrix
.
Translation
(
cam
.
matrix_basis
.
copy
()
*
track
.
bundle
)
matrix
=
Matrix
.
Translation
(
cam
.
matrix_basis
.
copy
()
*
track
.
bundle
)
# convert the position into AE space
# convert the position into AE space
ae_transform
=
convert_transform_matrix
(
matrix
,
data
[
'
width
'
],
data
[
'
height
'
],
data
[
'
aspect
'
],
x_rot_correction
=
False
)
ae_transform
=
convert_transform_matrix
(
matrix
,
data
[
'
width
'
],
data
[
'
height
'
],
data
[
'
aspect
'
],
x_rot_correction
=
False
)
js_data
[
'
bundles_cam
'
][
name_ae
][
'
position
'
]
+=
'
[%f,%f,%f],
'
%
(
ae_transform
[
0
],
ae_transform
[
1
],
ae_transform
[
2
])
js_data
[
'
bundles_cam
'
][
name_ae
][
'
position
'
]
+=
'
[%f,%f,%f],
'
%
(
ae_transform
[
0
],
ae_transform
[
1
],
ae_transform
[
2
])
# get all keyframes for each object and store in dico
# get all keyframes for each object and store in dico
for
frame
in
range
(
data
[
'
start
'
],
data
[
'
end
'
]
+
1
):
for
frame
in
range
(
data
[
'
start
'
],
data
[
'
end
'
]
+
1
):
...
@@ -401,21 +406,21 @@ def write_jsx_file(file, data, selection, include_active_cam, include_selected_c
...
@@ -401,21 +406,21 @@ def write_jsx_file(file, data, selection, include_active_cam, include_selected_c
js_data
[
'
cameras
'
][
name_ae
][
'
orientation
'
]
+=
'
[%f,%f,%f],
'
%
(
0
,
ae_transform
[
4
],
ae_transform
[
5
])
js_data
[
'
cameras
'
][
name_ae
][
'
orientation
'
]
+=
'
[%f,%f,%f],
'
%
(
0
,
ae_transform
[
4
],
ae_transform
[
5
])
js_data
[
'
cameras
'
][
name_ae
][
'
rotationX
'
]
+=
'
%f ,
'
%
(
ae_transform
[
3
])
js_data
[
'
cameras
'
][
name_ae
][
'
rotationX
'
]
+=
'
%f ,
'
%
(
ae_transform
[
3
])
js_data
[
'
cameras
'
][
name_ae
][
'
zoom
'
]
+=
'
[%f],
'
%
(
zoom
)
js_data
[
'
cameras
'
][
name_ae
][
'
zoom
'
]
+=
'
[%f],
'
%
(
zoom
)
# keyframes for all solids. Not ready yet. Temporarily not active
# for i, ob in enumerate(selection['solids']):
# #get object name
# name_ae = selection['solids'][i][1]
# #convert ob position to AE space
'''
# keyframes for all solids. Not ready yet. Temporarily not active
for i, ob in enumerate(selection[
'
solids
'
]):
#get object name
name_ae = selection[
'
solids
'
][i][1]
#convert ob position to AE space
# keyframes for all lights. Not ready yet. Temporarily not active
# for i, ob in enumerate(selection['lights']):
# #get object name
# name_ae = selection['lights'][i][1]
# #convert ob position to AE space
# keyframes for all lights. Not ready yet. Temporarily not active
for i, ob in enumerate(selection[
'
lights
'
]):
#get object name
name_ae = selection[
'
lights
'
][i][1]
#convert ob position to AE space
'''
# keyframes for all nulls
# keyframes for all nulls
if
include_selected_objects
:
if
include_selected_objects
:
...
@@ -467,7 +472,7 @@ def write_jsx_file(file, data, selection, include_active_cam, include_selected_c
...
@@ -467,7 +472,7 @@ def write_jsx_file(file, data, selection, include_active_cam, include_selected_c
jsx_file
.
write
(
'
%s.threeDLayer = true;
\n
'
%
name_ae
)
jsx_file
.
write
(
'
%s.threeDLayer = true;
\n
'
%
name_ae
)
jsx_file
.
write
(
'
%s.source.name =
"
%s
"
;
\n
'
%
(
name_ae
,
name_ae
))
jsx_file
.
write
(
'
%s.source.name =
"
%s
"
;
\n
'
%
(
name_ae
,
name_ae
))
jsx_file
.
write
(
'
%s.property(
"
position
"
).setValue(%s);
\n\n\n
'
%
(
name_ae
,
js_data
[
'
bundles_cam
'
][
obj
][
'
position
'
]))
jsx_file
.
write
(
'
%s.property(
"
position
"
).setValue(%s);
\n\n\n
'
%
(
name_ae
,
js_data
[
'
bundles_cam
'
][
obj
][
'
position
'
]))
# create object bundles (not ready yet)
# create object bundles (not ready yet)
# create objects (nulls)
# create objects (nulls)
...
@@ -538,46 +543,46 @@ class ExportJsx(bpy.types.Operator, ExportHelper):
...
@@ -538,46 +543,46 @@ class ExportJsx(bpy.types.Operator, ExportHelper):
bl_label
=
"
Export to Adobe After Effects
"
bl_label
=
"
Export to Adobe After Effects
"
filename_ext
=
"
.jsx
"
filename_ext
=
"
.jsx
"
filter_glob
=
StringProperty
(
default
=
"
*.jsx
"
,
options
=
{
'
HIDDEN
'
})
filter_glob
=
StringProperty
(
default
=
"
*.jsx
"
,
options
=
{
'
HIDDEN
'
})
include_active_cam
=
BoolProperty
(
include_active_cam
=
BoolProperty
(
name
=
"
Active Camera
"
,
name
=
"
Active Camera
"
,
description
=
"
Include Active Camera Data
"
,
description
=
"
Include Active Camera Data
"
,
default
=
True
,
default
=
True
,
)
)
include_selected_cams
=
BoolProperty
(
include_selected_cams
=
BoolProperty
(
name
=
"
Selected Cameras
"
,
name
=
"
Selected Cameras
"
,
description
=
"
Add Selected Cameras Data
"
,
description
=
"
Add Selected Cameras Data
"
,
default
=
True
,
default
=
True
,
)
)
include_selected_objects
=
BoolProperty
(
include_selected_objects
=
BoolProperty
(
name
=
"
Selected Objects
"
,
name
=
"
Selected Objects
"
,
description
=
"
Add Selected Objects Data
"
,
description
=
"
Add Selected Objects Data
"
,
default
=
True
,
default
=
True
,
)
)
include_rotation
=
BoolProperty
(
include_rotation
=
BoolProperty
(
name
=
"
Rotation
"
,
name
=
"
Rotation
"
,
description
=
"
Include rotation of selected objects
"
,
description
=
"
Include rotation of selected objects
"
,
default
=
True
,
default
=
True
,
)
)
include_scale
=
BoolProperty
(
include_scale
=
BoolProperty
(
name
=
"
Scale
"
,
name
=
"
Scale
"
,
description
=
"
Include scale of selected object
"
,
description
=
"
Include scale of selected object
"
,
default
=
True
,
default
=
True
,
)
)
include_cam_bundles
=
BoolProperty
(
include_cam_bundles
=
BoolProperty
(
name
=
"
Camera 3D Markers
"
,
name
=
"
Camera 3D Markers
"
,
description
=
"
Include 3D Markers of Camera Motion Solution for selected cameras
"
,
description
=
"
Include 3D Markers of Camera Motion Solution for selected cameras
"
,
default
=
True
,
default
=
True
,
)
)
# include_ob_bundles = BoolProperty(
# include_ob_bundles = BoolProperty(
# name
=
"Objects 3D Markers",
# name
=
"Objects 3D Markers",
# description
=
"Include 3D Markers of Object Motion Solution for selected cameras",
# description
=
"Include 3D Markers of Object Motion Solution for selected cameras",
# default
=
True,
# default
=
True,
# )
# )
def
draw
(
self
,
context
):
def
draw
(
self
,
context
):
layout
=
self
.
layout
layout
=
self
.
layout
box
=
layout
.
box
()
box
=
layout
.
box
()
box
.
label
(
'
Include Cameras and Objects:
'
)
box
.
label
(
'
Include Cameras and Objects:
'
)
box
.
prop
(
self
,
'
include_active_cam
'
)
box
.
prop
(
self
,
'
include_active_cam
'
)
...
@@ -616,4 +621,4 @@ def unregister():
...
@@ -616,4 +621,4 @@ def unregister():
bpy
.
types
.
INFO_MT_file_export
.
remove
(
menu_func
)
bpy
.
types
.
INFO_MT_file_export
.
remove
(
menu_func
)
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
register
()
register
()
\ No newline at end of file
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