Skip to content

Commit 1a3e5ac

Browse files
committed
Refactored Panellines using Collection properties, removed eval() and exec() calls,deleted unnecessary examples textures, rebranded addon name. Preset system changed, old presets should be recreated
1 parent 1c3c8f1 commit 1a3e5ac

9 files changed

+398
-918
lines changed

__init__.py

+34-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
bl_info = {
2-
"name": "Blender Substance Texture Importer",
2+
"name": "Substance Texture Importer",
33
"author": "Cosmin Planchon",
4-
"version": (0, 4, 0),
4+
"version": (0, 5, 0),
55
"blender": (4, 0, 0),
66
"location": "Properties > Material",
77
"description": "Import & autoassign images from Substance Painter or similar 3D painting tools",
@@ -11,85 +11,88 @@
1111
"category": "Material"}
1212

1313
import bpy
14+
from bpy.app.handlers import persistent
1415
from bpy.props import (
1516
StringProperty, IntProperty, BoolProperty,
1617
PointerProperty, CollectionProperty,
1718
FloatProperty,FloatVectorProperty,
18-
EnumProperty,
19+
EnumProperty,
1920
)
2021

21-
from . propertygroups import ( PaneLine0, PaneLine1, PaneLine2, PaneLine3,
22-
PaneLine4, PaneLine5, PaneLine6, PaneLine7,
23-
PaneLine8, PaneLine9, ShaderLinks,
24-
NodesLinks, BSMprops,
22+
from . propertygroups import ( ShaderLinks, NodesLinks, BSMprops,
23+
PanelLines, PanelLiner, ph
2524
)
2625

2726
from . operators import ( BSM_MT_presetsmenu, BSM_OT_execute_preset,
2827
BSM_OT_make_nodes, BSM_OT_assign_nodes,
29-
BSM_OT_reporter,
28+
BSM_OT_reporter,BSM_OT_add_substance_texture,
3029
BSM_OT_save_all, BSM_OT_load_all,
31-
BSM_OT_import_textures, BSM_OT_del_map_line,
32-
BSM_OT_add_preset,
33-
BSM_OT_add_map_line,
30+
BSM_OT_import_textures,
31+
BSM_OT_add_preset,BSM_OT_del_substance_texture,
3432
)
3533

36-
from . panels import ( BSM_PT_presets, BSM_PT_importpanel, BSM_PT_panel_line,
34+
from . panels import ( BSM_PT_presets, BSM_PT_importpanel, BSM_PT_panel_liner,
3735
BSM_PT_prefs, BSM_PT_options, BSM_PT_params, BSM_PT_buttons,
3836
)
3937

4038
classes = (
39+
PanelLines,
40+
PanelLiner,
4141
BSMprops,
4242
NodesLinks,
4343
ShaderLinks,
44-
PaneLine0,
45-
PaneLine1,
46-
PaneLine2,
47-
PaneLine3,
48-
PaneLine4,
49-
PaneLine5,
50-
PaneLine6,
51-
PaneLine7,
52-
PaneLine8,
53-
PaneLine9,
5444
BSM_OT_reporter,
55-
BSM_OT_add_map_line,
5645
BSM_OT_execute_preset,
5746
BSM_OT_make_nodes,
5847
BSM_MT_presetsmenu,
5948
BSM_OT_add_preset,
6049
BSM_PT_presets,
6150
BSM_OT_import_textures,
51+
BSM_OT_add_substance_texture,
52+
BSM_OT_del_substance_texture,
6253
BSM_PT_importpanel,
6354
BSM_PT_params,
64-
BSM_PT_panel_line,
55+
BSM_PT_panel_liner,
6556
BSM_PT_prefs,
6657
BSM_PT_buttons,
6758
BSM_PT_options,
68-
BSM_OT_del_map_line,
6959
BSM_OT_save_all,
7060
BSM_OT_load_all,
7161
BSM_OT_assign_nodes,
7262
)
7363

64+
65+
@persistent
66+
def initialize_defaults(arg_1,arg_2):
67+
props = bpy.context.scene.bsmprops
68+
if hasattr(props, "texture_importer"):
69+
maps = ["Color","Roughness","Metallic","Normal"]
70+
texture_importer = props.texture_importer
71+
if len(texture_importer.textures) == 0:
72+
propper = ph()
73+
for i in range(4):
74+
item = texture_importer.textures.add()
75+
item.name = f"{maps[i]} map"
76+
item.map_label = f"{maps[i]}"
77+
propper.default_sockets(bpy.context,item)
78+
7479
def register():
7580
from bpy.utils import register_class
7681
for cls in classes:
7782
register_class(cls)
7883
bpy.types.Scene.bsmprops = PointerProperty(type=BSMprops)
79-
for i in range(10) :
80-
exec(f"bpy.types.Scene.panel_line{i} = PointerProperty(type=PaneLine{i})")
8184
bpy.types.Scene.node_links = CollectionProperty(type=NodesLinks)
8285
bpy.types.Scene.shader_links = CollectionProperty(type=ShaderLinks)
86+
bpy.app.handlers.load_post.append(initialize_defaults)
8387

8488
def unregister():
8589
from bpy.utils import unregister_class
86-
for cls in classes:
87-
unregister_class(cls)
90+
bpy.app.handlers.load_post.remove(initialize_defaults)
8891
del bpy.types.Scene.shader_links
8992
del bpy.types.Scene.node_links
90-
for i in range(10) :
91-
exec(f"del bpy.types.Scene.panel_line{9-i}")
9293
del bpy.types.Scene.bsmprops
94+
for cls in reversed(classes):
95+
unregister_class(cls)
9396

9497
if __name__ == '__main__':
9598
register()
-929 Bytes
Binary file not shown.
-701 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)