mirror of
https://github.com/4sval/FModel.git
synced 2026-04-22 01:27:43 -05:00
somewhat usable
This commit is contained in:
parent
59973f95d6
commit
4da6b2d775
|
|
@ -1 +1 @@
|
|||
Subproject commit 00664537d9f861161e18f2e93308d77b8d3c7372
|
||||
Subproject commit 6bb149f6fa34ef0cc51c60df9334678727d29853
|
||||
|
|
@ -89,7 +89,7 @@ public class CUE4ParseViewModel : ViewModel
|
|||
WindowBorder = WindowBorder.Resizable,
|
||||
StartVisible = false,
|
||||
StartFocused = false,
|
||||
Title = "Title"
|
||||
Title = "3D Viewer"
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,15 +24,14 @@ public class Cache : IDisposable
|
|||
public bool TryGetModel(FGuid guid, out Model model) => _models.TryGetValue(guid, out model);
|
||||
public bool TryGetTexture(FGuid guid, out Texture texture) => _textures.TryGetValue(guid, out texture);
|
||||
|
||||
public void Setup(FGuid guid) => _models[guid].Setup();
|
||||
public void Setup()
|
||||
{
|
||||
foreach (var model in _models.Values)
|
||||
{
|
||||
if (model.IsSetup) continue;
|
||||
model.Setup();
|
||||
}
|
||||
}
|
||||
|
||||
public void Render(Shader shader)
|
||||
{
|
||||
foreach (var model in _models.Values)
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ public class Model : IDisposable
|
|||
public readonly List<Transform> Transforms;
|
||||
|
||||
public bool Show;
|
||||
public bool IsSetup;
|
||||
public bool IsSelected;
|
||||
public bool DisplayVertexColors;
|
||||
public bool DisplayBones;
|
||||
|
|
@ -201,6 +202,8 @@ public class Model : IDisposable
|
|||
{
|
||||
Sections[section].Setup();
|
||||
}
|
||||
|
||||
IsSetup = true;
|
||||
}
|
||||
|
||||
public void Render(Shader shader)
|
||||
|
|
|
|||
|
|
@ -11,9 +11,6 @@ public class Options
|
|||
public int SelectedSection { get; private set; }
|
||||
public int SelectedMorph { get; private set; }
|
||||
|
||||
public bool Append { get; set; }
|
||||
public bool Close { get; set; }
|
||||
|
||||
public Options()
|
||||
{
|
||||
Reset();
|
||||
|
|
@ -25,8 +22,6 @@ public class Options
|
|||
SelectedModelInstance = 0;
|
||||
SelectedSection = 0;
|
||||
SelectedMorph = 0;
|
||||
Append = false;
|
||||
Close = false;
|
||||
}
|
||||
|
||||
public void SelectModel(FGuid guid)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace FModel.Views.Snooper;
|
|||
public class Renderer : IDisposable
|
||||
{
|
||||
private Shader _shader;
|
||||
private Shader _outline;
|
||||
// private Shader _outline; // fix stutter
|
||||
private Vector3 _diffuseLight;
|
||||
private Vector3 _specularLight;
|
||||
|
||||
|
|
@ -30,34 +30,16 @@ public class Renderer : IDisposable
|
|||
Settings = new Options();
|
||||
}
|
||||
|
||||
public void Load(CancellationToken cancellationToken, UObject export)
|
||||
public Camera Load(CancellationToken cancellationToken, UObject export)
|
||||
{
|
||||
switch (export)
|
||||
return export switch
|
||||
{
|
||||
case UStaticMesh st:
|
||||
{
|
||||
LoadStaticMesh(st);
|
||||
break;
|
||||
}
|
||||
case USkeletalMesh sk:
|
||||
{
|
||||
LoadSkeletalMesh(sk);
|
||||
break;
|
||||
}
|
||||
case UMaterialInstance mi:
|
||||
{
|
||||
LoadMaterialInstance(mi);
|
||||
break;
|
||||
}
|
||||
case UWorld wd:
|
||||
{
|
||||
LoadWorld(cancellationToken, wd);
|
||||
// _camera = new Camera(new Vector3(0f, 5f, 5f), Vector3.Zero, 0.01f, 1000f, 5f);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(export));
|
||||
}
|
||||
UStaticMesh st => LoadStaticMesh(st),
|
||||
USkeletalMesh sk => LoadSkeletalMesh(sk),
|
||||
UMaterialInstance mi => LoadMaterialInstance(mi),
|
||||
UWorld wd => LoadWorld(cancellationToken, wd),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(export))
|
||||
};
|
||||
}
|
||||
|
||||
public void Swap(UMaterialInstance unrealMaterial)
|
||||
|
|
@ -72,7 +54,7 @@ public class Renderer : IDisposable
|
|||
public void Setup()
|
||||
{
|
||||
_shader = new Shader();
|
||||
_outline = new Shader("outline");
|
||||
// _outline = new Shader("outline");
|
||||
_diffuseLight = new Vector3(0.75f);
|
||||
_specularLight = new Vector3(0.5f);
|
||||
|
||||
|
|
@ -84,10 +66,10 @@ public class Renderer : IDisposable
|
|||
var viewMatrix = cam.GetViewMatrix();
|
||||
var projMatrix = cam.GetProjectionMatrix();
|
||||
|
||||
_outline.Use();
|
||||
_outline.SetUniform("uView", viewMatrix);
|
||||
_outline.SetUniform("uProjection", projMatrix);
|
||||
_outline.SetUniform("viewPos", cam.Position);
|
||||
// _outline.Use();
|
||||
// _outline.SetUniform("uView", viewMatrix);
|
||||
// _outline.SetUniform("uProjection", projMatrix);
|
||||
// _outline.SetUniform("viewPos", cam.Position);
|
||||
|
||||
_shader.Use();
|
||||
_shader.SetUniform("uView", viewMatrix);
|
||||
|
|
@ -104,62 +86,62 @@ public class Renderer : IDisposable
|
|||
_shader.SetUniform("light.specular", _specularLight);
|
||||
|
||||
Cache.Render(_shader);
|
||||
GL.Enable(EnableCap.StencilTest); // I don't get why this must be here but it works now so...
|
||||
Cache.Outline(_outline);
|
||||
// GL.Enable(EnableCap.StencilTest); // I don't get why this must be here but it works now so...
|
||||
// Cache.Outline(_outline);
|
||||
}
|
||||
|
||||
// private void SetupCamera(FBox box)
|
||||
// {
|
||||
// var far = box.Max.Max();
|
||||
// var center = box.GetCenter();
|
||||
// var position = new Vector3(0f, center.Z, box.Max.Y * 3);
|
||||
// var speed = far / 2f;
|
||||
// if (speed > _previousSpeed)
|
||||
// {
|
||||
// _camera = new Camera(position, center, 0.01f, far * 50f, speed);
|
||||
// _previousSpeed = _camera.Speed;
|
||||
// }
|
||||
// }
|
||||
private Camera SetupCamera(FBox box)
|
||||
{
|
||||
var far = box.Max.Max();
|
||||
var center = box.GetCenter();
|
||||
return new Camera(
|
||||
new Vector3(0f, center.Z, box.Max.Y * 3),
|
||||
new Vector3(center.X, center.Z, center.Y),
|
||||
0.01f, far * 50f, far / 2f);
|
||||
}
|
||||
|
||||
private void LoadStaticMesh(UStaticMesh original)
|
||||
private Camera LoadStaticMesh(UStaticMesh original)
|
||||
{
|
||||
var guid = original.LightingGuid;
|
||||
if (Cache.TryGetModel(guid, out var model))
|
||||
{
|
||||
model.AddInstance(Transform.Identity);
|
||||
return null;
|
||||
}
|
||||
else if (original.TryConvert(out var mesh))
|
||||
{
|
||||
Cache.AddModel(guid, new Model(original.Name, original.ExportType, mesh));
|
||||
// SetupCamera(mesh.BoundingBox *= Constants.SCALE_DOWN_RATIO);
|
||||
Settings.SelectModel(guid);
|
||||
}
|
||||
|
||||
if (!original.TryConvert(out var mesh))
|
||||
return null;
|
||||
|
||||
Cache.AddModel(guid, new Model(original.Name, original.ExportType, mesh));
|
||||
Settings.SelectModel(guid);
|
||||
return SetupCamera(mesh.BoundingBox *= Constants.SCALE_DOWN_RATIO);
|
||||
}
|
||||
|
||||
private void LoadSkeletalMesh(USkeletalMesh original)
|
||||
private Camera LoadSkeletalMesh(USkeletalMesh original)
|
||||
{
|
||||
var guid = Guid.NewGuid();
|
||||
if (Cache.HasModel(guid) || !original.TryConvert(out var mesh)) return;
|
||||
if (Cache.HasModel(guid) || !original.TryConvert(out var mesh)) return null;
|
||||
|
||||
Cache.AddModel(guid, new Model(original.Name, original.ExportType, original.MorphTargets, mesh));
|
||||
// SetupCamera(mesh.BoundingBox *= Constants.SCALE_DOWN_RATIO);
|
||||
Settings.SelectModel(guid);
|
||||
return SetupCamera(mesh.BoundingBox *= Constants.SCALE_DOWN_RATIO);
|
||||
}
|
||||
|
||||
private void LoadMaterialInstance(UMaterialInstance original)
|
||||
private Camera LoadMaterialInstance(UMaterialInstance original)
|
||||
{
|
||||
var guid = Guid.NewGuid();
|
||||
if (Cache.HasModel(guid)) return;
|
||||
if (Cache.HasModel(guid)) return null;
|
||||
|
||||
Cache.AddModel(guid, new Cube(original));
|
||||
// SetupCamera(new FBox(new FVector(-.65f), new FVector(.65f)));
|
||||
Settings.SelectModel(guid);
|
||||
return SetupCamera(new FBox(new FVector(-.65f), new FVector(.65f)));
|
||||
}
|
||||
|
||||
private void LoadWorld(CancellationToken cancellationToken, UWorld original)
|
||||
private Camera LoadWorld(CancellationToken cancellationToken, UWorld original)
|
||||
{
|
||||
var ret = new Camera(new Vector3(0f, 5f, 5f), Vector3.Zero, 0.01f, 1000f, 5f);
|
||||
if (original.PersistentLevel.Load<ULevel>() is not { } persistentLevel)
|
||||
return;
|
||||
return ret;
|
||||
|
||||
var length = persistentLevel.Actors.Length;
|
||||
for (var i = 0; i < length; i++)
|
||||
|
|
@ -228,12 +210,14 @@ public class Renderer : IDisposable
|
|||
Cache.AddModel(guid, model);
|
||||
}
|
||||
}
|
||||
Services.ApplicationService.ApplicationView.Status.UpdateStatusLabel($"Actor {length}/{length}");
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_shader.Dispose();
|
||||
_outline.Dispose();
|
||||
// _outline.Dispose();
|
||||
Cache.Dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,12 +34,23 @@ public class Snooper : GameWindow
|
|||
public void SwapMaterial(UMaterialInstance mi) => _renderer.Swap(mi);
|
||||
public void LoadExport(CancellationToken cancellationToken, UObject export)
|
||||
{
|
||||
_renderer.Load(cancellationToken, export);
|
||||
_camera = new Camera(new Vector3(0f, 5f, 5f), Vector3.Zero, 0.01f, 1000f, 5f);
|
||||
var newCamera = _renderer.Load(cancellationToken, export);
|
||||
if (newCamera == null || !(newCamera.Speed > _previousSpeed)) return;
|
||||
|
||||
_camera = newCamera;
|
||||
_previousSpeed = _camera.Speed;
|
||||
}
|
||||
|
||||
private unsafe void WindowShouldClose(bool value)
|
||||
private unsafe void WindowShouldClose(bool value, bool clear)
|
||||
{
|
||||
if (clear)
|
||||
{
|
||||
_renderer.Cache.DisposeModels();
|
||||
_renderer.Cache.ClearModels();
|
||||
_renderer.Settings.Reset();
|
||||
_previousSpeed = 0f;
|
||||
}
|
||||
|
||||
GLFW.SetWindowShouldClose(WindowPtr, value); // start / stop game loop
|
||||
CursorState = value ? CursorState.Normal : CursorState.Grabbed;
|
||||
IsVisible = !value;
|
||||
|
|
@ -49,7 +60,7 @@ public class Snooper : GameWindow
|
|||
{
|
||||
Application.Current.Dispatcher.Invoke(delegate
|
||||
{
|
||||
WindowShouldClose(false);
|
||||
WindowShouldClose(false, false);
|
||||
base.Run();
|
||||
});
|
||||
}
|
||||
|
|
@ -58,11 +69,12 @@ public class Snooper : GameWindow
|
|||
{
|
||||
if (_init)
|
||||
{
|
||||
_renderer.Cache.Setup(_renderer.Settings.SelectedModel);
|
||||
_renderer.Cache.Setup();
|
||||
return;
|
||||
}
|
||||
|
||||
base.OnLoad();
|
||||
CenterWindow();
|
||||
|
||||
GL.ClearColor(Color4.Red);
|
||||
GL.Enable(EnableCap.Blend);
|
||||
|
|
@ -109,7 +121,7 @@ public class Snooper : GameWindow
|
|||
protected override void OnMouseMove(MouseMoveEventArgs e)
|
||||
{
|
||||
base.OnMouseMove(e);
|
||||
if (!IsFocused)
|
||||
if (!IsVisible)
|
||||
return;
|
||||
|
||||
const float lookSensitivity = 0.1f;
|
||||
|
|
@ -120,7 +132,7 @@ public class Snooper : GameWindow
|
|||
protected override void OnUpdateFrame(FrameEventArgs e)
|
||||
{
|
||||
base.OnUpdateFrame(e);
|
||||
if (!IsFocused)
|
||||
if (!IsVisible)
|
||||
return;
|
||||
|
||||
var multiplier = KeyboardState.IsKeyDown(Keys.LeftShift) ? 2f : 1f;
|
||||
|
|
@ -142,10 +154,10 @@ public class Snooper : GameWindow
|
|||
if (KeyboardState.IsKeyDown(Keys.C))
|
||||
_camera.ModifyZoom(+.5f);
|
||||
|
||||
if (KeyboardState.IsKeyPressed(Keys.H))
|
||||
IsVisible = false;
|
||||
if (KeyboardState.IsKeyPressed(Keys.R))
|
||||
WindowShouldClose(true, false);
|
||||
if (KeyboardState.IsKeyPressed(Keys.Escape))
|
||||
WindowShouldClose(true);
|
||||
WindowShouldClose(true, true);
|
||||
}
|
||||
|
||||
protected override void OnResize(ResizeEventArgs e)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user