Esempio n. 1
0
        private void LoadAnim(VisibilityAnim vis)
        {
            VisibilityAnim = vis;
            FrameCount     = vis.FrameCount;

            Text = vis.Name;

            if (vis.BaseDataList == null)
            {
                vis.BaseDataList = new bool[0];
            }

            if (vis.Names == null)
            {
                vis.Names = new string[0];
            }

            BaseValues = vis.BaseDataList;

            foreach (var name in vis.Names)
            {
                BoneNames.Add(name);
            }

            for (int curve = 0; curve < vis.Curves.Count; curve++)
            {
                var track = CurveHelper.CreateBooleanTrack(vis.Curves[curve]);
                track.Text = BoneNames[(int)track.AnimDataOffset];
                Values.Add(track);
            }
        }
Esempio n. 2
0
        private void LoadAnim(ResU.VisibilityAnim vis)
        {
            VisibilityAnimU = vis;
            FrameCount      = vis.FrameCount;

            Text = vis.Name;

            if (vis.BaseDataList == null)
            {
                vis.BaseDataList = new bool[0];
            }

            if (vis.Names == null)
            {
                vis.Names = new string[0];
            }

            BaseValues = vis.BaseDataList;

            foreach (var name in vis.Names)
            {
                BoneNames.Add(name);
            }

            for (int curve = 0; curve < vis.Curves.Count; curve++)
            {
                Values.Add(CurveHelper.CreateBooleanTrackWiiU(vis.Curves[curve]));
            }
        }
Esempio n. 3
0
        public void LoadAnim(ShaderParamAnim anim, AnimationType type)
        {
            Initialize();

            Text = anim.Name;

            AnimType = type;

            FrameCount      = anim.FrameCount;
            ShaderParamAnim = anim;
            foreach (ShaderParamMatAnim matAnim in anim.ShaderParamMatAnims)
            {
                MaterialAnimEntry matNode = new MaterialAnimEntry(matAnim.Name);
                matNode.materialAnimData = matAnim;
                Materials.Add(matNode);

                //Param info determines which curves to use for each param
                //Add the curves and keys for left/right for interpolating after
                foreach (var param in matAnim.ParamAnimInfos)
                {
                    BfresParamAnim paramInfo = new BfresParamAnim(param.Name);
                    paramInfo.Type = type;
                    matNode.Params.Add(paramInfo);

                    //Get constant anims
                    for (int constant = 0; constant < param.ConstantCount; constant++)
                    {
                        Animation.KeyGroup keyGroup = new Animation.KeyGroup();
                        keyGroup.Keys.Add(new Animation.KeyFrame()
                        {
                            InterType = InterpolationType.CONSTANT,
                            Frame     = 0,
                            Value     = matAnim.Constants[constant].Value,
                        });

                        paramInfo.Values.Add(new Animation.KeyGroup()
                        {
                            AnimDataOffset = matAnim.Constants[constant].AnimDataOffset,
                            Keys           = keyGroup.Keys,
                        });
                    }

                    for (int curve = 0; curve < param.FloatCurveCount + param.IntCurveCount; curve++)
                    {
                        int index = curve + param.BeginCurve;

                        Animation.KeyGroup keyGroup = CurveHelper.CreateTrackWiiU(matAnim.Curves[index]);
                        keyGroup.AnimDataOffset = matAnim.Curves[index].AnimDataOffset;
                        paramInfo.Values.Add(new Animation.KeyGroup()
                        {
                            AnimDataOffset = keyGroup.AnimDataOffset,
                            Keys           = keyGroup.Keys,
                        });
                    }
                }
            }
        }
Esempio n. 4
0
            private AnimCurve CreateAnimCurve()
            {
                //Create empty curve
                AnimCurve curve = new AnimCurve();

                curve.Offset         = 0;
                curve.StartFrame     = 0;
                curve.EndFrame       = MatAnimWrapper.FrameCount;
                curve.CurveType      = AnimCurveType.StepInt;
                curve.AnimDataOffset = 0;
                curve.Scale          = 1;

                //Start with sbyte. Increase only if index is > 255
                curve.KeyType = AnimCurveKeyType.SByte;

                //Set by frame count
                curve.FrameType = CurveHelper.GetFrameType((uint)MatAnimWrapper.FrameCount);

                return(curve);
            }
