コード例 #1
0
        private void listAnims_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listAnims.SelectedItems.Count > 0)
            {
                _selectedAnim = listAnims.SelectedItems[0].Tag as CHR0Node;
            }
            else
            {
                _selectedAnim = null;
            }

            if (_selectedAnim == null)
            {
                btnInsert.Enabled = btnDelete.Enabled = btnClear.Enabled = false;
            }
            else
            {
                btnInsert.Enabled = btnDelete.Enabled = btnClear.Enabled = true;
            }

            _copyAllIndex = -1;

            if (SelectedAnimationChanged != null)
            {
                SelectedAnimationChanged(this, null);
            }
        }
コード例 #2
0
        private static SkeletalAnim Chr02Fska(CHR0Node chr0)
        {
            SkeletalAnim fska = new SkeletalAnim();

            fska.FrameCount   = chr0.FrameCount;
            fska.Name         = chr0.Name;
            fska.Path         = chr0.OriginalPath;
            fska.UserDatas    = new List <Syroot.NintenTools.NSW.Bfres.UserData>();
            fska.UserDataDict = new ResDict();

            //Set flags
            if (chr0.Loop)
            {
                fska.FlagsAnimSettings |= SkeletalAnimFlags.Looping;
            }
            fska.FlagsRotate = SkeletalAnimFlagsRotate.EulerXYZ;
            fska.FlagsScale  = SkeletalAnimFlagsScale.Maya;

            //Set bone anims and then calculate data after
            foreach (var entry in chr0.Children)
            {
                fska.BoneAnims.Add(Chr0Entry2BoneAnim((CHR0EntryNode)entry));
            }

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

            return(fska);
        }
コード例 #3
0
ファイル: Undo.cs プロジェクト: aidanjohnys/BrawlCrate
        private void ApplyVertexState(VertexState state)
        {
            IModel   model = TargetModel;
            CHR0Node n     = _chr0;
            int      frame = CurrentFrame;

            if (TargetModel != state._targetModel)
            {
                _resetCamera = false;
                TargetModel  = state._targetModel;
            }

            SelectedCHR0 = state._chr0;
            CurrentFrame = state._animFrame;

            for (int i = 0; i < state._vertices.Count; i++)
            {
                state._vertices[i].WeightedPosition = state._weightedPositions[i];
            }

            SetSelectedVertices(state._vertices);

            _vertexLoc = null;

            if (TargetModel != model)
            {
                _resetCamera = false;
                TargetModel  = model;
            }

            SelectedCHR0 = n;
            CurrentFrame = frame;

            UpdateModel();
        }
コード例 #4
0
        private bool UpdateReferences()
        {
            listAnims.BeginUpdate();
            listAnims.Items.Clear();

            if (_targetModel != null)
            {
                LoadAnims(_targetModel.RootNode);
            }

            int count = listAnims.Items.Count;

            if (_externalNode != null)
            {
                LoadAnims(_externalNode.RootNode);
            }

            if ((_selectedAnim != null) && (listAnims.SelectedItems.Count == 0))
            {
                _selectedAnim = null;
                if (SelectedAnimationChanged != null)
                {
                    SelectedAnimationChanged(this, null);
                }
            }

            listAnims.EndUpdate();

            return(count != listAnims.Items.Count);
        }
コード例 #5
0
        private static void Chr0Convert(string[] args)
        {
            string openbfres = "";

            if (args.Length > 0)
            {
                openbfres = args[0];
            }
            else
            {
                openbfres = "dv_Kaigan_Original.bfres";
            }

            Console.WriteLine($"Loading bfres {openbfres}");
            ResFile resFile = new ResFile(openbfres);

            resFile.Textures[0].Export("dummy.bftex", resFile);

            Chr02Fska(CHR0Node.FromFile("walk.chr0"));

            Console.WriteLine($"Saving bfres");
            resFile.Save($"{openbfres}NEW.bfres");
            Console.WriteLine($"File Saved!");
            Console.Read();
        }
コード例 #6
0
        private void ReloadIcons()
        {
            if (miscdata80 == null)
            {
                return;
            }
            CHR0Node chr0 = miscdata80.FindChild("AnmChr(NW4R)/MenSelmapPos_TopN__" + (MyMusic ? "1" : "0"), false) as CHR0Node;

            if (chr0 == null)
            {
                return;
            }

            icons = new Tuple <Image, RectangleF> [_numIcons + 1];

            CHR0EntryNode entry  = chr0.FindChild("MenSelmapPos_TopN", false) as CHR0EntryNode;
            Vector3       offset = entry.GetAnimFrame(_numIcons + OFFSET).Translation;

            for (int i = 1; i <= _numIcons; i++)
            {
                entry = chr0.FindChild("pos" + i.ToString("D2"), false) as CHR0EntryNode;
                CHRAnimationFrame frame = entry.GetAnimFrame(_numIcons + OFFSET, true);
                float             x     = (BRAWLWIDTH / 2 + frame.Translation._x + offset._x) / BRAWLWIDTH;
                float             y     = (BRAWLHEIGHT / 2 - frame.Translation._y - offset._y) / BRAWLHEIGHT;
                float             w     = 6.4f * (frame.Scale._x) / BRAWLWIDTH;
                float             h     = 5.6f * (frame.Scale._y) / BRAWLHEIGHT;
                RectangleF        r     = new RectangleF(x, y, w, h);

                TextureContainer tc = new TextureContainer(miscdata80,
                                                           IconOrder != null && i <= IconOrder.Length ? IconOrder[i - 1] : 100);
                if (tc.icon.tex0 == null)
                {
                    continue;
                }
                Image image = tc.icon.tex0.GetImage(0);

                icons[i] = new Tuple <Image, RectangleF>(image, r);
            }

            var nexttex0 = miscdata80.FindChild("Textures(NW4R)/MenSelmapIcon_Change.1", false) as TEX0Node;

            if (nexttex0 != null)
            {
                float NEXTOFFSET = 10.8f;
                entry = chr0.FindChild("pos" + (_numIcons + 1).ToString("D2"), false) as CHR0EntryNode;
                CHRAnimationFrame frame2 = entry.GetAnimFrame(_numIcons + OFFSET, true);
                float             x2     = (BRAWLWIDTH / 2 + frame2.Translation._x - NEXTOFFSET) / BRAWLWIDTH;
                float             y2     = (BRAWLHEIGHT / 2 - frame2.Translation._y) / BRAWLHEIGHT;
                float             w2     = 14.4f * (frame2.Scale._x) / BRAWLWIDTH;
                float             h2     = 4.8f * (frame2.Scale._y) / BRAWLHEIGHT;
                RectangleF        r2     = new RectangleF(x2, y2, w2, h2);
                Image             image2 = nexttex0.GetImage(0);
                icons[0] = new Tuple <Image, RectangleF>(image2, r2);                //pos00 is not used anyway, so let's overwrite it
            }

            this.Invalidate();
        }
コード例 #7
0
        public void NewChr()
        {
            CHR0Node    node = ((BRESNode)_resource).CreateResource <CHR0Node>("NewCHR");
            BaseWrapper res  = this.FindResource(node, true);

            res = res.FindResource(node, false);
            res.EnsureVisible();
            res.TreeView.SelectedNode = res;
        }
コード例 #8
0
        public void Loop(int timesToLoop)
        {
            CHR0Node temp = ((CHR0Node)_resource);

            ((CHR0Node)_resource).Append(temp, timesToLoop);
            BaseWrapper res = this.FindResource(_resource, false);

            res.EnsureVisible();
            res.TreeView.SelectedNode = res;
        }
コード例 #9
0
        public static CHR0Node Convert(string input)
        {
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(BoneAnimation));
            Stream        inputFile = new FileStream(input, FileMode.Open, FileAccess.Read);
            BoneAnimation data      = (BoneAnimation)serializer.ReadObject(inputFile);

            CHR0Node node = data.ToCHR0Node();

            node.Name = Path.GetFileNameWithoutExtension(input);
            return(node);
        }
コード例 #10
0
        public static void Serialize(CHR0Node node, bool bake, string output)
        {
            using (StreamWriter file = new StreamWriter(output))
            {
                file.WriteLine("animVersion 1.1;");
                file.WriteLine("mayaVersion 2014 x64;");
                file.WriteLine("timeUnit ntsc;");
                file.WriteLine("linearUnit cm;");
                file.WriteLine("angularUnit deg;");
                file.WriteLine("startTime 1;");
                file.WriteLine(String.Format("endTime {0};", node.FrameCount));
                foreach (CHR0EntryNode e in node.Children)
                {
                    KeyframeCollection c = e.Keyframes;
                    for (int index = 0; index < 9; index++)
                    {
                        KeyFrameMode m = (KeyFrameMode)(index + 0x10);

                        if (c[m] <= 0)
                        {
                            continue;
                        }

                        file.WriteLine(String.Format("anim {0}.{0}{1} {0}{1} {2} {3} {4} {5}", types[index / 3], axes[index % 3], e.Name, e.Index, index / 3, index % 3));
                        file.WriteLine("animData {");
                        file.WriteLine(" input time;");
                        file.WriteLine(String.Format(" output {0};", index > 2 && index < 6 ? "angular" : "linear"));
                        file.WriteLine(" weighted 1;");
                        file.WriteLine(" preInfinity constant;");
                        file.WriteLine(" postInfinity constant;");
                        file.WriteLine(" keys {");
                        for (KeyframeEntry entry = c._keyRoots[index]._next; (entry != c._keyRoots[index]); entry = entry._next)
                        {
                            float angle = (float)Math.Atan(entry._tangent) * Maths._rad2degf;
                            file.WriteLine(String.Format(" {0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10};",
                                                         entry._index + 1,
                                                         entry._value.ToString(CultureInfo.InvariantCulture.NumberFormat),
                                                         "fixed",
                                                         "fixed",
                                                         "1",
                                                         "1",
                                                         "0",
                                                         angle.ToString(CultureInfo.InvariantCulture.NumberFormat),
                                                         (Math.Abs(entry._tangent) + 1).ToString(CultureInfo.InvariantCulture.NumberFormat),
                                                         angle.ToString(CultureInfo.InvariantCulture.NumberFormat),
                                                         (Math.Abs(entry._tangent) + 1).ToString(CultureInfo.InvariantCulture.NumberFormat)));
                        }
                        file.WriteLine(" }");
                        file.WriteLine("}");
                    }
                }
            }
        }
コード例 #11
0
        public void ImportChr()
        {
            if (Program.OpenFile(FileFilters.CHR0Import, out string path) > 0)
            {
                CHR0Node node = CHR0Node.FromFile(path);
                ((BRRESNode)_resource).GetOrCreateFolder <CHR0Node>().AddChild(node);

                BaseWrapper w = FindResource(node, true);
                w.EnsureVisible();
                w.TreeView.SelectedNode = w;
            }
        }
コード例 #12
0
        public void ImportChr()
        {
            string path;

            if (Program.OpenFile(ExportFilters.CHR0, out path) > 0)
            {
                CHR0Node node = NodeFactory.FromFile(null, path) as CHR0Node;
                ((BRESNode)_resource).GetOrCreateFolder <CHR0Node>().AddChild(node);

                BaseWrapper w = this.FindResource(node, true);
                w.EnsureVisible();
                w.TreeView.SelectedNode = w;
            }
        }
コード例 #13
0
        public void AddToNode(CHR0Node parentNode)
        {
            CHR0EntryNode entryNode = new CHR0EntryNode();

            parentNode.AddChild(entryNode);
            entryNode.SetSize(parentNode.FrameCount, parentNode.Loop);
            entryNode.Name = Name;

            foreach (Keyframe keyframe in Keyframes)
            {
                keyframe.AddToNode(entryNode);
            }

            //entryNode.Keyframes.Clean();
        }
コード例 #14
0
        public CHR0Node ToCHR0Node()
        {
            CHR0Node node = new CHR0Node();

            node.Version    = 4;
            node.FrameCount = FrameCount;
            node.Loop       = Loop;

            foreach (Bone bone in Bones)
            {
                bone.AddToNode(node);
            }

            return(node);
        }
コード例 #15
0
        public CHR0Node ToCHR0Node()
        {
            CHR0Node node = new CHR0Node
            {
                Version    = 4,
                FrameCount = FrameCount,
                Loop       = Loop
            };

            foreach (Bone bone in Bones)
            {
                bone.AddToNode(node);
            }

            return(node);
        }
コード例 #16
0
        public static void Fska2Chr0(SkeletalAnim fska, string FileName)
        {
            CHR0Node chr0 = new CHR0Node();

            chr0.FrameCount   = fska.FrameCount;
            chr0.Name         = fska.Name;
            chr0.OriginalPath = fska.Path;
            chr0.UserEntries  = new UserDataCollection();
            chr0.Loop         = fska.Loop;

            foreach (var entry in fska.BoneAnims)
            {
                BoneAnim2Chr0Entry(entry, chr0);
            }

            chr0.Export(FileName);
        }
コード例 #17
0
        public static void Serialize(CHR0Node node, string output)
        {
            MDL0Node model;

            OpenFileDialog dlgOpen = new OpenFileDialog
            {
                Filter = "MDL0 Model (*.mdl0)|*.mdl0",
                Title  = "Select the model this animation is for..."
            };

            if (dlgOpen.ShowDialog() != DialogResult.OK ||
                (model = (MDL0Node)NodeFactory.FromFile(null, dlgOpen.FileName)) == null)
            {
                return;
            }

            Serialize(node, output, model);
        }
コード例 #18
0
        public void Merge()
        {
            OpenFileDialog o = new OpenFileDialog
            {
                Filter = ImportFilter,
                Title  = "Please select an animation to merge with."
            };

            if (o.ShowDialog() == DialogResult.OK)
            {
                CHR0Node external;
                if ((external = CHR0Node.FromFile(o.FileName)) != null)
                {
                    ((CHR0Node)_resource).MergeWith(external);
                }
            }

            BaseWrapper res = FindResource(_resource, false);

            res.EnsureVisible();
            res.TreeView.SelectedNode = res;
        }
コード例 #19
0
 private void pnlAnim_SelectedAnimationChanged(object sender, EventArgs e)
 {
     _selectedAnim = pnlAnim.SelectedAnimation; AnimChanged();
 }
コード例 #20
0
        public static CHR0Node Read(string input)
        {
            CHR0Node node = new CHR0Node {
                _name = Path.GetFileNameWithoutExtension(input)
            };

            using (StreamReader file = new StreamReader(input))
            {
                float  start = 0.0f;
                float  end   = 0.0f;
                string line;
                while (true)
                {
                    line = file.ReadLine();

                    if (line == null)
                    {
                        break;
                    }

                    int    i   = line.IndexOf(' ');
                    string tag = line.Substring(0, i);

                    if (tag == "anim")
                    {
                        break;
                    }

                    string val = line.Substring(i + 1, line.IndexOf(';') - i - 1);

                    switch (tag)
                    {
                    case "startTime":
                    case "startUnitless":
                        float.TryParse(val, out start);
                        break;

                    case "endTime":
                    case "endUnitless":
                        float.TryParse(val, out end);
                        break;

                    case "animVersion":
                    case "mayaVersion":
                    case "timeUnit":
                    case "linearUnit":
                    case "angularUnit":
                    default:
                        break;
                    }
                }

                int frameCount = (int)(end - start + 1.5f);
                node.FrameCount = frameCount;

                while (true)
                {
                    if (line == null)
                    {
                        break;
                    }

                    string[] anim = line.Split(' ');
                    if (anim.Length != 7)
                    {
                        while ((line = file.ReadLine()) != null && !line.StartsWith("anim "))
                        {
                            ;
                        }

                        continue;
                    }

                    string t    = anim[2];
                    string bone = anim[3];
                    int    mode = -1;
                    if (t.StartsWith("scale"))
                    {
                        if (t.EndsWith("X"))
                        {
                            mode = 0;
                        }
                        else if (t.EndsWith("Y"))
                        {
                            mode = 1;
                        }
                        else if (t.EndsWith("Z"))
                        {
                            mode = 2;
                        }
                    }
                    else if (t.StartsWith("rotate"))
                    {
                        if (t.EndsWith("X"))
                        {
                            mode = 3;
                        }
                        else if (t.EndsWith("Y"))
                        {
                            mode = 4;
                        }
                        else if (t.EndsWith("Z"))
                        {
                            mode = 5;
                        }
                    }
                    else if (t.StartsWith("translate"))
                    {
                        if (t.EndsWith("X"))
                        {
                            mode = 6;
                        }
                        else if (t.EndsWith("Y"))
                        {
                            mode = 7;
                        }
                        else if (t.EndsWith("Z"))
                        {
                            mode = 8;
                        }
                    }

                    if (mode == -1)
                    {
                        while ((line = file.ReadLine()) != null && !line.StartsWith("anim "))
                        {
                            ;
                        }

                        continue;
                    }

                    line = file.ReadLine();

                    if (line.StartsWith("animData"))
                    {
                        CHR0EntryNode e;

                        if ((e = node.FindChild(bone, false) as CHR0EntryNode) == null)
                        {
                            e = new CHR0EntryNode {
                                _name = bone
                            };
                            node.AddChild(e);
                        }

                        while (true)
                        {
                            line = file.ReadLine().TrimStart();
                            int i = line.IndexOf(' ');

                            if (i < 0)
                            {
                                break;
                            }

                            string tag = line.Substring(0, i);

                            if (tag == "keys")
                            {
                                List <KeyframeEntry> l = new List <KeyframeEntry>();
                                while (true)
                                {
                                    line = file.ReadLine().TrimStart();

                                    if (line == "}")
                                    {
                                        break;
                                    }

                                    string[] s = line.Split(' ');

                                    for (int si = 0; si < s.Length; si++)
                                    {
                                        s[si] = s[si].Trim('\n', ';', ' ');
                                    }

                                    float.TryParse(s[0], NumberStyles.Number, CultureInfo.InvariantCulture,
                                                   out float inVal);
                                    float.TryParse(s[1], NumberStyles.Number, CultureInfo.InvariantCulture,
                                                   out float outVal);

                                    float weight1 = 0;
                                    float weight2 = 0;

                                    float angle1 = 0;
                                    float angle2 = 0;

                                    bool firstFixed  = false;
                                    bool secondFixed = false;
                                    switch (s[2])
                                    {
                                    case "linear":
                                    case "spline":
                                    case "auto":
                                        break;

                                    case "fixed":
                                        firstFixed = true;
                                        float.TryParse(s[7], NumberStyles.Number, CultureInfo.InvariantCulture,
                                                       out angle1);
                                        float.TryParse(s[8], NumberStyles.Number, CultureInfo.InvariantCulture,
                                                       out weight1);
                                        break;
                                    }

                                    switch (s[3])
                                    {
                                    case "linear":
                                    case "spline":
                                    case "auto":
                                        break;

                                    case "fixed":
                                        secondFixed = true;
                                        if (firstFixed)
                                        {
                                            float.TryParse(s[9], NumberStyles.Number, CultureInfo.InvariantCulture,
                                                           out angle2);
                                            float.TryParse(s[10], NumberStyles.Number, CultureInfo.InvariantCulture,
                                                           out weight2);
                                        }
                                        else
                                        {
                                            float.TryParse(s[7], NumberStyles.Number, CultureInfo.InvariantCulture,
                                                           out angle2);
                                            float.TryParse(s[8], NumberStyles.Number, CultureInfo.InvariantCulture,
                                                           out weight2);
                                        }

                                        break;
                                    }

                                    bool anyFixed  = secondFixed || firstFixed;
                                    bool bothFixed = secondFixed && firstFixed;

                                    KeyframeEntry x = e.SetKeyframe(mode, (int)(inVal - 0.5f), outVal, true);
                                    if (!anyFixed)
                                    {
                                        l.Add(x);
                                    }
                                    else
                                    {
                                        if (bothFixed)
                                        {
                                            x._tangent = (float)Math.Tan((angle1 + angle2) / 2 * Maths._deg2radf) *
                                                         ((weight1 + weight2) / 2);
                                        }
                                        else if (firstFixed)
                                        {
                                            x._tangent = (float)Math.Tan(angle1 * Maths._deg2radf) * weight1;
                                        }
                                        else
                                        {
                                            x._tangent = (float)Math.Tan(angle2 * Maths._deg2radf) * weight2;
                                        }
                                    }
                                }

                                foreach (KeyframeEntry w in l)
                                {
                                    w.GenerateTangent();
                                }
                            }
                            else
                            {
                                int z = line.IndexOf(';') - i - 1;
                                if (z < 0)
                                {
                                    continue;
                                }

                                string val = line.Substring(i + 1, z);

                                switch (tag)
                                {
                                case "input":

                                    break;

                                case "output":

                                    break;

                                case "weighted":

                                    break;

                                case "inputUnit":

                                    break;

                                case "outputUnit":

                                    break;

                                case "preInfinity":
                                case "postInfinity":
                                default:
                                    break;
                                }
                            }
                        }
                    }

                    line = file.ReadLine();
                }
            }

            return(node);
        }
コード例 #21
0
        public static void Serialize(CHR0Node node, string output, MDL0Node model)
        {
            model.Populate();
            using (StreamWriter file = new StreamWriter(output))
            {
                file.WriteLine("animVersion 1.1;");
                file.WriteLine("mayaVersion 2015;");
                file.WriteLine("timeUnit ntscf;");
                file.WriteLine("linearUnit cm;");
                file.WriteLine("angularUnit deg;");
                file.WriteLine("startTime 0;");
                file.WriteLine($"endTime {node.FrameCount - 1};");
                foreach (MDL0BoneNode b in model.AllBones)
                {
                    CHR0EntryNode e = node.FindChild(b.Name, true) as CHR0EntryNode;
                    if (e == null)
                    {
                        file.WriteLine($"anim {b.Name} 0 {b.Children.Count} 0;");
                        continue;
                    }

                    KeyframeCollection c = e.Keyframes;
                    int counter          = 0;
                    for (int index = 0; index < 9; index++)
                    {
                        KeyframeArray array = c._keyArrays[index];

                        if (array._keyCount <= 0)
                        {
                            continue;
                        }

                        file.WriteLine("anim {0}.{0}{1} {0}{1} {2} {3} {4} {5};", types[index / 3], axes[index % 3],
                                       e.Name, 0, b.Children.Count, counter);
                        file.WriteLine("animData {");
                        file.WriteLine("  input time;");
                        file.WriteLine($"  output {(index > 2 && index < 6 ? "angular" : "linear")};");
                        file.WriteLine("  weighted 1;");
                        file.WriteLine("  preInfinity constant;");
                        file.WriteLine("  postInfinity constant;");
                        file.WriteLine("  keys {");
                        for (KeyframeEntry entry = array._keyRoot._next; entry != array._keyRoot; entry = entry._next)
                        {
                            float angle = (float)Math.Atan(entry._tangent) * Maths._rad2degf;
                            file.WriteLine("    {0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10};",
                                           entry._index,
                                           entry._value.ToString(CultureInfo.InvariantCulture.NumberFormat),
                                           "fixed",
                                           "fixed",
                                           "1",
                                           "1",
                                           "0",
                                           angle.ToString(CultureInfo.InvariantCulture.NumberFormat),
                                           "1",
                                           angle.ToString(CultureInfo.InvariantCulture.NumberFormat),
                                           "1");
                        }

                        file.WriteLine("  }");
                        file.WriteLine("}");
                        counter++;
                    }
                }
            }
        }
コード例 #22
0
        public static CHR0Node Convert(string input)
        {
            try
            {
                CHR0Node chr0 = new CHR0Node
                {
                    Name    = Path.GetFileNameWithoutExtension(input),
                    Loop    = false,
                    Version = 4
                };

                for (TextReader reader = new StreamReader(input); reader.Peek() != -1;)
                {
                    string line = reader.ReadLine();
                    if (line.CompareTo("Animation Keyframe Data Frames") == 0)
                    {
                        line = reader.ReadLine();

                        //Remove any non-digit characters
                        string justNumbers   = new string(line.Where(char.IsDigit).ToArray());
                        int    keyFrameCount = int.Parse(justNumbers);
                        chr0.FrameCount = keyFrameCount;

                        for (line = reader.ReadLine();
                             line != null && line.CompareTo("End Of Animation Data") != 0;
                             line = reader.ReadLine())
                        {
                            if (line.CompareTo("Keyframe Data") == 0)
                            {
                                CHR0EntryNode node = new CHR0EntryNode();
                                chr0.AddChild(node);
                                node.Name = reader.ReadLine();
                                node.SetSize(keyFrameCount, chr0.Loop);

                                Coords translation = new Coords();
                                Coords rotation    = new Coords();
                                Coords scale       = new Coords();

                                for (line = reader.ReadLine();
                                     line != null && line.CompareTo("End of Keyframe Data") != 0;
                                     line = reader.ReadLine())
                                {
                                    //Use goto to retry the loop without advancing the reader, when it returns from getCoords it will have the next line we need from it.
retry:
                                    if (line.CompareTo("Translation") == 0)
                                    {
                                        reader.ReadLine(); //Skip first blank line
                                        translation = getCoords(reader, out line);
                                        goto retry;
                                    }
                                    else if (line.CompareTo("Rotation") == 0)
                                    {
                                        reader.ReadLine(); //Skip first blank line
                                        rotation = getCoords(reader, out line);
                                        goto retry;
                                    }
                                    else if (line.CompareTo("Scale") == 0)
                                    {
                                        reader.ReadLine(); //Skip first blank line
                                        scale = getCoords(reader, out line);
                                        goto retry;
                                    }
                                    else if (line.CompareTo("End of Keyframe Data") == 0
                                             ) //If line equals this now it's time to break
                                    {
                                        break;
                                    }
                                }

                                //Add frames to node
                                for (int frameCount = 0;
                                     translation.highestCount > frameCount || rotation.highestCount > frameCount ||
                                     scale.highestCount > frameCount;
                                     frameCount++)
                                {
                                    if (translation.highestCount > frameCount)
                                    {
                                        if (translation.x.Count != 0 && frameCount < translation.x.Count)
                                        {
                                            node.SetKeyframe(6, frameCount, translation.x[frameCount]);
                                        }

                                        if (translation.y.Count != 0 && frameCount < translation.y.Count)
                                        {
                                            node.SetKeyframe(7, frameCount, translation.y[frameCount]);
                                        }

                                        if (translation.z.Count != 0 && frameCount < translation.z.Count)
                                        {
                                            node.SetKeyframe(8, frameCount, translation.z[frameCount]);
                                        }
                                    }

                                    if (rotation.highestCount > frameCount)
                                    {
                                        if (rotation.x.Count != 0 && frameCount < rotation.x.Count)
                                        {
                                            node.SetKeyframe(3, frameCount, rotation.x[frameCount]);
                                        }

                                        if (rotation.y.Count != 0 && frameCount < rotation.y.Count)
                                        {
                                            node.SetKeyframe(4, frameCount, rotation.y[frameCount]);
                                        }

                                        if (rotation.z.Count != 0 && frameCount < rotation.z.Count)
                                        {
                                            node.SetKeyframe(5, frameCount, rotation.z[frameCount]);
                                        }
                                    }

                                    if (scale.highestCount > frameCount)
                                    {
                                        if (scale.x.Count != 0 && frameCount < scale.x.Count)
                                        {
                                            node.SetKeyframe(0, frameCount, scale.x[frameCount]);
                                        }

                                        if (scale.y.Count != 0 && frameCount < scale.y.Count)
                                        {
                                            node.SetKeyframe(1, frameCount, scale.y[frameCount]);
                                        }

                                        if (scale.z.Count != 0 && frameCount < scale.z.Count)
                                        {
                                            node.SetKeyframe(2, frameCount, scale.z[frameCount]);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Not a valid CHR0 text file.");
                        return(null);
                    }
                }

                return(chr0);
            }
            catch (Exception e)
            {
                MessageBox.Show("There was a problem importing keyframes.\n\nError:\n" + e.ToString());
                return(null);
            }
        }
コード例 #23
0
        public static void Serialize(CHR0Node node, bool bake, string output)
        {
            MDL0Node model;

            OpenFileDialog dlgOpen = new OpenFileDialog();

            dlgOpen.Filter = "MDL0 Model (*.mdl0)|*.mdl0";
            dlgOpen.Title  = "Select the model this animation is for...";

            if (dlgOpen.ShowDialog() != DialogResult.OK || (model = (MDL0Node)NodeFactory.FromFile(null, dlgOpen.FileName)) == null)
            {
                return;
            }

            using (StreamWriter file = new StreamWriter(output))
            {
                file.WriteLine("animVersion 1.1;");
                file.WriteLine("mayaVersion 2015;");
                file.WriteLine("timeUnit ntsc;");
                file.WriteLine("linearUnit cm;");
                file.WriteLine("angularUnit deg;");
                file.WriteLine("startTime 1;");
                file.WriteLine(String.Format("endTime {0};", node.FrameCount));
                foreach (CHR0EntryNode e in node.Children)
                {
                    MDL0BoneNode bone = model.FindChild("Bones/" + e.Name, true) as MDL0BoneNode;
                    if (bone == null)
                    {
                        continue;
                    }

                    KeyframeCollection c = e.Keyframes;
                    for (int index = 0; index < 9; index++)
                    {
                        KeyframeArray array = c._keyArrays[index];

                        if (array._keyCount <= 0)
                        {
                            continue;
                        }

                        file.WriteLine(String.Format("anim {0}.{0}{1} {0}{1} {2} {3} {4} {5}", types[index / 3], axes[index % 3], e.Name, 0, bone.Children.Count, index < 6 ? (index + 3) : index - 6));
                        file.WriteLine("animData {");
                        file.WriteLine("  input time;");
                        file.WriteLine(String.Format("  output {0};", index > 2 && index < 6 ? "angular" : "linear"));
                        file.WriteLine("  weighted 0;");
                        file.WriteLine("  preInfinity constant;");
                        file.WriteLine("  postInfinity constant;");
                        file.WriteLine("  keys {");
                        for (KeyframeEntry entry = array._keyRoot._next; (entry != array._keyRoot); entry = entry._next)
                        {
                            bool single = entry._next._index < 0 && entry._prev._index < 0;
                            //float angle = (float)Math.Atan(entry._tangent) * Maths._rad2degf;
                            //if (single)
                            {
                                file.WriteLine(String.Format("    {0} {1} {2} {2} {3} {4} {5};",
                                                             entry._index + 1,
                                                             entry._value.ToString(CultureInfo.InvariantCulture.NumberFormat),
                                                             "auto",//single ? "auto" : "fixed",
                                                             "1",
                                                             "1",
                                                             "0"));
                            }
                        }
                        file.WriteLine("  }");
                        file.WriteLine("}");
                    }
                }
            }
        }
コード例 #24
0
        private unsafe void button5_Click(object sender, EventArgs e)
        {
            //Set vertices (0), normals (1), and/or colors (2, 3)
            //UVs are not morphed so there's no need to set them

            if (SelectedAnimation == null ||
                SelectedSource == null ||
                TargetModel == null ||
                TargetModel.Objects == null ||
                TargetModel.Objects.Length == 0)
            {
                return;
            }

            SHP0EntryNode entry = SelectedAnimation.FindChild(SelectedSource, false) as SHP0EntryNode;

            if (entry == null)
            {
                return;
            }

            if (MessageBox.Show(this, "Are you sure you want to continue?\nThis will edit the model and make the selected object's vertices, normals and/or colors default to the current morph.", "Are you sure?", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                return;
            }

            //Set the model to be only the bind pose with the SHP0 applied
            //This is so when the data is unweighted,
            //only the influence of the SHP0 will be set to the model.
            //Otherwise the entire CHR0 pose would be set as well
            float    frame = CurrentFrame;
            SHP0Node shp   = _mainWindow.SelectedSHP0;
            CHR0Node chr   = _mainWindow.SelectedCHR0;

            if (TargetModel != null)
            {
                TargetModel.ApplyCHR(null, 0);
                TargetModel.ApplySHP(shp, frame);
            }

            ResourceNode[] nodes = ((ResourceNode)TargetModel).FindChildrenByName(SelectedSource);
            foreach (ResourceNode n in nodes)
            {
                if (n is MDL0VertexNode)
                {
                    MDL0VertexNode   node = (MDL0VertexNode)n;
                    MDL0ObjectNode[] o    = new MDL0ObjectNode[node._objects.Count];
                    node._objects.CopyTo(o);
                    foreach (MDL0ObjectNode obj in o)
                    {
                        //Set the unweighted positions using the weighted positions
                        //Created using the SHP0
                        obj.Unweight(false);
                        obj.SetEditedAssets(true, true, false, false, false);
                    }
                }
                else if (n is MDL0NormalNode)
                {
                    MDL0NormalNode   node = (MDL0NormalNode)n;
                    MDL0ObjectNode[] o    = new MDL0ObjectNode[node._objects.Count];
                    node._objects.CopyTo(o);
                    foreach (MDL0ObjectNode obj in o)
                    {
                        obj.SetEditedAssets(true, false, true, false, false);
                    }
                }
                else if (n is MDL0ColorNode)
                {
                    MDL0ColorNode    node = (MDL0ColorNode)n;
                    MDL0ObjectNode[] o    = new MDL0ObjectNode[node._objects.Count];
                    node._objects.CopyTo(o);
                    foreach (MDL0ObjectNode obj in o)
                    {
                        obj.SetEditedAssets(true, false, false, true, true);
                    }
                }
            }

            if (TargetModel != null)
            {
                TargetModel.ApplyCHR(chr, frame);
                TargetModel.ApplySHP(shp, frame);
            }
        }
コード例 #25
0
        public static CHR0Node Convert(string input)
        {
            try
            {
                CHR0Node chr0 = new CHR0Node
                {
                    Name = Path.GetFileNameWithoutExtension(input),
                    Loop = false,
                    Version = 4
                };
                List<string> boneNames = new List<string>();
                List<int> boneIDs = new List<int>();
                int lineNumber = 0;
                bool isReadingBones = false;
                bool isReadingFrames = false;
                int currentFrameID = new int();
                float radianFloat = 57.29579143313326f; //Angles are given in radians. To convert them into degrees, multiply them by this float.
                List<SMDFrame> allFrames = new List<SMDFrame>();
                for (TextReader reader = new StreamReader(input); reader.Peek() != -1;) //Writing data into Lists
                {
                    string line = reader.ReadLine();

                    if (line.CompareTo("end") == 0) //When reaching this line, we stop reading what we were reading
                    {
                        isReadingBones = false;
                        isReadingFrames = false;
                    }

                    if (isReadingBones)
                    {
                        string[] splitLine = line.Split('\"');
                        int boneID = int.Parse(splitLine[0].Split(' ')[0]);
                        string boneName = splitLine[1];
                        boneIDs.Add(boneID);
                        boneNames.Add(boneName);
                    }

                    if(isReadingFrames)
                    {
                        SMDFrame currentFrame = new SMDFrame();
                        if(line.Contains("time "))
                        {
                            currentFrameID = int.Parse(line.Split(' ')[1]);
                            line = reader.ReadLine();
                            lineNumber++;
                        }
                        string[] frameNumbers = line.Split(' ');

                        int boneID = int.Parse(frameNumbers[0], CultureInfo.InvariantCulture.NumberFormat);
                        float posX = float.Parse(frameNumbers[2], CultureInfo.InvariantCulture.NumberFormat);
                        float posY = float.Parse(frameNumbers[3], CultureInfo.InvariantCulture.NumberFormat);
                        float posZ = float.Parse(frameNumbers[4], CultureInfo.InvariantCulture.NumberFormat);
                        float rotX = float.Parse(frameNumbers[6], CultureInfo.InvariantCulture.NumberFormat) * radianFloat;
                        float rotY = float.Parse(frameNumbers[7], CultureInfo.InvariantCulture.NumberFormat) * radianFloat;
                        float rotZ = float.Parse(frameNumbers[8], CultureInfo.InvariantCulture.NumberFormat) * radianFloat;

                        currentFrame = new SMDFrame(currentFrameID, boneID, posX, posY, posZ, rotX, rotY, rotZ);

                        allFrames.Add(currentFrame);
                    }

                    if (lineNumber == 0) //First Line
                    {
                        if (line.CompareTo("version 1") != 0) //The first line contains the version number. It needs to be 1.
                        {
                            MessageBox.Show("Unsupported SMD Version. Please use SMD Version 1."); //I don't even know if there's versions >1 but let's not take risks
                            return null;
                        }
                    }

                    if (line.CompareTo("nodes") == 0) //When reaching this line, we start reading bones names
                    {
                        isReadingBones = true;
                    }

                    if (line.CompareTo("skeleton") == 0) //When reaching this line, we start reading frames
                    {
                        isReadingFrames = true;
                    }

                    lineNumber++;
                }

                foreach (int thisBone in boneIDs)
                {
                    CHR0EntryNode node = new CHR0EntryNode();
                    chr0.AddChild(node);
                    node.Name = boneNames[thisBone];
                    node.SetSize(currentFrameID + 1, true);

                    int keynum = 0;

                    foreach (SMDFrame currentFrame in allFrames)
                    {
                        //Keyframe Array documentation:
                        //  ---------------------
                        //  |       | X | Y | Z |
                        //  | Scale | 0 | 1 | 2 |
                        //  | Rot   | 3 | 4 | 5 |
                        //  | Pos   | 6 | 7 | 8 |
                        //  ---------------------
                        if (currentFrame.boneID == thisBone)
                        {
                            node.SetKeyframe(3, currentFrame.id, currentFrame.rotx);
                            node.SetKeyframe(4, currentFrame.id, currentFrame.roty);
                            node.SetKeyframe(5, currentFrame.id, currentFrame.rotz);
                            node.SetKeyframe(6, currentFrame.id, currentFrame.posx);
                            node.SetKeyframe(7, currentFrame.id, currentFrame.posy);
                            node.SetKeyframe(8, currentFrame.id, currentFrame.posz);

                            keynum++;
                        }
                    }

                    chr0.FrameCount = keynum;
                    chr0.Loop = true;
                }

                return chr0;
            }
            catch (Exception e)
            {
                MessageBox.Show("There was a problem importing keyframes.\n\nError:\n" + e);
                return null;
            }
        }
コード例 #26
0
        public static SkeletalAnim Chr02Fska(string FileName)
        {
            CHR0Node chr0 = CHR0Node.FromFile(FileName);

            return(Chr02Fska(chr0));
        }
コード例 #27
0
        public static void BoneAnim2Chr0Entry(BoneAnim boneAnim, CHR0Node chr0)
        {
            CHR0EntryNode chr0Entry = chr0.CreateEntry(boneAnim.Name);

            chr0Entry.UseModelRotate       = false;
            chr0Entry.UseModelScale        = false;
            chr0Entry.UseModelTranslate    = false;
            chr0Entry.ScaleCompensateApply = boneAnim.ApplySegmentScaleCompensate;

            //Float for time/frame
            Dictionary <float, FSKAKeyNode> TranslateX = new Dictionary <float, FSKAKeyNode>();
            Dictionary <float, FSKAKeyNode> TranslateY = new Dictionary <float, FSKAKeyNode>();
            Dictionary <float, FSKAKeyNode> TranslateZ = new Dictionary <float, FSKAKeyNode>();
            Dictionary <float, FSKAKeyNode> RotateX    = new Dictionary <float, FSKAKeyNode>();
            Dictionary <float, FSKAKeyNode> RotateY    = new Dictionary <float, FSKAKeyNode>();
            Dictionary <float, FSKAKeyNode> RotateZ    = new Dictionary <float, FSKAKeyNode>();
            Dictionary <float, FSKAKeyNode> ScaleX     = new Dictionary <float, FSKAKeyNode>();
            Dictionary <float, FSKAKeyNode> ScaleY     = new Dictionary <float, FSKAKeyNode>();
            Dictionary <float, FSKAKeyNode> ScaleZ     = new Dictionary <float, FSKAKeyNode>();

            if (boneAnim.FlagsBase.HasFlag(BoneAnimFlagsBase.Translate))
            {
                TranslateX.Add(0, new FSKAKeyNode()
                {
                    Value = boneAnim.BaseData.Translate.X,
                });
                TranslateY.Add(0, new FSKAKeyNode()
                {
                    Value = boneAnim.BaseData.Translate.Y,
                });
                TranslateZ.Add(0, new FSKAKeyNode()
                {
                    Value = boneAnim.BaseData.Translate.Z,
                });
            }
            if (boneAnim.FlagsBase.HasFlag(BoneAnimFlagsBase.Rotate))
            {
                RotateX.Add(0, new FSKAKeyNode()
                {
                    Value = boneAnim.BaseData.Rotate.X,
                });
                RotateY.Add(0, new FSKAKeyNode()
                {
                    Value = boneAnim.BaseData.Rotate.Y,
                });
                RotateZ.Add(0, new FSKAKeyNode()
                {
                    Value = boneAnim.BaseData.Rotate.Z,
                });
            }

            if (boneAnim.FlagsBase.HasFlag(BoneAnimFlagsBase.Scale))
            {
                ScaleX.Add(0, new FSKAKeyNode()
                {
                    Value = boneAnim.BaseData.Scale.X,
                });
                ScaleY.Add(0, new FSKAKeyNode()
                {
                    Value = boneAnim.BaseData.Scale.Y,
                });
                ScaleZ.Add(0, new FSKAKeyNode()
                {
                    Value = boneAnim.BaseData.Scale.Z,
                });
            }
            else
            {
                ScaleX.Add(0, new FSKAKeyNode()
                {
                    Value = 1
                });
                ScaleY.Add(0, new FSKAKeyNode()
                {
                    Value = 1
                });
                ScaleZ.Add(0, new FSKAKeyNode()
                {
                    Value = 1
                });
            }

            foreach (var curve in boneAnim.Curves)
            {
                for (int frame = 0; frame < curve.Frames.Length; frame++)
                {
                    float time   = curve.Frames[frame];
                    float value  = 0;
                    float slope  = 0;
                    float slope2 = 0;
                    float delta  = 0;

                    float scale = curve.Scale;
                    if (scale <= 0)
                    {
                        scale = 1;
                    }

                    if (curve.CurveType == AnimCurveType.Cubic)
                    {
                        value  = curve.Offset + curve.Keys[frame, 0] * scale;
                        slope  = curve.Offset + curve.Keys[frame, 1] * scale;
                        slope2 = curve.Offset + curve.Keys[frame, 2] * scale;
                        delta  = curve.Offset + curve.Keys[frame, 3] * scale;
                    }
                    if (curve.CurveType == AnimCurveType.Linear)
                    {
                        value = curve.Offset + curve.Keys[frame, 0] * scale;
                        delta = curve.Offset + curve.Keys[frame, 1] * scale;
                    }
                    if (curve.CurveType == AnimCurveType.StepInt)
                    {
                        value = curve.Offset + curve.Keys[frame, 0] * scale;
                    }


                    switch (curve.AnimDataOffset)
                    {
                    case 0x10:
                        if (TranslateX.Count > 0 && frame == 0)
                        {
                            TranslateX.Remove(0);
                        }

                        TranslateX.Add(time, new FSKAKeyNode()
                        {
                            Value  = value,
                            Slope  = slope,
                            Slope2 = slope2,
                            Delta  = delta,
                            Frame  = time,
                        });
                        break;

                    case 0x14:
                        if (TranslateY.Count > 0 && frame == 0)
                        {
                            TranslateY.Remove(0);
                        }

                        TranslateY.Add(time, new FSKAKeyNode()
                        {
                            Value  = value,
                            Slope  = slope,
                            Slope2 = slope2,
                            Delta  = delta,
                            Frame  = time,
                        });
                        break;

                    case 0x18:
                        if (TranslateZ.Count > 0 && frame == 0)
                        {
                            TranslateZ.Remove(0);
                        }

                        TranslateZ.Add(time, new FSKAKeyNode()
                        {
                            Value  = value,
                            Slope  = slope,
                            Slope2 = slope2,
                            Delta  = delta,
                            Frame  = time,
                        });
                        break;

                    case 0x20:
                        if (RotateX.Count > 0 && frame == 0)
                        {
                            RotateX.Remove(0);
                        }

                        RotateX.Add(time, new FSKAKeyNode()
                        {
                            Value  = value,
                            Slope  = slope,
                            Slope2 = slope2,
                            Delta  = delta,
                            Frame  = time,
                        });
                        break;

                    case 0x24:
                        if (RotateY.Count > 0 && frame == 0)
                        {
                            RotateY.Remove(0);
                        }

                        RotateY.Add(time, new FSKAKeyNode()
                        {
                            Value  = value,
                            Slope  = slope,
                            Slope2 = slope2,
                            Delta  = delta,
                            Frame  = time,
                        });
                        break;

                    case 0x28:
                        if (RotateZ.Count > 0 && frame == 0)
                        {
                            RotateZ.Remove(0);
                        }

                        RotateZ.Add(time, new FSKAKeyNode()
                        {
                            Value  = value,
                            Slope  = slope,
                            Slope2 = slope2,
                            Delta  = delta,
                            Frame  = time,
                        });
                        break;

                    case 0x04:
                        if (ScaleX.Count > 0 && frame == 0)
                        {
                            ScaleX.Remove(0);
                        }

                        ScaleX.Add(time, new FSKAKeyNode()
                        {
                            Value  = value,
                            Slope  = slope,
                            Slope2 = slope2,
                            Delta  = delta,
                            Frame  = time,
                        });
                        break;

                    case 0x08:
                        if (ScaleY.Count > 0 && frame == 0)
                        {
                            ScaleY.Remove(0);
                        }

                        ScaleY.Add(time, new FSKAKeyNode()
                        {
                            Value  = value,
                            Slope  = slope,
                            Slope2 = slope2,
                            Delta  = delta,
                            Frame  = time,
                        });
                        break;

                    case 0x0C:
                        if (ScaleZ.Count > 0 && frame == 0)
                        {
                            ScaleZ.Remove(0);
                        }

                        ScaleZ.Add(time, new FSKAKeyNode()
                        {
                            Value  = value,
                            Slope  = slope,
                            Slope2 = slope2,
                            Delta  = delta,
                            Frame  = time,
                        });
                        break;
                    }
                }
            }

            for (int frame = 0; frame < chr0.FrameCount; frame++)
            {
                if (TranslateX.ContainsKey(frame))
                {
                    chr0Entry.SetKeyframe(6, frame, TranslateX[frame].Value);
                }
                if (TranslateY.ContainsKey(frame))
                {
                    chr0Entry.SetKeyframe(7, frame, TranslateY[frame].Value);
                }
                if (TranslateZ.ContainsKey(frame))
                {
                    chr0Entry.SetKeyframe(8, frame, TranslateZ[frame].Value);
                }
                if (RotateX.ContainsKey(frame))
                {
                    chr0Entry.SetKeyframe(3, frame, RotateX[frame].Value * Rad2Deg);
                }
                if (RotateY.ContainsKey(frame))
                {
                    chr0Entry.SetKeyframe(4, frame, RotateY[frame].Value * Rad2Deg);
                }
                if (RotateZ.ContainsKey(frame))
                {
                    chr0Entry.SetKeyframe(5, frame, RotateZ[frame].Value * Rad2Deg);
                }
                if (ScaleX.ContainsKey(frame))
                {
                    chr0Entry.SetKeyframe(0, frame, ScaleX[frame].Value);
                }
                if (ScaleY.ContainsKey(frame))
                {
                    chr0Entry.SetKeyframe(1, frame, ScaleY[frame].Value);
                }
                if (ScaleZ.ContainsKey(frame))
                {
                    chr0Entry.SetKeyframe(2, frame, ScaleZ[frame].Value);
                }
            }
        }
コード例 #28
0
        public static SkeletalAnim Anim2Fska(string FileName)
        {
            CHR0Node chr0 = AnimFormat.Read(FileName);

            return(Chr02Fska(chr0));
        }