Add stream open to bufferview & image

This commit is contained in:
2026-10-23 21:36:22 +02:00
parent fe9d87155c
commit f10973aed6
2 changed files with 14 additions and 2 deletions
+7 -1
View File
@@ -1,4 +1,5 @@
using System;
using ReFuel.Gltf.IO;
using System;
using System.Text.Json;
namespace ReFuel.Gltf
@@ -26,6 +27,11 @@ namespace ReFuel.Gltf
buffer = new GltfSmartId<GltfBuffer>(document.Buffers);
}
public Stream Open()
{
return ((StreamWrapper)buffer.Value.Open()).ForkAbs(ByteOffset, ByteOffset + ByteLength);
}
internal override void Deserialize(JsonElement element)
{
AssertObject(element);
+7 -1
View File
@@ -39,7 +39,7 @@ namespace ReFuel.Gltf
{
if (Uri == null)
{
throw new Exception("Only images with a URI property are to be opened.");
return BufferView!.Open();
}
if (Uri.IsAbsoluteUri)
@@ -64,9 +64,13 @@ namespace ReFuel.Gltf
// otherwise
if (provider != null)
{
return provider.OpenFile(pwd, Uri) ?? throw new FileNotFoundException(Uri.ToString());
}
else
{
return File.OpenRead(Path.Combine(pwd ?? string.Empty, Uri.LocalPath));
}
// throw new Exception("Unrecognized URI scheme.");
}
@@ -74,7 +78,9 @@ namespace ReFuel.Gltf
internal override void Deserialize(JsonElement element)
{
if (element.ValueKind != JsonValueKind.Object)
{
throw new Exception("Expected a JSON object for glTF image node.");
}
foreach (JsonProperty property in element.EnumerateObject())
{