Help applying shape key to posed mesh

Hi All,

I am working on a way to import characters from makehuman, already rigged, complete with shape keys to make realistic joint deformation. I have written some patches for makehuman that allow the poses to be controlled via a unix socket, and return vertex positions when asked. As regards the blender end, this is the process that the script will complete:

  1. Import the complete mesh in default pose from makehuman. – DONE - works.
  2. Import armature. – Doing manually for now.
    2a. Make armature parent of mesh using bone heat. – Doing manually for now. (I wll probably ask how to do this using python later :confused: )

for pose in poses:
3. Pose armature – Doing manually for now.
4. Apply same pose to makehuman character. – DONE - works.
5. Import vertex positions for pose. – DONE - works.
6. Create a shape key for the posed mesh. THIS IS THE PROBLEM!!!

I don’t know how to control a shape key for a posed mesh in python. I can easily apply the shape to the default un-posed mesh, but this does not help me. I have tried baking the (bad) shape of the pose, and comparing it to the (good) shape received from makehuman, and applying the differences in vertex positions to the default (unposed) mesh, but this doesn’t give the expected result.

I would like to specify the vertex positions for the mesh while it is in the required pose. This is simple to do manually, but how do I do it in python?

Um… OK… why no replies in 2 days?

Anyone out there know how to manipulate vertices on a mesh in a deformed state with python? Pleeease!:eyebrowlift: Any help at all is appreciated.

Thanks.

I guess nobody replies because that is too difficult. Maybe more difficult than solving crazy space, which was the unpredictable behavior of vertices when editing a deformed mesh in versions before 2.46.

Modeling shapes using the posed mesh as reference would be easier. With well thought drivers only a few shapes would be needed.

Thanks for the reply toloban, that answer is as good as any, at least I know what I’m in for, I’m only a noob at this, so I think I’m in way too deep if no-one else has tried it.

Thanks again.

Ok, after a hectic few days teaching myself vector and matrix math (I’m a highschool dropout so I haven’t even been taught the basics) and familiarizing myself with how python used the above, I have sorted the problem, and I’ll post the solution in the interests of helping anyone else thinking of doing somethin similar.

ARMATURE_POSEDMESH = the mesh as posed (badly) by the armature in blender
UNPOSEDMESH = the same mesh in it’s rest (unposed) state
MH_POSEDMESH = the mesh exported from makehuman that is posed correctly

  1. create a reference copy of ARMATURE_POSEDMESH
    this will become origin_mesh

  2. create a list of 3 meshes, fill each of these with a mesh that is a copy of ARMATURE_POSEDMESH after moving each vertex in UNPOSEDMESH 1 B.U. (I hope I have the right lingo here) in the [x, y, z] direction in turn.

  3. the 3 meshes created above will provide the coordinates for the [x,y,z] points of the transformation matrix for each vertex that the armature applied to them.

  4. for each vertice: a) create a matrix with the following values:

[
[ meshes[0].verts[vert_num].co[0],  meshes[1].verts[vert_num].co[0], meshes[2].verts[vert_num].co[0], 0.0],  
[ meshes[0].verts[vert_num].co[1],  meshes[1].verts[vert_num].co[1], meshes[2].verts[vert_num].co[1], 0.0],  
[ meshes[0].verts[vert_num].co[2],  meshes[1].verts[vert_num].co[2], meshes[1].verts[vert_num].co[2], 0.0],
[ originmesh.verts.co[0], originmesh.verts.co[1], originmesh.verts.co[2], 1.0]
]

b) invert the matrix you just created.

c) create a vector whose tail is at originmesh[vert_num] and whose head is at MH_POSEDMESH[vert_num]

d) miltiply the matrix by the vector

e) add the transformed vector to UNPOSEDMESH[vertnum]

AND IT’S THAT (NOT) EASY!!! ha ha — toloban was sooo right, it was really really really hard and time consuming to work out. But hopefully I’ll soon be able to auto-rig my makehuman characters.

Now for the next question:

How do I make an armature the parent of a mesh using bone heat, with python?

I have also imported this girl from Makehuman and manually created shape keys. POSES MESH?
Already some Armature Animation is There. POSED MESH mean some shape keys are already in action, and you wanto create noew shape keys. I think you should put the Armature in REST mode. Select Mesh, Put all the shape keys to 0 position. Select Basic, and add new shape keys.

Hi kkrawal, The idea of my program is to import a character from makehuman, into blender automatically rigged, including shape keys, so far I have a single joint successfully working.

I am manually doing the “create from bone heat” parenting operation, and I would now like to automate this step using python, any ideas?

Thanks.

Automatically rigging may work with python ( I am not that expert just now ) , what about shape keys, How will python know that which vertex has to pull upward for smile and which one to pull downwards for crying?
I think shape keys you have to do manually. I have not used makehuman for a long time? is there shape key already in the makehuman?. When I was using makehuman, I get only Mesh ( Obj)

I am using the shape keys to correct deformations in the joints caused by the armature posing the mesh, not for facial expressions (please see the first post).

Anyways, I got that working ( please see post #5 ).

I now need to know how to perform the armature parenting operation “Create from bone heat” using python, rather than having to stop the script and do it manually.

Does anyone know how to parent an armature and a mesh using the “bone heat” method with a python script?

In Blender 2.47, there is a new function to add weight groups in bone heat from a given armature… but without parenting, i wrote this for the modifiers

:D:D:D:D:D:D:D:D:D COOL! Thanks for the info, looks like the timing is perfect, I’ll have to upgrade to 2.47 so that I can use the new function. Thanks.

Any tips on using this new function? Or at least what it is called and the module it is in. I can teach myself to use it, but I find that experienced advice can save hours of work. Thanks again for the info.

… heu… somewhere in the Object module.