Пример #1
0
        private void ReplaceAllBonesFromFile()
        {
            var boneCount = _bones.Count;

            using (FileDialog dialog = new OpenFileDialog())
            {
                dialog.InitialDirectory = PathC.GetDirectoryNameTry(_tool.DestinationWad.FileName);
                dialog.FileName         = PathC.GetFileNameTry(_tool.DestinationWad.FileName);
                dialog.Filter           = BaseGeometryImporter.FileExtensions.GetFilter();
                dialog.Title            = "Select a 3D file that you want to see imported.";
                if (dialog.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                using (var form = new GeometryIOSettingsDialog(new IOGeometrySettings()))
                {
                    form.AddPreset(IOSettingsPresets.GeometryImportSettingsPresets);
                    if (form.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }

                    var meshes = WadMesh.ImportFromExternalModel(dialog.FileName, form.Settings, false);
                    if (meshes == null || meshes.Count == 0)
                    {
                        ImportFailed();
                        return;
                    }

                    int meshCount;
                    if (meshes.Count > _bones.Count)
                    {
                        meshCount = _bones.Count;
                        popup.ShowError(panelRendering, "Mesh count is higher in imported model. Only first " + _bones.Count + " will be imported.");
                    }
                    else if (meshes.Count < _bones.Count)
                    {
                        meshCount = meshes.Count;
                        popup.ShowError(panelRendering, "Mesh count is lower in imported model. Only meshes up to " + meshes.Count + " will be replaced.");
                    }
                    else
                    {
                        meshCount = _bones.Count;
                    }

                    for (int i = 0; i < meshCount; i++)
                    {
                        ReplaceExistingBone(meshes[i], _bones[i]);
                    }
                }
            }
        }
Пример #2
0
        public static void ImportModelAsStaticMesh(WadToolClass tool, IWin32Window owner)
        {
            if (tool.DestinationWad == null)
            {
                tool.SendMessage("You must have a wad opened", PopupType.Error);
                return;
            }

            using (FileDialog dialog = new OpenFileDialog())
            {
                try
                {
                    dialog.InitialDirectory = Path.GetDirectoryName(tool.DestinationWad.FileName);
                    dialog.FileName         = Path.GetFileName(tool.DestinationWad.FileName);
                }
                catch
                {
                    // ignored
                }

                dialog.Filter = BaseGeometryImporter.FileExtensions.GetFilter();
                dialog.Title  = "Select a 3D file that you want to see imported.";
                if (dialog.ShowDialog(owner) != DialogResult.OK)
                {
                    return;
                }

                using (var form = new GeometryIOSettingsDialog(new IOGeometrySettings()))
                {
                    form.AddPreset(IOSettingsPresets.GeometryImportSettingsPresets);
                    if (form.ShowDialog(owner) != DialogResult.OK)
                    {
                        return;
                    }

                    var @static = new WadStatic(tool.DestinationWad.GetFirstFreeStaticMesh());
                    var mesh    = WadMesh.ImportFromExternalModel(dialog.FileName, form.Settings);
                    if (mesh == null)
                    {
                        tool.SendMessage("Error while loading the 3D model. Please check that the file " +
                                         "is one of the supported formats and that the meshes are textured", PopupType.Error);
                        return;
                    }
                    @static.Mesh          = mesh;
                    @static.VisibilityBox = @static.Mesh.BoundingBox;
                    @static.CollisionBox  = @static.Mesh.BoundingBox;
                    tool.DestinationWad.Statics.Add(@static.Id, @static);
                    tool.WadChanged(WadArea.Destination);
                }
            }
        }
Пример #3
0
        private void butImportMeshFromFile_Click(object sender, EventArgs e)
        {
            using (FileDialog dialog = new OpenFileDialog())
            {
                dialog.InitialDirectory = PathC.GetDirectoryNameTry(_tool.DestinationWad.FileName);
                dialog.FileName         = PathC.GetFileNameTry(_tool.DestinationWad.FileName);
                dialog.Filter           = BaseGeometryImporter.FileExtensions.GetFilter();
                dialog.Title            = "Select a 3D file that you want to see imported.";
                if (dialog.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                using (var form = new GeometryIOSettingsDialog(new IOGeometrySettings()))
                {
                    form.AddPreset(IOSettingsPresets.GeometryImportSettingsPresets);
                    if (form.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                    var mesh = WadMesh.ImportFromExternalModel(dialog.FileName, form.Settings);
                    if (mesh == null)
                    {
                        DarkMessageBox.Show(this, "Error while loading 3D model. Check that the file format \n" +
                                            "is supported, meshes are textured and texture file is present.",
                                            "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    _workingStatic.Mesh          = mesh;
                    _workingStatic.VisibilityBox = _workingStatic.Mesh.CalculateBoundingBox(panelRendering.GizmoTransform);
                    _workingStatic.CollisionBox  = _workingStatic.Mesh.CalculateBoundingBox(panelRendering.GizmoTransform);
                    _workingStatic.Version       = DataVersion.GetNext();
                    _workingStatic.Mesh.CalculateNormals();

                    panelRendering.Invalidate();
                    UpdatePositionUI();
                    UpdateCollisionBoxUI();
                    UpdateVisibilityBoxUI();
                    UpdateLightUI();
                }
            }
        }
Пример #4
0
        private void AddChildBoneFromFile()
        {
            if (treeSkeleton.SelectedNodes.Count == 0)
            {
                return;
            }
            var theNode = (WadMeshBoneNode)treeSkeleton.SelectedNodes[0].Tag;

            using (FileDialog dialog = new OpenFileDialog())
            {
                dialog.InitialDirectory = PathC.GetDirectoryNameTry(_tool.DestinationWad.FileName);
                dialog.FileName         = PathC.GetFileNameTry(_tool.DestinationWad.FileName);
                dialog.Filter           = BaseGeometryImporter.FileExtensions.GetFilter();
                dialog.Title            = "Select a 3D file that you want to see imported.";
                if (dialog.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }

                using (var form = new GeometryIOSettingsDialog(new IOGeometrySettings()))
                {
                    form.AddPreset(IOSettingsPresets.GeometryImportSettingsPresets);
                    if (form.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }
                    var mesh = WadMesh.ImportFromExternalModel(dialog.FileName, form.Settings);
                    if (mesh == null)
                    {
                        ImportFailed();
                        return;
                    }

                    InsertNewBone(mesh, theNode);
                }
            }
        }