Exemple #1
0
        protected void ParseDataObjectAnimationKey(AnimBone animBone)
        {
            ReadHeadOfDataObject();

            // read key type
            uint keyType = ReadInt();

            // read number of keys
            uint numKeys = ReadInt();

            for (uint a = 0; a < numKeys; a++)
            {
                // read time
                uint time = ReadInt();

                // read keys
                switch (keyType)
                {
                    case 0:
                        {
                            if (ReadInt() != 4)
                                ThrowException("Invalid number of arguments for quaternion key in animation");

                            var keyValue = new Quaternion();
                            keyValue.W = ReadFloat();
                            keyValue.X = ReadFloat();
                            keyValue.Y = ReadFloat();
                            keyValue.Z = ReadFloat();
                            QuatKey key = new QuatKey((double)time, keyValue);
                            animBone.RotKeys.Add(key);

                            CheckForSemicolon();
                            break;
                        }
                    case 1: // scale vector
                    case 2: // position vector
                        {
                            // read count
                            if (ReadInt() != 3)
                            {
                                ThrowException("Invalid number of arguments for vector key in animation");
                            }
                            VectorKey key = new VectorKey((double)time, ReadVector3());

                            if (keyType == 2)
                            {
                                animBone.PosKeys.Add(key);
                            }
                            else
                            {
                                animBone.ScaleKeys.Add(key);
                            }
                            break;
                        }
                    case 3:
                    case 4:
                        {
                            // read count
                            if (ReadInt() != 16)
                                ThrowException("Invalid number of arguments for matrix key in animation");

                            // read matrix
                            double key = (double)time;
                            Matrix4x4 value = new Matrix4x4();
                            value.M11 = ReadFloat(); value.M21 = ReadFloat();
                            value.M31 = ReadFloat(); value.M41 = ReadFloat();
                            value.M12 = ReadFloat(); value.M22 = ReadFloat();
                            value.M32 = ReadFloat(); value.M42 = ReadFloat();
                            value.M13 = ReadFloat(); value.M23 = ReadFloat();
                            value.M33 = ReadFloat(); value.M43 = ReadFloat();
                            value.M14 = ReadFloat(); value.M24 = ReadFloat();
                            value.M34 = ReadFloat(); value.M44 = ReadFloat();
                            animBone.TrafoKeys.Add(new MatrixKey(key, value));
                            CheckForSemicolon();
                            break;
                        }
                    default:
                        ThrowException(string.Format("Unknown key type {0} in animation.", keyType));
                        break;
                }
                CheckForSeparator();
            }
            CheckForClosingBrace();
        }
Exemple #2
0
        protected void ParseDataObjectAnimation(Animation pAnim)
        {
            ReadHeadOfDataObject();
            AnimBone banim = new AnimBone();
            pAnim.Anims.Add(banim);

            bool running = true;
            while (running)
            {
                string objectName = GetNextToken();
                if (objectName.Length == 0)
                {
                    ThrowException("Unexpected end of file while parsing animation.");
                }
                else if (objectName == "}")
                {
                    break; // animation finished
                }
                else if (objectName == "AnimationKey")
                {
                    ParseDataObjectAnimationKey(banim);
                }
                else if (objectName == "AnimationOptions")
                {
                    ParseUnknownDataObject(); // not interested
                }
                else if (objectName == "{")
                {
                    // read frame name
                    banim.BoneName = GetNextToken();
                    CheckForClosingBrace();
                }
                else
                {
                    Debug.WriteLine("Unknown data object in animation in x file");
                    ParseUnknownDataObject();
                }
            }
        }