Skip to content

Commit

Permalink
docking gets saved now wtf
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Oct 30, 2022
1 parent c6dcd92 commit 4e321d7
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 107 deletions.
5 changes: 4 additions & 1 deletion FModel/Framework/ImGuiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ public ImGuiController(int width, int height)
IntPtr context = ImGui.CreateContext();
ImGui.SetCurrentContext(context);
var io = ImGui.GetIO();
io.Fonts.AddFontDefault();
// io.Fonts.AddFontDefault();
io.Fonts.AddFontFromFileTTF("C:\\Windows\\Fonts\\segoeui.ttf", 16);

io.BackendFlags |= ImGuiBackendFlags.RendererHasVtxOffset;
io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard;
io.ConfigFlags |= ImGuiConfigFlags.DockingEnable;
io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable;

CreateDeviceResources();
SetKeyMappings();
Expand Down
4 changes: 0 additions & 4 deletions FModel/Views/Snooper/FramebufferObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ public void BindMsaa()
GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, _framebufferHandle);
GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, _postProcessingHandle);
GL.BlitFramebuffer(0, 0, _width, _height, 0, 0, _width, _height, ClearBufferMask.ColorBufferBit, BlitFramebufferFilter.Nearest);
}

public void BindStuff()
{
GL.Disable(EnableCap.DepthTest);

_shader.Use();
Expand Down
131 changes: 65 additions & 66 deletions FModel/Views/Snooper/Material.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public class Material : IDisposable
{
private int _handle;

private Vector3 _ambientLight;

public readonly CMaterialParams2 Parameters;
public readonly int UvNumber;
public bool IsUsed;
Expand All @@ -28,18 +26,29 @@ public class Material : IDisposable
public bool HasSpecularMap;
public bool HasDiffuseColor;

public Material()
private Vector3 _ambientLight;

public Material(int numUvs)
{
Parameters = new CMaterialParams2();
UvNumber = 1;
UvNumber = numUvs;
IsUsed = false;

Diffuse = Array.Empty<Texture>();
Normals = Array.Empty<Texture>();
SpecularMasks = Array.Empty<Texture>();
Emissive = Array.Empty<Texture>();

DiffuseColor = Vector4.Zero;
EmissionColor = Array.Empty<Vector4>();
IsUsed = false;
HasSpecularMap = false;
HasDiffuseColor = false;

_ambientLight = Vector3.One;
}

public Material(int numUvs, UMaterialInterface unrealMaterial) : this()
public Material(int numUvs, UMaterialInterface unrealMaterial) : this(numUvs)
{
UvNumber = numUvs;
SwapMaterial(unrealMaterial);
}

Expand All @@ -52,72 +61,62 @@ public void Setup(Cache cache)
{
_handle = GL.CreateProgram();

int index;
var platform = UserSettings.Default.OverridedPlatform;
void Add(Texture[] array, UTexture2D original)
{
var guid = original.LightingGuid;
if (cache.TryGetTexture(guid, out var texture))
{
array[index] = texture;
}
else if (original.GetFirstMip() is { } mip)
{
TextureDecoder.DecodeTexture(mip, original.Format, original.isNormalMap, platform, out var data, out _);

var t = new Texture(data, mip.SizeX, mip.SizeY, original);
cache.AddTexture(guid, t);
array[index] = t;
}
}

index = 0;
Diffuse = new Texture[UvNumber];
foreach (var d in Parameters.GetDiffuseTextures())
{
if (index < UvNumber && d is UTexture2D original)
Add(Diffuse, original);
index++;
}

index = 0;
Normals = new Texture[UvNumber];
foreach (var n in Parameters.GetNormalsTextures())
if (Parameters.IsNull)
{
if (index < UvNumber && n is UTexture2D original)
Add(Normals, original);
index++;
DiffuseColor = new Vector4(1, 0, 0, 1);
}

index = 0;
SpecularMasks = new Texture[UvNumber];
foreach (var s in Parameters.GetSpecularMasksTextures())
else
{
if (index < UvNumber && s is UTexture2D original)
Add(SpecularMasks, original);
index++;
}

index = 0;
Emissive = new Texture[UvNumber];
EmissionColor = new Vector4[UvNumber];
foreach (var e in Parameters.GetEmissiveTextures())
{
if (index < UvNumber && e is UTexture2D original)
var platform = UserSettings.Default.OverridedPlatform;
bool TryGetCached(UTexture2D o, out Texture t)
{
if (Parameters.TryGetLinearColor(out var color, $"Emissive{(index > 0 ? index + 1 : "")}") && color is { A: > 0})
EmissionColor[index] = new Vector4(color.R, color.G, color.B, color.A);
else EmissionColor[index] = Vector4.One;

Add(Emissive, original);
var guid = o.LightingGuid;
if (!cache.TryGetTexture(guid, out t))
{
if (o.GetFirstMip() is { } mip)
{
TextureDecoder.DecodeTexture(mip, o.Format, o.isNormalMap, platform, out var data, out _);

t = new Texture(data, mip.SizeX, mip.SizeY, o);
cache.AddTexture(guid, t);
}
else t = null;
}
return t != null;
}
else if (index < UvNumber) EmissionColor[index] = Vector4.Zero;
index++;

Diffuse = new Texture[UvNumber];
for (int i = 0; i < Diffuse.Length; i++)
if (Parameters.TryGetTexture2d(out var o, CMaterialParams2.Diffuse[i]) && TryGetCached(o, out var t))
Diffuse[i] = t;

Normals = new Texture[UvNumber];
for (int i = 0; i < Normals.Length; i++)
if (Parameters.TryGetTexture2d(out var o, CMaterialParams2.Normals[i]) && TryGetCached(o, out var t))
Normals[i] = t;

SpecularMasks = new Texture[UvNumber];
for (int i = 0; i < SpecularMasks.Length; i++)
if (Parameters.TryGetTexture2d(out var o, CMaterialParams2.SpecularMasks[i]) && TryGetCached(o, out var t))
SpecularMasks[i] = t;

Emissive = new Texture[UvNumber];
EmissionColor = new Vector4[UvNumber];
for (int i = 0; i < Emissive.Length; i++)
if (Parameters.TryGetTexture2d(out var o, CMaterialParams2.Emissive[i]) && TryGetCached(o, out var t))
{
Emissive[i] = t;

if (Parameters.TryGetLinearColor(out var color, $"Emissive{(i > 0 ? i + 1 : "")}") && color is { A: > 0})
EmissionColor[i] = new Vector4(color.R, color.G, color.B, color.A);
else EmissionColor[i] = Vector4.One;
}

// diffuse light is based on normal map, so increase ambient if no normal map
_ambientLight = new Vector3(Normals[0] == null ? 1.0f : 0.2f);
HasSpecularMap = SpecularMasks[0] != null;
}

// diffuse light is based on normal map, so increase ambient if no normal map
_ambientLight = new Vector3(Normals[0] == null ? 1.0f : 0.2f);
HasSpecularMap = SpecularMasks[0] != null;
HasDiffuseColor = DiffuseColor != Vector4.Zero;
}

Expand Down
5 changes: 2 additions & 3 deletions FModel/Views/Snooper/Model.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private Model(string name, string type, ResolvedObject[] materials, CBaseMeshLod
{
if ((materials[m]?.TryLoad(out var material) ?? false) && material is UMaterialInterface unrealMaterial)
Materials[m] = new Material(lod.NumTexCoords, unrealMaterial); // lod.NumTexCoords
else Materials[m] = new Material();
else Materials[m] = new Material(1);
}

if (lod.VertexColors is { Length: > 0})
Expand All @@ -104,8 +104,7 @@ private Model(string name, string type, ResolvedObject[] materials, CBaseMeshLod
for (var s = 0; s < sections.Length; s++)
{
var section = sections[s];
Materials[section.MaterialIndex].IsUsed = true;
Sections[s] = new Section(section.MaterialIndex, section.NumFaces * _faceSize, section.FirstIndex);
Sections[s] = new Section(section.MaterialIndex, section.NumFaces * _faceSize, section.FirstIndex, Materials[section.MaterialIndex]);
for (uint face = 0; face < section.NumFaces; face++)
{
foreach (var f in _facesIndex)
Expand Down
11 changes: 3 additions & 8 deletions FModel/Views/Snooper/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ public void Render(Camera cam)
_shader.SetUniform("uProjection", projMatrix);
_shader.SetUniform("viewPos", cam.Position);

// _shader.SetUniform("material.diffuseMap", 0);
// _shader.SetUniform("material.normalMap", 1);
// _shader.SetUniform("material.specularMap", 2);
// _shader.SetUniform("material.emissionMap", 3);

_shader.SetUniform("light.position", cam.Position);
_shader.SetUniform("light.diffuse", _diffuseLight);
_shader.SetUniform("light.specular", _specularLight);
Expand Down Expand Up @@ -191,13 +186,13 @@ private Camera LoadWorld(CancellationToken cancellationToken, UWorld original)

if (textureDataIdx.TryGetValue(out FPackageIndex diffuse, "Diffuse") &&
diffuse.Load() is UTexture2D diffuseTexture)
model.Materials[model.Sections[j].MaterialIndex].Parameters.Textures[CMaterialParams2.Diffuse[0]] = diffuseTexture;
model.Materials[model.Sections[j].MaterialIndex].Parameters.Textures[CMaterialParams2.Diffuse[0][0]] = diffuseTexture;
if (textureDataIdx.TryGetValue(out FPackageIndex normal, "Normal") &&
normal.Load() is UTexture2D normalTexture)
model.Materials[model.Sections[j].MaterialIndex].Parameters.Textures[CMaterialParams2.Normals[0]] = normalTexture;
model.Materials[model.Sections[j].MaterialIndex].Parameters.Textures[CMaterialParams2.Normals[0][0]] = normalTexture;
if (textureDataIdx.TryGetValue(out FPackageIndex specular, "Specular") &&
specular.Load() is UTexture2D specularTexture)
model.Materials[model.Sections[j].MaterialIndex].Parameters.Textures[CMaterialParams2.SpecularMasks[0]] = specularTexture;
model.Materials[model.Sections[j].MaterialIndex].Parameters.Textures[CMaterialParams2.SpecularMasks[0][0]] = specularTexture;
}
}
if (staticMeshComp.TryGetValue(out FPackageIndex[] overrideMaterials, "OverrideMaterials"))
Expand Down
6 changes: 6 additions & 0 deletions FModel/Views/Snooper/Section.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public Section(int index, int facesCount, int firstFaceIndex)
Show = true;
}

public Section(int index, int facesCount, int firstFaceIndex, Material material) : this(index, facesCount, firstFaceIndex)
{
material.IsUsed = true;
Show = !material.Parameters.IsNull && !material.Parameters.IsTransparent;
}

public void Setup()
{
_handle = GL.CreateProgram();
Expand Down
Loading

0 comments on commit 4e321d7

Please sign in to comment.