Browse Source

InterleavedBufferAttribute: Add get / set component functions (#27590)

* InterleavedBufferAttribute: add getComponent, setComponent

* Update docs
Garrett Johnson 1 năm trước cách đây
mục cha
commit
6fe0b840ec

+ 6 - 0
docs/api/en/core/InterleavedBufferAttribute.html

@@ -77,6 +77,9 @@
 			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>
 
@@ -89,6 +92,9 @@
 		<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>
 

+ 20 - 0
src/core/InterleavedBufferAttribute.js

@@ -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 );