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

InterleavedBufferAttribute: Add get / set component functions #27590

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/api/en/core/InterleavedBufferAttribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ <h3>[method:this transformDirection]( [param:Matrix4 m] )</h3>
vectors.
</p>

<h3>[method:Number getComponent]( [param:Integer index], [param:Integer component] ) </h3>
<p>Returns the given component of the vector at the given index.</p>

<h3>[method:Number getX]( [param:Integer index] )</h3>
<p>Returns the x component of the item at the given index.</p>

Expand All @@ -89,6 +92,9 @@ <h3>[method:Number getZ]( [param:Integer index] )</h3>
<h3>[method:Number getW]( [param:Integer index] )</h3>
<p>Returns the w component of the item at the given index.</p>

<h3>[method:Number setComponent]( [param:Integer index], [param:Integer component], [param:Float value] ) </h3>
<p>Sets the given component of the vector at the given index.</p>

<h3>[method:this setX]( [param:Integer index], [param:Float x] )</h3>
<p>Sets the x component of the item at the given index.</p>

Expand Down
20 changes: 20 additions & 0 deletions src/core/InterleavedBufferAttribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ class InterleavedBufferAttribute {

}

getComponent( index, component ) {

let value = this.array[ index * this.data.stride + this.offset + component ];

if ( this.normalized ) value = denormalize( value, this.array );

return value;

}

setComponent( index, component, value ) {

if ( this.normalized ) value = normalize( value, this.array );

this.data.array[ index * this.data.stride + this.offset + component ] = value;

return this;

}

setX( index, x ) {

if ( this.normalized ) x = normalize( x, this.array );
Expand Down