Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/exporters/GLTFExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,13 @@ class GLTFWriter {
componentSize = 4
}

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 @@ -1065,6 +1071,9 @@ class GLTFWriter {

offset += componentSize
}
if (offset % byteStride !== 0) {
offset += byteStride - (offset % byteStride)
}
}

const bufferViewDef = {
Expand All @@ -1077,7 +1086,7 @@ class GLTFWriter {

if (target === WEBGL_CONSTANTS.ARRAY_BUFFER) {
// Only define byteStride for vertex attributes.
bufferViewDef.byteStride = attribute.itemSize * componentSize
bufferViewDef.byteStride = byteStride
}

this.byteOffset += byteLength
Expand Down