Skip to content

Commit a21523a

Browse files
author
kosmin
committed
removed heavy operations from Panels + various code cleaning
1 parent e7dc3f6 commit a21523a

6 files changed

+128
-78
lines changed

__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
bl_info = {
22
"name": "Blender Substance Texture Importer",
33
"author": "Cosmin Planchon",
4-
"version": (0, 2, 3),
4+
"version": (0, 2, 4),
55
"blender": (2, 82, 0),
66
"location": "Properties > Material",
77
"description": "Import & autoassign images from Substance Painter or similar 3D painting tools",
@@ -34,7 +34,7 @@
3434
BSM_OT_add_map_line, BSM_OT_find_ext,
3535
)
3636

37-
from . panels import ( BSM_PT_presets, BSM_PT_importpanel, BSM_PT_linestopanel,
37+
from . panels import ( BSM_PT_presets, BSM_PT_importpanel, BSM_PT_panel_line,
3838
BSM_PT_prefs, BSM_PT_options, BSM_PT_params, BSM_PT_buttons,
3939
)
4040

@@ -65,7 +65,7 @@
6565
BSM_OT_import_textures,
6666
BSM_PT_importpanel,
6767
BSM_PT_params,
68-
BSM_PT_linestopanel,
68+
BSM_PT_panel_line,
6969
BSM_PT_prefs,
7070
BSM_PT_buttons,
7171
BSM_PT_options,

nodeshandler.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -325,22 +325,22 @@ def setup_nodes(self, **params):
325325
gofile = True
326326
if not manual:
327327
# bpy.ops.bsm.name_maker(line_num = index)
328-
gofile = (bpy.ops.bsm.name_checker(linen=index, lorigin="plug", called=True) == {'FINISHED'})
329-
lefilepath = panel_line.file_name
328+
gofile = (bpy.ops.bsm.name_checker(line_number=index, lorigin="plug", called=True) == {'FINISHED'})
329+
active_filepath = panel_line.file_name
330330

331-
imagename = Path(lefilepath).name
331+
imagename = Path(active_filepath).name
332332
lamap = panel_line.map_label
333333
if manual:
334-
lamap = Path(lefilepath).stem
334+
lamap = Path(active_filepath).stem
335335

336336
if lematerial.node_tree.nodes.find(lamap) > 0:
337337

338-
if Path(lefilepath).is_file() and gofile:
338+
if Path(active_filepath).is_file() and gofile:
339339
bpy.ops.image.open(
340-
filepath=Path(lefilepath).name,
341-
directory=str(Path(lefilepath).parent),
340+
filepath=Path(active_filepath).name,
341+
directory=str(Path(active_filepath).parent),
342342
#TODO why declare twice ?
343-
files=[{"name": Path(lefilepath).name, "name": Path(lefilepath).name}],
343+
files=[{"name": Path(active_filepath).name, "name": Path(active_filepath).name}],
344344
show_multiview=False
345345
)
346346
nodestofill = (nod for nod in lematerial.node_tree.nodes if nod.label == lamap)

operators.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ def execute(self, context):
129129
supposed = patterns_list[patternselected][1]
130130

131131
panel_line.probable = str(Path(lefolder).joinpath(supposed))
132+
133+
propper.update_file_is_real(context=panel_line)
132134
if Path(panel_line.probable).is_file():
133135
break
134136

@@ -138,22 +140,22 @@ def execute(self, context):
138140
class BSM_OT_find_ext(sub_poll,Operator):
139141
bl_idname = "bsm.find_ext"
140142
bl_label = ""
141-
bl_description = "set panel_line{linen}.map_ext according to dir content"
143+
bl_description = "set panel_line{line_number}.map_ext according to dir content"
142144

143145
keepat: bpy.props.BoolProperty(default=False)
144-
linen: bpy.props.IntProperty()
146+
line_number: bpy.props.IntProperty()
145147
called: bpy.props.BoolProperty(default=True)
146148

147149
def execute(self, context):
148150
keepat = self.keepat
149-
linen = self.linen
151+
line_number = self.line_number
150152
scene = context.scene
151-
panel_line = eval(f"scene.panel_line{linen}")
153+
panel_line = eval(f"scene.panel_line{line_number}")
152154
manual = panel_line.manual
153155
propper = ph()
154-
gs_params = {'context': context, 'props':panel_line, 'keep_pattern':keepat}
156+
ft_params = {'context': context, 'props':panel_line, 'keep_pattern':keepat}
155157
currentext = panel_line.map_ext
156-
is_in_dir = propper.file_tester(**gs_params)
158+
is_in_dir = propper.file_tester(**ft_params)
157159

158160
if not is_in_dir and not manual:
159161

@@ -165,7 +167,7 @@ def execute(self, context):
165167
for ext in filetypes:
166168
panel_line.map_ext = ext
167169

168-
is_in_dir = propper.file_tester(**gs_params)
170+
is_in_dir = propper.file_tester(**ft_params)
169171

170172
if is_in_dir:
171173
break
@@ -182,7 +184,7 @@ class BSM_OT_name_checker(sub_poll,Operator):
182184
bl_label = ""
183185
bl_description = "Check if a file containing the Map Name keyword matches the Pattern"
184186

185-
linen: bpy.props.IntProperty(default=0)
187+
line_number: bpy.props.IntProperty(default=0)
186188
lorigin: bpy.props.StringProperty(default="Not Set")
187189
called: bpy.props.BoolProperty(default=True)
188190
notfromext: bpy.props.BoolProperty(default=True)
@@ -192,30 +194,30 @@ def execute(self, context):
192194
keepat = self.keepat
193195
scene = context.scene
194196
bsmprops = scene.bsmprops
195-
linen = self.linen
197+
line_number = self.line_number
196198
notfromext = self.notfromext
197199

198-
panel_line = eval(f"scene.panel_line{linen}")
200+
panel_line = eval(f"scene.panel_line{line_number}")
199201
manual = panel_line.manual
200202
advanced_mode = bsmprops.advanced_mode
201203
prefix = bsmprops.prefix
202204
sel = context.object
203205
mat = sel.active_material
204206
mat.use_nodes = True
205207
propper = ph()
206-
gs_params = {'context':context, 'props':panel_line, 'keep_pattern':keepat}
208+
ft_params = {'context':context, 'props':panel_line, 'keep_pattern':keepat}
207209
if self.lorigin == "plug" and not manual:
208210
panel_line.probable = "reseted"
209211

210212
isafile = Path(panel_line.probable).is_file()
211213

212214
if not manual:
213215

214-
gotafile = propper.file_tester(**gs_params)
216+
gotafile = propper.file_tester(**ft_params)
215217

216218
if not gotafile:
217-
bpy.ops.bsm.find_ext(linen=linen)
218-
isafile = propper.file_tester(**gs_params)
219+
bpy.ops.bsm.find_ext(line_number=line_number)
220+
isafile = propper.file_tester(**ft_params)
219221

220222
if not isafile and self.called :
221223
toreport = panel_line.probable + " not found "
@@ -290,7 +292,7 @@ class BSM_OT_add_map_line(sub_poll, Operator):
290292
bl_label = ""
291293
bl_description = "Add a new map line below"
292294

293-
linen: IntProperty(default=0)
295+
line_number: IntProperty(default=0)
294296

295297
def execute(self, context):
296298
if len(context.scene.shader_links) == 0:

panels.py

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import bpy
2-
from pathlib import Path
32

43
from bpy.types import Panel
54

@@ -50,8 +49,8 @@ def draw(self, context):
5049
row.prop(bsmprops, "usr_dir")
5150

5251

53-
class BSM_PT_linestopanel(TexImporterPanel, Panel):
54-
bl_idname = "BSM_PT_linestopanel"
52+
class BSM_PT_panel_line(TexImporterPanel, Panel):
53+
bl_idname = "BSM_PT_panel_line"
5554
bl_label = "Texture maps"
5655
bl_parent_id = "BSM_PT_importpanel"
5756
bl_options = {'HIDE_HEADER'}
@@ -63,8 +62,6 @@ def draw(self, context):
6362
bsmprops = scene.bsmprops
6463
advanced_modemode = bsmprops.advanced_mode
6564
panel_rows = bsmprops.panel_rows
66-
#TODO: no globbing in panel, get it propped
67-
dir_content = [x.name for x in Path(bsmprops.usr_dir).glob('*.*') ]
6865
row = layout.row()
6966
col = row.column()
7067
col.alignment = 'RIGHT'
@@ -101,12 +98,6 @@ def draw(self, context):
10198
panel_line = eval(f"scene.panel_line{k}")
10299
file_name = panel_line.file_name
103100
manual = panel_line.manual
104-
lefile = Path(panel_line.probable).name
105-
106-
if manual:
107-
lefile = Path(file_name).name
108-
dir_content = bsmprops.dir_content
109-
110101
row = layout.row(align = True)
111102
row.prop(panel_line, "line_on", text = "")
112103
row.use_property_split = True
@@ -125,10 +116,10 @@ def draw(self, context):
125116
col = row.column(align = True)
126117
col.alignment = 'EXPAND'
127118
if not advanced_modemode:
128-
if lefile in dir_content:
129-
col.operator('BSM_OT_name_checker', icon='CHECKMARK').linen = k
119+
if panel_line.file_is_real:
120+
col.operator('BSM_OT_name_checker', icon='CHECKMARK').line_number = k
130121
else:
131-
col.operator('BSM_OT_name_checker', icon='QUESTION').linen = k
122+
col.operator('BSM_OT_name_checker', icon='QUESTION').line_number = k
132123
else :
133124

134125
col.prop(panel_line, "manual", text="", toggle=1, icon='FILE_TICK')

0 commit comments

Comments
 (0)