question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BufferGeometry: .setIndex method does not take null as input

See original GitHub issue

The following TypeScript code does not compile:

const geometry = new THREE.BufferGeometry();

geometry.setIndex(null); // Argument of type `null` is not assignable to parameter of type `BufferAttribute | number[]`.

I guess supporting this code would mean allowing to dynamically turn an indexed geometry into a non-indexed geometry without going through the toNonIndexed helper method e.g. without creating another BufferGeometry instance.

I am wondering if that’s a case that could easily be supported and if I should open a PR for that. If not, feel free to close this issue.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
Mugen87commented, Dec 4, 2019

I just want to add a note on the fact the setIndex implementation might already accept null as input, it’s only the TypeScript definition that lacks this input type.

Then feel free to enhance the respective TS declaration file if this solves your original issue 👍

1reaction
donmccurdycommented, Dec 3, 2019

For me it’s mostly an API consistency and ergonomics issue… if the following code is valid:

var geometry = new BufferGeometry();
geometry.setAttribute( 'position', positionAttribute );

// index is null.
geometry.setIndex( index );
// index is not null.

… then we are allowing users to incrementally construct BufferGeometry instances with “invalid” intermediate states, and as long as the state is valid when rendering, that’s fine. For the reverse — removing an index — not to work feels like a surprising “gotcha” in the API. Patterns exist for immutable objects (Builder patterns, or requiring immutable properties as constructor arguments) but irreversible setters are unusual.

I can contrive some use cases…

  • declarative frameworks like react-three-fiber or A-Frame might want to clear properties in one method and set the new values in another
  • user might use multiple indexes as more flexible draw ranges on a “triangle soup” mesh, or remove that index to draw the entire mesh

… but IMO the priority is “what is least likely to surprise the developer” here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

BufferGeometry#setIndex – three.js docs
Default is null . # .drawRange : Object. Determines the part of the geometry to render. This should not be set directly, instead...
Read more >
How to understand setIndex and index in BufferGeometry in ...
Using an indexed geometry is not required. If you are not using indices, the triangles are defined by the order of vertices in...
Read more >
Indexed BufferGeometry - CodePen
So you don't have access to higher-up elements like the <html> tag. If you want to add classes there that can affect the...
Read more >
Team:Munich/Hardware/threeJS - iGEM 2018
// We compute the minimum and maximum dot product values. If those values // are on the same side (back or front) of...
Read more >
Three.js Custom BufferGeometry
As a simple example let's make a cube using BufferGeometry . A cube is interesting because it appears to share vertices at the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found