Esempio n. 5
0
            public void LoadAnim(ResU.CameraAnim anim)
            {
                Initialize();

                CameraAnimU = anim;

                Text = anim.Name;

                FrameCount  = anim.FrameCount;
                AspectRatio = anim.BaseData.AspectRatio;
                ClipFar     = anim.BaseData.ClipFar;
                ClipNear    = anim.BaseData.ClipNear;
                FieldOfView = anim.BaseData.FieldOfView;
                Position    = Utils.ToVec3(anim.BaseData.Position);
                Rotation    = Utils.ToVec3(anim.BaseData.Rotation);
                Twist       = anim.BaseData.Twist;
                if (anim.Flags.HasFlag(CameraAnimFlags.EulerZXY))
                {
                    settings |= Settings.EulerZXY;
                }
                if (anim.Flags.HasFlag(CameraAnimFlags.Perspective))
                {
                    settings |= Settings.Perspective;
                }

                for (int curve = 0; curve < anim.Curves.Count; curve++)
                {
                    Animation.KeyGroup keyGroup = CurveHelper.CreateTrackWiiU(anim.Curves[curve]);
                    keyGroup.AnimDataOffset = anim.Curves[curve].AnimDataOffset;
                    Values.Add(new Animation.KeyGroup()
                    {
                        AnimDataOffset = keyGroup.AnimDataOffset,
                        Keys           = keyGroup.Keys,
                    });
                }
            }
Esempio n. 6
0
        private void LoadAnim(MaterialAnim anim)
        {
            Initialize();

            MaterialAnim = anim;
            FrameCount   = MaterialAnim.FrameCount;
            Text         = anim.Name;

            Textures.Clear();
            if (anim.TextureNames != null)
            {
                foreach (var name in anim.TextureNames)
                {
                    Textures.Add(name);
                }
            }

            Materials.Clear();
            foreach (var matanim in anim.MaterialAnimDataList)
            {
                var mat = new MaterialAnimEntry(matanim.Name);
                mat.MaterialAnimData = matanim;
                Materials.Add(mat);

                foreach (var param in matanim.ParamAnimInfos)
                {
                    FSHU.BfresParamAnim paramInfo = new FSHU.BfresParamAnim(param.Name);
                    mat.Params.Add(paramInfo);

                    paramInfo.Type = AnimationType.ShaderParam;

                    //There is no better way to determine if the param is a color type afaik
                    if (param.Name.Contains("Color") || param.Name.Contains("color") || param.Name == "multi_tex_reg2")
                    {
                        paramInfo.Type = AnimationType.Color;
                    }
                    else if (AnimType == AnimationType.TexturePattern)
                    {
                        paramInfo.Type = AnimationType.TexturePattern;
                    }
                    else if (AnimType == AnimationType.TextureSrt)
                    {
                        paramInfo.Type = AnimationType.TextureSrt;
                    }
                    else
                    {
                        paramInfo.Type = AnimationType.ShaderParam;
                    }

                    //Get constant anims
                    for (int constant = 0; constant < param.ConstantCount; constant++)
                    {
                        int index = constant + param.BeginConstant;

                        Animation.KeyGroup keyGroup = new Animation.KeyGroup();
                        keyGroup.Keys.Add(new Animation.KeyFrame()
                        {
                            InterType = InterpolationType.CONSTANT,
                            Frame     = 0,
                            Value     = matanim.Constants[index].Value,
                        });

                        paramInfo.Values.Add(new Animation.KeyGroup()
                        {
                            AnimDataOffset = matanim.Constants[index].AnimDataOffset,
                            Keys           = keyGroup.Keys,
                        });
                    }

                    for (int curve = 0; curve < param.FloatCurveCount + param.IntCurveCount; curve++)
                    {
                        int index = curve + param.BeginCurve;

                        Animation.KeyGroup keyGroup = CurveHelper.CreateTrack(matanim.Curves[index]);
                        keyGroup.AnimDataOffset = matanim.Curves[index].AnimDataOffset;

                        paramInfo.Values.Add(new Animation.KeyGroup()
                        {
                            AnimDataOffset = keyGroup.AnimDataOffset,
                            Keys           = keyGroup.Keys,
                        });
                    }
                }

                foreach (TexturePatternAnimInfo SamplerInfo in matanim.TexturePatternAnimInfos)
                {
                    BfresSamplerAnim sampler = new BfresSamplerAnim(SamplerInfo.Name, this, mat);
                    mat.Samplers.Add(sampler);


                    int textureIndex = 0;

                    if (SamplerInfo.BeginConstant != 65535)
                    {
                        textureIndex = matanim.Constants[SamplerInfo.BeginConstant].Value;

                        sampler.Keys.Add(new Animation.KeyFrame()
                        {
                            Frame = 0, Value = textureIndex
                        });
                        sampler.Constant       = true;
                        sampler.AnimDataOffset = matanim.Constants[SamplerInfo.BeginConstant].AnimDataOffset;
                    }
                    if (SamplerInfo.CurveIndex != 65535)
                    {
                        int index = (int)SamplerInfo.CurveIndex;

                        Animation.KeyGroup keyGroup = CurveHelper.CreateTrack(matanim.Curves[index]);

                        sampler.AnimDataOffset = matanim.Curves[index].AnimDataOffset;
                        sampler.Keys           = keyGroup.Keys;
                    }
                }
            }
        }
