Message 1 of 1
Adding Skin Weights Using C#

Not applicable
08-03-2016
08:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I'm trying to use the Autodesk.Max dll to write a plugin for 3ds Max using C# and have successfully pulled skin modifier weight data from my scene into a windows form application but am having trouble with writing weight data back to the skin modifier.
Specifically, I'm trying to use the IISkinImportData.AddWeights function but can't get it to return successful (The MessageBox always shows "Operation Failed"). This is what I have tried so far:
IInterface16 coreInterface = GlobalInterface.Instance.COREInterface16; IINode selectedNode = coreInterface.GetSelNode(0); IObject selObj = selectedNode.ObjectRef; IIDerivedObject derObj = (IIDerivedObject)selObj; IModifier skinMod = derObj.Modifiers[1]; IISkin iSkin = (IISkin)skinMod.GetInterface((InterfaceID)(0x00010000)); IISkinImportData iiSkinImportData = (IISkinImportData)skinMod.GetInterface((InterfaceID)0x00020000); ITab<IINode> nodes = GlobalInterface.Instance.Tab.Create<IINode>(); int ret1 = nodes.Append(1, iSkin.GetBone(1).NativePointer, 0); ITab<float> weights = GlobalInterface.Instance.Tab.Create<float>(); GCHandle floatHandle = GCHandle.Alloc(new float[] { 1f }, GCHandleType.Pinned); try { IntPtr pointer = floatHandle.AddrOfPinnedObject(); int ret2 = weights.Append(1, pointer, 0); if (iiSkinImportData.AddWeights(selectedNode, 0, nodes, weights)) MessageBox.Show("Operation Succeeded"); else MessageBox.Show("Operation Failed"); } finally { if (floatHandle.IsAllocated) { floatHandle.Free(); } }