mirror of
https://github.com/4sval/FModel.git
synced 2026-04-13 04:56:14 -05:00
append mode shortcut
This commit is contained in:
parent
872b01c7ef
commit
4710d3afbc
|
|
@ -7,6 +7,7 @@ using CUE4Parse_Conversion.Textures;
|
|||
using FModel.Services;
|
||||
using FModel.Settings;
|
||||
using Silk.NET.OpenGL;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace FModel.Views.Snooper;
|
||||
|
||||
|
|
@ -78,22 +79,22 @@ public class Section : IDisposable
|
|||
else if (Parameters.Diffuse is UTexture2D { IsVirtual: false } diffuse)
|
||||
{
|
||||
var mip = diffuse.GetFirstMip();
|
||||
TextureDecoder.DecodeTexture(mip, diffuse.Format, diffuse.isNormalMap, platform, out var data, out _);
|
||||
Textures[0] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, diffuse);
|
||||
TextureDecoder.DecodeTexture(mip, diffuse.Format, diffuse.isNormalMap, platform, out var data, out var colorType);
|
||||
Textures[0] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, colorType, diffuse);
|
||||
}
|
||||
|
||||
if (Parameters.Normal is UTexture2D { IsVirtual: false } normal)
|
||||
{
|
||||
var mip = normal.GetFirstMip();
|
||||
TextureDecoder.DecodeTexture(mip, normal.Format, normal.isNormalMap, platform, out var data, out _);
|
||||
Textures[1] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, normal);
|
||||
TextureDecoder.DecodeTexture(mip, normal.Format, normal.isNormalMap, platform, out var data, out var colorType);
|
||||
Textures[1] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, colorType, normal);
|
||||
}
|
||||
|
||||
if (Parameters.Specular is UTexture2D { IsVirtual: false } specular)
|
||||
{
|
||||
var mip = specular.GetFirstMip();
|
||||
SwapSpecular(specular, mip, platform, out var data);
|
||||
Textures[2] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, specular);
|
||||
SwapSpecular(specular, mip, platform, out var data, out var colorType);
|
||||
Textures[2] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, colorType, specular);
|
||||
}
|
||||
|
||||
if (Parameters.HasTopEmissiveTexture &&
|
||||
|
|
@ -101,8 +102,8 @@ public class Section : IDisposable
|
|||
Parameters.Emissive is UTexture2D { IsVirtual: false } emissive)
|
||||
{
|
||||
var mip = emissive.GetFirstMip();
|
||||
TextureDecoder.DecodeTexture(mip, emissive.Format, emissive.isNormalMap, platform, out var data, out _);
|
||||
Textures[3] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, emissive);
|
||||
TextureDecoder.DecodeTexture(mip, emissive.Format, emissive.isNormalMap, platform, out var data, out var colorType);
|
||||
Textures[3] = new Texture(_gl, data, (uint) mip.SizeX, (uint) mip.SizeY, colorType, emissive);
|
||||
EmissionColor = new Vector4(emissiveColor.R, emissiveColor.G, emissiveColor.B, emissiveColor.A);
|
||||
}
|
||||
}
|
||||
|
|
@ -122,9 +123,9 @@ public class Section : IDisposable
|
|||
/// Roughness on Green
|
||||
/// Ambient Occlusion on Red
|
||||
/// </summary>
|
||||
private void SwapSpecular(UTexture2D specular, FTexture2DMipMap mip, ETexturePlatform platform, out byte[] data)
|
||||
private void SwapSpecular(UTexture2D specular, FTexture2DMipMap mip, ETexturePlatform platform, out byte[] data, out SKColorType colorType)
|
||||
{
|
||||
TextureDecoder.DecodeTexture(mip, specular.Format, specular.isNormalMap, platform, out data, out _);
|
||||
TextureDecoder.DecodeTexture(mip, specular.Format, specular.isNormalMap, platform, out data, out colorType);
|
||||
|
||||
switch (_game)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ public class SnimGui : IDisposable
|
|||
|
||||
if (ImGui.BeginMenu("Window"))
|
||||
{
|
||||
ImGui.MenuItem("Append", "CTRL+A");
|
||||
ImGui.MenuItem("Append", "H");
|
||||
ImGui.MenuItem("Close", "ESC");
|
||||
ImGui.EndMenu();
|
||||
}
|
||||
|
|
@ -278,8 +278,8 @@ public class SnimGui : IDisposable
|
|||
if (ImGui.IsItemHovered())
|
||||
{
|
||||
ImGui.BeginTooltip();
|
||||
ImGui.Text($"Type: ({texture.Format}) {texture.Type}");
|
||||
ImGui.Text($"Texture: {texture.Path}.{texture.Name}");
|
||||
ImGui.Text($"Type: ({texture.Format}) {texture.Type} \"{texture.Name}\"");
|
||||
ImGui.Text($"Texture: {texture.Path}");
|
||||
ImGui.Text($"Imported: {texture.ImportedWidth}x{texture.ImportedHeight}");
|
||||
ImGui.Text($"Mip Used: {texture.Width}x{texture.Height}");
|
||||
ImGui.Spacing();
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@ public class Snooper
|
|||
private readonly List<Model> _models;
|
||||
|
||||
private Vector2D<int> _size;
|
||||
private float _previousSpeed;
|
||||
private bool _close;
|
||||
private bool _append;
|
||||
|
||||
public Snooper()
|
||||
{
|
||||
|
|
@ -82,6 +85,8 @@ public class Snooper
|
|||
|
||||
public void Run(UObject export)
|
||||
{
|
||||
_close = false;
|
||||
_append = false;
|
||||
switch (export)
|
||||
{
|
||||
case UStaticMesh st when st.TryConvert(out var mesh):
|
||||
|
|
@ -100,7 +105,16 @@ public class Snooper
|
|||
throw new ArgumentOutOfRangeException(nameof(export));
|
||||
}
|
||||
|
||||
_window.Run();
|
||||
_window.Initialize();
|
||||
while (!_close && !_append)
|
||||
{
|
||||
_window.DoEvents();
|
||||
_window.DoUpdate();
|
||||
_window.DoRender();
|
||||
}
|
||||
_window.DoEvents();
|
||||
if (!_append) _window.Close(); // dispose
|
||||
else _window.Reset();
|
||||
}
|
||||
|
||||
private void SetupCamera(FBox box)
|
||||
|
|
@ -108,7 +122,12 @@ public class Snooper
|
|||
var far = box.Max.Max();
|
||||
var center = box.GetCenter();
|
||||
var position = new Vector3(0f, center.Z, box.Max.Y * 3);
|
||||
_camera = new Camera(position, center, 0.01f, far * 50f, far / 2f);
|
||||
var speed = far / 2f;
|
||||
if (speed > _previousSpeed)
|
||||
{
|
||||
_camera = new Camera(position, center, 0.01f, far * 50f, speed);
|
||||
_previousSpeed = _camera.Speed;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnLoad()
|
||||
|
|
@ -116,22 +135,29 @@ public class Snooper
|
|||
_window.SetWindowIcon(ref _icon);
|
||||
_window.Center();
|
||||
|
||||
var input = _window.CreateInput();
|
||||
_keyboard = input.Keyboards[0];
|
||||
_mouse = input.Mice[0];
|
||||
|
||||
_gl = GL.GetApi(_window);
|
||||
_gl.Enable(EnableCap.Multisample);
|
||||
|
||||
_imGui = new SnimGui(_gl, _window, input);
|
||||
|
||||
_framebuffer.Setup(_gl);
|
||||
_skybox.Setup(_gl);
|
||||
_grid.Setup(_gl);
|
||||
|
||||
foreach (var model in _models)
|
||||
if (_append)
|
||||
{
|
||||
model.Setup(_gl);
|
||||
_models[^1].Setup(_gl);
|
||||
}
|
||||
else
|
||||
{
|
||||
var input = _window.CreateInput();
|
||||
_keyboard = input.Keyboards[0];
|
||||
_mouse = input.Mice[0];
|
||||
|
||||
_gl = GL.GetApi(_window);
|
||||
_gl.Enable(EnableCap.Multisample);
|
||||
|
||||
_imGui = new SnimGui(_gl, _window, input);
|
||||
|
||||
_framebuffer.Setup(_gl);
|
||||
_skybox.Setup(_gl);
|
||||
_grid.Setup(_gl);
|
||||
|
||||
foreach (var model in _models)
|
||||
{
|
||||
model.Setup(_gl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -192,8 +218,11 @@ public class Snooper
|
|||
_camera.Position += moveSpeed * _camera.Up;
|
||||
if (_keyboard.IsKeyPressed(Key.Q))
|
||||
_camera.Position -= moveSpeed * _camera.Up;
|
||||
|
||||
if (_keyboard.IsKeyPressed(Key.H))
|
||||
_append = true;
|
||||
if (_keyboard.IsKeyPressed(Key.Escape))
|
||||
_window.Close();
|
||||
_close = true;
|
||||
}
|
||||
|
||||
private void OnClose()
|
||||
|
|
@ -206,6 +235,7 @@ public class Snooper
|
|||
model.Dispose();
|
||||
}
|
||||
_models.Clear();
|
||||
_previousSpeed = 0f;
|
||||
_imGui.Dispose();
|
||||
_window.Dispose();
|
||||
_gl.Dispose();
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Windows;
|
|||
using CUE4Parse.UE4.Assets.Exports.Texture;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace FModel.Views.Snooper;
|
||||
|
||||
|
|
@ -64,7 +65,7 @@ public class Texture : IDisposable
|
|||
_gl.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, _handle, 0);
|
||||
}
|
||||
|
||||
public unsafe Texture(GL gl, byte[] data, uint width, uint height, UTexture2D texture2D) : this(gl, TextureType.Normal)
|
||||
public unsafe Texture(GL gl, byte[] data, uint width, uint height, SKColorType colorType, UTexture2D texture2D) : this(gl, TextureType.Normal)
|
||||
{
|
||||
Type = texture2D.ExportType;
|
||||
Name = texture2D.Name;
|
||||
|
|
@ -79,7 +80,6 @@ public class Texture : IDisposable
|
|||
fixed (void* d = &data[0])
|
||||
{
|
||||
_gl.TexImage2D(TextureTarget.Texture2D, 0, (int) InternalFormat.Rgba, Width, Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, d);
|
||||
|
||||
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int) GLEnum.LinearMipmapLinear);
|
||||
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int) GLEnum.Linear);
|
||||
_gl.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBaseLevel, 0);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user