瀏覽代碼

Merge pull request #20663 from Mugen87/dev44

InstancedMesh: Add .getColorAt().
Mr.doob 4 年之前
父節點
當前提交
fff9d45ac7

+ 11 - 0
docs/api/en/objects/InstancedMesh.html

@@ -66,6 +66,17 @@
 		<h2>Methods</h2>
 		<p>See the base [page:Mesh] class for common methods.</p>
 
+		<h3>[method:null getColorAt]( [param:Integer index], [param:Color color] )</h3>
+		<p>
+			[page:Integer index]: The index of an instance. Values have to be in the range [0, count].
+		</p>
+		<p>
+			[page:Color color]: This color object will be set to the color of the defined instance.
+		</p>
+		<p>
+			Get the color of the defined instance.
+		</p>
+
 		<h3>[method:null getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3>
 		<p>
 			[page:Integer index]: The index of an instance. Values have to be in the range [0, count].

+ 11 - 0
docs/api/zh/objects/InstancedMesh.html

@@ -65,6 +65,17 @@
 		<h2>方法</h2>
 		<p>See the base [page:Mesh] class for common methods.</p>
 
+		<h3>[method:null getColorAt]( [param:Integer index], [param:Color color] )</h3>
+		<p>
+			[page:Integer index]: The index of an instance. Values have to be in the range [0, count].
+		</p>
+		<p>
+			[page:Color color]: This color object will be set to the color of the defined instance.
+		</p>
+		<p>
+			Get the color of the defined instance.
+		</p>
+
 		<h3>[method:null getMatrixAt]( [param:Integer index], [param:Matrix4 matrix] )</h3>
 		<p>
 			[page:Integer index]: 实例的索引。值必须在 [0, count] 区间。

+ 2 - 1
src/objects/InstancedMesh.d.ts

@@ -22,8 +22,9 @@ export class InstancedMesh <
 	instanceMatrix: BufferAttribute;
 	readonly isInstancedMesh: true;
 
+	getColorAt( index: number, color: Color ): void;
 	getMatrixAt( index: number, matrix: Matrix4 ): void;
-	setMatrixAt( index: number, matrix: Matrix4 ): void;
 	setColorAt( index: number, color: Color ): void;
+	setMatrixAt( index: number, matrix: Matrix4 ): void;
 
 }

+ 14 - 8
src/objects/InstancedMesh.js

@@ -39,15 +39,9 @@ InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 	},
 
-	setColorAt: function ( index, color ) {
-
-		if ( this.instanceColor === null ) {
-
-			this.instanceColor = new BufferAttribute( new Float32Array( this.count * 3 ), 3 );
+	getColorAt: function ( index, color ) {
 
-		}
-
-		color.toArray( this.instanceColor.array, index * 3 );
+		color.fromArray( this.instanceColor.array, index * 3 );
 
 	},
 
@@ -98,6 +92,18 @@ InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
 
 	},
 
+	setColorAt: function ( index, color ) {
+
+		if ( this.instanceColor === null ) {
+
+			this.instanceColor = new BufferAttribute( new Float32Array( this.count * 3 ), 3 );
+
+		}
+
+		color.toArray( this.instanceColor.array, index * 3 );
+
+	},
+
 	setMatrixAt: function ( index, matrix ) {
 
 		matrix.toArray( this.instanceMatrix.array, index * 16 );