Skip to content

glTF importer corrupts interleaved vertex buffers #962

Description

@krapnikkk

Summary

The glTF importer corrupts meshes whose vertex attributes use an interleaved buffer view. Imported geometry appears as exploded or stretched triangles, and UVs are also scrambled.

@mr0x13f

Steps to reproduce

  1. Import a valid glTF 2.0 asset where POSITION, NORMAL, and TEXCOORD_0 share one buffer view with byteStride: 32.
  2. The bundled GLTFLoader creates THREE.InterleavedBufferAttribute instances for these attributes.
  3. Complete the import into a Blockbench generic model.

Expected behavior

The editable Blockbench mesh matches the glTF geometry and UVs.

Actual behavior

Most vertices are read from normal/UV slots instead of position slots, producing long spikes and scrambled faces.

Root cause

importMeshPrimitives() reads attribute storage as tightly packed arrays:

position.array[vertexIndex * 3]
uv.array[vertexIndex * 2]

For an InterleavedBufferAttribute, .array is the shared interleaved storage and these offsets ignore both the attribute offset and buffer stride. The loader already exposes stride-safe getX(), getY(), and getZ() methods.

Index access should also use geometry.getIndex().getX() for consistency across BufferAttribute implementations.

Proposed fix

Read position, UV, and index components through the BufferAttribute getter API rather than indexing .array directly. This supports both tightly packed and interleaved glTF buffers.

I have a focused fix and regression coverage ready for a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions