I’m trying to create a script to generate a shape key that makes a mesh with an armature modifier look a certain way after the effects of the armature pose are accounted for. Thus, the script has to set the base coordinates of the mesh such that the deform applied by the armature converts them into the desired way.
I know I can start with
import bpy
obj = bpy.context.active_object
arm_mod = obj.modifiers[0]
vertices = obj.data.shape_keys.key_blocks[1].data
target_obj = bpy.context.selected_objects[1] # assume this is the desired target
target_vertices = target_obj.data.vertices
but I’m unsure how to proceed from there, and haven’t even managed to determine how a script can access the displacement values for a given vertex. The end goal is to take the desired final coordinate (obtained from the target_obj mesh, which has the same number of vertices in the same order), and somehow invert the armature modifier transform to obtain the base coordinate that transforms to the coordinate in target_vertices[i].co, then set vertices[i].co to that value.
Any ideas?