Exemplo n.º 1
0
            public void Read(ResFile TargetWiiUBFRES, AnimationGroupNode ThisAnimation, ResNSW.ResFile b)
            {
                Console.WriteLine("Reading Skeleton Animations ...");

                if (b != null)
                {
                    TreeNode SkeletonAnimation = new TreeNode()
                    {
                        Text = "Skeleton Animations"
                    };

                    ThisAnimation.Nodes.Add(SkeletonAnimation);

                    TreeNode dummy = new TreeNode()
                    {
                        Text = "Animation Set"
                    };

                    int i = 0;
                    foreach (ResNSW.SkeletalAnim ska in b.SkeletalAnims)
                    {
                        if (i == 0)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "0 - 100"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 100)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "100 - 200"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 200)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "200 - 300"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 300)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "300 - 400"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 400)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "400 - 500"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 500)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "500 - 600"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 600)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "600 - 700"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 700)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "700 - 800"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 800)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "800 - 900"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 900)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "900 - 1000"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 1000)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "1000+"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }

                        Animation a = new Animation(ska.Name);
                        SkeletonAnimations.Add(a);

                        a.FrameCount = ska.FrameCount;

                        if (i >= 0 && i < 100)
                        {
                            SkeletonAnimation.Nodes[0].Nodes.Add(a);
                        }
                        if (i >= 100 && i < 200)
                        {
                            SkeletonAnimation.Nodes[1].Nodes.Add(a);
                        }
                        if (i >= 200 && i < 300)
                        {
                            SkeletonAnimation.Nodes[2].Nodes.Add(a);
                        }
                        if (i >= 300 && i < 400)
                        {
                            SkeletonAnimation.Nodes[3].Nodes.Add(a);
                        }
                        if (i >= 400 && i < 500)
                        {
                            SkeletonAnimation.Nodes[4].Nodes.Add(a);
                        }
                        if (i >= 500 && i < 600)
                        {
                            SkeletonAnimation.Nodes[5].Nodes.Add(a);
                        }
                        if (i >= 600 && i < 700)
                        {
                            SkeletonAnimation.Nodes[6].Nodes.Add(a);
                        }
                        if (i >= 700 && i < 800)
                        {
                            SkeletonAnimation.Nodes[7].Nodes.Add(a);
                        }
                        if (i >= 800 && i < 900)
                        {
                            SkeletonAnimation.Nodes[8].Nodes.Add(a);
                        }
                        if (i >= 900 && i < 1000)
                        {
                            SkeletonAnimation.Nodes[9].Nodes.Add(a);
                        }

                        i++;
                        try
                        {
                            foreach (ResNSW.BoneAnim bn in ska.BoneAnims)
                            {
                                FSKANode bonean = new FSKANode(bn);

                                Animation.KeyNode bone = new Animation.KeyNode("");
                                a.Bones.Add(bone);
                                if (ska.FlagsRotate == ResNSW.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++)
                                {
                                    //Set base/start values for bones.
                                    //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these
                                    if (Frame == 0)
                                    {
                                        if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Scale))
                                        {
                                            bone.XSCA.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.X
                                            });
                                            bone.YSCA.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Y
                                            });
                                            bone.ZSCA.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Z
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Rotate))
                                        {
                                            bone.XROT.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.X
                                            });
                                            bone.YROT.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Y
                                            });
                                            bone.ZROT.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Z
                                            });
                                            bone.WROT.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.W
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Translate))
                                        {
                                            bone.XPOS.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.X
                                            });
                                            bone.YPOS.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Y
                                            });
                                            bone.ZPOS.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Z
                                            });
                                        }
                                    }
                                    foreach (FSKATrack track in bonean.tracks)
                                    {
                                        Animation.KeyFrame frame = new Animation.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;
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    TreeNode SkeletonAnimation = new TreeNode()
                    {
                        Text = "Skeleton Animations"
                    };

                    ThisAnimation.Nodes.Add(SkeletonAnimation);

                    TreeNode dummy = new TreeNode()
                    {
                        Text = "Animation Set"
                    };

                    int i = 0;
                    foreach (SkeletalAnim ska in TargetWiiUBFRES.SkeletalAnims.Values)
                    {
                        if (i == 0)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "0 - 100"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 100)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "100 - 200"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 200)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "200 - 300"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 300)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "300 - 400"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 400)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "400 - 500"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 500)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "500 - 600"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 600)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "600 - 700"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 700)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "700 - 800"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 800)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "800 - 900"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 900)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "900 - 1000"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 1000)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "1000+"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }

                        Animation a = new Animation(ska.Name);
                        SkeletonAnimations.Add(a);

                        if (i >= 0 && i < 100)
                        {
                            SkeletonAnimation.Nodes[0].Nodes.Add(a);
                        }
                        if (i >= 100 && i < 200)
                        {
                            SkeletonAnimation.Nodes[1].Nodes.Add(a);
                        }
                        if (i >= 200 && i < 300)
                        {
                            SkeletonAnimation.Nodes[2].Nodes.Add(a);
                        }
                        if (i >= 300 && i < 400)
                        {
                            SkeletonAnimation.Nodes[3].Nodes.Add(a);
                        }
                        if (i >= 400 && i < 500)
                        {
                            SkeletonAnimation.Nodes[4].Nodes.Add(a);
                        }
                        if (i >= 500 && i < 600)
                        {
                            SkeletonAnimation.Nodes[5].Nodes.Add(a);
                        }
                        if (i >= 600 && i < 700)
                        {
                            SkeletonAnimation.Nodes[6].Nodes.Add(a);
                        }
                        if (i >= 700 && i < 800)
                        {
                            SkeletonAnimation.Nodes[7].Nodes.Add(a);
                        }
                        if (i >= 800 && i < 900)
                        {
                            SkeletonAnimation.Nodes[8].Nodes.Add(a);
                        }
                        if (i >= 900 && i < 1000)
                        {
                            SkeletonAnimation.Nodes[9].Nodes.Add(a);
                        }


                        a.FrameCount = ska.FrameCount;
                        i++;
                        try
                        {
                            foreach (BoneAnim bn in ska.BoneAnims)
                            {
                                FSKANodeWiiU bonean = new FSKANodeWiiU(bn);

                                Animation.KeyNode bone = new Animation.KeyNode("");
                                a.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++)
                                {
                                    //Set base/start values for bones.
                                    //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these
                                    if (Frame == 0)
                                    {
                                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Scale))
                                        {
                                            bone.XSCA.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.X
                                            });
                                            bone.YSCA.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Y
                                            });
                                            bone.ZSCA.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Z
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Rotate))
                                        {
                                            bone.XROT.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.X
                                            });
                                            bone.YROT.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Y
                                            });
                                            bone.ZROT.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Z
                                            });
                                            bone.WROT.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.W
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Translate))
                                        {
                                            bone.XPOS.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.X
                                            });
                                            bone.YPOS.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Y
                                            });
                                            bone.ZPOS.Keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Z
                                            });
                                        }
                                    }
                                    foreach (FSKATrack track in bonean.tracks)
                                    {
                                        Animation.KeyFrame frame = new Animation.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;
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }


                Console.WriteLine("Saving " + SkeletonAnimations.Count + " anims");

                foreach (var anim in SkeletonAnimations)
                {
                    anim.SaveAsExpeditedAnim();
                }
            }
