블랜더로 본을 만들다보면 mmd에 쓰던 본에서 뭘 자꾸 추가하고 붙이면서 VMD 파일의 움직임을 따르지않는 순간이 찾아오게됨. 더 편리하게 모션을 만들고싶어서 추가했던 본들이 VMD를 써야할때는 그것을 방해하기때문인것.
그래서 더미로 mmd 본을 하나 더 만들고 그 더미가 VMD파일로 춤추게 만들어놓고 원본은 그 더미의 움직임을 따라하도록 constraint을 붙이게되는데 이게 본 하나하나를 더미의 본을 따라하라고 설정해줘야되는 노동임.
춤을 따라할 필요가없을때는 다시 constraint 설정을 하나씩 꺼줘야하는 수고가 들어감. 이것을 딸깍으로 해결하기위해서 만든거임. text editor에서 사용할수있음
딴거 볼거없고 빨간네모칸 두개만 보면됨. 위에 네모는 on버튼 눌렀을때 영향을 받고 아래 네모는 off버튼 눌렀을때 영향을받음
저 안에 들어있는 영어로 뒤덮인 어쩌고는 전부 본이 가진 constraint 주소임
원하는 본의 constraint주소를 저기에 붙여넣으면 된다는뜻
그 주소를 어떻게 아는데?
사진처럼 copy full data path 를 누르면 복사가된거임
bpy.data.objects["Armature.003"].pose.bones["Bone.003"].constraints["Child Of"].influence
내꺼 경우에는 복사한걸 보면 저렇게 나옴. Armature.003 틀린거없고 Bone.003일치하고 Child Of인거도 똑같지. 이것을 빨간 네모안에서 인식할수있게 바꿔주면됨.
set_influence_from_path("bpy.data.objects['Armature.003'].pose.bones['Bone.003'].constraints['Child Of']", 1.0) 이렇게 바꿔서 저 빨간 네모칸 안에 붙여주면 그 해당 값은 앞으로 딸깍으로 1.0로 on 할수있는거임
패턴을 보아하니
set_influence_from_path("", 1.0) 사이에 bpy.data.objects['Armature.003'].pose.bones['Bone.003'].constraints['Child Of']를 끼워넣는 일관성이 보인다.
그리고 " 이었던게 '로 바뀌었음. '로 바꿔줘야 인식함.
그리고 마지막에 1.0 은 constraint을 1.0으로 바꾸라는 뜻이되겠지. 반대로 0.0으로 바꿔넣으면 constraint은 0.0이 바뀔거임
여기까지 한개의 본을 추가해보았다면 두번째 본 부터는 반복이야. 주소값 복사해서 '로 바꿔주고 set_influence_from_path("", 1.0) 사이에 끼워주고 빨간 네모안에 붙여넣고의 반복임 이걸 모든 본의 주소값을 복붙하는걸 반복하는거지. 그래서 자기 입맛대로 커스텀하는거지.
on 눌렀을때는 1.0으로 되게 빨간네모를 채우고 off 눌렀을때는 0.0으로 되게 빨간네모를 채워넣으면 딸깍이 완성됨
여기까지왔다면 예시로 넣은 주소값이 어떤거고 그것을 어디까지 지우고 자기꺼로 채워넣으면 될지를 알고있을거야
text editor에서 재생버튼을 누르면 on off 버튼이 생길거야. 이름은 MMD mode 인데 바꿔서 쓰면돼
import bpy
# 경로를 하나의 문자열로 관리하고, 이를 사용하여 influence 값을 변경하는 함수
def set_influence_from_path(data_path, influence_value):
try:
# 경로를 eval()로 처리하여 속성에 접근
eval(data_path).influence = influence_value
except Exception as e:
print(f"Error setting influence for path '{data_path}': {str(e)}")
class MMD_PT_ModePanel(bpy.types.Panel):
bl_label = "MMD Mode"
bl_idname = "MMD_PT_mode_panel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "MMD Mode"
@classmethod
def poll(cls, context):
return context.mode == 'POSE'
def draw(self, context):
layout = self.layout
layout.operator("mmdmode.enable", text="On", icon='CHECKMARK')
layout.operator("mmdmode.disable", text="Off", icon='CANCEL')
class MMD_OT_Enable(bpy.types.Operator):
bl_idname = "mmdmode.enable"
bl_label = "Enable MMD Mode"
def execute(self, context):
try:
# 경로에 해당하는 influence 값을 1.0으로 설정
set_influence_from_path("bpy.data.objects['Armature'].pose.bones['Bone'].constraints['Copy Rotation']", 1.0)
set_influence_from_path("bpy.data.objects['Armature'].pose.bones['Bone.001'].constraints['Copy Rotation']", 1.0)
set_influence_from_path("bpy.data.objects['Armature'].pose.bones['Bone.002'].constraints['Copy Rotation']", 1.0)
set_influence_from_path("bpy.data.objects['Armature.003'].pose.bones['Bone.002'].constraints['Child Of']", 1.0)
set_influence_from_path("bpy.data.objects['Armature.003'].pose.bones['Bone.003'].constraints['Child Of']", 1.0)
set_influence_from_path("bpy.data.objects['Armature.003'].pose.bones['Bone.004'].constraints['Track To']", 1.0)
set_influence_from_path("bpy.data.objects['Armature.003'].pose.bones['Bone.004'].constraints['Damped Track']", 1.0)
set_influence_from_path("bpy.data.objects['Armature.002'].pose.bones['Bone'].constraints['Clamp To']", 1.0)
set_influence_from_path("bpy.data.objects['Armature.002'].pose.bones['Bone.001'].constraints['Child Of']", 1.0)
set_influence_from_path("bpy.data.objects['Armature'].pose.bones['Bone.003'].constraints['Copy Rotation']", 0.0)
set_influence_from_path("bpy.data.objects['Armature'].pose.bones['Bone.004'].constraints['Copy Rotation']", 0.0)
set_influence_from_path("bpy.data.objects['Armature.002'].pose.bones['Bone.002'].constraints['Track To']", 0.0)
self.report({'INFO'}, "MMD Mode Enabled")
except Exception as e:
self.report({'ERROR'}, str(e))
return {'FINISHED'}
class MMD_OT_Disable(bpy.types.Operator):
bl_idname = "mmdmode.disable"
bl_label = "Disable MMD Mode"
def execute(self, context):
try:
# 경로에 해당하는 influence 값을 0.0으로 설정
set_influence_from_path("bpy.data.objects['Armature'].pose.bones['Bone'].constraints['Copy Rotation']", 0.0)
set_influence_from_path("bpy.data.objects['Armature'].pose.bones['Bone.001'].constraints['Copy Rotation']", 0.0)
set_influence_from_path("bpy.data.objects['Armature'].pose.bones['Bone.002'].constraints['Copy Rotation']", 0.0)
set_influence_from_path("bpy.data.objects['Armature.003'].pose.bones['Bone.002'].constraints['Child Of']", 0.0)
set_influence_from_path("bpy.data.objects['Armature.003'].pose.bones['Bone.003'].constraints['Child Of']", 0.0)
set_influence_from_path("bpy.data.objects['Armature.003'].pose.bones['Bone.004'].constraints['Track To']", 0.0)
set_influence_from_path("bpy.data.objects['Armature.003'].pose.bones['Bone.004'].constraints['Damped Track']", 0.0)
set_influence_from_path("bpy.data.objects['Armature.002'].pose.bones['Bone'].constraints['Clamp To'].influence", 0.0)
set_influence_from_path("bpy.data.objects['Armature.002'].pose.bones['Bone.001'].constraints['Child Of']", 0.0)
set_influence_from_path("bpy.data.objects['Armature'].pose.bones['Bone.003'].constraints['Copy Rotation']", 1.0)
set_influence_from_path("bpy.data.objects['Armature'].pose.bones['Bone.004'].constraints['Copy Rotation']", 1.0)
set_influence_from_path("bpy.data.objects['Armature.002'].pose.bones['Bone.002'].constraints['Track To']", 1.0)
self.report({'INFO'}, "MMD Mode Disabled")
except Exception as e:
self.report({'ERROR'}, str(e))
return {'FINISHED'}
def register():
bpy.utils.register_class(MMD_PT_ModePanel)
bpy.utils.register_class(MMD_OT_Enable)
bpy.utils.register_class(MMD_OT_Disable)
def unregister():
bpy.utils.unregister_class(MMD_PT_ModePanel)
bpy.utils.unregister_class(MMD_OT_Enable)
bpy.utils.unregister_class(MMD_OT_Disable)
if __name__ == "__main__":
register()
