-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path__init__.py
109 lines (82 loc) · 3.39 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
bl_info = {
"name": "VSE Masking Tools",
"author": "John C. Quillan, tintwotin",
"version": (0, 2),
"blender": (3, 4, 0),
"location": "Image/Mask Editor Sidebar > View > Background Display",
"description": "Syncs VSE to Image Editor render",
"warning": "",
"doc_url": "https://github.com/jquillan/vse_masking_tools",
"category": "Image Editor",
}
import bpy
from bpy.types import Operator, PropertyGroup
from bpy.props import BoolProperty, PointerProperty
from bpy_extras.object_utils import AddObjectHelper, object_data_add
from mathutils import Vector
# Registration
# def add_object_button(self, context):
# self.layout.operator(
# OBJECT_OT_add_object.bl_idname,
# text="Add Object",
# icon='PLUGIN')
# This allows you to right click on a button and link to documentation
# def add_object_manual_map():
# url_manual_prefix = "https://docs.blender.org/manual/en/latest/"
# url_manual_mapping = (
# ("bpy.ops.mesh.add_object", "scene_layout/object/types.html"),
# )
# return url_manual_prefix, url_manual_mapping
def vse_opengl_render_handler(dummy):
bpy.ops.render.opengl(animation=False, render_keyed_only=False, sequencer=True)
def vse_sync_changed_func(self, context):
if context.scene.vse_mask.vse_sync:
if not vse_opengl_render_handler in bpy.app.handlers.frame_change_post:
bpy.app.handlers.frame_change_post.append(vse_opengl_render_handler)
render_result = next(image for image in bpy.data.images if image.type == "RENDER_RESULT")
#print(render_result.name)
# Get the current active area
area = bpy.context.area
# Check if the current area is an Image Editor
if area.type == 'IMAGE_EDITOR':
# Get the space_data of the Image Editor
space_data = area.spaces.active
# Find the image data block by name
image = bpy.data.images.get(render_result.name)
if image:
# Set the selected image data block
space_data.image = image
space_data.ui_mode = 'MASK'
else:
if vse_opengl_render_handler in bpy.app.handlers.frame_change_post:
bpy.app.handlers.frame_change_post.remove(vse_opengl_render_handler)
class VSEMASK_settings(PropertyGroup):
vse_sync : BoolProperty(
name="Sync VSE",
description="Keep Render Layer in sync with Sequencer Preview",
default = False,
update = vse_sync_changed_func
)
class VSEMASK_PT_panel(bpy.types.Panel):
bl_label = "Background Display"
bl_category = "View"
bl_space_type = "IMAGE_EDITOR"
bl_region_type = "UI"
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
layout = layout.row(heading="Preview")
scene = context.scene
vse_mask = scene.vse_mask
layout.prop(vse_mask, "vse_sync", text=" Sequencer")
def register():
bpy.utils.register_class(VSEMASK_PT_panel)
bpy.utils.register_class(VSEMASK_settings)
bpy.types.Scene.vse_mask = PointerProperty(type=VSEMASK_settings)
def unregister():
bpy.utils.unregister_class(VSEMASK_PT_panel)
del bpy.types.Scene.vse_sync
if __name__ == "__main__":
register()