forked from SilentNightSound/GI-Model-Importer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbone_deletion_script.txt
More file actions
46 lines (36 loc) · 1.54 KB
/
Copy pathbone_deletion_script.txt
File metadata and controls
46 lines (36 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'''
Adapted from https://blender.stackexchange.com/a/226914/132453
Script written by: https://github.com/ssbucarlos
Use this Blender script to simplify bone structure for complicated models
Required in order to import complicated models like MMD into Genshin
'''
import bpy
def transfer_weights(source, target, obj):
source_group = obj.vertex_groups.get(source.name)
if source_group is None:
return
source_i = source_group.index
target_group = obj.vertex_groups.get(target.name)
if target_group is None:
target_group = obj.vertex_groups.new(name=target.name)
for v in obj.data.vertices:
for g in v.groups:
if g.group == source_i:
target_group.add((v.index,), g.weight, 'ADD')
obj.vertex_groups.remove(source_group)
def remove_bone(source, target):
for o in bpy.data.objects:
transfer_weights(source, target, o)
edit_bone = bpy.context.object.data.edit_bones.get(source.name)
bpy.context.object.data.edit_bones.remove(edit_bone)
def find_parent_not_in_collection(bone, collection):
if bone.parent in collection:
return find_parent_not_in_collection(bone.parent, collection)
else:
return bone.parent
def main():
selected_bones = [bone for bone in bpy.context.object.data.edit_bones if bone.select is True]
for selected_bone in selected_bones:
target = find_parent_not_in_collection(selected_bone, selected_bones)
remove_bone(selected_bone, target)
main()