Skip to content

Commit 1082b9a

Browse files
committed
Fix vertex buffer padding
1 parent c59c788 commit 1082b9a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Source/RunActivity/Viewer3D/GltfShape.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,13 @@ internal Stream GetBufferView(int? bufferViewNumber, int accessorByteOffset, out
711711
return stream;
712712
}
713713

714-
internal int GetSizeInBytes(Accessor accessor) => GetComponentNumber(accessor.Type) * GetComponentSizeInBytes(accessor.ComponentType);
714+
internal int GetSizeInBytes(Accessor accessor)
715+
{
716+
var componentNumber = GetComponentNumber(accessor.Type);
717+
var size = componentNumber * GetComponentSizeInBytes(accessor.ComponentType);
718+
var padding = componentNumber == 1 ? 0 : size % 4; // do not add padding to the index buffers
719+
return size + padding;
720+
}
715721

716722
int GetComponentNumber(Accessor.TypeEnum type)
717723
{
@@ -773,6 +779,7 @@ VertexElementFormat GetVertexElementFormat(Accessor accessor, bool msfsFlavoured
773779
case Accessor.TypeEnum.VEC4 when accessor.ComponentType == Accessor.ComponentTypeEnum.FLOAT: return VertexElementFormat.Vector4;
774780

775781
// MSFS twisted out, reversed definitions:
782+
// non-normalized, VEC3 FLOAT, VEC4 BYTE, VEC2 SHORT, VEC4 USHORT, SCALAR FLOAT
776783
case Accessor.TypeEnum.VEC2 when accessor.ComponentType == Accessor.ComponentTypeEnum.SHORT && msfsFlavoured: return accessor.Normalized ? VertexElementFormat.Short2 : VertexElementFormat.HalfVector2;
777784
case Accessor.TypeEnum.VEC2 when accessor.ComponentType == Accessor.ComponentTypeEnum.UNSIGNED_SHORT && msfsFlavoured: return accessor.Normalized ? VertexElementFormat.Short2 : VertexElementFormat.HalfVector2;
778785
case Accessor.TypeEnum.VEC4 when accessor.ComponentType == Accessor.ComponentTypeEnum.BYTE && msfsFlavoured: return VertexElementFormat.Color;

0 commit comments

Comments
 (0)