示例#1
0
        private BoneAnim GenericBoneAnimToBfresBoneAnim(Animation.KeyNode boneNode)
        {
            BoneAnim boneAnim = new BoneAnim();

            boneAnim.Name = boneNode.Text;
            var posx = boneNode.XPOS.GetValue(0);
            var posy = boneNode.YPOS.GetValue(0);
            var posz = boneNode.ZPOS.GetValue(0);
            var scax = boneNode.XSCA.GetValue(0);
            var scay = boneNode.YSCA.GetValue(0);
            var scaz = boneNode.ZSCA.GetValue(0);
            var rotx = boneNode.XROT.GetValue(0);
            var roty = boneNode.YROT.GetValue(0);
            var rotz = boneNode.ZROT.GetValue(0);
            var rotw = boneNode.WROT.GetValue(0);

            var Value3One  = Syroot.Maths.Vector3F.One;
            var Value3Zero = Syroot.Maths.Vector3F.Zero;
            var Value4Zero = Syroot.Maths.Vector4F.Zero;

            BoneAnimData boneBaseData = new BoneAnimData();

            boneBaseData.Translate      = new Syroot.Maths.Vector3F(posx, posy, posz);
            boneBaseData.Scale          = new Syroot.Maths.Vector3F(scax, scay, scaz);
            boneBaseData.Rotate         = new Syroot.Maths.Vector4F(rotx, roty, rotz, rotw);
            boneAnim.BaseData           = boneBaseData;
            boneAnim.BeginBaseTranslate = 0;
            boneAnim.BeginTranslate     = 6;
            boneAnim.BeginRotate        = 3;
            boneAnim.Curves             = new List <AnimCurve>();
            boneAnim.FlagsBase          = BoneAnimFlagsBase.Translate | BoneAnimFlagsBase.Scale | BoneAnimFlagsBase.Rotate;
            boneAnim.FlagsTransform     = BoneAnimFlagsTransform.Identity;

            if (boneNode.XPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateX;
                var curve = SetAnimationCurve(boneNode.XPOS, (uint)FSKA.TrackType.XPOS);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.YPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateY;
                var curve = SetAnimationCurve(boneNode.YPOS, (uint)FSKA.TrackType.YPOS);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.ZPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateZ;
                var curve = SetAnimationCurve(boneNode.ZPOS, (uint)FSKA.TrackType.ZPOS);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.XSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleX;
                var curve = SetAnimationCurve(boneNode.XSCA, (uint)FSKA.TrackType.XSCA);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.YSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleY;
                var curve = SetAnimationCurve(boneNode.YSCA, (uint)FSKA.TrackType.YSCA);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.ZSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleZ;
                var curve = SetAnimationCurve(boneNode.ZSCA, (uint)FSKA.TrackType.ZSCA);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.XROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateX;
                var curve = SetAnimationCurve(boneNode.XROT, (uint)FSKA.TrackType.XROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.YROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateY;
                var curve = SetAnimationCurve(boneNode.YROT, (uint)FSKA.TrackType.YROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.ZROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateZ;
                var curve = SetAnimationCurve(boneNode.ZROT, (uint)FSKA.TrackType.ZROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.WROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateW;
                var curve = SetAnimationCurve(boneNode.WROT, (uint)FSKA.TrackType.WROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }

            return(boneAnim);
        }
示例#2
0
        public void Read(SkeletalAnim ska, ResFile b)
        {
            FrameCount   = ska.FrameCount;
            SkeletalAnim = ska;

            foreach (BoneAnim bn in ska.BoneAnims)
            {
                FSKANode bonean = new FSKANode(bn);

                Animation.KeyNode bone = new Animation.KeyNode("");
                Bones.Add(bone);
                if (ska.FlagsRotate == SkeletalAnimFlagsRotate.EulerXYZ)
                {
                    bone.RotType = Animation.RotationType.EULER;
                }
                else
                {
                    bone.RotType = Animation.RotationType.QUATERNION;
                }

                bone.Text = bonean.Text;


                for (int Frame = 0; Frame < ska.FrameCount; Frame++)
                {
                    if (Frame == 0)
                    {
                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Scale))
                        {
                            bone.XSCA.Keys.Add(new KeyFrame()
                            {
                                Frame = 0, Value = bonean.sca.X
                            });
                            bone.YSCA.Keys.Add(new KeyFrame()
                            {
                                Frame = 0, Value = bonean.sca.Y
                            });
                            bone.ZSCA.Keys.Add(new KeyFrame()
                            {
                                Frame = 0, Value = bonean.sca.Z
                            });
                        }
                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Rotate))
                        {
                            bone.XROT.Keys.Add(new KeyFrame()
                            {
                                Frame = 0, Value = bonean.rot.X
                            });
                            bone.YROT.Keys.Add(new KeyFrame()
                            {
                                Frame = 0, Value = bonean.rot.Y
                            });
                            bone.ZROT.Keys.Add(new KeyFrame()
                            {
                                Frame = 0, Value = bonean.rot.Z
                            });
                            bone.WROT.Keys.Add(new KeyFrame()
                            {
                                Frame = 0, Value = bonean.rot.W
                            });
                        }
                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Translate))
                        {
                            bone.XPOS.Keys.Add(new KeyFrame()
                            {
                                Frame = 0, Value = bonean.pos.X
                            });
                            bone.YPOS.Keys.Add(new KeyFrame()
                            {
                                Frame = 0, Value = bonean.pos.Y
                            });
                            bone.ZPOS.Keys.Add(new KeyFrame()
                            {
                                Frame = 0, Value = bonean.pos.Z
                            });
                        }
                    }
                    foreach (FSKATrack track in bonean.tracks)
                    {
                        KeyFrame frame = new KeyFrame();
                        frame.InterType = Animation.InterpolationType.HERMITE;
                        frame.Frame     = Frame;

                        FSKAKey left  = track.GetLeft(Frame);
                        FSKAKey right = track.GetRight(Frame);
                        float   value;

                        value = Animation.Hermite(Frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1);

                        // interpolate the value and apply
                        switch (track.flag)
                        {
                        case (int)TrackType.XPOS: frame.Value = value; bone.XPOS.Keys.Add(frame); break;

                        case (int)TrackType.YPOS: frame.Value = value; bone.YPOS.Keys.Add(frame); break;

                        case (int)TrackType.ZPOS: frame.Value = value; bone.ZPOS.Keys.Add(frame); break;

                        case (int)TrackType.XROT: frame.Value = value; bone.XROT.Keys.Add(frame); break;

                        case (int)TrackType.YROT: frame.Value = value; bone.YROT.Keys.Add(frame); break;

                        case (int)TrackType.ZROT: frame.Value = value; bone.ZROT.Keys.Add(frame); break;

                        case (int)TrackType.XSCA: frame.Value = value; bone.XSCA.Keys.Add(frame); break;

                        case (int)TrackType.YSCA: frame.Value = value; bone.YSCA.Keys.Add(frame); break;

                        case (int)TrackType.ZSCA: frame.Value = value; bone.ZSCA.Keys.Add(frame); break;
                        }
                    }
                }
            }
        }
