proposal: BufferAttribute.copyVector( )
See original GitHub issueI was doing some computation on a buffer attribute where I needed to fetch each normal to create a new attribute, so I was looking for a way to copy the values of the attr to a vector, but I see we only have single fetches getX
, getY
, getZ
.
What about adding a copyVector
method to BufferAttribute that would do the work?
const myVector = new Vector3()
for (let i = 0; etc etc) {
bufferAttribute // itemSize 3
.copyVector(index, myVector)
}
This could be implemented as
copyVector( index, vector ) {
const x = this.getX( index )
const y = this.getY( index )
// either check the vector or check the buffer's itemSize
if ( vector.isVector3 ) {
vector.z = this.getZ( index )
}
if ( vector.isVector4 ) {
vector.w = this.getW( index );
}
}
Of course this is trivially done in userland, but it’s such a small snippet that it could be nice to have. I did a quick search and we also use this pattern in some examples and lib code: https://github.com/mrdoob/three.js/search?q=.getX (not all of these results apply )
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
BufferAttribute – three.js docs
BufferAttribute. This class stores data for an attribute (such as vertex positions, face indices, normals, colors, UVs, and any custom attributes ) ...
Read more >Improving BufferAttribute (maybe) · Issue #17089 - GitHub
I think this makes a strong case that (1) the current interleaving API may not yet offer enough benefits, and (2) we can...
Read more >three.js - BufferAttribute Size for IndexedBufferGeometry
attribute has itemSize property that determines how many numbers are meant for a single vector. position attribute has itemSize == 3.
Read more >How to use the three.BufferAttribute function in three - Snyk
To help you get started, we've selected a few three.BufferAttribute examples, based on popular ways it is used in public projects.
Read more >Ön hogyan látja munkánkat? - Magyar Védőnők Egyesülete
Insurance companies have proposed increases in health insurance premiums as high as 59 percent this ... buffer attribute in JSP page directive with...
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
@Mugen87 perhaps a sentence like https://github.com/mrdoob/three.js/pull/23772 would not be too intrusive?
Why are you not using
fromBufferAttribute()
?That is the intended way of extracting attribute data into vectors.