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; using System.Text.Json;
namespace ReFuel.Gltf namespace ReFuel.Gltf
@@ -26,6 +27,11 @@ namespace ReFuel.Gltf
buffer = new GltfSmartId<GltfBuffer>(document.Buffers); buffer = new GltfSmartId<GltfBuffer>(document.Buffers);
} }
public Stream Open()
{
return ((StreamWrapper)buffer.Value.Open()).ForkAbs(ByteOffset, ByteOffset + ByteLength);
}
internal override void Deserialize(JsonElement element) internal override void Deserialize(JsonElement element)
{ {
AssertObject(element); AssertObject(element);
+7 -1
View File
@@ -39,7 +39,7 @@ namespace ReFuel.Gltf
{ {
if (Uri == null) if (Uri == null)
{ {
throw new Exception("Only images with a URI property are to be opened."); return BufferView!.Open();
} }
if (Uri.IsAbsoluteUri) if (Uri.IsAbsoluteUri)
@@ -64,9 +64,13 @@ namespace ReFuel.Gltf
// otherwise // otherwise
if (provider != null) if (provider != null)
{
return provider.OpenFile(pwd, Uri) ?? throw new FileNotFoundException(Uri.ToString()); return provider.OpenFile(pwd, Uri) ?? throw new FileNotFoundException(Uri.ToString());
}
else else
{
return File.OpenRead(Path.Combine(pwd ?? string.Empty, Uri.LocalPath)); return File.OpenRead(Path.Combine(pwd ?? string.Empty, Uri.LocalPath));
}
// throw new Exception("Unrecognized URI scheme."); // throw new Exception("Unrecognized URI scheme.");
} }
@@ -74,7 +78,9 @@ namespace ReFuel.Gltf
internal override void Deserialize(JsonElement element) internal override void Deserialize(JsonElement element)
{ {
if (element.ValueKind != JsonValueKind.Object) if (element.ValueKind != JsonValueKind.Object)
{
throw new Exception("Expected a JSON object for glTF image node."); throw new Exception("Expected a JSON object for glTF image node.");
}
foreach (JsonProperty property in element.EnumerateObject()) foreach (JsonProperty property in element.EnumerateObject())
{ {