示例#3
0
        public virtual Animation GetAnimation()
        {
            Animation a = new Animation(Text);

            a.frameCount = (int)DatAnimation.FrameCount;

            int bid = 0;

            foreach (DatAnimationNode bone in DatAnimation.Nodes)
            {
                Animation.KeyNode node = new Animation.KeyNode("Bone_" + bid++);
                //Console.WriteLine(node.Text + " " + bone.Tracks.Count);
                a.bones.Add(node);
                node.rotType = Animation.RotationType.Euler;

                AnimationHelperTrack[] helper;
                try
                {
                    helper = AnimationKeyFrameHelper.DecodeKeyFrames(bone);
                }
                catch (Exception)
                {
                    Console.WriteLine("Error Loading animation");
                    helper = new AnimationHelperTrack[0];
                }

                foreach (AnimationHelperTrack track in helper)
                {
                    float prevValue            = 0;
                    float prevTan              = 0;
                    Animation.KeyFrame prevkey = null;
                    Animation.KeyGroup Group   = new Animation.KeyGroup();

                    foreach (AnimationHelperKeyFrame key in track.KeyFrames)
                    {
                        Animation.KeyFrame f = new Animation.KeyFrame();
                        f.Frame = key.Frame;
                        f.Value = key.Value;
                        f.In    = key.Tan;
                        switch (key.InterpolationType)
                        {
                        case InterpolationType.Constant: f.interType = Animation.InterpolationType.Constant; break;

                        case InterpolationType.Hermite: f.interType = Animation.InterpolationType.Hermite; break;

                        case InterpolationType.Linear: f.interType = Animation.InterpolationType.Linear; break;

                        case InterpolationType.Step: f.interType = Animation.InterpolationType.Step; break;

                        case InterpolationType.HermiteValue:
                            f.interType = Animation.InterpolationType.Hermite;
                            f.In        = prevTan;
                            break;

                        case InterpolationType.HermiteCurve:
                            prevkey.Out = key.Tan;
                            continue;
                        }
                        prevValue = key.Value;
                        prevTan   = key.Tan;
                        prevkey   = f;
                        Group.keys.Add(f);
                    }

                    switch (track.TrackType)
                    {
                    case AnimTrackType.XPOS: node.xpos = Group; break;

                    case AnimTrackType.YPOS: node.ypos = Group; break;

                    case AnimTrackType.ZPOS: node.zpos = Group; break;

                    case AnimTrackType.XROT: node.xrot = Group; break;

                    case AnimTrackType.YROT: node.yrot = Group; break;

                    case AnimTrackType.ZROT: node.zrot = Group; break;

                    case AnimTrackType.XSCA: node.xsca = Group; break;

                    case AnimTrackType.YSCA: node.ysca = Group; break;

                    case AnimTrackType.ZSCA: node.zsca = Group; break;
                    }
                }
            }

            return(a);
        }
        private static BoneAnim createBoneAnim(Animation.KeyNode bone, BfresSkeletonAnim anim)
        {
            BoneAnim boneAnim = new BoneAnim();

            boneAnim.Name = bone.Name;
            var posx = bone.XPOS.GetValue(0);
            var posy = bone.YPOS.GetValue(0);
            var posz = bone.ZPOS.GetValue(0);
            var scax = bone.XSCA.GetValue(0);
            var scay = bone.YSCA.GetValue(0);
            var scaz = bone.ZSCA.GetValue(0);
            var rotx = bone.XROT.GetValue(0);
            var roty = bone.YROT.GetValue(0);
            var rotz = bone.ZROT.GetValue(0);
            var rotw = bone.WROT.GetValue(0);

            BoneAnimData boneBaseData = new BoneAnimData();

            boneBaseData.Translate      = new Syroot.Maths.Vector3F(posx, posy, posz);
            boneBaseData.Scale          = new Syroot.Maths.Vector3F(scax, scay, scaz);
            boneBaseData.Rotate         = new Syroot.Maths.Vector4F(rotx, roty, rotz, rotw);
            boneAnim.BaseData           = boneBaseData;
            boneAnim.BeginBaseTranslate = 0;
            boneAnim.BeginRotate        = 0;
            boneAnim.BeginTranslate     = 0;
            boneAnim.Curves             = new List <AnimCurve>();
            boneAnim.FlagsBase          = BoneAnimFlagsBase.Translate | BoneAnimFlagsBase.Scale | BoneAnimFlagsBase.Rotate;
            boneAnim.FlagsTransform     = BoneAnimFlagsTransform.Identity;

            if (bone.XPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateX;
                boneAnim.Curves.Add(SetAnimationCurve(bone.XPOS));
            }
            if (bone.YPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateY;
                boneAnim.Curves.Add(SetAnimationCurve(bone.YPOS));
            }
            if (bone.ZPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateZ;
                boneAnim.Curves.Add(SetAnimationCurve(bone.ZPOS));
            }
            if (bone.XSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleX;
                boneAnim.Curves.Add(SetAnimationCurve(bone.XSCA));
            }
            if (bone.YSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleY;
                boneAnim.Curves.Add(SetAnimationCurve(bone.YSCA));
            }
            if (bone.ZSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleZ;
                boneAnim.Curves.Add(SetAnimationCurve(bone.ZSCA));
            }
            if (bone.XROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateX;
                boneAnim.Curves.Add(SetAnimationCurve(bone.XROT));
            }
            if (bone.YROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateY;
                boneAnim.Curves.Add(SetAnimationCurve(bone.YROT));
            }
            if (bone.ZROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateZ;
                boneAnim.Curves.Add(SetAnimationCurve(bone.ZROT));
            }
            if (bone.WROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateW;
                boneAnim.Curves.Add(SetAnimationCurve(bone.WROT));
            }

            return(boneAnim);
        }
