示例#1
0
        private void ReadVisibilityAnimations(Anim animFile, AnimGroup animGroup, SBAnimation animation)
        {
            var decoder = new SsbhAnimTrackDecoder(animFile);

            foreach (AnimNode animNode in animGroup.Nodes)
            {
                SBVisibilityAnimation visAnim = new SBVisibilityAnimation()
                {
                    MeshName = animNode.Name
                };
                foreach (AnimTrack track in animNode.Tracks)
                {
                    if (track.Name.Equals("Visibility"))
                    {
                        object[] Visibility = decoder.ReadTrack(track);

                        for (int i = 0; i < Visibility.Length; i++)
                        {
                            visAnim.Visibility.AddKey(i, (bool)Visibility[i]);
                        }
                    }
                }
                animation.VisibilityNodes.Add(visAnim);
            }
        }
示例#2
0
        public SBAnimation ImportSBAnimation(string FileName, SBSkeleton skeleton)
        {
            SBAnimation anim = new SBAnimation();

            using (StreamReader r = new StreamReader(new FileStream(FileName, FileMode.Open)))
            {
                if (r.ReadLine() != "#SBAnimation Version 1")
                {
                    return(anim);
                }

                while (!r.EndOfStream)
                {
                    var line = r.ReadLine();
                    var args = line.Trim().Split(' ');

                    switch (args[0])
                    {
                    case "comment":
                        break;

                    case "FrameCount":
                        anim.FrameCount = int.Parse(args[1]);
                        break;

                    case "visibility":
                        SBVisibilityAnimation visAnim = new SBVisibilityAnimation();
                        visAnim.MeshName = args[1];
                        var visLien = r.ReadLine();
                        if (visLien == "{")
                        {
                            visLien = r.ReadLine();
                            while (!r.EndOfStream && visLien != "}")
                            {
                                visLien = visLien.Replace(" ", "");
                                var frame = visLien.Substring(0, visLien.IndexOf(":")).Trim();
                                var value = visLien.Substring(visLien.IndexOf(":") + 1, visLien.Length - (visLien.IndexOf(":") + 1)).Trim();
                                visAnim.Visibility.AddKey(float.Parse(frame), bool.Parse(value));
                                visLien = r.ReadLine();
                            }
                        }
                        anim.VisibilityNodes.Add(visAnim);
                        break;

                    case "bone":
                        if (args[1].Contains(".anim"))
                        {
                            IO_MayaANIM manim = new IO_MayaANIM();
                            var         bones = manim.ImportSBAnimation(Path.GetDirectoryName(FileName) + "/" + args[1], skeleton);
                            anim.TransformNodes.AddRange(bones.TransformNodes);
                        }
                        break;

                    case "material":
                        SBMaterialAnimation matAnim = new SBMaterialAnimation();
                        matAnim.MaterialName  = args[1];
                        matAnim.AttributeName = args[2];
                        var matLien = r.ReadLine();
                        if (matLien == "{")
                        {
                            matLien = r.ReadLine();
                            while (!r.EndOfStream && matLien != "}")
                            {
                                matLien = matLien.Replace(" ", "");
                                var frame = matLien.Substring(0, matLien.IndexOf(":")).Trim();
                                var value = matLien.Substring(matLien.IndexOf(":") + 1, matLien.Length - (matLien.IndexOf(":") + 1)).Trim();

                                var vector = value.Replace(")", "").Replace("(", "").Split(',');
                                if (vector.Length != 4)
                                {
                                    continue;
                                }

                                matAnim.Keys.AddKey(float.Parse(frame), new Vector4(float.Parse(vector[0]), float.Parse(vector[1]), float.Parse(vector[2]), float.Parse(vector[3])));
                                matLien = r.ReadLine();
                            }
                        }
                        anim.MaterialNodes.Add(matAnim);
                        break;
                    }
                }
            }

            return(anim);
        }