Esempio n. 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;
        }
Esempio n. 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]);
                    }
                }
            }
        }
Esempio n. 3
0
        public string GetTRNGVersion()
        {
            var buffer = PathC.GetDirectoryNameTry(_level.Settings.MakeAbsolute(_level.Settings.GameExecutableFilePath)) + "\\Tomb_NextGeneration.dll";

            if (File.Exists(buffer))
            {
                buffer = (FileVersionInfo.GetVersionInfo(buffer)).ProductVersion;
                _progressReporter.ReportInfo("TRNG found, version is " + buffer);
            }
            else
            {
                buffer = "1,3,0,6";
                _progressReporter.ReportWarn("Tomb_NextGeneration.dll wasn't found in game directory. Probably you're using TRNG target on vanilla TR4/TRLE?");
            }
            return(buffer);
        }
Esempio n. 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();
                }
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 6
0
        private static bool LoadSamples(ChunkReader chunkIO, ChunkId idOuter, Wad2 wad, ref Dictionary <long, WadSample> outSamples, bool obsolete)
        {
            if (idOuter != Wad2Chunks.Samples)
            {
                return(false);
            }

            var  samples       = new Dictionary <long, WadSample>();
            long obsoleteIndex = 0; // Move this into each chunk once we got rid of old style *.wad2 files.

            chunkIO.ReadChunks((id, chunkSize) =>
            {
                if (id != Wad2Chunks.Sample)
                {
                    return(false);
                }

                string FilenameObsolete = null;
                byte[] data             = null;

                chunkIO.ReadChunks((id2, chunkSize2) =>
                {
                    if (id2 == Wad2Chunks.SampleIndex)
                    {
                        obsoleteIndex = chunkIO.ReadChunkLong(chunkSize2);
                    }
                    else if (id2 == Wad2Chunks.SampleFilenameObsolete)
                    {
                        FilenameObsolete = chunkIO.ReadChunkString(chunkSize2);
                    }
                    else if (id2 == Wad2Chunks.SampleData)
                    {
                        data = chunkIO.ReadChunkArrayOfBytes(chunkSize2);
                    }
                    else
                    {
                        return(false);
                    }
                    return(true);
                });

                if (data == null && !string.IsNullOrEmpty(FilenameObsolete))
                {
                    string fullPath = Path.Combine(PathC.GetDirectoryNameTry(Assembly.GetEntryAssembly().Location), "Sounds\\TR4\\Samples", FilenameObsolete + ".wav");
                    data            = File.ReadAllBytes(fullPath);
                }

                samples.Add(obsoleteIndex++, new WadSample("", WadSample.ConvertSampleFormat(data,
                                                                                             sampleRate => obsolete ?
                                                                                             new WadSample.ResampleInfo {
                    Resample = false, SampleRate = WadSample.GameSupportedSampleRate
                } :
                                                                                             new WadSample.ResampleInfo {
                    Resample = true, SampleRate = sampleRate
                })));
                return(true);
            });

            outSamples = samples;
            return(true);
        }