示例#5
0
        private BoneAnim GenericBoneAnimToBfresBoneAnim(Animation.KeyNode boneNode, int index)
        {
            BoneAnim boneAnim = new BoneAnim();

            boneAnim.Name = boneNode.Text;
            var posx = boneNode.XPOS.GetValue(0);
            var posy = boneNode.YPOS.GetValue(0);
            var posz = boneNode.ZPOS.GetValue(0);
            var scax = boneNode.XSCA.GetValue(0);
            var scay = boneNode.YSCA.GetValue(0);
            var scaz = boneNode.ZSCA.GetValue(0);
            var rotx = boneNode.XROT.GetValue(0);
            var roty = boneNode.YROT.GetValue(0);
            var rotz = boneNode.ZROT.GetValue(0);
            var rotw = boneNode.WROT.GetValue(0);

            BoneAnimData boneBaseData = new BoneAnimData();

            boneBaseData.Translate      = new Syroot.Maths.Vector3F(posx, posy, posz);
            boneBaseData.Scale          = new Syroot.Maths.Vector3F(scax, scay, scaz);
            boneBaseData.Rotate         = new Syroot.Maths.Vector4F(rotx, roty, rotz, rotw);
            boneAnim.BaseData           = boneBaseData;
            boneAnim.BeginBaseTranslate = 0;
            boneAnim.BeginTranslate     = 6;
            boneAnim.BeginRotate        = 3;
            boneAnim.Curves             = new List <AnimCurve>();
            boneAnim.FlagsBase          = BoneAnimFlagsBase.Translate | BoneAnimFlagsBase.Scale | BoneAnimFlagsBase.Rotate;

            if (boneBaseData.Rotate == new Syroot.Maths.Vector4F(0, 0, 0, 1))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.RotateZero;
            }
            if (boneBaseData.Translate == new Syroot.Maths.Vector3F(0, 0, 0))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.TranslateZero;
            }
            if (boneBaseData.Scale == new Syroot.Maths.Vector3F(1, 1, 1))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.ScaleOne;
            }
            if (IsUniform(boneBaseData.Scale))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.ScaleUniform;
            }
            if (index != 0) //root bone
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.SegmentScaleCompensate;
            }

            if (boneNode.XSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleX;
                var curve = SetAnimationCurve(boneNode.XSCA, (uint)FSKA.TrackType.XSCA);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.YSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleY;
                var curve = SetAnimationCurve(boneNode.YSCA, (uint)FSKA.TrackType.YSCA);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.ZSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleZ;
                var curve = SetAnimationCurve(boneNode.ZSCA, (uint)FSKA.TrackType.ZSCA);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.XROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateX;
                var curve = SetAnimationCurve(boneNode.XROT, (uint)FSKA.TrackType.XROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.YROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateY;
                var curve = SetAnimationCurve(boneNode.YROT, (uint)FSKA.TrackType.YROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.ZROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateZ;
                var curve = SetAnimationCurve(boneNode.ZROT, (uint)FSKA.TrackType.ZROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.WROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateW;
                var curve = SetAnimationCurve(boneNode.WROT, (uint)FSKA.TrackType.WROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.XPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateX;
                var curve = SetAnimationCurve(boneNode.XPOS, (uint)FSKA.TrackType.XPOS);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.YPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateY;
                var curve = SetAnimationCurve(boneNode.YPOS, (uint)FSKA.TrackType.YPOS);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.ZPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateZ;
                var curve = SetAnimationCurve(boneNode.ZPOS, (uint)FSKA.TrackType.ZPOS);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }

            return(boneAnim);
        }
示例#6
0
        private void DrawImage(Graphics g, Layout.ImageNode node)
        {
            if (!node.Visible)
            {
                return;
            }

            Vector4 offset = Vector4.Zero;
            Color   color  = Color.White;

            if (currentAnimType.Count > 0)
            {
                var animNode = GetAnimationNode(animation.LayoutNodes, currentAnimType.Peek());
                if (animNode != null)
                {
                    var curveNode = animNode.Children.FirstOrDefault(x => x is Animation.CurveNode);
                    var keyNodes  = curveNode.Children.Where(x => x is Animation.KeyNode).Cast <Animation.KeyNode>();

                    float maxTime   = keyNodes.Max(x => x.Time);
                    float localTime = (animValue % maxTime);

                    Animation.KeyNode last = keyNodes.FirstOrDefault(x => x.Time <= localTime);
                    Animation.KeyNode curr = keyNodes.FirstOrDefault(x => x.Time >= localTime);

                    if ((curveNode as Animation.CurveNode).Attribute == "pos")
                    {
                        offset = Vector4.Lerp(last.Value, curr.Value, localTime);
                    }
                    else if ((curveNode as Animation.CurveNode).Attribute == "color")
                    {
                        Vector4 tempResult = Vector4.Lerp(last.Value, curr.Value, localTime);
                        color = Color.FromArgb((int)tempResult.W, (int)tempResult.X, (int)tempResult.Y, (int)tempResult.Z);
                    }
                }
            }

            string textureName;

            if (styles.ImageLists.ContainsKey(node.Style))
            {
                var imageList = styles.ImageLists[node.Style];

                if (!currentNodeImageIndex.ContainsKey(node.Style))
                {
                    currentNodeImageIndex.Add(node.Style, (node.ImageNo + 1));
                }
                if (!currentNodeImageTimer.ContainsKey(node.Style))
                {
                    currentNodeImageTimer.Add(node.Style, 0.0f);
                }

                if ((currentNodeImageTimer[node.Style] += animValue) >= node.FlickTime)
                {
                    currentNodeImageTimer[node.Style] = 0.0f;

                    currentNodeImageIndex[node.Style]++;
                    if (currentNodeImageIndex[node.Style] > imageList.Count)
                    {
                        currentNodeImageIndex[node.Style] = (node.ImageNo + 1);
                    }
                }

                textureName = $"{node.Style}__xLIST{currentNodeImageIndex[node.Style]:D2}";
            }
            else
            {
                textureName = node.Style;
            }

            var texture = styles.Images.FirstOrDefault(x => x.Key == textureName);

            if (texture.Value != null)
            {
                g.TranslateTransform(offset.X, offset.Y);
                g.DrawImage(texture.Value, 0, 0);
            }
        }