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

BufferGeometry.getAttribute get a BufferAttribute without casting? #1527

Open
janne-hyoetylae-med opened this issue Feb 3, 2025 · 1 comment

Comments

@janne-hyoetylae-med
Copy link

janne-hyoetylae-med commented Feb 3, 2025

BufferGeometry.getAttribute returns BufferAttribute | InterleavedBufferAttribute when using with the default generic types. But there is code in threejs that only accepts BufferAttribute and not interleaved.

For example this code in the threejs codebase itself would not compile if used as is in Typescript:
https://github.com/mrdoob/three.js/blob/9004ed1d3dacbede52c5657a1556789be10c0a77/src/objects/Mesh.js#L383

intersection.normal = Triangle.getInterpolatedAttribute( normal, a, b, c, barycoord, new Vector3() );

normal would be a BufferAttribute|InterleavedBufferAttribute obtained from BufferGeometry.attributes (same as getAttribute), but Triangle.getInterpolatedAttribute accepts only BufferAttribute.

Note that there are no if checks in threejs around the normal variable or in Triangle.getInterpolatedAttribute, so they assume/know that this must be a strict BufferAttribute in the mesh. Can we make the same work in Typescript without casting / type assertion?

@Methuselah96
Copy link
Contributor

Thanks for the issue! I think Triangle.getInterpolatedAttribute can be updated to allow InterleavedBufferAttributes as well. Feel free to create a PR!

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

No branches or pull requests

2 participants