[Bf-extensions-cvs] [001ab4a] master: After Effects export: use f-strings for formatting
Damien Picard
noreply at git.blender.org
Wed May 25 12:43:15 CEST 2022
Commit: 001ab4aa5bc291b1950e072cb9f107eed3e863b6
Author: Damien Picard
Date: Mon Jun 14 16:23:45 2021 +0200
Branches: master
https://developer.blender.org/rBAC001ab4aa5bc291b1950e072cb9f107eed3e863b6
After Effects export: use f-strings for formatting
This allows a greater float precision, needed by AE for accuracy.
Noticed this when trying to export a shot starting at frame 101 at 24
fps:
>>> "%f" % (101 / 24)
'4.208333', not enough precision for AE
>>> f"{101/24}"
'4.208333333333333', good enough for AE
===================================================================
M io_export_after_effects.py
===================================================================
diff --git a/io_export_after_effects.py b/io_export_after_effects.py
index 582e518..8d73d19 100644
--- a/io_export_after_effects.py
+++ b/io_export_after_effects.py
@@ -23,7 +23,7 @@ bl_info = {
"description": "Export cameras, selected objects & camera solution "
"3D Markers to Adobe After Effects CS3 and above",
"author": "Bartek Skorupa",
- "version": (0, 0, 69),
+ "version": (0, 0, 70),
"blender": (2, 80, 0),
"location": "File > Export > Adobe After Effects (.jsx)",
"warning": "",
@@ -154,7 +154,7 @@ def get_plane_color(obj):
wrapper = node_shader_utils.PrincipledBSDFWrapper(obj.active_material)
color = Color(wrapper.base_color[:3]) + wrapper.emission_color
- return '[%f,%f,%f]' % (color[0], color[1], color[2])
+ return str(list(color))
def is_plane(obj):
@@ -601,7 +601,7 @@ def write_jsx_file(file, data, selection, include_animation,
ae_transform = (convert_transform_matrix(
matrix, data['width'], data['height'],
data['aspect'], False, ae_size))
- 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'[{ae_transform[0]},{ae_transform[1]},{ae_transform[2]}],'
# Get all keyframes for each object and store in dico
if include_animation:
@@ -613,7 +613,7 @@ def write_jsx_file(file, data, selection, include_animation,
data['scn'].frame_set(frame)
# Get time for this loop
- js_data['times'] += '%f,' % ((frame - data['start']) / data['fps'])
+ js_data['times'] += str((frame - data['start']) / data['fps']) + ','
# Keyframes for active camera/cameras
if include_active_cam and data['active_cam_frames'] != []:
@@ -632,11 +632,10 @@ def write_jsx_file(file, data, selection, include_animation,
zoom = convert_lens(active_cam, data['width'], data['height'],
data['aspect'])
# Store all values in dico
- position = '[%f,%f,%f],' % (ae_transform[0], ae_transform[1],
- ae_transform[2])
- orientation = '[%f,%f,%f],' % (ae_transform[3], ae_transform[4],
- ae_transform[5])
- zoom = '%f,' % (zoom)
+
+ position = f'[{ae_transform[0]},{ae_transform[1]},{ae_transform[2]}],'
+ orientation = f'[{ae_transform[3]},{ae_transform[4]},{ae_transform[5]}],'
+ zoom = str(zoom) + ','
js_camera = js_data['cameras'][name_ae]
js_camera['position'] += position
js_camera['orientation'] += orientation
@@ -669,13 +668,9 @@ def write_jsx_file(file, data, selection, include_animation,
zoom = convert_lens(obj, data['width'], data['height'],
data['aspect'])
# Store all values in dico
- position = '[%f,%f,%f],' % (ae_transform[0],
- ae_transform[1],
- ae_transform[2])
- orientation = '[%f,%f,%f],' % (ae_transform[3],
- ae_transform[4],
- ae_transform[5])
- zoom = '%f,' % (zoom)
+ position = f'[{ae_transform[0]},{ae_transform[1]},{ae_transform[2]}],'
+ orientation = f'[{ae_transform[3]},{ae_transform[4]},{ae_transform[5]}],'
+ zoom = str(zoom) + ','
js_camera = js_data['cameras'][name_ae]
js_camera['position'] += position
js_camera['orientation'] += orientation
@@ -707,16 +702,9 @@ def write_jsx_file(file, data, selection, include_animation,
plane_matrix, data['width'], data['height'],
data['aspect'], True, ae_size)
# Store all values in dico
- position = '[%f,%f,%f],' % (ae_transform[0],
- ae_transform[1],
- ae_transform[2])
- orientation = '[%f,%f,%f],' % (ae_transform[3],
- ae_transform[4],
- ae_transform[5])
- # plane_width, plane_height, _ = plane_matrix.to_scale()
- scale = '[%f,%f,%f],' % (ae_transform[6],
- ae_transform[7] * data['width'] / data['height'],
- ae_transform[8])
+ position = f'[{ae_transform[0]},{ae_transform[1]},{ae_transform[2]}],'
+ orientation = f'[{ae_transform[3]},{ae_transform[4]},{ae_transform[5]}],'
+ scale = f'[{ae_transform[6]},{ae_transform[7] * data["width"] / data["height"]},{ae_transform[8]}],'
opacity = '0.0,' if obj.hide_render else '100.0,'
js_solid = js_data['solids'][name_ae]
js_solid['color'] = get_plane_color(obj)
@@ -755,13 +743,10 @@ def write_jsx_file(file, data, selection, include_animation,
data['aspect'], True, ae_size)
color = obj.data.color
# Store all values in dico
- position = '[%f,%f,%f],' % (ae_transform[0], ae_transform[1],
- ae_transform[2])
- orientation = '[%f,%f,%f],' % (ae_transform[3],
- ae_transform[4],
- ae_transform[5])
- energy = '[%f],' % (obj.data.energy * 100.0)
- color = '[%f,%f,%f],' % (color[0], color[1], color[2])
+ position = f'[{ae_transform[0]},{ae_transform[1]},{ae_transform[2]}],'
+ orientation = f'[{ae_transform[3]},{ae_transform[4]},{ae_transform[5]}],'
+ energy = f'[{obj.data.energy * 100.0}],'
+ color = f'[{color[0]},{color[1]},{color[2]}],'
opacity = '0.0,' if obj.hide_render else '100.0,'
js_light = js_data['lights'][name_ae]
js_light['position'] += position
@@ -789,8 +774,8 @@ def write_jsx_file(file, data, selection, include_animation,
js_light['Color_static'] = color
js_light['opacity_static'] = opacity
if type == 'SPOT':
- cone_angle = '[%f],' % (degrees(obj.data.spot_size))
- cone_feather = '[%f],' % (obj.data.spot_blend * 100.0)
+ cone_angle = f'[{degrees(obj.data.spot_size)}],'
+ cone_feather = f'[obj.data.spot_blend * 100.0],'
js_light['Cone Angle'] += cone_angle
js_light['Cone Feather'] += cone_feather
# Check if properties change values compared to previous frame
@@ -812,12 +797,9 @@ def write_jsx_file(file, data, selection, include_animation,
# Convert obj transform properties to AE space
ae_transform = convert_transform_matrix(obj.matrix_world.copy(), data['width'], data['height'], data['aspect'], True, ae_size)
# Store all values in dico
- position = '[%f,%f,%f],' % (ae_transform[0], ae_transform[1],
- ae_transform[2])
- orientation = '[%f,%f,%f],' % (ae_transform[3], ae_transform[4],
- ae_transform[5])
- scale = '[%f,%f,%f],' % (ae_transform[6], ae_transform[7],
- ae_transform[8])
+ position = f'[{ae_transform[0]},{ae_transform[1]},{ae_transform[2]}],'
+ orientation = f'[{ae_transform[3]},{ae_transform[4]},{ae_transform[5]}],'
+ scale = f'[{ae_transform[6]},{ae_transform[7]},{ae_transform[8]}],'
js_null = js_data['nulls'][name_ae]
js_null['position'] += position
js_null['orientation'] += orientation
@@ -849,18 +831,11 @@ def write_jsx_file(file, data, selection, include_animation,
plane_matrix, data['width'], data['height'],
data['aspect'], True, ae_size)
# Store all values in dico
- position = '[%f,%f,%f],' % (ae_transform[0],
- ae_transform[1],
- ae_transform[2])
- orientation = '[%f,%f,%f],' % (ae_transform[3],
- ae_transform[4],
- ae_transform[5])
+ position = f'[{ae_transform[0]},{ae_transform[1]},{ae_transform[2]}],'
+ orientation = f'[{ae_transform[3]},{ae_transform[4]},{ae_transform[5]}],'
image_width, image_height = get_image_size(obj)
ratio_to_comp = image_width / data['width']
- scale = '[%f,%f,%f],' % (ae_transform[6] / ratio_to_comp,
- ae_transform[7] / ratio_to_comp
- * image_width / image_height,
- ae_transform[8])
+ scale = f'[{ae_transform[6] / ratio_to_comp},{ae_transform[7] / ratio_to_comp * image_width / image_height},{ae_transform[8]}],'
opacity = '0.0,' if obj.hide_render else '100.0,'
js_image = js_data['images'][name_ae]
js_image['position'] += position
@@ -897,13 +872,13 @@ def write_jsx_file(file, data, selection, include_animation,
jsx_file.write('#target AfterEffects\n\n')
# Script's header
jsx_file.write('/**************************************\n')
- jsx_file.write('Scene : %s\n' % data['scn'].name)
- jsx_file.write('Resolution
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list