Ejemplo n.º 1
0
        public static ResU.TexPatternAnim FTXPConvertSwitchToWiiU(ResNX.MaterialAnim materialAnim)
        {
            var texPatternAnim = new ResU.TexPatternAnim();

            //Different versions use different lists
            if (texPatternAnim.TextureRefNames == null)
            {
                texPatternAnim.TextureRefNames = new List <ResU.TextureRef>();
            }
            if (texPatternAnim.TextureRefs == null)
            {
                texPatternAnim.TextureRefs = new ResU.ResDict <ResU.TextureRef>();
            }

            texPatternAnim.Name        = materialAnim.Name;
            texPatternAnim.Path        = materialAnim.Path;
            texPatternAnim.BindIndices = materialAnim.BindIndices;
            texPatternAnim.FrameCount  = materialAnim.FrameCount;

            if (materialAnim.Loop)
            {
                texPatternAnim.Flags |= ResU.TexPatternAnimFlags.Looping;
            }

            //Fill both lists. On save only one will be used depending on version
            foreach (var texName in materialAnim.TextureNames)
            {
                var textureRef = new ResU.TextureRef();
                foreach (var container in PluginRuntime.ftexContainers)
                {
                    if (container.ResourceNodes.ContainsKey(texName))
                    {
                        textureRef.Texture = ((Bfres.Structs.FTEX)container.ResourceNodes[texName]).texture;
                    }
                }

                textureRef.Name = texName;
                texPatternAnim.TextureRefNames.Add(textureRef);
                texPatternAnim.TextureRefs.Add(texName, textureRef);
            }

            for (int m = 0; m < materialAnim.MaterialAnimDataList.Count; m++)
            {
                ResU.TexPatternMatAnim matAnimData = new ResU.TexPatternMatAnim();
                texPatternAnim.TexPatternMatAnims.Add(matAnimData);
                matAnimData.Name   = materialAnim.MaterialAnimDataList[m].Name;
                matAnimData.Curves = ConvertAnimCurveSwitchToWiiU(materialAnim.MaterialAnimDataList[m].Curves);

                foreach (var constants in materialAnim.MaterialAnimDataList[m].Constants)
                {
                    matAnimData.BaseDataList.Add((ushort)(int)constants.Value);
                }

                foreach (var patternInfoNX in materialAnim.MaterialAnimDataList[m].TexturePatternAnimInfos)
                {
                    var patternInfoU = new ResU.PatternAnimInfo();
                    patternInfoU.Name         = patternInfoNX.Name;
                    patternInfoU.CurveIndex   = (sbyte)patternInfoNX.CurveIndex;
                    patternInfoU.SubBindIndex = patternInfoNX.SubBindIndex;
                    matAnimData.PatternAnimInfos.Add(patternInfoU);
                }
            }

            return(texPatternAnim);
        }
Ejemplo n.º 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();
        }