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

Narrow BufferAttribute's array to TypedArray #515

Merged
merged 4 commits into from
Jul 4, 2023

Conversation

Methuselah96
Copy link
Contributor

@Methuselah96 Methuselah96 commented Jul 1, 2023

Why

Resolves #35. This allows code like this snippet from the misc_exporter_ply.html example to work:

const geometry = new THREE.BoxGeometry();

// color vertices based on vertex positions
const colors = geometry.getAttribute("position").array.slice();
for (let i = 0, l = colors.length; i < l; i++) {
  if (colors[i] > 0) colors[i] = 0.5;
  else colors[i] = 0;
}

What

Introduce a TypedArray type that is the union of all the typed arrays. This excludes BigInt64Array and BigUint64Array so that we don't have to change the ES version we're targeting. The better solution would be for TypeScript to provide a TypedArray interface which is discussed here.

Checklist

  • Checked the target branch (current goes master, next goes dev)
  • Added myself to contributors table
  • Ready to be merged

@Methuselah96 Methuselah96 merged commit 77387e1 into master Jul 4, 2023
@Methuselah96 Methuselah96 deleted the buffer-attribute-array branch July 4, 2023 19:11
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.

[RFC] Should BufferAttribute.array be TypedArray instead of ArrayLike?
1 participant