Ejemplo n.º 1
0
        /// <summary>
        /// Transform the decoder array to a mapping of index to type ID.
        /// </summary>
        private static AnimDecoderType[] MakeDecoderArray(IKeyValueCollection[] decoderArray)
        {
            var array = new AnimDecoderType[decoderArray.Length];

            for (var i = 0; i < decoderArray.Length; i++)
            {
                var decoder = decoderArray[i];
                array[i] = AnimDecoder.FromString(decoder.GetProperty <string>("m_szName"));
            }

            return(array);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Transform the decoder array to a mapping of index to type ID
        /// </summary>
        /// <param name="decoderArray"></param>
        /// <returns></returns>
        private AnimDecoderType[] MakeDecoderArray(NTROArray decoderArray)
        {
            var array = new AnimDecoderType[decoderArray.Count];

            for (var i = 0; i < decoderArray.Count; i++)
            {
                var decoder = decoderArray.Get <NTROStruct>(i);
                array[i] = AnimDecoder.FromString(decoder.Get <string>("m_szName"));
            }

            return(array);
        }
Ejemplo n.º 3
0
        public static int Size(this AnimDecoderType t)
        {
            switch (t)
            {
            case AnimDecoderType.CCompressedFullVector3:
            case AnimDecoderType.CCompressedAnimVector3:
                return(12);

            case AnimDecoderType.CCompressedStaticVector:
            case AnimDecoderType.CCompressedAnimQuaternion:
                return(6);
            }

            return(0);
        }
Ejemplo n.º 4
0
        // Construct an animation class from the animation description
        private void ConstructFromDesc(NTROStruct animDesc, NTROStruct decodeKey, AnimDecoderType[] decoderArray, NTROArray segmentArray)
        {
            // Get animation properties
            Name = animDesc.Get<string>("m_name");
            Fps = animDesc.Get<float>("fps");

            // Only consider first frame block for now
            var pData = animDesc.Get<NTROArray>("m_pData").Get<NTROStruct>(0);
            var frameBlockArray = pData.Get<NTROArray>("m_frameblockArray").ToArray<NTROStruct>();

            FrameCount = pData.Get<int>("m_nFrames");
            Frames = new Frame[FrameCount];

            // Figure out each frame
            for (var frame = 0; frame < FrameCount; frame++)
            {
                // Create new frame object
                Frames[frame] = new Frame();

                // Read all frame blocks
                foreach (var frameBlock in frameBlockArray)
                {
                    var startFrame = frameBlock.Get<int>("m_nStartFrame");
                    var endFrame = frameBlock.Get<int>("m_nEndFrame");

                    // Only consider blocks that actual contain info for this frame
                    if (frame >= startFrame && frame <= endFrame)
                    {
                        var segmentIndexArray = frameBlock.Get<NTROArray>("m_segmentIndexArray").ToArray<int>();

                        foreach (var segmentIndex in segmentIndexArray)
                        {
                            var segment = segmentArray.Get<NTROStruct>(segmentIndex);
                            ReadSegment(frame - startFrame, segment, decodeKey, decoderArray, ref Frames[frame]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void ReadSegment(int frame, NTROStruct segment, NTROStruct decodeKey, AnimDecoderType[] decoderArray, ref Frame outFrame)
        {
            //Clamp the frame number to be between 0 and the maximum frame
            frame = frame < 0 ? 0 : frame;
            frame = frame >= FrameCount ? FrameCount - 1 : frame;

            var localChannel = segment.Get<int>("m_nLocalChannel");
            var dataChannel = decodeKey.Get<NTROArray>("m_dataChannelArray").Get<NTROStruct>(localChannel);
            var boneNames = dataChannel.Get<NTROArray>("m_szElementNameArray").ToArray<string>();

            var channelAttribute = dataChannel.Get<string>("m_szVariableName");

            // Read container
            var container = segment.Get<NTROArray>("m_container").ToArray<byte>();
            using (var containerReader = new BinaryReader(new MemoryStream(container)))
            {
                var elementIndexArray = dataChannel.Get<NTROArray>("m_nElementIndexArray").ToArray<int>();
                var elementBones = new int[decodeKey.Get<int>("m_nChannelElements")];
                for (var i = 0; i < elementIndexArray.Length; i++)
                {
                    elementBones[elementIndexArray[i]] = i;
                }

                // Read header
                var decoder = decoderArray[containerReader.ReadInt16()];
                var cardinality = containerReader.ReadInt16();
                var numBones = containerReader.ReadInt16();
                var totalLength = containerReader.ReadInt16();

                // Read bone list
                var elements = new List<int>();
                for (var i = 0; i < numBones; i++)
                {
                    elements.Add(containerReader.ReadInt16());
                }

                // Skip data to find the data for the current frame.
                // Structure is just | Bone 0 - Frame 0 | Bone 1 - Frame 0 | Bone 0 - Frame 1 | Bone 1 - Frame 1|
                containerReader.BaseStream.Position += decoder.Size() * frame * numBones;

                // Read animation data for all bones
                for (var element = 0; element < numBones; element++)
                {
                    //Get the bone we are reading for
                    var bone = elementBones[elements[element]];

                    // Look at the decoder to see what to read
                    switch (decoder)
                    {
                        case AnimDecoderType.CCompressedStaticFullVector3:
                        case AnimDecoderType.CCompressedFullVector3:
                        case AnimDecoderType.CCompressedDeltaVector3:
                            outFrame.SetAttribute(boneNames[bone], channelAttribute, new Vector3(
                                containerReader.ReadSingle(),
                                containerReader.ReadSingle(),
                                containerReader.ReadSingle()));
                            break;
                        case AnimDecoderType.CCompressedStaticVector:
                            outFrame.SetAttribute(boneNames[bone], channelAttribute, new Vector3(
                                ReadHalfFloat(containerReader),
                                ReadHalfFloat(containerReader),
                                ReadHalfFloat(containerReader)));
                            break;
                        case AnimDecoderType.CCompressedAnimQuaternion:
                            outFrame.SetAttribute(boneNames[bone], channelAttribute, ReadQuaternion(containerReader));
                            break;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        // Transform the decoder array to a mapping of index to type ID
        private AnimDecoderType[] MakeDecoderArray(NTROArray decoderArray)
        {
            var array = new AnimDecoderType[decoderArray.Count];
            for (var i = 0; i < decoderArray.Count; i++)
            {
                var decoder = decoderArray.Get<NTROStruct>(i);
                array[i] = AnimDecoder.FromString(decoder.Get<string>("m_szName"));
            }

            return array;
        }