3

I have an bone name (e.g. Bone002) and I want to get the bone ID for it (not the index in skin list, but the ID that is required e.g. in skinOps.SetVertexWeights).

I know that reverse operation looks like this:

skinMod = $.modifiers[#skin]
boneListIndex = (skinOps.GetVertexWeightBoneID skinMod v w)
local boneName = skinOps.GetBoneNameByListID skinMod boneListIndex 0

But how to get boneID? I already have boneListIndex and boneName.

I assume that all bones have unique names.

PolGraphic
  • 3,233
  • 11
  • 51
  • 108

2 Answers2

3

What version of 3dsMax are you using? I remember the documentation being rather confusing here. Bone_ID and vertex_bone_integer are interchangeable in this case - I just tested on a simple mesh and SkinOps.GetVertexWeightBoneID and SkinOps.SetVertexWeights work with the same bone indices.

If you want to locate by name, then you need to match the indices by name. Create an array with your bone names:

boneNames = for i=1 to (skinOps.GetNumberBones skinMod) collect (skinOps.GetBoneName skinMod i 0)

Then you can use your favorite search method and retrieve the index, a simple findItem works well here:

boneIndex = findItem boneNames "Bone002"

Keep in mind that the skinOps.GetBoneName function is slightly borked; the last parameter is meant to determine whether to return the actual node or its name - regardless the setting, only the name string is ever returned. This means that if you have two bones in the skin with the same name, you'll have to find a clever way on how to get the appropriate node.

Klaudikus
  • 382
  • 3
  • 12
0

If what you want is the boneID corresponding to the bone owning the skin weights, then you need one more step, because skinOps.GetBoneName returns the parent of the bone owning the weights:

fn GenerateBoneList sk =
(
    boneNames  = #()
    for i=1 to (skinOps.GetNumberBones skinMod) do 
    (
        local aName = skinOps.GetBoneName skinMod i 0
        local inSkinUI = (execute ("$" + aName)).children[1].name
        append boneNames inSkinUI
    )   
    return boneNames
)

Now, when you use finditem, you can use the name of the bone that owns the skin weights

    finditem boneNames $Bone002.name