ValveResourceFormat/Resource/ResourceTypes/Animation/Skeleton.cs
/// <summary>
/// Construct the Armature object from mesh skeleton KV data.
/// </summary>
Construct the Armature object from mesh skeleton KV data.
Construct the Armature object from mesh skeleton KV data .
public void ConstructFromNTRO(IKeyValueCollection skeletonData, Dictionary<long, int> remapTable)
        {
            var boneNames = skeletonData.GetArray<string>("m_boneName");
            var boneParents = skeletonData.GetIntegerArray("m_nParent");
            var bonePositions = skeletonData.GetArray("m_bonePosParent", v => v.ToVector3());
            var boneRotations = skeletonData.GetArray("m_boneRotParent", v => v.ToQuaternion());
            Bones = new Bone[boneNames.Length];
            for (var i = 0; i < boneNames.Length; i++)
            {
                var name = boneNames[i];
                var position = bonePositions[i];
                var rotation = boneRotations[i];
                var index = remapTable.ContainsKey(i) ? remapTable[i] : -1;
                var bone = new Bone(name, index, position, rotation);
                if (boneParents[i] != -1)
                {
                    bone.SetParent(Bones[boneParents[i]]);
                    Bones[boneParents[i]].AddChild(bone);
                }
                Bones[i] = bone;
            }
            FindRoots();
            LastBone = Bones.Length > 0 ? Bones.Max(b => b.Index) : -1;
        }
public void ConstructFromNTRO ( IKeyValueCollection skeletonData , Dictionary < long , int > remapTable ) { var boneNames = skeletonData . GetArray < string > ( " " ) ; var boneParents = skeletonData . GetIntegerArray ( " " ) ; var bonePositions = skeletonData . GetArray ( " " , v => v . ToVector3 ( ) ) ; var boneRotations = skeletonData . GetArray ( " " , v => v . ToQuaternion ( ) ) ; Bones = new Bone [ boneNames . Length ] ; for ( var i = 0 ; i < boneNames . Length ; i ++ ) { var name = boneNames [ i ] ; var position = bonePositions [ i ] ; var rotation = boneRotations [ i ] ; var index = remapTable . ContainsKey ( i ) ? remapTable [ i ] : - 1 ; var bone = new Bone ( name , index , position , rotation ) ; if ( boneParents [ i ] != - 1 ) { bone . SetParent ( Bones [ boneParents [ i ] ] ) ; Bones [ boneParents [ i ] ] . AddChild ( bone ) ; } Bones [ i ] = bone ; } FindRoots ( ) ; LastBone = Bones . Length > 0 ? Bones . Max ( b => b . Index ) : - 1 ; }
Construct the Armature object from mesh skeleton KV data.
Construct the Armature object from mesh skeleton KV data .
// Initialise bone array //Add all bones to the list // Create bone // Figure out the index of the last bone so we dont have to do that every draw call
skeletonData
IKeyValueCollection
remapTable
Dictionary<long, int>