mirror of
https://github.com/4sval/FModel.git
synced 2026-06-21 07:20:05 -05:00
fixed crash if model viewer was closed
This commit is contained in:
parent
177ae1dc0a
commit
8cafa960e1
|
|
@ -85,4 +85,4 @@ namespace FModel
|
|||
return -d < n && d > n;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ namespace FModel.ViewModels
|
|||
public SearchViewModel SearchVm { get; }
|
||||
public TabControlViewModel TabControl { get; }
|
||||
public int LocalizedResourcesCount { get; set; }
|
||||
public bool HotfixedResourcesDone { get; set; } = false;
|
||||
public int VirtualPathCount { get; set; }
|
||||
|
||||
public CUE4ParseViewModel(string gameDirectory)
|
||||
|
|
@ -354,13 +355,13 @@ namespace FModel.ViewModels
|
|||
{
|
||||
if (Game != FGame.FortniteGame) return;
|
||||
|
||||
var i = 0;
|
||||
if (LocalizedResourcesCount <= 0) return;
|
||||
if (HotfixedResourcesDone) return;
|
||||
await _threadWorkerView.Begin(cancellationToken =>
|
||||
{
|
||||
var hotfixes = ApplicationService.ApiEndpointView.BenbotApi.GetHotfixes(cancellationToken, Provider.GetLanguageCode(UserSettings.Default.AssetLanguage));
|
||||
if (hotfixes == null) return;
|
||||
|
||||
HotfixedResourcesDone = true;
|
||||
foreach (var entries in hotfixes)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
|
@ -371,12 +372,10 @@ namespace FModel.ViewModels
|
|||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
Provider.LocalizedResources[entries.Key][keyValue.Key] = keyValue.Value;
|
||||
i++;
|
||||
LocalizedResourcesCount++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
LocalizedResourcesCount += i;
|
||||
}
|
||||
|
||||
public async Task LoadVirtualPaths()
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ using HelixToolkit.Wpf.SharpDX;
|
|||
using SharpDX;
|
||||
using Camera = HelixToolkit.Wpf.SharpDX.Camera;
|
||||
using Geometry3D = HelixToolkit.SharpDX.Core.Geometry3D;
|
||||
using Material = HelixToolkit.Wpf.SharpDX.Material;
|
||||
using PerspectiveCamera = HelixToolkit.Wpf.SharpDX.PerspectiveCamera;
|
||||
|
||||
namespace FModel.ViewModels
|
||||
|
|
@ -69,19 +68,19 @@ namespace FModel.ViewModels
|
|||
get => _group3d;
|
||||
set => SetProperty(ref _group3d, value);
|
||||
}
|
||||
public Material MainMaterial { get; } = PhongMaterials.White;
|
||||
|
||||
private readonly int[] _FACES_INDEX = { 1, 0, 2 };
|
||||
|
||||
public ModelViewerViewModel()
|
||||
{
|
||||
EffectManager = new DefaultEffectsManager();
|
||||
Group3d = new ObservableElement3DCollection();
|
||||
Cam = new PerspectiveCamera { NearPlaneDistance = 0.1, FarPlaneDistance = 99999999, FieldOfView = 80 };
|
||||
}
|
||||
|
||||
public void LoadExport(UObject export)
|
||||
{
|
||||
Group3d = new ObservableElement3DCollection();
|
||||
Group3d.Clear();
|
||||
switch (export)
|
||||
{
|
||||
case UStaticMesh st:
|
||||
|
|
@ -145,7 +144,7 @@ namespace FModel.ViewModels
|
|||
var n = new Vector3(vert.Normal.X, -vert.Normal.Y, vert.Normal.Z);
|
||||
var uv = new Vector2(vert.UV.U, vert.UV.V);
|
||||
builder.AddNode(p, n, uv);
|
||||
builder.TriangleIndices.Add(j * 3 + t); // one mesh part is "j * 3 + k" use "id" if you're building the full mesh
|
||||
builder.TriangleIndices.Add(j * 3 + t); // one mesh part is "j * 3 + t" use "id" if you're building the full mesh
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -159,8 +158,9 @@ namespace FModel.ViewModels
|
|||
|
||||
Group3d.Add(new MeshGeometryModel3D
|
||||
{
|
||||
Name = unrealMaterial.Name,
|
||||
Geometry = builder.ToMeshGeometry3D(),
|
||||
Material = new PhongMaterial
|
||||
Material = new DiffuseMaterial
|
||||
{
|
||||
DiffuseMap = new TextureModel(diffuse.Decode()?.Encode().AsStream())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ namespace FModel.ViewModels
|
|||
CurrentCancellationTokenSource = null; // kill token
|
||||
|
||||
Log.Error("{Exception}", e);
|
||||
|
||||
|
||||
FLogger.AppendError();
|
||||
FLogger.AppendText(e.Message, Constants.WHITE, true);
|
||||
FLogger.AppendText(" " + e.StackTrace.SubstringBefore('\n').Trim(), Constants.WHITE, true);
|
||||
|
|
@ -116,4 +116,4 @@ namespace FModel.ViewModels
|
|||
StatusChangeAttempted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
xmlns:adonisControls="clr-namespace:AdonisUI.Controls;assembly=AdonisUI"
|
||||
xmlns:helix="http://helix-toolkit.org/wpf/SharpDX"
|
||||
WindowStartupLocation="CenterScreen" ResizeMode="CanResize" IconVisibility="Collapsed" Background="#262630"
|
||||
PreviewKeyDown="OnWindowKeyDown"
|
||||
PreviewKeyDown="OnWindowKeyDown" Closing="OnClosing"
|
||||
Height="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenHeight}, Converter={converters:RatioConverter}, ConverterParameter='0.60'}"
|
||||
Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={converters:RatioConverter}, ConverterParameter='0.50'}">
|
||||
<adonisControls:AdonisWindow.Style>
|
||||
|
|
@ -31,15 +31,11 @@
|
|||
<MouseBinding Command="helix:ViewportCommands.Zoom" Gesture="RightClick" />
|
||||
<MouseBinding Command="helix:ViewportCommands.Pan" Gesture="MiddleClick" />
|
||||
</helix:Viewport3DX.InputBindings>
|
||||
|
||||
<helix:DirectionalLight3D Direction="0, 0, -1" Color="White" />
|
||||
<helix:DirectionalLight3D Direction="0, -1, 0" Color="White"/>
|
||||
|
||||
<helix:LineGeometryModel3D Geometry="{Binding ModelViewer.XAxis}" Color="#FC3854" />
|
||||
<helix:LineGeometryModel3D Geometry="{Binding ModelViewer.YAxis}" Color="#85CB22" />
|
||||
<helix:LineGeometryModel3D Geometry="{Binding ModelViewer.ZAxis}" Color="#388EED" />
|
||||
|
||||
<helix:GroupModel3D ItemsSource="{Binding ModelViewer.Group3d}" />
|
||||
<helix:GroupModel3D x:Name="group" ItemsSource="{Binding ModelViewer.Group3d}" />
|
||||
</helix:Viewport3DX>
|
||||
</Grid>
|
||||
</adonisControls:AdonisWindow>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Windows.Input;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Input;
|
||||
using CUE4Parse.UE4.Assets.Exports;
|
||||
using FModel.Services;
|
||||
using FModel.Settings;
|
||||
|
|
@ -17,6 +18,10 @@ namespace FModel.Views
|
|||
}
|
||||
|
||||
public void Load(UObject export) => _applicationView.ModelViewer.LoadExport(export);
|
||||
private void OnClosing(object sender, CancelEventArgs e)
|
||||
{
|
||||
group.ItemsSource = null; // <3
|
||||
}
|
||||
|
||||
private void OnWindowKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user