Пример #1
0
        private ImageKeyFrame[] GetImages(Image image)
        {
            FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]);
            // Number of frames
            int frameCount = image.GetFrameCount(dimension);

            // Return an Image at a certain index

            ImageKeyFrame[] images = new ImageKeyFrame[frameCount];
            for (int frame = 0; frame < frameCount; frame++)
            {
                images[frame]       = new ImageKeyFrame();
                images[frame].Image = new Bitmap(image);
                images[frame].Frame = frame;

                image.SelectActiveFrame(dimension, frame);
            }
            return(images);
        }
Пример #2
0
        public GifToTexturePatternAnimation(string FileName, BFRESGroupNode TargetFTEXFolder, FTXP ftxp)
        {
            string TextureName = System.IO.Path.GetFileNameWithoutExtension(FileName);

            string ext = Utils.GetExtension(FileName);

            ImageKeyFrame[] Images = new ImageKeyFrame[0];

            if (ext == ".gif")
            {
                Image gifImg = Image.FromFile(FileName);

                //Add all the images
                Images = GetImages(gifImg);
            }
            if (ext == ".png" || ext == ".apng")
            {
                APNG png = new APNG();
                png.Load(FileName);
                for (int i = 0; i < png.NumEmbeddedPNG; i++)
                {
                    Images[i] = new ImageKeyFrame()
                    {
                        Frame = i,
                        Image = png.ToBitmap(i)
                    };
                }
            }

            TargetFTEXFolder.ImportTexture(Images, TextureName);

            //Now load the key data to the animation
            ftxp.TexPatternAnim             = new ResU.TexPatternAnim();
            ftxp.TexPatternAnim.Name        = ftxp.Text;
            ftxp.TexPatternAnim.Path        = "";
            ftxp.TexPatternAnim.FrameCount  = Images.Length;
            ftxp.TexPatternAnim.TextureRefs = new ResU.ResDict <ResU.TextureRef>();
            foreach (ImageKeyFrame key in Images)
            {
                string name = $"{TextureName}{key.Frame}";

                ftxp.TexPatternAnim.TextureRefs.Add($"{TextureName}{key.Frame}",
                                                    new ResU.TextureRef()
                {
                    Name    = $"{name}",
                    Texture = ((FTEX)TargetFTEXFolder.ResourceNodes[name]).texture,
                });
            }

            var material = new ResU.TexPatternMatAnim();

            material.Name = "NewMaterial";

            material.PatternAnimInfos = new List <ResU.PatternAnimInfo>();

            material.BaseDataList.Add(0);

            ResU.PatternAnimInfo info = new ResU.PatternAnimInfo();
            info.CurveIndex   = 0;
            info.SubBindIndex = -1;
            info.Name         = "_a0";
            material.PatternAnimInfos.Add(info);

            ftxp.TexPatternAnim.TexPatternMatAnims.Add(material);
            ResU.AnimCurve curve = new ResU.AnimCurve();
            curve.AnimDataOffset = 0;
            curve.CurveType      = ResU.AnimCurveType.StepInt;
            curve.Delta          = 0;
            curve.EndFrame       = Images.Length;
            curve.StartFrame     = 0;
            curve.FrameType      = ResU.AnimCurveFrameType.Byte;
            curve.Scale          = 1;
            curve.Offset         = 0;
            curve.Frames         = new float[(int)curve.EndFrame];

            for (int i = 0; i < curve.EndFrame; i++)
            {
                curve.Frames[i] = Images[i].Frame;
            }

            curve.Keys = new float[(int)curve.Frames.Length, 1];
            for (int i = 0; i < (ushort)curve.Keys.Length; i++)
            {
                int index = ftxp.TexPatternAnim.TextureRefs.IndexOf($"{TextureName}{Images[i].Frame}");
                curve.Keys[i, 0] = index;
            }

            material.Curves.Add(curve);

            ftxp.UpdateMaterialBinds();
        }