When loading embedded data, the entire buffer is returned by the LoadBinaryBuffer method without taking into account the bufferView.byteOffset.
Changing the code to:
public static byte[] LoadBinaryBuffer(this Gltf model, int bufferIndex, Func<string, byte[]> externalReferenceSolver, int bufferViewByteOffset = 0)
{
var buffer = model.Buffers[bufferIndex];
var bufferData = LoadBinaryBufferUnchecked(buffer, externalReferenceSolver);
// As per https://github.com/KhronosGroup/glTF/issues/1026
// Due to buffer padding, buffer length can be equal or larger than expected length by only 3 bytes
if (bufferData.Length < buffer.ByteLength || (bufferData.Length - buffer.ByteLength) > 3)
{
throw new InvalidDataException($"The buffer length is {bufferData.Length}, expected {buffer.ByteLength}");
}
if (bufferViewByteOffset > 0)
{
var newBufferData = new byte[bufferData.Length - bufferViewByteOffset];
for (var i = 0; i < newBufferData.Length; i++)
{
newBufferData[i] = bufferData[bufferViewByteOffset + i];
}
bufferData = newBufferData;
}
return bufferData;
}
When loading embedded data, the entire buffer is returned by the LoadBinaryBuffer method without taking into account the bufferView.byteOffset.
Changing the code to:
Fixes it.