Skip to content

Commit 5dda5d3

Browse files
[Feature]: KitbashTool: Possible to set animation matrix, for things such as building animations.
1 parent 916bec5 commit 5dda5d3

File tree

10 files changed

+40
-15
lines changed

10 files changed

+40
-15
lines changed

Editors/ImportExportEditor/Editors.ImportExport/Importing/Importers/GltfToRmv/Helper/Rmv2FromGltfFIleConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ RmvModel CreateRmvModel(ModelMaterialEnum rigidMaterial, VertexFormat vertexForm
156156
{
157157
var boneNames = skeleton.BoneNames;
158158
var attachmentPoints = AttachmentPointHelper.CreateFromBoneList(boneNames);
159-
newModel.Material.EnrichDataBeforeSaving(attachmentPoints);
159+
newModel.Material.EnrichDataBeforeSaving(attachmentPoints, -1);
160160
}
161161

162162
return newModel;

Editors/ImportExportEditor/Editors.ImportExport/Importing/Importers/GltfToRmv/Helper/RmvMeshBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ private static RmvModel CreateRmvModel(RmvMesh rmv2Mesh, string modelName, Anima
202202
{
203203
var boneNames = animSkeletonFile.Bones.Select(x => x.Name).ToList();
204204
var attachmentPoints = AttachmentPointHelper.CreateFromBoneList(boneNames);
205-
newModel.Material.EnrichDataBeforeSaving(attachmentPoints);
205+
newModel.Material.EnrichDataBeforeSaving(attachmentPoints, -1);
206206
}
207207

208208
return newModel;

Editors/Kitbashing/KitbasherEditor/Core/SceneNodeEditor/Nodes/MeshNode/Mesh.Animation/AnimationView.xaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,23 @@
5858
<DockPanel DockPanel.Dock="Top" >
5959
<Label Width ="{StaticResource labelWidth}" DockPanel.Dock="Left" Content="Attach To"/>
6060
<Label>:</Label>
61-
<ComboBox Grid.Column="2" Grid.ColumnSpan="2" Grid.Row="0"
61+
<ComboBox
6262
IsEditable="True"
6363
IsTextSearchEnabled="false"
6464
DisplayMemberPath="Name.Value"
6565
Text="{Binding Animation.AttachableBones.Filter, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
6666
ItemsSource="{Binding Animation.AttachableBones.Values}"
6767
SelectedItem="{Binding Animation.AttachableBones.SelectedItem, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"/>
68+
69+
70+
</DockPanel>
71+
72+
<DockPanel DockPanel.Dock="Top" >
73+
<Label Width ="{StaticResource labelWidth}" DockPanel.Dock="Left" Content="Animation Matrix "/>
74+
<Label>:</Label>
75+
<TextBox DockPanel.Dock="Top" Margin="0,2,0,2" Text="{Binding Animation.AnimationMatrixOverride, UpdateSourceTrigger=LostFocus}" MaxLength="8" VerticalContentAlignment="Center" Width="100" HorizontalAlignment="Left" HorizontalContentAlignment="Right"/>
6876
</DockPanel>
77+
6978
</DockPanel>
7079
</Expander>
7180
</UserControl>

Editors/Kitbashing/KitbasherEditor/Core/SceneNodeEditor/Nodes/MeshNode/Mesh.Animation/AnimationViewModel.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ public partial class AnimationViewModel : ObservableObject, IDisposable
1313
{
1414
private readonly KitbasherRootScene _kitbasherRootScene;
1515
private readonly SkeletonAnimationLookUpHelper _animLookUp;
16-
Rmv2MeshNode _meshNode;
16+
Rmv2MeshNode? _meshNode;
1717

18-
[ObservableProperty] string _skeletonName = string.Empty;
19-
[ObservableProperty] List<AnimatedBone> _animatedBones;
20-
[ObservableProperty] FilterCollection<AnimatedBone> _attachableBones = new(null);
18+
[ObservableProperty] public partial string SkeletonName { get; set; } = string.Empty;
19+
[ObservableProperty] public partial List<AnimatedBone> AnimatedBones { get; set; }
20+
[ObservableProperty] public partial FilterCollection<AnimatedBone> AttachableBones { get; set; } = new(null);
21+
[ObservableProperty] public partial int AnimationMatrixOverride { get; set; } = -1;
2122

2223
public AnimationViewModel(KitbasherRootScene kitbasherRootScene, SkeletonAnimationLookUpHelper animLookUp)
2324
{
@@ -29,6 +30,7 @@ public void Initialize(Rmv2MeshNode meshNode)
2930
{
3031
_meshNode = meshNode;
3132

33+
AnimationMatrixOverride = _meshNode.AnimationMatrixOverride;
3234
SkeletonName = _meshNode.Geometry.SkeletonName;
3335

3436
var skeletonFile = _animLookUp.GetSkeletonFileFromName(SkeletonName);
@@ -89,6 +91,13 @@ private void ModelBoneList_SelectedItemChanged(AnimatedBone newValue)
8991
}
9092
}
9193

94+
partial void OnAnimationMatrixOverrideChanged(int value)
95+
{
96+
if(_meshNode==null)
97+
return;
98+
_meshNode.AnimationMatrixOverride = value;
99+
}
100+
92101
public void Dispose()
93102
{
94103
AttachableBones.SelectedItemChanged -= ModelBoneList_SelectedItemChanged;

GameWorld/View3D/SceneNodes/Rmv2MeshNode.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public class Rmv2MeshNode : SceneNode, ITransformable, IEditableGeometry, ISelec
3333
public Vector3 PivotPoint { get; set; }
3434

3535
public string AttachmentPointName { get; set; } = "";
36-
36+
public int AnimationMatrixOverride { get; set; } = -1;
37+
3738
public bool DisplayBoundingBox { get; set; } = false;
3839
public bool DisplayPivotPoint { get; set; } = false;
3940
public bool ReduceMeshOnLodGeneration { get; set; } = true;
@@ -58,6 +59,9 @@ public Rmv2MeshNode(MeshObject meshObject, IRmvMaterial material, CapabilityMate
5859

5960
Name = material.ModelName;
6061
PivotPoint = material.PivotPoint;
62+
63+
if(material != null && material is WeightedMaterial weightedMaterial)
64+
AnimationMatrixOverride = weightedMaterial.MatrixIndex;
6165
}
6266

6367
private Rmv2MeshNode() { }
@@ -138,6 +142,7 @@ public void CopyInto(ISceneNode target, bool includeMesh)
138142
typedTarget.PivotPoint = PivotPoint;
139143

140144
typedTarget.RmvMaterial = RmvMaterial.Clone();
145+
typedTarget.AnimationMatrixOverride = AnimationMatrixOverride;
141146
typedTarget.Geometry = Geometry.Clone();
142147
typedTarget.Material = Material.Clone();
143148

GameWorld/View3D/Services/SceneSaving/Geometry/NodeToRmvSaveHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ RmvFile GenerateBytes(Rmv2ModelNode modelNode, RmvVersionEnum version, GameSkele
8080
for (var meshIndex = 0; meshIndex < meshes.Count; meshIndex++)
8181
{
8282
var modelname = meshes[meshIndex].Name;
83-
rmvFile.ModelList[lodIndex][meshIndex] = CreateRmvModel(modelname, meshes[meshIndex].PivotPoint, meshes[meshIndex].Material, meshes[meshIndex].Geometry, skeleton, saveSettings.AttachmentPoints);
83+
rmvFile.ModelList[lodIndex][meshIndex] = CreateRmvModel(modelname, meshes[meshIndex].PivotPoint, meshes[meshIndex].Material, meshes[meshIndex].Geometry, skeleton, saveSettings.AttachmentPoints, meshes[meshIndex].AnimationMatrixOverride);
8484
}
8585
}
8686

@@ -90,7 +90,7 @@ RmvFile GenerateBytes(Rmv2ModelNode modelNode, RmvVersionEnum version, GameSkele
9090
return rmvFile;
9191
}
9292

93-
RmvModel CreateRmvModel(string modelName, Vector3 pivotPoint, CapabilityMaterial capabilityMaterial, MeshObject geometry, GameSkeleton? skeleton, List<RmvAttachmentPoint> attachmentPoints)
93+
RmvModel CreateRmvModel(string modelName, Vector3 pivotPoint, CapabilityMaterial capabilityMaterial, MeshObject geometry, GameSkeleton? skeleton, List<RmvAttachmentPoint> attachmentPoints, int animationMatrixOverride)
9494
{
9595
var newRmvMaterial = new MaterialToRmvSerializer().CreateMaterialFromCapabilityMaterial(capabilityMaterial);
9696
newRmvMaterial.UpdateInternalState(geometry.VertexFormat);
@@ -108,7 +108,7 @@ RmvModel CreateRmvModel(string modelName, Vector3 pivotPoint, CapabilityMaterial
108108
newModel.UpdateModelTypeFlag(newModel.Material.MaterialId);
109109

110110

111-
newModel.Material.EnrichDataBeforeSaving(attachmentPoints);
111+
newModel.Material.EnrichDataBeforeSaving(attachmentPoints, animationMatrixOverride);
112112

113113

114114
return newModel;

Shared/GameFiles/RigidModel/MaterialHeaders/CustomTerrainMaterial.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public List<RmvTexture> GetAllTextures()
5858
return new List<RmvTexture>();
5959
}
6060

61-
public void EnrichDataBeforeSaving(List<RmvAttachmentPoint> attachmentPoints)
61+
public void EnrichDataBeforeSaving(List<RmvAttachmentPoint> attachmentPoints, int matrixOverride)
6262
{
6363
throw new NotImplementedException();
6464
}

Shared/GameFiles/RigidModel/MaterialHeaders/IRmvMaterial.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public interface IRmvMaterial
1818
void SetTexture(TextureType texureType, string path);
1919

2020
void UpdateInternalState(UiVertexFormat uiVertexFormat);
21-
void EnrichDataBeforeSaving(List<RmvAttachmentPoint> attachmentPoints);
21+
void EnrichDataBeforeSaving(List<RmvAttachmentPoint> attachmentPoints, int matrixOverride);
2222
}
2323

2424
public interface IMaterialCreator

Shared/GameFiles/RigidModel/MaterialHeaders/TerrainTileMaterial.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void UpdateInternalState(UiVertexFormat uiVertexFormat)
6767
throw new NotImplementedException();
6868
}
6969

70-
public void EnrichDataBeforeSaving(List<RmvAttachmentPoint> attachmentPoints)
70+
public void EnrichDataBeforeSaving(List<RmvAttachmentPoint> attachmentPoints, int matrixOverride)
7171
{
7272
throw new NotImplementedException();
7373
}

Shared/GameFiles/RigidModel/MaterialHeaders/WeightedMaterial.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,12 @@ internal void DetermineMaterial()
212212
}
213213
}
214214

215-
public void EnrichDataBeforeSaving(List<RmvAttachmentPoint> attachmentPoints)
215+
public void EnrichDataBeforeSaving(List<RmvAttachmentPoint> attachmentPoints, int matrixOverride)
216216
{
217217
AttachmentPointParams.Clear();
218218
AttachmentPointParams.AddRange(attachmentPoints);
219+
220+
MatrixIndex = matrixOverride;
219221
}
220222
}
221223

0 commit comments

Comments
 (0)