1
$\begingroup$

Is it possible to generate a rig based on a mesh? I'm thinking something simple like having one bone per edge. I'm going to look into scripting it I guess but if someone did something similar already it may save me the trouble.

$\endgroup$
2

2 Answers 2

2
$\begingroup$
  • Add Skin Modifier to your Mesh (edge structure)
  • Press "Create Armature"

enter image description here

$\endgroup$
1
  • $\begingroup$ It's noteworthy, that the mesh is converted to an armature. It has to duplicated, otherwise the original will be gone. $\endgroup$
    – Leander
    Nov 30, 2019 at 11:34
3
$\begingroup$

If you have one connected edge loop, you can use this script.

result

The mesh object has to be selected before executing the script.

import bpy

def CreateBoneChainFromVertices():
    obj = bpy.context.active_object
    if (None == obj):
        return

    if (obj.type != 'MESH'):
        return
    bpy.ops.object.mode_set(mode='OBJECT')

    edgesA = []
    edgesB = []
    for i in range(len(obj.data.edges)):
        ver = obj.data.edges[i].vertices
        edgesA.append(ver[0])
        edgesB.append(ver[1])

    chain = []
    chain.append(edgesA[0])
    while(True):
        current = chain[len(chain)-1]
        if current in edgesA:
            idx = edgesA.index(current)
            next = edgesB[idx]
            del edgesA[idx]
            del edgesB[idx]
            chain.append(next)
        elif current in edgesB:
            idx = edgesB.index(current)
            next = edgesA[idx]
            del edgesA[idx]
            del edgesB[idx] 
            chain.append(next)
        else:
            if (chain[0] in edgesA) or (chain[0] in edgesB):
                chain = list(reversed(chain))
            else:
                break

    amt = bpy.data.armatures.new(obj.name + "_vBones")
    rig = bpy.data.objects.new(obj.name + '_vRig', amt)
    bpy.context.collection.objects.link(rig)
    bpy.context.view_layer.objects.active = rig
    bpy.context.view_layer.update()

    print(chain, "here we go")
    bpy.ops.object.editmode_toggle()
    for i in range(0, len(chain) - 1):
        bone = amt.edit_bones.new(str(i + 1))
        bone.head = obj.data.vertices[chain[i]].co
        bone.tail = obj.data.vertices[chain[i + 1]].co
    for i in range(0, len(amt.edit_bones) - 1):
        amt.edit_bones[i + 1].parent = amt.edit_bones[i]
        amt.edit_bones[i + 1].use_connect = True
    bpy.ops.object.editmode_toggle()

CreateBoneChainFromVertices()
$\endgroup$
6
  • $\begingroup$ Thank you so much for such a quick response and fix for 2.8. I just noticed the Skin modifier option, that also works for fork (like hand with fingers). Sorry. $\endgroup$
    – vklidu
    Nov 30, 2019 at 12:38
  • $\begingroup$ Thanks @Leander, I'll study this $\endgroup$
    – Kiskit
    Nov 30, 2019 at 16:18
  • $\begingroup$ @Leander thanks a million for your example. It prompted me to actually write something to do the job automatically. There may be a gravity rig add-on before long. $\endgroup$
    – Kiskit
    Dec 9, 2019 at 16:16
  • $\begingroup$ @Kiskit Cool, please update me if there is an (open-source) github or blender.se post. $\endgroup$
    – Leander
    Dec 9, 2019 at 16:18
  • 1
    $\begingroup$ I'm not sure yet how I'm going to release it, but given how you took time to help me with code, I won't ask you for money if you want it ;). Also you're in the thanks on the youtube video's description. Look for "Gravity Rig Blender add-on introduction". $\endgroup$
    – Kiskit
    Dec 9, 2019 at 16:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .