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.
-
$\begingroup$ Thanks to both of you. It seems you have the same acquaintances :). Blender 2.49, that's a scary thought. But I'll look into it and the script, if I can lay my hands on it, would probably help. $\endgroup$– KiskitNov 30, 2019 at 8:21
-
$\begingroup$ EDIT: Armature from Edge Loop blenderartists.org/t/armature-from-edge-loops/515611/12 last update 2012, but liero was always very kind to help, you can try to ask. Previously posted unfolding (armature from faces) raw.githubusercontent.com/addam/Export-Paper-Model-from-Blender/… (2.79) or extended blenderartists.org/t/unfold-transition/586992 (2.79 / 2.80) generates bones that expects rig these faces (not other mesh). $\endgroup$– vkliduNov 30, 2019 at 9:54
2 Answers
-
$\begingroup$ It's noteworthy, that the mesh is converted to an armature. It has to duplicated, otherwise the original will be gone. $\endgroup$– LeanderNov 30, 2019 at 11:34
If you have one connected edge loop, you can use this script.
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()
-
$\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$– vkliduNov 30, 2019 at 12:38
-
-
$\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$– KiskitDec 9, 2019 at 16:16
-
$\begingroup$ @Kiskit Cool, please update me if there is an (open-source) github or blender.se post. $\endgroup$– LeanderDec 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$– KiskitDec 9, 2019 at 16:23