Notifications
Clear all

[Closed] Calling C++ function inside C#

 MZ1

Please let me know if you still need older version, I can re-build again

 MZ1

This is the right method to get the biped interface to call SetBipedTM:

public IIBipMaster12 GetIBipMasterInterface12(IINode node)
{
    var ptr = ((INativeObject)node.TMController.GetInterface((InterfaceID)0x9167)).NativePointer;
    return (IIBipMaster12)Autodesk.Max.Wrappers.CustomMarshalerIBipMaster12.GetInstance(string.Empty).MarshalNativeToManaged(ptr);
}

and we can check to see if the object is biped:

public static bool IsBipedNode(IINode node)
{
    IControl c = node.TMController;
    if (c == null) return false;
    if (c.ClassID.PartA == 0x9154) return true;
    if (c.ClassID.PartA == 0x9156) return true;
    if (c.ClassID.PartA == 0x3011) return true;
    return false;
}

Then we can set transform like this:

private void Part_Slider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
    if (canChange == true)
    {
        int time = coreInterface.Time;
        float val = Convert.ToSingle(e.NewValue / 100d);
        globalInterface.DisableRefMsgs();
        for (int i = 0; i < sourceNodes.Count; i++)
        {
            IMatrix3 blendTM = BlendMatrix(sourceTMs[i], targetTMs[i], val);
            if (IsBipedNode(sourceNodes[i]))
            {
                IIBipMaster12 iBipMaster12 = GetIBipMasterInterface12(sourceNodes[i]);
                int id = 0;
                int link = 0;
                iBipMaster12.GetIdLink(sourceNodes[i], ref id, ref link);
                iBipMaster12.StartSettingBipedKeys();
                iBipMaster12.SetBipedTM(time, blendTM, id, link);
                iBipMaster12.StopSettingBipedKeys();
            }
            else
            {
                sourceNodes[i].SetNodeTM(time, BlendMatrix(sourceTMs[i], targetTMs[i], val));
            }
        }
        globalInterface.EnableRefMsgs();
        for (int i = 0; i < sourceNodes.Count; i++)
        {
            sourceNodes[i].InvalidateTM();
        }
        coreInterface.RedrawViews(time, RedrawFlags.Normal, null);
    }
}
 MZ1

Now the code works in this case as well.

 MZ1

Because we start from the root node in the scene, it works on the hierarchy. (if we use the SetBipedTM for biped parts).

 MZ1

This is the update so far: TestProject(2020).rar (6.2 MB)

 MZ1

This is another example that tool doesn’t work: TestMaxFile(2016).max (1.0 MB)

 MZ1

oops, it was my mistake, StartSettingBipedKeys and StopSettingBipedKeys should be outside the loop. Now it’s work on the latest scene as well.

Page 3 / 3