-
Notifications
You must be signed in to change notification settings - Fork 6
/
tsynth_ui.py
211 lines (171 loc) · 8.46 KB
/
tsynth_ui.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
'''
Copyright (C) 2019 JOSECONSCO
Created by JOSECONSCO (loosely based on 'dynamic enum' blender template and Simple Asset Manager)
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 3 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, see <http://www.gnu.org/licenses/>.
'''
import bpy
import os
from . import tsynth_props
MESSAGE = None
class VIEW_3D_UL_sel_imgs(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
pcoll = tsynth_props.preview_collections["main"]
# row = col.row(align=True)
# for ico_name in tsynth_params.my_previews_multi:
# layout.template_icon(pcoll[item.image_name].icon_id, scale=5.0)
layout.label(text=item.image_name, icon_value=pcoll[item.image_name].icon_id)
# def draw_filter(self, context, layout):
# pass
class TSYNTH_OT_AddImg(bpy.types.Operator):
bl_idname = "object.add_img_synth"
bl_label = "add_img_synth"
bl_description = "Add Image"
bl_options = {"REGISTER","UNDO"}
name: bpy.props.StringProperty(name='name', description='', default='')
def execute(self, context):
tsynth_params = context.scene.tsynth_params
new_img = tsynth_params.selected_imgs.add()
new_img.image_name = self.name
return {"FINISHED"}
class TSYNTH_OT_RemoveImg(bpy.types.Operator):
bl_idname = "object.remove_img_synth"
bl_label = "remove_img_synth"
bl_description = "Remove Image"
bl_options = {"REGISTER", "UNDO"}
idx: bpy.props.IntProperty(name='idx', description='', default=1, min=0, max=100, subtype='PERCENTAGE')
def execute(self, context):
tsynth_params = context.scene.tsynth_params
if self.idx < len(tsynth_params.selected_imgs):
tsynth_params.selected_imgs.remove(self.idx)
# tsynth_params.active_img %= len(tsynth_params.selected_imgs)
return {"FINISHED"}
class TSYNTH_OT_ClearImg(bpy.types.Operator):
bl_idname = "object.clear_img_synth"
bl_label = "clear_img_synth"
bl_description = "Clear Images"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
tsynth_params = context.scene.tsynth_params
tsynth_params.selected_imgs.clear()
return {"FINISHED"}
# class TSYNTH_PT_Previews(bpy.types.Panel):
# bl_idname = 'TSYNTH_PT_Previews'
# bl_label = 'PanelName'
# bl_space_type = 'VIEW_3D'
# bl_region_type = 'UI'
# bl_ui_units_x = 5
# def draw(self, context):
# layout = self.layout
# col = layout.column(align=True)
# col.scale_y = 1.2
# col.prop(context.scene.tsynth_params, 'my_previews_multi', expand=True)
class TSYNTH_PT_TextureSynthesis(bpy.types.Panel):
bl_idname = "TSYNTH_PT_TextureSynthesis"
bl_label = "Texture Synthesis"
bl_space_type = 'IMAGE_EDITOR'
bl_region_type = 'UI'
bl_category = 'Texture Synthesis'
# bl_context = 'objectmode'
def draw(self, context):
tsynth_params = context.scene.tsynth_params
layout = self.layout.box()
layout.prop(tsynth_params, 'gen_type')
box = layout.box()
box.label(text='Input Image(s)')
col = box.column(align=True)
if tsynth_params.gen_type == 'guided-synthesis':
split = col.split(factor=0.14, align=True)
split.label(text='From')
split.template_ID(tsynth_params, "from_guide", new="image.new", open="image.open")
split = col.split(factor=0.14, align=True)
split.label(text='To')
split.template_ID(tsynth_params, "to_guide", new="image.new", open="image.open")
row = col.row(align=True)
# row.prop(tsynth_params, 'from_guide')
# row.prop(tsynth_params, 'to_guide')
if tsynth_params.gen_type == 'transfer-style':
row = col.row(align=True)
row.prop(tsynth_params, 'alpha')
split = col.split(factor=0.14, align=True)
split.label(text='Guide')
split.template_ID(tsynth_params, "to_guide", new="image.new", open="image.open")
row = col.row(align=True)
box.label(text='Style:')
if tsynth_params.gen_type == 'inpaint':
split = col.split(factor=0.14, align=True)
split.label(text='Mask')
split.template_ID(tsynth_params, "to_guide", new="image.new", open="image.open")
col = box.column(align=True)
row = col.row(align=True)
row.prop(tsynth_params, "input_images_dir")
row.operator("object.refresh_directory", text='', icon='FILE_REFRESH')
col.template_icon_view(tsynth_params, "my_previews", show_labels=True, scale=4.0, scale_popup=5.0)
row = col.row(align=True)
row.prop(tsynth_params, "my_previews", text='')
if tsynth_params.input_images_dir and tsynth_params.my_previews:
img_open = row.operator("image.open", icon='IMPORT', text='').filepath = os.path.join(tsynth_params.input_images_dir, tsynth_params.my_previews)
if tsynth_params.gen_type == 'multi-generate': # also multigenerate
row = box.row()
row.template_list("VIEW_3D_UL_sel_imgs", "", tsynth_params, "selected_imgs", tsynth_params, "active_img", rows=1)
col = row.column(align=True)
col.operator("object.add_img_synth", icon='ADD', text="").name = tsynth_params.my_previews
col.operator("object.remove_img_synth", icon='REMOVE', text="").idx = tsynth_params.active_img
# pcoll = tsynth_props.preview_collections["main"]
# row = col.row(align=True)
# for ico_name in tsynth_params.my_previews_multi:
# row.template_icon(pcoll[ico_name].icon_id, scale=4.0)
# # col.template_icon_view(tsynth_params, "my_previews_multi", show_labels=True)
# col.prop_with_popover(tsynth_params, 'my_previews', text='', panel='TSYNTH_PT_Previews') # 'my_previews' cos it wont work with 'my_previews_multi'
#* SETTINGS
box = layout.box()
box.label(text='Settings')
box_col = box.column(align=True)
box_col.prop(tsynth_params, 'tiling', icon='OUTLINER_OB_LIGHTPROBE')
box_col.prop(tsynth_params, 'seed')
box_col.prop(tsynth_params, 'rand_init')
box_col.prop(tsynth_params, 'backtrack_pct')
box_col.prop(tsynth_params, 'backtrack_stages')
box_col.prop(tsynth_params, 'k_neighs')
box_col.prop(tsynth_params, 'cauchy')
col = box.column(align=True)
row = col.row(align=True)
if tsynth_params.in_size_from_preset:
row.prop(tsynth_params, 'in_size_preset_x')
row.prop(tsynth_params, 'in_size_preset_y', text='')
else:
row.label(text='Input')
row.prop(tsynth_params, 'in_size_x', text='x')
row.prop(tsynth_params, 'in_size_y', text='y')
row.prop(tsynth_params, 'in_size_percent')
row.prop(tsynth_params, 'in_size_from_preset', icon='PRESET', text='')
row = col.row(align=True)
if tsynth_params.out_size_from_preset:
row.prop(tsynth_params, 'out_size_preset_x')
row.prop(tsynth_params, 'out_size_preset_y', text='')
else:
row.label(text='Output')
row.prop(tsynth_params, 'out_size_x', text='x')
row.prop(tsynth_params, 'out_size_y', text='y')
row.prop(tsynth_params, 'out_size_percent')
row.prop(tsynth_params, 'out_size_from_preset', icon='PRESET', text='')
#* OUTPUT
box = layout.box()
box.label(text='Output')
col = box.column(align=True)
col.prop(tsynth_params, 'out_method')
if tsynth_params.out_method == 'TARGET_DIR':
col.prop(tsynth_params, 'out_image_path')
if MESSAGE:
col.label(text=MESSAGE)
if tsynth_params.out_method != 'OVERRIDE' or tsynth_params.gen_type == 'multi-generate':
col.prop(tsynth_params, 'output_file_name')
layout.operator("object.run_tsynthesis", icon='NODE_TEXTURE')