Python script to place bones in the middle of a mesh?

As I’ve been experimenting with different rigging techniques, I was thinking it would be ideal if I had a script that would simply make a branching armature down the center points of any branch of a mesh.

Here’s what I was thinking: with this human figure mesh selected, the script would make an armature right where the red lines are:


Perhaps there could be a tolerance setting for defining how big of a branch or bump in a mesh should have a bone made for it.

Anyway, I’m not a coder, but I was wondering if this sounded easy enough that someone might want to make a script like this?

I imagine it would be a great way to get famous in the Blender community since it would make armature making SO much quicker and easier!

so a center line is supposed to be a line parallel to a mesh’s bounding box, more precisely the bounding box side with the largest extent?

if your torso, arms, body, legs etc are separate meshes, this is a fairly easy problem using the bounding boxes. However if the mesh is alll one complex object (a dyntopo sculpt for example) this would be quite challenging. You would need some kind of mesh analysis to give you the best oriented bounding box for sections of your arms and legs.

I was thinking more along the lines of how to analyze a figure that is one mesh and find a path down through the center of all the limbs so that bones could be placed accordingly in the center of all the limbs.

I suppose it would require analyzing the vertices/edges/faces of the mesh to find limbs, then find central middle points along those limbs, then put bones along those middle points.


This is Mr. Stretch from the Fantastic Four

Tall order without some user input.

In our newest (pending) version of the Contours Retopology addon, we find the path through the approximate center of limbs by going through the center of the cuts. We can then relax the cuts along that approximate path to attempt to get them more perpendicular to the limb. I could see this technique being used to attempt to place bones on limbs.

If you want to be any smarter than that…this is the next kind of thing you have to do
http://www.gvu.gatech.edu/people/official/jarek/papers/Plumber.pdf

@Patmo141: Yes, the Plumber algorithm looks exactly like what I was envisioning.

I’m sure all the Blender developers have already thought of this and just haven’t had time to implement it, but I was thinking it would be a huge improvement to the Blender’s armatures if there was an option to have a full skeleton automatically built for you in the selected 3D mesh, regardless of whether it was humanoid or not.

Don’t forget though, there is also the

mesh -> skin modifier -> sculpt workflow

The skin modifier will automatically make an armature

Thanks for the tip Patmo! I hadn’t thought of that. However, my computer is so slow that when I tried to use skin on a detailed figure, below, Blender just sat there for at least 10 minutes unresponsive, so I finally just had to force quit. :frowning:


Oh, ha ha. The skin modifier goes the other direction :slight_smile:

What do you mean Patmo? You mean I can’t use Skin to make an armature for an existing model? That is one of my main goals in my idea – to select an existing mesh model and create an armature perfectly fitting it.

The skin modifier creates an initial mesh from an armature, that’s what he wanted to say. If you add it a skin modifier to an existing mesh, it will hang and do something, but no idea what or if it can ever finish.

@patmo: Impressive algorithm you created there, I wonder what O(?) it is?

Oh, ok thanks Codeman!

O(50)?

Not fast by any means :slight_smile:

I was reading a comp sci lecture handout that I found about different techniques for min bounding box ranging from
A) Try a bunch of directions
B) Bunch of directions with some binary search
C) Try a bunch of directions but use fact that two edges lie tangent to box
D) Magical mystery techniques…

I stopped at option a. Close enough for govt work! I’ll proably try to get it faster or more accurate by adding a refining set of iterations.

N = number of verts
n = faction of solid sphere precision

It iterates over the hull once per iteration so a matrix multiply * N verts in hull
and the prescision is to the 2 * pi /n solid angle and it does n^3 iterations

So it’s pretty linear with verts and n^3 with precision

Option C involves checking combinations of edges and will go N^2 I think since you have to handshake all the edge pairs?

I need to modalize this code so we can watch the box spin around :-)!!

Edit: Used N to represent too many things

Hey guys, what if we made a tool that would snap bone heads/tails to loops on meshes? For example, here we have a selection around an arm and

  • with Snap To Selection, we could snap something to that center point, ideally a bone head/tail:


It would be quite a lot like the new Edge Rip tool – that tool

  • takes existing vertices on one mesh and snaps them to vertices on another mesh

So, similarly, for this new Armature Placing tool, the tool would

  • grab & drag bone heads/tails to loop selections on the mesh nearest the mouse cursor

The way it would work would be you’d grab a bone head/tail and drag it near a mesh and then, as it gets near a mesh, a loop around the mesh gets selected and the bone part is snapped to that point.

It would work quite a lot like a loop slide, except that it’s a sliding loop-selection and the bone part is snapped to the center of the loop.

Upon release of the bone part, it’d be positioned there in the middle of the limb.

The mesh loop selection part of the tool might be like a cross between a Loop Select tool and a Loop Slide tool.

The bone part dragging part of the tool would be like Edge Rip’s vertex placing action.

What do you think?

What about this: a Snap Metarig to Figure tool. Basically, all figures that are humanoid & rigging ready are all in one of the rigging-ready poses, so maybe there could be some way to snap an entire metarig into a humanoid mesh by dragging & dropping the rig onto the mesh.
What do you think?

Apparently Martin Pourier (Theeth) has been making something like this called Skeletor.

Another possible method is to mark limbs on your target figure mesh. For example, you could have a palette of colors and each color representing one bone like so:


etc…

and then you could paint your mesh areas to mark which bones go where:


Then you could snap the bones into the mesh.

@Patmo141 @CodemanX Do you know if MakeHuman will autorig a figure? If so, it’s code is open source so maybe it could be used to make an autorigging addon for Blender.