BufferGeometry: .setIndex method does not take null as input
See original GitHub issueThe 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:
- Created 4 years ago
- Comments:20 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Then feel free to enhance the respective TS declaration file if this solves your original issue 👍
For me it’s mostly an API consistency and ergonomics issue… if the following code is valid:
… 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…
… but IMO the priority is “what is least likely to surprise the developer” here.