fix: forgotten yaml converter for Matrix4x4

This commit is contained in:
2026-02-09 13:14:45 +03:00
parent 499f875903
commit 32a7e9be24

View File

@@ -0,0 +1,33 @@
using System;
using Engine.Core;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Serialization;
namespace Engine.Serializers.Yaml;
public class Matrix4x4Converter : EngineTypeYamlSerializerBase<Matrix4x4>
{
private static readonly int SUBSTRING_START_LENGTH = nameof(Matrix4x4).Length + 1;
public override Matrix4x4 Read(IParser parser, Type type, ObjectDeserializer rootDeserializer)
{
string value = parser.Consume<Scalar>().Value;
string insideParenthesis = value[SUBSTRING_START_LENGTH..^1];
string[] values = insideParenthesis.Split(", ");
return new Matrix4x4(
float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2]), float.Parse(values[3]),
float.Parse(values[4]), float.Parse(values[5]), float.Parse(values[6]), float.Parse(values[7]),
float.Parse(values[8]), float.Parse(values[9]), float.Parse(values[10]), float.Parse(values[11]),
float.Parse(values[12]), float.Parse(values[13]), float.Parse(values[14]), float.Parse(values[15])
);
}
public override void WriteYaml(IEmitter emitter, object? value, Type type, ObjectSerializer serializer)
{
Matrix4x4 m = (Matrix4x4)value!;
emitter.Emit(new Scalar($"{nameof(Matrix4x4)}({m.M11}, {m.M12}, {m.M13}, {m.M14},{m.M21}, {m.M22}, {m.M23}, {m.M24},{m.M31}, {m.M32}, {m.M33}, {m.M34},{m.M41}, {m.M42}, {m.M43}, {m.M44})"));
}
}