First Commit

This commit is contained in:
2026-04-08 11:47:23 +02:00
committed by GitHub
parent 67b5d118c2
commit 96d567eb9e
11 changed files with 1050 additions and 0 deletions

18
utilities/constants.py Normal file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
MMD_VISEME_COUNT = 5
MMD_SEP_1 = '---MMD Visemes---'
MMD_SEP_2 = '^MMD Visemes / Other v'
MMD_CANDIDATES = {
'a': ['', 'a', 'A', 'mouth_a', 'Mouth_A', 'あ口', 'v_a'],
'o': ['', 'o', 'O', 'mouth_o', 'Mouth_O', 'お口', 'v_o'],
'ch': ['', 'ch', 'CH', 'mouth_i', 'Mouth_I', 'い口', 'v_ch', 'i', 'I'],
'blink': [
'まばたき', '目閉じ', '眼閉じ', 'ウィンク2',
'Blink', 'blink', 'blink_all',
'eye_blink', 'Eye_Blink', 'eyes_blink', 'Eyes_Blink',
'eye_close', 'Eye_Close', 'eyes_close', 'Eyes_Close',
],
}

61
utilities/functions.py Normal file
View File

@@ -0,0 +1,61 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from collections import OrderedDict
MMD_JP_MAPPING = [
('', 'a', 'A (あ)', ['ah', 'a', 'A', 'vrc.v_aa', '']),
('', 'i', 'I / CH (い)', ['ch', 'i', 'I', 'CH', 'vrc.v_ch', 'vrc.v_ih', '']),
('', 'u', 'U (う)', ['u', 'U', 'vrc.v_ou', '']),
('', 'e', 'E (え)', ['e', 'E', 'vrc.v_e', '']),
('', 'o', 'O (お)', ['oh', 'o', 'O', 'vrc.v_oh', '']),
('笑い', 'warau', 'Blink Happy (笑い)', ['blink_happy', 'BlinkHappy', 'blink happy', 'smile', '笑い']),
('はう', 'hau', 'Close >< (はう)', ['close><', 'hau', 'はう']),
('ウィンク', 'wink', 'Wink (ウィンク)', ['wink', 'Wink', 'ウィンク']),
('ウィンク右', 'wink_r', 'Wink Right (ウィンク右)', ['wink_right', 'WinkRight', 'wink right', 'ウィンク右']),
('ウィンク2', 'wink2', 'Wink 2 (ウィンク2)', ['wink_2', 'wink2', 'Wink2', 'wink 2', 'ウィンク2']),
('ウィンク2右','wink2_r', 'Wink 2 Right (ウィンク2右)',['wink_2_right', 'Wink2Right', 'wink 2 right', 'ウィンク2右']),
('にこり', 'nikori', 'Cheerful (にこり)', ['cheerful', 'Cheerful', 'nikori', 'にこり']),
('真面目', 'majime', 'Serious (真面目)', ['serious', 'Serious', 'stare', 'calm', '真面目']),
('怒り', 'ikari', 'Anger (怒り)', ['anger', 'angry', 'Anger', 'Angry', '怒り']),
('困る', 'komaru', 'Sadness (困る)', ['sadness', 'sad', 'Sadness', 'Sad', 'komaru', '困る']),
]
VRC_ORDER = [
'vrc.v_sil',
'vrc.v_aa',
'vrc.v_ch',
'vrc.v_dd',
'vrc.v_e',
'vrc.v_ff',
'vrc.v_ih',
'vrc.v_kk',
'vrc.v_nn',
'vrc.v_oh',
'vrc.v_ou',
'vrc.v_pp',
'vrc.v_rr',
'vrc.v_ss',
'vrc.v_th',
'vrc.blink',
]
def build_viseme_map(shape_a, shape_o, shape_ch):
m = OrderedDict()
m['vrc.v_aa'] = [(shape_a, 0.9998)]
m['vrc.v_ch'] = [(shape_ch, 0.9996)]
m['vrc.v_dd'] = [(shape_a, 0.3), (shape_ch, 0.7)]
m['vrc.v_e'] = [(shape_a, 0.5), (shape_ch, 0.2)]
m['vrc.v_ff'] = [(shape_a, 0.2), (shape_ch, 0.4)]
m['vrc.v_ih'] = [(shape_ch, 0.7), (shape_o, 0.3)]
m['vrc.v_kk'] = [(shape_a, 0.7), (shape_ch, 0.4)]
m['vrc.v_nn'] = [(shape_a, 0.2), (shape_ch, 0.7)]
m['vrc.v_oh'] = [(shape_a, 0.2), (shape_o, 0.8)]
m['vrc.v_ou'] = [(shape_o, 0.9994)]
m['vrc.v_pp'] = [(shape_a, 0.0004), (shape_o, 0.0004)]
m['vrc.v_rr'] = [(shape_ch, 0.5), (shape_o, 0.3)]
m['vrc.v_sil'] = [(shape_a, 0.0002), (shape_ch, 0.0002)]
m['vrc.v_ss'] = [(shape_ch, 0.8)]
m['vrc.v_th'] = [(shape_a, 0.4), (shape_o, 0.15)]
return m

42
utilities/helpers.py Normal file
View File

@@ -0,0 +1,42 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class _PreviewState:
active = False
saved_values: dict = {}
_ps = _PreviewState()
def guess_shape(mesh_obj, candidates):
if not mesh_obj or not mesh_obj.data.shape_keys:
return ''
keys = [k.name for k in mesh_obj.data.shape_keys.key_blocks]
for c in candidates:
if c in keys:
return c
return ''
def _save_shapekey_values(mesh_obj):
_ps.saved_values = {k.name: k.value for k in mesh_obj.data.shape_keys.key_blocks}
def _restore_shapekey_values(mesh_obj):
for k in mesh_obj.data.shape_keys.key_blocks:
k.value = _ps.saved_values.get(k.name, 0.0)
def _reset_all_shapekeys(mesh_obj):
for k in mesh_obj.data.shape_keys.key_blocks:
k.value = 0.0
def _apply_mix(mesh_obj, mix, intensity):
_reset_all_shapekeys(mesh_obj)
keys = mesh_obj.data.shape_keys.key_blocks
for shape_name, weight in mix:
if shape_name in keys:
keys[shape_name].value = weight * intensity