Adjusting agentrig_footoffsets position in World Space

   778   2   1
User Avatar
Member
4 posts
Joined: Nov. 2024
Offline
I am trying to adjust my agentrig_footoffsets positions (created by the agent prep node) in world position, so that if I move it up for example {0, .2, 0}, will move .2 up in Y. I need to do this because I need to adjust the agentrig_footoffsets regardless of the orientation of the joint it is attached to.

It have some code in vex to do this, however it doesn't quite seem to do the conversions correctly when I am am trying to adjust agentrig_footoffsets in World Space.

I also attached a file.

int verbose = chi("verbose_debug");
// Get foot offsets (Local Space)
vector footoffsets[] = point(0, "agentrig_footoffsets", @ptnum);
// Joint names (e.g., LeftFoot, LeftToe_End, etc.)
string joints[] = s[]@agentrig_lowerlimbs;
string joint_names[] = array(joints[2], joints[3], joints[6], joints[7]);
// Additional Offsets (World Space)
vector additional_offsets[] = array(
    chv("add_left_ankle"),
    chv("add_left_toe"),
    chv("add_right_ankle"),
    chv("add_right_toe")
);
// Joint indices
int joint_indices[] = array();
foreach (string name; joint_names)
    append(joint_indices, agentrigfind(0, @primnum, name));
// Get local transforms for all joints
matrix local_xforms[] = agentlocaltransforms(0, @primnum);
// Convert to world transforms
matrix world_xforms[] = local_xforms;
agenttransformtoworld(0, @primnum, world_xforms);
// For each joint of interest
for (int i = 0; i < len(joint_indices); i++)
{
    int joint_idx = joint_indices[i];
    if (joint_idx < 0 || joint_idx >= len(world_xforms)) continue;
    string joint_name = joint_names[i];
    matrix local_xform = local_xforms[joint_idx];
    matrix world_xform = world_xforms[joint_idx];
    // Transform foot offset to world space
    vector foot_offset_local = footoffsets[i];
    vector foot_offset_world = foot_offset_local * world_xform;
    // Add the world-space offset
    vector foot_offset_world_new = foot_offset_world + additional_offsets[i];
    // Convert the updated offset back to joint-local space
    vector foot_offset_local_new = foot_offset_world_new * invert(world_xform);
    // Store result
    footoffsets[i] = foot_offset_local_new;
    if (verbose)
    {
        printf("\n=== [%s] Joint idx %d ===\n", joint_name, joint_idx);
        printf("Original Foot Offset (Local Space):             %g\n", foot_offset_local);
        printf("Original Foot Offset (World Space):             %g\n", foot_offset_world);
        printf("Additional Offset (World Space):                %g\n", additional_offsets[i]);
        printf("New Foot Offset (World Space):                  %g\n", foot_offset_world_new);
        printf("New Foot Offset (Local Space):                  %g\n", foot_offset_local_new);
        printf("[%s] World Transform:\n", joint_name);
        for (int r = 0; r < 4; r++) {
            vector row = set(
                getcomp(world_xform, r, 0),
                getcomp(world_xform, r, 1),
                getcomp(world_xform, r, 2)
            );
            printf("Row %d: %g %g %g\n", r, row.x, row.y, row.z);
        }
        printf("[%s] Local Transform:\n", joint_name);
        for (int r = 0; r < 4; r++) {
            vector row = set(
                getcomp(local_xform, r, 0),
                getcomp(local_xform, r, 1),
                getcomp(local_xform, r, 2)
            );
            printf("Row %d: %g %g %g\n", r, row.x, row.y, row.z);
        }
    }
}
// Save updated offsets back
setpointattrib(0, "agentrig_footoffsets", @ptnum, footoffsets, "set");
Edited by tbritton_aurora - May 28, 2025 21:16:16

Attachments:
Screenshot from 2025-05-28 17-31-53.png (1.3 MB)
Screenshot from 2025-05-28 17-32-28.png (1.3 MB)
foot_offset_help.hip (422.7 KB)

User Avatar
Staff
795 posts
Joined: Oct. 2012
Offline
I think your setup looks right to me, but perhaps having such a large offset for only the ankle joint isn't working well when it tries to rotate the toe joint onto the terrain

If you turn off foot locking and terrain adaptation you can see the offset is being applied correctly. Things are backwards to what you might expect at first, though - if the offset is increased in y, then the leg will need to stretch farther down to ensure that the joint + offset is on the terrain
User Avatar
Member
4 posts
Joined: Nov. 2024
Offline
Thank you. You were right about the large ankle offset was affecting the toe's agentrig_footoffsets. Also I forgot the guides are show after the terrain adaption, not the pre-adapted positions I modified it to.

It looks correct in the demo scene once I set all of them to have a similar offset, I will report back if I have any other issues.
  • Quick Links