Ejemplo n.º 1
0
        private void butSaveChanges_Click(object sender, EventArgs e)
        {
            // Check if we need to transform mesh
            var transform = panelRendering.GizmoTransform;

            if (transform != Matrix4x4.Identity)
            {
                for (int i = 0; i < _workingStatic.Mesh.VerticesPositions.Count; i++)
                {
                    var position = MathC.HomogenousTransform(_workingStatic.Mesh.VerticesPositions[i], transform);
                    _workingStatic.Mesh.VerticesPositions[i] = new Vector3(position.X, position.Y, position.Z);
                }

                for (int i = 0; i < _workingStatic.Mesh.VerticesNormals.Count; i++)
                {
                    var normal = MathC.HomogenousTransform(_workingStatic.Mesh.VerticesNormals[i], transform);
                    _workingStatic.Mesh.VerticesNormals[i] = new Vector3(normal.X, normal.Y, normal.Z);
                }
            }

            // Assign the edited mesh to original static mesh
            _wad.Statics.Remove(_workingStatic.Id);
            _wad.Statics.Add(_workingStatic.Id, _workingStatic);

            _workingStatic.Version = DataVersion.GetNext();

            _tool.ToggleUnsavedChanges();

            DialogResult = DialogResult.OK;
            Close();
        }
Ejemplo n.º 2
0
 private void FormStaticEditor_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (DialogResult == DialogResult.OK)
     {
         _workingStatic.Version = DataVersion.GetNext();
     }
 }
Ejemplo n.º 3
0
 private void Tool_EditorEventRaised(IEditorEvent obj)
 {
     if (obj is WadToolClass.StaticSelectedLightChangedEvent)
     {
         UpdateLightUI();
     }
     else if (obj is WadToolClass.StaticLightsChangedEvent)
     {
         UpdateLightsList();
         UpdateLightUI();
         _workingStatic.Version = DataVersion.GetNext();
         panelRendering.Invalidate();
     }
 }
Ejemplo n.º 4
0
        private void SaveChanges()
        {
            // First check if skeleton is valid
            int numPop  = 0;
            int numPush = 0;

            foreach (var bone in _bones)
            {
                if (bone.Bone.OpCode == WadLinkOpcode.Pop)
                {
                    numPop++;
                }
                if (bone.Bone.OpCode == WadLinkOpcode.Push)
                {
                    numPush++;
                }
            }

            // We can have more PUSH than POP, but the opposite case (POP more than PUSH) will result in a leak
            // inside the previous moveables in the list
            if (numPop > numPush)
            {
                DarkMessageBox.Show(this, "Your mesh tree is unbalanced, you have added more POP than PUSH.",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (treeSkeleton.Nodes.Count > 1)
            {
                DarkMessageBox.Show(this, "Your mesh tree is unbalanced, you must have a single bone as root.",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Insert new bones in moveable
            _moveable.Bones.Clear();
            foreach (var bone in _bones)
            {
                _moveable.Bones.Add(bone.Bone);
            }

            // Replace the moveable
            _wad.Moveables[_moveable.Id] = _moveable;

            // Now cause the moveable to reload
            _moveable.Version = DataVersion.GetNext();

            _tool.ToggleUnsavedChanges();
        }
Ejemplo n.º 5
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();
                }
            }
        }
Ejemplo n.º 6
0
        public bool SaveChanges(IWin32Window owner = null)  // No owner - no confirmation!
        {
            if (owner != null && DarkMessageBox.Show(owner, "Do you really want to save changes to animations?", "Save changes",
                                                     MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return(false);
            }

            // Clear the old animations
            Moveable.Animations.Clear();

            // Combine WadAnimation and Animation classes
            foreach (var animation in Animations)
            {
                Moveable.Animations.Add(GetSavedAnimation(animation));
            }

            Moveable.Version = DataVersion.GetNext();
            Tool.ToggleUnsavedChanges();
            return(true);
        }