Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLTFExporter: Missing required padding on integer vertex attributes #27064

Merged
merged 4 commits into from
Mar 19, 2024
20 changes: 18 additions & 2 deletions examples/jsm/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,17 @@ class GLTFWriter {

}

const byteLength = getPaddedBufferSize( count * attribute.itemSize * componentSize );
let byteStride = attribute.itemSize * componentSize;

if ( target === WEBGL_CONSTANTS.ARRAY_BUFFER ) {

// Each element of a vertex attribute MUST be aligned to 4-byte boundaries
// inside a bufferView
byteStride = Math.ceil( byteStride / 4 ) * 4;

}

const byteLength = getPaddedBufferSize( count * byteStride );
const dataView = new DataView( new ArrayBuffer( byteLength ) );
let offset = 0;

Expand Down Expand Up @@ -1041,6 +1051,12 @@ class GLTFWriter {

}

if ( ( offset % byteStride ) !== 0 ) {

offset += byteStride - ( offset % byteStride );

}

}

const bufferViewDef = {
Expand All @@ -1056,7 +1072,7 @@ class GLTFWriter {
if ( target === WEBGL_CONSTANTS.ARRAY_BUFFER ) {

// Only define byteStride for vertex attributes.
bufferViewDef.byteStride = attribute.itemSize * componentSize;
bufferViewDef.byteStride = byteStride;

}

Expand Down