Skip to content

Commit

Permalink
Update UI of vertex morphs and fix minor bugs of shape keys
Browse files Browse the repository at this point in the history
  • Loading branch information
powroupi committed Jul 11, 2021
1 parent d0571cc commit fd4b35c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
18 changes: 12 additions & 6 deletions mmd_tools/core/morph.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __move_to_bottom(key_blocks, name):
key_blocks = obj.data.shape_keys.key_blocks
for name in shape_key_names:
if name not in key_blocks:
obj.shape_key_add(name=name)
obj.shape_key_add(name=name, from_mix=False)
elif len(key_blocks) > 1:
__move_to_bottom(key_blocks, name)

Expand Down Expand Up @@ -270,7 +270,7 @@ def __load(self, obj, mmd_root):
#if name[-1] == '\\': # fix driver's bug???
# m.name = name = name + ' '
if name and name not in morph_sliders:
obj.shape_key_add(name=name)
obj.shape_key_add(name=name, from_mix=False)


@staticmethod
Expand All @@ -293,7 +293,12 @@ def __add_single_prop(variables, id_obj, data_path, prefix):
return var

@staticmethod
def __shape_key_driver_check(key_block):
def __shape_key_driver_check(key_block, resolve_path=False):
if resolve_path:
try:
kb = key_block.id_data.path_resolve(key_block.path_from_id())
except ValueError as e:
return False
if not key_block.id_data.animation_data:
return True
d = key_block.id_data.animation_data.drivers.find(key_block.path_from_id('value'))
Expand All @@ -303,6 +308,7 @@ def __shape_key_driver_check(key_block):
return (not d or d.driver.expression == ''.join(('*w','+g','v')[-1 if i < 1 else i%2]+str(i+1) for i in range(len(d.driver.variables))))

def __cleanup(self, names_in_use=None):
from math import floor, ceil
names_in_use = names_in_use or {}
rig = self.__rig
morph_sliders = self.placeholder()
Expand All @@ -317,7 +323,7 @@ def __cleanup(self, names_in_use=None):
elif kb.name in morph_sliders and self.__shape_key_driver_check(kb):
ms = morph_sliders[kb.name]
kb.driver_remove('value')
kb.slider_min, kb.slider_max = min(ms.slider_min, kb.value), max(ms.slider_max, kb.value)
kb.slider_min, kb.slider_max = min(ms.slider_min, floor(kb.value)), max(ms.slider_max, ceil(kb.value))
for m in mesh.modifiers: # uv morph
if m.name.startswith('mmd_bind') and m.name not in names_in_use:
mesh.modifiers.remove(m)
Expand Down Expand Up @@ -380,12 +386,12 @@ def bind(self):
if kb_name not in morph_sliders:
continue

if self.__shape_key_driver_check(kb):
if self.__shape_key_driver_check(kb, resolve_path=True):
name_bind, kb_bind = kb_name, kb
else:
name_bind = 'mmd_bind%s'%hash(morph_sliders[kb_name])
if name_bind not in key_blocks:
mesh.shape_key_add(name=name_bind)
mesh.shape_key_add(name=name_bind, from_mix=False)
kb_bind = key_blocks[name_bind]
kb_bind.relative_key = kb
kb_bind.slider_min = -10
Expand Down
18 changes: 18 additions & 0 deletions mmd_tools/operators/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@
from mmd_tools.core.bone import FnBone


@register_wrap
class SelecttObject(Operator):
bl_idname = 'mmd_tools.object_select'
bl_label = 'Select Object'
bl_description = 'Select the object'
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}

name = bpy.props.StringProperty(
name='Name',
description='The object name',
default='',
options={'HIDDEN', 'SKIP_SAVE'},
)

def execute(self, context):
utils.selectAObject(bpy.data.objects[self.name])
return {'FINISHED'}

@register_wrap
class MoveObject(Operator, utils.ItemMoveOp):
bl_idname = 'mmd_tools.object_move'
Expand Down
4 changes: 2 additions & 2 deletions mmd_tools/panels/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def _template_morph_offset_list(self, layout, morph, list_type_name):

def _draw_vertex_data(self, context, rig, col, morph):
r = col.row()
col = r.column()
col = r.column(align=True)
for i in rig.meshes():
shape_keys = i.data.shape_keys
if shape_keys is None:
Expand All @@ -454,7 +454,7 @@ def _draw_vertex_data(self, context, rig, col, morph):
if kb:
found = row = col.row(align=True)
row.active = not (i.show_only_shape_key or kb.mute)
row.label(text=i.name, icon='OBJECT_DATA')
row.operator('mmd_tools.object_select', text=i.name, icon='OBJECT_DATA').name = i.name
row.prop(kb, 'value', text=kb.name)
if 'found' not in locals():
col.label(text='Not found', icon='INFO')
Expand Down

0 comments on commit fd4b35c

Please sign in to comment.