Esempio n. 7
0
        private void LoadAnimData(ResU.SkeletalAnim ska)
        {
            Nodes.Clear();
            Bones.Clear();

            CanLoop = ska.FlagsAnimSettings.HasFlag(ResU.SkeletalAnimFlags.Looping);

            foreach (ResU.BoneAnim bn in ska.BoneAnims)
            {
                BoneAnimNode bone = new BoneAnimNode(bn.Name, false);
                bone.BoneAnimU = bn;
                bone.UseSegmentScaleCompensate = bn.ApplySegmentScaleCompensate;

                Bones.Add(bone);
                //    Nodes.Add(bone);

                if (ska.FlagsRotate == ResU.SkeletalAnimFlagsRotate.EulerXYZ)
                {
                    bone.RotType = Animation.RotationType.EULER;
                }
                else
                {
                    bone.RotType = Animation.RotationType.QUATERNION;
                }


                if (bn.FlagsBase.HasFlag(ResU.BoneAnimFlagsBase.Scale))
                {
                    bone.XSCA.Keys.Add(new KeyFrame()
                    {
                        Frame = 0, Value = bn.BaseData.Scale.X, IsKeyed = true
                    });
                    bone.YSCA.Keys.Add(new KeyFrame()
                    {
                        Frame = 0, Value = bn.BaseData.Scale.Y, IsKeyed = true
                    });
                    bone.ZSCA.Keys.Add(new KeyFrame()
                    {
                        Frame = 0, Value = bn.BaseData.Scale.Z, IsKeyed = true
                    });
                }
                if (bn.FlagsBase.HasFlag(ResU.BoneAnimFlagsBase.Rotate))
                {
                    bone.XROT.Keys.Add(new KeyFrame()
                    {
                        Frame = 0, Value = bn.BaseData.Rotate.X, IsKeyed = true
                    });
                    bone.YROT.Keys.Add(new KeyFrame()
                    {
                        Frame = 0, Value = bn.BaseData.Rotate.Y, IsKeyed = true
                    });
                    bone.ZROT.Keys.Add(new KeyFrame()
                    {
                        Frame = 0, Value = bn.BaseData.Rotate.Z, IsKeyed = true
                    });
                    bone.WROT.Keys.Add(new KeyFrame()
                    {
                        Frame = 0, Value = bn.BaseData.Rotate.W, IsKeyed = true
                    });
                }
                if (bn.FlagsBase.HasFlag(ResU.BoneAnimFlagsBase.Translate))
                {
                    bone.XPOS.Keys.Add(new KeyFrame()
                    {
                        Frame = 0, Value = bn.BaseData.Translate.X, IsKeyed = true
                    });
                    bone.YPOS.Keys.Add(new KeyFrame()
                    {
                        Frame = 0, Value = bn.BaseData.Translate.Y, IsKeyed = true
                    });
                    bone.ZPOS.Keys.Add(new KeyFrame()
                    {
                        Frame = 0, Value = bn.BaseData.Translate.Z, IsKeyed = true
                    });
                }

                for (int curve = 0; curve < bn.Curves.Count; curve++)
                {
                    Animation.KeyGroup keyGroup = CurveHelper.CreateTrackWiiU(bn.Curves[curve]);
                    keyGroup.AnimDataOffset = bn.Curves[curve].AnimDataOffset;
                    switch (keyGroup.AnimDataOffset)
                    {
                    case (int)TrackType.XPOS: bone.XPOS.Keys.AddRange(keyGroup.Keys); break;

                    case (int)TrackType.YPOS: bone.YPOS.Keys.AddRange(keyGroup.Keys); break;

                    case (int)TrackType.ZPOS: bone.ZPOS.Keys.AddRange(keyGroup.Keys); break;

                    case (int)TrackType.XROT: bone.XROT.Keys.AddRange(keyGroup.Keys); break;

                    case (int)TrackType.YROT: bone.YROT.Keys.AddRange(keyGroup.Keys); break;

                    case (int)TrackType.ZROT: bone.ZROT.Keys.AddRange(keyGroup.Keys); break;

                    case (int)TrackType.WROT: bone.WROT.Keys.AddRange(keyGroup.Keys); break;

                    case (int)TrackType.XSCA: bone.XSCA.Keys.AddRange(keyGroup.Keys); break;

                    case (int)TrackType.YSCA: bone.YSCA.Keys.AddRange(keyGroup.Keys); break;

                    case (int)TrackType.ZSCA: bone.ZSCA.Keys.AddRange(keyGroup.Keys); break;

                    default: throw new Exception("Unknown Anim Offset " + keyGroup.AnimDataOffset);
                    }
                }
            }
        }
