Skip to content

Commit

Permalink
FModel v4.4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Oct 20, 2024
1 parent f266cd4 commit c6c8cf2
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 9 deletions.
4 changes: 2 additions & 2 deletions FModel/Creator/Bases/FN/BasePlaylist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void ParseForInfo()
return;

var playlist = _apiEndpointView.FortniteApi.GetPlaylist(playlistName.Text);
if (!playlist.IsSuccess || !playlist.Data.Images.HasShowcase ||
if (!playlist.IsSuccess || playlist.Data.Images is not { HasShowcase: true } ||
!_apiEndpointView.FortniteApi.TryGetBytes(playlist.Data.Images.Showcase, out var image))
return;

Expand Down Expand Up @@ -74,4 +74,4 @@ private void DrawMissionIcon(SKCanvas c)
if (_missionIcon == null) return;
c.DrawBitmap(_missionIcon, new SKPoint(5, 5), ImagePaint);
}
}
}
6 changes: 3 additions & 3 deletions FModel/FModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<TargetFramework>net8.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<ApplicationIcon>FModel.ico</ApplicationIcon>
<Version>4.4.3.6</Version>
<AssemblyVersion>4.4.3.6</AssemblyVersion>
<FileVersion>4.4.3.6</FileVersion>
<Version>4.4.4.0</Version>
<AssemblyVersion>4.4.4.0</AssemblyVersion>
<FileVersion>4.4.4.0</FileVersion>
<IsPackable>false</IsPackable>
<IsPublishable>true</IsPublishable>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
Expand Down
1 change: 1 addition & 0 deletions FModel/ViewModels/CUE4ParseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ public void ExtractAndScroll(CancellationToken cancellationToken, string fullPat
"JunoBuildingPropAccountItemDefinition" => true,
_ => false
}:
case UPaperSprite when isNone && UserSettings.Default.PreviewMaterials:
case UStaticMesh when isNone && UserSettings.Default.PreviewStaticMeshes:
case USkeletalMesh when isNone && UserSettings.Default.PreviewSkeletalMeshes:
case USkeleton when isNone && UserSettings.Default.SaveSkeletonAsMesh:
Expand Down
5 changes: 5 additions & 0 deletions FModel/ViewModels/TabControlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ private void SetImage(SKBitmap bitmap)
Image = null;
return;
}

_bmp = bitmap;
using var data = _bmp.Encode(NoAlpha ? ETextureFormat.Jpeg : UserSettings.Default.TextureExportFormat, 100);
using var stream = new MemoryStream(ImageBuffer = data.ToArray(), false);
if (UserSettings.Default.TextureExportFormat == ETextureFormat.Tga)
return;

var image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
Expand Down Expand Up @@ -305,6 +309,7 @@ private void SaveImage(TabImage image, bool updateUi)
var ext = UserSettings.Default.TextureExportFormat switch
{
ETextureFormat.Png => ".png",
ETextureFormat.Jpeg => ".jpg",
ETextureFormat.Tga => ".tga",
_ => ".png"
};
Expand Down
58 changes: 57 additions & 1 deletion FModel/Views/Snooper/Models/StaticModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System.Numerics;
using System;
using System.Numerics;
using CUE4Parse_Conversion.Meshes.PSK;
using CUE4Parse.UE4.Assets.Exports.Material;
using CUE4Parse.UE4.Assets.Exports.StaticMesh;
using CUE4Parse.UE4.Assets.Exports.Texture;
using CUE4Parse.UE4.Objects.Core.Math;
using CUE4Parse.UE4.Objects.PhysicsEngine;
using FModel.Views.Snooper.Shading;
using OpenTK.Graphics.OpenGL4;
Expand Down Expand Up @@ -52,6 +55,59 @@ public StaticModel(UMaterialInterface unrealMaterial, CStaticMesh staticMesh) :
Box = staticMesh.BoundingBox * 1.5f * Constants.SCALE_DOWN_RATIO;
}

