@@ -136,7 +136,7 @@ def vroid2pmx(self):
136136 if not model :
137137 return False
138138
139- model = self .transfer_astance (model )
139+ model = self .transfer_stance (model )
140140 if not model :
141141 return False
142142
@@ -788,7 +788,7 @@ def create_body_rigidbody(self, model: PmxModel):
788788
789789 return model
790790
791- def transfer_astance (self , model : PmxModel ):
791+ def transfer_stance (self , model : PmxModel ):
792792 # 各頂点
793793 all_vertex_relative_poses = {}
794794 for vertex in model .vertex_dict .values ():
@@ -851,22 +851,38 @@ def transfer_astance(self, model: PmxModel):
851851 trans_vs = MServiceUtils .calc_relative_position (model , bone_links , VmdMotion (), 0 )
852852
853853 if "右" in "," .join (list (bone_links .all ().keys ())):
854- astance_qq = MQuaternion .fromEulerAngles (0 , 0 , 35 )
854+ arm_astance_qq = MQuaternion .fromEulerAngles (0 , 0 , 35 )
855855 arm_bone_name = "右腕"
856+ thumb0_stance_qq = MQuaternion .fromEulerAngles (0 , 8 , 0 )
857+ thumb0_bone_name = "右親指0"
858+ thumb1_stance_qq = MQuaternion .fromEulerAngles (0 , 24 , 0 )
859+ thumb1_bone_name = "右親指1"
856860 elif "左" in "," .join (list (bone_links .all ().keys ())):
857- astance_qq = MQuaternion .fromEulerAngles (0 , 0 , - 35 )
861+ arm_astance_qq = MQuaternion .fromEulerAngles (0 , 0 , - 35 )
858862 arm_bone_name = "左腕"
863+ thumb0_stance_qq = MQuaternion .fromEulerAngles (0 , - 8 , 0 )
864+ thumb0_bone_name = "左親指0"
865+ thumb1_stance_qq = MQuaternion .fromEulerAngles (0 , - 24 , 0 )
866+ thumb1_bone_name = "左親指1"
859867 else :
860- astance_qq = MQuaternion .fromEulerAngles (0 , 0 , 0 )
868+ arm_astance_qq = MQuaternion .fromEulerAngles (0 , 0 , 0 )
861869 arm_bone_name = ""
870+ thumb0_bone_name = ""
871+ thumb1_bone_name = ""
862872
863873 mat = MMatrix4x4 ()
864874 mat .setToIdentity ()
865875 for vi , (bone_name , trans_v ) in enumerate (zip (bone_links .all ().keys (), trans_vs )):
866876 mat .translate (trans_v )
867877 if bone_name == arm_bone_name :
868- # 腕だけ回転させる
869- mat .rotate (astance_qq )
878+ # 腕回転させる
879+ mat .rotate (arm_astance_qq )
880+ elif bone_name == thumb0_bone_name :
881+ # 親指0回転させる
882+ mat .rotate (thumb0_stance_qq )
883+ elif bone_name == thumb1_bone_name :
884+ # 親指1回転させる
885+ mat .rotate (thumb1_stance_qq )
870886
871887 if bone_name not in trans_bone_vecs :
872888 trans_bone_vecs [bone_name ] = mat * MVector3D ()
@@ -1005,7 +1021,7 @@ def transfer_astance(self, model: PmxModel):
10051021 model .vertex_dict [vertex_idx ].position = vertex_vec
10061022 model .vertex_dict [vertex_idx ].normal = vertex_normal .normalized ()
10071023
1008- logger .info ("-- Aスタンス調整終了 " )
1024+ logger .info ("-- Aスタンス・親指調整終了 " )
10091025
10101026 return model
10111027
@@ -1733,51 +1749,56 @@ def reconvert_bone(self, model: PmxModel):
17331749 tongue_poses .append (v .position .data ())
17341750 v .deform = Bdef1 (model .bones ["舌1" ].index )
17351751
1736- # 舌ボーン位置配置
1737- tongue1_pos = np .max (tongue_poses , axis = 0 )
1738- model .bones ["舌1" ].position = MVector3D (0 , tongue1_pos [1 ], tongue1_pos [2 ])
1739- tongue4_pos = np .min (tongue_poses , axis = 0 )
1740- model .bones ["舌4" ].position = MVector3D (0 , tongue4_pos [1 ], tongue4_pos [2 ])
1741- model .bones ["舌2" ].position = model .bones ["舌1" ].position + (
1742- (model .bones ["舌4" ].position - model .bones ["舌1" ].position ) * 0.4
1743- )
1744- model .bones ["舌3" ].position = model .bones ["舌1" ].position + (
1745- (model .bones ["舌4" ].position - model .bones ["舌1" ].position ) * 0.7
1746- )
1747-
1748- for from_bone_name , to_bone_name in [("舌1" , "舌2" ), ("舌2" , "舌3" ), ("舌3" , "舌4" )]:
1749- # ローカル軸
1750- model .bones [from_bone_name ].local_x_vector = (
1751- model .bones [to_bone_name ].position - model .bones [from_bone_name ].position
1752- ).normalized ()
1753- model .bones [from_bone_name ].local_z_vector = MVector3D .crossProduct (
1754- model .bones [from_bone_name ].local_x_vector , MVector3D (0 , - 1 , 0 )
1755- ).normalized ()
1756- model .bones ["舌4" ].local_x_vector = model .bones ["舌3" ].local_x_vector .copy ()
1757- model .bones ["舌4" ].local_z_vector = model .bones ["舌3" ].local_z_vector .copy ()
1752+ if tongue_poses and tongue_vertices and tongue_vidxs :
1753+ # 舌ボーン位置配置
1754+ tongue1_pos = np .max (tongue_poses , axis = 0 )
1755+ model .bones ["舌1" ].position = MVector3D (0 , tongue1_pos [1 ], tongue1_pos [2 ])
1756+ tongue4_pos = np .min (tongue_poses , axis = 0 )
1757+ model .bones ["舌4" ].position = MVector3D (0 , tongue4_pos [1 ], tongue4_pos [2 ])
1758+ model .bones ["舌2" ].position = model .bones ["舌1" ].position + (
1759+ (model .bones ["舌4" ].position - model .bones ["舌1" ].position ) * 0.4
1760+ )
1761+ model .bones ["舌3" ].position = model .bones ["舌1" ].position + (
1762+ (model .bones ["舌4" ].position - model .bones ["舌1" ].position ) * 0.7
1763+ )
17581764
1759- for vertex in tongue_vertices :
17601765 for from_bone_name , to_bone_name in [("舌1" , "舌2" ), ("舌2" , "舌3" ), ("舌3" , "舌4" )]:
1761- tongue_distance = model .bones [to_bone_name ].position .z () - model .bones [from_bone_name ].position .z ()
1762- vertex_distance = vertex .position .z () - model .bones [from_bone_name ].position .z ()
1763-
1764- if np .sign (tongue_distance ) == np .sign (vertex_distance ):
1765- # 範囲内である場合、ウェイト分布
1766- vertex .deform = Bdef2 (
1767- model .bones [to_bone_name ].index ,
1768- model .bones [from_bone_name ].index ,
1769- vertex_distance / tongue_distance ,
1766+ # ローカル軸
1767+ model .bones [from_bone_name ].local_x_vector = (
1768+ model .bones [to_bone_name ].position - model .bones [from_bone_name ].position
1769+ ).normalized ()
1770+ model .bones [from_bone_name ].local_z_vector = MVector3D .crossProduct (
1771+ model .bones [from_bone_name ].local_x_vector , MVector3D (0 , - 1 , 0 )
1772+ ).normalized ()
1773+ model .bones ["舌4" ].local_x_vector = model .bones ["舌3" ].local_x_vector .copy ()
1774+ model .bones ["舌4" ].local_z_vector = model .bones ["舌3" ].local_z_vector .copy ()
1775+
1776+ for vertex in tongue_vertices :
1777+ for from_bone_name , to_bone_name in [("舌1" , "舌2" ), ("舌2" , "舌3" ), ("舌3" , "舌4" )]:
1778+ tongue_distance = (
1779+ model .bones [to_bone_name ].position .z () - model .bones [from_bone_name ].position .z ()
17701780 )
1781+ vertex_distance = vertex .position .z () - model .bones [from_bone_name ].position .z ()
1782+
1783+ if np .sign (tongue_distance ) == np .sign (vertex_distance ):
1784+ # 範囲内である場合、ウェイト分布
1785+ vertex .deform = Bdef2 (
1786+ model .bones [to_bone_name ].index ,
1787+ model .bones [from_bone_name ].index ,
1788+ vertex_distance / tongue_distance ,
1789+ )
17711790
1772- # 舌頂点モーフを削除
1773- for morph in model .org_morphs .values ():
1774- if morph .morph_type == 1 :
1775- # 頂点モーフの場合
1776- without_tongue_offsets = []
1777- for offset in morph .offsets :
1778- if offset .vertex_index not in tongue_vidxs :
1779- without_tongue_offsets .append (offset )
1780- morph .offsets = without_tongue_offsets
1791+ # 舌頂点モーフを削除
1792+ for morph in model .org_morphs .values ():
1793+ if morph .morph_type == 1 :
1794+ # 頂点モーフの場合
1795+ without_tongue_offsets = []
1796+ for offset in morph .offsets :
1797+ if offset .vertex_index not in tongue_vidxs :
1798+ without_tongue_offsets .append (offset )
1799+ morph .offsets = without_tongue_offsets
1800+ else :
1801+ logger .warning ("舌関連頂点が見つからなかったため、舌分離処理をスキップします" , decoration = MLogger .DECORATION_BOX )
17811802
17821803 logger .info ("-- ボーンデータ調整終了" )
17831804
0 commit comments