Esempio n. 8
0
        private void LoadAnim(TexPatternAnim anim)
        {
            CanReplace = true;
            CanExport  = true;
            CanDelete  = true;
            CanRename  = true;

            Text = anim.Name;

            TexPatternAnim = anim;
            FrameCount     = anim.FrameCount;

            Materials.Clear();
            Textures.Clear();
            if (anim.TextureRefNames != null)
            {
                foreach (var tex in anim.TextureRefNames)
                {
                    Textures.Add(tex.Name);
                }
            }

            if (anim.TextureRefs != null)
            {
                foreach (var tex in anim.TextureRefs)
                {
                    Textures.Add(tex.Key);
                }
            }


            foreach (TexPatternMatAnim matanim in anim.TexPatternMatAnims)
            {
                var mat = new MaterialAnimEntry(matanim.Name);
                mat.TexPatternMatAnim = matanim;
                Materials.Add(mat);

                foreach (PatternAnimInfo SamplerInfo in matanim.PatternAnimInfos)
                {
                    BfresSamplerAnim sampler = new BfresSamplerAnim(SamplerInfo.Name, this);
                    mat.Samplers.Add(sampler);

                    int textureIndex = 0;

                    if (SamplerInfo.SubBindIndex != -1)
                    {
                        textureIndex = SamplerInfo.SubBindIndex;

                        sampler.Keys.Add(new Animation.KeyFrame()
                        {
                            Frame = 0, Value = textureIndex
                        });
                        sampler.Constant = true;
                    }
                    if (SamplerInfo.CurveIndex != -1)
                    {
                        int index = (int)SamplerInfo.CurveIndex;

                        Animation.KeyGroup keyGroup = CurveHelper.CreateTrackWiiU(matanim.Curves[index]);
                        sampler.AnimDataOffset = matanim.Curves[index].AnimDataOffset;
                        sampler.Keys           = keyGroup.Keys;

                        foreach (var ind in keyGroup.Keys)
                        {
                            Console.WriteLine($"{SamplerInfo.Name} {ind.Value}");
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        public void SaveData()
        {
            if (!IsEdited) //Use original data instead of generic data from editors
            {
                return;
            }

            if (VisibilityAnimU != null)
            {
                VisibilityAnimU.Name  = Text;
                VisibilityAnimU.Names = BoneNames;
                VisibilityAnimU.Path  = "";
            }
            else
            {
                VisibilityAnim.Name         = Text;
                VisibilityAnim.Names        = BoneNames;
                VisibilityAnim.Path         = "";
                VisibilityAnim.FrameCount   = FrameCount;
                VisibilityAnim.BaseDataList = new bool[BoneNames.Count];

                int boneIndex = 0;
                foreach (BooleanKeyGroup value in Values)
                {
                    if (!value.Constant)
                    {
                        AnimCurve curve = new AnimCurve();
                        curve.AnimDataOffset = (uint)BoneNames.IndexOf(value.Text);
                        curve.Scale          = value.Scale;
                        curve.Offset         = value.Offset;
                        curve.KeyType        = AnimCurveKeyType.SByte;
                        curve.FrameType      = CurveHelper.GetFrameType((uint)FrameCount);
                        curve.CurveType      = AnimCurveType.StepBool;

                        if (IsBaked)
                        {
                            curve.CurveType = AnimCurveType.BakedBool;
                        }

                        curve.Delta      = value.Delta;
                        curve.EndFrame   = value.EndFrame;
                        curve.StartFrame = value.StartFrame;

                        List <bool>  KeyBooleans = new List <bool>();
                        List <float> KeyFrames   = new List <float>();

                        for (int frame = 0; frame < value.Keys.Count; frame++)
                        {
                            bool  currentValue = value.Keys[frame].Visible;
                            float currentFrame = value.Keys[frame].Frame;

                            if (frame > 0)
                            {
                                bool previousValue = value.Keys[frame - 1].Visible;
                                if (previousValue != currentValue)
                                {
                                    KeyFrames.Add(currentFrame);
                                    KeyBooleans.Add(currentValue);
                                }
                            }
                            else
                            {
                                KeyFrames.Add(currentFrame);
                                KeyBooleans.Add(currentValue);
                                VisibilityAnim.BaseDataList[boneIndex] = currentValue;
                            }
                        }

                        curve.KeyStepBoolData = KeyBooleans.ToArray();

                        for (int frame = 0; frame < FrameCount; frame++)
                        {
                        }
                    }
                    else
                    {
                        //Else for constant types it's only base values
                    }

                    boneIndex++;
                }
            }
        }