-
Notifications
You must be signed in to change notification settings - Fork 16
/
__init__.py
147 lines (112 loc) · 4.18 KB
/
__init__.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
# ##### 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 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, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
#
# Copyright (C) 2020 Michael Vigovsky
import logging
import bpy # pylint: disable=import-error
from . import addon_updater_ops
from . import common, library, assets, morphing, randomize, file_io, hair, finalize, rig, rigify, pose, prefs, cmedit
from .lib import charlib
logger = logging.getLogger(__name__)
bl_info = {
"name": "CharMorph",
"author": "Michael Vigovsky",
"version": (0, 3, 5),
"blender": (3, 3, 0),
"location": "View3D > Tools > CharMorph",
"description": "Character creation and morphing, cloth fitting and rigging tools",
'wiki_url': "",
'tracker_url': 'https://github.com/Upliner/CharMorph/issues',
"category": "Characters"
}
VERSION_ANNEX = ""
owner = object()
class VIEW3D_PT_CharMorph(bpy.types.Panel):
bl_idname = "VIEW3D_PT_CharMorph"
bl_label = "".join(("CharMorph ", ".".join(str(item) for item in bl_info["version"]), VERSION_ANNEX))
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "CharMorph"
bl_order = 1
def draw(self, _):
pass
def on_select():
common.manager.on_select()
@bpy.app.handlers.persistent
def undoredo_post(_context, _scene):
common.manager.on_select(undoredo=True)
def subscribe_select_obj():
bpy.msgbus.clear_by_owner(owner)
bpy.msgbus.subscribe_rna(
owner=owner,
key=(bpy.types.LayerObjects, "active"),
args=(),
options={"PERSISTENT"},
notify=on_select)
@bpy.app.handlers.persistent
def load_handler(_):
subscribe_select_obj()
common.manager.del_charmorphs()
on_select()
@bpy.app.handlers.persistent
def select_handler(_):
on_select()
classes: list[type] = [None, prefs.CharMorphPrefs, VIEW3D_PT_CharMorph]
uiprops = [bpy.types.PropertyGroup]
for module in library, morphing, randomize, file_io, assets, hair, rig, rigify, finalize, pose:
classes.extend(module.classes)
if hasattr(module, "UIProps"):
uiprops.append(module.UIProps)
CharMorphUIProps = type("CharMorphUIProps", tuple(uiprops), {})
classes[0] = CharMorphUIProps
class_register, class_unregister = bpy.utils.register_classes_factory(classes)
def register():
# addon updater code and configurations
# in case of broken version, try to register the updater first
# so that users can revert back to a working version
addon_updater_ops.register(bl_info)
logger.debug("Charmorph register")
charlib.library.load()
class_register()
common.register()
bpy.types.WindowManager.charmorph_ui = bpy.props.PointerProperty(type=CharMorphUIProps, options={"SKIP_SAVE"})
subscribe_select_obj()
bpy.app.handlers.load_post.append(load_handler)
bpy.app.handlers.undo_post.append(undoredo_post)
bpy.app.handlers.redo_post.append(undoredo_post)
bpy.app.handlers.depsgraph_update_post.append(select_handler)
cmedit.register()
def unregister():
# addon updater unregister
addon_updater_ops.unregister()
logger.debug("Charmorph unregister")
cmedit.unregister()
for hlist in bpy.app.handlers:
if not isinstance(hlist, list):
continue
for handler in hlist:
if handler in (load_handler, select_handler):
hlist.remove(handler)
break
bpy.msgbus.clear_by_owner(owner)
del bpy.types.WindowManager.charmorph_ui
common.manager.del_charmorphs()
common.unregister()
class_unregister()
if __name__ == "__main__":
register()