Skip to content

Commit

Permalink
Merge pull request #27 from miu200521358/work_5.01_cython4
Browse files Browse the repository at this point in the history
ver5.01.03
  • Loading branch information
miu200521358 authored Jun 30, 2021
2 parents dfd22a6 + 7298919 commit 31b56a7
Show file tree
Hide file tree
Showing 14 changed files with 392 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
*.bat text eol=crlf
*.csv text eol=crlf
*.txt text eol=crlf
*.spec text encoding=shift-jis eol=crlf
*.spec text eol=crlf
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"version": "0.2.0",
"configurations": [

{
"name": "exec_sizing",
"type": "python",
Expand Down Expand Up @@ -234,6 +235,20 @@
"console": "integratedTerminal",
"python": "${command:python.interpreterPath}",
"stopOnEntry": false,
"args": [
"--verbose", "1",
"--out_log", "1",
]
},
{
"name": "exec_vrm2pmx",
"type": "python",
"request": "launch",
"program": "src/executor.py",
"cwd": "${workspaceFolder}/../vrm2pmx/",
"console": "integratedTerminal",
"python": "${command:python.interpreterPath}",
"stopOnEntry": false,
"args": [
"--verbose", "10",
"--out_log", "1",
Expand Down
31 changes: 28 additions & 3 deletions archive/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

�@�uVMD�T�C�W���O�@���[�J���Łv

�@�@ver5.01.02
�@�@ver5.01.03

�@�@�@�@�@�@�@�@�@�@�@�@�@�@�@�@�@miu200521358

Expand Down Expand Up @@ -36,6 +36,7 @@ https://www.nicovideo.jp/watch/sm37848503

���@�u���}�K
https://ch.nicovideo.jp/miu200521358/blomaga/ar1919098
�i2021/10�܂łɈڍs�\��j

���@�R���e���c�c���[�p��
https://seiga.nicovideo.jp/seiga/im9755721
Expand All @@ -44,7 +45,7 @@ https://seiga.nicovideo.jp/seiga/im9755721
���@�����t�@�C��
----------------------------------------------------------------

�@�EVMDSizing_5.01.02_64bit.exe�@�@�@�c�@�c�[���{�́iver5.00���64bit�ł݂̂ł��j
�@�EVMDSizing_5.01.03_64bit.exe�@�@�@�c�@�c�[���{�́iver5.00���64bit�ł݂̂ł��j
�@�EReadme.txt�@�@�@�@�@�@�@�@�@�@�c�@���h�~
�@�EVMD�T�C�W���OWiki�@�@�@�@�@�@ �c�@Wiki�ւ̃����N
�@�E�R���e���c�c���[�p�É�@�@�@�@�c�@�R���e���c�c���[�p�É�ւ̃����N
Expand Down Expand Up @@ -133,7 +134,7 @@ https://seiga.nicovideo.jp/seiga/im9755721
�@�@�@���W���܂ł̃{�[���ō\�����ꂽ�l�‘����f���Ȃǂ͒������܂��B

�E�‚ܐ�h�j�␳
�@�c�@�‚ܐ�h�j�̈ړ��ʂ��A���h�j�̉�]�ʂɕϊ����܂��B
�@�c�@�‚ܐ�h�j�̈ړ��ʂ��A���h�j�̉�]�ʂɕϊ����܂��B�i�‚ܐ�h�j�̒l�͏����l�ɂȂ�܂��j
�@�@�@�‚ܐ�h�j���g�������[�V�����Ō��ʂ�������₷���ł��B

�E���h�j�␳
Expand All @@ -148,6 +149,7 @@ https://seiga.nicovideo.jp/seiga/im9755721
�E���␳
�@�c�@�����X�^���X�̌��̌X���̈Ⴂ���l�����āA�����f���Ɠ������炢�ɓ������悤�A���ƌ�P�i����΁j�𒲐����܂��B
�@�@�@�����傫���������[�V�������_�C�i�~�b�N�ɂȂ�܂��B
�@�@�@����P�̒l�͌��ɕϊ����ĈڐA���܂��B�i��P�̒l�͏����l�ɂȂ�܂��j

�E�Z���^�[Y�␳
�@�c�@������̘r�̋������A�����f���Ɠ����悤�Ȉʒu�ɍ��킹��悤�A�Z���^�[�𒲐����܂��B
Expand Down Expand Up @@ -395,10 +397,33 @@ https://github.com/miu200521358/vmd_sizing
�@Mail: garnet200521358@gmail.com


----------------------------------------------------------------
���@�R�~���j�e�B�̂��ē�
----------------------------------------------------------------

�@�j�R�j�R�~���j�e�B�Fhttps://com.nicovideo.jp/community/co5387214

�@�@VMD�T�C�W���O�⃂�[�V�����T�|�[�^�[�ȂǁA����c�[���Ɋւ��鏔�X������
�@�@�ꑫ�������ł������Ă����������Ƃ��ł��܂��B
�@�@�T�C�W���O�����܂������Ȃ��ꍇ�̃t�H���[�Ȃǂ��s�����炢���ȁ[�Ǝv���Ă܂��B
�@�@�ꉞ�N���[�Y�h�ł����������F�Ȃ̂ł��C�y�ɂǂ���


----------------------------------------------------------------
���@����
----------------------------------------------------------------

ver5.01.03�@�i2021/06/30�j
�@�@�E�@�\�lj��F�ϊ��O�Ȃǂ̕s���{�[���`�F�b�N���ɁA�{�[���̐������̃`�F�b�N�����킹�čs���悤�����lj�
�@�@�@�@�@�@�@�@���@D�{�[���Ȃǂ������Ă��邪����������Ă���ꍇ�Ȃǂɕ�����₷���Ȃ�܂��B
�@�@�E�@�\�ύX: �ʒu���킹
�@�@�@�@�@�@�@�@�E�Ђ��̊p�x��30�x�����ł���ꍇ�A�ʒu���킹�rIK��������Ђ������O����悤�����lj�
�@�@�@�@�@�@�@�@�@���@����ɔ����Ђ����t�����ɍ��܂���”\�����������͂�
�@�@�E�@�\�ύX�F�r�X�^���X�␳
�@�@�@�@�@�@�@�@�EISAO���~�N�Ŏ�񂪐܂��̂�����ł���悤��������
�@�@�@�@�@�@�@�@�@�iISAO���~�N�̏ꍇ�A���ƒ��w�����f����Ă�̂ŁA�\������x�[�X�ɒ�������j


ver5.01.02�@�i2021/05/04�j
�@�@�E�d�l�ύX�F�X�^���X�lj��␳�́u���h�j�␳�v���m�[�}���̌^���Ƒ��������Ă��܂��̂Ńf�t�H���gOFF�ɕύX
�@�@�EBugfix: IK�v�Z�����̃N�H�[�^�j�I���̂����Z���Ԃ��Ԉ���Ă����̂ŏC���i�ʒu���킹�E�ڐG����̐��x����j
Expand Down
2 changes: 1 addition & 1 deletion src/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from service.SizingService import SizingService
from utils.MException import SizingException

VERSION_NAME = "ver5.01.02"
VERSION_NAME = "ver5.01.03"

# 指数表記なし、有効小数点桁数6、30を超えると省略あり、一行の文字数200
np.set_printoptions(suppress=True, precision=6, threshold=30, linewidth=200)
Expand Down
25 changes: 25 additions & 0 deletions src/form/parts/SizingFileSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def is_loaded_valid(self):
not_org_morphs = []
not_rep_bones = []
not_rep_morphs = []
mismatch_bones = []

motion = self.motion_vmd_file_ctrl.data
org_pmx = self.org_model_file_ctrl.data
Expand Down Expand Up @@ -174,6 +175,25 @@ def is_loaded_valid(self):
if k not in rep_pmx.bones:
not_rep_bones.append(k)

if k in org_pmx.bones and k in rep_pmx.bones:
mismatch_types = []
# 両方にボーンがある場合、フラグが同じであるかチェック
if org_pmx.bones[k].getRotatable() != rep_pmx.bones[k].getRotatable():
mismatch_types.append("性能:回転")
if org_pmx.bones[k].getTranslatable() != rep_pmx.bones[k].getTranslatable():
mismatch_types.append("性能:移動")
if org_pmx.bones[k].getIkFlag() != rep_pmx.bones[k].getIkFlag():
mismatch_types.append("性能:IK")
if org_pmx.bones[k].getVisibleFlag() != rep_pmx.bones[k].getVisibleFlag():
mismatch_types.append("性能:表示")
if org_pmx.bones[k].getManipulatable() != rep_pmx.bones[k].getManipulatable():
mismatch_types.append("性能:操作")
if org_pmx.bones[k].display != rep_pmx.bones[k].display:
mismatch_types.append("表示枠")

if len(mismatch_types) > 0:
mismatch_bones.append(f"{k}  【差異】{', '.join(mismatch_types)})")

# 1件あればOK
break

Expand Down Expand Up @@ -202,6 +222,11 @@ def is_loaded_valid(self):
display_set_no, self.rep_model_file_ctrl.title, rep_pmx.name, ",".join(not_rep_bones), ",".join(not_rep_morphs), decoration=MLogger.DECORATION_BOX)
is_warning = True

if len(mismatch_bones) > 0:
logger.warning("%s%sで、モーションで使用されているボーンの性能等が異なっています。\nモデル: %s\n差異ボーン:\n %s", \
display_set_no, self.rep_model_file_ctrl.title, rep_pmx.name, "\n ".join(mismatch_bones), decoration=MLogger.DECORATION_BOX)
is_warning = True

if not is_warning:
logger.info("モーションで使用されているボーン・モーフが揃っています。", decoration=MLogger.DECORATION_BOX, title="OK")

Expand Down
2 changes: 2 additions & 0 deletions src/module/MMath.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ cdef class MQuaternion:

cpdef double toDegree(self)

cpdef double toDegreeSign(self, MVector3D local_axis)

cpdef double calcTheata(self, MQuaternion v)

cpdef data(self)
Expand Down
10 changes: 10 additions & 0 deletions src/module/MMath.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,16 @@ cdef class MQuaternion:
cpdef double toDegree(self):
return degrees(2 * acos(min(1, max(-1, self.scalar()))))

# 軸による符号付き角度に変換
cpdef double toDegreeSign(self, MVector3D local_axis):
cdef double deg = self.toDegree() * np.sign(MVector3D.dotProduct(self.vector(), local_axis)) * np.sign(self.scalar())

if abs(deg) > 180:
# 180度を超してる場合、フリップなので、除去
return (abs(deg) - 180) * np.sign(deg)

return deg

# 自分ともうひとつの値vとのtheta(変位量)を返す
cpdef double calcTheata(self, MQuaternion v):
return (1 - MQuaternion.dotProduct(self.normalized(), v.normalized()))
Expand Down
13 changes: 13 additions & 0 deletions src/module/MParams.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ cdef class BoneLinks:
def append(self, bone):
self.__links[bone.name] = bone.copy()

# リンクに挿入
def insert(self, bone, prev_bone_name):
new_links = {}
for lidx, lkey in enumerate(self.__links.keys()):
new_links[lkey] = self.__links[lkey].copy()

if lkey == prev_bone_name:
# 直前ボーンが見つかったら、その後に挿入する
new_links[bone.name] = bone.copy()

# 終わったら置き換える
self.__links = new_links

# リンクの反転
def reversed(self):
return reversed(self.__links)
Expand Down
10 changes: 8 additions & 2 deletions src/service/parts/ArmAlignmentService.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,13 @@ cdef class ArmAlignmentService:
if is_avoidance_arm_x:
# 腕X回避済みのため、除去
ik_links = ik_links.remove_links(["{0}腕".format(ik_links.first_name()[0]), "{0}腕捩".format(ik_links.first_name()[0])])
else:
elbow_bone_name = "{0}ひじ".format(ik_links.first_name()[0])

# ひじの角度が浅い場合、ひじ対象外とする
if elbow_bone_name in org_bfs and org_bfs[elbow_bone_name].org_rotation.toDegree() < 30:
ik_links = ik_links.remove_links([elbow_bone_name])

for now_ik_max_count in range(1):
now_ik_links = ik_links # .from_links(target_bone_names[-1])
# if ik_cnt > 0:
Expand Down Expand Up @@ -1139,12 +1145,12 @@ cdef class ArmAlignmentService:
now_ik_links = target_link.tip_ik_links

# IK処理実行
for now_ik_max_count in range(1, 10):
for now_ik_max_count in range(1):
logger.debug("先端IK計算開始(%s): f: %s(%s:%s), 現在[%s], 指定[%s]", now_ik_max_count, fno, (data_set_idx + 1), \
list(now_ik_links.all().keys()), rep_global_tip.to_log(), rep_target_global_tip.to_log())

# IK計算実行
MServiceUtils.c_calc_IK(data_set.rep_model, target_link.rep_links, data_set.motion, fno, rep_target_global_tip, now_ik_links, max_count=1)
MServiceUtils.c_calc_IK(data_set.rep_model, target_link.rep_links, data_set.motion, fno, rep_target_global_tip, now_ik_links, max_count=10)

# 現在のエフェクタ位置
aligned_rep_global_3ds, _ = MServiceUtils.c_calc_global_pos(data_set.rep_model, target_link.rep_links, data_set.motion, fno, return_matrix=False, is_local_x=False, limit_links=None)
Expand Down
32 changes: 29 additions & 3 deletions src/service/parts/StanceService.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ cdef class StanceService():
elbow_local_z2y_axis = elbow_y2z_qq * elbow_local_y_axis

# 腕のスタンス差
arm_diff_qq_dic = self.calc_arm_stance(data_set)
arm_diff_qq_dic = self.calc_arm_stance(data_set, data_set_idx)
elbow_stance_degree = (arm_diff_qq_dic[elbow_bone_name]["from"].inverted() * arm_diff_qq_dic[elbow_bone_name]["to"]).toDegree()
logger.debug("%s: elbow_stance_degree: %s, from: %s, to: %s", elbow_bone_name, elbow_stance_degree, arm_diff_qq_dic[elbow_bone_name]["from"].toDegree(), arm_diff_qq_dic[elbow_bone_name]["to"].toDegree())

Expand Down Expand Up @@ -3792,7 +3792,7 @@ cdef class StanceService():
logger.info("腕スタンス補正 【No.%s", (data_set_idx + 1), decoration=MLogger.DECORATION_LINE)

# 腕のスタンス差
arm_diff_qq_dic = self.calc_arm_stance(data_set)
arm_diff_qq_dic = self.calc_arm_stance(data_set, data_set_idx)

futures = []
with ThreadPoolExecutor(thread_name_prefix="arm{0}".format(data_set_idx), max_workers=self.options.max_workers) as executor:
Expand Down Expand Up @@ -3888,7 +3888,7 @@ cdef class StanceService():
raise e

# 腕スタンス補正用傾き計算
cdef dict calc_arm_stance(self, MOptionsDataSet data_set):
cdef dict calc_arm_stance(self, MOptionsDataSet data_set, int data_set_idx):
cdef dict arm_diff_qq_dic = {}
cdef str from_bone_name, target_bone_name, to_bone_name
cdef list bone_names
Expand Down Expand Up @@ -3924,6 +3924,32 @@ cdef class StanceService():
_, org_to_qq = data_set.org_model.calc_arm_stance(target_bone_name, to_bone_name)
_, rep_to_qq = data_set.rep_model.calc_arm_stance(target_bone_name, to_bone_name)

if "手首" in target_bone_name and f"{direction}中指2" in data_set.org_model.bones and f"{direction}中指2" in data_set.rep_model.bones:
org_wrist2finger1 = data_set.org_model.bones[f"{direction}手首"].position.distanceToPoint(data_set.org_model.bones[f"{direction}中指1"].position)
org_finget12finger3 = data_set.org_model.bones[f"{direction}中指1"].position.distanceToPoint(data_set.org_model.bones[f"{direction}中指3"].position)

logger.debug(f"手首-指1: {org_wrist2finger1}")
logger.debug(f"指1-指3: {org_finget12finger3)}")

rep_wrist2finger1 = data_set.rep_model.bones[f"{direction}手首"].position.distanceToPoint(data_set.rep_model.bones[f"{direction}中指1"].position)
rep_finget12finger3 = data_set.rep_model.bones[f"{direction}中指1"].position.distanceToPoint(data_set.rep_model.bones[f"{direction}中指3"].position)

logger.debug(f"手首-指1: {rep_wrist2finger1}")
logger.debug(f"指1-指3: {rep_finget12finger3)}")

if org_wrist2finger1 > org_finget12finger3 * 2 or rep_wrist2finger1 > rep_finget12finger3 * 2:
# ISAO式ミクの場合、手首と中指が分断されてるので、表示先をベースに調整する
if direction == "":
if org_wrist2finger1 > org_finget12finger3 * 2:
logger.warning(f"作成元モデルの、手首から中指付け根までの長さ({round(org_wrist2finger1, 4)})が中指の長さx2の長さ({round(org_finget12finger3 * 2, 4)})より長いため、手首の表示先で傾きを調整します。【No.{(data_set_idx + 1)}】")

if rep_wrist2finger1 > rep_finget12finger3 * 2:
logger.warning(f"変換先モデルの、手首から中指付け根までの長さ({round(rep_wrist2finger1, 4)})が中指の長さx2の長さ({round(rep_finget12finger3 * 2, 4)})より長いため、手首の表示先で傾きを調整します。【No.{(data_set_idx + 1)}】")

# TARGET-TOの傾き
_, org_to_qq = data_set.org_model.calc_arm_stance(target_bone_name, None)
_, rep_to_qq = data_set.rep_model.calc_arm_stance(target_bone_name, None)

arm_diff_qq_dic[target_bone_name]["to"] = rep_to_qq.inverted() * org_to_qq

return arm_diff_qq_dic
Expand Down
Loading

0 comments on commit 31b56a7

Please sign in to comment.