コード例 #1
0
        bool ICustomSerialization.Serialize(BinarySerializer Serializer)
        {
            uint ConstantMask = (uint)GfxAnimTransformFlags.IsScaleXConstant;
            uint NotExistMask = (uint)GfxAnimTransformFlags.IsScaleXInexistent;

            long Position = Serializer.BaseStream.Position;

            GfxAnimTransformFlags Flags = 0;

            //Serializer.Writer.Write(0u);
            bool[] HasFrameGrp = new bool[10];

            for (int ElemIndex = 0; ElemIndex < 10; ElemIndex++)
            {
                GfxFloatKeyFrameGroup FrameGrp = GetFrameGrpByElemIndex(ElemIndex);

                if (FrameGrp == null)
                {
                    Flags |= (GfxAnimTransformFlags)NotExistMask;

                    Serializer.Writer.Write(0u);
                }
                else if (FrameGrp.KeyFrames.Count == 1)
                {
                    Flags |= (GfxAnimTransformFlags)ConstantMask;

                    Serializer.Writer.Write(FrameGrp.KeyFrames[0].Value);
                }
                else
                {
                    if (FrameGrp.KeyFrames.Count > 1)
                    {
                        /*Serializer.Sections[(uint)GfxSectionId.Contents].Values.Add(new RefValue()
                         * {
                         *  Value    = FrameGrp,
                         *  Position = Serializer.BaseStream.Position
                         * });*/
                        HasFrameGrp[ElemIndex] = true;
                    }
                    else
                    {
                        Flags |= (GfxAnimTransformFlags)NotExistMask;
                    }

                    Serializer.Writer.Write(0u);
                }

                ConstantMask <<= 1;
                NotExistMask <<= 1;
            }

            long[] AxisPtrs = new long[10];

            for (int ElemIndex = 0; ElemIndex < 10; ElemIndex++)
            {
                if (HasFrameGrp[ElemIndex])
                {
                    AxisPtrs[ElemIndex] = Serializer.BaseStream.Position;
                    Serializer.WriteValue(GetFrameGrpByElemIndex(ElemIndex));
                }
            }

            long EndPos = Serializer.BaseStream.Position;

            GfxAnimVector.WriteFlagsToElem(Serializer, Position, (uint)Flags);

            Serializer.BaseStream.Seek(Position, SeekOrigin.Begin);
            foreach (ulong Ptr in AxisPtrs)
            {
                Serializer.WritePointer((uint)Ptr);
            }

            Serializer.BaseStream.Seek(EndPos, SeekOrigin.Begin);

            return(true);
        }
コード例 #2
0
ファイル: GfxAnimTransform.cs プロジェクト: yorki00/SPICA
        bool ICustomSerialization.Serialize(BinarySerializer Serializer)
        {
            uint ConstantMask = (uint)GfxAnimTransformFlags.IsScaleXConstant;
            uint NotExistMask = (uint)GfxAnimTransformFlags.IsScaleXInexistent;

            long Position = Serializer.BaseStream.Position;

            GfxAnimTransformFlags Flags = 0;

            Serializer.Writer.Write(0u);

            for (int ElemIndex = 0; ElemIndex < 10; ElemIndex++)
            {
                GfxFloatKeyFrameGroup FrameGrp = null;

                switch (ElemIndex)
                {
                case 0: FrameGrp = _ScaleX;       break;

                case 1: FrameGrp = _ScaleY;       break;

                case 2: FrameGrp = _ScaleZ;       break;

                case 3: FrameGrp = _RotationX;    break;

                case 4: FrameGrp = _RotationY;    break;

                case 5: FrameGrp = _RotationZ;    break;

                case 7: FrameGrp = _TranslationX; break;

                case 8: FrameGrp = _TranslationY; break;

                case 9: FrameGrp = _TranslationZ; break;
                }

                if (FrameGrp == null)
                {
                    Flags |= (GfxAnimTransformFlags)NotExistMask;

                    Serializer.Writer.Write(0u);
                }
                else if (FrameGrp.KeyFrames.Count == 1)
                {
                    Flags |= (GfxAnimTransformFlags)ConstantMask;

                    Serializer.Writer.Write(FrameGrp.KeyFrames[0].Value);
                }
                else
                {
                    if (FrameGrp.KeyFrames.Count > 1)
                    {
                        Serializer.Sections[(uint)GfxSectionId.Contents].Values.Add(new RefValue()
                        {
                            Value    = FrameGrp,
                            Position = Serializer.BaseStream.Position
                        });
                    }
                    else
                    {
                        Flags |= (GfxAnimTransformFlags)NotExistMask;
                    }

                    Serializer.Writer.Write(0u);
                }

                ConstantMask <<= 1;
                NotExistMask <<= 1;
            }

            GfxAnimVector.WriteFlagsToElem(Serializer, Position, (uint)Flags);

            Serializer.BaseStream.Seek(Position + 4 + 9 * 4, SeekOrigin.Begin);

            return(true);
        }