public StaticModel(UPaperSprite paperSprite, UTexture2D texture) : base(paperSprite)
{
Indices = new uint[paperSprite.BakedRenderData.Length];
for (int i = 0; i < Indices.Length; i++)
{
Indices[i] = (uint) i;
}

Vertices = new float[paperSprite.BakedRenderData.Length * VertexSize];
for (int i = 0; i < paperSprite.BakedRenderData.Length; i++)
{
var count = 0;
var baseIndex = i * VertexSize;
var vert = paperSprite.BakedRenderData[i];
var u = vert.Z;
var v = vert.W;

Vertices[baseIndex + count++] = i;
Vertices[baseIndex + count++] = vert.X * paperSprite.PixelsPerUnrealUnit * Constants.SCALE_DOWN_RATIO;
Vertices[baseIndex + count++] = vert.Y * paperSprite.PixelsPerUnrealUnit * Constants.SCALE_DOWN_RATIO;
Vertices[baseIndex + count++] = 0;
Vertices[baseIndex + count++] = 0;
Vertices[baseIndex + count++] = 0;
Vertices[baseIndex + count++] = 0;
Vertices[baseIndex + count++] = 0;
Vertices[baseIndex + count++] = 0;
Vertices[baseIndex + count++] = 0;
Vertices[baseIndex + count++] = u;
Vertices[baseIndex + count++] = v;
Vertices[baseIndex + count++] = .5f;
}

Materials = new Material[1];
if (paperSprite.DefaultMaterial?.TryLoad(out UMaterialInstance unrealMaterial) ?? false)
{
Materials[0] = new Material(unrealMaterial);
}
else
{
Materials[0] = new Material();
}
Materials[0].Parameters.Textures[CMaterialParams2.FallbackDiffuse] = texture;
Materials[0].IsUsed = true;

Sections = new Section[1];
Sections[0] = new Section(0, Indices.Length, 0);

AddInstance(Transform.Identity);

var backward = new FVector(0, Math.Max(paperSprite.BakedSourceDimension.X, paperSprite.BakedSourceDimension.Y) / 2, 0);
Box = new FBox(-backward, backward) * Constants.SCALE_DOWN_RATIO;
}

public StaticModel(UStaticMesh export, CStaticMesh staticMesh, Transform transform = null)
: base(export, staticMesh.LODs[LodLevel], export.Materials, staticMesh.LODs[LodLevel].Verts, staticMesh.LODs.Count, transform)
{
Expand Down
20 changes: 20 additions & 0 deletions FModel/Views/Snooper/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public void Load(CancellationToken cancellationToken, UObject export)
LoadJunoWorld(cancellationToken, bp, Transform.Identity);
Color = VertexColor.Colors;
break;
case UPaperSprite ps:
LoadPaperSprite(ps);
break;
}
CameraOp.Mode = _saveCameraMode ? UserSettings.Default.CameraMode : Camera.WorldMode.FlyCam;
SetupCamera();
Expand Down Expand Up @@ -397,6 +400,23 @@ private void LoadMaterialInstance(UMaterialInstance original)
Options.SelectModel(guid);
}

private void LoadPaperSprite(UPaperSprite original)
{
if (!(original.BakedSourceTexture?.TryLoad(out UTexture2D texture) ?? false))
return;

var guid = texture.LightingGuid;
if (Options.TryGetModel(guid, out var model))
{
model.AddInstance(Transform.Identity);
Application.Current.Dispatcher.Invoke(() => model.SetupInstances());
return;
}

Options.Models[guid] = new StaticModel(original, texture);
Options.SelectModel(guid);
}

private void SetupCamera()
{
if (Options.TryGetModel(out var model))
Expand Down
4 changes: 2 additions & 2 deletions FModel/Views/Snooper/SnimGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,8 +1014,8 @@ private void Theme()
style.Colors[(int) ImGuiCol.Tab] = new Vector4(0.15f, 0.15f, 0.19f, 1.00f);
style.Colors[(int) ImGuiCol.TabHovered] = new Vector4(0.35f, 0.35f, 0.41f, 0.80f);
style.Colors[(int) ImGuiCol.TabSelected] = new Vector4(0.23f, 0.24f, 0.29f, 1.00f);
style.Colors[(int) ImGuiCol.TabSelectedOverline] = new Vector4(0.15f, 0.15f, 0.15f, 1.00f);
style.Colors[(int) ImGuiCol.TabDimmed] = new Vector4(0.23f, 0.24f, 0.29f, 1.00f);
style.Colors[(int) ImGuiCol.TabDimmed] = new Vector4(0.15f, 0.15f, 0.15f, 1.00f);
style.Colors[(int) ImGuiCol.TabDimmedSelected] = new Vector4(0.23f, 0.24f, 0.29f, 1.00f);
style.Colors[(int) ImGuiCol.DockingPreview] = new Vector4(0.26f, 0.59f, 0.98f, 0.70f);
style.Colors[(int) ImGuiCol.DockingEmptyBg] = new Vector4(0.20f, 0.20f, 0.20f, 1.00f);
style.Colors[(int) ImGuiCol.PlotLines] = new Vector4(0.61f, 0.61f, 0.61f, 1.00f);
Expand Down

0 comments on commit c6c8cf2

Please sign in to comment.