Welcome to mirror list, hosted at ThFree Co, Russian Federation.

eco.py « kinoraw_tools - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 01d13f713f3442b27cacc934f60c0727a1214b75 (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#----------------------------------------------------------
# File sequencer_slide_strip.py
#----------------------------------------------------------

# ##### 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 #####



import bpy
from bpy.props import IntProperty, BoolProperty

from . import functions
    
 
class EcoPanel(bpy.types.Panel):
    bl_label = "Eco Tool"
    bl_idname = "OBJECT_PT_EcoTool"
    bl_space_type = "SEQUENCE_EDITOR"
    bl_region_type = "UI"

    @staticmethod
    def has_sequencer(context):
        return (context.space_data.view_type\
        in {'SEQUENCER', 'SEQUENCER_PREVIEW'})

    @classmethod
    def poll(self, context):
        if context.space_data.view_type in {'SEQUENCER', 'SEQUENCER_PREVIEW'}:
            strip = functions.act_strip(context)
            scn = context.scene
            preferences = context.user_preferences
            prefs = preferences.addons[__package__].preferences
            if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
                if prefs.use_eco_tools:
                    return strip.type in ('META')
        else:
            return False
    
    def draw_header(self, context):
        layout = self.layout
        layout.label(text="", icon="FORCE_HARMONIC")
    
    def draw(self, context):
        scn = bpy.context.scene
        strip = functions.act_strip(context)
        seq_type = strip.type

        preferences = context.user_preferences
        prefs = preferences.addons[__package__].preferences
        
        if seq_type in ( 'MOVIE', 'IMAGE', 'META', 'MOVIECLIP', 'SCENE') :
            active_strip = functions.act_strip(context)
            layout = self.layout
            row=layout.row()
            row.prop(prefs, 'eco_value', text="Ecos")
            row=layout.row()
            row.prop(prefs, 'eco_offset', text="Offset")
            row=layout.row()
            row.prop(prefs, 'eco_use_add_blend_mode', text="use_add_blend_mode")
            row=layout.row()
            row.operator('sequencer.eco')
            
            
        
     
class OBJECT_OT_EcoOperator(bpy.types.Operator):
    
    bl_idname = "sequencer.eco"
    bl_label = "Eco operator"
    bl_description = 'generate an echo effect by duplicating the selected strip'
    bl_options = {'REGISTER', 'UNDO'}

    @staticmethod
    def has_sequencer(context):
        return (context.space_data.view_type\
        in {'SEQUENCER', 'SEQUENCER_PREVIEW'})

    @classmethod
    def poll(self, context):
        strip = functions.act_strip(context)
        scn = context.scene
        if scn and scn.sequence_editor and scn.sequence_editor.active_strip:
            return strip.type in ('META')
        else:
            return False
 
    def execute(self, context):
        
        active_strip=functions.act_strip(context)
        
        preferences = context.user_preferences
        prefs = preferences.addons[__package__].preferences
        
        scn = bpy.context.scene
        sel_strips = bpy.context.selected_sequences
        cur_camera = scn.camera
        eco = prefs.eco_value
        offset = prefs.eco_offset  
        
        active_strip.blend_type = 'REPLACE'
        active_strip.blend_alpha = 1
        for i in range(eco):
            bpy.ops.sequencer.duplicate(mode='TRANSLATION')
            bpy.ops.transform.seq_slide(value=(offset, 1), snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), release_confirm=False)
            
            active_strip = functions.act_strip(context)
            
            if prefs.eco_use_add_blend_mode:
                active_strip.blend_type = 'ADD'
                active_strip.blend_alpha = 1-1/eco
            else:
                active_strip.blend_type = 'ALPHA_OVER'
                active_strip.blend_alpha = 1/eco
            
        
        bpy.ops.sequencer.select_all(action='TOGGLE')
        bpy.ops.sequencer.select_all(action='TOGGLE')
        bpy.ops.sequencer.meta_make()

        
        return {'FINISHED'}