예제 #1
0
        public ImportedGeometryManager()
        {
            InitializeComponent();

            _correctColor = dataGridView.BackColor.MixWith(Color.LimeGreen, 0.55);
            _wrongColor   = dataGridView.BackColor.MixWith(Color.DarkRed, 0.55);

            dataGridView.CellMouseDoubleClick += dataGridView_CellMouseDoubleClick;

            // Initialize sound path data grid view
            dataGridViewControls.DataGridView = dataGridView;
            dataGridViewControls.Enabled      = true;
            dataGridViewControls.CreateNewRow = delegate
            {
                List <string> paths = LevelFileDialog.BrowseFiles(this, null, PathC.GetDirectoryNameTry(LevelSettings.LevelFilePath),
                                                                  "Select 3D files that you want to see imported.", ImportedGeometry.FileExtensions).ToList();

                // Load imported geometries
                var importInfos = new List <KeyValuePair <ImportedGeometry, ImportedGeometryInfo> >();
                foreach (string path in paths)
                {
                    using (var settingsDialog = new GeometryIOSettingsDialog(new IOGeometrySettings()))
                    {
                        settingsDialog.AddPreset(IOSettingsPresets.GeometryImportSettingsPresets);
                        settingsDialog.SelectPreset("Normal scale to TR scale");

                        if (settingsDialog.ShowDialog(this) == DialogResult.Cancel)
                        {
                            continue;
                        }

                        var info = new ImportedGeometryInfo(LevelSettings.MakeRelative(path, VariableType.LevelDirectory), settingsDialog.Settings);
                        importInfos.Add(new KeyValuePair <ImportedGeometry, ImportedGeometryInfo>(new ImportedGeometry(), info));
                    }
                }

                LevelSettings.ImportedGeometryUpdate(importInfos);
                LevelSettings.ImportedGeometries.AddRange(importInfos.Select(entry => entry.Key));
                return(importInfos.Select(entry => new ImportedGeometryWrapper(this, entry.Key)));
            };
            dataGridView.DataSource = _dataGridViewDataSource;
            dataGridViewControls.DeleteRowCheckIfCancel = MessageUserAboutHimDeletingRows;
            _dataGridViewDataSource.ListChanged        += delegate(object sender, ListChangedEventArgs e)
            {
                switch (e.ListChangedType)
                {
                case ListChangedType.ItemDeleted:
                    var remainingElements = new HashSet <ImportedGeometry>(_dataGridViewDataSource.Select(wrapper => wrapper.Object));
                    LevelSettings.ImportedGeometries.RemoveAll(obj => !remainingElements.Contains(obj));         // Don't use indices here, the wrapper indices might not match with the real object if sorting was enabled.
                    break;
                }
            };
            Enabled = true;
        }
예제 #2
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]);
                    }
                }
            }
        }
예제 #3
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);
                }
            }
        }
예제 #4
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();
                }
            }
        }
예제 #5
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);
                }
            }
        }
예제 #6
0
        public static WadAnimation ImportAnimationFromModel(WadToolClass tool, IWin32Window owner, int nodeCount, string fileName)
        {
            IOModel tmpModel = null;

            // Import the model
            try
            {
                var settings = new IOGeometrySettings()
                {
                    ProcessAnimations = true, ProcessGeometry = false
                };
                using (var form = new GeometryIOSettingsDialog(settings))
                {
                    form.AddPreset(IOSettingsPresets.AnimationSettingsPresets);
                    string resultingExtension = Path.GetExtension(fileName).ToLowerInvariant();

                    if (resultingExtension.Equals(".fbx"))
                    {
                        form.SelectPreset("3dsmax Filmbox (FBX)");
                    }
                    else if (resultingExtension.Equals(".dae"))
                    {
                        form.SelectPreset("3dsmax COLLADA");
                    }

                    if (form.ShowDialog(owner) != DialogResult.OK)
                    {
                        return(null);
                    }

                    var importer = BaseGeometryImporter.CreateForFile(fileName, settings, null);
                    tmpModel = importer.ImportFromFile(fileName);

                    // We don't support animation importing from custom-written mqo importer yet...
                    if (importer is MetasequoiaImporter)
                    {
                        tool.SendMessage("Metasequoia importer isn't currently supported.", PopupType.Error);
                        return(null);
                    }

                    // If no animations, return null
                    if (tmpModel.Animations.Count == 0)
                    {
                        tool.SendMessage("Selected file has no supported animations!", PopupType.Error);
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                tool.SendMessage("Unknown error while importing animation. \n" + ex?.Message, PopupType.Error);
                logger.Warn(ex, "'ImportAnimationFromModel' failed.");
                return(null);
            }

            IOAnimation animToImport;

            if (tmpModel.Animations.Count > 1)
            {
                using (var dialog = new AnimationImportDialog(tmpModel.Animations.Select(o => o.Name).ToList()))
                {
                    dialog.ShowDialog(owner);
                    if (dialog.DialogResult == DialogResult.Cancel)
                    {
                        return(null);
                    }
                    else
                    {
                        animToImport = tmpModel.Animations[dialog.AnimationToImport];
                    }
                }
            }
            else
            {
                animToImport = tmpModel.Animations[0];
            }


            // Integrity check, for cases when something totally went wrong with assimp
            if (animToImport == null)
            {
                tool.SendMessage("Animation importer encountered serious error. No animation imported.", PopupType.Error);
                return(null);
            }

            // Integrity check, is there any valid frames?
            if (animToImport.Frames.Count <= 0)
            {
                tool.SendMessage("Selected animation has no frames!", PopupType.Error);
                return(null);
            }

            // Integrity check, number of bones = number of nodes?
            if (animToImport.NumNodes != nodeCount)
            {
                tool.SendMessage("Selected animation has different number of bones!", PopupType.Error);
                return(null);
            }

            WadAnimation animation = new WadAnimation();

            animation.Name = animToImport.Name;

            foreach (var frame in animToImport.Frames)
            {
                var keyFrame = new WadKeyFrame();
                keyFrame.Offset = frame.Offset;
                frame.Angles.ForEach(angle => keyFrame.Angles.Add(new WadKeyFrameRotation()
                {
                    Rotations = angle
                }));

                animation.KeyFrames.Add(keyFrame);
            }

            animation.EndFrame = (ushort)(animToImport.Frames.Count - 1);

            return(animation);
        }