Skip to content

Commit

Permalink
proof of concept
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Aug 25, 2022
1 parent 9b96734 commit 2c0fee3
Show file tree
Hide file tree
Showing 14 changed files with 480 additions and 88 deletions.
2 changes: 1 addition & 1 deletion FModel/Creator/Bases/FN/BaseCommunity.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using CUE4Parse.FN.Enums;
using CUE4Parse.UE4.Assets.Exports;
using CUE4Parse.UE4.Objects.GameplayTags;
using CUE4Parse.UE4.Objects.UObject;
using CUE4Parse.UE4.Versions;
using CUE4Parse_Fortnite.Enums;
using FModel.Extensions;
using FModel.Framework;
using FModel.Services;
Expand Down
2 changes: 1 addition & 1 deletion FModel/Creator/Bases/FN/BaseIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using CUE4Parse.FN.Enums;
using CUE4Parse.UE4.Assets.Exports;
using CUE4Parse.UE4.Assets.Exports.Engine;
using CUE4Parse.UE4.Assets.Exports.Material;
Expand All @@ -12,7 +13,6 @@
using CUE4Parse.UE4.Objects.GameplayTags;
using CUE4Parse.UE4.Objects.UObject;
using CUE4Parse_Conversion.Textures;
using CUE4Parse_Fortnite.Enums;
using FModel.Settings;
using SkiaSharp;

Expand Down
4 changes: 2 additions & 2 deletions FModel/Creator/Bases/FN/BaseIconStats.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
using CUE4Parse.FN.Enums;
using CUE4Parse.UE4.Assets.Exports;
using CUE4Parse.UE4.Assets.Exports.Engine;
using CUE4Parse.UE4.Assets.Objects;
using CUE4Parse.UE4.Objects.Core.i18N;
using CUE4Parse.UE4.Objects.Engine.Curves;
using CUE4Parse.UE4.Objects.GameplayTags;
using CUE4Parse.UE4.Objects.UObject;
using CUE4Parse_Fortnite.Enums;
using FModel.Extensions;
using FModel.Framework;
using SkiaSharp;
Expand Down Expand Up @@ -288,4 +288,4 @@ public void Draw(SKCanvas c, SKColor sliderColor, int width, int height, ref flo
var sliderWidth = (sliderRight - height * 2) * (floatValue / _maxValue);
c.DrawRect(new SKRect(height * 2, y, Math.Min(height * 2 + sliderWidth, sliderRight), y + 5), _statPaint);
}
}
}
6 changes: 0 additions & 6 deletions FModel/FModel.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FModel", "FModel.csproj", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CUE4Parse", "..\CUE4Parse\CUE4Parse\CUE4Parse.csproj", "{C4620341-BBB7-4384-AC7D-5082D3E0386E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CUE4Parse-Fortnite", "..\CUE4Parse\CUE4Parse-Fortnite\CUE4Parse-Fortnite.csproj", "{7765FB4C-B54D-427B-ABB6-1073687E56BD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CUE4Parse-Conversion", "..\CUE4Parse\CUE4Parse-Conversion\CUE4Parse-Conversion.csproj", "{D0E1E8F7-F56D-469A-8E24-C2439B9FFD83}"
EndProject
Global
Expand All @@ -25,10 +23,6 @@ Global
{C4620341-BBB7-4384-AC7D-5082D3E0386E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4620341-BBB7-4384-AC7D-5082D3E0386E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4620341-BBB7-4384-AC7D-5082D3E0386E}.Release|Any CPU.Build.0 = Release|Any CPU
{7765FB4C-B54D-427B-ABB6-1073687E56BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7765FB4C-B54D-427B-ABB6-1073687E56BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7765FB4C-B54D-427B-ABB6-1073687E56BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7765FB4C-B54D-427B-ABB6-1073687E56BD}.Release|Any CPU.Build.0 = Release|Any CPU
{D0E1E8F7-F56D-469A-8E24-C2439B9FFD83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D0E1E8F7-F56D-469A-8E24-C2439B9FFD83}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D0E1E8F7-F56D-469A-8E24-C2439B9FFD83}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
11 changes: 6 additions & 5 deletions FModel/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using FModel.ViewModels;
using FModel.Views;
using FModel.Views.Resources.Controls;
using FModel.Views.Snooper;
using ICSharpCode.AvalonEdit.Editing;

namespace FModel;
Expand Down Expand Up @@ -53,10 +52,6 @@ private async void OnLoaded(object sender, RoutedEventArgs e)
ApplicationService.ApiEndpointView.FModelApi.CheckForUpdates(UserSettings.Default.UpdateMode);
#endif

var v = new Viewer();
v.Run();
return;

switch (UserSettings.Default.AesReload)
{
case EAesReload.Always:
Expand All @@ -80,6 +75,12 @@ private async void OnLoaded(object sender, RoutedEventArgs e)

if (UserSettings.Default.DiscordRpc == EDiscordRpc.Always)
_discordHandler.Initialize(_applicationView.CUE4Parse.Game);

#if DEBUG
await _threadWorkerView.Begin(_ =>
_applicationView.CUE4Parse.Extract(
"FortniteGame/Content/Environments/Props/Winter/Meshes/SM_Garland_Merge.uasset"));
#endif
}

