Skip to content

Commit

Permalink
fixed EULER rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Nov 4, 2022
1 parent 2f3b076 commit 481078c
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 29 deletions.
4 changes: 2 additions & 2 deletions FModel/FModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<UseWPF>true</UseWPF>
<ApplicationIcon>FModel.ico</ApplicationIcon>
<Version>4.3.2</Version>
<AssemblyVersion>4.3.2.0</AssemblyVersion>
<FileVersion>4.3.2.0</FileVersion>
<AssemblyVersion>4.3.2.1</AssemblyVersion>
<FileVersion>4.3.2.1</FileVersion>
<IsPackable>false</IsPackable>
<IsPublishable>true</IsPublishable>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
Expand Down
2 changes: 1 addition & 1 deletion FModel/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private async void OnLoaded(object sender, RoutedEventArgs e)
#if DEBUG
await _threadWorkerView.Begin(cancellationToken =>
_applicationView.CUE4Parse.Extract(cancellationToken,
"FortniteGame/Content/Athena/Artemis/Maps/Buildings/15x25/Artemis_Blimp_party.umap"));
"FortniteGame/Content/Athena/Artemis/Maps/Buildings/5x5/Artemis_5x5_Shop_AB.umap"));
#endif
}

Expand Down
11 changes: 11 additions & 0 deletions FModel/Views/Snooper/Material.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CUE4Parse.UE4.Assets.Exports.Material;
using CUE4Parse.UE4.Assets.Exports.Texture;
using OpenTK.Graphics.OpenGL4;
Expand Down Expand Up @@ -117,11 +118,21 @@ private void Fill(Cache cache, int numTexCoords, ref Texture[] array, bool top,
array[i] = array[i - 1];
}
}
else if (Parameters.Colors.TryGetValue("Color", out var linearColor)) // POC
{
for (int i = 0; i < array.Length; i++)
array[i] = new Texture(linearColor);
}
else if (Parameters.Textures.TryGetValue(fallback, out var u) && u is UTexture2D o && cache.TryGetCachedTexture(o, out var t))
{
for (int i = 0; i < array.Length; i++)
array[i] = t;
}
else if (Parameters.Textures.First() is { Value: UTexture2D d } && cache.TryGetCachedTexture(d, out var rip))
{
for (int i = 0; i < array.Length; i++)
array[i] = rip;
}
}

public void Render(Shader shader)
Expand Down
25 changes: 19 additions & 6 deletions FModel/Views/Snooper/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void Render(Camera cam)

