@@ -672,8 +672,26 @@ def __export_bone_morphs(self, root):
672
672
return
673
673
categories = self .CATEGORIES
674
674
pose_bones = self .__armature .pose .bones
675
- use_pose_mode = mmd_root .is_built and self .__armature .data .pose_position != 'REST'
676
- bone_util_cls = BoneConverterPoseMode if use_pose_mode else BoneConverter
675
+ matrix_world = self .__armature .matrix_world
676
+ bone_util_cls = BoneConverterPoseMode if self .__armature .data .pose_position != 'REST' else BoneConverter
677
+
678
+ class _RestBone :
679
+ def __init__ (self , b ):
680
+ self .matrix_local = matmul (matrix_world , b .bone .matrix_local )
681
+
682
+ class _PoseBone : # world space
683
+ def __init__ (self , b ):
684
+ self .bone = _RestBone (b )
685
+ self .matrix = matmul (matrix_world , b .matrix )
686
+ self .matrix_basis = b .matrix_basis
687
+ self .location = b .location
688
+
689
+ converter_cache = {}
690
+ def _get_converter (b ):
691
+ if b not in converter_cache :
692
+ converter_cache [b ] = bone_util_cls (_PoseBone (blender_bone ), self .__scale , invert = True )
693
+ return converter_cache [b ]
694
+
677
695
for morph in mmd_root .bone_morphs :
678
696
bone_morph = pmx .BoneMorph (
679
697
name = morph .name ,
@@ -690,7 +708,7 @@ def __export_bone_morphs(self, root):
690
708
if blender_bone is None :
691
709
logging .warning ('Bone Morph (%s): Bone "%s" was not found.' , morph .name , data .bone )
692
710
continue
693
- converter = bone_util_cls (blender_bone , self . __scale , invert = True )
711
+ converter = _get_converter (blender_bone )
694
712
morph_data .location_offset = converter .convert_location (data .location )
695
713
rw , rx , ry , rz = data .rotation
696
714
rw , rx , ry , rz = converter .convert_rotation ([rx , ry , rz , rw ])
@@ -1126,10 +1144,12 @@ def __init__(self, uvs):
1126
1144
shape_key_name = kb .name
1127
1145
logging .info (' - processing shape key: %s' , shape_key_name )
1128
1146
kb_mute , kb .mute = kb .mute , False
1147
+ kb_value , kb .value = kb .value , 1.0
1129
1148
meshObj .active_shape_key_index = i
1130
1149
mesh = _to_mesh (meshObj )
1131
1150
mesh .transform (pmx_matrix )
1132
1151
kb .mute = kb_mute
1152
+ kb .value = kb_value
1133
1153
if len (mesh .vertices ) != len (base_vertices ):
1134
1154
logging .warning (' * Error! vertex count mismatch!' )
1135
1155
continue
@@ -1174,7 +1194,6 @@ def __init__(self, uvs):
1174
1194
1175
1195
def __loadMeshData (self , meshObj , bone_map ):
1176
1196
show_only_shape_key = meshObj .show_only_shape_key
1177
- meshObj .show_only_shape_key = True
1178
1197
active_shape_key_index = meshObj .active_shape_key_index
1179
1198
meshObj .active_shape_key_index = 0
1180
1199
uv_textures = getattr (meshObj .data , 'uv_textures' , meshObj .data .uv_layers )
@@ -1191,6 +1210,7 @@ def __loadMeshData(self, meshObj, bone_map):
1191
1210
1192
1211
try :
1193
1212
logging .info ('Loading mesh: %s' , meshObj .name )
1213
+ meshObj .show_only_shape_key = bool (muted_modifiers )
1194
1214
return self .__doLoadMeshData (meshObj , bone_map )
1195
1215
finally :
1196
1216
meshObj .show_only_shape_key = show_only_shape_key
0 commit comments