diff --git a/CUE4Parse b/CUE4Parse index 756358e4..fe8f97ce 160000 --- a/CUE4Parse +++ b/CUE4Parse @@ -1 +1 @@ -Subproject commit 756358e40b47b65106a8c74893652c659eb56633 +Subproject commit fe8f97ce2d8062f6cacee2422215c4fd2b72eed7 diff --git a/FModel/ViewModels/CUE4ParseViewModel.cs b/FModel/ViewModels/CUE4ParseViewModel.cs index e7882e7b..d8931b0f 100644 --- a/FModel/ViewModels/CUE4ParseViewModel.cs +++ b/FModel/ViewModels/CUE4ParseViewModel.cs @@ -722,12 +722,15 @@ public class CUE4ParseViewModel : ViewModel break; } + var showSnooper = false; for (var i = result.InclusiveStart; i < result.ExclusiveEnd; i++) { - if (CheckExport(cancellationToken, result.Package, i, bulk)) + if (CheckExport(cancellationToken, result.Package, i, ref showSnooper, bulk)) break; } + if (showSnooper) SnooperViewer.Run(); + break; } case "ini" when entry.Name.Contains("BinaryConfig"): @@ -1249,14 +1252,15 @@ public class CUE4ParseViewModel : ViewModel TabControl.SelectedTab.Highlighter = AvalonExtensions.HighlighterSelector(""); // json TabControl.SelectedTab.SetDocumentText(JsonConvert.SerializeObject(result.GetDisplayData(), Formatting.Indented), false, false); + var showSnooper = false; for (var i = result.InclusiveStart; i < result.ExclusiveEnd; i++) { - if (CheckExport(cancellationToken, result.Package, i)) + if (CheckExport(cancellationToken, result.Package, i, ref showSnooper)) break; } } - private bool CheckExport(CancellationToken cancellationToken, IPackage pkg, int index, EBulkType bulk = EBulkType.None) // return true once you want to stop searching for exports + private bool CheckExport(CancellationToken cancellationToken, IPackage pkg, int index, ref bool showSnooper, EBulkType bulk = EBulkType.None) // return true once you want to stop searching for exports { var isNone = bulk == EBulkType.None; var updateUi = !HasFlag(bulk, EBulkType.Auto); @@ -1606,20 +1610,26 @@ public class CUE4ParseViewModel : ViewModel pkg.Name.Contains("/MI_BPTile/", StringComparison.OrdinalIgnoreCase))): { if (SnooperViewer.TryLoadExport(cancellationToken, dummy, pointer.Object)) - SnooperViewer.Run(); + showSnooper = true; return true; } + case UIRMeshComponent when isNone && UserSettings.Default.PreviewStaticMeshes: + { + if (SnooperViewer.TryLoadExport(cancellationToken, dummy, pointer.Object)) + showSnooper = true; + return false; + } case UMaterialInstance when isNone && ModelIsOverwritingMaterial && pointer.Object.Value is UMaterialInstance m: { SnooperViewer.Renderer.Swap(m); - SnooperViewer.Run(); + showSnooper = true; return true; } case UAnimSequenceBase when isNone && UserSettings.Default.PreviewAnimations || ModelIsWaitingAnimation: { // animate all animations using their specified skeleton or when we explicitly asked for a loaded model to be animated (ignoring whether we wanted to preview animations) SnooperViewer.Renderer.Animate(pointer.Object.Value); - SnooperViewer.Run(); + showSnooper = true; return true; } case UStaticMesh when HasFlag(bulk, EBulkType.Meshes): diff --git a/FModel/Views/Snooper/Models/StaticModel.cs b/FModel/Views/Snooper/Models/StaticModel.cs index f7af310b..5ac1ce5d 100644 --- a/FModel/Views/Snooper/Models/StaticModel.cs +++ b/FModel/Views/Snooper/Models/StaticModel.cs @@ -152,9 +152,10 @@ public class StaticModel : UModel Box = staticMesh.Bounds * Constants.SCALE_DOWN_RATIO; } - public StaticModel(UIRMesh export, StaticMeshDto mesh) - : base(export, mesh.LODs[LodLevel], new FPackageIndex[mesh.Materials.Length], mesh.LODs[LodLevel].Vertices, mesh.LODs.Count) + public StaticModel(UIRMesh export, StaticMeshDto mesh, int meshIndex) + : base(export, mesh.LODs[LodLevel], export.Materials, mesh.LODs[LodLevel].Vertices, mesh.LODs.Count) { + Name = meshIndex > 0 ? $"{Name}_{meshIndex}": Name; Box = mesh.Bounds * Constants.SCALE_DOWN_RATIO; } diff --git a/FModel/Views/Snooper/Models/UModel.cs b/FModel/Views/Snooper/Models/UModel.cs index 9fa2a11d..8f429988 100644 --- a/FModel/Views/Snooper/Models/UModel.cs +++ b/FModel/Views/Snooper/Models/UModel.cs @@ -46,7 +46,7 @@ public abstract class UModel : IRenderableModel where TVertex : struct, public VertexArrayObject Vao { get; set; } public string Path { get; } - public string Name { get; } + public string Name { get; protected set; } public string Type { get; protected set; } public int UvCount { get; } public uint[] Indices { get; set; } diff --git a/FModel/Views/Snooper/Renderer.cs b/FModel/Views/Snooper/Renderer.cs index e2749c52..e99f9afa 100644 --- a/FModel/Views/Snooper/Renderer.cs +++ b/FModel/Views/Snooper/Renderer.cs @@ -23,6 +23,7 @@ using CUE4Parse_Conversion.Animations; using CUE4Parse_Conversion.Dto; using CUE4Parse_Conversion.Meshes; using CUE4Parse_Conversion.Options; +using CUE4Parse.UE4.Assets.Exports.Component; using FModel.Creator; using FModel.Settings; using FModel.Views.Snooper.Animations; @@ -91,8 +92,11 @@ public class Renderer : IDisposable case UStaticMesh when export.Value is UStaticMesh st: LoadStaticMesh(st, UserSettings.Default.NaniteMeshExportFormat); break; - case UIRMesh when export.Value is UIRMesh ir: - LoadIRMesh(ir); + case UIRMesh when export.Value is UIRMesh irmc: + LoadIRMeshCollection(irmc); + break; + case UIRMeshComponent when export.Value is UIRMeshComponent meshcomp: + LoadIRMeshComponent(meshcomp); break; case UGeometryCollection when export.Value is UGeometryCollection gc: LoadStaticMesh(gc, UserSettings.Default.NaniteMeshExportFormat); @@ -370,32 +374,40 @@ public class Renderer : IDisposable Options.SelectModel(guid); } - private void LoadIRMesh(UIRMesh original) + private void LoadIRMeshCollection(UIRMesh original, FPackageIndex[]? materials = null) { - var guid = new FGuid((uint) original.GetFullName().GetHashCode()); + var hash = (uint) original.GetFullName().GetHashCode(); + var guid = new FGuid(hash); if (Options.TryGetModel(guid, out var model)) - { - model.AddInstance(Transform.Identity); - Application.Current.Dispatcher.Invoke(model.SetupInstances); return; + + if (materials is not null && original.Info.MaterialCount == materials.Length) + original.SetMaterials(materials); + for (int i = 0; i < original.Info.PartCount; i++) + { + try + { + var mesh = new StaticMeshDto(original, i); + Options.Models[new FGuid(hash ^ (uint) i)] = new StaticModel(original, mesh, i) { IsVisible = true }; + mesh.Dispose(); + } + catch (Exception e) + { + Log.Error(e, "Failed to convert IR static mesh part {PartIndex}", i); + } } - StaticMeshDto mesh; - try - { - mesh = new StaticMeshDto(original); - } - catch (Exception e) - { - Log.Error(e, "Failed to convert IR mesh"); - return; - } - - Options.Models[guid] = new StaticModel(original, mesh); - mesh.Dispose(); Options.SelectModel(guid); } + private void LoadIRMeshComponent(UIRMeshComponent original) + { + if (original.Mesh is { IsNull: false } meshref && meshref.TryLoad(out UIRMesh mesh)) + { + LoadIRMeshCollection(mesh, original.OverrideMaterials); + } + } + private void LoadStaticMesh(UGeometryCollection original, ENaniteMeshFormat naniteFormat = ENaniteMeshFormat.NoNanite) { var guid = new FGuid((uint) original.GetFullName().GetHashCode()); @@ -611,26 +623,33 @@ public class Renderer : IDisposable { foreach (var component in instanceComponents) { - if (!component.TryLoad(out UStaticMeshComponent staticMeshComp) || - !staticMeshComp.GetStaticMesh().TryLoad(out UStaticMesh m) || m.Materials.Length < 1) - continue; + if (!component.TryLoad(out UMeshComponent meshComponent)) continue; - var relation = CalculateTransform(staticMeshComp, transform); - if (staticMeshComp is UInstancedStaticMeshComponent { PerInstanceSMData.Length: > 0 } instancedStaticMeshComp) + if (meshComponent is UStaticMeshComponent staticMeshComp) { + if (!staticMeshComp.GetStaticMesh().TryLoad(out UStaticMesh m) || m.Materials.Length < 1) + continue; - foreach (var perInstanceData in instancedStaticMeshComp.PerInstanceSMData) + var relation = CalculateTransform(staticMeshComp, transform); + if (staticMeshComp is UInstancedStaticMeshComponent { PerInstanceSMData.Length: > 0 } instancedStaticMeshComp) { - ProcessMesh(actor, instancedStaticMeshComp, m, new Transform + foreach (var perInstanceData in instancedStaticMeshComp.PerInstanceSMData) { - Relation = relation.Matrix, - Position = perInstanceData.TransformData.Translation * Constants.SCALE_DOWN_RATIO, - Rotation = perInstanceData.TransformData.Rotation, - Scale = perInstanceData.TransformData.Scale3D - }); + ProcessMesh(actor, instancedStaticMeshComp, m, new Transform + { + Relation = relation.Matrix, + Position = perInstanceData.TransformData.Translation * Constants.SCALE_DOWN_RATIO, + Rotation = perInstanceData.TransformData.Rotation, + Scale = perInstanceData.TransformData.Scale3D + }); + } } + else ProcessMesh(actor, staticMeshComp, m, relation); + } + else if (meshComponent is UIRMeshComponent irMeshComponent) + { + LoadIRMeshComponent(irMeshComponent); } - else ProcessMesh(actor, staticMeshComp, m, relation); } } else if (actor.TryGetValue(out FPackageIndex componentTemplate, "ComponentTemplate") &&