Files
ReFuel.Gltf/ReFuel.Gltf/GlbStructures.cs
T
2025-10-12 14:33:16 +03:00

60 lines
1.4 KiB
C#
Executable File

using System;
using System.IO;
using System.Runtime.InteropServices;
namespace ReFuel.Gltf
{
[StructLayout(LayoutKind.Explicit, Size = 12)]
public struct GlbHeader
{
[FieldOffset(0)]
public int Signature;
[FieldOffset(4)]
public int Version;
[FieldOffset(8)]
public int Length;
public const int SIGNATURE_VALUE = 0x46546C67; // "glTF"
public static unsafe bool Read(Stream str, out GlbHeader header)
{
header = default;
int len;
fixed (GlbHeader* pheader = &header)
len = str.Read(new Span<byte>(pheader, sizeof(GlbHeader)));
if (len != sizeof(GlbHeader))
return false;
else if (header.Signature == GlbHeader.SIGNATURE_VALUE)
return true;
else
return false;
}
}
[StructLayout(LayoutKind.Explicit, Size = 8)]
public struct GlbChunk
{
[FieldOffset(0)]
public int Size;
[FieldOffset(4)]
public GlbChunkType Type;
public static unsafe bool Read(Stream str, out GlbChunk chunk)
{
chunk = default;
fixed (GlbChunk* pchunk = &chunk)
return str.Read(new Span<byte>(pchunk, sizeof(GlbChunk))) == sizeof(GlbChunk);
}
}
public enum GlbChunkType : int
{
Json = 0x4E4F534A,
Bin = 0x004E4942,
}
}