Last active
July 13, 2026 17:13
-
-
Save keerah/393d0ef509e411844139841f24a828d2 to your computer and use it in GitHub Desktop.
Transfer capture weights from one bone to another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // VEX point attribute snippet to transfer capture weights from one bone to another. | |
| // Use Capture Attribute Unpack SOP before | |
| // and Capture Attribute Pack SOP after this snippet | |
| // | |
| // To make capture data accessible to VEX | |
| // Capture Attribute Unpack SOP firstly unpacks capture attributes | |
| // into a few array attributes: | |
| //- Array of all bone names in the detail = s[]@boneCapture_pCaptPath | |
| //- Array of bone indices (from the previous detail attribute) for each point = i[]@boneCapture_index | |
| //- Array of the corresponding weights for each point = f[]@boneCapture_data | |
| // | |
| // So this wrangle looks up for the names of the source & destination bones | |
| // finds their indices in the point's bone index array and changes the corresponding weigths. | |
| string rNames[] = detail(0, 'boneCapture_pCaptPath', 0); // get the list of regions | |
| string rSourceName = chs('source_region'); | |
| string rDestName = chs('destination_region'); | |
| int rSourceIndex = find(rNames, rSourceName); // find the source region index in the detail attribute | |
| if (rSourceIndex < 0) error('Source region "%s" is not present in the capture data', rSourceName); | |
| int rDestIndex = find(rNames, rDestName); // find the destination region index in the detail attribute | |
| if (rDestIndex < 0) error('Destination region "%s" is not present in the capture data', rDestName); | |
| int captIndex[] = i[]@boneCapture_index; | |
| int rSourceCaptIndex = find(captIndex, rSourceIndex); // find if the source region is present for this point | |
| if (rSourceCaptIndex >= 0) { | |
| float captData[] = f[]@boneCapture_data; | |
| int rDestCaptIndex = find(captIndex, rDestIndex); // find if the destination region is present for this point | |
| if (rDestCaptIndex >= 0) { | |
| // set the destination reqion weight to the sum of both | |
| captData[rDestCaptIndex] = clamp(captData[rDestCaptIndex] + captData[rSourceCaptIndex], 0, 1); | |
| } else { | |
| // if the destination region was not found, add it | |
| push(captIndex, rDestIndex); | |
| push(captData, captData[rSourceCaptIndex]); | |
| }; | |
| // remove the source region completely | |
| pop(captIndex, rSourceCaptIndex); | |
| pop(captData, rSourceCaptIndex); | |
| // save back the attributes | |
| f[]@boneCapture_data = captData; | |
| f[]@boneCapture_index = captIndex; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment