勝手に自動ウェイトしたりArmature設定とかするスクリプト
書いた人: formerpaper.icon
cluster向けに作ったロリレルちゃん向けなので、オブジェクト名やボーン構造はロリレルちゃんのものになっています。 やっていること:肌のメッシュに指定ボーンを自動のウェイトで適用→関連する服などにウェイトの転送→(自動ウェイトの邪魔になるので分離している)髪の毛のArmatureと身体のArmatureをJoin→分離しているHairボーンをHeadボーンにくっつける→JoinしたArmatureを身体や服などのArmatureモディファイアに指定
なんかシングルクオーテーションとダブルクオーテーションが混ざってしまってますが見なかったことにして下さい。
コピペ/参考にしてきたサイトが違うとか自分で書いたとかそういう違いです、多分
code:doChangeBone.py
import bpy
bpy.context.view_layer.objects.active = None
for obj in bpy.data.objects:
obj.select_set(False)
bpy.context.view_layer.objects.active = skin
bpy.ops.object.vertex_group_add()
bpy.ops.object.vertex_group_remove(all=True)
bpy.ops.object.modifier_remove(modifier="Armature")
for obj in bpy.data.objects:
obj.select_set(False)
skin.select_set(True)
arm_body.select_set(True)
bpy.context.view_layer.objects.active = arm_body
bpy.ops.object.parent_set(type='ARMATURE_AUTO')
skin.select_set(False)
arm_body.select_set(False)
for s in childs:
bpy.context.view_layer.objects.active = bpy.data.objectss bpy.ops.object.modifier_add(type='DATA_TRANSFER')
bpy.context.object.modifiers"DataTransfer".data_types_verts = {'VGROUP_WEIGHTS'} bpy.ops.object.datalayout_transfer(modifier="DataTransfer")
bpy.ops.object.modifier_apply(modifier="DataTransfer")
bpy.data.objectss.select_set(False) bpy.ops.object.duplicate(
{"object": arm_body,
linked=False)
arm_fbx = bpy.context.selected_objects0 arm_tmp = bpy.context.selected_objects1 for obj in bpy.data.objects:
obj.select_set(False)
arm_fbx.select_set(True)
arm_tmp.select_set(True)
bpy.context.view_layer.objects.active = arm_fbx
bpy.ops.object.join()
arm_fbx = bpy.context.view_layer.objects.active
arm_fbx.name = 'Armature.fbx'
bpy.ops.object.editmode_toggle()
head = arm_fbx.data.edit_bones.get('Head')
hair = arm_fbx.data.edit_bones.get('Hair')
hair.parent = head
hair.use_connect = True
bpy.ops.object.editmode_toggle()
for obj in bpy.data.objects:
obj.select_set(False)
bpy.context.view_layer.objects.active = skin
bpy.context.object.modifiers"Armature".object = arm_fbx for s in childs:
bpy.context.view_layer.objects.active = bpy.data.objectss bpy.context.object.modifiers"Armature".object = arm_fbx bpy.context.view_layer.objects.active = None
for obj in bpy.data.objects:
obj.select_set(False)
bpy.context.view_layer.objects.active = skin
bpy.context.object.modifiers"Armature".object = arm_fbx for s in childs:
bpy.context.view_layer.objects.active = bpy.data.objectss bpy.context.object.modifiers"Armature".object = arm_fbx for s in no_paint_child:
bpy.context.view_layer.objects.active = bpy.data.objectss bpy.context.object.modifiers"Armature".object = arm_fbx これは今作りかけのVRC向けロリレルちゃんVer1.2.0用の自動ウェイトスクリプト
code:WT_REL_LITTLE_v120.py
import bpy
bpy.context.view_layer.objects.active = None
for obj in bpy.data.objects:
obj.select_set(False)
bpy.context.view_layer.objects.active = hair
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
bpy.ops.object.vertex_group_add()
bpy.ops.object.vertex_group_remove(all=True)
bpy.ops.object.modifier_remove(modifier="Armature")
for obj in bpy.data.objects:
obj.select_set(False)
hair.select_set(True)
arm_hair.select_set(True)
bpy.context.view_layer.objects.active = arm_hair
# No mirror (not Symmetry)
bpy.ops.object.parent_set(type='ARMATURE_AUTO')
arm_body.select_set(False)
bpy.context.view_layer.objects.active = hair
bpy.ops.object.mode_set(mode='WEIGHT_PAINT', toggle=False)
bpy.ops.object.vertex_group_limit_total(group_select_mode='ALL',limit=4)
bpy.ops.object.vertex_group_normalize_all(lock_active=False)
bpy.ops.object.vertex_group_normalize_all()
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
hair.select_set(False)
arm_hair.select_set(False)
bpy.context.view_layer.objects.active = skin
bpy.ops.object.vertex_group_add()
bpy.ops.object.vertex_group_remove(all=True)
bpy.ops.object.modifier_remove(modifier="Armature")
for obj in bpy.data.objects:
obj.select_set(False)
skin.select_set(True)
arm_body.select_set(True)
bpy.context.view_layer.objects.active = arm_body
bpy.ops.object.parent_set(type='ARMATURE_AUTO', xmirror=True)
arm_body.select_set(False)
bpy.context.view_layer.objects.active = skin
bpy.ops.object.mode_set(mode='WEIGHT_PAINT', toggle=False)
bpy.ops.object.vertex_group_limit_total(group_select_mode='ALL',limit=4)
bpy.ops.object.vertex_group_normalize_all(lock_active=False)
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
skin.select_set(False)
arm_body.select_set(False)
for s in childs:
bpy.context.view_layer.objects.active = None
for obj in bpy.data.objects:
obj.select_set(False)
nowObj = bpy.data.objectss bpy.context.view_layer.objects.active = nowObj
bpy.ops.object.vertex_group_add()
bpy.ops.object.vertex_group_remove(all=True)
bpy.ops.object.modifier_remove(modifier="Armature")
nowObj.select_set(True)
arm_body.select_set(True)
bpy.context.view_layer.objects.active = arm_body
bpy.ops.object.parent_set(type='ARMATURE_AUTO', xmirror=True)
arm_body.select_set(False)
bpy.context.view_layer.objects.active = nowObj
nowObj.select_set(False)
arm_body.select_set(False)
for s , x in childs_transfer:
bpy.context.view_layer.objects.active = None
for obj in bpy.data.objects:
obj.select_set(False)
nowObj = bpy.data.objectss bpy.context.view_layer.objects.active = nowObj
bpy.ops.object.vertex_group_add()
bpy.ops.object.vertex_group_remove(all=True)
bpy.ops.object.modifier_remove(modifier="Armature")
nowObj.select_set(True)
arm_body.select_set(True)
bpy.context.view_layer.objects.active = arm_body
bpy.ops.object.parent_set(type='ARMATURE_AUTO', xmirror=True)
arm_body.select_set(False)
bpy.context.view_layer.objects.active = nowObj
nowObj.select_set(False)
arm_body.select_set(False)
for s , mix in childs_transfer:
bpy.context.view_layer.objects.active = bpy.data.objectss bpy.ops.object.modifier_add(type='DATA_TRANSFER')
bpy.context.object.modifiers"DataTransfer".data_types_verts = {'VGROUP_WEIGHTS'} bpy.ops.object.modifier_apply(modifier="DataTransfer")
bpy.data.objectss.select_set(False) bpy.ops.object.duplicate(
{"object": arm_body,
linked=False)
arm_fbx = bpy.context.selected_objects0 arm_tmp = bpy.context.selected_objects1 arm_tmp2 = bpy.context.selected_objects2 for obj in bpy.data.objects:
obj.select_set(False)
arm_fbx.select_set(True)
arm_tmp.select_set(True)
arm_tmp2.select_set(True)
bpy.context.view_layer.objects.active = arm_fbx
bpy.ops.object.join()
arm_fbx = bpy.context.view_layer.objects.active
arm_fbx.name = 'Armature.fbx'
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
arm_fbx.data.edit_bones.remove(arm_fbx.data.edit_bones.get('Head.001'))
head = arm_fbx.data.edit_bones.get('Head')
hair = arm_fbx.data.edit_bones.get('Hair')
hair.parent = head
hair.use_connect = True
chest = arm_fbx.data.edit_bones.get('Chest')
chest_002 = arm_fbx.data.edit_bones.get('Chest.002')
chest_002.parent = chest
chest_002_L = arm_fbx.data.edit_bones.get('Boob_L')
chest_002_R = arm_fbx.data.edit_bones.get('Boob_R')
mune_L = arm_fbx.data.edit_bones.get('mune_L')
mune_R = arm_fbx.data.edit_bones.get('mune_R')
mune_L.parent = chest_002_L
mune_R.parent = chest_002_R
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
bpy.context.view_layer.objects.active = None
for obj in bpy.data.objects:
obj.select_set(False)
#Set armature object(child) bpy.context.view_layer.objects.active = skin
bpy.context.object.modifiers"Armature".object = arm_fbx for s in no_paint_child:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
bpy.context.view_layer.objects.active = bpy.data.objectss bpy.ops.object.mode_set(mode='WEIGHT_PAINT', toggle=False)
bpy.context.object.modifiers"Armature".object = arm_fbx bpy.ops.object.vertex_group_clean(group_select_mode='ALL')
bpy.ops.object.vertex_group_limit_total(group_select_mode='ALL',limit=4)
bpy.ops.object.vertex_group_normalize_all(lock_active=False)
for s , x in childs_transfer:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
bpy.context.view_layer.objects.active = bpy.data.objectss bpy.ops.object.mode_set(mode='WEIGHT_PAINT', toggle=False)
bpy.context.object.modifiers"Armature".object = arm_fbx bpy.ops.object.vertex_group_clean(group_select_mode='ALL')
bpy.ops.object.vertex_group_limit_total(group_select_mode='ALL',limit=4)
bpy.ops.object.vertex_group_normalize_all(lock_active=False)
for s in childs:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
bpy.context.view_layer.objects.active = bpy.data.objectss bpy.ops.object.mode_set(mode='WEIGHT_PAINT', toggle=False)
bpy.context.object.modifiers"Armature".object = arm_fbx bpy.ops.object.vertex_group_clean(group_select_mode='ALL')
bpy.ops.object.vertex_group_limit_total(group_select_mode='ALL',limit=4)
bpy.ops.object.vertex_group_normalize_all(lock_active=False)
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)