コード例 #1
0
        protected override void LoadChildren()
        {
            _lmpFile.ReadDirectory();
            foreach (var entry in _lmpFile.Directory)
            {
                var ext = "";
                try
                {
                    ext = (System.IO.Path.GetExtension(entry.Key) ?? "").ToLower();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    continue;
                }

                TreeViewItemViewModel child;
                switch (ext)
                {
                case ".world":
                    child = new WorldFileTreeViewModel(_world, this, _lmpFile, entry.Key);
                    break;

                default:
                    child = new LmpEntryTreeViewModel(_world, this, _lmpFile, entry.Key);
                    break;
                }
                Children.Add(child);
            }
        }
コード例 #2
0
        private void OnLmpEntrySelected(LmpEntryTreeViewModel lmpEntry)
        {
            var lmpFile = lmpEntry.LmpFileProperty;
            var entry = lmpFile.Directory[lmpEntry.Text];

            var ext = (Path.GetExtension(lmpEntry.Text) ?? "").ToLower();

            switch (ext)
            {
                case ".tex":
                    {
                        SelectedNodeImage = TexDecoder.Decode(lmpFile.FileData, entry.StartOffset, entry.Length);

                        _window.tabControl.SelectedIndex = 0; // Texture View
                    }
                    break;
                case ".vif":
                    {
                        string texFilename = Path.GetFileNameWithoutExtension(lmpEntry.Text) + ".tex";
                        var texEntry = lmpFile.Directory[texFilename];
                        SelectedNodeImage = TexDecoder.Decode(lmpFile.FileData, texEntry.StartOffset, texEntry.Length);
                        var log = new StringLogger();
                        _modelViewModel.Texture = SelectedNodeImage;
                        _modelViewModel.AnimData = null;
                        Model model = new Model();
                        model.meshList = VifDecoder.Decode(log, lmpFile.FileData, entry.StartOffset, entry.Length,
                                                           SelectedNodeImage.PixelWidth, SelectedNodeImage.PixelHeight);
                        _modelViewModel.VifModel = model;

                        /*// Load animation data
                        var animData = LoadFirstAnim(lmpFile);
                        // Make sure the animation will work with the model
                        if (animData.Count > 0 && animData[0].NumBones == model.CountBones())
                            _modelViewModel.AnimData = animData.Count == 0 ? null : animData.First();*/

                        LogText += log.ToString();

                        _window.tabControl.SelectedIndex = 1; // Model View
                        _window.ResetCamera();
                        _window.SetViewportText(1, lmpEntry.Text, "");
                    }
                    break;
                case ".anm":
                    {
                        var engineVersion = App.Settings.Get("Core.EngineVersion", EngineVersion.DarkAlliance);
                        var animData = AnmDecoder.Decode(engineVersion, lmpFile.FileData, entry.StartOffset, entry.Length);
                        _skeletonViewModel.AnimData = animData;
                        LogText = animData.ToString();

                        if (_modelViewModel.VifModel != null)
                        {
                            int boneCount = _modelViewModel.VifModel.CountBones();
                            if (boneCount != 0 && boneCount == animData.NumBones)
                            {
                                _modelViewModel.AnimData = animData;

                                // Switch tab to animation tab only if the current tab isnt the model view tab
                                if (_window.tabControl.SelectedIndex != 1) // Model View
                                {
                                    _window.tabControl.SelectedIndex = 2; // Skeleton View
                                    _window.ResetCamera();
                                }
                            }
                            else
                            {
                                // Bone count doesn't match, switch to skeleton view
                                _window.tabControl.SelectedIndex = 2; // Skeleton View
                                _window.ResetCamera();
                            }
                        }
                        else
                        {
                            _window.tabControl.SelectedIndex = 2; // Skeleton View
                            _window.ResetCamera();
                        }
                    }

                    _window.SetViewportText(2, lmpEntry.Text, ""); // Set Skeleton View Text

                    break;
                case ".ob":
                    var objects = ObDecoder.Decode(lmpFile.FileData, entry.StartOffset, entry.Length);

                    var sb = new StringBuilder();

                    foreach (var obj in objects)
                    {
                        sb.AppendFormat("Name: {0}\n", obj.Name);
                        sb.AppendFormat("I6: {0}\n", obj.I6.ToString("X4"));
                        sb.AppendFormat("Floats: {0},{1},{2}\n", obj.Floats[0], obj.Floats[1], obj.Floats[2]);
                        if (obj.Properties != null)
                        {
                            foreach (var prop in obj.Properties)
                            {
                                sb.AppendFormat("Property: {0}\n", prop);
                            }
                        }
                        sb.Append("\n");
                    }

                    LogText = sb.ToString();
                    _window.tabControl.SelectedIndex = 4; // Log View

                    break;
            }
        }
