Files
2025-10-12 14:33:16 +03:00

74 lines
2.0 KiB
C#

using System;
using System.Text.Json;
namespace ReFuel.Gltf
{
public class GltfTexture : GltfIdObject
{
public override GltfObjectKind Kind => GltfObjectKind.Texture;
private GltfSmartId<GltfSampler> _sampler;
private GltfSmartId<GltfImage> _source;
public string? Name { get; set; } = null;
public GltfSampler? Sampler
{
get => _sampler.IsSet ? _sampler.Value : null;
set
{
if (value is null)
_sampler.Reset();
else
_sampler.Value = value;
}
}
public GltfImage? Source
{
get => _source.IsSet ? _source.Value : null;
set
{
if (value is null)
_source.Reset();
else
_source.Value = value;
}
}
internal GltfTexture(GltfDocument document) : base(document)
{
_sampler = new GltfSmartId<GltfSampler>(document.Samplers);
_source = new GltfSmartId<GltfImage>(document.Images);
}
internal override void Deserialize(JsonElement element)
{
if (element.ValueKind != JsonValueKind.Object)
throw new Exception("Expected an object.");
foreach (JsonProperty property in element.EnumerateObject())
{
switch (property.Name)
{
case "name":
Name = property.Value.GetString();
break;
case "source":
_source.Id = property.Value.GetInt32();
break;
case "sampler":
_sampler.Id = property.Value.GetInt32();
break;
}
}
DeserializeCommon(element);
}
internal override void Serialize(Utf8JsonWriter writer)
{
throw new NotImplementedException();
}
}
}