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

[🐞 Bug Fix] 6.2.8 breaks parsing of models with interleaved buffers #214

Merged
merged 2 commits into from
Dec 21, 2023

Conversation

billykwok
Copy link
Contributor

@billykwok billykwok commented Jul 18, 2023

Issue

After updating to 6.2.8, parsing 3D models with interleaved buffer always gives the following error.

TypeError: Cannot set property count of #<InterleavedBufferAttribute> which has only a getter
    at file:///<redacted>/node_modules/.pnpm/[email protected]/node_modules/gltfjsx/src/bin/GLTFLoader.js:1675:27
    at async Promise.all (index 0)
    at async Promise.all (index 0)
    at async Promise.all (index 0)
    at async Promise.all (index 1)
    at async Promise.all (index 0)
    at async Promise.all (index 1)
    at async Promise.all (index 0)
    at async Promise.all (index 0)

Investigation

In /src/bin/GLTFLoader.js#L1675, the count property of bufferAttribute is assigned an updated value.

// ...
bufferAttribute.count = accessorDef.count
// ...

Prior to the assignment, bufferAttribute was instantiated as either BufferAttribute or InterleavedBufferAttribute. This is fine for BufferAttribute as its count property is mutable.

However, in InterleavedBufferAttribute, count is just a getter that returns the count of the underlying InterleavedBuffer. Attempting to assign a new value to count will throw an error.

https://github.com/mrdoob/three.js/blob/master/src/core/InterleavedBufferAttribute.js#L23

get count() {
  return this.data.count;
}

This issue doesn't apply to versions prior to 6.2.8 because the line was newly added to this version.

Solution

I made a very small fix to update count differently if the bufferAttribute is a InterleavedBufferAttribute.

if (bufferAttribute.isInterleavedBufferAttribute) {
  bufferAttribute.data.count = accessorDef.count
} else {
  bufferAttribute.count = accessorDef.count
}

@billykwok billykwok changed the title 6.2.8 breaks parsing of models with interleaved buffers [🐞 Bug] 6.2.8 breaks parsing of models with interleaved buffers Jul 18, 2023
@billykwok billykwok changed the title [🐞 Bug] 6.2.8 breaks parsing of models with interleaved buffers [🐞 Bug Fix] 6.2.8 breaks parsing of models with interleaved buffers Jul 18, 2023
@drcmda
Copy link
Member

drcmda commented Dec 21, 2023

thanks!

@drcmda drcmda merged commit 86594d3 into pmndrs:master Dec 21, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants