示例#1
0
        private unsafe void ResetBox(int index)
        {
            NumericInputBox box = _transBoxes[index];

            if (_transformObject is MDL0BoneNode)
            {
                MDL0BoneNode  bone = _transformObject as MDL0BoneNode;
                CHR0EntryNode entry;
                if ((_selectedAnim != null) && (_animFrame > 0) && ((entry = _selectedAnim.FindChild(bone.Name, false) as CHR0EntryNode) != null))
                {
                    KeyframeEntry e = entry.Keyframes.GetKeyframe((KeyFrameMode)index + 0x10, _animFrame - 1);
                    if (e == null)
                    {
                        box.Value     = entry.Keyframes[KeyFrameMode.ScaleX + index, _animFrame - 1];
                        box.BackColor = Color.White;
                    }
                    else
                    {
                        box.Value     = e._value;
                        box.BackColor = Color.Yellow;
                    }
                }
                else
                {
                    FrameState state = bone._bindState;
                    box.Value     = ((float *)&state)[index];
                    box.BackColor = Color.White;
                }
            }
            else
            {
                box.Value     = 0;
                box.BackColor = Color.White;
            }
        }
        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();
        }
示例#3
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);
        }
示例#4
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++;
                    }
                }
            }
        }