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.

proposal: BufferAttribute.copyVector( )

See original GitHub issue

I 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:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
donmccurdycommented, Mar 22, 2022

@Mugen87 perhaps a sentence like https://github.com/mrdoob/three.js/pull/23772 would not be too intrusive?

1reaction
Mugen87commented, Mar 22, 2022

Why are you not using fromBufferAttribute()?

myVector.fromBufferAttribute( bufferAttribute, index );

That is the intended way of extracting attribute data into vectors.

Read more comments on GitHub >

github_iconTop 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 >

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