private void OnGridSplitterDoubleClick(object sender, MouseButtonEventArgs e)
Expand Down
8 changes: 3 additions & 5 deletions FModel/ViewModels/CUE4ParseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
using FModel.Settings;
using FModel.Views;
using FModel.Views.Resources.Controls;
using FModel.Views.Snooper;
using Newtonsoft.Json;
using Serilog;
using SkiaSharp;
Expand Down Expand Up @@ -752,11 +753,8 @@ public void ExtractAndScroll(string fullPath, string objectName)
export.Owner.Name.EndsWith($"/RenderSwitch_Materials/{export.Name}", StringComparison.OrdinalIgnoreCase) ||
export.Owner.Name.EndsWith($"/MI_BPTile/{export.Name}", StringComparison.OrdinalIgnoreCase))):
{
Application.Current.Dispatcher.Invoke(delegate
{
var modelViewer = Helper.GetWindow<ModelViewer>("Model Viewer", () => new ModelViewer().Show());
modelViewer.Load(export);
});
var snooper = new Snooper(export);
snooper.Run();
return true;
}
case UMaterialInstance m when ModelIsOverwritingMaterial:
Expand Down
34 changes: 34 additions & 0 deletions FModel/Views/Snooper/BufferObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Silk.NET.OpenGL;

namespace FModel.Views.Snooper;

public class BufferObject<TDataType> : IDisposable where TDataType : unmanaged
{
private uint _handle;
private BufferTargetARB _bufferType;
private GL _gl;

public unsafe BufferObject(GL gl, Span<TDataType> data, BufferTargetARB bufferType)
{
_gl = gl;
_bufferType = bufferType;

_handle = _gl.GenBuffer();
Bind();
fixed (void* d = data)
{
_gl.BufferData(bufferType, (nuint) (data.Length * sizeof(TDataType)), d, BufferUsageARB.StaticDraw);
}
}

public void Bind()
{
_gl.BindBuffer(_bufferType, _handle);
}

public void Dispose()
{
_gl.DeleteBuffer(_handle);
}
}
142 changes: 142 additions & 0 deletions FModel/Views/Snooper/Shader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
using System;
using System.Numerics;
using Silk.NET.OpenGL;

namespace FModel.Views.Snooper;

public class Shader : IDisposable
{
private uint _handle;
private GL _gl;

private readonly string VertexShaderSource = @"
#version 330 core
layout (location = 0) in vec3 vPos;
layout (location = 1) in vec3 vNormal;
layout (location = 2) in vec2 vTexCoords;
uniform mat4 uModel;
uniform mat4 uView;
uniform mat4 uProjection;
out vec3 fNormal;
out vec3 fPos;
out vec2 fTexCoords;
void main()
{
//Multiplying our uniform with the vertex position, the multiplication order here does matter.
gl_Position = uProjection * uView * uModel * vec4(vPos, 1.0);
//We want to know the fragment's position in World space, so we multiply ONLY by uModel and not uView or uProjection
fPos = vec3(uModel * vec4(vPos, 1.0));
//The Normal needs to be in World space too, but needs to account for Scaling of the object
fNormal = mat3(transpose(inverse(uModel))) * vNormal;
//Pass the texture coordinates straight through to the fragment shader
fTexCoords = vTexCoords;
}
";

private readonly string FragmentShaderSource = @"
#version 330 core
in vec3 fNormal;
in vec3 fPos;
in vec2 fTexCoords;
uniform vec3 viewPos;
out vec4 FragColor;
void main()
{
vec3 viewDirection = normalize(viewPos - fPos);
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
}
";

public Shader(GL gl)
{
_gl = gl;

uint vertex = LoadShader(ShaderType.VertexShader, VertexShaderSource);
uint fragment = LoadShader(ShaderType.FragmentShader, FragmentShaderSource);
_handle = _gl.CreateProgram();
_gl.AttachShader(_handle, vertex);
_gl.AttachShader(_handle, fragment);
_gl.LinkProgram(_handle);
_gl.GetProgram(_handle, GLEnum.LinkStatus, out var status);
if (status == 0)
{
throw new Exception($"Program failed to link with error: {_gl.GetProgramInfoLog(_handle)}");
}
_gl.DetachShader(_handle, vertex);
_gl.DetachShader(_handle, fragment);
_gl.DeleteShader(vertex);
_gl.DeleteShader(fragment);
}

public void Use()
{
_gl.UseProgram(_handle);
}

public void SetUniform(string name, int value)
{
int location = _gl.GetUniformLocation(_handle, name);
if (location == -1)
{
throw new Exception($"{name} uniform not found on shader.");
}
_gl.Uniform1(location, value);
}

public unsafe void SetUniform(string name, Matrix4x4 value)
{
//A new overload has been created for setting a uniform so we can use the transform in our shader.
int location = _gl.GetUniformLocation(_handle, name);
if (location == -1)
{
throw new Exception($"{name} uniform not found on shader.");
}
_gl.UniformMatrix4(location, 1, false, (float*) &value);
}

public void SetUniform(string name, float value)
{
int location = _gl.GetUniformLocation(_handle, name);
if (location == -1)
{
throw new Exception($"{name} uniform not found on shader.");
}
_gl.Uniform1(location, value);
}

public void SetUniform(string name, Vector3 value)
{
int location = _gl.GetUniformLocation(_handle, name);
if (location == -1)
{
throw new Exception($"{name} uniform not found on shader.");
}
_gl.Uniform3(location, value.X, value.Y, value.Z);
}

public void Dispose()
{
_gl.DeleteProgram(_handle);
}

private uint LoadShader(ShaderType type, string content)
{
uint handle = _gl.CreateShader(type);
_gl.ShaderSource(handle, content);
_gl.CompileShader(handle);
string infoLog = _gl.GetShaderInfoLog(handle);
if (!string.IsNullOrWhiteSpace(infoLog))
{
throw new Exception($"Error compiling shader of type {type}, failed with error {infoLog}");
}

return handle;
}
}
Loading

0 comments on commit 2c0fee3

Please sign in to comment.