Exemplo n.º 1
0
        public static ResU.ShaderParamAnim Clr02Fshu(string FileName)
        {
            CLR0Node clr0 = NodeFactory.FromFile(null, FileName) as CLR0Node;

            ResU.ShaderParamAnim fshu = new ResU.ShaderParamAnim();
            fshu.FrameCount = clr0.FrameCount;
            fshu.Name       = clr0.Name;
            fshu.Path       = clr0.OriginalPath;
            fshu.UserData   = new ResU.ResDict <Syroot.NintenTools.Bfres.UserData>();

            //Set flags
            if (clr0.Loop)
            {
                fshu.Flags |= ResU.ShaderParamAnimFlags.Looping;
            }

            //Set mat anims and then calculate data after
            foreach (var entry in clr0.Children)
            {
                fshu.ShaderParamMatAnims.Add(Clr0Entry2ShaderMatAnim(clr0, (CLR0MaterialNode)entry));
            }

            fshu.BakedSize   = CalculateBakeSize(fshu);
            fshu.BindIndices = SetIndices(fshu);

            return(fshu);
        }
Exemplo n.º 2
0
        public void NewClr()
        {
            CLR0Node node = ((BRRESNode)_resource).CreateResource <CLR0Node>("NewCLR");

            node.Version = 3;
            BaseWrapper res = this.FindResource(node, true);

            res = res.FindResource(node, false);
            res.EnsureVisible();
            res.TreeView.SelectedNode = res;
        }
Exemplo n.º 3
0
        public void ImportClr()
        {
            if (Program.OpenFile(FileFilters.CLR0, out string path) > 0)
            {
                CLR0Node node = NodeFactory.FromFile(null, path) as CLR0Node;
                ((BRRESNode)_resource).GetOrCreateFolder <CLR0Node>().AddChild(node);

                BaseWrapper w = FindResource(node, true);
                w.EnsureVisible();
                w.TreeView.SelectedNode = w;
            }
        }
Exemplo n.º 4
0
        public static ResU.ShaderParamMatAnim Clr0Entry2ShaderMatAnim(CLR0Node clr0, CLR0MaterialNode clrMaterial)
        {
            ResU.ShaderParamMatAnim matAnim = new ResU.ShaderParamMatAnim();
            matAnim.Name = clrMaterial.Name;
            foreach (var entry in clrMaterial.Children)
            {
                ushort curveIndex    = 0;
                ushort constantIndex = 0;

                CLR0MaterialEntryNode ParamEntry = (CLR0MaterialEntryNode)entry;

                //Add constants for RGBA if constant
                if (ParamEntry.Constant)
                {
                    //Red
                    matAnim.Constants.Add(new ResU.AnimConstant()
                    {
                        AnimDataOffset = 0,
                        Value          = (float)ParamEntry.Colors[0].R / 255f,
                    });

                    //Green
                    matAnim.Constants.Add(new ResU.AnimConstant()
                    {
                        AnimDataOffset = 4,
                        Value          = (float)ParamEntry.Colors[0].G / 255f,
                    });

                    //Blue
                    matAnim.Constants.Add(new ResU.AnimConstant()
                    {
                        AnimDataOffset = 8,
                        Value          = (float)ParamEntry.Colors[0].B / 255f,
                    });

                    //Alpha
                    matAnim.Constants.Add(new ResU.AnimConstant()
                    {
                        AnimDataOffset = 12,
                        Value          = (float)ParamEntry.Colors[0].A / 255f,
                    });
                }

                var RedCurve   = GenerateCurve(0, clr0, ParamEntry);
                var GreenCurve = GenerateCurve(4, clr0, ParamEntry);
                var BlueCurve  = GenerateCurve(8, clr0, ParamEntry);
                var AlphaCurve = GenerateCurve(12, clr0, ParamEntry);

                if (RedCurve != null)
                {
                    matAnim.Curves.Add(RedCurve);
                }
                if (GreenCurve != null)
                {
                    matAnim.Curves.Add(GreenCurve);
                }
                if (BlueCurve != null)
                {
                    matAnim.Curves.Add(BlueCurve);
                }
                if (AlphaCurve != null)
                {
                    matAnim.Curves.Add(AlphaCurve);
                }

                matAnim.ParamAnimInfos.Add(new ResU.ParamAnimInfo()
                {
                    Name            = entry.Name,
                    BeginCurve      = matAnim.Curves.Count > 0 ? curveIndex : ushort.MaxValue,
                    FloatCurveCount = (ushort)matAnim.Curves.Count,
                    SubBindIndex    = ushort.MaxValue,
                    ConstantCount   = (ushort)matAnim.Constants.Count,
                    BeginConstant   = matAnim.Constants.Count > 0 ? constantIndex : ushort.MaxValue,
                });

                constantIndex += (ushort)matAnim.Constants.Count;
                curveIndex    += (ushort)matAnim.Curves.Count;
            }

            return(matAnim);
        }