Exemplo n.º 2
0
        public static AnimationGroupNode Read(string filename, ResFile TargetWiiUBFRES)
        {
            FileData f = new FileData(filename);

            f.seek(0);

            f.Endian = Endianness.Little;

            Console.WriteLine("Reading Animations ...");

            f.seek(4);                     // magic check
            int SwitchCheck = f.readInt(); //Switch version only has padded magic

            f.skip(4);
            if (SwitchCheck == 0x20202020)
            {
                //    SwitchAnim2WiiU(path); //Hacky auto convert switch anims to wii u


                ResNSW.ResFile b = new ResNSW.ResFile(filename);

                AnimationGroupNode ThisAnimation = new AnimationGroupNode()
                {
                    Text = "Skeleton Animations"
                };

                TreeNode dummy = new TreeNode()
                {
                    Text = "Animation Set"
                };

                int i = 0;
                foreach (ResNSW.SkeletalAnim ska in b.SkeletalAnims)
                {
                    Animation a = new Animation(ska.Name);
                    ThisAnimation.Nodes.Add(a);

                    a.FrameCount = ska.FrameCount;
                    i++;
                    try
                    {
                        foreach (Syroot.NintenTools.NSW.Bfres.BoneAnim bn in ska.BoneAnims)
                        {
                            FSKANode bonean = new FSKANode(bn);

                            Animation.KeyNode bone = new Animation.KeyNode("");
                            a.Bones.Add(bone);
                            if (ska.FlagsRotate == ResNSW.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++)
                            {
                                //Set base/start values for bones.
                                //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these
                                if (Frame == 0 && Runtime.HasNoAnimationBaseValues == false)
                                {
                                    bone.XSCA.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = 1
                                    });
                                    bone.YSCA.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = 1
                                    });
                                    bone.ZSCA.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = 1
                                    });
                                    bone.XROT.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.rot.X
                                    });
                                    bone.YROT.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.rot.Y
                                    });
                                    bone.ZROT.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.rot.Z
                                    });
                                    bone.XPOS.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.pos.X
                                    });
                                    bone.YPOS.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.pos.Y
                                    });
                                    bone.ZPOS.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.pos.Z
                                    });
                                }
                                foreach (FSKATrack track in bonean.tracks)
                                {
                                    Animation.KeyFrame frame = new Animation.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;
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }
                return(ThisAnimation);
            }
            else
            {
                f.eof();

                TargetWiiUBFRES = new ResFile(filename);

                ThisAnimation = new AnimationGroupNode()
                {
                    Text = "Skeleton Animations"
                };

                TreeNode dummy = new TreeNode()
                {
                    Text = "Animation Set"
                };

                int i = 0;
                foreach (SkeletalAnim ska in TargetWiiUBFRES.SkeletalAnims.Values)
                {
                    Animation a = new Animation(ska.Name);
                    ThisAnimation.Nodes.Add(a);

                    a.FrameCount = ska.FrameCount;
                    i++;
                    try
                    {
                        foreach (BoneAnim bn in ska.BoneAnims)
                        {
                            FSKANodeWiiU bonean = new FSKANodeWiiU(bn);

                            Animation.KeyNode bone = new Animation.KeyNode("");
                            a.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++)
                            {
                                //Set base/start values for bones.
                                //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these
                                if (Frame == 0 && Runtime.HasNoAnimationBaseValues == false)
                                {
                                    bone.XSCA.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.sca.X
                                    });
                                    bone.YSCA.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.sca.Y
                                    });
                                    bone.ZSCA.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.sca.Z
                                    });
                                    bone.XROT.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.rot.X
                                    });
                                    bone.YROT.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.rot.Y
                                    });
                                    bone.ZROT.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.rot.Z
                                    });
                                    bone.XPOS.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.pos.X
                                    });
                                    bone.YPOS.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.pos.Y
                                    });
                                    bone.ZPOS.Keys.Add(new Animation.KeyFrame()
                                    {
                                        Frame = 0, Value = bonean.pos.Z
                                    });
                                }
                                foreach (FSKATrack track in bonean.tracks)
                                {
                                    Animation.KeyFrame frame = new Animation.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;
                                    }
                                }
                            }
                        }
                    }
                    catch
                    {
                    }
                }
                return(ThisAnimation);
            }
        }