private Camera SetupCamera(FBox box)
{
var far = Math.Abs(box.Max.Max());
var far = box.Max.AbsMax();
var center = box.GetCenter();
return new Camera(
new Vector3(0f, center.Z, box.Max.Y * 3),
Expand Down Expand Up @@ -151,8 +151,22 @@ private Camera LoadWorld(CancellationToken cancellationToken, UWorld original)
{
cancellationToken.ThrowIfCancellationRequested();

if (persistentLevel.Actors[i].Load() is not { } actor ||actor.ExportType == "LODActor" ||
!actor.TryGetValue(out FPackageIndex staticMeshComponent, "StaticMeshComponent", "Mesh") ||
if (persistentLevel.Actors[i].Load() is not { } actor || actor.ExportType == "LODActor") continue;

if (actor.ExportType == "LevelBounds" && actor.TryGetValue(out FPackageIndex boxComponent, "BoxComponent") &&
boxComponent.Load() is { } boxObject && boxObject.TryGetValue(out FVector relativeLocation, "RelativeLocation") &&
boxObject.TryGetValue(out FVector relativeScale3D, "RelativeScale3D"))
{
var direction = relativeLocation.ToMapVector() * Constants.SCALE_DOWN_RATIO;
var position = relativeScale3D.ToMapVector() / 2f * Constants.SCALE_DOWN_RATIO;
var far = position.AbsMax();
ret = new Camera(
new Vector3(position.X, position.Y, position.Z),
new Vector3(direction.X, direction.Y, direction.Z),
0.01f, far * 25f, far / 10f);
}

if (!actor.TryGetValue(out FPackageIndex staticMeshComponent, "StaticMeshComponent", "Mesh") ||
staticMeshComponent.Load() is not { } staticMeshComp) continue;

if (!staticMeshComp.TryGetValue(out FPackageIndex staticMesh, "StaticMesh") && actor.Class is UBlueprintGeneratedClass)
Expand All @@ -167,11 +181,10 @@ private Camera LoadWorld(CancellationToken cancellationToken, UWorld original)
var guid = m.LightingGuid;
var transform = new Transform
{
Position = staticMeshComp.GetOrDefault("RelativeLocation", FVector.ZeroVector) * Constants.SCALE_DOWN_RATIO,
Position = staticMeshComp.GetOrDefault("RelativeLocation", FVector.ZeroVector).ToMapVector() * Constants.SCALE_DOWN_RATIO,
Rotation = staticMeshComp.GetOrDefault("RelativeRotation", FRotator.ZeroRotator),
Scale = staticMeshComp.GetOrDefault("RelativeScale3D", FVector.OneVector)
Scale = staticMeshComp.GetOrDefault("RelativeScale3D", FVector.OneVector).ToMapVector()
};
transform.Rotation.Yaw = -transform.Rotation.Yaw;

if (Cache.Models.TryGetValue(guid, out var model))
{
Expand Down
41 changes: 31 additions & 10 deletions FModel/Views/Snooper/SnimGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public void Render(Snooper s)

ImGui.Begin("Camera");
ImGui.DragFloat("Speed", ref s.Camera.Speed, 0.01f);
ImGui.DragFloat("Near", ref s.Camera.Near, 0.1f, 0.01f, s.Camera.Far - 0.1f, "%.2f m", ImGuiSliderFlags.AlwaysClamp);
ImGui.DragFloat("Far", ref s.Camera.Far, 0.1f, s.Camera.Near + 0.1f, 0f, "%.2f m", ImGuiSliderFlags.AlwaysClamp);
ImGui.DragFloat("Far Plane", ref s.Camera.Far, 0.1f, 5f, s.Camera.Far * 2f, "%.2f m", ImGuiSliderFlags.AlwaysClamp);
ImGui.End();
ImGui.Begin("World");
ImGui.End();
Expand Down Expand Up @@ -175,7 +174,7 @@ private void DrawDetails(Snooper s)
if (ImGui.Button("Go To"))
{
var instancePos = model.Transforms[model.SelectedInstance].Position;
s.Camera.Position = new Vector3(instancePos.X, instancePos.Z, instancePos.Y);
s.Camera.Position = new Vector3(instancePos.X, instancePos.Y, instancePos.Z);
}
ImGui.NextColumn(); ImGui.Checkbox("Show", ref model.Show);
ImGui.NextColumn(); ImGui.BeginDisabled(!model.Show); ImGui.Checkbox("Wire", ref model.Wireframe); ImGui.EndDisabled();
Expand Down Expand Up @@ -290,6 +289,8 @@ private void DrawDetails(Snooper s)
ImGui.SameLine(); ImGui.PushID(99);
ImGui.VSliderFloat("", box with { X = width }, ref model.MorphTime, 0.0f, 1.0f, "", ImGuiSliderFlags.AlwaysClamp);
ImGui.PopID(); ImGui.PopStyleVar();
ImGui.Spacing();
ImGui.Text($"Time: {model.MorphTime:P}%");
}
}
else
Expand Down Expand Up @@ -330,10 +331,10 @@ private void DrawTransform(Snooper s)
ImGui.DragFloat("X", ref model.Transforms[model.SelectedInstance].Position.X, speed, 0f, 0f, "%.2f m");

ImGui.SetNextItemWidth(width);
ImGui.DragFloat("Y", ref model.Transforms[model.SelectedInstance].Position.Y, speed, 0f, 0f, "%.2f m");
ImGui.DragFloat("Y", ref model.Transforms[model.SelectedInstance].Position.Z, speed, 0f, 0f, "%.2f m");

ImGui.SetNextItemWidth(width);
ImGui.DragFloat("Z", ref model.Transforms[model.SelectedInstance].Position.Z, speed, 0f, 0f, "%.2f m");
ImGui.DragFloat("Z", ref model.Transforms[model.SelectedInstance].Position.Y, speed, 0f, 0f, "%.2f m");

ImGui.PopID();
ImGui.TreePop();
Expand All @@ -344,10 +345,10 @@ private void DrawTransform(Snooper s)
{
ImGui.PushID(2);
ImGui.SetNextItemWidth(width);
ImGui.DragFloat("X", ref model.Transforms[model.SelectedInstance].Rotation.Pitch, .5f, 0f, 0f, "%.1f°");
ImGui.DragFloat("X", ref model.Transforms[model.SelectedInstance].Rotation.Roll, .5f, 0f, 0f, "%.1f°");

ImGui.SetNextItemWidth(width);
ImGui.DragFloat("Y", ref model.Transforms[model.SelectedInstance].Rotation.Roll, .5f, 0f, 0f, "%.1f°");
ImGui.DragFloat("Y", ref model.Transforms[model.SelectedInstance].Rotation.Pitch, .5f, 0f, 0f, "%.1f°");

ImGui.SetNextItemWidth(width);
ImGui.DragFloat("Z", ref model.Transforms[model.SelectedInstance].Rotation.Yaw, .5f, 0f, 0f, "%.1f°");
Expand All @@ -363,10 +364,10 @@ private void DrawTransform(Snooper s)
ImGui.DragFloat("X", ref model.Transforms[model.SelectedInstance].Scale.X, speed, 0f, 0f, "%.3f");

ImGui.SetNextItemWidth(width);
ImGui.DragFloat("Y", ref model.Transforms[model.SelectedInstance].Scale.Y, speed, 0f, 0f, "%.3f");
ImGui.DragFloat("Y", ref model.Transforms[model.SelectedInstance].Scale.Z, speed, 0f, 0f, "%.3f");

ImGui.SetNextItemWidth(width);
ImGui.DragFloat("Z", ref model.Transforms[model.SelectedInstance].Scale.Z, speed, 0f, 0f, "%.3f");
ImGui.DragFloat("Z", ref model.Transforms[model.SelectedInstance].Scale.Y, speed, 0f, 0f, "%.3f");

ImGui.PopID();
ImGui.TreePop();
Expand Down Expand Up @@ -496,8 +497,28 @@ private void TextColored(Vector4 color, string text)
ImGui.TextColored(color, text);
}

private void DrawSquareTexture(Texture texture, Vector2 size) =>
private void DrawSquareTexture(Texture texture, Vector2 size)
{
ImGui.Image(texture?.GetPointer() ?? IntPtr.Zero, size, Vector2.Zero, Vector2.One, Vector4.One, new Vector4(1, 1, 1, .5f));
if (texture == null) return;

if (ImGui.IsItemHovered())
{
ImGui.BeginTooltip();
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();
ImGui.TextDisabled(texture.Label);
ImGui.EndTooltip();
}
if (ImGui.IsItemClicked())
{
ImGui.SetClipboardText(Creator.Utils.FixPath(texture.Path));
texture.Label = "(?) Path Copied to Clipboard";
}
}

private void Theme(ImGuiStylePtr style)
{
Expand Down
19 changes: 18 additions & 1 deletion FModel/Views/Snooper/Texture.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Windows;
using CUE4Parse.UE4.Assets.Exports.Texture;
using CUE4Parse.UE4.Objects.Core.Math;
using OpenTK.Graphics.OpenGL4;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SkiaSharp;

namespace FModel.Views.Snooper;

Expand Down Expand Up @@ -90,6 +90,23 @@ public Texture(byte[] data, int width, int height, UTexture2D texture2D) : this(
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
}

public Texture(FLinearColor color) : this(TextureType.Normal)
{
Type = "LinearColor";
Name = color.Hex;
Width = 1;
Height = 1;
Bind(TextureUnit.Texture0);

GL.TexImage2D(_target, 0, PixelInternalFormat.Rgba, Width, Height, 0, PixelFormat.Rgba, PixelType.Float, ref color);
GL.TexParameter(_target, TextureParameterName.TextureMinFilter, (int) TextureMinFilter.LinearMipmapLinear);
GL.TexParameter(_target, TextureParameterName.TextureMagFilter, (int) TextureMinFilter.Linear);
GL.TexParameter(_target, TextureParameterName.TextureBaseLevel, 0);
GL.TexParameter(_target, TextureParameterName.TextureMaxLevel, 8);

GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
}

public Texture(string[] textures) : this(TextureType.Cubemap)
{
Bind(TextureUnit.Texture0);
Expand Down
14 changes: 6 additions & 8 deletions FModel/Views/Snooper/Transform.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Numerics;
using System.Numerics;
using CUE4Parse.UE4.Objects.Core.Math;

namespace FModel.Views.Snooper;
Expand All @@ -10,16 +10,14 @@ public static Transform Identity
get => new ();
}

public FVector Position = FVector.ZeroVector;
public FVector Position = FVector.ZeroVector.ToMapVector();
public FRotator Rotation = FRotator.ZeroRotator;
public FVector Scale = FVector.OneVector;
public FVector Scale = FVector.OneVector.ToMapVector();

public Matrix4x4 Matrix =>
Matrix4x4.Identity *
Matrix4x4.CreateFromYawPitchRoll(
Helper.DegreesToRadians(Rotation.Yaw),
Helper.DegreesToRadians(Rotation.Pitch),
Helper.DegreesToRadians(Rotation.Roll)) *
Matrix4x4.CreateScale(Scale) *
Matrix4x4.CreateRotationX(Helper.DegreesToRadians(Rotation.Roll)) *
Matrix4x4.CreateRotationY(Helper.DegreesToRadians(-Rotation.Yaw)) *
Matrix4x4.CreateRotationZ(Helper.DegreesToRadians(Rotation.Pitch)) *
Matrix4x4.CreateTranslation(Position);
}

0 comments on commit 481078c

Please sign in to comment.