2024-11-19 02:13:14 +03:00
|
|
|
|
using Silk.NET.OpenGL;
|
|
|
|
|
using TexmLib;
|
2024-11-15 19:06:44 +03:00
|
|
|
|
|
|
|
|
|
namespace NResUI.Models;
|
|
|
|
|
|
2024-11-18 23:48:42 +03:00
|
|
|
|
public class TexmExplorerViewModel
|
2024-11-15 19:06:44 +03:00
|
|
|
|
{
|
|
|
|
|
public bool HasFile { get; set; }
|
|
|
|
|
public string? Error { get; set; }
|
|
|
|
|
|
2024-11-18 23:48:42 +03:00
|
|
|
|
public TexmFile? TexmFile { get; set; }
|
2024-11-19 02:13:14 +03:00
|
|
|
|
|
2024-11-15 19:06:44 +03:00
|
|
|
|
public string? Path { get; set; }
|
2024-11-19 02:13:14 +03:00
|
|
|
|
public List<OpenGlTexture> GlTextures { get; set; } = [];
|
|
|
|
|
|
|
|
|
|
private bool _glTexturesDirty = false;
|
|
|
|
|
public bool IsWhiteBgEnabled;
|
|
|
|
|
|
|
|
|
|
public bool IsBlackBgEnabled;
|
2024-11-19 02:28:49 +03:00
|
|
|
|
public bool DoubleSize;
|
2024-11-19 02:13:14 +03:00
|
|
|
|
|
2024-11-18 23:48:42 +03:00
|
|
|
|
public void SetParseResult(TexmParseResult result, string path)
|
2024-11-15 19:06:44 +03:00
|
|
|
|
{
|
|
|
|
|
Error = result.Error;
|
|
|
|
|
|
2024-11-18 23:48:42 +03:00
|
|
|
|
if (result.TexmFile != null)
|
2024-11-15 19:06:44 +03:00
|
|
|
|
{
|
|
|
|
|
HasFile = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-18 23:48:42 +03:00
|
|
|
|
TexmFile = result.TexmFile;
|
2024-11-15 19:06:44 +03:00
|
|
|
|
Path = path;
|
2024-11-19 02:13:14 +03:00
|
|
|
|
_glTexturesDirty = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сгенерировать OpenGL текстуры из всех мипмапов Texm файла
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void GenerateGlTextures(GL gl)
|
|
|
|
|
{
|
|
|
|
|
if (_glTexturesDirty && TexmFile is not null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var glTexture in GlTextures)
|
|
|
|
|
{
|
|
|
|
|
glTexture.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GlTextures.Clear();
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < TexmFile!.Header.MipmapCount; i++)
|
|
|
|
|
{
|
|
|
|
|
var bytes = TexmFile.GetRgba32BytesFromMipmap(i, out var width, out var height);
|
|
|
|
|
|
|
|
|
|
var glTexture = new OpenGlTexture(
|
|
|
|
|
gl,
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
bytes
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
GlTextures.Add(glTexture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_glTexturesDirty = false;
|
|
|
|
|
}
|
2024-11-15 19:06:44 +03:00
|
|
|
|
}
|
|
|
|
|
}
|