浏览代码

Triangle: Add setFromAttributeAndIndices(). (#22404)

* Triangle: Add setFromAttributeAndIndices().

* Docs: Improve setFromAttributeAndIndices() description.
Michael Herzog 3 年之前
父节点
当前提交
d957011fd3
共有 4 个文件被更改,包括 44 次插入0 次删除
  1. 10 0
      docs/api/en/math/Triangle.html
  2. 11 0
      docs/api/zh/math/Triangle.html
  3. 10 0
      src/math/Triangle.js
  4. 13 0
      test/unit/src/math/Triangle.tests.js

+ 10 - 0
docs/api/en/math/Triangle.html

@@ -126,6 +126,16 @@
 		Please note that this method only copies the values from the given objects.
 		</p>
 
+		<h3>[method:Triangle setFromAttributeAndIndices]( [param:BufferAttribute attribute], [param:Integer i0], [param:Integer i1], [param:Integer i2] ) [param:Triangle this]</h3>
+		<p>
+		attribute - [page:BufferAttribute] of vertex data <br />
+		i0 - [page:Integer] index <br />
+		i1 - [page:Integer] index <br />
+		i2 - [page:Integer] index<br /><br />
+
+		Sets the triangle's vertices from the buffer attribute vertex data.
+		</p>
+
 		<h3>[method:Triangle setFromPointsAndIndices]( [param:Array points], [param:Integer i0], [param:Integer i1], [param:Integer i2] ) [param:Triangle this]</h3>
 		<p>
 		points - [page:Array] of [page:Vector3]s <br />

+ 11 - 0
docs/api/zh/math/Triangle.html

@@ -123,6 +123,17 @@
 			请注意,此方法仅复制给定对象的值。
 		</p>
 
+		<h3>[method:Triangle setFromAttributeAndIndices]( [param:BufferAttribute attribute], [param:Integer i0], [param:Integer i1], [param:Integer i2] ) [param:Triangle this]</h3>
+		<p>
+		attribute - [page:BufferAttribute] of vertex data <br />
+		i0 - [page:Integer] index <br />
+		i1 - [page:Integer] index <br />
+		i2 - [page:Integer] index<br /><br />
+
+		Sets the triangle's vertices from the buffer attribute vertex data.
+		</p>
+
+
 		<h3>[method:Triangle setFromPointsAndIndices]( [param:Array points], [param:Integer i0], [param:Integer i1], [param:Integer i2] ) [param:Triangle this]</h3>
 		<p>
 		points - [page:Vector3]数组([page:Array]) <br />

+ 10 - 0
src/math/Triangle.js

@@ -124,6 +124,16 @@ class Triangle {
 
 	}
 
+	setFromAttributeAndIndices( attribute, i0, i1, i2 ) {
+
+		this.a.fromBufferAttribute( attribute, i0 );
+		this.b.fromBufferAttribute( attribute, i1 );
+		this.c.fromBufferAttribute( attribute, i2 );
+
+		return this;
+
+	}
+
 	clone() {
 
 		return new this.constructor().copy( this );

+ 13 - 0
test/unit/src/math/Triangle.tests.js

@@ -1,5 +1,6 @@
 /* global QUnit */
 
+import { BufferAttribute } from '../../../../src/core/BufferAttribute';
 import { Triangle } from '../../../../src/math/Triangle';
 import { Box3 } from '../../../../src/math/Box3';
 import { Plane } from '../../../../src/math/Plane';
@@ -72,6 +73,18 @@ export default QUnit.module( 'Maths', () => {
 
 		} );
 
+		QUnit.test( "setFromAttributeAndIndices", ( assert ) => {
+
+			var a = new Triangle();
+			var attribute = new BufferAttribute( new Float32Array( [ 1, 1, 1, - 1, - 1, - 1, 2, 2, 2 ] ), 3 );
+
+			a.setFromAttributeAndIndices( attribute, 1, 0, 2 );
+			assert.ok( a.a.equals( one3.clone().negate() ), "Passed!" );
+			assert.ok( a.b.equals( one3 ), "Passed!" );
+			assert.ok( a.c.equals( two3 ), "Passed!" );
+
+		} );
+
 		QUnit.todo( "clone", ( assert ) => {
 
 			assert.ok( false, "everything's gonna be alright" );