1
mirror of https://github.com/sampletext32/ParkanPlayground.git synced 2025-12-12 01:31:20 +04:00

Material parsing and viewing

This commit is contained in:
bird_egop
2025-12-04 03:50:29 +03:00
parent 3b1fd5ef97
commit 75b1548f55
18 changed files with 1694 additions and 63 deletions

View File

@@ -18,9 +18,10 @@ public class NResExplorerPanel : IImGuiPanel
private readonly CpDatSchemeViewModel _cpDatSchemeViewModel;
private readonly MissionTmaViewModel _missionTmaViewModel;
private readonly ScrViewModel _scrViewModel;
private readonly MaterialViewModel _materialViewModel;
public NResExplorerPanel(NResExplorerViewModel viewModel, TexmExplorerViewModel texmExplorerViewModel,
VarsetViewModel varsetViewModel, CpDatSchemeViewModel cpDatSchemeViewModel, MissionTmaViewModel missionTmaViewModel, ScrViewModel scrViewModel)
VarsetViewModel varsetViewModel, CpDatSchemeViewModel cpDatSchemeViewModel, MissionTmaViewModel missionTmaViewModel, ScrViewModel scrViewModel, MaterialViewModel materialViewModel)
{
_viewModel = viewModel;
_texmExplorerViewModel = texmExplorerViewModel;
@@ -28,6 +29,7 @@ public class NResExplorerPanel : IImGuiPanel
_cpDatSchemeViewModel = cpDatSchemeViewModel;
_missionTmaViewModel = missionTmaViewModel;
_scrViewModel = scrViewModel;
_materialViewModel = materialViewModel;
}
int contextMenuRow = -1;
@@ -272,6 +274,28 @@ public class NResExplorerPanel : IImGuiPanel
_scrViewModel.SetParseResult(parseResult, Path.Combine(_viewModel.Path!, file.FileName));
Console.WriteLine("Read .scr from context menu");
}
if (ImGui.MenuItem("Open as Material"))
{
using var fs = new FileStream(_viewModel.Path!, FileMode.Open, FileAccess.Read, FileShare.Read);
fs.Seek(file.OffsetInFile, SeekOrigin.Begin);
var buffer = new byte[file.FileLength];
fs.ReadExactly(buffer, 0, file.FileLength);
using var ms = new MemoryStream(buffer);
try
{
var parseResult = MaterialLib.MaterialParser.ReadFromStream(ms, file.FileName, (int)file.ElementCount, file.Magic1);
_materialViewModel.SetParseResult(parseResult, Path.Combine(_viewModel.Path!, file.FileName));
Console.WriteLine("Read Material from context menu");
}
catch (Exception ex)
{
Console.WriteLine($"Error reading material: {ex}");
_materialViewModel.SetError(ex.Message);
}
}
}
ImGui.EndPopup();