Exemplo n.º 5
0
        private static ResU.AnimCurve GenerateCurve(uint AnimOffset, CLR0Node anim, CLR0MaterialEntryNode entry)
        {
            ResU.AnimCurve curve = new ResU.AnimCurve();
            curve.AnimDataOffset = AnimOffset;
            curve.StartFrame     = 0;
            curve.Offset         = 0;
            curve.Scale          = 1;
            curve.FrameType      = ResU.AnimCurveFrameType.Single;
            curve.KeyType        = ResU.AnimCurveKeyType.Single;
            curve.CurveType      = ResU.AnimCurveType.Linear;

            List <float> Frames = new List <float>();
            List <float> Keys   = new List <float>();

            for (int c = 0; c < entry.Colors.Count; c++)
            {
                Frames.Add(c);
                //Max of 4 values.  Cubic using 4, linear using 2, and step using 1
                float[] KeyValues = new float[4];

                switch (AnimOffset)
                {
                case 0:     //Red
                    Keys.Add((float)entry.Colors[c].R / 255f);
                    break;

                case 4:     //Green
                    Keys.Add((float)entry.Colors[c].G / 255f);
                    break;

                case 8:     //Blue
                    Keys.Add((float)entry.Colors[c].B / 255f);
                    break;

                case 12:     //Alpha
                    Keys.Add((float)entry.Colors[c].A / 255f);
                    break;

                default:
                    throw new Exception("Invalid animation offset set!");
                }
            }

            //Max value in frames is our end frame
            curve.EndFrame = Frames.Max();
            curve.Frames   = Frames.ToArray();

            //If a curve only has one frame we don't need to interpolate or add keys to a curve as it's constant
            if (curve.Frames.Length <= 1)
            {
                return(null);
            }

            switch (curve.CurveType)
            {
            case ResU.AnimCurveType.Cubic:
                curve.Keys = new float[Keys.Count, 4];
                for (int frame = 0; frame < Keys.Count; frame++)
                {
                    float Delta = 0;

                    if (frame < Keys.Count - 1)
                    {
                        Delta = Keys[frame + 1] - Keys[frame];
                    }

                    float value  = Keys[frame];
                    float Slope  = 0;
                    float Slope2 = 0;

                    curve.Keys[frame, 0] = value;
                    curve.Keys[frame, 1] = Slope;
                    curve.Keys[frame, 2] = Slope2;
                    curve.Keys[frame, 3] = Delta;
                }
                break;

            case ResU.AnimCurveType.StepInt:
                //Step requires no interpolation
                curve.Keys = new float[Keys.Count, 1];
                for (int frame = 0; frame < Keys.Count; frame++)
                {
                    curve.Keys[frame, 0] = 0;
                }
                break;

            case ResU.AnimCurveType.Linear:
                curve.Keys = new float[Keys.Count, 2];
                for (int frame = 0; frame < Keys.Count; frame++)
                {
                    //Delta for second value used in linear curves
                    float time  = curve.Frames[frame];
                    float Delta = 0;

                    if (frame < Keys.Count - 1)
                    {
                        Delta = Keys[frame + 1] - Keys[frame];
                    }

                    curve.Keys[frame, 0] = Keys[frame];
                    curve.Keys[frame, 1] = Delta;
                }
                break;
            }

            return(curve);
        }