public static ResNX.MaterialAnim FTXPConvertWiiUToSwitch(ResU.TexPatternAnim 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>();
            }

            ResNX.MaterialAnim matAnim = new ResNX.MaterialAnim();
            matAnim.Name        = texPatternAnim.Name;
            matAnim.Path        = texPatternAnim.Path;
            matAnim.FrameCount  = texPatternAnim.FrameCount;
            matAnim.BindIndices = texPatternAnim.BindIndices;
            matAnim.BakedSize   = texPatternAnim.BakedSize;
            matAnim.Loop        = texPatternAnim.Flags.HasFlag(ResU.TexPatternAnimFlags.Looping);

            foreach (var texRef in texPatternAnim.TextureRefNames)
            {
                matAnim.TextureNames.Add(texRef.Name);
            }

            foreach (var texRef in texPatternAnim.TextureRefs)
            {
                matAnim.TextureNames.Add(texRef.Key);
            }

            int CurveIndex = 0;

            for (int m = 0; m < texPatternAnim.TexPatternMatAnims.Count; m++)
            {
                ResNX.MaterialAnimData matAnimData = new ResNX.MaterialAnimData();
                matAnimData.Name = texPatternAnim.TexPatternMatAnims[m].Name;

                foreach (var patternInfoU in texPatternAnim.TexPatternMatAnims[m].PatternAnimInfos)
                {
                    ResNX.TexturePatternAnimInfo animInfo = new ResNX.TexturePatternAnimInfo();
                    animInfo.Name          = patternInfoU.Name;
                    animInfo.CurveIndex    = (uint)patternInfoU.CurveIndex;
                    animInfo.BeginConstant = (ushort)patternInfoU.SubBindIndex;
                    matAnimData.TexturePatternAnimInfos.Add(animInfo);
                }

                if (texPatternAnim.TexPatternMatAnims[m].Curves.Count == 0)
                {
                    foreach (var baseData in texPatternAnim.TexPatternMatAnims[m].BaseDataList)
                    {
                        //Add base values as constants
                        matAnimData.Constants.Add(new ResNX.AnimConstant()
                        {
                            Value          = (int)baseData,
                            AnimDataOffset = 0,
                        });
                    }
                }
                else
                {
                    matAnimData.TexturePatternCurveIndex = CurveIndex++;
                    matAnimData.BeginVisalConstantIndex  = 0;

                    matAnimData.Curves = ConvertAnimCurveWiiUToSwitch(texPatternAnim.TexPatternMatAnims[m].Curves);
                }

                matAnim.MaterialAnimDataList.Add(matAnimData);
            }

            matAnim.TextureBindArray = new long[matAnim.TextureNames.Count];
            for (int i = 0; i < matAnim.TextureNames.Count; i++)
            {
                matAnim.TextureBindArray[i] = -1;
            }

            matAnim.UserData = ConvertUserDataWiiU2Switch(texPatternAnim.UserData);

            return(matAnim);
        }
Example #2
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);
        }