Skip to content

Commit

Permalink
Fixed bugs related to animation
Browse files Browse the repository at this point in the history
Added settings for only importing mesh lod 0 for references meshes
Fixed potential crash
  • Loading branch information
donkeyProgramming committed Nov 19, 2024
1 parent 08078e3 commit dbf1206
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 54 deletions.
3 changes: 3 additions & 0 deletions AssetEditor/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ partial class SettingsViewModel : ObservableObject
[ObservableProperty] private bool _loadCaPacksByDefault;
[ObservableProperty] private bool _loadWemFiles;
[ObservableProperty] private string _wwisePath;
[ObservableProperty] private bool _onlyLoadLod0ForReferenceMeshes;

public bool IsLoadWemFilesEnabled => LoadCaPacksByDefault;

Expand All @@ -44,6 +45,7 @@ public SettingsViewModel(ApplicationSettingsService settingsService, GameInforma
CurrentGame = _settingsService.CurrentSettings.CurrentGame;
LoadCaPacksByDefault = _settingsService.CurrentSettings.LoadCaPacksByDefault;
LoadWemFiles = _settingsService.CurrentSettings.LoadWemFiles;
OnlyLoadLod0ForReferenceMeshes = _settingsService.CurrentSettings.OnlyLoadLod0ForReferenceMeshes;
foreach (var game in gameInformationFactory.Games.OrderBy(g => g.DisplayName))
{
GameDirectores.Add(
Expand Down Expand Up @@ -72,6 +74,7 @@ [RelayCommand] private void Save()
_settingsService.CurrentSettings.CurrentGame = CurrentGame;
_settingsService.CurrentSettings.LoadCaPacksByDefault = LoadCaPacksByDefault;
_settingsService.CurrentSettings.LoadWemFiles = LoadWemFiles;
_settingsService.CurrentSettings.OnlyLoadLod0ForReferenceMeshes = OnlyLoadLod0ForReferenceMeshes;
_settingsService.CurrentSettings.GameDirectories.Clear();
foreach (var item in GameDirectores)
_settingsService.CurrentSettings.GameDirectories.Add(new ApplicationSettings.GamePathPair() { Game = item.GameType, Path = item.Path });
Expand Down
8 changes: 6 additions & 2 deletions AssetEditor/Views/Settings/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="230"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
Expand All @@ -47,6 +47,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Text="Application" Margin="5, 10, 0, 0" FontSize="15"/>
Expand All @@ -72,7 +73,10 @@

<TextBlock Grid.Row="7" Grid.Column="0" Text="Load audio (.wem) files" Margin="5, 0, 0, 0"/>
<CheckBox Grid.Row="7" Grid.Column="1" Margin="-1, 0, 0, 5" IsChecked="{Binding LoadWemFiles, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" IsEnabled="{Binding IsLoadWemFilesEnabled}"/>


<TextBlock Grid.Row="8" Grid.Column="0" Text="Only load Lod0 for Reference meshes" Margin="5, 0, 0, 0" ToolTip="When importing a reference mesh in the Kitbash tool, only import Lod0 in order to save memory."/>
<CheckBox Grid.Row="8" Grid.Column="1" Margin="-1, 0, 0, 5" IsChecked="{Binding OnlyLoadLod0ForReferenceMeshes, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />

</Grid>

<Grid Grid.Row="1">
Expand Down
2 changes: 1 addition & 1 deletion Editors/AnimationMeta/Visualisation/MetaDataFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private IMetaDataInstance CreateAnimatedProp(IAnimatedPropMeta animatedPropMeta,
var propPlayer = _animationsContainerComponent.RegisterAnimationPlayer(new AnimationPlayer(), propName + Guid.NewGuid());

// Configure the mesh
var loadedNode = _complexMeshLoader.Load(meshPath, new GroupNode(propName), propPlayer);
var loadedNode = _complexMeshLoader.Load(meshPath, new GroupNode(propName), propPlayer, false); // TODO: Could last arg be true? WOuld be better

// Configure animation
if (animationPath != null)
Expand Down
1 change: 1 addition & 0 deletions Editors/KitbasherEditor/DependencyInjectionContainer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Editors.KitbasherEditor.EventHandlers;
using Editors.KitbasherEditor.Services;
using Editors.KitbasherEditor.UiCommands;
using Editors.KitbasherEditor.ViewModels;
using Editors.KitbasherEditor.ViewModels.PinTool;
using Editors.KitbasherEditor.ViewModels.SaveDialog;
using Editors.KitbasherEditor.ViewModels.SceneExplorer;
Expand Down
15 changes: 10 additions & 5 deletions Editors/KitbasherEditor/Services/KitbashSceneCreator.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System.IO;
using Editors.KitbasherEditor.ViewModels;
using GameWorld.Core.Components;
using GameWorld.Core.SceneNodes;
using GameWorld.Core.Services;
using GameWorld.Core.Services.SceneSaving;
using GameWorld.Core.Utility;
using KitbasherEditor.ViewModels;
using Serilog;
using Shared.Core.ErrorHandling;
using Shared.Core.PackFiles;
using Shared.Core.PackFiles.Models;
using Shared.Core.Services;
using Shared.GameFormats.RigidModel;
using Shared.GameFormats.WsModel;
using Xceed.Wpf.AvalonDock.Layout;
Expand All @@ -19,13 +20,15 @@ public class KitbashSceneCreator
{
private readonly ILogger _logger = Logging.Create<KitbashSceneCreator>();
private readonly PackFileService _packFileService;
private readonly ApplicationSettingsService _settingsService;
private readonly KitbasherRootScene _kitbasherRootScene;
private readonly ComplexMeshLoader _complexMeshLoader;
private readonly SceneManager _sceneManager;
private readonly Rmv2ModelNodeLoader _rmv2ModelNodeLoader;
private readonly GeometrySaveSettings _saveSettings;

public KitbashSceneCreator(
ApplicationSettingsService settingsService,
KitbasherRootScene kitbasherRootScene,
ComplexMeshLoader complexMeshLoader,
SceneManager sceneManager,
Expand All @@ -34,6 +37,7 @@ public KitbashSceneCreator(
GeometrySaveSettings saveSettings)
{
_packFileService = packFileService;
_settingsService = settingsService;
_kitbasherRootScene = kitbasherRootScene;
_complexMeshLoader = complexMeshLoader;
_sceneManager = sceneManager;
Expand Down Expand Up @@ -63,7 +67,7 @@ public void CreateFromPackFile(PackFile file)
rmv = ModelFactory.Create().Load(file.DataSource.ReadData());
}

var lodNodes = _rmv2ModelNodeLoader.CreateModelNodesFromFile(rmv, modelFullPath, _kitbasherRootScene.Player, wsModel);
var lodNodes = _rmv2ModelNodeLoader.CreateModelNodesFromFile(rmv, modelFullPath, _kitbasherRootScene.Player, false, wsModel);
mainNode.Children.Clear();
foreach(var lodNode in lodNodes)
mainNode.AddObject(lodNode);
Expand All @@ -81,15 +85,15 @@ public void CreateFromPackFile(PackFile file)
public void LoadReference(PackFile file)
{
_logger.Here().Information($"Loading reference model - {_packFileService.GetFullPath(file)}");
var result = LoadModel(file);
var result = LoadModel(file, _settingsService.CurrentSettings.OnlyLoadLod0ForReferenceMeshes);

var referenceMeshNode = _sceneManager.GetNodeByName<GroupNode>(SpecialNodes.ReferenceMeshs);
referenceMeshNode.AddObject(result!);
}

SceneNode? LoadModel(PackFile file)
SceneNode? LoadModel(PackFile file, bool onlyLoadRootNode)
{
var loadedNode = _complexMeshLoader.Load(file, _kitbasherRootScene.Player);
var loadedNode = _complexMeshLoader.Load(file, _kitbasherRootScene.Player, onlyLoadRootNode);
if (loadedNode == null)
{
_logger.Here().Error("Unable to load model");
Expand All @@ -104,6 +108,7 @@ public void LoadReference(PackFile file)

if (node is Rmv2MeshNode mesh && string.IsNullOrWhiteSpace(mesh.AttachmentPointName) == false)
{
mesh.AnimationPlayer = _kitbasherRootScene.Player;
if (_kitbasherRootScene.Skeleton != null)
{
var boneIndex = _kitbasherRootScene.Skeleton.GetBoneIndexByName(mesh.AttachmentPointName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using KitbasherEditor.ViewModels.MenuBarViews;
using Shared.Core.Events;
using Shared.Core.PackFiles;
using Shared.Core.PackFiles.Models;
using Shared.Ui.Common.MenuSystem;

namespace Editors.KitbasherEditor.UiCommands
Expand Down Expand Up @@ -81,6 +82,11 @@ public void Execute(string path)

_kitbashSceneCreator.LoadReference(packFile);
}

public void Execute(PackFile file)
{
_kitbashSceneCreator.LoadReference(file);
}
}

public class ImportGoblinReferenceCommand : BaseImportReferenceCommand
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Windows;
using CommonControls.Editors.BoneMapping.View;
using Editors.KitbasherEditor.ViewModels;
using Editors.Shared.Core.Services;
using GameWorld.Core.Components.Selection;
using GameWorld.Core.SceneNodes;
using KitbasherEditor.ViewModels;
using KitbasherEditor.ViewModels.MenuBarViews;
using KitbasherEditor.ViewModels.MeshFitter;
using Shared.Core.PackFiles;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using CommunityToolkit.Mvvm.Input;
using System.Collections.ObjectModel;
using System.IO;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
using Editors.KitbasherEditor.Events;
using Editors.Shared.Core.Services;
using GameWorld.Core.Animation;
Expand All @@ -7,13 +10,10 @@
using Shared.Core.PackFiles;
using Shared.Core.PackFiles.Models;
using Shared.GameFormats.Animation;
using System.Collections.ObjectModel;
using System.IO;
using System.Windows.Input;
using static CommonControls.FilterDialog.FilterUserControl;
using static Editors.Shared.Core.Services.SkeletonAnimationLookUpHelper;

namespace KitbasherEditor.ViewModels
namespace Editors.KitbasherEditor.ViewModels
{
public class AnimationControllerViewModel : NotifyPropertyChangedImpl
{
Expand Down
17 changes: 9 additions & 8 deletions Editors/KitbasherEditor/ViewModels/KitbashViewDropHandler.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using Editors.KitbasherEditor.Services;
using System.IO;
using Editors.KitbasherEditor.UiCommands;
using Shared.Core.Events;
using Shared.Ui.BaseDialogs.PackFileBrowser;
using System.IO;

namespace KitbasherEditor.ViewModels
namespace Editors.KitbasherEditor.ViewModels
{
public class KitbashViewDropHandler
{
private readonly KitbashSceneCreator _kitbashSceneCreator;
private readonly IUiCommandFactory _uiCommandFactory;

public KitbashViewDropHandler(KitbashSceneCreator kitbashSceneCreator)
public KitbashViewDropHandler(IUiCommandFactory uiCommandFactory)
{
_kitbashSceneCreator = kitbashSceneCreator;
_uiCommandFactory = uiCommandFactory;
}

public bool AllowDrop(TreeNode node, TreeNode targeNode = null)
Expand All @@ -24,9 +25,9 @@ public bool AllowDrop(TreeNode node, TreeNode targeNode = null)
return false;
}

public bool Drop(TreeNode node, TreeNode targeNode = null)
public bool Drop(TreeNode node)
{
_kitbashSceneCreator.LoadReference(node.Item);
_uiCommandFactory.Create<ImportReferenceMeshCommand>().Execute(node.Item);
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Editors/KitbasherEditor/ViewModels/KitbasherRootScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Shared.Core.PackFiles;
using Shared.GameFormats.Animation;

namespace KitbasherEditor.ViewModels
namespace Editors.KitbasherEditor.ViewModels
{
public class KitbasherRootScene : ISkeletonProvider
{
Expand Down
5 changes: 2 additions & 3 deletions Editors/KitbasherEditor/ViewModels/KitbasherViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.IO;
using System.Windows;
using CommunityToolkit.Mvvm.ComponentModel;
using Editors.KitbasherEditor.EventHandlers;
using Editors.KitbasherEditor.Services;
Expand All @@ -18,7 +17,7 @@
using Shared.Ui.BaseDialogs.PackFileBrowser;
using Shared.Ui.Common;

namespace KitbasherEditor.ViewModels
namespace Editors.KitbasherEditor.ViewModels
{
public partial class KitbasherViewModel : ObservableObject,
IEditorInterface,
Expand Down Expand Up @@ -107,7 +106,7 @@ public bool HasUnsavedChanges
}

public bool AllowDrop(TreeNode node, TreeNode targeNode = null) => _dropHandler.AllowDrop(node, targeNode);
public bool Drop(TreeNode node, TreeNode targeNode = null) => _dropHandler.Drop(node, targeNode);
public bool Drop(TreeNode node, TreeNode targeNode = null) => _dropHandler.Drop(node);

void OnFileSaved(ScopedFileSavedEvent notification)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Editors.Shared.Core.Services;
using GameWorld.Core.Components.Rendering;
using GameWorld.Core.SceneNodes;
using KitbasherEditor.ViewModels;
using KitbasherEditor.Views.EditorViews;
using Shared.Core.Events;
using Shared.Ui.Common.DataTemplates;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Editors.Shared.Core.Services;
using GameWorld.Core.SceneNodes;
using GameWorld.Core.Utility;
using KitbasherEditor.ViewModels;
using Shared.Core.PackFiles;
using Shared.Ui.Common;
using Shared.Ui.Editors.BoneMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using CommunityToolkit.Mvvm.Input;
using GameWorld.Core.Components;
using GameWorld.Core.SceneNodes;
using KitbasherEditor.ViewModels;
using Microsoft.Xna.Framework;
using Shared.GameFormats.RigidModel;
using Shared.Ui.BaseDialogs.MathViews;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void SetMesh(SceneObject sceneObject, PackFile file)
{
_logger.Here().Information($"Loading reference model - {_packFileService.GetFullPath(file)}");

var loadedNode = _complexMeshLoader.Load(file, sceneObject.Player);
var loadedNode = _complexMeshLoader.Load(file, sceneObject.Player, false);// TODO: Could last arg be true? WOuld be better
if (loadedNode == null)
{
_logger.Here().Error("Unable to load model");
Expand Down
4 changes: 2 additions & 2 deletions GameWorld/View3D/SceneNodes/Rmv2MeshNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private Rmv2MeshNode() { }

public void Render(RenderEngineComponent renderEngine, Matrix parentWorld)
{
var animationCapability = Material.GetCapability<AnimationCapability>();
var animationCapability = Material.TryGetCapability<AnimationCapability>();
if (animationCapability != null)
{
var data = new Matrix[256];
Expand All @@ -83,7 +83,7 @@ public void Render(RenderEngineComponent renderEngine, Matrix parentWorld)

animationCapability.AnimationTransforms = data;
animationCapability.AnimationWeightCount = Geometry.WeightCount;
animationCapability.ApplyAnimation = AnimationPlayer != null && AnimationPlayer.IsEnabled;
animationCapability.ApplyAnimation = AnimationPlayer != null && AnimationPlayer.IsEnabled && Geometry.VertexFormat != UiVertexFormat.Static;
}

if (AttachmentBoneResolver != null)
Expand Down
11 changes: 10 additions & 1 deletion GameWorld/View3D/SceneNodes/Rmv2ModelNodeLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using GameWorld.Core.Rendering.Materials;
using GameWorld.Core.Rendering.Materials.Shaders;
using GameWorld.Core.Services;
using Serilog;
using Shared.Core.ErrorHandling;
using Shared.Core.ErrorHandling.Exceptions;
using Shared.Core.PackFiles;
using Shared.GameFormats.RigidModel;
Expand All @@ -14,6 +16,7 @@ namespace GameWorld.Core.SceneNodes
{
public class Rmv2ModelNodeLoader
{
private readonly ILogger _logger = Logging.Create<Rmv2ModelNodeLoader>();
private readonly MeshBuilderService _meshBuilderService;
private readonly PackFileService _packFileService;
private readonly CapabilityMaterialFactory _capabilityMaterialFactory;
Expand All @@ -27,7 +30,7 @@ public Rmv2ModelNodeLoader(MeshBuilderService meshBuilderService, PackFileServic
_exceptionService = exceptionService;
}

public List<Rmv2LodNode> CreateModelNodesFromFile(RmvFile model, string modelFullPath, AnimationPlayer animationPlayer, WsModelFile? wsModel = null)
public List<Rmv2LodNode> CreateModelNodesFromFile(RmvFile model, string modelFullPath, AnimationPlayer animationPlayer, bool onlyLoadRootNode, WsModelFile? wsModel = null)
{
WsModelMaterialProvider wsMaterialProvider;
if(wsModel != null)
Expand Down Expand Up @@ -71,6 +74,12 @@ public List<Rmv2LodNode> CreateModelNodesFromFile(RmvFile model, string modelFul
var node = new Rmv2MeshNode(geometry, rmvModel.Material, shader, animationPlayer);
currentNode.AddObject(node);
}

if (onlyLoadRootNode)
{
_logger.Here().Information($"Only loading root node for mesh - {modelFullPath}");
break;
}
}

return output;
Expand Down
Loading

0 comments on commit dbf1206

Please sign in to comment.