Exemplo n.º 3
0
            public void Read(ResFile targetWiiUbfres, AnimationGroupNode thisAnimation, ResNSW.ResFile b)
            {
                Console.WriteLine("Reading Skeleton Animations ...");

                if (b != null)
                {
                    TreeNode skeletonAnimationNode = new TreeNode {
                        Text = "Skeleton Animations"
                    };

                    thisAnimation.Nodes.Add(skeletonAnimationNode);

                    // Split animation nodes into groups so they can all fit inside the view.
                    // Make sure to add an additional set if the animations can't be divided evenly.
                    int setCount = b.SkeletalAnims.Count / setSize;
                    if (b.SkeletalAnims.Count % setSize != 0)
                    {
                        setCount += 1;
                    }

                    for (int i = 0; i < setCount; i++)
                    {
                        int start = i * setSize;
                        int end   = start + setSize - 1;
                        skeletonAnimationNode.Nodes.Add(new TreeNode {
                            Text = $"Animation Set {start} - {end}"
                        });
                    }

                    for (int i = 0; i < b.SkeletalAnims.Count; i++)
                    {
                        var ska      = b.SkeletalAnims[i];
                        int setIndex = i / setSize;

                        Animation a = new Animation(ska.Name);
                        SkeletonAnimations.Add(a);

                        a.frameCount = ska.FrameCount;

                        skeletonAnimationNode.Nodes[setIndex].Nodes.Add(a);

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

                                Animation.KeyNode bone = new Animation.KeyNode("");
                                a.bones.Add(bone);
                                if (ska.FlagsRotate == ResNSW.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++)
                                {
                                    //Set base/start values for bones.
                                    //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these
                                    if (frame == 0)
                                    {
                                        if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Scale))
                                        {
                                            bone.xsca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.X
                                            });
                                            bone.ysca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Y
                                            });
                                            bone.zsca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Z
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Rotate))
                                        {
                                            bone.xrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.X
                                            });
                                            bone.yrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Y
                                            });
                                            bone.zrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Z
                                            });
                                            bone.wrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.W
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(ResNSW.BoneAnimFlagsBase.Translate))
                                        {
                                            bone.xpos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.X
                                            });
                                            bone.ypos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Y
                                            });
                                            bone.zpos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Z
                                            });
                                        }
                                    }
                                    foreach (FSKATrack track in bonean.tracks)
                                    {
                                        Animation.KeyFrame keyFrame = new Animation.KeyFrame();
                                        keyFrame.interType = Animation.InterpolationType.Hermite;
                                        keyFrame.Frame     = frame;

                                        FSKAKey left  = track.GetLeft(frame);
                                        FSKAKey right = track.GetRight(frame);

                                        // interpolate the value and apply
                                        float value = Animation.Hermite(frame, left.frame, right.frame, 0, 0, left.unk1, right.unk1);
                                        switch (track.flag)
                                        {
                                        case (int)TrackType.XPOS: keyFrame.Value = value; bone.xpos.keys.Add(keyFrame); break;

                                        case (int)TrackType.YPOS: keyFrame.Value = value; bone.ypos.keys.Add(keyFrame); break;

                                        case (int)TrackType.ZPOS: keyFrame.Value = value; bone.zpos.keys.Add(keyFrame); break;

                                        case (int)TrackType.XROT: keyFrame.Value = value; bone.xrot.keys.Add(keyFrame); break;

                                        case (int)TrackType.YROT: keyFrame.Value = value; bone.yrot.keys.Add(keyFrame); break;

                                        case (int)TrackType.ZROT: keyFrame.Value = value; bone.zrot.keys.Add(keyFrame); break;

                                        case (int)TrackType.XSCA: keyFrame.Value = value; bone.xsca.keys.Add(keyFrame); break;

                                        case (int)TrackType.YSCA: keyFrame.Value = value; bone.ysca.keys.Add(keyFrame); break;

                                        case (int)TrackType.ZSCA: keyFrame.Value = value; bone.zsca.keys.Add(keyFrame); break;
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    TreeNode SkeletonAnimation = new TreeNode()
                    {
                        Text = "Skeleton Animations"
                    };

                    thisAnimation.Nodes.Add(SkeletonAnimation);

                    TreeNode dummy = new TreeNode()
                    {
                        Text = "Animation Set"
                    };

                    int i = 0;
                    foreach (SkeletalAnim ska in targetWiiUbfres.SkeletalAnims.Values)
                    {
                        if (i == 0)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "0 - 100"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 100)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "100 - 200"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 200)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "200 - 300"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 300)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "300 - 400"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 400)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "400 - 500"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 500)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "500 - 600"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 600)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "600 - 700"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 700)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "700 - 800"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 800)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "800 - 900"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 900)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "900 - 1000"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }
                        if (i == 1000)
                        {
                            dummy = new TreeNode()
                            {
                                Text = "Animation Set " + "1000+"
                            };
                            SkeletonAnimation.Nodes.Add(dummy);
                        }

                        Animation a = new Animation(ska.Name);

                        if (i >= 0 && i < 100)
                        {
                            SkeletonAnimation.Nodes[0].Nodes.Add(a);
                        }
                        if (i >= 100 && i < 200)
                        {
                            SkeletonAnimation.Nodes[1].Nodes.Add(a);
                        }
                        if (i >= 200 && i < 300)
                        {
                            SkeletonAnimation.Nodes[2].Nodes.Add(a);
                        }
                        if (i >= 300 && i < 400)
                        {
                            SkeletonAnimation.Nodes[3].Nodes.Add(a);
                        }
                        if (i >= 400 && i < 500)
                        {
                            SkeletonAnimation.Nodes[4].Nodes.Add(a);
                        }
                        if (i >= 500 && i < 600)
                        {
                            SkeletonAnimation.Nodes[5].Nodes.Add(a);
                        }
                        if (i >= 600 && i < 700)
                        {
                            SkeletonAnimation.Nodes[6].Nodes.Add(a);
                        }
                        if (i >= 700 && i < 800)
                        {
                            SkeletonAnimation.Nodes[7].Nodes.Add(a);
                        }
                        if (i >= 800 && i < 900)
                        {
                            SkeletonAnimation.Nodes[8].Nodes.Add(a);
                        }
                        if (i >= 900 && i < 1000)
                        {
                            SkeletonAnimation.Nodes[9].Nodes.Add(a);
                        }


                        a.frameCount = ska.FrameCount;
                        i++;
                        try
                        {
                            foreach (BoneAnim bn in ska.BoneAnims)
                            {
                                FSKANodeWiiU bonean = new FSKANodeWiiU(bn);

                                Animation.KeyNode bone = new Animation.KeyNode("");
                                a.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++)
                                {
                                    //Set base/start values for bones.
                                    //Note. BOTW doesn't use base values as it uses havok engine. Need to add option to disable these
                                    if (Frame == 0)
                                    {
                                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Scale))
                                        {
                                            bone.xsca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.X
                                            });
                                            bone.ysca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Y
                                            });
                                            bone.zsca.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.sca.Z
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Rotate))
                                        {
                                            bone.xrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.X
                                            });
                                            bone.yrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Y
                                            });
                                            bone.zrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.Z
                                            });
                                            bone.wrot.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.rot.W
                                            });
                                        }
                                        if (bn.FlagsBase.HasFlag(BoneAnimFlagsBase.Translate))
                                        {
                                            bone.xpos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.X
                                            });
                                            bone.ypos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Y
                                            });
                                            bone.zpos.keys.Add(new Animation.KeyFrame()
                                            {
                                                Frame = 0, Value = bonean.pos.Z
                                            });
                                        }
                                    }
                                    foreach (FSKATrack track in bonean.tracks)
                                    {
                                        Animation.KeyFrame frame = new Animation.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;
                                        }
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
            }