UuuNyaa / blender_mmd_tools

MMD Tools is a blender addon for importing/exporting Models and Motions of MikuMikuDance.
GNU General Public License v3.0
2.27k stars 109 forks source link

Add 'move bone to bone order number' feature instead of pressing the arrow a million times #88

Open wikid24 opened 1 year ago

wikid24 commented 1 year ago

Hi there, would it be possible to improve the panel that shows the bone order, to type in a number for bone order instead of having to press the up/down arrow a million times? For example, sometimes I would want to move an entire hierarchy of bones up or down, instead of just one bone at a time... That is a lot of arrow buttons to click.

image

This adds a small ui change does it for the vertex groups , but it only does one vertex group at a time, it would be good to have something to move entire hierarchies of bones all at once: image

https://blender.stackexchange.com/questions/137444/how-can-i-move-reorder-a-vertex-group-more-than-one-spot-at-a-time

I started writing something as a proof of concept that will move a vertex group to the desired spot for an example:

#MOVE VERTEX GROUP / BONE ORDER TO A SPECIFIC POSITION
def vgmove(delta):
    direction = 'UP' if delta > 0 else 'DOWN'
    for i in range(abs(delta)):
        bpy.ops.object.vertex_group_move(direction=direction)

def move_vg_to_pos(mesh, vg_name, target_pos):

    bpy.ops.object.mode_set(mode='OBJECT')
    bpy.context.view_layer.objects.active = mesh

    #search for vg_name in mesh
    for vg in mesh.vertex_groups:
        if vg.name == vg_name:
            #set the active index to the matching criteria
            mesh.vertex_groups.active_index = vg.index
            #get delta from the current index position to the target position
            delta = vg.index - min(target_pos, len(mesh.vertex_groups) - 1)
            #call vgmove to set the vg to that specific position
            vgmove(delta)        

mesh = bpy.data.objects['c1801b0002_top Part 9.0']  #mesh that contains the bone order
vg_name = 'waist' #name of the vertex group I would like to move
target_pos = 10 #the bone order position I would like it to have

move_vg_to_pos(mesh,vg_name,target_pos)    

thanks again! :)

wikid24 commented 1 year ago

Sorry, while we are talking about this section, it would also be good to show the blender bone group OR display panel group (because not all bones names are easy to remember what they are or where they are on the body)

image

wikid24 commented 1 year ago

I am so sorry for all the suggestions, this is the last thing I promise :)

I think this is a defect, but clicking on a bone icon should set it as the active bone:

image