public static void EncodeSRT0Keyframes(KeyframeCollection kf, VoidPtr entryAddress, VoidPtr dataAddress, SRT0Code code)
        {
            SRT0TextureEntry *header = (SRT0TextureEntry *)entryAddress;

            header->Code = code;

            bint *pOffset = (bint *)entryAddress + 1;

            int index = 0;

            //Write values/offset and encode groups
            for (int type = 0; type < 3; type++)
            {
                bool has = false;
                switch (type)
                {
                case 0: has = !code.NoScale; break;

                case 1: has = !code.NoRotation; break;

                case 2: has = !code.NoTranslation; break;
                }
                for (int axis = 0; axis < (type == 1 ? 1 : 2); axis++, index++)
                {
                    if (has)
                    {
                        if (code.ScaleIsotropic && type == 0)
                        {
                            if (axis == 0)
                            {
                                if (code.FixedScaleX)
                                {
                                    *(bfloat *)pOffset++ = kf._keyArrays[0]._keyRoot._next._value;
                                }
                                else
                                {
                                    *pOffset = (int)dataAddress - (int)pOffset; pOffset++;
                                    dataAddress += EncodeEntry(index, AnimDataFormat.I12, kf, dataAddress);
                                }
                            }
                        }
                        else
                        {
                            //This gets the fixed bit. Same order, so it can be indexed
                            if (code._data[5 + index])
                            {
                                *(bfloat *)pOffset++ = kf._keyArrays[index]._keyRoot._next._value;
                            }
                            else
                            {
                                *pOffset = (int)dataAddress - (int)pOffset; pOffset++;
                                dataAddress += EncodeEntry(index, AnimDataFormat.I12, kf, dataAddress);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        protected override bool OnInitialize()
        {
            if (_name == null)
            {
                _name = "Texture" + _textureIndex;
            }

            _flags = Header->Code;

            _keyframes = null;

            if (_parent is SRT0EntryNode && _parent._parent is SRT0Node)
            {
                _numFrames = ((SRT0Node)_parent._parent).FrameCount;
            }

            return(false);
        }
Example #3
0
        public override bool OnInitialize()
        {
            if (_name == null)
            {
                _name = (_indirect ? "Ind" : "") + "Texture" + _textureIndex;
            }

            _flags = Header->Code;

            _keyframes = null;

            if (Parent is SRT0EntryNode && Parent.Parent is SRT0Node)
            {
                _numFrames = ((SRT0Node)Parent.Parent).FrameCount;
            }

            return(false);
        }
Example #4
0
        private static int EvaluateSRT0Group(ref SRT0Code code, KeyframeCollection kf, int group, ref int entrySize)
        {
            //SRT0s always use I12

            //group
            //0 = scale
            //1 = rot
            //2 = trans

            int index     = group == 0 ? 0 : group == 1 ? 2 : 3;
            int numFrames = kf.FrameLimit;
            int dataLen   = 0;

            KeyframeEntry[] roots     = new KeyframeEntry[2];
            bool            exist     = false;
            bool            isotropic = group == 0;

            int[]  count   = new int[2];
            bool[] isExist = new bool[2];
            bool[] isFixed = new bool[2];

            for (int i = 0; i < (group == 1 ? 1 : 2); i++)
            {
                roots[i]   = kf._keyArrays[index + i]._keyRoot;
                count[i]   = kf._keyArrays[index + i]._keyCount;
                isExist[i] = count[i] > 0;
                isFixed[i] = count[i] <= 1;
            }

            if (exist = isExist[0] || isExist[1])
            {
                if (group == 0)
                {
                    if (isFixed[0] != isFixed[1])
                    {
                        isotropic = false;
                    }
                    else if (count[0] != count[1])
                    {
                        isotropic = false;
                    }
                    else
                    {
                        KeyframeEntry e1 = roots[0], e2 = roots[1];
                        for (int i = count[0]; i-- > 0;)
                        {
                            e1 = e1._next;
                            e2 = e2._next;
                            if (e1._index != e2._index ||
                                e1._value != e2._value)
                            {
                                isotropic = false;
                                break;
                            }
                        }
                    }
                }
            }

            if (group == 0 && !isotropic)
            {
                code.ScaleIsotropic = false;
            }

            for (int i = 0; i < (group == 1 ? 1 : 2); i++)
            {
                if (exist)
                {
                    switch (group)
                    {
                    case 0:
                        code.NoScale = false;
                        break;

                    case 1:
                        code.NoRotation = false;
                        break;

                    case 2:
                        code.NoTranslation = false;
                        break;
                    }

                    if (!(group == 0 && i == 1 && code.ScaleIsotropic))
                    {
                        entrySize += 4;
                    }

                    if (!isFixed[i])
                    {
                        switch (group)
                        {
                        case 0:
                            switch (i)
                            {
                            case 0:
                                code.FixedScaleX = false;
                                break;

                            case 1:
                                code.FixedScaleY = false;
                                break;
                            }

                            break;

                        case 1:
                            code.FixedRotation = false;
                            break;

                        case 2:
                            switch (i)
                            {
                            case 0:
                                code.FixedX = false;
                                break;

                            case 1:
                                code.FixedY = false;
                                break;
                            }

                            break;
                        }

                        if (!(group == 0 && i == 1 && code.ScaleIsotropic))
                        {
                            dataLen += 8 + count[i] * 12;
                        }
                    }
                }
            }

            return(dataLen);
        }
Example #5
0
        public static KeyframeCollection DecodeSRT0Keyframes(SRT0TextureEntry *entry, int numFrames)
        {
            KeyframeCollection kf = new KeyframeCollection(5, numFrames, 1, 1);

            if (entry == null)
            {
                return(kf);
            }

            bfloat * sPtr = (bfloat *)entry->Data;
            SRT0Code code = entry->Code;

            if (!code.NoScale)
            {
                if (code.ScaleIsotropic)
                {
                    if (code.FixedScaleX)
                    {
                        kf[0, 0, 1] = *sPtr++;
                    }
                    else
                    {
                        DecodeFrames(kf, (VoidPtr)sPtr + *(buint *)sPtr++, AnimDataFormat.I12, 0, 1);
                    }
                }
                else
                {
                    if (code.FixedScaleX)
                    {
                        kf[0, 0] = *sPtr++;
                    }
                    else
                    {
                        DecodeFrames(kf, (VoidPtr)sPtr + *(buint *)sPtr++, AnimDataFormat.I12, 0);
                    }

                    if (code.FixedScaleY)
                    {
                        kf[0, 1] = *sPtr++;
                    }
                    else
                    {
                        DecodeFrames(kf, (VoidPtr)sPtr + *(buint *)sPtr++, AnimDataFormat.I12, 1);
                    }
                }
            }

            if (!code.NoRotation)
            {
                if (code.FixedRotation)
                {
                    kf[0, 2] = *sPtr++;
                }
                else
                {
                    DecodeFrames(kf, (VoidPtr)sPtr + *(buint *)sPtr++, AnimDataFormat.I12, 2);
                }
            }

            if (!code.NoTranslation)
            {
                if (code.FixedX)
                {
                    kf[0, 3] = *sPtr++;
                }
                else
                {
                    DecodeFrames(kf, (VoidPtr)sPtr + *(buint *)sPtr++, AnimDataFormat.I12, 3);
                }

                if (code.FixedY)
                {
                    kf[0, 4] = *sPtr++;
                }
                else
                {
                    DecodeFrames(kf, (VoidPtr)sPtr + *(buint *)sPtr++, AnimDataFormat.I12, 4);
                }
            }

            return(kf);
        }
Example #6
0
        public static int CalculateSRT0Size(KeyframeCollection kf, out int entrySize, out SRT0Code code)
        {
            int dataSize = 0;

            entrySize = 4;

            code = SRT0Code.Default;

            for (int i = 0; i < 3; i++)
            {
                dataSize += EvaluateSRT0Group(ref code, kf, i, ref entrySize);
            }

            return(dataSize);
        }
Example #7
0
        public static void EncodeSRT0Keyframes(KeyframeCollection kf, VoidPtr entryAddress, VoidPtr dataAddress)
        {
            SRT0Code code = kf._texEvalCode;

            SRT0TextureEntry *header = (SRT0TextureEntry *)entryAddress;

            header->_code = code.data._data;

            bint *pOffset = (bint *)entryAddress + 1;

            int r = 0;

            //Write values/offset and encode groups
            for (int type = 0; type < 3; type++)
            {
                r = type * 3; //Increment to next
                bool has = false;
                switch (type)
                {
                case 0: has = !code.NoScale; break;

                case 1: has = !code.NoRotation; break;

                case 2: has = !code.NoTranslation; break;
                }
                for (int axis = 0; axis < (type == 1 ? 1 : 2); axis++)
                {
                    if (has)
                    {
                        if (code.ScaleIsotropic && type == 0)
                        {
                            if (axis == 0)
                            {
                                if (code.FixedScaleX)
                                {
                                    *(bfloat *)pOffset++ = kf._keyRoots[0]._next._value;
                                }
                                else
                                {
                                    *pOffset = (int)(dataAddress - pOffset); pOffset++;
                                    dataAddress += EncodeEntry(r + axis, AnimDataFormat.I12, kf, dataAddress);
                                }
                            }
                        }
                        else
                        {
                            bool fix = false;
                            switch (type)
                            {
                            case 0:
                                switch (axis)
                                {
                                case 0:
                                    fix = code.FixedScaleX;
                                    break;

                                case 1:
                                    fix = code.FixedScaleY;
                                    break;
                                }
                                break;

                            case 1:
                                fix = code.FixedRotation;
                                break;

                            case 2:
                                switch (axis)
                                {
                                case 0:
                                    fix = code.FixedX;
                                    break;

                                case 1:
                                    fix = code.FixedY;
                                    break;
                                }
                                break;
                            }

                            if (fix)
                            {
                                *(bfloat *)pOffset++ = kf._keyRoots[r + axis]._next._value;
                            }
                            else
                            {
                                *pOffset = (int)(dataAddress - pOffset); pOffset++;
                                dataAddress += EncodeEntry(r + axis, AnimDataFormat.I12, kf, dataAddress);
                            }
                        }
                    }
                }
            }
        }
Example #8
0
        public static KeyframeCollection DecodeSRT0Keyframes(SRT0TextureEntry *entry, int numFrames)
        {
            KeyframeCollection kf   = new KeyframeCollection(numFrames);
            bfloat *           sPtr = (bfloat *)entry->Data;
            SRT0Code           code = entry->Code;

            if (!code.NoScale)
            {
                if (code.ScaleIsotropic)
                {
                    if (code.FixedScaleX)
                    {
                        kf[KeyFrameMode.ScaleXYZ, 0] = *sPtr++;
                    }
                    else
                    {
                        DecodeSRT0Frames(kf, (VoidPtr)sPtr + *(buint *)sPtr++, KeyFrameMode.ScaleXYZ);
                    }
                }
                else
                {
                    if (code.FixedScaleX)
                    {
                        kf[KeyFrameMode.ScaleX, 0] = *sPtr++;
                    }
                    else
                    {
                        DecodeSRT0Frames(kf, (VoidPtr)sPtr + *(buint *)sPtr++, KeyFrameMode.ScaleX);
                    }
                    if (code.FixedScaleY)
                    {
                        kf[KeyFrameMode.ScaleY, 0] = *sPtr++;
                    }
                    else
                    {
                        DecodeSRT0Frames(kf, (VoidPtr)sPtr + *(buint *)sPtr++, KeyFrameMode.ScaleY);
                    }
                }
            }
            if (!code.NoRotation)
            {
                if (code.FixedRotation)
                {
                    kf[KeyFrameMode.RotX, 0] = *sPtr++;
                }
                else
                {
                    DecodeSRT0Frames(kf, (VoidPtr)sPtr + *(buint *)sPtr++, KeyFrameMode.RotX);
                }
            }

            if (!code.NoTranslation)
            {
                if (code.FixedX)
                {
                    kf[KeyFrameMode.TransX, 0] = *sPtr++;
                }
                else
                {
                    DecodeSRT0Frames(kf, (VoidPtr)sPtr + *(buint *)sPtr++, KeyFrameMode.TransX);
                }
                if (code.FixedY)
                {
                    kf[KeyFrameMode.TransY, 0] = *sPtr++;
                }
                else
                {
                    DecodeSRT0Frames(kf, (VoidPtr)sPtr + *(buint *)sPtr++, KeyFrameMode.TransY);
                }
            }

            return(kf);
        }
        public static void EncodeSRT0Keyframes(KeyframeCollection kf, VoidPtr entryAddress, VoidPtr dataAddress)
        {
            SRT0Code code = kf._texEvalCode;

            SRT0TextureEntry *header = (SRT0TextureEntry *)entryAddress;

            header->_code = code.data;

            bint *pOffset = (bint *)entryAddress + 1;

            int r = 0;

            //Write values/offset and encode groups
            for (int type = 0; type < 3; type++)
            {
                r = type * 3; //Increment to next
                for (int axis = 0; axis < (type == 1 ? 1 : 2); axis++)
                {
                    int loc = 0;
                    if (type == 2)
                    {
                        loc = 2;
                    }
                    else if (type == 1)
                    {
                        loc = 1;
                    }
                    else if (type == 0 && axis == 0)
                    {
                        loc = 3;
                    }
                    else
                    {
                        loc = 0;
                    }

                    int fix = 0;
                    if (type == 0)
                    {
                        fix = axis;
                    }
                    else if (type == 1)
                    {
                        fix = 2;
                    }
                    else if (type == 2)
                    {
                        fix = 3 + axis;
                    }

                    if (code.GetHas(loc))
                    {
                        if (code.GetFixed(fix))
                        {
                            *(bfloat *)pOffset++ = kf._keyRoots[r + axis]._next._value;
                        }
                        else
                        {
                            *pOffset = (int)(dataAddress - pOffset); pOffset++;
                            dataAddress += EncodeEntry(r + axis, AnimDataFormat.I12, kf, dataAddress);
                        }
                    }
                }
            }
        }
        private static int EvaluateSRT0Group(ref SRT0Code code, KeyframeCollection kf, int group, ref int entrySize)
        {
            //SRT0s always use I12

            //group
            //0 = scale
            //1 = rot
            //2 = trans

            int index     = group * 3;
            int numFrames = kf.FrameLimit;
            int dataLen   = 0;

            bool exist = false;

            int * count   = stackalloc int[2];
            bool *isExist = stackalloc bool[2];
            bool *isFixed = stackalloc bool[2];

            for (int i = 0; i < (group == 1 ? 1 : 2); i++)
            {
                count[i]   = kf._keyCounts[index + i];
                isExist[i] = count[i] > 0;
                isFixed[i] = count[i] <= 1;
            }

            exist = isExist[0] || isExist[1];
            for (int i = 0; i < (group == 1 ? 1 : 2); i++)
            {
                int loc = 0;
                if (group == 2)
                {
                    loc = 2;
                }
                else if (group == 1)
                {
                    loc = 1;
                }
                else if (group == 0 && i == 0)
                {
                    loc = 3;
                }
                else
                {
                    loc = 0;
                }

                int fix = 0;
                if (group == 0)
                {
                    fix = i;
                }
                else if (group == 1)
                {
                    fix = 2;
                }
                else if (group == 2)
                {
                    fix = 3 + i;
                }

                if (exist)
                {
                    entrySize += 4;
                    if (!isFixed[i])
                    {
                        dataLen += 8 + (count[i] * 12);
                    }
                }
                code.SetFixed(fix, isFixed[i]);
                code.SetHas(loc, exist);
            }
            return(dataLen);
        }