How to get morph target weights in c# ?
Not applicable
10-02-2017
07:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
How to retreive the weight of each morph target listed inside the 'morpher' modifier when no animation is defined?
Currently i'm only able to get the animation values of such attribute.
A screenshot of what i want:
Here is the code i have using 3ds Max 2017:
IIGameNode meshNode = ... // initialized previously
// Retreive modifiers with morpher flag List<IIGameModifier> modifiers = new List<IIGameModifier>(); for (int i = 0; i < meshNode.IGameObject.NumModifiers; i++) { IIGameModifier modifier = meshNode.IGameObject.GetIGameModifier(i); if (modifier.ModifierType == Autodesk.Max.IGameModifier.ModType.Morpher) { modifiers.Add(modifier); } } // Cast modifiers to morphers List<IIGameMorpher> morphers = new List<IIGameMorpher>(); modifiers.ForEach(modifier => { Assembly wrappersAssembly = Assembly.Load("Autodesk.Max.Wrappers, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"); Type type = wrappersAssembly.GetType("Autodesk.Max.Wrappers.IGameMorpher"); ConstructorInfo constructor = type.GetConstructors()[0]; unsafe { void* voidPtr = modifier.GetNativeHandle().ToPointer(); IIGameMorpher morpher = (IIGameMorpher)constructor.Invoke(new object[] { modifier.GetNativeHandle(), false }); morphers.Add(morpher); } }); // Retreive morph target weights morphers.ForEach(morpher => { for (int i = 0; i < morpher.NumberOfMorphTargets; i++) { IIGameControl morphWeight = morpher.GetMorphWeight(i); // Retreive weight animation values ITab<IIGameKey> gameKeyTab = GlobalInterface.Instance.Tab.Create<IIGameKey>(); morphWeight.GetQuickSampledKeys(gameKeyTab, IGameControlType.Float); for (int indexKey = 0; indexKey < gameKeyTab.Count; indexKey++) { IIGameKey gameKey = gameKeyTab[indexKey]; // Animation value int time = gameKey.T; float weight = gameKey.SampleKey.Fval / 100.0f; } // TODO - HOW TO GET MORPH TARGET WEIGHT? } });
I was expecting IIGameMorpher.GetMorphWeight to return a float and have another method like IIGameMorpher.GetMorphWeightControl to get the animation control...
Noalak
Link copied