Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
* Solid in Blender has the same size as in After Effects
* added Scale support
* switch between CSGOs and Blenders coordinate system (infos in the Read.me)
  • Loading branch information
Devostated authored Oct 1, 2021
1 parent 033210b commit 3065ac5
Showing 1 changed file with 129 additions and 48 deletions.
177 changes: 129 additions & 48 deletions HLAE_CoordIO.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bl_info = {
"name": "HLAE CoordIO",
"author": "Devostated.",
"version": (1, 3, 0),
"version": (2, 0, 0),
"blender": (2, 93, 0),
"operator": "Import-Export",
"location": "Operator Search",
Expand All @@ -10,70 +10,151 @@
"description": "Exporting transformation data to After Effects."
}
import bpy
from math import degrees
import bmesh
from bpy.types import Panel, Operator, PropertyGroup, Scene
from math import degrees, radians

class bl2ae_plane(bpy.types.Operator):
class COORD_PT_Panel(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "HLAE CoordIO"
bl_label = "HLAE CoordIO"

def draw(self, context):
layout = self.layout
scene = context.scene
bl2ae_settings = scene.bl2ae_settings

layout.column(align=True).label(text='Set Coordinate System:')
layout.prop(bl2ae_settings, 'coord_sys', expand = True)
layout.operator('bl.plane')
layout.operator('bl.coords')

class bl2ae_properties(PropertyGroup):
coord_sys: bpy.props.EnumProperty(
name = "Set Coordinate System",
items = (
('CSGO','CSGO','Set to CSGOs coordinate system.'),
('BLENDER','Blender','Set to Blenders coordinate system.')
)
)

class bl2ae_plane(Operator):
bl_idname = 'bl.plane'
bl_label = "Create Plane"
bl_label = "Create Solid"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
# Create Plane WIP
bpy.ops.mesh.primitive_plane_add(size=2, enter_editmode=False, align='WORLD', rotation=(1.5707963, 0, 0))
# Decent size for Blender and AE
scene = context.scene
width = scene.render.resolution_x
height = scene.render.resolution_y
aspect = width / height

if scene.bl2ae_settings.coord_sys == 'BLENDER':
Z = 0
Y = 0.225
X = Y * aspect
name = "Blender Solid"
else:
Z = 0.225
Y = Z * aspect
X = 0
name = "CSGO Solid"
verts = [
(-X, Y, -Z),
(-X, -Y, -Z),
( X, -Y, Z),
( X, Y, Z)
]
mesh = bpy.data.meshes.new(name)
solid = bpy.data.objects.new(name, mesh)
context.collection.objects.link(solid)

bm = bmesh.new()
for v in reversed(verts):
bm.verts.new(v)
bm.faces.new(bm.verts)
bm.to_mesh(mesh)
bm.free()

context.view_layer.objects.active = solid
if scene.bl2ae_settings.coord_sys == 'BLENDER':
context.object.rotation_euler[0] = radians(90)
return {'FINISHED'}

class bl2ae_coords(bpy.types.Operator):
class bl2ae_coords(Operator):
bl_idname = 'bl.coords'
bl_label = "Copy to Clipboard"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):
# Transformation Blender to AE
# Location
loc = bpy.context.object.location
LX = loc.x * 100
LY = loc.z * - 1 * 100
LZ = loc.y * 100

# Rotation
rot = list(bpy.context.object.matrix_world.to_euler('ZYX'))
RX = degrees(rot[0]) - 90
RY = -degrees(rot[1])
RZ = -degrees(rot[2])
trans = context.object
loc = trans.location
scl = 4.165
if context.scene.bl2ae_settings.coord_sys == 'BLENDER':
# Location Blender coords to AE
LX = loc.x * 100
LY = -loc.z * 100
LZ = loc.y * 100

# Copy to Clipboard
copy = bpy.context.window_manager
copy.clipboard = "Adobe After Effects 8.0 Keyframe Data\r\n"
copy.clipboard = copy.clipboard + "\r\n"
copy.clipboard = copy.clipboard + "Transform\tPosition\r\n"
copy.clipboard = copy.clipboard + "\tFrame\tX pixels\tY pixels\tZ pixels\t\r\n"
copy.clipboard = copy.clipboard + "\t\t{}\t{}\t{}\t\r\n".format(LX, LY, LZ,)
copy.clipboard = copy.clipboard + "\r\n"
copy.clipboard = copy.clipboard + "Transform\tOrientation\r\n"
copy.clipboard = copy.clipboard + "\tFrame\tX degrees\t\r\n"
copy.clipboard = copy.clipboard + "\t\t{}\t{}\t{}\t\r\n".format(RX, RY, RZ,)
copy.clipboard = copy.clipboard + "\r\n"
copy.clipboard = copy.clipboard + "\r\n"
copy.clipboard = copy.clipboard + "End of Keyframe Data"
return {'FINISHED'}
# Rotation Blender coords to AE
rot = list(trans.matrix_world.to_euler('ZYX'))
RX = degrees(rot[0]) - 90
RY = -degrees(rot[1])
RZ = -degrees(rot[2])

class coordPanel(bpy.types.Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "HLAE CoordIO"
bl_label = "HLAE CoordIO"
# Scale Blender coords to AE
SX = scl * trans.scale[0]
SY = scl * trans.scale[1]
SZ = scl * trans.scale[2]
else:
# Location CSGO coords to AE
LX = -loc.y * 100
LY = -loc.z * 100
LZ = loc.x * 100

def draw(self, context):
self.layout.operator('bl.plane')
self.layout.operator('bl.coords')
# Rotation CSGO coords to AE
rot = list(trans.matrix_world.to_euler('XZY'))
RX = -degrees(rot[1])
RY = -degrees(rot[2])
RZ = degrees(rot[0])

# Scale CSGO coords to AE
SX = scl * trans.scale[1]
SY = scl * trans.scale[2]
SZ = scl * trans.scale[0]

# Copy to Clipboard
context.window_manager.clipboard = (
"Adobe After Effects 8.0 Keyframe Data\r\n"
"Transform\tPosition\r"
"\tFrame\tX pixels\tY pixels\tZ pixels\t\r"
f"\t\t{LX}\t{LY}\t{LZ}\t\r\n"
"Transform\tOrientation\r"
"\tFrame\tX degrees\t\r"
f"\t\t{RX}\t{RY}\t{RZ}\t\r\n"
"Transform\tScale\r"
"\tFrame\tX percent\tY percent\tZ percent\t\r"
f"\t\t{SX}\t{SY}\t{SZ}\t\r"
"\r\n"
"End of Keyframe Data"
)
return {'FINISHED'}

# Hotkey
addon_keymaps = []
classes = [
COORD_PT_Panel,
bl2ae_properties,
bl2ae_plane,
bl2ae_coords,
]

def register():
bpy.utils.register_class(bl2ae_plane)
bpy.utils.register_class(bl2ae_coords)
bpy.utils.register_class(coordPanel)
for cls in classes:
bpy.utils.register_class(cls)
Scene.bl2ae_settings = bpy.props.PointerProperty(type= bl2ae_properties)

# Hotkey
wm = bpy.context.window_manager
Expand All @@ -84,9 +165,9 @@ def register():
addon_keymaps.append((km, kmi))

def unregister():
bpy.utils.register_class(bl2ae_plane)
bpy.utils.unregister_class(bl2ae_coords)
bpy.utils.unregister_class(coordPanel)
for cls in classes:
bpy.utils.unregister_class(cls)
del Scene.bl2ae_settings

# Hotkey
for km, kmi in addon_keymaps:
Expand Down

0 comments on commit 3065ac5

Please sign in to comment.