I made an IK-FK and FK-IK snap script for UE4Tools. The UE4Tools rig is a single chain rig (instead of IK and FK separated) which led to a few problems, like being to unable to reset the FK rotation when switching to IK (if you reset the FK rotation you would get a snap because the IK constraint took in account the FK rotation). This means that the pole target will be a bit inaccurate when switching from FK to IK, but maybe not a huge issue. You could also reset the FK rotation on the next IK pose keyframe and have a nice blend between them. Ideally you would have a separate IK chain and FK chain though I think.
The main setup was to make new pole targets (grabbing the thigh/upperarm bones, copying in edit mode, then disabling location lock and drag them out on the local x axis). These were set to be the new pole targets, then they were copied again and set to have the thigh/upperarm bones as parents. These new bones will be used for snapping FK to IK.
The snapping itself is pretty easy:
IK-FK
1. Select the bones that should be keyed (depending on selected IK bone/s), for example left thigh, left calf and left poletarget if the left foot was selected.
2. Insert LocRot keyframes.
3. Set the value of the FK-IK switch to 1.000 and insert a keyframe. (bpy.context.selected_objects[0][IKDataPath] = 1.000 where IKDataPath is the data path for the FK-IK switch for the bone. Then bpy.context.selected_objects[0].keyframe_insert(data_path='["'+IKDataPath+'"]'))
4. Go to the next frame and select the thigh/calf bones again, insert a keyframe with visual locrot. This will give the FK rotations you need.
5. Set the FK-IK switch to 0.000 and insert a keyframe.
FK-IK
1. Set the FK-IK switch to 0.000 and insert a keyframe.
2. Select the thigh/calf bones and insert LocRot keyframes. Deselect bones.
3. Select the pole snap target (the pole target parented to thigh/upperarm), do Cursor to Selected. Deselect bones.
4. Select the real pole target and do Selected to Cursor. Insert a LocRot keyframe. Deselect bones.
5. Repeat the above method for the foot bone, set a 3D cursor there, then snap the feet IK control to it.
6. Go to the next frame, set the FK-IK switch to 1.000 and insert a keyframe.
(normally you would reset the transforms for the FK bones and insert a keyframe here, but in a single chain rig this will cause a snap because of the FK rotation influencing the IK bones).
You can use this for snapping the cursor:
Code:
def SnapCursor(type): for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
ctx = bpy.context.copy()
ctx['area'] = area
ctx['region'] = area.regions[-1]
if(type=="CursorToSelected"):
bpy.ops.view3d.snap_cursor_to_selected(ctx)
if(type=="SelectedToCursor"):
bpy.ops.view3d.snap_selected_to_cursor(ctx)
I don't really use this stuff myself though, I use IK for everything using the smoothed f-curve branch. But I may release it in the future as a fork of UE4Tools.
Bookmarks