Skip to content

Commit

Permalink
InterleavedBufferAttribute: Add get / set component functions (#27590)
Browse files Browse the repository at this point in the history
* InterleavedBufferAttribute: add getComponent, setComponent

* Update docs
  • Loading branch information
gkjohnson authored Jan 19, 2024
1 parent b622238 commit 6fe0b84
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
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

0 comments on commit 6fe0b84

Please sign in to comment.