コード例 #3
0
        private void OnLmpEntrySelected(LmpEntryTreeViewModel lmpEntry)
        {
            var lmpFile = lmpEntry.LmpFileProperty;
            var entry   = lmpFile.Directory[lmpEntry.Text];

            var ext = (Path.GetExtension(lmpEntry.Text) ?? "").ToLower();

            switch (ext)
            {
            case ".tex":
            {
                SelectedNodeImage = TexDecoder.Decode(lmpFile.FileData, entry.StartOffset, entry.Length);

                _window.tabControl.SelectedIndex = 0;         // Texture View
            }
            break;

            case ".vif":
            {
                string texFilename = Path.GetFileNameWithoutExtension(lmpEntry.Text) + ".tex";
                var    texEntry    = lmpFile.Directory[texFilename];
                SelectedNodeImage = TexDecoder.Decode(lmpFile.FileData, texEntry.StartOffset, texEntry.Length);
                var log = new StringLogger();
                _modelViewModel.Texture  = SelectedNodeImage;
                _modelViewModel.AnimData = null;
                Model model = new Model();
                model.meshList = VifDecoder.Decode(log, lmpFile.FileData, entry.StartOffset, entry.Length,
                                                   SelectedNodeImage.PixelWidth, SelectedNodeImage.PixelHeight);
                _modelViewModel.VifModel = model;

                /*// Load animation data
                 * var animData = LoadFirstAnim(lmpFile);
                 * // Make sure the animation will work with the model
                 * if (animData.Count > 0 && animData[0].NumBones == model.CountBones())
                 *  _modelViewModel.AnimData = animData.Count == 0 ? null : animData.First();*/

                LogText += log.ToString();

                _window.tabControl.SelectedIndex = 1;         // Model View
                _window.ResetCamera();
                _window.SetViewportText(1, lmpEntry.Text, "");
            }
            break;

            case ".anm":
            {
                var engineVersion = App.Settings.Get("Core.EngineVersion", EngineVersion.DarkAlliance);
                var animData      = AnmDecoder.Decode(engineVersion, lmpFile.FileData, entry.StartOffset, entry.Length);
                _skeletonViewModel.AnimData = animData;
                LogText = animData.ToString();

                if (_modelViewModel.VifModel != null)
                {
                    int boneCount = _modelViewModel.VifModel.CountBones();
                    if (boneCount != 0 && boneCount == animData.NumBones)
                    {
                        _modelViewModel.AnimData = animData;

                        // Switch tab to animation tab only if the current tab isnt the model view tab
                        if (_window.tabControl.SelectedIndex != 1)        // Model View
                        {
                            _window.tabControl.SelectedIndex = 2;         // Skeleton View
                            _window.ResetCamera();
                        }
                    }
                    else
                    {
                        // Bone count doesn't match, switch to skeleton view
                        _window.tabControl.SelectedIndex = 2;         // Skeleton View
                        _window.ResetCamera();
                    }
                }
                else
                {
                    _window.tabControl.SelectedIndex = 2;         // Skeleton View
                    _window.ResetCamera();
                }
            }

                _window.SetViewportText(2, lmpEntry.Text, "");     // Set Skeleton View Text

                break;

            case ".ob":
                var objects = ObDecoder.Decode(lmpFile.FileData, entry.StartOffset, entry.Length);

                var sb = new StringBuilder();

                foreach (var obj in objects)
                {
                    sb.AppendFormat("Name: {0}\n", obj.Name);
                    sb.AppendFormat("I6: {0}\n", obj.I6.ToString("X4"));
                    sb.AppendFormat("Floats: {0},{1},{2}\n", obj.Floats[0], obj.Floats[1], obj.Floats[2]);
                    if (obj.Properties != null)
                    {
                        foreach (var prop in obj.Properties)
                        {
                            sb.AppendFormat("Property: {0}\n", prop);
                        }
                    }
                    sb.Append("\n");
                }

                LogText = sb.ToString();
                _window.tabControl.SelectedIndex = 4;     // Log View

                break;
            }
        }
コード例 #4
0
        protected override void LoadChildren()
        {
            _lmpFile.ReadDirectory();
            foreach (var entry in _lmpFile.Directory)
            {
                var ext = (System.IO.Path.GetExtension(entry.Key) ?? "").ToLower();

                TreeViewItemViewModel child;
                switch (ext)
                {
                    case ".world":
                        child = new WorldFileTreeViewModel(_world, this, _lmpFile, entry.Key);
                        break;
                    default:
                        child = new LmpEntryTreeViewModel(_world, this, _lmpFile, entry.Key);
                        break;
                }
                Children.Add(child);
            }
        }