forked from ReFuel/ReFuel.Gltf
81 lines
2.4 KiB
C#
81 lines
2.4 KiB
C#
using System;
|
|
using System.Text.Json;
|
|
|
|
namespace ReFuel.Gltf
|
|
{
|
|
public class GltfSkin : GltfIdObject
|
|
{
|
|
private GltfSmartId<GltfAccessor> _inverseBindMatrices = new GltfSmartId<GltfAccessor>();
|
|
private GltfSmartId<GltfNode> _skeleton = new GltfSmartId<GltfNode>();
|
|
|
|
public override GltfObjectKind Kind => GltfObjectKind.Skin;
|
|
|
|
public string? Name { get; set; }
|
|
public GltfAccessor? InverseBindMatrices
|
|
{
|
|
get => _inverseBindMatrices.IsSet ? _inverseBindMatrices.Value : null;
|
|
set
|
|
{
|
|
if (value is null)
|
|
_inverseBindMatrices.Reset();
|
|
else
|
|
_inverseBindMatrices.Value = value;
|
|
}
|
|
}
|
|
public GltfNode? Skeleton
|
|
{
|
|
get => _skeleton.IsSet ? _skeleton.Value : null;
|
|
set
|
|
{
|
|
if (value is null)
|
|
_skeleton.Reset();
|
|
else
|
|
_skeleton.Value = value;
|
|
}
|
|
}
|
|
|
|
public GltfRefList<GltfNode> Joints { get; }
|
|
|
|
internal GltfSkin(GltfDocument document) : base(document)
|
|
{
|
|
Joints = new GltfRefList<GltfNode>(document.Nodes);
|
|
}
|
|
|
|
internal override void Deserialize(JsonElement element)
|
|
{
|
|
AssertObject(element);
|
|
|
|
if (!element.TryGetProperty("joints", out JsonElement jointsElement))
|
|
RequiredProperty("joints");
|
|
AssertArray(jointsElement, "joints");
|
|
|
|
foreach (JsonElement joint in jointsElement.EnumerateArray())
|
|
{
|
|
Joints.Add(joint.GetInt32());
|
|
}
|
|
|
|
foreach (JsonProperty property in element.EnumerateObject())
|
|
{
|
|
switch (property.Name)
|
|
{
|
|
case "inverseBindMatrices":
|
|
_inverseBindMatrices.Id = property.Value.GetInt32();
|
|
break;
|
|
case "skeleton":
|
|
_skeleton.Id = property.Value.GetInt32();
|
|
break;
|
|
case "name":
|
|
Name = property.Value.GetString();
|
|
break;
|
|
}
|
|
}
|
|
|
|
DeserializeCommon(element);
|
|
}
|
|
|
|
internal override void Serialize(Utf8JsonWriter writer)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
} |