Skip to content

Commit acbe035

Browse files
authored
Merge pull request sugiany#65 from UuuNyaa/64-feature-partial-support-for-library-override-workflow
Add patching to all mmd_tools propeties
2 parents 8edfa02 + b4378e2 commit acbe035

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

mmd_tools/core/morph.py

+9
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,18 @@ def update_mmd_morph():
684684
@staticmethod
685685
def ensure_material_id_not_conflict():
686686
mat_ids_set = set()
687+
688+
# The reference library properties cannot be modified and bypassed in advance.
689+
need_update_mat = []
687690
for mat in bpy.data.materials:
688691
if mat.mmd_material.material_id < 0:
689692
continue
693+
if mat.library is not None:
694+
mat_ids_set.add(mat.mmd_material.material_id)
695+
else:
696+
need_update_mat.append(mat)
697+
698+
for mat in need_update_mat:
690699
if mat.mmd_material.material_id in mat_ids_set:
691700
mat.mmd_material.material_id = max(mat_ids_set) + 1
692701
mat_ids_set.add(mat.mmd_material.material_id)

mmd_tools/properties/__init__.py

+28
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,34 @@ def __set_hide(prop, value):
6464

6565

6666
def __patch(properties): # temporary patching, should be removed in the future
67+
def __patch_override(prop: bpy.props._PropertyDeferred):
68+
"""Apply recursively for each mmd_tools property class annotations
69+
70+
# Hint for bpy.props._PropertyDeferred class
71+
p = bpy.props.IntProperty(name='abc123')
72+
assert isinstance(p, bpy.props._PropertyDeferred)
73+
assert p.function == bpy.props.IntProperty
74+
assert p.keywords == {'name': 'abc123'}
75+
"""
76+
prop.keywords.setdefault('override', set()).add('LIBRARY_OVERRIDABLE')
77+
78+
if prop.function.__name__ not in {'PointerProperty', 'CollectionProperty'}:
79+
return
80+
81+
prop_type = prop.keywords['type']
82+
# The __annotations__ cannot be inherited. Manually search for base classes.
83+
for inherited_type in [prop_type, *prop_type.__bases__]:
84+
if not inherited_type.__module__.startswith('mmd_tools.properties'):
85+
continue
86+
for annotation in inherited_type.__annotations__.values():
87+
if not isinstance(annotation, bpy.props._PropertyDeferred):
88+
continue
89+
__patch_override(annotation)
90+
91+
for props in properties.values():
92+
for prop in props.values():
93+
__patch_override(prop)
94+
6795
prop_obj = properties.setdefault(bpy.types.Object, {})
6896

6997
prop_obj['select'] = bpy.props.BoolProperty(

0 commit comments

Comments
 (0)