|
1 | 1 | bl_info = {
|
2 |
| - "name": "Blender Substance Texture Importer", |
| 2 | + "name": "Substance Texture Importer", |
3 | 3 | "author": "Cosmin Planchon",
|
4 |
| - "version": (0, 4, 0), |
| 4 | + "version": (0, 5, 0), |
5 | 5 | "blender": (4, 0, 0),
|
6 | 6 | "location": "Properties > Material",
|
7 | 7 | "description": "Import & autoassign images from Substance Painter or similar 3D painting tools",
|
|
11 | 11 | "category": "Material"}
|
12 | 12 |
|
13 | 13 | import bpy
|
| 14 | +from bpy.app.handlers import persistent |
14 | 15 | from bpy.props import (
|
15 | 16 | StringProperty, IntProperty, BoolProperty,
|
16 | 17 | PointerProperty, CollectionProperty,
|
17 | 18 | FloatProperty,FloatVectorProperty,
|
18 |
| - EnumProperty, |
| 19 | + EnumProperty, |
19 | 20 | )
|
20 | 21 |
|
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 |
25 | 24 | )
|
26 | 25 |
|
27 | 26 | from . operators import ( BSM_MT_presetsmenu, BSM_OT_execute_preset,
|
28 | 27 | BSM_OT_make_nodes, BSM_OT_assign_nodes,
|
29 |
| - BSM_OT_reporter, |
| 28 | + BSM_OT_reporter,BSM_OT_add_substance_texture, |
30 | 29 | 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, |
34 | 32 | )
|
35 | 33 |
|
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, |
37 | 35 | BSM_PT_prefs, BSM_PT_options, BSM_PT_params, BSM_PT_buttons,
|
38 | 36 | )
|
39 | 37 |
|
40 | 38 | classes = (
|
| 39 | + PanelLines, |
| 40 | + PanelLiner, |
41 | 41 | BSMprops,
|
42 | 42 | NodesLinks,
|
43 | 43 | ShaderLinks,
|
44 |
| - PaneLine0, |
45 |
| - PaneLine1, |
46 |
| - PaneLine2, |
47 |
| - PaneLine3, |
48 |
| - PaneLine4, |
49 |
| - PaneLine5, |
50 |
| - PaneLine6, |
51 |
| - PaneLine7, |
52 |
| - PaneLine8, |
53 |
| - PaneLine9, |
54 | 44 | BSM_OT_reporter,
|
55 |
| - BSM_OT_add_map_line, |
56 | 45 | BSM_OT_execute_preset,
|
57 | 46 | BSM_OT_make_nodes,
|
58 | 47 | BSM_MT_presetsmenu,
|
59 | 48 | BSM_OT_add_preset,
|
60 | 49 | BSM_PT_presets,
|
61 | 50 | BSM_OT_import_textures,
|
| 51 | + BSM_OT_add_substance_texture, |
| 52 | + BSM_OT_del_substance_texture, |
62 | 53 | BSM_PT_importpanel,
|
63 | 54 | BSM_PT_params,
|
64 |
| - BSM_PT_panel_line, |
| 55 | + BSM_PT_panel_liner, |
65 | 56 | BSM_PT_prefs,
|
66 | 57 | BSM_PT_buttons,
|
67 | 58 | BSM_PT_options,
|
68 |
| - BSM_OT_del_map_line, |
69 | 59 | BSM_OT_save_all,
|
70 | 60 | BSM_OT_load_all,
|
71 | 61 | BSM_OT_assign_nodes,
|
72 | 62 | )
|
73 | 63 |
|
| 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 | + |
74 | 79 | def register():
|
75 | 80 | from bpy.utils import register_class
|
76 | 81 | for cls in classes:
|
77 | 82 | register_class(cls)
|
78 | 83 | 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})") |
81 | 84 | bpy.types.Scene.node_links = CollectionProperty(type=NodesLinks)
|
82 | 85 | bpy.types.Scene.shader_links = CollectionProperty(type=ShaderLinks)
|
| 86 | + bpy.app.handlers.load_post.append(initialize_defaults) |
83 | 87 |
|
84 | 88 | def unregister():
|
85 | 89 | from bpy.utils import unregister_class
|
86 |
| - for cls in classes: |
87 |
| - unregister_class(cls) |
| 90 | + bpy.app.handlers.load_post.remove(initialize_defaults) |
88 | 91 | del bpy.types.Scene.shader_links
|
89 | 92 | del bpy.types.Scene.node_links
|
90 |
| - for i in range(10) : |
91 |
| - exec(f"del bpy.types.Scene.panel_line{9-i}") |
92 | 93 | del bpy.types.Scene.bsmprops
|
| 94 | + for cls in reversed(classes): |
| 95 | + unregister_class(cls) |
93 | 96 |
|
94 | 97 | if __name__ == '__main__':
|
95 | 98 | register()
|
0 commit comments