fix #203: preserve animation on appearance updates
This commit is contained in:
parent
ff06aa3107
commit
c7607f019c
9 changed files with 237 additions and 22 deletions
|
|
@ -0,0 +1,65 @@
|
|||
using System.Numerics;
|
||||
using AcDream.App.Rendering;
|
||||
using AcDream.Core.Physics;
|
||||
using AcDream.Core.World;
|
||||
using DatReaderWriter.DBObjs;
|
||||
|
||||
namespace AcDream.App.Tests.Rendering;
|
||||
|
||||
public sealed class LiveAppearanceAnimationTests
|
||||
{
|
||||
[Fact]
|
||||
public void RebindAppearance_PreservesEntitySequencerAndPlaybackState()
|
||||
{
|
||||
var setup = new Setup();
|
||||
var animation = new Animation();
|
||||
var sequencer = new AnimationSequencer(setup, new MotionTable(), new NullLoader());
|
||||
var oldEntity = Entity(0x70000001u, 0x01000001u);
|
||||
var state = new GameWindow.AnimatedEntity
|
||||
{
|
||||
Entity = oldEntity,
|
||||
Setup = setup,
|
||||
Animation = animation,
|
||||
LowFrame = 2,
|
||||
HighFrame = 9,
|
||||
Framerate = 30f,
|
||||
Scale = 1f,
|
||||
PartTemplate = [(0x01000001u, null)],
|
||||
CurrFrame = 6.5f,
|
||||
Sequencer = sequencer,
|
||||
};
|
||||
IReadOnlyList<MeshRef> dressedParts =
|
||||
[
|
||||
new MeshRef(0x01000002u, Matrix4x4.Identity),
|
||||
new MeshRef(0x01000003u, Matrix4x4.CreateTranslation(1f, 2f, 3f)),
|
||||
];
|
||||
|
||||
oldEntity.ApplyAppearance(dressedParts, paletteOverride: null, partOverrides: []);
|
||||
GameWindow.RebindAnimatedEntityForAppearance(
|
||||
state, oldEntity, setup, 1.25f, dressedParts);
|
||||
|
||||
Assert.Same(oldEntity, state.Entity);
|
||||
Assert.Same(dressedParts, state.Entity.MeshRefs);
|
||||
Assert.Same(sequencer, state.Sequencer);
|
||||
Assert.Equal(6.5f, state.CurrFrame);
|
||||
Assert.Equal((2, 9, 30f), (state.LowFrame, state.HighFrame, state.Framerate));
|
||||
Assert.Equal(1.25f, state.Scale);
|
||||
Assert.Equal(new[] { 0x01000002u, 0x01000003u },
|
||||
state.PartTemplate.Select(part => part.GfxObjId));
|
||||
}
|
||||
|
||||
private static WorldEntity Entity(uint id, uint gfxObjId) => new()
|
||||
{
|
||||
Id = id,
|
||||
ServerGuid = 0x50000001u,
|
||||
SourceGfxObjOrSetupId = 0x02000001u,
|
||||
Position = Vector3.Zero,
|
||||
Rotation = Quaternion.Identity,
|
||||
MeshRefs = [new MeshRef(gfxObjId, Matrix4x4.Identity)],
|
||||
};
|
||||
|
||||
private sealed class NullLoader : IAnimationLoader
|
||||
{
|
||||
public Animation? LoadAnimation(uint id) => null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue